Completed
Push — master ( 1fed4c...6bbecb )
by Yannick
05:53
created
require/class.Image.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -319,6 +319,9 @@
 block discarded – undo
319 319
 		return false;
320 320
 	}
321 321
 
322
+	/**
323
+	 * @param string $aircraft_icao
324
+	 */
322 325
 	public function fromIvaoMtl($aircraft_icao,$airline_icao) {
323 326
 		$Common = new Common();
324 327
 		//echo "\n".'SEARCH IMAGE : http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg';
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
 	}
13 13
 
14 14
 	/**
15
-	* Gets the images based on the aircraft registration
16
-	*
17
-	* @return Array the images list
18
-	*
19
-	*/
15
+	 * Gets the images based on the aircraft registration
16
+	 *
17
+	 * @return Array the images list
18
+	 *
19
+	 */
20 20
 	public function getSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
21 21
 	{
22 22
 		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 			WHERE spotter_image.registration = :registration";
30 30
 		$sth = $this->db->prepare($query);
31 31
 		$sth->execute(array(':registration' => $registration));
32
-          /*
32
+		  /*
33 33
         $images_array = array();
34 34
 	$temp_array = array();
35 35
 
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 
54 54
 	/**
55
-	* Gets the image copyright based on the Exif data
56
-	*
57
-	* @return String image copyright
58
-	*
59
-	*/
55
+	 * Gets the image copyright based on the Exif data
56
+	 *
57
+	 * @return String image copyright
58
+	 *
59
+	 */
60 60
 	public function getExifCopyright($url) {
61 61
 		$exif = exif_read_data($url);
62 62
 		$copyright = '';
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	}
72 72
 
73 73
 	/**
74
-	* Adds the images based on the aircraft registration
75
-	*
76
-	* @return String either success or error
77
-	*
78
-	*/
74
+	 * Adds the images based on the aircraft registration
75
+	 *
76
+	 * @return String either success or error
77
+	 *
78
+	 */
79 79
 	public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
80 80
 	{
81 81
 		global $globalDebug,$globalAircraftImageFetch;
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 	}
105 105
 
106 106
 	/**
107
-	* Gets the aircraft image
108
-	*
109
-	* @param String $aircraft_registration the registration of the aircraft
110
-	* @return Array the aircraft thumbnail, orignal url and copyright
111
-	*
112
-	*/
107
+	 * Gets the aircraft image
108
+	 *
109
+	 * @param String $aircraft_registration the registration of the aircraft
110
+	 * @return Array the aircraft thumbnail, orignal url and copyright
111
+	 *
112
+	 */
113 113
 	public function findAircraftImage($aircraft_registration, $aircraft_icao = '', $airline_icao = '')
114 114
 	{
115 115
 		global $globalAircraftImageSources, $globalIVAO;
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 
151 151
 	/**
152
-	* Gets the aircraft image from Planespotters
153
-	*
154
-	* @param String $aircraft_registration the registration of the aircraft
155
-	* @param String $aircraft_name type of the aircraft
156
-	* @return Array the aircraft thumbnail, orignal url and copyright
157
-	*
158
-	*/
152
+	 * Gets the aircraft image from Planespotters
153
+	 *
154
+	 * @param String $aircraft_registration the registration of the aircraft
155
+	 * @param String $aircraft_name type of the aircraft
156
+	 * @return Array the aircraft thumbnail, orignal url and copyright
157
+	 *
158
+	 */
159 159
 	public function fromPlanespotters($aircraft_registration, $aircraft_name='') {
160 160
 		$Common = new Common();
161 161
 		// If aircraft registration is only number, also check with aircraft model
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	}
183 183
 
184 184
 	/**
185
-	* Gets the aircraft image from Deviantart
186
-	*
187
-	* @param String $aircraft_registration the registration of the aircraft
188
-	* @param String $aircraft_name type of the aircraft
189
-	* @return Array the aircraft thumbnail, orignal url and copyright
190
-	*
191
-	*/
185
+	 * Gets the aircraft image from Deviantart
186
+	 *
187
+	 * @param String $aircraft_registration the registration of the aircraft
188
+	 * @param String $aircraft_name type of the aircraft
189
+	 * @return Array the aircraft thumbnail, orignal url and copyright
190
+	 *
191
+	 */
192 192
 	public function fromDeviantart($aircraft_registration, $aircraft_name='') {
193 193
 		$Common = new Common();
194 194
 		// If aircraft registration is only number, also check with aircraft model
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	/**
219
-	* Gets the aircraft image from JetPhotos
220
-	*
221
-	* @param String $aircraft_registration the registration of the aircraft
222
-	* @param String $aircraft_name type of the aircraft
223
-	* @return Array the aircraft thumbnail, orignal url and copyright
224
-	*
225
-	*/
219
+	 * Gets the aircraft image from JetPhotos
220
+	 *
221
+	 * @param String $aircraft_registration the registration of the aircraft
222
+	 * @param String $aircraft_name type of the aircraft
223
+	 * @return Array the aircraft thumbnail, orignal url and copyright
224
+	 *
225
+	 */
226 226
 	public function fromJetPhotos($aircraft_registration, $aircraft_name='') {
227 227
 		$Common = new Common();
228 228
 		$url= 'http://jetphotos.net/showphotos.php?displaymode=2&regsearch='.$aircraft_registration;
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Gets the aircraft image from PlanePictures
262
-	*
263
-	* @param String $aircraft_registration the registration of the aircraft
264
-	* @param String $aircraft_name type of the aircraft
265
-	* @return Array the aircraft thumbnail, orignal url and copyright
266
-	*
267
-	*/
261
+	 * Gets the aircraft image from PlanePictures
262
+	 *
263
+	 * @param String $aircraft_registration the registration of the aircraft
264
+	 * @param String $aircraft_name type of the aircraft
265
+	 * @return Array the aircraft thumbnail, orignal url and copyright
266
+	 *
267
+	 */
268 268
 	public function fromPlanePictures($aircraft_registration, $aircraft_name='') {
269 269
 		$Common = new Common();
270 270
 		$url= 'http://www.planepictures.net/netsearch4.cgi?srch='.$aircraft_registration.'&stype=reg&srng=2';
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
 	}
293 293
 
294 294
 	/**
295
-	* Gets the aircraft image from Flickr
296
-	*
297
-	* @param String $aircraft_registration the registration of the aircraft
298
-	* @param String $aircraft_name type of the aircraft
299
-	* @return Array the aircraft thumbnail, orignal url and copyright
300
-	*
301
-	*/
295
+	 * Gets the aircraft image from Flickr
296
+	 *
297
+	 * @param String $aircraft_registration the registration of the aircraft
298
+	 * @param String $aircraft_name type of the aircraft
299
+	 * @return Array the aircraft thumbnail, orignal url and copyright
300
+	 *
301
+	 */
302 302
 	public function fromFlickr($aircraft_registration,$aircraft_name='') {
303 303
 		$Common = new Common();
304 304
 		if ($aircraft_name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name);
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
 	}
337 337
 
338 338
 	/**
339
-	* Gets the aircraft image from Bing
340
-	*
341
-	* @param String $aircraft_registration the registration of the aircraft
342
-	* @param String $aircraft_name type of the aircraft
343
-	* @return Array the aircraft thumbnail, orignal url and copyright
344
-	*
345
-	*/
339
+	 * Gets the aircraft image from Bing
340
+	 *
341
+	 * @param String $aircraft_registration the registration of the aircraft
342
+	 * @param String $aircraft_name type of the aircraft
343
+	 * @return Array the aircraft thumbnail, orignal url and copyright
344
+	 *
345
+	 */
346 346
 	public function fromBing($aircraft_registration,$aircraft_name='') {
347 347
 		global $globalImageBingKey;
348 348
 		$Common = new Common();
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
 	}
369 369
 
370 370
 	/**
371
-	* Gets the aircraft image from airport-data
372
-	*
373
-	* @param String $aircraft_registration the registration of the aircraft
374
-	* @param String $aircraft_name type of the aircraft
375
-	* @return Array the aircraft thumbnail, orignal url and copyright
376
-	*
377
-	*/
371
+	 * Gets the aircraft image from airport-data
372
+	 *
373
+	 * @param String $aircraft_registration the registration of the aircraft
374
+	 * @param String $aircraft_name type of the aircraft
375
+	 * @return Array the aircraft thumbnail, orignal url and copyright
376
+	 *
377
+	 */
378 378
 	public function fromAirportData($aircraft_registration,$aircraft_name='') {
379 379
 		$Common = new Common();
380 380
 		$url = 'http://www.airport-data.com/api/ac_thumb.json?&n=1&r='.$aircraft_registration;
@@ -393,13 +393,13 @@  discard block
 block discarded – undo
393 393
 	}
394 394
 
395 395
 	/**
396
-	* Gets the aircraft image from WikiMedia
397
-	*
398
-	* @param String $aircraft_registration the registration of the aircraft
399
-	* @param String $aircraft_name type of the aircraft
400
-	* @return Array the aircraft thumbnail, orignal url and copyright
401
-	*
402
-	*/
396
+	 * Gets the aircraft image from WikiMedia
397
+	 *
398
+	 * @param String $aircraft_registration the registration of the aircraft
399
+	 * @param String $aircraft_name type of the aircraft
400
+	 * @return Array the aircraft thumbnail, orignal url and copyright
401
+	 *
402
+	 */
403 403
 	public function fromWikimedia($aircraft_registration,$aircraft_name='') {
404 404
 		$Common = new Common();
405 405
 		if ($aircraft_name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name);
@@ -449,13 +449,13 @@  discard block
 block discarded – undo
449 449
 	}
450 450
 
451 451
 	/**
452
-	* Gets the aircraft image from custom url
453
-	*
454
-	* @param String $aircraft_registration the registration of the aircraft
455
-	* @param String $aircraft_name type of the aircraft
456
-	* @return Array the aircraft thumbnail, orignal url and copyright
457
-	*
458
-	*/
452
+	 * Gets the aircraft image from custom url
453
+	 *
454
+	 * @param String $aircraft_registration the registration of the aircraft
455
+	 * @param String $aircraft_name type of the aircraft
456
+	 * @return Array the aircraft thumbnail, orignal url and copyright
457
+	 *
458
+	 */
459 459
 	public function fromCustomSource($aircraft_registration,$aircraft_name='') {
460 460
 		global $globalAircraftCustomSources;
461 461
 		//$globalAircraftImageCustomSource[] = array('thumbnail' => '','original' => '', 'copyright' => '', 'source_website' => '', 'source' => '','exif' => true);
Please login to merge, or discard this patch.
Braces   +126 added lines, -46 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
23 23
 		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
24 24
 		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
25
-		if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao;
25
+		if ($registration == '' && $aircraft_icao != '') {
26
+			$registration = $aircraft_icao.$airline_icao;
27
+		}
26 28
 		$registration = trim($registration);
27 29
 		$query  = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright
28 30
 			FROM spotter_image 
@@ -60,8 +62,11 @@  discard block
 block discarded – undo
60 62
 	public function getExifCopyright($url) {
61 63
 		$exif = exif_read_data($url);
62 64
 		$copyright = '';
63
-		if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright'];
64
-		elseif (isset($exif['copyright'])) $copyright = $exif['copyright'];
65
+		if (isset($exif['COMPUTED']['copyright'])) {
66
+			$copyright = $exif['COMPUTED']['copyright'];
67
+		} elseif (isset($exif['copyright'])) {
68
+			$copyright = $exif['copyright'];
69
+		}
65 70
 		if ($copyright != '') {
66 71
 			$copyright = str_replace('Copyright ','',$copyright);
67 72
 			$copyright = str_replace('© ','',$copyright);
@@ -79,18 +84,29 @@  discard block
 block discarded – undo
79 84
 	public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
80 85
 	{
81 86
 		global $globalDebug,$globalAircraftImageFetch;
82
-		if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return '';
87
+		if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) {
88
+			return '';
89
+		}
83 90
 		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
84 91
 		$registration = trim($registration);
85 92
 		//getting the aircraft image
86
-		if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...';
87
-		elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...';
88
-		elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...';
89
-		else return "success";
93
+		if ($globalDebug && $registration != '') {
94
+			echo 'Try to find an aircraft image for '.$registration.'...';
95
+		} elseif ($globalDebug && $aircraft_icao != '') {
96
+			echo 'Try to find an aircraft image for '.$aircraft_icao.'...';
97
+		} elseif ($globalDebug && $airline_icao != '') {
98
+			echo 'Try to find an aircraft image for '.$airline_icao.'...';
99
+		} else {
100
+			return "success";
101
+		}
90 102
 		$image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao);
91
-		if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao;
103
+		if ($registration == '' && $aircraft_icao != '') {
104
+			$registration = $aircraft_icao.$airline_icao;
105
+		}
92 106
 		if ($image_url['original'] != '') {
93
-			if ($globalDebug) echo 'Found !'."\n";
107
+			if ($globalDebug) {
108
+				echo 'Found !'."\n";
109
+			}
94 110
 			$query  = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)";
95 111
 			try {
96 112
 				$sth = $this->db->prepare($query);
@@ -99,7 +115,9 @@  discard block
 block discarded – undo
99 115
 				echo $e->getMessage()."\n";
100 116
 				return "error";
101 117
 			}
102
-		} elseif ($globalDebug) echo "Not found :'(\n";
118
+		} elseif ($globalDebug) {
119
+			echo "Not found :'(\n";
120
+		}
103 121
 		return "success";
104 122
 	}
105 123
 
@@ -114,36 +132,75 @@  discard block
 block discarded – undo
114 132
 	{
115 133
 		global $globalAircraftImageSources, $globalIVAO;
116 134
 		$Spotter = new Spotter($this->db);
117
-		if (!isset($globalIVAO)) $globalIVAO = FALSE;
135
+		if (!isset($globalIVAO)) {
136
+			$globalIVAO = FALSE;
137
+		}
118 138
 		$aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING);
119 139
 		if ($aircraft_registration != '') {
120
-			if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
140
+			if (strpos($aircraft_registration,'/') !== false) {
141
+				return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
142
+			}
121 143
 			$aircraft_registration = urlencode(trim($aircraft_registration));
122 144
 			$aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration);
123
-			if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name'];
124
-			else $aircraft_name = '';
125
-			if (isset($aircraft_info[0]['aircraft_icao'])) $aircraft_name = $aircraft_info[0]['aircraft_icao'];
126
-			else $aircraft_icao = '';
127
-			if (isset($aircraft_info[0]['airline_icao'])) $airline_icao = $aircraft_info[0]['airline_icao'];
128
-			else $airline_icao = '';
145
+			if (isset($aircraft_info[0]['aircraft_name'])) {
146
+				$aircraft_name = $aircraft_info[0]['aircraft_name'];
147
+			} else {
148
+				$aircraft_name = '';
149
+			}
150
+			if (isset($aircraft_info[0]['aircraft_icao'])) {
151
+				$aircraft_name = $aircraft_info[0]['aircraft_icao'];
152
+			} else {
153
+				$aircraft_icao = '';
154
+			}
155
+			if (isset($aircraft_info[0]['airline_icao'])) {
156
+				$airline_icao = $aircraft_info[0]['airline_icao'];
157
+			} else {
158
+				$airline_icao = '';
159
+			}
129 160
 		} elseif ($aircraft_icao != '') {
130 161
 			$aircraft_registration = $aircraft_icao;
131 162
 			$aircraft_name = '';
132
-		} else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
133
-		if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
163
+		} else {
164
+			return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
165
+		}
166
+		if (!isset($globalAircraftImageSources)) {
167
+			$globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
168
+		}
134 169
 		foreach ($globalAircraftImageSources as $source) {
135 170
 			$source = strtolower($source);
136
-			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl($aircraft_icao,$airline_icao);
137
-			if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters($aircraft_registration,$aircraft_name);
138
-			if ($source == 'flickr') $images_array = $this->fromFlickr($aircraft_registration,$aircraft_name);
139
-			if ($source == 'bing') $images_array = $this->fromBing($aircraft_registration,$aircraft_name);
140
-			if ($source == 'deviantart') $images_array = $this->fromDeviantart($aircraft_registration,$aircraft_name);
141
-			if ($source == 'wikimedia') $images_array = $this->fromWikimedia($aircraft_registration,$aircraft_name);
142
-			if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos($aircraft_registration,$aircraft_name);
143
-			if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures($aircraft_registration,$aircraft_name);
144
-			if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData($aircraft_registration,$aircraft_name);
145
-			if ($source == 'customsources') $images_array = $this->fromCustomSource($aircraft_registration,$aircraft_name);
146
-			if (isset($images_array) && $images_array['original'] != '') return $images_array;
171
+			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') {
172
+				$images_array = $this->fromIvaoMtl($aircraft_icao,$airline_icao);
173
+			}
174
+			if ($source == 'planespotters' && !$globalIVAO) {
175
+				$images_array = $this->fromPlanespotters($aircraft_registration,$aircraft_name);
176
+			}
177
+			if ($source == 'flickr') {
178
+				$images_array = $this->fromFlickr($aircraft_registration,$aircraft_name);
179
+			}
180
+			if ($source == 'bing') {
181
+				$images_array = $this->fromBing($aircraft_registration,$aircraft_name);
182
+			}
183
+			if ($source == 'deviantart') {
184
+				$images_array = $this->fromDeviantart($aircraft_registration,$aircraft_name);
185
+			}
186
+			if ($source == 'wikimedia') {
187
+				$images_array = $this->fromWikimedia($aircraft_registration,$aircraft_name);
188
+			}
189
+			if ($source == 'jetphotos' && !$globalIVAO) {
190
+				$images_array = $this->fromJetPhotos($aircraft_registration,$aircraft_name);
191
+			}
192
+			if ($source == 'planepictures' && !$globalIVAO) {
193
+				$images_array = $this->fromPlanePictures($aircraft_registration,$aircraft_name);
194
+			}
195
+			if ($source == 'airportdata' && !$globalIVAO) {
196
+				$images_array = $this->fromAirportData($aircraft_registration,$aircraft_name);
197
+			}
198
+			if ($source == 'customsources') {
199
+				$images_array = $this->fromCustomSource($aircraft_registration,$aircraft_name);
200
+			}
201
+			if (isset($images_array) && $images_array['original'] != '') {
202
+				return $images_array;
203
+			}
147 204
 		}
148 205
 		return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
149 206
 	}
@@ -301,8 +358,11 @@  discard block
 block discarded – undo
301 358
 	*/
302 359
 	public function fromFlickr($aircraft_registration,$aircraft_name='') {
303 360
 		$Common = new Common();
304
-		if ($aircraft_name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name);
305
-		else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.',aircraft';
361
+		if ($aircraft_name != '') {
362
+			$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name);
363
+		} else {
364
+			$url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.',aircraft';
365
+		}
306 366
 		$data = $Common->getData($url);
307 367
 		if ($xml = simplexml_load_string($data)) {
308 368
 			if (isset($xml->channel->item)) {
@@ -346,9 +406,14 @@  discard block
 block discarded – undo
346 406
 	public function fromBing($aircraft_registration,$aircraft_name='') {
347 407
 		global $globalImageBingKey;
348 408
 		$Common = new Common();
349
-		if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false;
350
-		if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27';
351
-		else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27';
409
+		if (!isset($globalImageBingKey) || $globalImageBingKey == '') {
410
+			return false;
411
+		}
412
+		if ($aircraft_name != '') {
413
+			$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27';
414
+		} else {
415
+			$url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27';
416
+		}
352 417
 		$headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey));
353 418
 		$data = $Common->getData($url,'get','',$headers);
354 419
 		$result = json_decode($data);
@@ -402,13 +467,18 @@  discard block
 block discarded – undo
402 467
 	*/
403 468
 	public function fromWikimedia($aircraft_registration,$aircraft_name='') {
404 469
 		$Common = new Common();
405
-		if ($aircraft_name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name);
406
-		else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20aircraft';
470
+		if ($aircraft_name != '') {
471
+			$url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name);
472
+		} else {
473
+			$url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20aircraft';
474
+		}
407 475
 		$data = $Common->getData($url);
408 476
 		$result = json_decode($data);
409 477
 		if (isset($result->query->search[0]->title)) {
410 478
 			$fileo = $result->query->search[0]->title;
411
-			if (substr($fileo,-3) == 'pdf') return false;
479
+			if (substr($fileo,-3) == 'pdf') {
480
+				return false;
481
+			}
412 482
 			$file = urlencode($fileo);
413 483
 			$url2 = 'https://commons.wikimedia.org/w/api.php?action=query&format=json&continue&iilimit=500&prop=imageinfo&iiprop=user|url|size|mime|sha1|timestamp&iiurlwidth=200%27&titles='.$file;
414 484
 			$data2 = $Common->getData($url2);
@@ -460,7 +530,9 @@  discard block
 block discarded – undo
460 530
 		global $globalAircraftCustomSources;
461 531
 		//$globalAircraftImageCustomSource[] = array('thumbnail' => '','original' => '', 'copyright' => '', 'source_website' => '', 'source' => '','exif' => true);
462 532
 		if (!empty($globalAircraftImageCustomSources)) {
463
-			if (!isset($globalAircraftImageCustomSources[0])) $globalAircraftImageCustomSources[] = $globalAircraftImageCustomSources;
533
+			if (!isset($globalAircraftImageCustomSources[0])) {
534
+				$globalAircraftImageCustomSources[] = $globalAircraftImageCustomSources;
535
+			}
464 536
 			foreach ($globalAircraftImageCustomSources as $source) {
465 537
 				$Common = new Common();
466 538
 				$url = str_replace('{registration}',$aircraft_registration,$source['original']);
@@ -469,17 +541,25 @@  discard block
 block discarded – undo
469 541
 					$image_url = array();
470 542
 					$image_url['thumbnail'] = $url_thumbnail;
471 543
 					$image_url['original'] = $url;
472
-					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url);
473
-					else $exifCopyright = '';
474
-					if ($exifCopyright  != '') $image_url['copyright'] = $exifCopyright;
475
-					else $image_url['copyright'] = $source['copyright'];
544
+					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) {
545
+						$exifCopyright = $this->getExifCopyright($url);
546
+					} else {
547
+						$exifCopyright = '';
548
+					}
549
+					if ($exifCopyright  != '') {
550
+						$image_url['copyright'] = $exifCopyright;
551
+					} else {
552
+						$image_url['copyright'] = $source['copyright'];
553
+					}
476 554
 					$image_url['source_website'] = $source['source_website'];
477 555
 					$image_url['source'] = $source['source'];
478 556
 					return $image_url;
479 557
 				}
480 558
 			}
481 559
 			return false;
482
-		} else return false;
560
+		} else {
561
+			return false;
562
+		}
483 563
 	}
484 564
 }
485 565
 
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
 	* @return Array the images list
18 18
 	*
19 19
 	*/
20
-	public function getSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
20
+	public function getSpotterImage($registration, $aircraft_icao = '', $airline_icao = '')
21 21
 	{
22
-		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
23
-		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
24
-		$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING);
22
+		$registration = filter_var($registration, FILTER_SANITIZE_STRING);
23
+		$aircraft_icao = filter_var($aircraft_icao, FILTER_SANITIZE_STRING);
24
+		$airline_icao = filter_var($airline_icao, FILTER_SANITIZE_STRING);
25 25
 		if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao;
26 26
 		$registration = trim($registration);
27
-		$query  = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright, spotter_image.registration 
27
+		$query = "SELECT spotter_image.image, spotter_image.image_thumbnail, spotter_image.image_source, spotter_image.image_source_website,spotter_image.image_copyright, spotter_image.registration 
28 28
 			FROM spotter_image 
29 29
 			WHERE spotter_image.registration = :registration";
30 30
 		$sth = $this->db->prepare($query);
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 		if (isset($exif['COMPUTED']['copyright'])) $copyright = $exif['COMPUTED']['copyright'];
64 64
 		elseif (isset($exif['copyright'])) $copyright = $exif['copyright'];
65 65
 		if ($copyright != '') {
66
-			$copyright = str_replace('Copyright ','',$copyright);
67
-			$copyright = str_replace('© ','',$copyright);
68
-			$copyright = str_replace('(c) ','',$copyright);
66
+			$copyright = str_replace('Copyright ', '', $copyright);
67
+			$copyright = str_replace('© ', '', $copyright);
68
+			$copyright = str_replace('(c) ', '', $copyright);
69 69
 		}
70 70
 		return $copyright;
71 71
 	}
@@ -76,26 +76,26 @@  discard block
 block discarded – undo
76 76
 	* @return String either success or error
77 77
 	*
78 78
 	*/
79
-	public function addSpotterImage($registration,$aircraft_icao = '', $airline_icao = '')
79
+	public function addSpotterImage($registration, $aircraft_icao = '', $airline_icao = '')
80 80
 	{
81
-		global $globalDebug,$globalAircraftImageFetch;
81
+		global $globalDebug, $globalAircraftImageFetch;
82 82
 		if (isset($globalAircraftImageFetch) && !$globalAircraftImageFetch) return '';
83
-		$registration = filter_var($registration,FILTER_SANITIZE_STRING);
83
+		$registration = filter_var($registration, FILTER_SANITIZE_STRING);
84 84
 		$registration = trim($registration);
85 85
 		//getting the aircraft image
86 86
 		if ($globalDebug && $registration != '') echo 'Try to find an aircraft image for '.$registration.'...';
87 87
 		elseif ($globalDebug && $aircraft_icao != '') echo 'Try to find an aircraft image for '.$aircraft_icao.'...';
88 88
 		elseif ($globalDebug && $airline_icao != '') echo 'Try to find an aircraft image for '.$airline_icao.'...';
89 89
 		else return "success";
90
-		$image_url = $this->findAircraftImage($registration,$aircraft_icao,$airline_icao);
90
+		$image_url = $this->findAircraftImage($registration, $aircraft_icao, $airline_icao);
91 91
 		if ($registration == '' && $aircraft_icao != '') $registration = $aircraft_icao.$airline_icao;
92 92
 		if ($image_url['original'] != '') {
93 93
 			if ($globalDebug) echo 'Found !'."\n";
94
-			$query  = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)";
94
+			$query = "INSERT INTO spotter_image (registration, image, image_thumbnail, image_copyright, image_source,image_source_website) VALUES (:registration,:image,:image_thumbnail,:copyright,:source,:source_website)";
95 95
 			try {
96 96
 				$sth = $this->db->prepare($query);
97
-				$sth->execute(array(':registration' => $registration,':image' => $image_url['original'],':image_thumbnail' => $image_url['thumbnail'], ':copyright' => $image_url['copyright'],':source' => $image_url['source'],':source_website' => $image_url['source_website']));
98
-			} catch(PDOException $e) {
97
+				$sth->execute(array(':registration' => $registration, ':image' => $image_url['original'], ':image_thumbnail' => $image_url['thumbnail'], ':copyright' => $image_url['copyright'], ':source' => $image_url['source'], ':source_website' => $image_url['source_website']));
98
+			} catch (PDOException $e) {
99 99
 				echo $e->getMessage()."\n";
100 100
 				return "error";
101 101
 			}
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 		global $globalAircraftImageSources, $globalIVAO;
116 116
 		$Spotter = new Spotter($this->db);
117 117
 		if (!isset($globalIVAO)) $globalIVAO = FALSE;
118
-		$aircraft_registration = filter_var($aircraft_registration,FILTER_SANITIZE_STRING);
118
+		$aircraft_registration = filter_var($aircraft_registration, FILTER_SANITIZE_STRING);
119 119
 		if ($aircraft_registration != '') {
120
-			if (strpos($aircraft_registration,'/') !== false) return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
120
+			if (strpos($aircraft_registration, '/') !== false) return array('thumbnail' => '', 'original' => '', 'copyright' => '', 'source' => '', 'source_website' => '');
121 121
 			$aircraft_registration = urlencode(trim($aircraft_registration));
122 122
 			$aircraft_info = $Spotter->getAircraftInfoByRegistration($aircraft_registration);
123 123
 			if (isset($aircraft_info[0]['aircraft_name'])) $aircraft_name = $aircraft_info[0]['aircraft_name'];
@@ -129,23 +129,23 @@  discard block
 block discarded – undo
129 129
 		} elseif ($aircraft_icao != '') {
130 130
 			$aircraft_registration = $aircraft_icao;
131 131
 			$aircraft_name = '';
132
-		} else return array('thumbnail' => '','original' => '', 'copyright' => '', 'source' => '','source_website' => '');
133
-		if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
132
+		} else return array('thumbnail' => '', 'original' => '', 'copyright' => '', 'source' => '', 'source_website' => '');
133
+		if (!isset($globalAircraftImageSources)) $globalAircraftImageSources = array('ivaomtl', 'wikimedia', 'airportdata', 'deviantart', 'flickr', 'bing', 'jetphotos', 'planepictures', 'planespotters');
134 134
 		foreach ($globalAircraftImageSources as $source) {
135 135
 			$source = strtolower($source);
136
-			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl($aircraft_icao,$airline_icao);
137
-			if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters($aircraft_registration,$aircraft_name);
138
-			if ($source == 'flickr') $images_array = $this->fromFlickr($aircraft_registration,$aircraft_name);
139
-			if ($source == 'bing') $images_array = $this->fromBing($aircraft_registration,$aircraft_name);
140
-			if ($source == 'deviantart') $images_array = $this->fromDeviantart($aircraft_registration,$aircraft_name);
141
-			if ($source == 'wikimedia') $images_array = $this->fromWikimedia($aircraft_registration,$aircraft_name);
142
-			if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos($aircraft_registration,$aircraft_name);
143
-			if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures($aircraft_registration,$aircraft_name);
144
-			if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData($aircraft_registration,$aircraft_name);
145
-			if ($source == 'customsources') $images_array = $this->fromCustomSource($aircraft_registration,$aircraft_name);
136
+			if ($source == 'ivaomtl' && $globalIVAO && $aircraft_icao != '' && $airline_icao != '') $images_array = $this->fromIvaoMtl($aircraft_icao, $airline_icao);
137
+			if ($source == 'planespotters' && !$globalIVAO) $images_array = $this->fromPlanespotters($aircraft_registration, $aircraft_name);
138
+			if ($source == 'flickr') $images_array = $this->fromFlickr($aircraft_registration, $aircraft_name);
139
+			if ($source == 'bing') $images_array = $this->fromBing($aircraft_registration, $aircraft_name);
140
+			if ($source == 'deviantart') $images_array = $this->fromDeviantart($aircraft_registration, $aircraft_name);
141
+			if ($source == 'wikimedia') $images_array = $this->fromWikimedia($aircraft_registration, $aircraft_name);
142
+			if ($source == 'jetphotos' && !$globalIVAO) $images_array = $this->fromJetPhotos($aircraft_registration, $aircraft_name);
143
+			if ($source == 'planepictures' && !$globalIVAO) $images_array = $this->fromPlanePictures($aircraft_registration, $aircraft_name);
144
+			if ($source == 'airportdata' && !$globalIVAO) $images_array = $this->fromAirportData($aircraft_registration, $aircraft_name);
145
+			if ($source == 'customsources') $images_array = $this->fromCustomSource($aircraft_registration, $aircraft_name);
146 146
 			if (isset($images_array) && $images_array['original'] != '') return $images_array;
147 147
 		}
148
-		return array('thumbnail' => '','original' => '', 'copyright' => '','source' => '','source_website' => '');
148
+		return array('thumbnail' => '', 'original' => '', 'copyright' => '', 'source' => '', 'source_website' => '');
149 149
 	}
150 150
 
151 151
 	/**
@@ -156,24 +156,24 @@  discard block
 block discarded – undo
156 156
 	* @return Array the aircraft thumbnail, orignal url and copyright
157 157
 	*
158 158
 	*/
159
-	public function fromPlanespotters($aircraft_registration, $aircraft_name='') {
159
+	public function fromPlanespotters($aircraft_registration, $aircraft_name = '') {
160 160
 		$Common = new Common();
161 161
 		// If aircraft registration is only number, also check with aircraft model
162
-		if (preg_match('/^[[:digit]]+$/',$aircraft_registration) && $aircraft_name != '') {
163
-			$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$aircraft_registration.'&actype=s_'.urlencode($aircraft_name).'&output=rss';
162
+		if (preg_match('/^[[:digit]]+$/', $aircraft_registration) && $aircraft_name != '') {
163
+			$url = 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$aircraft_registration.'&actype=s_'.urlencode($aircraft_name).'&output=rss';
164 164
 		} else {
165 165
 			//$url= 'http://www.planespotters.net/Aviation_Photos/search.php?tag='.$airline_aircraft_type.'&output=rss';
166
-			$url= 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss';
166
+			$url = 'http://www.planespotters.net/Aviation_Photos/search.php?reg='.$aircraft_registration.'&output=rss';
167 167
 		}
168 168
 		$data = $Common->getData($url);
169 169
 		if ($xml = simplexml_load_string($data)) {
170 170
 			if (isset($xml->channel->item)) {
171 171
 				$image_url = array();
172
-				$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url);
172
+				$thumbnail_url = trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url);
173 173
 				$image_url['thumbnail'] = $thumbnail_url;
174
-				$image_url['original'] = str_replace('thumbnail','original',$thumbnail_url);
175
-				$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright);
176
-				$image_url['source_website'] = trim((string)$xml->channel->item->link);
174
+				$image_url['original'] = str_replace('thumbnail', 'original', $thumbnail_url);
175
+				$image_url['copyright'] = trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright);
176
+				$image_url['source_website'] = trim((string) $xml->channel->item->link);
177 177
 				$image_url['source'] = 'planespotters';
178 178
 				return $image_url;
179 179
 			}
@@ -189,25 +189,25 @@  discard block
 block discarded – undo
189 189
 	* @return Array the aircraft thumbnail, orignal url and copyright
190 190
 	*
191 191
 	*/
192
-	public function fromDeviantart($aircraft_registration, $aircraft_name='') {
192
+	public function fromDeviantart($aircraft_registration, $aircraft_name = '') {
193 193
 		$Common = new Common();
194 194
 		// If aircraft registration is only number, also check with aircraft model
195
-		if (preg_match('/^[[:digit]]+$/',$aircraft_registration) && $aircraft_name != '') {
196
-			$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q='.$aircraft_registration.'%20'.urlencode($aircraft_name);
195
+		if (preg_match('/^[[:digit]]+$/', $aircraft_registration) && $aircraft_name != '') {
196
+			$url = 'http://backend.deviantart.com/rss.xml?type=deviation&q='.$aircraft_registration.'%20'.urlencode($aircraft_name);
197 197
 		} else {
198
-			$url= 'http://backend.deviantart.com/rss.xml?type=deviation&q=aircraft%20'.$aircraft_registration;
198
+			$url = 'http://backend.deviantart.com/rss.xml?type=deviation&q=aircraft%20'.$aircraft_registration;
199 199
 		}
200 200
 
201 201
 		$data = $Common->getData($url);
202 202
 		if ($xml = simplexml_load_string($data)) {
203 203
 			if (isset($xml->channel->item->link)) {
204 204
 				$image_url = array();
205
-				$thumbnail_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url);
205
+				$thumbnail_url = trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url);
206 206
 				$image_url['thumbnail'] = $thumbnail_url;
207
-				$original_url = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->content->attributes()->url);
207
+				$original_url = trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->content->attributes()->url);
208 208
 				$image_url['original'] = $original_url;
209
-				$image_url['copyright'] = str_replace('Copyright ','',trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright));
210
-				$image_url['source_website'] = trim((string)$xml->channel->item->link);
209
+				$image_url['copyright'] = str_replace('Copyright ', '', trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->copyright));
210
+				$image_url['source_website'] = trim((string) $xml->channel->item->link);
211 211
 				$image_url['source'] = 'deviantart';
212 212
 				return $image_url;
213 213
 			}
@@ -223,32 +223,32 @@  discard block
 block discarded – undo
223 223
 	* @return Array the aircraft thumbnail, orignal url and copyright
224 224
 	*
225 225
 	*/
226
-	public function fromJetPhotos($aircraft_registration, $aircraft_name='') {
226
+	public function fromJetPhotos($aircraft_registration, $aircraft_name = '') {
227 227
 		$Common = new Common();
228
-		$url= 'http://jetphotos.net/showphotos.php?displaymode=2&regsearch='.$aircraft_registration;
228
+		$url = 'http://jetphotos.net/showphotos.php?displaymode=2&regsearch='.$aircraft_registration;
229 229
 		$data = $Common->getData($url);
230 230
 		$dom = new DOMDocument();
231 231
 		@$dom->loadHTML($data);
232 232
 		$all_pics = array();
233
-		foreach($dom->getElementsByTagName('img') as $image) {
233
+		foreach ($dom->getElementsByTagName('img') as $image) {
234 234
 			if ($image->getAttribute('itemprop') == "http://schema.org/image") {
235 235
 				$all_pics[] = $image->getAttribute('src');
236 236
 			}
237 237
 		}
238 238
 		$all_authors = array();
239
-		foreach($dom->getElementsByTagName('meta') as $author) {
239
+		foreach ($dom->getElementsByTagName('meta') as $author) {
240 240
 			if ($author->getAttribute('itemprop') == "http://schema.org/author") {
241 241
 				$all_authors[] = $author->getAttribute('content');
242 242
 			}
243 243
 		}
244 244
 		$all_ref = array();
245
-		foreach($dom->getElementsByTagName('a') as $link) {
245
+		foreach ($dom->getElementsByTagName('a') as $link) {
246 246
 			$all_ref[] = $link->getAttribute('href');
247 247
 		}
248 248
 		if (isset($all_pics[0])) {
249 249
 			$image_url = array();
250 250
 			$image_url['thumbnail'] = $all_pics[0];
251
-			$image_url['original'] = str_replace('_tb','',$all_pics[0]);
251
+			$image_url['original'] = str_replace('_tb', '', $all_pics[0]);
252 252
 			$image_url['copyright'] = $all_authors[0];
253 253
 			$image_url['source_website'] = 'http://jetphotos.net'.$all_ref[8];
254 254
 			$image_url['source'] = 'JetPhotos';
@@ -265,24 +265,24 @@  discard block
 block discarded – undo
265 265
 	* @return Array the aircraft thumbnail, orignal url and copyright
266 266
 	*
267 267
 	*/
268
-	public function fromPlanePictures($aircraft_registration, $aircraft_name='') {
268
+	public function fromPlanePictures($aircraft_registration, $aircraft_name = '') {
269 269
 		$Common = new Common();
270
-		$url= 'http://www.planepictures.net/netsearch4.cgi?srch='.$aircraft_registration.'&stype=reg&srng=2';
270
+		$url = 'http://www.planepictures.net/netsearch4.cgi?srch='.$aircraft_registration.'&stype=reg&srng=2';
271 271
 		$data = $Common->getData($url);
272 272
 		$dom = new DOMDocument();
273 273
 		@$dom->loadHTML($data);
274 274
 		$all_pics = array();
275
-		foreach($dom->getElementsByTagName('img') as $image) {
275
+		foreach ($dom->getElementsByTagName('img') as $image) {
276 276
 			$all_pics[] = $image->getAttribute('src');
277 277
 		}
278 278
 		$all_links = array();
279
-		foreach($dom->getElementsByTagName('a') as $link) {
280
-			$all_links[] = array('text' => $link->textContent,'href' => $link->getAttribute('href'));
279
+		foreach ($dom->getElementsByTagName('a') as $link) {
280
+			$all_links[] = array('text' => $link->textContent, 'href' => $link->getAttribute('href'));
281 281
 		}
282
-		if (isset($all_pics[1]) && !preg_match('/bit.ly/',$all_pics[1])) {
282
+		if (isset($all_pics[1]) && !preg_match('/bit.ly/', $all_pics[1])) {
283 283
 			$image_url = array();
284 284
 			$image_url['thumbnail'] = 'http://www.planepictures.net'.$all_pics[1];
285
-			$image_url['original'] = 'http://www.planepictures.net'.str_replace('_TN','',$all_pics[1]);
285
+			$image_url['original'] = 'http://www.planepictures.net'.str_replace('_TN', '', $all_pics[1]);
286 286
 			$image_url['copyright'] = $all_links[6]['text'];
287 287
 			$image_url['source_website'] = 'http://www.planepictures.net/'.$all_links[2]['href'];
288 288
 			$image_url['source'] = 'PlanePictures';
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
 	* @return Array the aircraft thumbnail, orignal url and copyright
300 300
 	*
301 301
 	*/
302
-	public function fromFlickr($aircraft_registration,$aircraft_name='') {
302
+	public function fromFlickr($aircraft_registration, $aircraft_name = '') {
303 303
 		$Common = new Common();
304 304
 		if ($aircraft_name != '') $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.','.urlencode($aircraft_name);
305 305
 		else $url = 'https://api.flickr.com/services/feeds/photos_public.gne?format=rss2&license=1,2,3,4,5,6,7&per_page=1&tags='.$aircraft_registration.',aircraft';
306 306
 		$data = $Common->getData($url);
307 307
 		if ($xml = simplexml_load_string($data)) {
308 308
 			if (isset($xml->channel->item)) {
309
-				$original_url = trim((string)$xml->channel->item->enclosure->attributes()->url);
309
+				$original_url = trim((string) $xml->channel->item->enclosure->attributes()->url);
310 310
 				$image_url = array();
311 311
 				$image_url['thumbnail'] = $original_url;
312 312
 				$image_url['original'] = $original_url;
313
-				$image_url['copyright'] = trim((string)$xml->channel->item->children('http://search.yahoo.com/mrss/')->credit);
314
-				$image_url['source_website'] = trim((string)$xml->channel->item->link);
313
+				$image_url['copyright'] = trim((string) $xml->channel->item->children('http://search.yahoo.com/mrss/')->credit);
314
+				$image_url['source_website'] = trim((string) $xml->channel->item->link);
315 315
 				$image_url['source'] = 'flickr';
316 316
 				return $image_url;
317 317
 			}
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		return false;
320 320
 	}
321 321
 
322
-	public function fromIvaoMtl($aircraft_icao,$airline_icao) {
322
+	public function fromIvaoMtl($aircraft_icao, $airline_icao) {
323 323
 		$Common = new Common();
324 324
 		//echo "\n".'SEARCH IMAGE : http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg';
325 325
 		if ($Common->urlexist('http://mtlcatalog.ivao.aero/images/aircraft/'.$aircraft_icao.$airline_icao.'.jpg')) {
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
 	* @return Array the aircraft thumbnail, orignal url and copyright
344 344
 	*
345 345
 	*/
346
-	public function fromBing($aircraft_registration,$aircraft_name='') {
346
+	public function fromBing($aircraft_registration, $aircraft_name = '') {
347 347
 		global $globalImageBingKey;
348 348
 		$Common = new Common();
349 349
 		if (!isset($globalImageBingKey) || $globalImageBingKey == '') return false;
350 350
 		if ($aircraft_name != '') $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27'.$aircraft_registration.'%20'.urlencode($aircraft_name).'%20-site:planespotters.com%20-site:flickr.com%27';
351 351
 		else $url = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&$top=1&Query=%27%2B'.$aircraft_registration.'%20%2Baircraft%20-site:planespotters.com%20-site:flickr.com%27';
352
-		$headers = array("Authorization: Basic " . base64_encode("ignored:".$globalImageBingKey));
353
-		$data = $Common->getData($url,'get','',$headers);
352
+		$headers = array("Authorization: Basic ".base64_encode("ignored:".$globalImageBingKey));
353
+		$data = $Common->getData($url, 'get', '', $headers);
354 354
 		$result = json_decode($data);
355 355
 		if (isset($result->d->results[0]->MediaUrl)) {
356 356
 			$image_url = array();
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 	* @return Array the aircraft thumbnail, orignal url and copyright
376 376
 	*
377 377
 	*/
378
-	public function fromAirportData($aircraft_registration,$aircraft_name='') {
378
+	public function fromAirportData($aircraft_registration, $aircraft_name = '') {
379 379
 		$Common = new Common();
380 380
 		$url = 'http://www.airport-data.com/api/ac_thumb.json?&n=1&r='.$aircraft_registration;
381 381
 		$data = $Common->getData($url);
382 382
 		$result = json_decode($data);
383 383
 		if (isset($result->count) && $result->count > 0) {
384 384
 			$image_url = array();
385
-			$image_url['original'] = str_replace('thumbnails','large',$result->data[0]->image);
385
+			$image_url['original'] = str_replace('thumbnails', 'large', $result->data[0]->image);
386 386
 			$image_url['source_website'] = $result->data[0]->link;
387 387
 			$image_url['thumbnail'] = $result->data[0]->image;
388 388
 			$image_url['copyright'] = $result->data[0]->photographer;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	* @return Array the aircraft thumbnail, orignal url and copyright
401 401
 	*
402 402
 	*/
403
-	public function fromWikimedia($aircraft_registration,$aircraft_name='') {
403
+	public function fromWikimedia($aircraft_registration, $aircraft_name = '') {
404 404
 		$Common = new Common();
405 405
 		if ($aircraft_name != '') $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20'.urlencode($aircraft_name);
406 406
 		else $url = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srlimit=1&srnamespace=6&continue&srsearch="'.$aircraft_registration.'"%20aircraft';
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		$result = json_decode($data);
409 409
 		if (isset($result->query->search[0]->title)) {
410 410
 			$fileo = $result->query->search[0]->title;
411
-			if (substr($fileo,-3) == 'pdf') return false;
411
+			if (substr($fileo, -3) == 'pdf') return false;
412 412
 			$file = urlencode($fileo);
413 413
 			$url2 = 'https://commons.wikimedia.org/w/api.php?action=query&format=json&continue&iilimit=500&prop=imageinfo&iiprop=user|url|size|mime|sha1|timestamp&iiurlwidth=200%27&titles='.$file;
414 414
 			$data2 = $Common->getData($url2);
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
 				if (isset($result2->query->pages)) {
434 434
 					foreach ($result2->query->pages as $page) {
435 435
 						if (isset($page->imageinfo[0]->extmetadata->Artist)) {
436
-							$image_url['copyright'] = preg_replace('/ from(.*)/','',strip_tags($page->imageinfo[0]->extmetadata->Artist->value));
436
+							$image_url['copyright'] = preg_replace('/ from(.*)/', '', strip_tags($page->imageinfo[0]->extmetadata->Artist->value));
437 437
 							if (isset($page->imageinfo[0]->extmetadata->License->value)) {
438 438
 								$image_url['copyright'] = $image_url['copyright'].' (under '.$page->imageinfo[0]->extmetadata->License->value.')';
439 439
 							}
440
-							$image_url['copyright'] = trim(str_replace('\n','',$image_url['copyright']));
440
+							$image_url['copyright'] = trim(str_replace('\n', '', $image_url['copyright']));
441 441
 							return $image_url;
442 442
 						}
443 443
 					}
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 	* @return Array the aircraft thumbnail, orignal url and copyright
457 457
 	*
458 458
 	*/
459
-	public function fromCustomSource($aircraft_registration,$aircraft_name='') {
459
+	public function fromCustomSource($aircraft_registration, $aircraft_name = '') {
460 460
 		global $globalAircraftImageCustomSources;
461 461
 		//$globalAircraftImageCustomSource[] = array('thumbnail' => '','original' => '', 'copyright' => '', 'source_website' => '', 'source' => '','exif' => true);
462 462
 		if (!empty($globalAircraftImageCustomSources)) {
463 463
 			if (!isset($globalAircraftImageCustomSources[0])) $globalAircraftImageCustomSources[] = $globalAircraftImageCustomSources;
464 464
 			foreach ($globalAircraftImageCustomSources as $source) {
465 465
 				$Common = new Common();
466
-				$url = str_replace('{registration}',$aircraft_registration,$source['original']);
467
-				$url_thumbnail = str_replace('{registration}',$aircraft_registration,$source['original']);
466
+				$url = str_replace('{registration}', $aircraft_registration, $source['original']);
467
+				$url_thumbnail = str_replace('{registration}', $aircraft_registration, $source['original']);
468 468
 				if ($Common->urlexist($url)) {
469 469
 					$image_url = array();
470 470
 					$image_url['thumbnail'] = $url_thumbnail;
471 471
 					$image_url['original'] = $url;
472 472
 					if ($source['exif'] && exif_imagetype($url) == IMAGETYPE_JPEG) $exifCopyright = $this->getExifCopyright($url);
473 473
 					else $exifCopyright = '';
474
-					if ($exifCopyright  != '') $image_url['copyright'] = $exifCopyright;
474
+					if ($exifCopyright != '') $image_url['copyright'] = $exifCopyright;
475 475
 					else $image_url['copyright'] = $source['copyright'];
476 476
 					$image_url['source_website'] = $source['source_website'];
477 477
 					$image_url['source'] = $source['source'];
Please login to merge, or discard this patch.
require/class.METAR.php 3 patches
Braces   +94 added lines, -36 removed lines patch added patch discarded remove patch
@@ -58,8 +58,11 @@  discard block
 block discarded – undo
58 58
                         return "error : ".$e->getMessage();
59 59
                 }
60 60
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
61
-                if ($row['nb'] > 0) return false;
62
-                else return true;
61
+                if ($row['nb'] > 0) {
62
+                	return false;
63
+                } else {
64
+                	return true;
65
+                }
63 66
         }
64 67
 
65 68
         public static function insert_last_update() {
@@ -83,9 +86,14 @@  discard block
 block discarded – undo
83 86
     		//$pieces = explode(' ',$data);
84 87
     		$pieces = preg_split('/\s/',$data);
85 88
     		$pos = 0;
86
-    		if ($pieces[0] == 'METAR') $pos++;
87
-    		elseif ($pieces[0] == 'SPECI') $pos++;
88
-    		if (strlen($pieces[$pos]) != 4) $pos++;
89
+    		if ($pieces[0] == 'METAR') {
90
+    			$pos++;
91
+    		} elseif ($pieces[0] == 'SPECI') {
92
+    			$pos++;
93
+    		}
94
+    		if (strlen($pieces[$pos]) != 4) {
95
+    			$pos++;
96
+    		}
89 97
     		$result = array();
90 98
     		$result['location'] = $pieces[$pos];
91 99
     		$pos++;
@@ -94,16 +102,26 @@  discard block
 block discarded – undo
94 102
     		$c = count($pieces);
95 103
     		for($pos++; $pos < $c; $pos++) {
96 104
     			$piece = $pieces[$pos];
97
-    			if ($piece == 'RMK') break;
98
-    			if ($piece == 'AUTO') $result['auto'] = true;
99
-    			if ($piece == 'COR') $result['correction'] = true;
105
+    			if ($piece == 'RMK') {
106
+    				break;
107
+    			}
108
+    			if ($piece == 'AUTO') {
109
+    				$result['auto'] = true;
110
+    			}
111
+    			if ($piece == 'COR') {
112
+    				$result['correction'] = true;
113
+    			}
100 114
     			// Wind Speed
101 115
     			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
102 116
     				$result['wind']['direction'] = (float)$matches[1];
103 117
 				$result['wind']['unit'] = $matches[4];
104
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
105
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
106
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
118
+    				if ($result['wind']['unit'] == 'KT') {
119
+    					$result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
120
+    				} elseif ($result['wind']['unit'] == 'KPH') {
121
+    					$result['wind']['speed'] = round(((float)$matches[2])*1000,2);
122
+    				} elseif ($result['wind']['unit'] == 'MPS') {
123
+    					$result['wind']['speed'] = round(((float)$matches[2]),2);
124
+    				}
107 125
 				$result['wind']['gust'] = (float)$matches[3];
108 126
 				$result['wind']['unit'] = $matches[4];
109 127
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
@@ -185,14 +203,23 @@  discard block
 block discarded – undo
185 203
     				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
186 204
     				$type = $matches[1];
187 205
     				$cloud = array();
188
-    				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
189
-    				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
190
-    				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
191
-    				elseif ($type == 'FEW') $cloud['type'] = 'Few';
192
-    				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
193
-    				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
194
-    				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
195
-    				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
206
+    				if ($type == 'SKC') {
207
+    					$cloud['type'] = 'No cloud/Sky clear';
208
+    				} elseif ($type == 'CLR') {
209
+    					$cloud['type'] = 'No cloud below 12,000ft (3700m)';
210
+    				} elseif ($type == 'NSC') {
211
+    					$cloud['type'] = 'No significant cloud';
212
+    				} elseif ($type == 'FEW') {
213
+    					$cloud['type'] = 'Few';
214
+    				} elseif ($type == 'SCT') {
215
+    					$cloud['type'] = 'Scattered';
216
+    				} elseif ($type == 'BKN') {
217
+    					$cloud['type'] = 'Broken';
218
+    				} elseif ($type == 'OVC') {
219
+    					$cloud['type'] = 'Overcast/Full cloud coverage';
220
+    				} elseif ($type == 'VV') {
221
+    					$cloud['type'] = 'Vertical visibility';
222
+    				}
196 223
     				$cloud['type_code'] = $type;
197 224
     				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
198 225
     				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
@@ -222,8 +249,11 @@  discard block
 block discarded – undo
222 249
     			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
223 250
     				//echo $piece;
224 251
     				//print_r($matches);
225
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
226
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
252
+    				if (isset($matches[5])) {
253
+    					$range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
254
+    				} else {
255
+    					$range = array('exact' => (float)$matches[2], 'unit' => 'M');
256
+    				}
227 257
 				if (isset($matches[3])) {
228 258
 					$range = Array(
229 259
 					    'from' => (float)$matches[2],
@@ -256,8 +286,11 @@  discard block
 block discarded – undo
256 286
 				if (isset($matches[3])) {
257 287
 					$text[] = $this->texts[$matches[3]];
258 288
 				}
259
-				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
260
-				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
289
+				if (!isset($result['weather'])) {
290
+					$result['weather'] = implode(' ', $text);
291
+				} else {
292
+					$result['weather'] = $result['weather'].' / '.implode(' ', $text);
293
+				}
261 294
     			}
262 295
     		}
263 296
     		return $result;
@@ -269,8 +302,11 @@  discard block
 block discarded – undo
269 302
     		if (isset($globalMETARcycle) && $globalMETARcycle) {
270 303
             		$query = "SELECT * FROM metar WHERE metar_location = :icao";
271 304
                 } else {
272
-            		if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
273
-            		else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
305
+            		if ($globalDBdriver == 'mysql') {
306
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
307
+            		} else {
308
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
309
+            		}
274 310
                 }
275 311
                 $query_values = array(':icao' => $icao);
276 312
                  try {
@@ -325,7 +361,9 @@  discard block
 block discarded – undo
325 361
         
326 362
         public function addMETARCycle() {
327 363
     		global $globalDebug, $globalIVAO;
328
-    		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
364
+    		if (isset($globalDebug) && $globalDebug) {
365
+    			echo "Downloading METAR cycle...";
366
+    		}
329 367
     		date_default_timezone_set("UTC");
330 368
     		$Common = new Common();
331 369
     		if (isset($globalIVAO) && $globalIVAO) {
@@ -333,7 +371,9 @@  discard block
 block discarded – undo
333 371
     		} else {
334 372
 			$cycle = $Common->getData('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT');
335 373
     		}
336
-    		if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
374
+    		if (isset($globalDebug) && $globalDebug) {
375
+    			echo "Done - Updating DB...";
376
+    		}
337 377
     		$date = '';
338 378
     		foreach(explode("\n",$cycle) as $line) {
339 379
     			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
@@ -342,22 +382,32 @@  discard block
 block discarded – undo
342 382
     			} elseif ($line != '') {
343 383
     			    //$this->parse($line);
344 384
     			    //echo $line;
345
-    			    if ($date == '') $date = date('Y/m/d H:m');
385
+    			    if ($date == '') {
386
+    			    	$date = date('Y/m/d H:m');
387
+    			    }
346 388
     			    $pos = 0;
347 389
     			    $pieces = preg_split('/\s/',$line);
348
-    			    if ($pieces[0] == 'METAR') $pos++;
349
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
390
+    			    if ($pieces[0] == 'METAR') {
391
+    			    	$pos++;
392
+    			    }
393
+    			    if (strlen($pieces[$pos]) != 4) {
394
+    			    	$pos++;
395
+    			    }
350 396
 	        	    $location = $pieces[$pos];
351 397
 	        	    echo $this->addMETAR($location,$line,$date);
352 398
     			}
353 399
     			//echo $line."\n";
354 400
     		}
355
-    		if (isset($globalDebug) && $globalDebug) echo "Done\n";
401
+    		if (isset($globalDebug) && $globalDebug) {
402
+    			echo "Done\n";
403
+    		}
356 404
         
357 405
         }
358 406
         public function downloadMETAR($icao) {
359 407
     		global $globalMETARurl;
360
-    		if ($globalMETARurl == '') return array();
408
+    		if ($globalMETARurl == '') {
409
+    			return array();
410
+    		}
361 411
     		date_default_timezone_set("UTC");
362 412
     		$Common = new Common();
363 413
     		$url = str_replace('{icao}',$icao,$globalMETARurl);
@@ -370,16 +420,24 @@  discard block
 block discarded – undo
370 420
     			} elseif ($line != '') {
371 421
     			    //$this->parse($line);
372 422
     			    //echo $line;
373
-    			    if ($date == '') $date = date('Y/m/d H:m');
423
+    			    if ($date == '') {
424
+    			    	$date = date('Y/m/d H:m');
425
+    			    }
374 426
     			    $pos = 0;
375 427
     			    $pieces = preg_split('/\s/',$line);
376
-    			    if ($pieces[0] == 'METAR') $pos++;
377
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
428
+    			    if ($pieces[0] == 'METAR') {
429
+    			    	$pos++;
430
+    			    }
431
+    			    if (strlen($pieces[$pos]) != 4) {
432
+    			    	$pos++;
433
+    			    }
378 434
 	        	    $location = $pieces[$pos];
379 435
 	        	    if (strlen($location == 4)) {
380 436
 	        		$this->addMETAR($location,$line,$date);
381 437
 	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
382
-	        	    } else return array();
438
+	        	    } else {
439
+	        	    	return array();
440
+	        	    }
383 441
     			}
384 442
     			//echo $line."\n";
385 443
     		}
Please login to merge, or discard this patch.
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  discard block
 block discarded – undo
7 7
 	public $db;
8 8
 	
9 9
 	protected $texts = Array(
10
-	    'MI' => 'Shallow',
11
-	    'PR' => 'Partial',
12
-	    'BC' => 'Low drifting',
13
-	    'BL' => 'Blowing',
14
-	    'SH' => 'Showers',
15
-	    'TS' => 'Thunderstorm',
16
-	    'FZ' => 'Freezing',
17
-	    'DZ' => 'Drizzle',
18
-	    'RA' => 'Rain',
19
-	    'SN' => 'Snow',
20
-	    'SG' => 'Snow Grains',
21
-	    'IC' => 'Ice crystals',
22
-	    'PL' => 'Ice pellets',
23
-	    'GR' => 'Hail',
24
-	    'GS' => 'Small hail',
25
-	    'UP' => 'Unknown',
26
-	    'BR' => 'Mist',
27
-	    'FG' => 'Fog',
28
-	    'FU' => 'Smoke',
29
-	    'VA' => 'Volcanic ash',
30
-	    'DU' => 'Widespread dust',
31
-	    'SA' => 'Sand',
32
-	    'HZ' => 'Haze',
33
-	    'PY' => 'Spray',
34
-	    'PO' => 'Well developed dust / sand whirls',
35
-	    'SQ' => 'Squalls',
36
-	    'FC' => 'Funnel clouds inc tornadoes or waterspouts',
37
-	    'SS' => 'Sandstorm',
38
-	    'DS' => 'Duststorm'
10
+		'MI' => 'Shallow',
11
+		'PR' => 'Partial',
12
+		'BC' => 'Low drifting',
13
+		'BL' => 'Blowing',
14
+		'SH' => 'Showers',
15
+		'TS' => 'Thunderstorm',
16
+		'FZ' => 'Freezing',
17
+		'DZ' => 'Drizzle',
18
+		'RA' => 'Rain',
19
+		'SN' => 'Snow',
20
+		'SG' => 'Snow Grains',
21
+		'IC' => 'Ice crystals',
22
+		'PL' => 'Ice pellets',
23
+		'GR' => 'Hail',
24
+		'GS' => 'Small hail',
25
+		'UP' => 'Unknown',
26
+		'BR' => 'Mist',
27
+		'FG' => 'Fog',
28
+		'FU' => 'Smoke',
29
+		'VA' => 'Volcanic ash',
30
+		'DU' => 'Widespread dust',
31
+		'SA' => 'Sand',
32
+		'HZ' => 'Haze',
33
+		'PY' => 'Spray',
34
+		'PO' => 'Well developed dust / sand whirls',
35
+		'SQ' => 'Squalls',
36
+		'FC' => 'Funnel clouds inc tornadoes or waterspouts',
37
+		'SS' => 'Sandstorm',
38
+		'DS' => 'Duststorm'
39 39
 	);
40 40
 	
41 41
 	public function __construct($dbc = null) {
42
-                $Connection = new Connection($dbc);
43
-                $this->db = $Connection->db;
44
-        }
42
+				$Connection = new Connection($dbc);
43
+				$this->db = $Connection->db;
44
+		}
45 45
 
46
-       public static function check_last_update() {
47
-    		global $globalDBdriver;
48
-    		if ($globalDBdriver == 'mysql') {
46
+	   public static function check_last_update() {
47
+			global $globalDBdriver;
48
+			if ($globalDBdriver == 'mysql') {
49 49
 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value > DATE_SUB(NOW(), INTERVAL 20 MINUTE)";
50 50
 		} else {
51 51
 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_metar' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '20 MINUTES'";
52 52
 		}
53
-                try {
54
-                        $Connection = new Connection();
55
-                        $sth = $Connection->db->prepare($query);
56
-                        $sth->execute();
57
-                } catch(PDOException $e) {
58
-                        return "error : ".$e->getMessage();
59
-                }
60
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
61
-                $sth->closeCursor();
62
-                if ($row['nb'] > 0) return false;
63
-                else return true;
64
-        }
53
+				try {
54
+						$Connection = new Connection();
55
+						$sth = $Connection->db->prepare($query);
56
+						$sth->execute();
57
+				} catch(PDOException $e) {
58
+						return "error : ".$e->getMessage();
59
+				}
60
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
61
+				$sth->closeCursor();
62
+				if ($row['nb'] > 0) return false;
63
+				else return true;
64
+		}
65 65
 
66
-        public static function insert_last_update() {
67
-                $query = "DELETE FROM config WHERE name = 'last_update_metar';
66
+		public static function insert_last_update() {
67
+				$query = "DELETE FROM config WHERE name = 'last_update_metar';
68 68
                         INSERT INTO config (name,value) VALUES ('last_update_metar',NOW());";
69
-                try {
70
-                        $Connection = new Connection();
71
-                        $sth = $Connection->db->prepare($query);
72
-                        $sth->execute();
73
-                } catch(PDOException $e) {
74
-                        return "error : ".$e->getMessage();
75
-                }
76
-        }
69
+				try {
70
+						$Connection = new Connection();
71
+						$sth = $Connection->db->prepare($query);
72
+						$sth->execute();
73
+				} catch(PDOException $e) {
74
+						return "error : ".$e->getMessage();
75
+				}
76
+		}
77 77
 
78 78
 
79 79
         
80
-        public function parse($data) {
81
-    		//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82
-    		$codes = implode('|', array_keys($this->texts));
83
-    		$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
84
-    		//$pieces = explode(' ',$data);
85
-    		$pieces = preg_split('/\s/',$data);
86
-    		$pos = 0;
87
-    		if ($pieces[0] == 'METAR') $pos++;
88
-    		elseif ($pieces[0] == 'SPECI') $pos++;
89
-    		if (strlen($pieces[$pos]) != 4) $pos++;
90
-    		$result = array();
91
-    		$result['location'] = $pieces[$pos];
92
-    		$pos++;
93
-    		$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
-    		$result['time'] = substr($pieces[$pos],2,4);
95
-    		$c = count($pieces);
96
-    		for($pos++; $pos < $c; $pos++) {
97
-    			$piece = $pieces[$pos];
98
-    			if ($piece == 'RMK') break;
99
-    			if ($piece == 'AUTO') $result['auto'] = true;
100
-    			if ($piece == 'COR') $result['correction'] = true;
101
-    			// Wind Speed
102
-    			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
-    				$result['wind']['direction'] = (float)$matches[1];
80
+		public function parse($data) {
81
+			//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82
+			$codes = implode('|', array_keys($this->texts));
83
+			$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
84
+			//$pieces = explode(' ',$data);
85
+			$pieces = preg_split('/\s/',$data);
86
+			$pos = 0;
87
+			if ($pieces[0] == 'METAR') $pos++;
88
+			elseif ($pieces[0] == 'SPECI') $pos++;
89
+			if (strlen($pieces[$pos]) != 4) $pos++;
90
+			$result = array();
91
+			$result['location'] = $pieces[$pos];
92
+			$pos++;
93
+			$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
+			$result['time'] = substr($pieces[$pos],2,4);
95
+			$c = count($pieces);
96
+			for($pos++; $pos < $c; $pos++) {
97
+				$piece = $pieces[$pos];
98
+				if ($piece == 'RMK') break;
99
+				if ($piece == 'AUTO') $result['auto'] = true;
100
+				if ($piece == 'COR') $result['correction'] = true;
101
+				// Wind Speed
102
+				if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
+					$result['wind']['direction'] = (float)$matches[1];
104 104
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
105
+					if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
+					elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
+					elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
108 108
 				$result['wind']['gust'] = (float)$matches[3];
109 109
 				$result['wind']['unit'] = $matches[4];
110 110
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
111 111
 				$result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0;
112
-    			}
112
+				}
113 113
 
114 114
 /*    			if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) {
115 115
     				$result['wind_direction'] = (float)$matches[1];
@@ -126,35 +126,35 @@  discard block
 block discarded – undo
126 126
     				}
127 127
     			}
128 128
     			*/
129
-    			// Temperature
130
-    			if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
-    				$temp = (float)$matches[1];
129
+				// Temperature
130
+				if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
+					$temp = (float)$matches[1];
132 132
 				if ($matches[1]{0} == 'M') {
133 133
 					$temp = ((float)substr($matches[1], 1)) * -1;
134 134
 				}
135
-    				$result['temperature'] = $temp;
136
-    				$dew = (float)$matches[2];
135
+					$result['temperature'] = $temp;
136
+					$dew = (float)$matches[2];
137 137
 				if ($matches[2]{0} == 'M') {
138 138
 					$dew = ((float)substr($matches[2], 1)) * -1;
139 139
 				}
140 140
 				$result['dew'] = $dew;
141
-    			}
142
-    			// QNH
143
-    			if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) {
144
-    			// #^(Q|A)(////|[0-9]{4})( )#
145
-    				if ($matches[1] == 'Q') {
146
-    					// hPa
147
-    					$result['QNH'] = $matches[2];
148
-    				} else {
149
-    					// inHg
150
-    					$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
151 141
 				}
152
-    				/*
142
+				// QNH
143
+				if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) {
144
+				// #^(Q|A)(////|[0-9]{4})( )#
145
+					if ($matches[1] == 'Q') {
146
+						// hPa
147
+						$result['QNH'] = $matches[2];
148
+					} else {
149
+						// inHg
150
+						$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
151
+				}
152
+					/*
153 153
     				$result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100);
154 154
     				$result['QNH_format'] = $matches[1] == 'Q' ? 'hPa' : 'inHg';
155 155
     				*/
156
-    			}
157
-                     /*
156
+				}
157
+					 /*
158 158
     			// Wind Direction
159 159
     			if (preg_match('#^([0-9]{3})V([0-9]{3})$#', $piece, $matches)) {
160 160
     				$result['wind_direction'] = $matches[1];
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
     				$result['speed_variable'] = $matches[1];
166 166
     			}
167 167
     			*/
168
-    			// Visibility
169
-    			if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170
-    				if (isset($matches[3]) && strlen($matches[3]) > 0) {
168
+				// Visibility
169
+				if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170
+					if (isset($matches[3]) && strlen($matches[3]) > 0) {
171 171
 					$result['visibility'] = (float)$matches[3] * 1609.34;
172 172
 				} else {
173 173
 					if ($matches[1] == '9999') {
@@ -180,28 +180,28 @@  discard block
 block discarded – undo
180 180
 					$result['visibility'] = '> 10000';
181 181
 					$result['weather'] = "CAVOK";
182 182
 				}
183
-    			}
184
-    			// Cloud Coverage
185
-    			if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) {
186
-    				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187
-    				$type = $matches[1];
188
-    				$cloud = array();
189
-    				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
-    				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
-    				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
-    				elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
-    				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
-    				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
-    				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
-    				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197
-    				$cloud['type_code'] = $type;
198
-    				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199
-    				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200
-    				$result['cloud'][] = $cloud;
201
-    			}
202
-    			// RVR
203
-    			 if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) {
204
-    				$rvr = array();
183
+				}
184
+				// Cloud Coverage
185
+				if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) {
186
+					//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187
+					$type = $matches[1];
188
+					$cloud = array();
189
+					if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
+					elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
+					elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
+					elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
+					elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
+					elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
+					elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
+					elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197
+					$cloud['type_code'] = $type;
198
+					$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199
+					$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200
+					$result['cloud'][] = $cloud;
201
+				}
202
+				// RVR
203
+				 if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) {
204
+					$rvr = array();
205 205
 				$rvr['runway'] = $matches[1];
206 206
 				$rvr['assessment'] = $matches[2];
207 207
 				$rvr['rvr'] = $matches[3];
@@ -210,33 +210,33 @@  discard block
 block discarded – undo
210 210
 				$result['RVR'] = $rvr;
211 211
 			}
212 212
     			
213
-    			//if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
214
-    			if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) {
215
-    				//print_r($matches);
216
-    				// https://github.com/davidmegginson/metar-taf/blob/master/Metar.php
217
-    				$result['RVR']['runway'] = $matches[1];
218
-        			$result['RVR']['deposits'] = $matches[2];
219
-        			$result['RVR']['extent'] = $matches[3];
220
-        			$result['RVR']['depth'] = $matches[4];
221
-        			$result['RVR']['friction'] = $matches[5];
222
-    			}
223
-    			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224
-    				//echo $piece;
225
-    				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
213
+				//if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
214
+				if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) {
215
+					//print_r($matches);
216
+					// https://github.com/davidmegginson/metar-taf/blob/master/Metar.php
217
+					$result['RVR']['runway'] = $matches[1];
218
+					$result['RVR']['deposits'] = $matches[2];
219
+					$result['RVR']['extent'] = $matches[3];
220
+					$result['RVR']['depth'] = $matches[4];
221
+					$result['RVR']['friction'] = $matches[5];
222
+				}
223
+				if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224
+					//echo $piece;
225
+					//print_r($matches);
226
+					if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
+					else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
228 228
 				if (isset($matches[3])) {
229 229
 					$range = Array(
230
-					    'from' => (float)$matches[2],
231
-					    'to'   => (float)$matches[4],
232
-					    'unit' => $matches[5] ? 'FT' : 'M'
230
+						'from' => (float)$matches[2],
231
+						'to'   => (float)$matches[4],
232
+						'unit' => $matches[5] ? 'FT' : 'M'
233 233
 					);
234 234
 				}
235 235
 				$result['RVR'] = $matches[1];
236 236
 				$result['RVR_range'] = $range;
237
-    			}
238
-    			// Weather
239
-    			if (preg_match($regWeather, $piece, $matches)) {
237
+				}
238
+				// Weather
239
+				if (preg_match($regWeather, $piece, $matches)) {
240 240
 				$text = Array();
241 241
 				switch ($matches[1]) {
242 242
 					case '+':
@@ -259,35 +259,35 @@  discard block
 block discarded – undo
259 259
 				}
260 260
 				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
261 261
 				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
262
-    			}
263
-    		}
264
-    		return $result;
262
+				}
263
+			}
264
+			return $result;
265 265
         
266
-        }
266
+		}
267 267
         
268 268
 	public function getMETAR($icao) {
269
-    		global $globalMETARcycle, $globalDBdriver;
270
-    		if (isset($globalMETARcycle) && $globalMETARcycle) {
271
-            		$query = "SELECT * FROM metar WHERE metar_location = :icao";
272
-                } else {
273
-            		if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
-            		else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
275
-                }
276
-                $query_values = array(':icao' => $icao);
277
-                 try {
278
-                        $sth = $this->db->prepare($query);
279
-                        $sth->execute($query_values);
280
-                } catch(PDOException $e) {
281
-                        return "error : ".$e->getMessage();
282
-                }
283
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
284
-                if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) {
285
-            		$all = $this->downloadMETAR($icao);
286
-                }
287
-                return $all;
288
-        }
269
+			global $globalMETARcycle, $globalDBdriver;
270
+			if (isset($globalMETARcycle) && $globalMETARcycle) {
271
+					$query = "SELECT * FROM metar WHERE metar_location = :icao";
272
+				} else {
273
+					if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
+					else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
275
+				}
276
+				$query_values = array(':icao' => $icao);
277
+				 try {
278
+						$sth = $this->db->prepare($query);
279
+						$sth->execute($query_values);
280
+				} catch(PDOException $e) {
281
+						return "error : ".$e->getMessage();
282
+				}
283
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
284
+				if ((!isset($globalMETARcycle) || $globalMETARcycle === false) && count($all) == 0) {
285
+					$all = $this->downloadMETAR($icao);
286
+				}
287
+				return $all;
288
+		}
289 289
 
290
-       public function addMETAR($location,$metar,$date) {
290
+	   public function addMETAR($location,$metar,$date) {
291 291
 		global $globalDBdriver;
292 292
 		$date = date('Y-m-d H:i:s',strtotime($date));
293 293
 		if ($globalDBdriver == 'mysql') {
@@ -295,100 +295,100 @@  discard block
 block discarded – undo
295 295
 		} else {
296 296
 			$query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);";
297 297
 		}
298
-                $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
299
-                 try {
300
-                        $sth = $this->db->prepare($query);
301
-                        $sth->execute($query_values);
302
-                } catch(PDOException $e) {
303
-                        return "error : ".$e->getMessage();
304
-                }
305
-        }
298
+				$query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
299
+				 try {
300
+						$sth = $this->db->prepare($query);
301
+						$sth->execute($query_values);
302
+				} catch(PDOException $e) {
303
+						return "error : ".$e->getMessage();
304
+				}
305
+		}
306 306
 
307
-       public function deleteMETAR($id) {
308
-                $query = "DELETE FROM metar WHERE id = :id";
309
-                $query_values = array(':id' => $id);
310
-                 try {
311
-                        $sth = $this->db->prepare($query);
312
-                        $sth->execute($query_values);
313
-                } catch(PDOException $e) {
314
-                        return "error : ".$e->getMessage();
315
-                }
316
-        }
317
-       public function deleteAllMETARLocation() {
318
-                $query = "DELETE FROM metar";
319
-                 try {
320
-                        $sth = $this->db->prepare($query);
321
-                        $sth->execute();
322
-                } catch(PDOException $e) {
323
-                        return "error : ".$e->getMessage();
324
-                }
325
-        }
307
+	   public function deleteMETAR($id) {
308
+				$query = "DELETE FROM metar WHERE id = :id";
309
+				$query_values = array(':id' => $id);
310
+				 try {
311
+						$sth = $this->db->prepare($query);
312
+						$sth->execute($query_values);
313
+				} catch(PDOException $e) {
314
+						return "error : ".$e->getMessage();
315
+				}
316
+		}
317
+	   public function deleteAllMETARLocation() {
318
+				$query = "DELETE FROM metar";
319
+				 try {
320
+						$sth = $this->db->prepare($query);
321
+						$sth->execute();
322
+				} catch(PDOException $e) {
323
+						return "error : ".$e->getMessage();
324
+				}
325
+		}
326 326
         
327
-        public function addMETARCycle() {
328
-    		global $globalDebug, $globalIVAO;
329
-    		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
330
-    		date_default_timezone_set("UTC");
331
-    		$Common = new Common();
332
-    		if (isset($globalIVAO) && $globalIVAO) {
333
-        		$cycle = $Common->getData('http://wx.ivao.aero/metar.php');
334
-    		} else {
327
+		public function addMETARCycle() {
328
+			global $globalDebug, $globalIVAO;
329
+			if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
330
+			date_default_timezone_set("UTC");
331
+			$Common = new Common();
332
+			if (isset($globalIVAO) && $globalIVAO) {
333
+				$cycle = $Common->getData('http://wx.ivao.aero/metar.php');
334
+			} else {
335 335
 			$cycle = $Common->getData('http://tgftp.nws.noaa.gov/data/observations/metar/cycles/'.date('H').'Z.TXT');
336
-    		}
337
-    		if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
338
-    		$date = '';
339
-    		foreach(explode("\n",$cycle) as $line) {
340
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
341
-    				//echo "date : ".$line."\n";
342
-    				$date = $line;
343
-    			} 
344
-    			if ($line != '') {
345
-    			    //$this->parse($line);
346
-    			    //echo $line;
347
-    			    if ($date == '') $date = date('Y/m/d H:m');
348
-    			    $pos = 0;
349
-    			    $pieces = preg_split('/\s/',$line);
350
-    			    if ($pieces[0] == 'METAR') $pos++;
351
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
352
-	        	    $location = $pieces[$pos];
353
-	        	    echo $this->addMETAR($location,$line,$date);
354
-    			}
355
-    			//echo $line."\n";
356
-    		}
357
-    		if (isset($globalDebug) && $globalDebug) echo "Done\n";
336
+			}
337
+			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
338
+			$date = '';
339
+			foreach(explode("\n",$cycle) as $line) {
340
+				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
341
+					//echo "date : ".$line."\n";
342
+					$date = $line;
343
+				} 
344
+				if ($line != '') {
345
+					//$this->parse($line);
346
+					//echo $line;
347
+					if ($date == '') $date = date('Y/m/d H:m');
348
+					$pos = 0;
349
+					$pieces = preg_split('/\s/',$line);
350
+					if ($pieces[0] == 'METAR') $pos++;
351
+					if (strlen($pieces[$pos]) != 4) $pos++;
352
+					$location = $pieces[$pos];
353
+					echo $this->addMETAR($location,$line,$date);
354
+				}
355
+				//echo $line."\n";
356
+			}
357
+			if (isset($globalDebug) && $globalDebug) echo "Done\n";
358 358
         
359
-        }
360
-        public function downloadMETAR($icao) {
361
-    		global $globalMETARurl;
362
-    		if ($globalMETARurl == '') return array();
363
-    		date_default_timezone_set("UTC");
364
-    		$Common = new Common();
365
-    		$url = str_replace('{icao}',$icao,$globalMETARurl);
366
-    		$cycle = $Common->getData($url);
367
-    		$date = '';
368
-    		foreach(explode("\n",$cycle) as $line) {
369
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
370
-    				//echo "date : ".$line."\n";
371
-    				$date = $line;
372
-    			} 
373
-    			if ($line != '') {
374
-    			    //$this->parse($line);
375
-    			    //echo $line;
376
-    			    if ($date == '') $date = date('Y/m/d H:m');
377
-    			    $pos = 0;
378
-    			    $pieces = preg_split('/\s/',$line);
379
-    			    if ($pieces[0] == 'METAR') $pos++;
380
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
381
-	        	    $location = $pieces[$pos];
382
-	        	    if (strlen($location == 4)) {
383
-	        		$this->addMETAR($location,$line,$date);
384
-	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
385
-	        	    } else return array();
386
-    			}
387
-    			//echo $line."\n";
388
-    		}
389
-    		return array();
359
+		}
360
+		public function downloadMETAR($icao) {
361
+			global $globalMETARurl;
362
+			if ($globalMETARurl == '') return array();
363
+			date_default_timezone_set("UTC");
364
+			$Common = new Common();
365
+			$url = str_replace('{icao}',$icao,$globalMETARurl);
366
+			$cycle = $Common->getData($url);
367
+			$date = '';
368
+			foreach(explode("\n",$cycle) as $line) {
369
+				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
370
+					//echo "date : ".$line."\n";
371
+					$date = $line;
372
+				} 
373
+				if ($line != '') {
374
+					//$this->parse($line);
375
+					//echo $line;
376
+					if ($date == '') $date = date('Y/m/d H:m');
377
+					$pos = 0;
378
+					$pieces = preg_split('/\s/',$line);
379
+					if ($pieces[0] == 'METAR') $pos++;
380
+					if (strlen($pieces[$pos]) != 4) $pos++;
381
+					$location = $pieces[$pos];
382
+					if (strlen($location == 4)) {
383
+					$this->addMETAR($location,$line,$date);
384
+					return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
385
+					} else return array();
386
+				}
387
+				//echo $line."\n";
388
+			}
389
+			return array();
390 390
         
391
-        }
391
+		}
392 392
 }
393 393
 /*
394 394
 $METAR = new METAR();
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
                         $Connection = new Connection();
55 55
                         $sth = $Connection->db->prepare($query);
56 56
                         $sth->execute();
57
-                } catch(PDOException $e) {
57
+                } catch (PDOException $e) {
58 58
                         return "error : ".$e->getMessage();
59 59
                 }
60 60
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
                         $Connection = new Connection();
71 71
                         $sth = $Connection->db->prepare($query);
72 72
                         $sth->execute();
73
-                } catch(PDOException $e) {
73
+                } catch (PDOException $e) {
74 74
                         return "error : ".$e->getMessage();
75 75
                 }
76 76
         }
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
         public function parse($data) {
81 81
     		//$data = str_replace(array('\n','\r','\r','\n'),'',$data);
82 82
     		$codes = implode('|', array_keys($this->texts));
83
-    		$regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#';
83
+    		$regWeather = '#^(\+|\-|VC)?('.$codes.')('.$codes.')?$#';
84 84
     		//$pieces = explode(' ',$data);
85
-    		$pieces = preg_split('/\s/',$data);
85
+    		$pieces = preg_split('/\s/', $data);
86 86
     		$pos = 0;
87 87
     		if ($pieces[0] == 'METAR') $pos++;
88 88
     		elseif ($pieces[0] == 'SPECI') $pos++;
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
     		$result = array();
91 91
     		$result['location'] = $pieces[$pos];
92 92
     		$pos++;
93
-    		$result['dayofmonth'] = substr($pieces[$pos],0,2);
94
-    		$result['time'] = substr($pieces[$pos],2,4);
93
+    		$result['dayofmonth'] = substr($pieces[$pos], 0, 2);
94
+    		$result['time'] = substr($pieces[$pos], 2, 4);
95 95
     		$c = count($pieces);
96
-    		for($pos++; $pos < $c; $pos++) {
96
+    		for ($pos++; $pos < $c; $pos++) {
97 97
     			$piece = $pieces[$pos];
98 98
     			if ($piece == 'RMK') break;
99 99
     			if ($piece == 'AUTO') $result['auto'] = true;
100 100
     			if ($piece == 'COR') $result['correction'] = true;
101 101
     			// Wind Speed
102 102
     			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103
-    				$result['wind']['direction'] = (float)$matches[1];
103
+    				$result['wind']['direction'] = (float) $matches[1];
104 104
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
108
-				$result['wind']['gust'] = (float)$matches[3];
105
+    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float) $matches[2])*0.51444444444, 2);
106
+    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float) $matches[2])*1000, 2);
107
+    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float) $matches[2]), 2);
108
+				$result['wind']['gust'] = (float) $matches[3];
109 109
 				$result['wind']['unit'] = $matches[4];
110
-				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
111
-				$result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0;
110
+				$result['wind']['min_variation'] = array_key_exists(5, $matches) ? $matches[5] : 0;
111
+				$result['wind']['max_variation'] = array_key_exists(6, $matches) ? $matches[6] : 0;
112 112
     			}
113 113
 
114 114
 /*    			if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) {
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
     			*/
129 129
     			// Temperature
130 130
     			if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) {
131
-    				$temp = (float)$matches[1];
131
+    				$temp = (float) $matches[1];
132 132
 				if ($matches[1]{0} == 'M') {
133
-					$temp = ((float)substr($matches[1], 1)) * -1;
133
+					$temp = ((float) substr($matches[1], 1))*-1;
134 134
 				}
135 135
     				$result['temperature'] = $temp;
136
-    				$dew = (float)$matches[2];
136
+    				$dew = (float) $matches[2];
137 137
 				if ($matches[2]{0} == 'M') {
138
-					$dew = ((float)substr($matches[2], 1)) * -1;
138
+					$dew = ((float) substr($matches[2], 1))*-1;
139 139
 				}
140 140
 				$result['dew'] = $dew;
141 141
     			}
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     					$result['QNH'] = $matches[2];
148 148
     				} else {
149 149
     					// inHg
150
-    					$result['QNH'] = round(($matches[2] / 100)*33.86389,2);
150
+    					$result['QNH'] = round(($matches[2]/100)*33.86389, 2);
151 151
 				}
152 152
     				/*
153 153
     				$result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100);
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
     			// Visibility
169 169
     			if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) {
170 170
     				if (isset($matches[3]) && strlen($matches[3]) > 0) {
171
-					$result['visibility'] = (float)$matches[3] * 1609.34;
171
+					$result['visibility'] = (float) $matches[3]*1609.34;
172 172
 				} else {
173 173
 					if ($matches[1] == '9999') {
174 174
 						$result['visibility'] = '> 10000';
175 175
 					} else {
176
-						$result['visibility'] = (float)$matches[1];
176
+						$result['visibility'] = (float) $matches[1];
177 177
 					}
178 178
 				}
179 179
 				if (preg_match('#^CAVOK$#', $piece, $matches)) {
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196 196
     				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
197 197
     				$cloud['type_code'] = $type;
198
-    				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
198
+    				$cloud['level'] = round(((float) $matches[2])*100*0.3048);
199 199
     				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
200 200
     				$result['cloud'][] = $cloud;
201 201
     			}
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 				$rvr['runway'] = $matches[1];
206 206
 				$rvr['assessment'] = $matches[2];
207 207
 				$rvr['rvr'] = $matches[3];
208
-				$rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0;
209
-				$rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : '';
208
+				$rvr['rvr_max'] = array_key_exists(4, $matches) ? $matches[4] : 0;
209
+				$rvr['unit'] = array_key_exists(5, $matches) ? $matches[5] : '';
210 210
 				$result['RVR'] = $rvr;
211 211
 			}
212 212
     			
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
     			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224 224
     				//echo $piece;
225 225
     				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
226
+    				if (isset($matches[5])) $range = array('exact' => (float) $matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
+    				else $range = array('exact' => (float) $matches[2], 'unit' => 'M');
228 228
 				if (isset($matches[3])) {
229 229
 					$range = Array(
230
-					    'from' => (float)$matches[2],
231
-					    'to'   => (float)$matches[4],
230
+					    'from' => (float) $matches[2],
231
+					    'to'   => (float) $matches[4],
232 232
 					    'unit' => $matches[5] ? 'FT' : 'M'
233 233
 					);
234 234
 				}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                  try {
278 278
                         $sth = $this->db->prepare($query);
279 279
                         $sth->execute($query_values);
280
-                } catch(PDOException $e) {
280
+                } catch (PDOException $e) {
281 281
                         return "error : ".$e->getMessage();
282 282
                 }
283 283
                 $all = $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
                 return $all;
288 288
         }
289 289
 
290
-       public function addMETAR($location,$metar,$date) {
290
+       public function addMETAR($location, $metar, $date) {
291 291
 		global $globalDBdriver;
292
-		$date = date('Y-m-d H:i:s',strtotime($date));
292
+		$date = date('Y-m-d H:i:s', strtotime($date));
293 293
 		if ($globalDBdriver == 'mysql') {
294 294
 			$query = "INSERT INTO metar (metar_location,metar_date,metar) VALUES (:location,:date,:metar) ON DUPLICATE KEY UPDATE metar_date = :date, metar = :metar";
295 295
 		} else {
296 296
 			$query = "UPDATE metar SET metar_date = :date, metar = metar WHERE metar_location = :location;INSERT INTO metar (metar_location,metar_date,metar) SELECT :location,:date,:metar WHERE NOT EXISTS (SELECT 1 FROM metar WHERE metar_location = :location);";
297 297
 		}
298
-                $query_values = array(':location' => $location,':date' => $date,':metar' => utf8_encode($metar));
298
+                $query_values = array(':location' => $location, ':date' => $date, ':metar' => utf8_encode($metar));
299 299
                  try {
300 300
                         $sth = $this->db->prepare($query);
301 301
                         $sth->execute($query_values);
302
-                } catch(PDOException $e) {
302
+                } catch (PDOException $e) {
303 303
                         return "error : ".$e->getMessage();
304 304
                 }
305 305
         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                  try {
311 311
                         $sth = $this->db->prepare($query);
312 312
                         $sth->execute($query_values);
313
-                } catch(PDOException $e) {
313
+                } catch (PDOException $e) {
314 314
                         return "error : ".$e->getMessage();
315 315
                 }
316 316
         }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
                  try {
320 320
                         $sth = $this->db->prepare($query);
321 321
                         $sth->execute();
322
-                } catch(PDOException $e) {
322
+                } catch (PDOException $e) {
323 323
                         return "error : ".$e->getMessage();
324 324
                 }
325 325
         }
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
     		}
337 337
     		if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
338 338
     		$date = '';
339
-    		foreach(explode("\n",$cycle) as $line) {
340
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
339
+    		foreach (explode("\n", $cycle) as $line) {
340
+    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
341 341
     				//echo "date : ".$line."\n";
342 342
     				$date = $line;
343 343
     			} 
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
     			    //echo $line;
347 347
     			    if ($date == '') $date = date('Y/m/d H:m');
348 348
     			    $pos = 0;
349
-    			    $pieces = preg_split('/\s/',$line);
349
+    			    $pieces = preg_split('/\s/', $line);
350 350
     			    if ($pieces[0] == 'METAR') $pos++;
351 351
     			    if (strlen($pieces[$pos]) != 4) $pos++;
352 352
 	        	    $location = $pieces[$pos];
353
-	        	    echo $this->addMETAR($location,$line,$date);
353
+	        	    echo $this->addMETAR($location, $line, $date);
354 354
     			}
355 355
     			//echo $line."\n";
356 356
     		}
@@ -362,11 +362,11 @@  discard block
 block discarded – undo
362 362
     		if ($globalMETARurl == '') return array();
363 363
     		date_default_timezone_set("UTC");
364 364
     		$Common = new Common();
365
-    		$url = str_replace('{icao}',$icao,$globalMETARurl);
365
+    		$url = str_replace('{icao}', $icao, $globalMETARurl);
366 366
     		$cycle = $Common->getData($url);
367 367
     		$date = '';
368
-    		foreach(explode("\n",$cycle) as $line) {
369
-    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
368
+    		foreach (explode("\n", $cycle) as $line) {
369
+    			if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#', $line)) {
370 370
     				//echo "date : ".$line."\n";
371 371
     				$date = $line;
372 372
     			} 
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
     			    //echo $line;
376 376
     			    if ($date == '') $date = date('Y/m/d H:m');
377 377
     			    $pos = 0;
378
-    			    $pieces = preg_split('/\s/',$line);
378
+    			    $pieces = preg_split('/\s/', $line);
379 379
     			    if ($pieces[0] == 'METAR') $pos++;
380 380
     			    if (strlen($pieces[$pos]) != 4) $pos++;
381 381
 	        	    $location = $pieces[$pos];
382 382
 	        	    if (strlen($location == 4)) {
383
-	        		$this->addMETAR($location,$line,$date);
383
+	        		$this->addMETAR($location, $line, $date);
384 384
 	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
385 385
 	        	    } else return array();
386 386
     			}
Please login to merge, or discard this patch.
require/class.Scheduler.php 3 patches
Braces   +164 added lines, -56 removed lines patch added patch discarded remove patch
@@ -122,7 +122,9 @@  discard block
 block discarded – undo
122 122
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
123 123
 		if (count($row) > 0) {
124 124
 			return $row;
125
-		} else return array();
125
+		} else {
126
+			return array();
127
+		}
126 128
 	}
127 129
 
128 130
 	public function checkSchedule($ident) {
@@ -157,7 +159,9 @@  discard block
 block discarded – undo
157 159
 		$Common = new Common();
158 160
 		$check_date = new Datetime($date);
159 161
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
160
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
162
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
163
+			return array();
164
+		}
161 165
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
162 166
 		$json = $Common->getData($url);
163 167
 	
@@ -184,7 +188,9 @@  discard block
 block discarded – undo
184 188
 			*/
185 189
 		
186 190
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
187
-		} else return array();
191
+		} else {
192
+			return array();
193
+		}
188 194
 	}
189 195
 
190 196
 	/**
@@ -199,7 +205,9 @@  discard block
 block discarded – undo
199 205
 		date_default_timezone_set($globalTimezone);
200 206
 		$check_date = new Datetime($date);
201 207
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
202
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
208
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
209
+			return array();
210
+		}
203 211
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
204 212
 		$json = $Common->getData($url);
205 213
 		$parsed_json = json_decode($json);
@@ -212,7 +220,9 @@  discard block
 block discarded – undo
212 220
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
213 221
 
214 222
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
215
-		} else return array();
223
+		} else {
224
+			return array();
225
+		}
216 226
 	}
217 227
 
218 228
 	/**
@@ -223,7 +233,9 @@  discard block
 block discarded – undo
223 233
 	private function getRyanair($callsign) {
224 234
 		$Common = new Common();
225 235
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
226
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
236
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
237
+			return array();
238
+		}
227 239
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
228 240
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
229 241
 		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
@@ -237,8 +249,12 @@  discard block
 block discarded – undo
237 249
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
238 250
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
239 251
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
240
-			} else return array();
241
-		} else return array();
252
+			} else {
253
+				return array();
254
+			}
255
+		} else {
256
+			return array();
257
+		}
242 258
 	}
243 259
 
244 260
 	/**
@@ -249,7 +265,9 @@  discard block
 block discarded – undo
249 265
 	private function getSwiss($callsign) {
250 266
 		$Common = new Common();
251 267
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
252
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
268
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
269
+			return array();
270
+		}
253 271
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
254 272
 		$json = $Common->getData($url);
255 273
 		$parsed_json = json_decode($json);
@@ -269,8 +287,12 @@  discard block
 block discarded – undo
269 287
 			}
270 288
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
271 289
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
272
-			} else return array();
273
-		} else return array();
290
+			} else {
291
+				return array();
292
+			}
293
+		} else {
294
+			return array();
295
+		}
274 296
 	}
275 297
 	
276 298
 	/**
@@ -284,12 +306,18 @@  discard block
 block discarded – undo
284 306
 		$Common = new Common();
285 307
 		$check_date = new Datetime($date);
286 308
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
287
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
288
-		if ($globalBritishAirwaysKey == '') return array();
309
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
310
+			return array();
311
+		}
312
+		if ($globalBritishAirwaysKey == '') {
313
+			return array();
314
+		}
289 315
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
290 316
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
291 317
 		$json = $Common->getData($url,'get','',$headers);
292
-		if ($json == '') return array();
318
+		if ($json == '') {
319
+			return array();
320
+		}
293 321
 		$parsed_json = json_decode($json);
294 322
 		$flights = $parsed_json->{'FlightsResponse'};
295 323
 		if (count($flights) > 0) {
@@ -298,7 +326,9 @@  discard block
 block discarded – undo
298 326
 			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
299 327
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
300 328
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
301
-		} else return array();
329
+		} else {
330
+			return array();
331
+		}
302 332
 	}
303 333
 
304 334
 	/**
@@ -312,19 +342,27 @@  discard block
 block discarded – undo
312 342
 		$Common = new Common();
313 343
 		$check_date = new Datetime($date);
314 344
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
315
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
316
-		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
345
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
346
+			return array();
347
+		}
348
+		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') {
349
+			return array();
350
+		}
317 351
 		$url = "https://api.lufthansa.com/v1/oauth/token";
318 352
 		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
319 353
 		$data = $Common->getData($url,'post',$post);
320 354
 		$parsed_data = json_decode($data);
321
-		if (!isset($parsed_data->{'access_token'})) return array();
355
+		if (!isset($parsed_data->{'access_token'})) {
356
+			return array();
357
+		}
322 358
 		$token = $parsed_data->{'access_token'};
323 359
 		
324 360
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
325 361
 		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
326 362
 		$json = $Common->getData($url,'get','',$headers);
327
-		if ($json == '') return array();
363
+		if ($json == '') {
364
+			return array();
365
+		}
328 366
 		$parsed_json = json_decode($json);
329 367
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
330 368
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
@@ -332,7 +370,9 @@  discard block
 block discarded – undo
332 370
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
333 371
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
334 372
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
335
-		} else return array();
373
+		} else {
374
+			return array();
375
+		}
336 376
 	}
337 377
 
338 378
 	/**
@@ -346,14 +386,20 @@  discard block
 block discarded – undo
346 386
 		$Common = new Common();
347 387
 		$check_date = new Datetime($date);
348 388
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
349
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
350
-		if ($globalTransaviaKey == '') return array();
389
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
390
+			return array();
391
+		}
392
+		if ($globalTransaviaKey == '') {
393
+			return array();
394
+		}
351 395
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
352 396
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
353 397
 		$headers = array('apikey: '.$globalTransaviaKey);
354 398
 		$json = $Common->getData($url,'get','',$headers);
355 399
 		//echo 'result : '.$json;
356
-		if ($json == '') return array();
400
+		if ($json == '') {
401
+			return array();
402
+		}
357 403
 		$parsed_json = json_decode($json);
358 404
 		
359 405
 		if (isset($parsed_json->{'data'}[0])) {
@@ -362,7 +408,9 @@  discard block
 block discarded – undo
362 408
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
363 409
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
364 410
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
365
-		} else return array();
411
+		} else {
412
+			return array();
413
+		}
366 414
 	}
367 415
 
368 416
 	/**
@@ -373,7 +421,9 @@  discard block
 block discarded – undo
373 421
 	public function getTunisair($callsign) {
374 422
 		$Common = new Common();
375 423
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
376
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
424
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
425
+			return array();
426
+		}
377 427
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
378 428
 		$data = $Common->getData($url);
379 429
 		$table = $Common->table2array($data);
@@ -394,7 +444,9 @@  discard block
 block discarded – undo
394 444
 		$Common = new Common();
395 445
 		$check_date = new Datetime($date);
396 446
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
397
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
447
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
448
+			return array();
449
+		}
398 450
 		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
399 451
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
400 452
 		$data = $Common->getData($url);
@@ -404,8 +456,11 @@  discard block
 block discarded – undo
404 456
 			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
405 457
 			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
406 458
 			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
407
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
408
-			else return array();
459
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') {
460
+				return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
461
+			} else {
462
+				return array();
463
+			}
409 464
 		}
410 465
 		return array();
411 466
 	}
@@ -420,7 +475,9 @@  discard block
 block discarded – undo
420 475
 		$Common = new Common();
421 476
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
422 477
 		$check_date = new Datetime($date);
423
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
478
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
479
+			return array();
480
+		}
424 481
 		$url = "https://www.iberia.com/web/flightDetail.do";
425 482
 		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
426 483
 		$data = $Common->getData($url,'post',$post);
@@ -437,7 +494,9 @@  discard block
 block discarded – undo
437 494
 				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
438 495
 				if ($arrivalTime == 'Hora estimada de llegada') {
439 496
 					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
440
-				} else $arrivalTime = substr($arrivalTime,0,5);
497
+				} else {
498
+					$arrivalTime = substr($arrivalTime,0,5);
499
+				}
441 500
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
442 501
 			}
443 502
 		}
@@ -455,7 +514,9 @@  discard block
 block discarded – undo
455 514
 		$Common = new Common();
456 515
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
457 516
 		$check_date = new Datetime($date);
458
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
517
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
518
+			return array();
519
+		}
459 520
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
460 521
 		$data = $Common->getData($url);
461 522
 		if ($data != '') {
@@ -471,7 +532,9 @@  discard block
 block discarded – undo
471 532
 					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
472 533
 					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
473 534
 					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
474
-				} else return array();
535
+				} else {
536
+					return array();
537
+				}
475 538
 			}
476 539
 			
477 540
 
@@ -491,7 +554,9 @@  discard block
 block discarded – undo
491 554
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
492 555
 		$check_date = new Datetime($date);
493 556
 		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
494
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
557
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
558
+			return array();
559
+		}
495 560
 		$data = $Common->getData($url);
496 561
 		if ($data != '') {
497 562
 			$table = $Common->text2array($data);
@@ -515,7 +580,9 @@  discard block
 block discarded – undo
515 580
 		$check_date = new Datetime($date);
516 581
 		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
517 582
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
518
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
583
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
584
+			return array();
585
+		}
519 586
 		$data = $Common->getData($url);
520 587
 		if ($data != '') {
521 588
 		    //echo $data;
@@ -605,7 +672,9 @@  discard block
 block discarded – undo
605 672
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
606 673
 		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
607 674
 		//$check_date = new Datetime($date);
608
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
675
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
676
+			return array();
677
+		}
609 678
 		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
610 679
 		$data = $Common->getData($url,'post',$post);
611 680
 		if ($data != '') {
@@ -637,11 +706,15 @@  discard block
 block discarded – undo
637 706
 				$airline_icao = substr($callsign, 0, 3);
638 707
 			} 
639 708
 		}
640
-		if ($airline_icao == '') return array();
709
+		if ($airline_icao == '') {
710
+			return array();
711
+		}
641 712
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
642 713
 		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
643 714
 		//$check_date = new Datetime($date);
644
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
715
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
716
+			return array();
717
+		}
645 718
 		$data = $Common->getData($url);
646 719
 		if ($data != '') {
647 720
 			$table = $Common->table2array($data);
@@ -684,7 +757,9 @@  discard block
 block discarded – undo
684 757
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
685 758
 		$url= "http://fr.flightaware.com/live/flight/".$callsign;
686 759
 		//$check_date = new Datetime($date);
687
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
760
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
761
+			return array();
762
+		}
688 763
 		$data = $Common->getData($url);
689 764
 		if ($data != '') {
690 765
 			$table = $Common->table2array($data);
@@ -737,11 +812,15 @@  discard block
 block discarded – undo
737 812
 		$check_date = new Datetime($date);
738 813
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
739 814
 		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
740
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
815
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
816
+			return array();
817
+		}
741 818
 		$data = $Common->getData($url);
742 819
 		$dom = new DomDocument();
743 820
 		$dom->loadXML($data);
744
-		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
821
+		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) {
822
+			return array();
823
+		}
745 824
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
746 825
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
747 826
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
@@ -750,7 +829,9 @@  discard block
 block discarded – undo
750 829
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
751 830
 			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
752 831
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
753
-		} else return array();
832
+		} else {
833
+			return array();
834
+		}
754 835
 	}
755 836
 
756 837
 	/**
@@ -764,7 +845,9 @@  discard block
 block discarded – undo
764 845
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
765 846
 		$check_date = new Datetime($date);
766 847
 		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
767
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
848
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
849
+			return array();
850
+		}
768 851
 		$data = $Common->getData($url);
769 852
 		if ($data != '') {
770 853
 			$table = $Common->table2array($data);
@@ -793,7 +876,9 @@  discard block
 block discarded – undo
793 876
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
794 877
 		$check_date = new Datetime($date);
795 878
 		$url= "http://www.airberlin.com/en-US/site/aims.php";
796
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
879
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
880
+			return array();
881
+		}
797 882
 		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
798 883
 		$data = $Common->getData($url,'post',$post);
799 884
 		//echo $data;
@@ -803,11 +888,19 @@  discard block
 block discarded – undo
803 888
 		if ($data != '') {
804 889
 			$table = $Common->table2array($data);
805 890
 			$flight = $table;
806
-			if (isset($flight[5][4])) $departureTime = $flight[5][4];
807
-			else $departureTime = '';
808
-			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
809
-			else $departureAirport = '';
810
-		} else return array();
891
+			if (isset($flight[5][4])) {
892
+				$departureTime = $flight[5][4];
893
+			} else {
894
+				$departureTime = '';
895
+			}
896
+			if (isset($flight[5][2])) {
897
+				$departureAirport = $flight[5][2];
898
+			} else {
899
+				$departureAirport = '';
900
+			}
901
+		} else {
902
+			return array();
903
+		}
811 904
 		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
812 905
 		$data = $Common->getData($url,'post',$post);
813 906
 		if ($data != '') {
@@ -820,10 +913,14 @@  discard block
 block discarded – undo
820 913
 			    $arrivalTime = '';
821 914
 			    $arrivalAirport = '';
822 915
 			}
823
-		} else return array();
916
+		} else {
917
+			return array();
918
+		}
824 919
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
825 920
 		$json = $Common->getData($url);
826
-		if ($json == '') return array();
921
+		if ($json == '') {
922
+			return array();
923
+		}
827 924
 		$parsed_json = json_decode($json);
828 925
 		$airports = $parsed_json->{'suggestList'};
829 926
 		if (count($airports) > 0) {
@@ -838,7 +935,9 @@  discard block
 block discarded – undo
838 935
 		}
839 936
 		if (isset($DepartureAirportIata)) {
840 937
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
841
-		} else return array();
938
+		} else {
939
+			return array();
940
+		}
842 941
 	}
843 942
 
844 943
 
@@ -846,7 +945,9 @@  discard block
 block discarded – undo
846 945
 	public function fetchSchedule($ident,$date = 'NOW') {
847 946
 		global $globalSchedulesSources, $globalSchedulesFetch;
848 947
 		//$Common = new Common();
849
-		if (!$globalSchedulesFetch) return array();
948
+		if (!$globalSchedulesFetch) {
949
+			return array();
950
+		}
850 951
 		$airline_icao = '';
851 952
 		if (!is_numeric(substr($ident, 0, 3)))
852 953
 		{
@@ -1074,14 +1175,21 @@  discard block
 block discarded – undo
1074 1175
 				default:
1075 1176
 					// Randomly use a generic function to get hours
1076 1177
 					if (strlen($airline_icao) == 2) {
1077
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1178
+						if (!isset($globalSchedulesSources)) {
1179
+							$globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1180
+						}
1078 1181
 						if (count($globalSchedulesSources) > 0) {
1079 1182
 							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1080 1183
 							$source = $globalSchedulesSources[$rand];
1081
-							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1082
-							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
1184
+							if ($source == 'flightmapper') {
1185
+								return $this->getFlightMapper($ident);
1186
+							} elseif ($source == 'costtotravel') {
1187
+								return $this->getCostToTravel($ident);
1188
+							}
1083 1189
 							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1084
-							elseif ($source == 'flightaware') return $this->getFlightAware($ident);
1190
+							elseif ($source == 'flightaware') {
1191
+								return $this->getFlightAware($ident);
1192
+							}
1085 1193
 						}
1086 1194
 					}
1087 1195
 			}
Please login to merge, or discard this patch.
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -8,29 +8,29 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Schedule {
10 10
 	protected $cookies = array();
11
-        public $db;
11
+		public $db;
12 12
 	public function __construct($dbc = null) {
13 13
 		$Connection = new Connection($dbc);
14 14
 		$this->db = $Connection->db();
15
-        }
15
+		}
16 16
 	
17 17
 	/**
18
-	* Add schedule data to database
19
-	* @param String $ident aircraft ident
20
-	* @param String $departure_airport_icao departure airport icao
21
-	* @param String $departure_airport_time departure airport time
22
-	* @param String $arrival_airport_icao arrival airport icao
23
-	* @param String $arrival_airport_time arrival airport time
18
+	 * Add schedule data to database
19
+	 * @param String $ident aircraft ident
20
+	 * @param String $departure_airport_icao departure airport icao
21
+	 * @param String $departure_airport_time departure airport time
22
+	 * @param String $arrival_airport_icao arrival airport icao
23
+	 * @param String $arrival_airport_time arrival airport time
24 24
 	/ @param String $source source of data
25
-	*/
25
+	 */
26 26
 	
27 27
 	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
28 28
 		date_default_timezone_set('UTC');
29 29
 		$date = date("Y-m-d H:i:s",time());
30
-	        //if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31
-	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32
-	        $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
33
-	        $query_values = array(':ident' => $ident);
30
+			//if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31
+			//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32
+			$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
33
+			$query_values = array(':ident' => $ident);
34 34
 		 try {
35 35
 			$sth = $this->db->prepare($query);
36 36
 			$sth->execute($query_values);
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($sth->fetchColumn() > 0) {
41 41
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
42
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
42
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
44 44
 			} elseif ($arrival_airport_time == '') {
45
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
45
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
47 47
 			} elseif ($departure_airport_time == '') {
48
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
48
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
50 50
 			} else {
51
-			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
51
+				//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
54 54
 			}
55 55
 			try {
56 56
 				$sth = $this->db->prepare($query);
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 			if ($sth->fetchColumn() == 0) {
62 62
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
63 63
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
64
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
64
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
66 66
 				} elseif ($arrival_airport_time == '') {
67
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
67
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
69 69
 				} elseif ($departure_airport_time == '') {
70
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
70
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
72 72
 				} else {
73
-                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
73
+									$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
+					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
75 75
 				}
76 76
 				 try {
77 77
 					$sth = $this->db->prepare($query);
@@ -104,15 +104,15 @@  discard block
 block discarded – undo
104 104
 	}
105 105
 
106 106
 	public function getSchedule($ident) {
107
-	        $Translation = new Translation($this->db);
108
-	        $operator = $Translation->checkTranslation($ident,false);
109
-	        if ($ident != $operator) {
110
-	    		$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1";
111
-	    		$query_values = array(':ident' => $ident,'operator' => $operator);
112
-	    	} else {
113
-		        $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1";
114
-	    		$query_values = array(':ident' => $ident);
115
-	    	}
107
+			$Translation = new Translation($this->db);
108
+			$operator = $Translation->checkTranslation($ident,false);
109
+			if ($ident != $operator) {
110
+				$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1";
111
+				$query_values = array(':ident' => $ident,'operator' => $operator);
112
+			} else {
113
+				$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1";
114
+				$query_values = array(':ident' => $ident);
115
+			}
116 116
 		 try {
117 117
 			$sth = $this->db->prepare($query);
118 118
 			$sth->execute($query_values);
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
 
129 129
 	public function checkSchedule($ident) {
130 130
 		global $globalDBdriver;
131
-	        //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
132
-	        if ($globalDBdriver == 'mysql') {
131
+			//$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
132
+			if ($globalDBdriver == 'mysql') {
133 133
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1";
134 134
 		} else {
135 135
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident 
136 136
 			AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL)
137 137
 			     OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1";
138 138
 		}
139
-	        $query_values = array(':ident' => $ident);
139
+			$query_values = array(':ident' => $ident);
140 140
 		 try {
141 141
 			$sth = $this->db->prepare($query);
142 142
 			$sth->execute($query_values);
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 
151 151
 	/**
152
-	* Get flight info from Air France
153
-	* @param String $callsign The callsign
154
-	* @param String $date date we want flight number info
155
-	* @param String $carrier IATA code
156
-	* @return Flight departure and arrival airports and time
157
-	*/
152
+	 * Get flight info from Air France
153
+	 * @param String $callsign The callsign
154
+	 * @param String $date date we want flight number info
155
+	 * @param String $carrier IATA code
156
+	 * @return Flight departure and arrival airports and time
157
+	 */
158 158
 	private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
159 159
 		$Common = new Common();
160 160
 		$check_date = new Datetime($date);
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	}
191 191
 
192 192
 	/**
193
-	* Get flight info from EasyJet
194
-	* @param String $callsign The callsign
195
-	* @param String $date date we want flight number info
196
-	* @return Flight departure and arrival airports and time
197
-	*/
193
+	 * Get flight info from EasyJet
194
+	 * @param String $callsign The callsign
195
+	 * @param String $date date we want flight number info
196
+	 * @return Flight departure and arrival airports and time
197
+	 */
198 198
 	private function getEasyJet($callsign, $date = 'NOW') {
199 199
 		global $globalTimezone;
200 200
 		$Common = new Common();
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	/**
221
-	* Get flight info from Ryanair
222
-	* @param String $callsign The callsign
223
-	* @return Flight departure and arrival airports and time
224
-	*/
221
+	 * Get flight info from Ryanair
222
+	 * @param String $callsign The callsign
223
+	 * @return Flight departure and arrival airports and time
224
+	 */
225 225
 	private function getRyanair($callsign) {
226 226
 		$Common = new Common();
227 227
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 	}
245 245
 
246 246
 	/**
247
-	* Get flight info from Swiss
248
-	* @param String $callsign The callsign
249
-	* @return Flight departure and arrival airports and time
250
-	*/
247
+	 * Get flight info from Swiss
248
+	 * @param String $callsign The callsign
249
+	 * @return Flight departure and arrival airports and time
250
+	 */
251 251
 	private function getSwiss($callsign) {
252 252
 		$Common = new Common();
253 253
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 	}
277 277
 	
278 278
 	/**
279
-	* Get flight info from British Airways API
280
-	* @param String $callsign The callsign
281
-	* @param String $date date we want flight number info
282
-	* @return Flight departure and arrival airports and time
283
-	*/
279
+	 * Get flight info from British Airways API
280
+	 * @param String $callsign The callsign
281
+	 * @param String $date date we want flight number info
282
+	 * @return Flight departure and arrival airports and time
283
+	 */
284 284
 	public function getBritishAirways($callsign, $date = 'NOW') {
285 285
 		global $globalBritishAirwaysKey;
286 286
 		$Common = new Common();
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
 	}
305 305
 
306 306
 	/**
307
-	* Get flight info from Lutfhansa API
308
-	* @param String $callsign The callsign
309
-	* @param String $date date we want flight number info
310
-	* @return Flight departure and arrival airports and time
311
-	*/
307
+	 * Get flight info from Lutfhansa API
308
+	 * @param String $callsign The callsign
309
+	 * @param String $date date we want flight number info
310
+	 * @return Flight departure and arrival airports and time
311
+	 */
312 312
 	public function getLufthansa($callsign, $date = 'NOW') {
313 313
 		global $globalLufthansaKey;
314 314
 		$Common = new Common();
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	}
339 339
 
340 340
 	/**
341
-	* Get flight info from Transavia API
342
-	* @param String $callsign The callsign
343
-	* @param String $date date we want flight number info
344
-	* @return Flight departure and arrival airports and time
345
-	*/
341
+	 * Get flight info from Transavia API
342
+	 * @param String $callsign The callsign
343
+	 * @param String $date date we want flight number info
344
+	 * @return Flight departure and arrival airports and time
345
+	 */
346 346
 	public function getTransavia($callsign, $date = 'NOW') {
347 347
 		global $globalTransaviaKey;
348 348
 		$Common = new Common();
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 	}
369 369
 
370 370
 	/**
371
-	* Get flight info from Tunisair
372
-	* @param String $callsign The callsign
373
-	* @return Flight departure and arrival airports and time
374
-	*/
371
+	 * Get flight info from Tunisair
372
+	 * @param String $callsign The callsign
373
+	 * @return Flight departure and arrival airports and time
374
+	 */
375 375
 	public function getTunisair($callsign) {
376 376
 		$Common = new Common();
377 377
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
 	}
389 389
 
390 390
 	/**
391
-	* Get flight info from Vueling
392
-	* @param String $callsign The callsign
393
-	* @return Flight departure and arrival airports and time
394
-	*/
391
+	 * Get flight info from Vueling
392
+	 * @param String $callsign The callsign
393
+	 * @return Flight departure and arrival airports and time
394
+	 */
395 395
 	public function getVueling($callsign,$date = 'NOW') {
396 396
 		$Common = new Common();
397 397
 		$check_date = new Datetime($date);
@@ -413,11 +413,11 @@  discard block
 block discarded – undo
413 413
 	}
414 414
 
415 415
 	/**
416
-	* Get flight info from Iberia
417
-	* @param String $callsign The callsign
418
-	* @param String $date date we want flight number info
419
-	* @return Flight departure and arrival airports and time
420
-	*/
416
+	 * Get flight info from Iberia
417
+	 * @param String $callsign The callsign
418
+	 * @param String $date date we want flight number info
419
+	 * @return Flight departure and arrival airports and time
420
+	 */
421 421
 	public function getIberia($callsign, $date = 'NOW') {
422 422
 		$Common = new Common();
423 423
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
 	}
448 448
 
449 449
 	/**
450
-	* Get flight info from Star Alliance
451
-	* @param String $callsign The callsign
452
-	* @param String $date date we want flight number info
453
-	* @return Flight departure and arrival airports and time
454
-	*/
450
+	 * Get flight info from Star Alliance
451
+	 * @param String $callsign The callsign
452
+	 * @param String $date date we want flight number info
453
+	 * @return Flight departure and arrival airports and time
454
+	 */
455 455
 
456 456
 	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
457 457
 		$Common = new Common();
@@ -483,11 +483,11 @@  discard block
 block discarded – undo
483 483
 
484 484
 
485 485
 	/**
486
-	* Get flight info from Alitalia
487
-	* @param String $callsign The callsign
488
-	* @param String $date date we want flight number info
489
-	* @return Flight departure and arrival airports and time
490
-	*/
486
+	 * Get flight info from Alitalia
487
+	 * @param String $callsign The callsign
488
+	 * @param String $date date we want flight number info
489
+	 * @return Flight departure and arrival airports and time
490
+	 */
491 491
 	private function getAlitalia($callsign, $date = 'NOW') {
492 492
 		$Common = new Common();
493 493
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 	}
507 507
 
508 508
 	/**
509
-	* Get flight info from Brussels airlines
510
-	* @param String $callsign The callsign
511
-	* @param String $date date we want flight number info
512
-	* @return Flight departure and arrival airports and time
513
-	*/
509
+	 * Get flight info from Brussels airlines
510
+	 * @param String $callsign The callsign
511
+	 * @param String $date date we want flight number info
512
+	 * @return Flight departure and arrival airports and time
513
+	 */
514 514
 	private function getBrussels($callsign, $date = 'NOW') {
515 515
 		$Common = new Common();
516 516
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -520,24 +520,24 @@  discard block
 block discarded – undo
520 520
 		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
521 521
 		$data = $Common->getData($url);
522 522
 		if ($data != '') {
523
-		    //echo $data;
524
-		    $parsed_json = json_decode($data,true);
525
-		    if (isset($parsed_json[0]['FromAirportCode'])) {
523
+			//echo $data;
524
+			$parsed_json = json_decode($data,true);
525
+			if (isset($parsed_json[0]['FromAirportCode'])) {
526 526
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
527 527
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
528 528
 			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
529 529
 			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
530 530
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
531
-		    }
531
+			}
532 532
 		}
533 533
 	}
534 534
 
535 535
 	/**
536
-	* Get flight info from FlightRadar24
537
-	* @param String $callsign The callsign
538
-	* @param String $date date we want flight number info
539
-	* @return Flight departure and arrival airports and time
540
-	*/
536
+	 * Get flight info from FlightRadar24
537
+	 * @param String $callsign The callsign
538
+	 * @param String $date date we want flight number info
539
+	 * @return Flight departure and arrival airports and time
540
+	 */
541 541
 /*
542 542
 	public function getFlightRadar24($callsign, $date = 'NOW') {
543 543
 		$Common = new Common();
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
 	}
567 567
   */
568 568
 	/**
569
-	* Get flight info from Lufthansa
570
-	* @param String $callsign The callsign
571
-	* @param String $date date we want flight number info
572
-	* @return Flight departure and arrival airports and time
573
-	*/
569
+	 * Get flight info from Lufthansa
570
+	 * @param String $callsign The callsign
571
+	 * @param String $date date we want flight number info
572
+	 * @return Flight departure and arrival airports and time
573
+	 */
574 574
 
575 575
 /*	private function getLufthansa($callsign, $date = 'NOW') {
576 576
 		$Common = new Common();
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 	}
599 599
   */
600 600
 	/**
601
-	* Get flight info from flytap
602
-	* @param String $callsign The callsign
603
-	* @return Flight departure and arrival airports and time
604
-	*/
601
+	 * Get flight info from flytap
602
+	 * @param String $callsign The callsign
603
+	 * @return Flight departure and arrival airports and time
604
+	 */
605 605
 	private function getFlyTap($callsign) {
606 606
 		$Common = new Common();
607 607
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 	}
625 625
 
626 626
 	/**
627
-	* Get flight info from flightmapper
628
-	* @param String $callsign The callsign
629
-	* @return Flight departure and arrival airports and time
630
-	*/
627
+	 * Get flight info from flightmapper
628
+	 * @param String $callsign The callsign
629
+	 * @return Flight departure and arrival airports and time
630
+	 */
631 631
 	public function getFlightMapper($callsign) {
632 632
 		$Common = new Common();
633 633
 		$airline_icao = '';
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
 				$aarr = '';
656 656
 				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
657 657
 				if ($n == 7) {
658
-				    $departureTime = $dhour;
659
-				    $arrivalTime = $ahour;
660
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
658
+					$departureTime = $dhour;
659
+					$arrivalTime = $ahour;
660
+					$DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
+					$ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
+					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
663 663
 				}
664 664
 			}
665 665
 		}
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 	}
668 668
 
669 669
 	/**
670
-	* Get flight info from flightaware
671
-	* @param String $callsign The callsign
672
-	* @return Flight departure and arrival airports and time
673
-	*/
670
+	 * Get flight info from flightaware
671
+	 * @param String $callsign The callsign
672
+	 * @return Flight departure and arrival airports and time
673
+	 */
674 674
 	public function getFlightAware($callsign) {
675 675
 		$Common = new Common();
676 676
 		/*
@@ -703,10 +703,10 @@  discard block
 block discarded – undo
703 703
 	}
704 704
 
705 705
 	/**
706
-	* Get flight info from CostToTravel
707
-	* @param String $callsign The callsign
708
-	* @return Flight departure and arrival airports and time
709
-	*/
706
+	 * Get flight info from CostToTravel
707
+	 * @param String $callsign The callsign
708
+	 * @return Flight departure and arrival airports and time
709
+	 */
710 710
 	public function getCostToTravel($callsign) {
711 711
 		$Common = new Common();
712 712
 		$url= "http://www.costtotravel.com/flight-number/".$callsign;
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
 	}
729 729
 
730 730
 	/**
731
-	* Get flight info from Air Canada
732
-	* @param String $callsign The callsign
733
-	* @param String $date date we want flight number info
734
-	* @return Flight departure and arrival airports and time
735
-	*/
731
+	 * Get flight info from Air Canada
732
+	 * @param String $callsign The callsign
733
+	 * @param String $date date we want flight number info
734
+	 * @return Flight departure and arrival airports and time
735
+	 */
736 736
 	private function getAirCanada($callsign,$date = 'NOW') {
737 737
 		$Common = new Common();
738 738
 		date_default_timezone_set('UTC');
@@ -756,11 +756,11 @@  discard block
 block discarded – undo
756 756
 	}
757 757
 
758 758
 	/**
759
-	* Get flight info from Vietnam Airlines
760
-	* @param String $callsign The callsign
761
-	* @param String $date date we want flight number info
762
-	* @return Flight departure and arrival airports and time
763
-	*/
759
+	 * Get flight info from Vietnam Airlines
760
+	 * @param String $callsign The callsign
761
+	 * @param String $date date we want flight number info
762
+	 * @return Flight departure and arrival airports and time
763
+	 */
764 764
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
765 765
 		$Common = new Common();
766 766
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -782,12 +782,12 @@  discard block
 block discarded – undo
782 782
 	}
783 783
 
784 784
 	/**
785
-	* Get flight info from Air Berlin
786
-	* @param String $callsign The callsign
787
-	* @param String $date date we want flight number info
788
-	* @param String $carrier airline code
789
-	* @return Flight departure and arrival airports and time
790
-	*/
785
+	 * Get flight info from Air Berlin
786
+	 * @param String $callsign The callsign
787
+	 * @param String $date date we want flight number info
788
+	 * @param String $carrier airline code
789
+	 * @return Flight departure and arrival airports and time
790
+	 */
791 791
 	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
792 792
 		$Common = new Common();
793 793
 		date_default_timezone_set('UTC');
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
 			$table = $Common->table2array($data);
817 817
 			$flight = $table;
818 818
 			if (isset($flight[5][4])) {
819
-			    $arrivalTime = $flight[5][4];
820
-			    $arrivalAirport = $flight[5][3];
819
+				$arrivalTime = $flight[5][4];
820
+				$arrivalAirport = $flight[5][3];
821 821
 			} else {
822
-			    $arrivalTime = '';
823
-			    $arrivalAirport = '';
822
+				$arrivalTime = '';
823
+				$arrivalAirport = '';
824 824
 			}
825 825
 		} else return array();
826 826
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 					}
1089 1089
 			}
1090 1090
 		}
1091
-	        return array();
1091
+			return array();
1092 1092
 	}
1093 1093
 }
1094 1094
 
Please login to merge, or discard this patch.
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 	/ @param String $source source of data
25 25
 	*/
26 26
 	
27
-	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
27
+	public function addSchedule($ident, $departure_airport_icao, $departure_airport_time, $arrival_airport_icao, $arrival_airport_time, $source = 'website') {
28 28
 		date_default_timezone_set('UTC');
29
-		$date = date("Y-m-d H:i:s",time());
29
+		$date = date("Y-m-d H:i:s", time());
30 30
 	        //if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31 31
 	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32 32
 	        $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
@@ -34,69 +34,69 @@  discard block
 block discarded – undo
34 34
 		 try {
35 35
 			$sth = $this->db->prepare($query);
36 36
 			$sth->execute($query_values);
37
-		} catch(PDOException $e) {
37
+		} catch (PDOException $e) {
38 38
 			return "error : ".$e->getMessage();
39 39
 		}
40 40
 		if ($sth->fetchColumn() > 0) {
41 41
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
42 42
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
43
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao);
44 44
 			} elseif ($arrival_airport_time == '') {
45 45
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
46
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao);
47 47
 			} elseif ($departure_airport_time == '') {
48 48
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
49
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
50 50
 			} else {
51 51
 			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52 52
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
53
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
54 54
 			}
55 55
 			try {
56 56
 				$sth = $this->db->prepare($query);
57 57
 				$sth->execute($query_values);
58
-			} catch(PDOException $e) {
58
+			} catch (PDOException $e) {
59 59
 				return "error : ".$e->getMessage();
60 60
 			}
61 61
 			if ($sth->fetchColumn() == 0) {
62 62
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
63 63
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
64 64
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
65
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
66 66
 				} elseif ($arrival_airport_time == '') {
67 67
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
68
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
69 69
 				} elseif ($departure_airport_time == '') {
70 70
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
71
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
72 72
 				} else {
73 73
                             	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
-				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
74
+				    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
75 75
 				}
76 76
 				 try {
77 77
 					$sth = $this->db->prepare($query);
78 78
 					$sth->execute($query_values);
79
-				} catch(PDOException $e) {
79
+				} catch (PDOException $e) {
80 80
 					return "error : ".$e->getMessage();
81 81
 				}
82 82
 			} else {
83 83
 				//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident';
84 84
 				$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident';
85
-				$query_values = array(':ident' => $ident,':date' => $date);
85
+				$query_values = array(':ident' => $ident, ':date' => $date);
86 86
 				 try {
87 87
 					$sth = $this->db->prepare($query);
88 88
 					$sth->execute($query_values);
89
-				} catch(PDOException $e) {
89
+				} catch (PDOException $e) {
90 90
 					return "error : ".$e->getMessage();
91 91
 				}
92 92
 			}
93 93
 		} else {
94 94
 			$query = 'INSERT INTO  routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source)  VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)';
95
-			$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
95
+			$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
96 96
 			 try {
97 97
 				$sth = $this->db->prepare($query);
98 98
 				$sth->execute($query_values);
99
-			} catch(PDOException $e) {
99
+			} catch (PDOException $e) {
100 100
 				return "error : ".$e->getMessage();
101 101
 			}
102 102
 		}
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 
106 106
 	public function getSchedule($ident) {
107 107
 	        $Translation = new Translation($this->db);
108
-	        $operator = $Translation->checkTranslation($ident,false);
108
+	        $operator = $Translation->checkTranslation($ident, false);
109 109
 	        if ($ident != $operator) {
110 110
 	    		$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1";
111
-	    		$query_values = array(':ident' => $ident,'operator' => $operator);
111
+	    		$query_values = array(':ident' => $ident, 'operator' => $operator);
112 112
 	    	} else {
113 113
 		        $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1";
114 114
 	    		$query_values = array(':ident' => $ident);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 		 try {
117 117
 			$sth = $this->db->prepare($query);
118 118
 			$sth->execute($query_values);
119
-		} catch(PDOException $e) {
119
+		} catch (PDOException $e) {
120 120
 			return "error : ".$e->getMessage();
121 121
 		}
122 122
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		 try {
141 141
 			$sth = $this->db->prepare($query);
142 142
 			$sth->execute($query_values);
143
-		} catch(PDOException $e) {
143
+		} catch (PDOException $e) {
144 144
 			return "error : ".$e->getMessage();
145 145
 		}
146 146
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 	* @param String $carrier IATA code
156 156
 	* @return Flight departure and arrival airports and time
157 157
 	*/
158
-	private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
158
+	private function getAirFrance($callsign, $date = 'NOW', $carrier = 'AF') {
159 159
 		$Common = new Common();
160 160
 		$check_date = new Datetime($date);
161
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
162
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
161
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
162
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
163 163
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
164 164
 		$json = $Common->getData($url);
165 165
 	
166 166
 		$parsed_json = json_decode($json);
167
-		if (property_exists($parsed_json,'errors') === false) {
167
+		if (property_exists($parsed_json, 'errors') === false) {
168 168
 			//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'};
169 169
 			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
170 170
 			//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 			//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
175 175
 			$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'};
176 176
 
177
-			preg_match('/\((.*?)\)/',$originShort,$originiata);
177
+			preg_match('/\((.*?)\)/', $originShort, $originiata);
178 178
 			$DepartureAirportIata = $originiata[1];
179
-			preg_match('/\((.*?)\)/',$destinationShort,$destinationiata);
179
+			preg_match('/\((.*?)\)/', $destinationShort, $destinationiata);
180 180
 			$ArrivalAirportIata = $destinationiata[1];
181 181
 
182 182
 			/*
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 			$arrivalTime = gmdate('H:i',strtotime($arrivalTime));
186 186
 			*/
187 187
 		
188
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
188
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airfrance');
189 189
 		} else return array();
190 190
 	}
191 191
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 		$Common = new Common();
201 201
 		date_default_timezone_set($globalTimezone);
202 202
 		$check_date = new Datetime($date);
203
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
204
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
203
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
204
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
205 205
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
206 206
 		$json = $Common->getData($url);
207 207
 		$parsed_json = json_decode($json);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'};
214 214
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
215 215
 
216
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
216
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_easyjet');
217 217
 		} else return array();
218 218
 	}
219 219
 
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 	*/
225 225
 	private function getRyanair($callsign) {
226 226
 		$Common = new Common();
227
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
228
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
227
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
228
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
229 229
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
230 230
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
231
-		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
232
-		$json = $Common->getData($url,'post',$post,$headers);
231
+		$headers = array('Content-Type: application/json', 'Content-Length: '.strlen($post));
232
+		$json = $Common->getData($url, 'post', $post, $headers);
233 233
 		$parsed_json = json_decode($json);
234 234
 		if (isset($parsed_json->{'flightInfo'})) {
235 235
 			$flights = $parsed_json->{'flightInfo'};
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name
239 239
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
240 240
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
241
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
241
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
242 242
 			} else return array();
243 243
 		} else return array();
244 244
 	}
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	*/
251 251
 	private function getSwiss($callsign) {
252 252
 		$Common = new Common();
253
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
254
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
253
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
254
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
255 255
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
256 256
 		$json = $Common->getData($url);
257 257
 		$parsed_json = json_decode($json);
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 				if ($flight->{'no'} == "Vol LX ".$numvol) {
266 266
 					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
267 267
 					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
268
-					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
269
-					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
268
+					$departureTime = substr($flight->{'from'}->{'hour'},0, 5);
269
+					$arrivalTime = substr($flight->{'to'}->{'hour'},0, 5);
270 270
 				}
271 271
 			}
272 272
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
273
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
273
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_swiss');
274 274
 			} else return array();
275 275
 		} else return array();
276 276
 	}
@@ -285,21 +285,21 @@  discard block
 block discarded – undo
285 285
 		global $globalBritishAirwaysKey;
286 286
 		$Common = new Common();
287 287
 		$check_date = new Datetime($date);
288
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
289
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
288
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
289
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
290 290
 		if ($globalBritishAirwaysKey == '') return array();
291 291
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
292 292
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
293
-		$json = $Common->getData($url,'get','',$headers);
293
+		$json = $Common->getData($url, 'get', '', $headers);
294 294
 		if ($json == '') return array();
295 295
 		$parsed_json = json_decode($json);
296 296
 		$flights = $parsed_json->{'FlightsResponse'};
297 297
 		if (count($flights) > 0) {
298 298
 			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
299 299
 			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
300
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
301
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
302
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
300
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
301
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
302
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_britishairways');
303 303
 		} else return array();
304 304
 	}
305 305
 
@@ -313,27 +313,27 @@  discard block
 block discarded – undo
313 313
 		global $globalLufthansaKey;
314 314
 		$Common = new Common();
315 315
 		$check_date = new Datetime($date);
316
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
317
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
316
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
317
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
318 318
 		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
319 319
 		$url = "https://api.lufthansa.com/v1/oauth/token";
320
-		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
321
-		$data = $Common->getData($url,'post',$post);
320
+		$post = array('client_id' => $globalLufthansaKey['key'], 'client_secret' => $globalLufthansaKey['secret'], 'grant_type' => 'client_credentials');
321
+		$data = $Common->getData($url, 'post', $post);
322 322
 		$parsed_data = json_decode($data);
323 323
 		if (!isset($parsed_data->{'access_token'})) return array();
324 324
 		$token = $parsed_data->{'access_token'};
325 325
 		
326 326
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
327
-		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
328
-		$json = $Common->getData($url,'get','',$headers);
327
+		$headers = array('Authorization: Bearer '.$token, 'Accept: application/json');
328
+		$json = $Common->getData($url, 'get', '', $headers);
329 329
 		if ($json == '') return array();
330 330
 		$parsed_json = json_decode($json);
331 331
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
332 332
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
333
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
333
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
334 334
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
335
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
336
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
335
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
336
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_lufthansa');
337 337
 		} else return array();
338 338
 	}
339 339
 
@@ -347,23 +347,23 @@  discard block
 block discarded – undo
347 347
 		global $globalTransaviaKey;
348 348
 		$Common = new Common();
349 349
 		$check_date = new Datetime($date);
350
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
351
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
350
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
351
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
352 352
 		if ($globalTransaviaKey == '') return array();
353 353
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
354 354
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
355 355
 		$headers = array('apikey: '.$globalTransaviaKey);
356
-		$json = $Common->getData($url,'get','',$headers);
356
+		$json = $Common->getData($url, 'get', '', $headers);
357 357
 		//echo 'result : '.$json;
358 358
 		if ($json == '') return array();
359 359
 		$parsed_json = json_decode($json);
360 360
 		
361 361
 		if (isset($parsed_json->{'data'}[0])) {
362 362
 			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
363
-			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
363
+			$departureTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
364 364
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
365
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
366
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
365
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
366
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_transavia');
367 367
 		} else return array();
368 368
 	}
369 369
 
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 	*/
375 375
 	public function getTunisair($callsign) {
376 376
 		$Common = new Common();
377
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
378
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
377
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
378
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
379 379
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
380 380
 		$data = $Common->getData($url);
381 381
 		$table = $Common->table2array($data);
382 382
 		foreach ($table as $flight) {
383
-			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
384
-				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
383
+			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d', $numvol)) {
384
+				return array('DepartureAirportIATA' => $flight[2], 'DepartureTime' => str_replace('.', ':', $flight[5]), 'ArrivalAirportIATA' => $flight[3], 'ArrivalTime' => str_replace('.', ':', $flight[6]), 'Source' => 'website_tunisair');
385 385
 			}
386 386
 		}
387 387
 		return array();
@@ -392,21 +392,21 @@  discard block
 block discarded – undo
392 392
 	* @param String $callsign The callsign
393 393
 	* @return Flight departure and arrival airports and time
394 394
 	*/
395
-	public function getVueling($callsign,$date = 'NOW') {
395
+	public function getVueling($callsign, $date = 'NOW') {
396 396
 		$Common = new Common();
397 397
 		$check_date = new Datetime($date);
398
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
399
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
400
-		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
398
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
399
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
400
+		$final_date = str_replace('/', '%2F', $check_date->format('d/m/Y'));
401 401
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
402 402
 		$data = $Common->getData($url);
403
-		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
403
+		$data = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $data));
404 404
 		if ($data != '') {
405
-			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
406
-			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
407
-			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
408
-			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
409
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
405
+			preg_match('/flightOri=[A-Z]{3}/', $data, $result);
406
+			$DepartureAirportIata = str_replace('flightOri=', '', $result[0]);
407
+			preg_match('/flightDest=[A-Z]{3}/', $data, $result);
408
+			$ArrivalAirportIata = str_replace('flightDest=', '', $result[0]);
409
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'Source' => 'website_vueling');
410 410
 			else return array();
411 411
 		}
412 412
 		return array();
@@ -420,27 +420,27 @@  discard block
 block discarded – undo
420 420
 	*/
421 421
 	public function getIberia($callsign, $date = 'NOW') {
422 422
 		$Common = new Common();
423
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
423
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
424 424
 		$check_date = new Datetime($date);
425
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
425
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
426 426
 		$url = "https://www.iberia.com/web/flightDetail.do";
427
-		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
428
-		$data = $Common->getData($url,'post',$post);
427
+		$post = array('numvuelo' => $numvol, 'fecha' => $check_date->format('Ymd'), 'airlineID' => 'IB');
428
+		$data = $Common->getData($url, 'post', $post);
429 429
 		if ($data != '') {
430 430
 			$table = $Common->table2array($data);
431 431
 			//print_r($table);
432 432
 			if (count($table) > 0) {
433 433
 				$flight = $table;
434
-				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
435
-				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
434
+				preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
435
+				preg_match('/([A-Z]{3})/', $flight[5][0], $ArrivalAirportIataMatch);
436 436
 				$DepartureAirportIata = $DepartureAirportIataMatch[0];
437 437
 				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
438
-				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
439
-				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
438
+				$departureTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[3][2]))), 0, 5);
439
+				$arrivalTime = trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][1])));
440 440
 				if ($arrivalTime == 'Hora estimada de llegada') {
441
-					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
442
-				} else $arrivalTime = substr($arrivalTime,0,5);
443
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
441
+					$arrivalTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][2]))), 0, 5);
442
+				} else $arrivalTime = substr($arrivalTime, 0, 5);
443
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_iberia');
444 444
 			}
445 445
 		}
446 446
 		return array();
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
 	* @return Flight departure and arrival airports and time
454 454
 	*/
455 455
 
456
-	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
456
+	private function getStarAlliance($callsign, $date = 'NOW', $carrier = '') {
457 457
 		$Common = new Common();
458
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
458
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
459 459
 		$check_date = new Datetime($date);
460
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
460
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
461 461
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
462 462
 		$data = $Common->getData($url);
463 463
 		if ($data != '') {
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
 				$flight = $table;
467 467
 				//print_r($table);
468 468
 				if (isset($flight[25]) && isset($flight[29])) {
469
-					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
470
-					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
469
+					preg_match('/([A-Z]{3})/', $flight[25][1], $DepartureAirportIataMatch);
470
+					preg_match('/([A-Z]{3})/', $flight[25][3], $ArrivalAirportIataMatch);
471 471
 					$DepartureAirportIata = $DepartureAirportIataMatch[0];
472 472
 					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
473
-					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
474
-					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
475
-					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
473
+					$departureTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][0])), 0, 5);
474
+					$arrivalTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][1])), 0, 5);
475
+					return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_staralliance');
476 476
 				} else return array();
477 477
 			}
478 478
 			
@@ -490,10 +490,10 @@  discard block
 block discarded – undo
490 490
 	*/
491 491
 	private function getAlitalia($callsign, $date = 'NOW') {
492 492
 		$Common = new Common();
493
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
493
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
494 494
 		$check_date = new Datetime($date);
495
-		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
496
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
495
+		$url = "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
496
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
497 497
 		$data = $Common->getData($url);
498 498
 		if ($data != '') {
499 499
 			$table = $Common->text2array($data);
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 			$ArrivalAirportIata = '';
502 502
 			$departureTime = $table[4];
503 503
 			$arrivalTime = $table[5];
504
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
504
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_alitalia');
505 505
 		}
506 506
 	}
507 507
 
@@ -513,21 +513,21 @@  discard block
 block discarded – undo
513 513
 	*/
514 514
 	private function getBrussels($callsign, $date = 'NOW') {
515 515
 		$Common = new Common();
516
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
516
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
517 517
 		$check_date = new Datetime($date);
518
-		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
518
+		$url = "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
519 519
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
520
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
520
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
521 521
 		$data = $Common->getData($url);
522 522
 		if ($data != '') {
523 523
 		    //echo $data;
524
-		    $parsed_json = json_decode($data,true);
524
+		    $parsed_json = json_decode($data, true);
525 525
 		    if (isset($parsed_json[0]['FromAirportCode'])) {
526 526
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
527 527
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
528
-			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
529
-			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
530
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
528
+			$departureTime = date('H:i', strtotime($parsed_json[0]['ScheduledDepatureDate']));
529
+			$arrivalTime = date('H:i', strtotime($parsed_json[0]['ScheduledArrivalDate']));
530
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_brussels');
531 531
 		    }
532 532
 		}
533 533
 	}
@@ -604,21 +604,21 @@  discard block
 block discarded – undo
604 604
 	*/
605 605
 	private function getFlyTap($callsign) {
606 606
 		$Common = new Common();
607
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
608
-		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
607
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
608
+		$url = "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
609 609
 		//$check_date = new Datetime($date);
610
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
611
-		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
612
-		$data = $Common->getData($url,'post',$post);
610
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
611
+		$post = array('arrivalsdepartures_content' => 'number', 'arrivalsdepartures_tp' => $numvol, 'arrivalsdepartures_trk' => 'ARR', 'arrivalsdepartures_date_trk' => '1', 'aptCode' => '', 'arrivalsdepartures' => 'DEP', 'arrivalsdepartures_date' => '1', 'aptCodeFrom' => '', 'aptCodeTo' => '', 'arrivalsdepartures2' => 'DEP', 'arrivalsdepartures_date2' => '1');
612
+		$data = $Common->getData($url, 'post', $post);
613 613
 		if ($data != '') {
614 614
 			$table = $Common->table2array($data);
615
-			$departureTime = trim(substr($table[15][0],0,5));
616
-			$arrivalTime = trim(substr($table[35][0],0,5));
617
-			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
618
-			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
615
+			$departureTime = trim(substr($table[15][0], 0, 5));
616
+			$arrivalTime = trim(substr($table[35][0], 0, 5));
617
+			preg_match('/([A-Z]{3})/', $table[11][0], $DepartureAirportIataMatch);
618
+			preg_match('/([A-Z]{3})/', $table[31][0], $ArrivalAirportIataMatch);
619 619
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
620 620
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
621
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
621
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flytap');
622 622
 		}
623 623
 		return array();
624 624
 	}
@@ -640,10 +640,10 @@  discard block
 block discarded – undo
640 640
 			} 
641 641
 		}
642 642
 		if ($airline_icao == '') return array();
643
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
644
-		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
643
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
644
+		$url = "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
645 645
 		//$check_date = new Datetime($date);
646
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
646
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
647 647
 		$data = $Common->getData($url);
648 648
 		if ($data != '') {
649 649
 			$table = $Common->table2array($data);
@@ -653,13 +653,13 @@  discard block
 block discarded – undo
653 653
 				$darr = '';
654 654
 				$ahour = '';
655 655
 				$aarr = '';
656
-				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
656
+				$n = sscanf($sched, '%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])', $dhour, $darr, $ahour, $aarr);
657 657
 				if ($n == 7) {
658 658
 				    $departureTime = $dhour;
659 659
 				    $arrivalTime = $ahour;
660
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
660
+				    $DepartureAirportIata = str_replace(array('(', ')'), '', $darr);
661
+				    $ArrivalAirportIata = str_replace(array('(', ')'), '', $aarr);
662
+				    return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightmapper');
663 663
 				}
664 664
 			}
665 665
 		}
@@ -683,20 +683,20 @@  discard block
 block discarded – undo
683 683
 			} 
684 684
 		}
685 685
 		*/
686
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
687
-		$url= "http://fr.flightaware.com/live/flight/".$callsign;
686
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
687
+		$url = "http://fr.flightaware.com/live/flight/".$callsign;
688 688
 		//$check_date = new Datetime($date);
689
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
689
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
690 690
 		$data = $Common->getData($url);
691 691
 		if ($data != '') {
692 692
 			$table = $Common->table2array($data);
693 693
 			if (isset($table[11][0])) {
694
-				$departureTime = str_replace('h',':',substr($table[5][0],0,5));
695
-				$arrivalTime = str_replace('h',':',substr($table[5][1],0,5));
694
+				$departureTime = str_replace('h', ':', substr($table[5][0], 0, 5));
695
+				$arrivalTime = str_replace('h', ':', substr($table[5][1], 0, 5));
696 696
 				echo $table[3][0];
697
-				sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata);
698
-				sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata);
699
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware');
697
+				sscanf($table[3][0], '%*[^(] (%3[A-Z] / %*4[A-Z])', $DepartureAirportIata);
698
+				sscanf($table[3][1], '%*[^(] (%3[A-Z] / %*4[A-Z])', $ArrivalAirportIata);
699
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightaware');
700 700
 			}
701 701
 		}
702 702
 		return array();
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	*/
710 710
 	public function getCostToTravel($callsign) {
711 711
 		$Common = new Common();
712
-		$url= "http://www.costtotravel.com/flight-number/".$callsign;
712
+		$url = "http://www.costtotravel.com/flight-number/".$callsign;
713 713
 		//$check_date = new Datetime($date);
714 714
 		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
715 715
 		$data = $Common->getData($url);
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
 			$table = $Common->table2array($data);
718 718
 			//print_r($table);
719 719
 			if (isset($table[11][1])) {
720
-				$departureTime = substr($table[11][1],0,5);
721
-				$arrivalTime = substr($table[17][1],0,5);
722
-				$DepartureAirportIata = substr($table[13][1],0,3);
723
-				$ArrivalAirportIata = substr($table[15][1],0,3);
724
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
720
+				$departureTime = substr($table[11][1], 0, 5);
721
+				$arrivalTime = substr($table[17][1], 0, 5);
722
+				$DepartureAirportIata = substr($table[13][1], 0, 3);
723
+				$ArrivalAirportIata = substr($table[15][1], 0, 3);
724
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_costtotravel');
725 725
 			}
726 726
 		}
727 727
 		return array();
@@ -733,13 +733,13 @@  discard block
 block discarded – undo
733 733
 	* @param String $date date we want flight number info
734 734
 	* @return Flight departure and arrival airports and time
735 735
 	*/
736
-	private function getAirCanada($callsign,$date = 'NOW') {
736
+	private function getAirCanada($callsign, $date = 'NOW') {
737 737
 		$Common = new Common();
738 738
 		date_default_timezone_set('UTC');
739 739
 		$check_date = new Datetime($date);
740
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
741
-		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
742
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
740
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
741
+		$url = "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
742
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
743 743
 		$data = $Common->getData($url);
744 744
 		$dom = new DomDocument();
745 745
 		$dom->loadXML($data);
@@ -747,11 +747,11 @@  discard block
 block discarded – undo
747 747
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
748 748
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
749 749
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
750
-			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
750
+			$departureTime = date('H:i', strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
751 751
 			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
752 752
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
753
-			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
754
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
753
+			$arrivalTime = date('H:i', strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
754
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_aircanada');
755 755
 		} else return array();
756 756
 	}
757 757
 
@@ -763,21 +763,21 @@  discard block
 block discarded – undo
763 763
 	*/
764 764
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
765 765
 		$Common = new Common();
766
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
766
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
767 767
 		$check_date = new Datetime($date);
768
-		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
769
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
768
+		$url = "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
769
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
770 770
 		$data = $Common->getData($url);
771 771
 		if ($data != '') {
772 772
 			$table = $Common->table2array($data);
773 773
 			$flight = $table;
774
-			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
775
-			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
774
+			preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
775
+			preg_match('/([A-Z]{3})/', $flight[21][0], $ArrivalAirportIataMatch);
776 776
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
777 777
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
778 778
 			$departureTime = $flight[5][1];
779 779
 			$arrivalTime = $flight[23][1];
780
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
780
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_vietnamairlines');
781 781
 		}
782 782
 	}
783 783
 
@@ -788,16 +788,16 @@  discard block
 block discarded – undo
788 788
 	* @param String $carrier airline code
789 789
 	* @return Flight departure and arrival airports and time
790 790
 	*/
791
-	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
791
+	private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') {
792 792
 		$Common = new Common();
793 793
 		date_default_timezone_set('UTC');
794 794
 		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
795
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
795
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
796 796
 		$check_date = new Datetime($date);
797
-		$url= "http://www.airberlin.com/en-US/site/aims.php";
798
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
799
-		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
800
-		$data = $Common->getData($url,'post',$post);
797
+		$url = "http://www.airberlin.com/en-US/site/aims.php";
798
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
799
+		$post = array('type' => 'departure', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => $carrier);
800
+		$data = $Common->getData($url, 'post', $post);
801 801
 		//echo $data;
802 802
 		$DepartureAirportIata = '';
803 803
 		$ArrivalAirportIata = '';
@@ -810,8 +810,8 @@  discard block
 block discarded – undo
810 810
 			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
811 811
 			else $departureAirport = '';
812 812
 		} else return array();
813
-		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
814
-		$data = $Common->getData($url,'post',$post);
813
+		$post = array('type' => 'arrival', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB');
814
+		$data = $Common->getData($url, 'post', $post);
815 815
 		if ($data != '') {
816 816
 			$table = $Common->table2array($data);
817 817
 			$flight = $table;
@@ -839,13 +839,13 @@  discard block
 block discarded – undo
839 839
 			}
840 840
 		}
841 841
 		if (isset($DepartureAirportIata)) {
842
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
842
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airberlin');
843 843
 		} else return array();
844 844
 	}
845 845
 
846 846
 
847 847
 	
848
-	public function fetchSchedule($ident,$date = 'NOW') {
848
+	public function fetchSchedule($ident, $date = 'NOW') {
849 849
 		global $globalSchedulesSources, $globalSchedulesFetch;
850 850
 		//$Common = new Common();
851 851
 		if (!$globalSchedulesFetch) return array();
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 				// Brussels Airlines
916 916
 				case "BEL":
917 917
 				case "SN":
918
-					return $this->getBrussels($ident,$date);
918
+					return $this->getBrussels($ident, $date);
919 919
 /*
920 920
 				// Copa Airlines
921 921
 				case "CMP":
@@ -1000,17 +1000,17 @@  discard block
 block discarded – undo
1000 1000
 				// Air France
1001 1001
 				case "AF":
1002 1002
 				case "AFR":
1003
-					return $this->getAirFrance($ident,$date,'AF');
1003
+					return $this->getAirFrance($ident, $date, 'AF');
1004 1004
 				// HOP
1005 1005
 				case "A5":
1006 1006
 				case "HOP":
1007
-					return $this->getAirFrance($ident,$date,'A5');
1007
+					return $this->getAirFrance($ident, $date, 'A5');
1008 1008
 				// EasyJet
1009 1009
 				case "U2":
1010 1010
 				case "DS":
1011 1011
 				case "EZY":
1012 1012
 				case "EZS":
1013
-					return $this->getEasyJet($ident,$date);
1013
+					return $this->getEasyJet($ident, $date);
1014 1014
 				// Ryanair
1015 1015
 				case "FR":
1016 1016
 				case "RYR":
@@ -1060,25 +1060,25 @@  discard block
 block discarded – undo
1060 1060
 					return $this->getIberia($ident);
1061 1061
 				// Vietnam Airlines
1062 1062
 				case "HVN":
1063
-					return $this->getVietnamAirlines($ident,$date);
1063
+					return $this->getVietnamAirlines($ident, $date);
1064 1064
 				// Air Berlin
1065 1065
 				case "AB":
1066 1066
 				case "BER":
1067
-					return $this->getAirBerlin($ident,$date,'AB');
1067
+					return $this->getAirBerlin($ident, $date, 'AB');
1068 1068
 				// NIKI
1069 1069
 				case "HG":
1070 1070
 				case "NLY":
1071
-					return $this->getAirBerlin($ident,$date,'HG');
1071
+					return $this->getAirBerlin($ident, $date, 'HG');
1072 1072
 				// BelAir
1073 1073
 				case "4T":
1074 1074
 				case "BHP":
1075
-					return $this->getAirBerlin($ident,$date,'4T');
1075
+					return $this->getAirBerlin($ident, $date, '4T');
1076 1076
 				default:
1077 1077
 					// Randomly use a generic function to get hours
1078 1078
 					if (strlen($airline_icao) == 2) {
1079
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1079
+						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightradar24', 'flightaware');
1080 1080
 						if (count($globalSchedulesSources) > 0) {
1081
-							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1081
+							$rand = mt_rand(0, count($globalSchedulesSources) - 1);
1082 1082
 							$source = $globalSchedulesSources[$rand];
1083 1083
 							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1084 1084
 							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
Please login to merge, or discard this patch.
require/class.Connection.php 4 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@  discard block
 block discarded – undo
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 23;
8 8
 	
9
+	/**
10
+	 * @param string $dbname
11
+	 */
9 12
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10 13
 	    global $globalDBdriver;
11 14
 	    if ($dbc === null) {
@@ -131,6 +134,9 @@  discard block
 block discarded – undo
131 134
 		return true;
132 135
 	}
133 136
 
137
+	/**
138
+	 * @param string $table
139
+	 */
134 140
 	public function tableExists($table)
135 141
 	{
136 142
 		global $globalDBdriver, $globalDBname;
@@ -180,6 +186,11 @@  discard block
 block discarded – undo
180 186
 	/*
181 187
 	* Check if index exist
182 188
 	*/
189
+
190
+	/**
191
+	 * @param string $table
192
+	 * @param string $index
193
+	 */
183 194
 	public function indexExists($table,$index)
184 195
 	{
185 196
 		global $globalDBdriver, $globalDBname;
@@ -225,6 +236,11 @@  discard block
 block discarded – undo
225 236
 	* Check if a column name exist in a table
226 237
 	* @return Boolean column exist or not
227 238
 	*/
239
+
240
+	/**
241
+	 * @param string $table
242
+	 * @param string $name
243
+	 */
228 244
 	public function checkColumnName($table,$name)
229 245
 	{
230 246
 		$query = "SELECT * FROM ".$table." LIMIT 0";
Please login to merge, or discard this patch.
Braces   +77 added lines, -30 removed lines patch added patch discarded remove patch
@@ -64,8 +64,11 @@  discard block
 block discarded – undo
64 64
 				$globalDBSname = $globalDBname;
65 65
 				$globalDBSuser = $globalDBuser;
66 66
 				$globalDBSpass = $globalDBpass;
67
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
68
-				else $globalDBSport = $globalDBport;
67
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
68
+					$globalDBSport = 3306;
69
+				} else {
70
+					$globalDBSport = $globalDBport;
71
+				}
69 72
 			} else {
70 73
 				$DBname = 'default';
71 74
 				$globalDBSdriver = $globalDBdriver;
@@ -73,8 +76,11 @@  discard block
 block discarded – undo
73 76
 				$globalDBSname = $globalDBname;
74 77
 				$globalDBSuser = $user;
75 78
 				$globalDBSpass = $pass;
76
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
77
-				else $globalDBSport = $globalDBport;
79
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
80
+					$globalDBSport = 3306;
81
+				} else {
82
+					$globalDBSport = $globalDBport;
83
+				}
78 84
 			}
79 85
 		} else {
80 86
 			$globalDBSdriver = $globalDB[$DBname]['driver'];
@@ -82,11 +88,16 @@  discard block
 block discarded – undo
82 88
 			$globalDBSname = $globalDB[$DBname]['name'];
83 89
 			$globalDBSuser = $globalDB[$DBname]['user'];
84 90
 			$globalDBSpass = $globalDB[$DBname]['pass'];
85
-			if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port'];
86
-			else $globalDBSport = 3306;
91
+			if (isset($globalDB[$DBname]['port'])) {
92
+				$globalDBSport = $globalDB[$DBname]['port'];
93
+			} else {
94
+				$globalDBSport = 3306;
95
+			}
87 96
 		}
88 97
 		// Set number of try to connect to DB
89
-		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5;
98
+		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) {
99
+			$globalDBretry = 5;
100
+		}
90 101
 		$i = 0;
91 102
 		while (true) {
92 103
 			try {
@@ -95,10 +106,16 @@  discard block
 block discarded – undo
95 106
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
96 107
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
97 108
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
98
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
99
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
100
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
101
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
109
+					if (!isset($globalDBTimeOut)) {
110
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
111
+					} else {
112
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
113
+					}
114
+					if (!isset($globalDBPersistent)) {
115
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
116
+					} else {
117
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
118
+					}
102 119
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
103 120
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
104 121
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -112,22 +129,34 @@  discard block
 block discarded – undo
112 129
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
113 130
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
114 131
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
115
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
116
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
117
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
118
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
132
+					if (!isset($globalDBTimeOut)) {
133
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
134
+					} else {
135
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
136
+					}
137
+					if (!isset($globalDBPersistent)) {
138
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
139
+					} else {
140
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
141
+					}
119 142
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
120 143
 				}
121 144
 				break;
122 145
 			} catch(PDOException $e) {
123 146
 				$i++;
124
-				if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n";
147
+				if (isset($globalDebug) && $globalDebug) {
148
+					echo $e->getMessage()."\n";
149
+				}
125 150
 				//exit;
126
-				if ($i > $globalDBretry) return false;
151
+				if ($i > $globalDBretry) {
152
+					return false;
153
+				}
127 154
 				//return false;
128 155
 			}
129 156
 		}
130
-		if ($DBname === 'default') $this->db = $this->dbs['default'];
157
+		if ($DBname === 'default') {
158
+			$this->db = $this->dbs['default'];
159
+		}
131 160
 		return true;
132 161
 	}
133 162
 
@@ -139,7 +168,9 @@  discard block
 block discarded – undo
139 168
 		} else {
140 169
 			$query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'";
141 170
 		}
142
-		if ($this->db == NULL) return false;
171
+		if ($this->db == NULL) {
172
+			return false;
173
+		}
143 174
 		try {
144 175
 			//$Connection = new Connection();
145 176
 			$results = $this->db->query($query);
@@ -148,21 +179,28 @@  discard block
 block discarded – undo
148 179
 		}
149 180
 		if($results->rowCount()>0) {
150 181
 		    return true; 
182
+		} else {
183
+			return false;
151 184
 		}
152
-		else return false;
153 185
 	}
154 186
 
155 187
 	public function connectionExists()
156 188
 	{
157 189
 		global $globalDBdriver, $globalDBCheckConnection;
158
-		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true;
190
+		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) {
191
+			return true;
192
+		}
159 193
 		$query = "SELECT 1 + 1";
160
-		if ($this->db === null) return false;
194
+		if ($this->db === null) {
195
+			return false;
196
+		}
161 197
 		try {
162 198
 			$sum = @$this->db->query($query);
163 199
 			if ($sum instanceof \PDOStatement) {
164 200
 				$sum = $sum->fetchColumn(0);
165
-			} else $sum = 0;
201
+			} else {
202
+				$sum = 0;
203
+			}
166 204
 			if (intval($sum) !== 2) {
167 205
 			     return false;
168 206
 			}
@@ -196,8 +234,9 @@  discard block
 block discarded – undo
196 234
 		}
197 235
 		if($results->rowCount()>0) {
198 236
 		    return true; 
237
+		} else {
238
+			return false;
199 239
 		}
200
-		else return false;
201 240
 	}
202 241
 
203 242
 	/*
@@ -240,9 +279,12 @@  discard block
 block discarded – undo
240 279
 				echo "error : ".$e->getMessage()."\n";
241 280
 			}
242 281
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
243
-			if ($result['nb'] > 0) return true;
244
-			else return false;
245
-/*		} else {
282
+			if ($result['nb'] > 0) {
283
+				return true;
284
+			} else {
285
+				return false;
286
+			}
287
+			/*		} else {
246 288
 			$query = "SELECT * FROM ".$table." LIMIT 0";
247 289
 			try {
248 290
 				$results = $this->db->query($query);
@@ -280,7 +322,9 @@  discard block
 block discarded – undo
280 322
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
281 323
 				return $result['value'];
282 324
 			}
283
-		} else return $version;
325
+		} else {
326
+			return $version;
327
+		}
284 328
 	}
285 329
 	
286 330
 	/*
@@ -288,8 +332,11 @@  discard block
 block discarded – undo
288 332
 	* @return Boolean if latest version or not
289 333
 	*/
290 334
 	public function latest() {
291
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
292
-	    else return false;
335
+	    if ($this->check_schema_version() == $this->latest_schema) {
336
+	    	return true;
337
+	    } else {
338
+	    	return false;
339
+	    }
293 340
 	}
294 341
 
295 342
 }
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 26;
8 8
 	
9 9
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10
-	    global $globalDBdriver;
11
-	    if ($dbc === null) {
10
+		global $globalDBdriver;
11
+		if ($dbc === null) {
12 12
 		if ($this->db === null && $dbname === null) {
13
-		    if ($user === null && $pass === null) {
13
+			if ($user === null && $pass === null) {
14 14
 			$this->createDBConnection();
15
-		    } else {
15
+			} else {
16 16
 			$this->createDBConnection(null,$user,$pass);
17
-		    }
17
+			}
18 18
 		} else {
19
-		    $this->createDBConnection($dbname);
19
+			$this->createDBConnection($dbname);
20 20
 		}
21
-	    } elseif ($dbname === null || $dbname === 'default') {
21
+		} elseif ($dbname === null || $dbname === 'default') {
22 22
 		$this->db = $dbc;
23 23
 		if ($this->connectionExists() === false) {
24 24
 			/*
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 			*/
29 29
 			$this->createDBConnection();
30 30
 		}
31
-	    } else {
31
+		} else {
32 32
 		//$this->connectionExists();
33 33
 		$this->dbs[$dbname] = $dbc;
34
-	    }
34
+		}
35 35
 	}
36 36
 
37 37
 	public function db() {
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
 	}
48 48
 
49 49
 	/**
50
-	* Creates the database connection
51
-	*
52
-	* @return Boolean of the database connection
53
-	*
54
-	*/
50
+	 * Creates the database connection
51
+	 *
52
+	 * @return Boolean of the database connection
53
+	 *
54
+	 */
55 55
 
56 56
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
57 57
 	{
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 			return false;
148 148
 		}
149 149
 		if($results->rowCount()>0) {
150
-		    return true; 
150
+			return true; 
151 151
 		}
152 152
 		else return false;
153 153
 	}
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
 				$sum = $sum->fetchColumn(0);
165 165
 			} else $sum = 0;
166 166
 			if (intval($sum) !== 2) {
167
-			     return false;
167
+				 return false;
168 168
 			}
169 169
 			
170 170
 		} catch(PDOException $e) {
171 171
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
172
-            			throw $e;
173
-	                }
174
-	                //echo 'error ! '.$e->getMessage();
172
+						throw $e;
173
+					}
174
+					//echo 'error ! '.$e->getMessage();
175 175
 			return false;
176 176
 		}
177 177
 		return true; 
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 		$version = 0;
269 269
 		if ($this->tableExists('aircraft')) {
270 270
 			if (!$this->tableExists('config')) {
271
-	    			$version = '1';
272
-	    			return $version;
271
+					$version = '1';
272
+					return $version;
273 273
 			} else {
274 274
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
275 275
 				try {
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	* @return Boolean if latest version or not
290 290
 	*/
291 291
 	public function latest() {
292
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
293
-	    else return false;
292
+		if ($this->check_schema_version() == $this->latest_schema) return true;
293
+		else return false;
294 294
 	}
295 295
 
296 296
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 
4
-class Connection{
4
+class Connection {
5 5
 	public $db = null;
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 26;
8 8
 	
9
-	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
9
+	public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) {
10 10
 	    global $globalDBdriver;
11 11
 	    if ($dbc === null) {
12 12
 		if ($this->db === null && $dbname === null) {
13 13
 		    if ($user === null && $pass === null) {
14 14
 			$this->createDBConnection();
15 15
 		    } else {
16
-			$this->createDBConnection(null,$user,$pass);
16
+			$this->createDBConnection(null, $user, $pass);
17 17
 		    }
18 18
 		} else {
19 19
 		    $this->createDBConnection($dbname);
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 		while (true) {
92 92
 			try {
93 93
 				if ($globalDBSdriver == 'mysql') {
94
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
94
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass);
95 95
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
96 96
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
97
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
98
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
99
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
100
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
101
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
97
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
98
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500);
99
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
100
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
101
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
102 102
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
103 103
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
104 104
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 					$this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"');
109 109
 					//$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"');
110 110
 				} else {
111
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser,  $globalDBSpass);
111
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass);
112 112
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
113 113
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
114
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
115
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
116
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
117
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
118
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
114
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
115
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200);
116
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
117
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
118
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
119 119
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
120 120
 				}
121 121
 				break;
122
-			} catch(PDOException $e) {
122
+			} catch (PDOException $e) {
123 123
 				$i++;
124 124
 				if (isset($globalDebug) && $globalDebug) echo $e->getMessage()."\n";
125 125
 				//exit;
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 		try {
144 144
 			//$Connection = new Connection();
145 145
 			$results = $this->db->query($query);
146
-		} catch(PDOException $e) {
146
+		} catch (PDOException $e) {
147 147
 			return false;
148 148
 		}
149
-		if($results->rowCount()>0) {
149
+		if ($results->rowCount() > 0) {
150 150
 		    return true; 
151 151
 		}
152 152
 		else return false;
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 			     return false;
168 168
 			}
169 169
 			
170
-		} catch(PDOException $e) {
171
-			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
170
+		} catch (PDOException $e) {
171
+			if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
172 172
             			throw $e;
173 173
 	                }
174 174
 	                //echo 'error ! '.$e->getMessage();
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	/*
181 181
 	* Check if index exist
182 182
 	*/
183
-	public function indexExists($table,$index)
183
+	public function indexExists($table, $index)
184 184
 	{
185 185
 		global $globalDBdriver, $globalDBname;
186 186
 		if ($globalDBdriver == 'mysql') {
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
 		try {
192 192
 			//$Connection = new Connection();
193 193
 			$results = $this->db->query($query);
194
-		} catch(PDOException $e) {
194
+		} catch (PDOException $e) {
195 195
 			return false;
196 196
 		}
197 197
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
198
-		if($nb[0]['nb'] > 0) {
198
+		if ($nb[0]['nb'] > 0) {
199 199
 			return true; 
200 200
 		}
201 201
 		else return false;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		$query = "SELECT * FROM ".$table." LIMIT 0";
211 211
 		try {
212 212
 			$results = $this->db->query($query);
213
-		} catch(PDOException $e) {
213
+		} catch (PDOException $e) {
214 214
 			return "error : ".$e->getMessage()."\n";
215 215
 		}
216 216
 		$columns = array();
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	* Check if a column name exist in a table
227 227
 	* @return Boolean column exist or not
228 228
 	*/
229
-	public function checkColumnName($table,$name)
229
+	public function checkColumnName($table, $name)
230 230
 	{
231 231
 		global $globalDBdriver, $globalDBname;
232 232
 		if ($globalDBdriver == 'mysql') {
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 		}
237 237
 			try {
238 238
 				$sth = $this->db()->prepare($query);
239
-				$sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name));
240
-			} catch(PDOException $e) {
239
+				$sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name));
240
+			} catch (PDOException $e) {
241 241
 				echo "error : ".$e->getMessage()."\n";
242 242
 			}
243 243
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 				try {
277 277
 					$sth = $this->db->prepare($query);
278 278
 					$sth->execute();
279
-				} catch(PDOException $e) {
279
+				} catch (PDOException $e) {
280 280
 					return "error : ".$e->getMessage()."\n";
281 281
 				}
282 282
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.
install/class.update_db.php 4 patches
Doc Comments   +42 added lines patch added patch discarded remove patch
@@ -10,6 +10,9 @@  discard block
 block discarded – undo
10 10
 class update_db {
11 11
 	public static $db_sqlite;
12 12
 
13
+	/**
14
+	 * @param string $file
15
+	 */
13 16
 	public static function download($url, $file, $referer = '') {
14 17
 		$fp = fopen($file, 'w+');
15 18
 		$ch = curl_init();
@@ -24,6 +27,9 @@  discard block
 block discarded – undo
24 27
 		fclose($fp);
25 28
 	}
26 29
 
30
+	/**
31
+	 * @param string $in_file
32
+	 */
27 33
 	public static function gunzip($in_file,$out_file_name = '') {
28 34
 		//echo $in_file.' -> '.$out_file_name."\n";
29 35
 		$buffer_size = 4096; // read 4kb at a time
@@ -45,6 +51,9 @@  discard block
 block discarded – undo
45 51
 		}
46 52
 	}
47 53
 
54
+	/**
55
+	 * @param string $in_file
56
+	 */
48 57
 	public static function unzip($in_file) {
49 58
 		if ($in_file != '' && file_exists($in_file)) {
50 59
 			$path = pathinfo(realpath($in_file), PATHINFO_DIRNAME);
@@ -66,6 +75,9 @@  discard block
 block discarded – undo
66 75
 		}
67 76
 	}
68 77
 	
78
+	/**
79
+	 * @param string $database_file
80
+	 */
69 81
 	public static function retrieve_route_sqlite_to_dest($database_file) {
70 82
 		global $globalDebug, $globalTransaction;
71 83
 		//$query = 'TRUNCATE TABLE routes';
@@ -108,6 +120,10 @@  discard block
 block discarded – undo
108 120
 		}
109 121
                 return '';
110 122
 	}
123
+
124
+	/**
125
+	 * @param string $database_file
126
+	 */
111 127
 	public static function retrieve_route_oneworld($database_file) {
112 128
 		global $globalDebug, $globalTransaction;
113 129
 		//$query = 'TRUNCATE TABLE routes';
@@ -147,6 +163,9 @@  discard block
 block discarded – undo
147 163
                 return '';
148 164
 	}
149 165
 	
166
+	/**
167
+	 * @param string $database_file
168
+	 */
150 169
 	public static function retrieve_route_skyteam($database_file) {
151 170
 		global $globalDebug, $globalTransaction;
152 171
 		//$query = 'TRUNCATE TABLE routes';
@@ -186,6 +205,10 @@  discard block
 block discarded – undo
186 205
 		}
187 206
                 return '';
188 207
 	}
208
+
209
+	/**
210
+	 * @param string $database_file
211
+	 */
189 212
 	public static function retrieve_modes_sqlite_to_dest($database_file) {
190 213
 		global $globalTransaction;
191 214
 		//$query = 'TRUNCATE TABLE aircraft_modes';
@@ -251,6 +274,9 @@  discard block
 block discarded – undo
251 274
 		return '';
252 275
 	}
253 276
 
277
+	/**
278
+	 * @param string $database_file
279
+	 */
254 280
 	public static function retrieve_modes_flarmnet($database_file) {
255 281
 		global $globalTransaction;
256 282
 		$Common = new Common();
@@ -321,6 +347,9 @@  discard block
 block discarded – undo
321 347
 		return '';
322 348
 	}
323 349
 
350
+	/**
351
+	 * @param string $database_file
352
+	 */
324 353
 	public static function retrieve_modes_ogn($database_file) {
325 354
 		global $globalTransaction;
326 355
 		//$query = 'TRUNCATE TABLE aircraft_modes';
@@ -389,6 +418,9 @@  discard block
 block discarded – undo
389 418
 		return '';
390 419
 	}
391 420
 
421
+	/**
422
+	 * @param string $database_file
423
+	 */
392 424
 	public static function retrieve_owner($database_file,$country = 'F') {
393 425
 		global $globalTransaction;
394 426
 		//$query = 'TRUNCATE TABLE aircraft_modes';
@@ -939,6 +971,10 @@  discard block
 block discarded – undo
939 971
 		return '';
940 972
         }
941 973
 
974
+	/**
975
+	 * @param string $filename
976
+	 * @param string $tletype
977
+	 */
942 978
 	public static function tle($filename,$tletype) {
943 979
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
944 980
 		global $tmp_dir, $globalTransaction;
@@ -1071,6 +1107,9 @@  discard block
 block discarded – undo
1071 1107
 
1072 1108
 	}
1073 1109
 */
1110
+	/**
1111
+	 * @param string $filename
1112
+	 */
1074 1113
 	public static function waypoints($filename) {
1075 1114
 		//require_once(dirname(__FILE__).'/../require/class.Spotter.php');
1076 1115
 		global $tmp_dir, $globalTransaction;
@@ -1118,6 +1157,9 @@  discard block
 block discarded – undo
1118 1157
 		return '';
1119 1158
         }
1120 1159
 
1160
+	/**
1161
+	 * @param string $filename
1162
+	 */
1121 1163
 	public static function ivao_airlines($filename) {
1122 1164
 		//require_once(dirname(__FILE__).'/../require/class.Spotter.php');
1123 1165
 		global $tmp_dir, $globalTransaction;
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
 		try {
76 76
 			//$Connection = new Connection();
77 77
 			$sth = $Connection->db->prepare($query);
78
-                        $sth->execute(array(':source' => $database_file));
79
-                } catch(PDOException $e) {
80
-                        return "error : ".$e->getMessage();
81
-                }
78
+						$sth->execute(array(':source' => $database_file));
79
+				} catch(PDOException $e) {
80
+						return "error : ".$e->getMessage();
81
+				}
82 82
 
83
-    		if ($globalDebug) echo " - Add routes to DB -";
84
-    		update_db::connect_sqlite($database_file);
83
+			if ($globalDebug) echo " - Add routes to DB -";
84
+			update_db::connect_sqlite($database_file);
85 85
 		//$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';
86 86
 		$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";
87 87
 		try {
88
-                        $sth = update_db::$db_sqlite->prepare($query);
89
-                        $sth->execute();
90
-                } catch(PDOException $e) {
91
-                        return "error : ".$e->getMessage();
92
-                }
88
+						$sth = update_db::$db_sqlite->prepare($query);
89
+						$sth->execute();
90
+				} catch(PDOException $e) {
91
+						return "error : ".$e->getMessage();
92
+				}
93 93
 		//$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)';
94 94
 		$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,ToAirport_ICAO,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO, :ToAirport_ICAO, :routestop, :source)';
95 95
 		$Connection = new Connection();
96 96
 		$sth_dest = $Connection->db->prepare($query_dest);
97 97
 		try {
98 98
 			if ($globalTransaction) $Connection->db->beginTransaction();
99
-            		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
99
+					while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
100 100
 				//$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);
101 101
 				$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);
102 102
 				$sth_dest->execute($query_dest_values);
103
-            		}
103
+					}
104 104
 			if ($globalTransaction) $Connection->db->commit();
105 105
 		} catch(PDOException $e) {
106 106
 			if ($globalTransaction) $Connection->db->rollBack(); 
107 107
 			return "error : ".$e->getMessage();
108 108
 		}
109
-                return '';
109
+				return '';
110 110
 	}
111 111
 	public static function retrieve_route_oneworld($database_file) {
112 112
 		global $globalDebug, $globalTransaction;
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
 		try {
118 118
 			//$Connection = new Connection();
119 119
 			$sth = $Connection->db->prepare($query);
120
-                        $sth->execute(array(':source' => 'oneworld'));
121
-                } catch(PDOException $e) {
122
-                        return "error : ".$e->getMessage();
123
-                }
120
+						$sth->execute(array(':source' => 'oneworld'));
121
+				} catch(PDOException $e) {
122
+						return "error : ".$e->getMessage();
123
+				}
124 124
 
125
-    		if ($globalDebug) echo " - Add routes to DB -";
125
+			if ($globalDebug) echo " - Add routes to DB -";
126 126
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
127 127
 		$Spotter = new Spotter();
128 128
 		if ($fh = fopen($database_file,"r")) {
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			}
147 147
 			if ($globalTransaction) $Connection->db->commit();
148 148
 		}
149
-                return '';
149
+				return '';
150 150
 	}
151 151
 	
152 152
 	public static function retrieve_route_skyteam($database_file) {
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 		try {
159 159
 			//$Connection = new Connection();
160 160
 			$sth = $Connection->db->prepare($query);
161
-                        $sth->execute(array(':source' => 'skyteam'));
162
-                } catch(PDOException $e) {
163
-                        return "error : ".$e->getMessage();
164
-                }
161
+						$sth->execute(array(':source' => 'skyteam'));
162
+				} catch(PDOException $e) {
163
+						return "error : ".$e->getMessage();
164
+				}
165 165
 
166
-    		if ($globalDebug) echo " - Add routes to DB -";
166
+			if ($globalDebug) echo " - Add routes to DB -";
167 167
 
168 168
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
169 169
 		$Spotter = new Spotter();
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 				return "error : ".$e->getMessage();
190 190
 			}
191 191
 		}
192
-                return '';
192
+				return '';
193 193
 	}
194 194
 	public static function retrieve_modes_sqlite_to_dest($database_file) {
195 195
 		global $globalTransaction;
@@ -198,27 +198,27 @@  discard block
 block discarded – undo
198 198
 		try {
199 199
 			$Connection = new Connection();
200 200
 			$sth = $Connection->db->prepare($query);
201
-                        $sth->execute(array(':source' => $database_file));
202
-                } catch(PDOException $e) {
203
-                        return "error : ".$e->getMessage();
204
-                }
201
+						$sth->execute(array(':source' => $database_file));
202
+				} catch(PDOException $e) {
203
+						return "error : ".$e->getMessage();
204
+				}
205 205
 		$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source";
206 206
 		try {
207 207
 			$Connection = new Connection();
208 208
 			$sth = $Connection->db->prepare($query);
209
-                        $sth->execute(array(':source' => $database_file));
210
-                } catch(PDOException $e) {
211
-                        return "error : ".$e->getMessage();
212
-                }
209
+						$sth->execute(array(':source' => $database_file));
210
+				} catch(PDOException $e) {
211
+						return "error : ".$e->getMessage();
212
+				}
213 213
 
214
-    		update_db::connect_sqlite($database_file);
214
+			update_db::connect_sqlite($database_file);
215 215
 		$query = 'select * from Aircraft';
216 216
 		try {
217
-                        $sth = update_db::$db_sqlite->prepare($query);
218
-                        $sth->execute();
219
-                } catch(PDOException $e) {
220
-                        return "error : ".$e->getMessage();
221
-                }
217
+						$sth = update_db::$db_sqlite->prepare($query);
218
+						$sth->execute();
219
+				} catch(PDOException $e) {
220
+						return "error : ".$e->getMessage();
221
+				}
222 222
 		//$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)';
223 223
 		$query_dest = 'INSERT INTO aircraft_modes (LastModified, ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type,:source)';
224 224
 		
@@ -229,17 +229,17 @@  discard block
 block discarded – undo
229 229
 		$sth_dest_owner = $Connection->db->prepare($query_dest_owner);
230 230
 		try {
231 231
 			if ($globalTransaction) $Connection->db->beginTransaction();
232
-            		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
232
+					while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
233 233
 			//$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']);
234 234
 				if ($values['UserString4'] == 'M') $type = 'military';
235 235
 				else $type = null;
236 236
 				$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type);
237 237
 				$sth_dest->execute($query_dest_values);
238 238
 				if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') {
239
-				    $query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']);
240
-				    $sth_dest_owner->execute($query_dest_owner_values);
239
+					$query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']);
240
+					$sth_dest_owner->execute($query_dest_owner_values);
241 241
 				}
242
-            		}
242
+					}
243 243
 			if ($globalTransaction) $Connection->db->commit();
244 244
 		} catch(PDOException $e) {
245 245
 			return "error : ".$e->getMessage();
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
 		try {
251 251
 			$Connection = new Connection();
252 252
 			$sth = $Connection->db->prepare($query);
253
-                        $sth->execute(array(':source' => $database_file));
254
-                } catch(PDOException $e) {
255
-                        return "error : ".$e->getMessage();
256
-                }
253
+						$sth->execute(array(':source' => $database_file));
254
+				} catch(PDOException $e) {
255
+						return "error : ".$e->getMessage();
256
+				}
257 257
 		return '';
258 258
 	}
259 259
 
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 		try {
266 266
 			$Connection = new Connection();
267 267
 			$sth = $Connection->db->prepare($query);
268
-                        $sth->execute(array(':source' => $database_file));
269
-                } catch(PDOException $e) {
270
-                        return "error : ".$e->getMessage();
271
-                }
268
+						$sth->execute(array(':source' => $database_file));
269
+				} catch(PDOException $e) {
270
+						return "error : ".$e->getMessage();
271
+				}
272 272
 		
273 273
 		if ($fh = fopen($database_file,"r")) {
274 274
 			//$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)';
@@ -278,26 +278,26 @@  discard block
 block discarded – undo
278 278
 			$sth_dest = $Connection->db->prepare($query_dest);
279 279
 			try {
280 280
 				if ($globalTransaction) $Connection->db->beginTransaction();
281
-            			while (!feof($fh)) {
282
-            				$values = array();
283
-            				$line = $Common->hex2str(fgets($fh,9999));
281
+						while (!feof($fh)) {
282
+							$values = array();
283
+							$line = $Common->hex2str(fgets($fh,9999));
284 284
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
285
-            				$values['ModeS'] = substr($line,0,6);
286
-            				$values['Registration'] = trim(substr($line,69,6));
287
-            				$aircraft_name = trim(substr($line,48,6));
288
-            				// Check if we can find ICAO, else set it to GLID
289
-            				$aircraft_name_split = explode(' ',$aircraft_name);
290
-            				$search_more = '';
291
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
292
-            				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
293
-            				$sth_search = $Connection->db->prepare($query_search);
285
+							$values['ModeS'] = substr($line,0,6);
286
+							$values['Registration'] = trim(substr($line,69,6));
287
+							$aircraft_name = trim(substr($line,48,6));
288
+							// Check if we can find ICAO, else set it to GLID
289
+							$aircraft_name_split = explode(' ',$aircraft_name);
290
+							$search_more = '';
291
+							if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
292
+							$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
293
+							$sth_search = $Connection->db->prepare($query_search);
294 294
 					try {
295
-                                    		$sth_search->execute();
296
-	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
297
-	            				//if (count($result) > 0) {
298
-	            				if (isset($result['icao']) && $result['icao'] != '') {
299
-	            				    $values['ICAOTypeCode'] = $result['icao'];
300
-	            				} 
295
+											$sth_search->execute();
296
+								$result = $sth_search->fetch(PDO::FETCH_ASSOC);
297
+								//if (count($result) > 0) {
298
+								if (isset($result['icao']) && $result['icao'] != '') {
299
+									$values['ICAOTypeCode'] = $result['icao'];
300
+								} 
301 301
 					} catch(PDOException $e) {
302 302
 						return "error : ".$e->getMessage();
303 303
 					}
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
 		try {
321 321
 			$Connection = new Connection();
322 322
 			$sth = $Connection->db->prepare($query);
323
-                        $sth->execute(array(':source' => $database_file));
324
-                } catch(PDOException $e) {
325
-                        return "error : ".$e->getMessage();
326
-                }
323
+						$sth->execute(array(':source' => $database_file));
324
+				} catch(PDOException $e) {
325
+						return "error : ".$e->getMessage();
326
+				}
327 327
 		return '';
328 328
 	}
329 329
 
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
 		try {
335 335
 			$Connection = new Connection();
336 336
 			$sth = $Connection->db->prepare($query);
337
-                        $sth->execute(array(':source' => $database_file));
338
-                } catch(PDOException $e) {
339
-                        return "error : ".$e->getMessage();
340
-                }
337
+						$sth->execute(array(':source' => $database_file));
338
+				} catch(PDOException $e) {
339
+						return "error : ".$e->getMessage();
340
+				}
341 341
 		
342 342
 		if ($fh = fopen($database_file,"r")) {
343 343
 			//$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)';
@@ -348,24 +348,24 @@  discard block
 block discarded – undo
348 348
 			try {
349 349
 				if ($globalTransaction) $Connection->db->beginTransaction();
350 350
 				$tmp = fgetcsv($fh,9999,',',"'");
351
-            			while (!feof($fh)) {
352
-            				$line = fgetcsv($fh,9999,',',"'");
351
+						while (!feof($fh)) {
352
+							$line = fgetcsv($fh,9999,',',"'");
353 353
             				
354 354
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
355 355
 					//print_r($line);
356
-            				$values['ModeS'] = $line[1];
357
-            				$values['Registration'] = $line[3];
358
-            				$aircraft_name = $line[2];
359
-            				// Check if we can find ICAO, else set it to GLID
360
-            				$aircraft_name_split = explode(' ',$aircraft_name);
361
-            				$search_more = '';
362
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
363
-            				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
364
-            				$sth_search = $Connection->db->prepare($query_search);
356
+							$values['ModeS'] = $line[1];
357
+							$values['Registration'] = $line[3];
358
+							$aircraft_name = $line[2];
359
+							// Check if we can find ICAO, else set it to GLID
360
+							$aircraft_name_split = explode(' ',$aircraft_name);
361
+							$search_more = '';
362
+							if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
363
+							$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
364
+							$sth_search = $Connection->db->prepare($query_search);
365 365
 					try {
366
-                                    		$sth_search->execute();
367
-	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
368
-	            				if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
366
+											$sth_search->execute();
367
+								$result = $sth_search->fetch(PDO::FETCH_ASSOC);
368
+								if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
369 369
 					} catch(PDOException $e) {
370 370
 						return "error : ".$e->getMessage();
371 371
 					}
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
 		try {
389 389
 			$Connection = new Connection();
390 390
 			$sth = $Connection->db->prepare($query);
391
-                        $sth->execute(array(':source' => $database_file));
392
-                } catch(PDOException $e) {
393
-                        return "error : ".$e->getMessage();
394
-                }
391
+						$sth->execute(array(':source' => $database_file));
392
+				} catch(PDOException $e) {
393
+						return "error : ".$e->getMessage();
394
+				}
395 395
 		return '';
396 396
 	}
397 397
 
@@ -402,10 +402,10 @@  discard block
 block discarded – undo
402 402
 		try {
403 403
 			$Connection = new Connection();
404 404
 			$sth = $Connection->db->prepare($query);
405
-                        $sth->execute(array(':source' => $database_file));
406
-                } catch(PDOException $e) {
407
-                        return "error : ".$e->getMessage();
408
-                }
405
+						$sth->execute(array(':source' => $database_file));
406
+				} catch(PDOException $e) {
407
+						return "error : ".$e->getMessage();
408
+				}
409 409
 		
410 410
 		if ($fh = fopen($database_file,"r")) {
411 411
 			//$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)';
@@ -416,95 +416,95 @@  discard block
 block discarded – undo
416 416
 			try {
417 417
 				if ($globalTransaction) $Connection->db->beginTransaction();
418 418
 				$tmp = fgetcsv($fh,9999,',','"');
419
-            			while (!feof($fh)) {
420
-            				$line = fgetcsv($fh,9999,',','"');
421
-            				$values = array();
422
-            				//print_r($line);
423
-            				if ($country == 'F') {
424
-            				    $values['registration'] = $line[0];
425
-            				    $values['base'] = $line[4];
426
-            				    $values['owner'] = $line[5];
427
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
428
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
429
-					    $values['cancel'] = $line[7];
419
+						while (!feof($fh)) {
420
+							$line = fgetcsv($fh,9999,',','"');
421
+							$values = array();
422
+							//print_r($line);
423
+							if ($country == 'F') {
424
+								$values['registration'] = $line[0];
425
+								$values['base'] = $line[4];
426
+								$values['owner'] = $line[5];
427
+								if ($line[6] == '') $values['date_first_reg'] = null;
428
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
429
+						$values['cancel'] = $line[7];
430 430
 					} elseif ($country == 'EI') {
431
-					    // TODO : add modeS & reg to aircraft_modes
432
-            				    $values['registration'] = $line[0];
433
-            				    $values['base'] = $line[3];
434
-            				    $values['owner'] = $line[2];
435
-            				    if ($line[1] == '') $values['date_first_reg'] = null;
436
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
437
-					    $values['cancel'] = '';
431
+						// TODO : add modeS & reg to aircraft_modes
432
+								$values['registration'] = $line[0];
433
+								$values['base'] = $line[3];
434
+								$values['owner'] = $line[2];
435
+								if ($line[1] == '') $values['date_first_reg'] = null;
436
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
437
+						$values['cancel'] = '';
438 438
 					} elseif ($country == 'HB') {
439
-					    // TODO : add modeS & reg to aircraft_modes
440
-            				    $values['registration'] = $line[0];
441
-            				    $values['base'] = null;
442
-            				    $values['owner'] = $line[5];
443
-            				    $values['date_first_reg'] = null;
444
-					    $values['cancel'] = '';
439
+						// TODO : add modeS & reg to aircraft_modes
440
+								$values['registration'] = $line[0];
441
+								$values['base'] = null;
442
+								$values['owner'] = $line[5];
443
+								$values['date_first_reg'] = null;
444
+						$values['cancel'] = '';
445 445
 					} elseif ($country == 'OK') {
446
-					    // TODO : add modeS & reg to aircraft_modes
447
-            				    $values['registration'] = $line[3];
448
-            				    $values['base'] = null;
449
-            				    $values['owner'] = $line[5];
450
-            				    if ($line[18] == '') $values['date_first_reg'] = null;
451
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
452
-					    $values['cancel'] = '';
446
+						// TODO : add modeS & reg to aircraft_modes
447
+								$values['registration'] = $line[3];
448
+								$values['base'] = null;
449
+								$values['owner'] = $line[5];
450
+								if ($line[18] == '') $values['date_first_reg'] = null;
451
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
452
+						$values['cancel'] = '';
453 453
 					} elseif ($country == 'VH') {
454
-					    // TODO : add modeS & reg to aircraft_modes
455
-            				    $values['registration'] = $line[0];
456
-            				    $values['base'] = null;
457
-            				    $values['owner'] = $line[12];
458
-            				    if ($line[28] == '') $values['date_first_reg'] = null;
459
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
460
-
461
-					    $values['cancel'] = $line[39];
454
+						// TODO : add modeS & reg to aircraft_modes
455
+								$values['registration'] = $line[0];
456
+								$values['base'] = null;
457
+								$values['owner'] = $line[12];
458
+								if ($line[28] == '') $values['date_first_reg'] = null;
459
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
460
+
461
+						$values['cancel'] = $line[39];
462 462
 					} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') {
463
-            				    $values['registration'] = $line[0];
464
-            				    $values['base'] = null;
465
-            				    $values['owner'] = $line[4];
466
-            				    $values['date_first_reg'] = null;
467
-					    $values['cancel'] = '';
463
+								$values['registration'] = $line[0];
464
+								$values['base'] = null;
465
+								$values['owner'] = $line[4];
466
+								$values['date_first_reg'] = null;
467
+						$values['cancel'] = '';
468 468
 					} elseif ($country == 'CC') {
469
-            				    $values['registration'] = $line[0];
470
-            				    $values['base'] = null;
471
-            				    $values['owner'] = $line[6];
472
-            				    $values['date_first_reg'] = null;
473
-					    $values['cancel'] = '';
469
+								$values['registration'] = $line[0];
470
+								$values['base'] = null;
471
+								$values['owner'] = $line[6];
472
+								$values['date_first_reg'] = null;
473
+						$values['cancel'] = '';
474 474
 					} elseif ($country == 'HJ') {
475
-            				    $values['registration'] = $line[0];
476
-            				    $values['base'] = null;
477
-            				    $values['owner'] = $line[8];
478
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
479
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
480
-					    $values['cancel'] = '';
475
+								$values['registration'] = $line[0];
476
+								$values['base'] = null;
477
+								$values['owner'] = $line[8];
478
+								if ($line[7] == '') $values['date_first_reg'] = null;
479
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
480
+						$values['cancel'] = '';
481 481
 					} elseif ($country == 'PP') {
482
-            				    $values['registration'] = $line[0];
483
-            				    $values['base'] = null;
484
-            				    $values['owner'] = $line[4];
485
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
486
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
487
-					    $values['cancel'] = $line[7];
482
+								$values['registration'] = $line[0];
483
+								$values['base'] = null;
484
+								$values['owner'] = $line[4];
485
+								if ($line[6] == '') $values['date_first_reg'] = null;
486
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
487
+						$values['cancel'] = $line[7];
488 488
 					} elseif ($country == 'E7') {
489
-            				    $values['registration'] = $line[0];
490
-            				    $values['base'] = null;
491
-            				    $values['owner'] = $line[4];
492
-            				    if ($line[5] == '') $values['date_first_reg'] = null;
493
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
494
-					    $values['cancel'] = '';
489
+								$values['registration'] = $line[0];
490
+								$values['base'] = null;
491
+								$values['owner'] = $line[4];
492
+								if ($line[5] == '') $values['date_first_reg'] = null;
493
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
494
+						$values['cancel'] = '';
495 495
 					} elseif ($country == '8Q') {
496
-            				    $values['registration'] = $line[0];
497
-            				    $values['base'] = null;
498
-            				    $values['owner'] = $line[3];
499
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
500
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
501
-					    $values['cancel'] = '';
496
+								$values['registration'] = $line[0];
497
+								$values['base'] = null;
498
+								$values['owner'] = $line[3];
499
+								if ($line[7] == '') $values['date_first_reg'] = null;
500
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
501
+						$values['cancel'] = '';
502 502
 					} elseif ($country == 'ZK' || $country == 'OM' || $country == 'TF') {
503
-            				    $values['registration'] = $line[0];
504
-            				    $values['base'] = null;
505
-            				    $values['owner'] = $line[3];
506
-            				    $values['date_first_reg'] = null;
507
-					    $values['cancel'] = '';
503
+								$values['registration'] = $line[0];
504
+								$values['base'] = null;
505
+								$values['owner'] = $line[3];
506
+								$values['date_first_reg'] = null;
507
+						$values['cancel'] = '';
508 508
 					}
509 509
 					if ($values['cancel'] == '' && $values['registration'] != null) {
510 510
 						$query_dest_values = array(':registration' => $values['registration'],':base' => $values['base'],':date_first_reg' => $values['date_first_reg'],':owner' => $values['owner'],':source' => $database_file);
@@ -626,20 +626,20 @@  discard block
 block discarded – undo
626 626
 		try {
627 627
 			$Connection = new Connection();
628 628
 			$sth = $Connection->db->prepare($query);
629
-                        $sth->execute();
630
-                } catch(PDOException $e) {
631
-                        return "error : ".$e->getMessage();
632
-                }
629
+						$sth->execute();
630
+				} catch(PDOException $e) {
631
+						return "error : ".$e->getMessage();
632
+				}
633 633
 
634 634
 
635 635
 		$query = 'ALTER TABLE airport DROP INDEX icaoidx';
636 636
 		try {
637 637
 			$Connection = new Connection();
638 638
 			$sth = $Connection->db->prepare($query);
639
-                        $sth->execute();
640
-                } catch(PDOException $e) {
641
-                        return "error : ".$e->getMessage();
642
-                }
639
+						$sth->execute();
640
+				} catch(PDOException $e) {
641
+						return "error : ".$e->getMessage();
642
+				}
643 643
 
644 644
 		$query_dest = "INSERT INTO airport (`airport_id`,`name`,`city`,`country`,`iata`,`icao`,`latitude`,`longitude`,`altitude`,`type`,`home_link`,`wikipedia_link`,`image_thumb`,`image`)
645 645
 		    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image_thumb, :image)";
@@ -705,10 +705,10 @@  discard block
 block discarded – undo
705 705
 		try {
706 706
 			$Connection = new Connection();
707 707
 			$sth = $Connection->db->prepare($query);
708
-                        $sth->execute();
709
-                } catch(PDOException $e) {
710
-                        return "error : ".$e->getMessage();
711
-                }
708
+						$sth->execute();
709
+				} catch(PDOException $e) {
710
+						return "error : ".$e->getMessage();
711
+				}
712 712
 
713 713
 
714 714
 		if ($globalDebug) echo "Insert Not available Airport...\n";
@@ -718,10 +718,10 @@  discard block
 block discarded – undo
718 718
 		try {
719 719
 			$Connection = new Connection();
720 720
 			$sth = $Connection->db->prepare($query);
721
-                        $sth->execute($query_values);
722
-                } catch(PDOException $e) {
723
-                        return "error : ".$e->getMessage();
724
-                }
721
+						$sth->execute($query_values);
722
+				} catch(PDOException $e) {
723
+						return "error : ".$e->getMessage();
724
+				}
725 725
 		$i++;
726 726
 /*
727 727
 		$query = 'DELETE FROM airport WHERE airport_id IN (SELECT * FROM (SELECT min(a.airport_id) FROM airport a GROUP BY a.icao) x)';
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 
836 836
 
837 837
 
838
-                return "success";
838
+				return "success";
839 839
 	}
840 840
 	
841 841
 	public static function translation() {
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
 		try {
852 852
 			$Connection = new Connection();
853 853
 			$sth = $Connection->db->prepare($query);
854
-                        $sth->execute(array(':source' => 'translation.csv'));
855
-                } catch(PDOException $e) {
856
-                        return "error : ".$e->getMessage();
857
-                }
854
+						$sth->execute(array(':source' => 'translation.csv'));
855
+				} catch(PDOException $e) {
856
+						return "error : ".$e->getMessage();
857
+				}
858 858
 
859 859
 		
860 860
 		//update_db::unzip($out_file);
@@ -873,21 +873,21 @@  discard block
 block discarded – undo
873 873
 					$data = $row;
874 874
 					$operator = $data[2];
875 875
 					if ($operator != '' && is_numeric(substr(substr($operator, 0, 3), -1, 1))) {
876
-                                                $airline_array = $Spotter->getAllAirlineInfo(substr($operator, 0, 2));
877
-                                                //echo substr($operator, 0, 2)."\n";;
878
-                                                if (count($airline_array) > 0) {
876
+												$airline_array = $Spotter->getAllAirlineInfo(substr($operator, 0, 2));
877
+												//echo substr($operator, 0, 2)."\n";;
878
+												if (count($airline_array) > 0) {
879 879
 							//print_r($airline_array);
880 880
 							$operator = $airline_array[0]['icao'].substr($operator,2);
881
-                                                }
882
-                                        }
881
+												}
882
+										}
883 883
 					
884 884
 					$operator_correct = $data[3];
885 885
 					if ($operator_correct != '' && is_numeric(substr(substr($operator_correct, 0, 3), -1, 1))) {
886
-                                                $airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2));
887
-                                                if (count($airline_array) > 0) {
888
-                                            		$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2);
889
-                                            	}
890
-                                        }
886
+												$airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2));
887
+												if (count($airline_array) > 0) {
888
+													$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2);
889
+												}
890
+										}
891 891
 					$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)';
892 892
 					try {
893 893
 						$sth = $Connection->db->prepare($query);
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
 			//$Connection->db->commit();
902 902
 		}
903 903
 		return '';
904
-        }
904
+		}
905 905
 	
906 906
 	public static function translation_fam() {
907 907
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
@@ -911,10 +911,10 @@  discard block
 block discarded – undo
911 911
 		try {
912 912
 			$Connection = new Connection();
913 913
 			$sth = $Connection->db->prepare($query);
914
-                        $sth->execute(array(':source' => 'website_fam'));
915
-                } catch(PDOException $e) {
916
-                        return "error : ".$e->getMessage();
917
-                }
914
+						$sth->execute(array(':source' => 'website_fam'));
915
+				} catch(PDOException $e) {
916
+						return "error : ".$e->getMessage();
917
+				}
918 918
 
919 919
 		
920 920
 		//update_db::unzip($out_file);
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
 			//$Connection->db->commit();
944 944
 		}
945 945
 		return '';
946
-        }
946
+		}
947 947
 
948 948
 	public static function modes_faa() {
949 949
 		global $tmp_dir, $globalTransaction;
@@ -951,19 +951,19 @@  discard block
 block discarded – undo
951 951
 		try {
952 952
 			$Connection = new Connection();
953 953
 			$sth = $Connection->db->prepare($query);
954
-                        $sth->execute(array(':source' => 'website_faa'));
955
-                } catch(PDOException $e) {
956
-                        return "error : ".$e->getMessage();
957
-                }
954
+						$sth->execute(array(':source' => 'website_faa'));
955
+				} catch(PDOException $e) {
956
+						return "error : ".$e->getMessage();
957
+				}
958 958
 
959 959
 		$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source = :source";
960 960
 		try {
961 961
 			$Connection = new Connection();
962 962
 			$sth = $Connection->db->prepare($query);
963
-                        $sth->execute(array(':source' => 'website_faa'));
964
-                } catch(PDOException $e) {
965
-                        return "error : ".$e->getMessage();
966
-                }
963
+						$sth->execute(array(':source' => 'website_faa'));
964
+				} catch(PDOException $e) {
965
+						return "error : ".$e->getMessage();
966
+				}
967 967
 
968 968
 		
969 969
 		//$aircrafts_icao = array('7102811' => 'P28R',...
@@ -1001,17 +1001,17 @@  discard block
 block discarded – undo
1001 1001
 			if ($globalTransaction) $Connection->db->commit();
1002 1002
 		}
1003 1003
 		return '';
1004
-        }
1004
+		}
1005 1005
 	public static function modes_fam() {
1006 1006
 		global $tmp_dir, $globalTransaction;
1007 1007
 		$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source = :source";
1008 1008
 		try {
1009 1009
 			$Connection = new Connection();
1010 1010
 			$sth = $Connection->db->prepare($query);
1011
-                        $sth->execute(array(':source' => 'website_fam'));
1012
-                } catch(PDOException $e) {
1013
-                        return "error : ".$e->getMessage();
1014
-                }
1011
+						$sth->execute(array(':source' => 'website_fam'));
1012
+				} catch(PDOException $e) {
1013
+						return "error : ".$e->getMessage();
1014
+				}
1015 1015
 
1016 1016
 		
1017 1017
 		//update_db::unzip($out_file);
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 			if ($globalTransaction) $Connection->db->commit();
1041 1041
 		}
1042 1042
 		return '';
1043
-        }
1043
+		}
1044 1044
         
1045 1045
 	public static function owner_fam() {
1046 1046
 		global $tmp_dir, $globalTransaction;
@@ -1048,10 +1048,10 @@  discard block
 block discarded – undo
1048 1048
 		try {
1049 1049
 			$Connection = new Connection();
1050 1050
 			$sth = $Connection->db->prepare($query);
1051
-                        $sth->execute(array(':source' => 'website_fam'));
1052
-                } catch(PDOException $e) {
1053
-                        return "error : ".$e->getMessage();
1054
-                }
1051
+						$sth->execute(array(':source' => 'website_fam'));
1052
+				} catch(PDOException $e) {
1053
+						return "error : ".$e->getMessage();
1054
+				}
1055 1055
 
1056 1056
 		$delimiter = "\t";
1057 1057
 		$Connection = new Connection();
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
 			if ($globalTransaction) $Connection->db->commit();
1078 1078
 		}
1079 1079
 		return '';
1080
-        }
1080
+		}
1081 1081
 
1082 1082
 	public static function routes_fam() {
1083 1083
 		global $tmp_dir, $globalTransaction;
@@ -1085,10 +1085,10 @@  discard block
 block discarded – undo
1085 1085
 		try {
1086 1086
 			$Connection = new Connection();
1087 1087
 			$sth = $Connection->db->prepare($query);
1088
-                        $sth->execute(array(':source' => 'website_fam'));
1089
-                } catch(PDOException $e) {
1090
-                        return "error : ".$e->getMessage();
1091
-                }
1088
+						$sth->execute(array(':source' => 'website_fam'));
1089
+				} catch(PDOException $e) {
1090
+						return "error : ".$e->getMessage();
1091
+				}
1092 1092
 
1093 1093
 		
1094 1094
 		//update_db::unzip($out_file);
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
 			if ($globalTransaction) $Connection->db->commit();
1118 1118
 		}
1119 1119
 		return '';
1120
-        }
1120
+		}
1121 1121
 
1122 1122
 	public static function tle($filename,$tletype) {
1123 1123
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
@@ -1128,10 +1128,10 @@  discard block
 block discarded – undo
1128 1128
 		try {
1129 1129
 			$Connection = new Connection();
1130 1130
 			$sth = $Connection->db->prepare($query);
1131
-                        $sth->execute(array(':source' => $filename));
1132
-                } catch(PDOException $e) {
1133
-                        return "error : ".$e->getMessage();
1134
-                }
1131
+						$sth->execute(array(':source' => $filename));
1132
+				} catch(PDOException $e) {
1133
+						return "error : ".$e->getMessage();
1134
+				}
1135 1135
 		
1136 1136
 		$Connection = new Connection();
1137 1137
 		if (($handle = fopen($filename, 'r')) !== FALSE)
@@ -1166,54 +1166,54 @@  discard block
 block discarded – undo
1166 1166
 			//$Connection->db->commit();
1167 1167
 		}
1168 1168
 		return '';
1169
-        }
1169
+		}
1170 1170
 
1171 1171
 	/**
1172
-        * Convert a HTML table to an array
1173
-        * @param String $data HTML page
1174
-        * @return Array array of the tables in HTML page
1175
-        */
1176
-        private static function table2array($data) {
1177
-                $html = str_get_html($data);
1178
-                $tabledata=array();
1179
-                foreach($html->find('tr') as $element)
1180
-                {
1181
-                        $td = array();
1182
-                        foreach( $element->find('th') as $row)
1183
-                        {
1184
-                                $td [] = trim($row->plaintext);
1185
-                        }
1186
-                        $td=array_filter($td);
1187
-                        $tabledata[] = $td;
1188
-
1189
-                        $td = array();
1190
-                        $tdi = array();
1191
-                        foreach( $element->find('td') as $row)
1192
-                        {
1193
-                                $td [] = trim($row->plaintext);
1194
-                                $tdi [] = trim($row->innertext);
1195
-                        }
1196
-                        $td=array_filter($td);
1197
-                        $tdi=array_filter($tdi);
1198
-                    //    $tabledata[]=array_merge($td,$tdi);
1199
-                        $tabledata[]=$td;
1200
-                }
1201
-                return(array_filter($tabledata));
1202
-        }
1203
-
1204
-       /**
1205
-        * Get data from form result
1206
-        * @param String $url form URL
1207
-        * @return String the result
1208
-        */
1209
-        private static function getData($url) {
1210
-                $ch = curl_init();
1211
-                curl_setopt($ch, CURLOPT_URL, $url);
1212
-                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1213
-                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
1214
-                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');
1215
-                return curl_exec($ch);
1216
-        }
1172
+	 * Convert a HTML table to an array
1173
+	 * @param String $data HTML page
1174
+	 * @return Array array of the tables in HTML page
1175
+	 */
1176
+		private static function table2array($data) {
1177
+				$html = str_get_html($data);
1178
+				$tabledata=array();
1179
+				foreach($html->find('tr') as $element)
1180
+				{
1181
+						$td = array();
1182
+						foreach( $element->find('th') as $row)
1183
+						{
1184
+								$td [] = trim($row->plaintext);
1185
+						}
1186
+						$td=array_filter($td);
1187
+						$tabledata[] = $td;
1188
+
1189
+						$td = array();
1190
+						$tdi = array();
1191
+						foreach( $element->find('td') as $row)
1192
+						{
1193
+								$td [] = trim($row->plaintext);
1194
+								$tdi [] = trim($row->innertext);
1195
+						}
1196
+						$td=array_filter($td);
1197
+						$tdi=array_filter($tdi);
1198
+					//    $tabledata[]=array_merge($td,$tdi);
1199
+						$tabledata[]=$td;
1200
+				}
1201
+				return(array_filter($tabledata));
1202
+		}
1203
+
1204
+	   /**
1205
+	    * Get data from form result
1206
+	    * @param String $url form URL
1207
+	    * @return String the result
1208
+	    */
1209
+		private static function getData($url) {
1210
+				$ch = curl_init();
1211
+				curl_setopt($ch, CURLOPT_URL, $url);
1212
+				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1213
+				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
1214
+				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');
1215
+				return curl_exec($ch);
1216
+		}
1217 1217
 /*
1218 1218
 	public static function waypoints() {
1219 1219
 		$data = update_db::getData('http://www.fallingrain.com/world/FR/waypoints.html');
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
 			if ($globalTransaction) $Connection->db->commit();
1297 1297
 		}
1298 1298
 		return '';
1299
-        }
1299
+		}
1300 1300
 
1301 1301
 	public static function ivao_airlines($filename) {
1302 1302
 		//require_once(dirname(__FILE__).'/../require/class.Spotter.php');
@@ -1306,10 +1306,10 @@  discard block
 block discarded – undo
1306 1306
 		try {
1307 1307
 			$Connection = new Connection();
1308 1308
 			$sth = $Connection->db->prepare($query);
1309
-                        $sth->execute();
1310
-                } catch(PDOException $e) {
1311
-                        return "error : ".$e->getMessage();
1312
-                }
1309
+						$sth->execute();
1310
+				} catch(PDOException $e) {
1311
+						return "error : ".$e->getMessage();
1312
+				}
1313 1313
 
1314 1314
 		$header = NULL;
1315 1315
 		$delimiter = ':';
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
 			if ($globalTransaction) $Connection->db->commit();
1334 1334
 		}
1335 1335
 		return '';
1336
-        }
1336
+		}
1337 1337
 	
1338 1338
 	public static function update_airspace() {
1339 1339
 		global $tmp_dir, $globalDBdriver;
@@ -1343,11 +1343,11 @@  discard block
 block discarded – undo
1343 1343
 			$query = 'DROP TABLE airspace';
1344 1344
 			try {
1345 1345
 				$sth = $Connection->db->prepare($query);
1346
-                    		$sth->execute();
1347
-	                } catch(PDOException $e) {
1346
+							$sth->execute();
1347
+					} catch(PDOException $e) {
1348 1348
 				return "error : ".$e->getMessage();
1349
-	                }
1350
-	        }
1349
+					}
1350
+			}
1351 1351
 
1352 1352
 
1353 1353
 		if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
@@ -1402,10 +1402,10 @@  discard block
 block discarded – undo
1402 1402
 			$query = 'DROP TABLE countries';
1403 1403
 			try {
1404 1404
 				$sth = $Connection->db->prepare($query);
1405
-            	        	$sth->execute();
1406
-	                } catch(PDOException $e) {
1407
-    	                	echo "error : ".$e->getMessage();
1408
-	                }
1405
+							$sth->execute();
1406
+					} catch(PDOException $e) {
1407
+							echo "error : ".$e->getMessage();
1408
+					}
1409 1409
 		}
1410 1410
 		if ($globalDBdriver == 'mysql') {
1411 1411
 			update_db::gunzip('../db/countries.sql.gz',$tmp_dir.'countries.sql');
@@ -1865,11 +1865,11 @@  discard block
 block discarded – undo
1865 1865
 						$query = 'DROP TABLE airspace';
1866 1866
 						try {
1867 1867
 							$sth = $Connection->db->prepare($query);
1868
-    	    	    					$sth->execute();
1869
-			            		} catch(PDOException $e) {
1868
+										$sth->execute();
1869
+								} catch(PDOException $e) {
1870 1870
 							return "error : ".$e->getMessage();
1871
-		            			}
1872
-		    			}
1871
+								}
1872
+						}
1873 1873
 					$error = create_db::import_file($tmp_dir.'airspace.sql');
1874 1874
 					update_db::insert_airspace_version($airspace_md5);
1875 1875
 				} else $error = "File ".$tmp_dir.'airpsace.sql.gz'." doesn't exist. Download failed.";
@@ -1989,12 +1989,12 @@  discard block
 block discarded – undo
1989 1989
 		echo $data;
1990 1990
 		*/
1991 1991
 		if (file_exists($tmp_dir.'aircrafts.html')) {
1992
-		    //var_dump(file_get_html($tmp_dir.'aircrafts.html'));
1993
-		    $fh = fopen($tmp_dir.'aircrafts.html',"r");
1994
-		    $result = fread($fh,100000000);
1995
-		    //echo $result;
1996
-		    //var_dump(str_get_html($result));
1997
-		    //print_r(self::table2array($result));
1992
+			//var_dump(file_get_html($tmp_dir.'aircrafts.html'));
1993
+			$fh = fopen($tmp_dir.'aircrafts.html',"r");
1994
+			$result = fread($fh,100000000);
1995
+			//echo $result;
1996
+			//var_dump(str_get_html($result));
1997
+			//print_r(self::table2array($result));
1998 1998
 		}
1999 1999
 
2000 2000
 	}
@@ -2008,10 +2008,10 @@  discard block
 block discarded – undo
2008 2008
 		try {
2009 2009
 			$Connection = new Connection();
2010 2010
 			$sth = $Connection->db->prepare($query);
2011
-                        $sth->execute();
2012
-                } catch(PDOException $e) {
2013
-                        return "error : ".$e->getMessage();
2014
-                }
2011
+						$sth->execute();
2012
+				} catch(PDOException $e) {
2013
+						return "error : ".$e->getMessage();
2014
+				}
2015 2015
 
2016 2016
 		$error = '';
2017 2017
 		if ($globalDebug) echo "Notam : Download...";
@@ -2067,8 +2067,8 @@  discard block
 block discarded – undo
2067 2067
 					$data['date_end'] = date("Y-m-d H:i:s",strtotime($to));
2068 2068
 					$data['permanent'] = 0;
2069 2069
 				} else {
2070
-				    $data['date_end'] = NULL;
2071
-				    $data['permanent'] = 1;
2070
+					$data['date_end'] = NULL;
2071
+					$data['permanent'] = 1;
2072 2072
 				}
2073 2073
 				$data['full_notam'] = $notam['title'].'<br>'.$notam['description'];
2074 2074
 				$NOTAM = new NOTAM();
@@ -2127,13 +2127,13 @@  discard block
 block discarded – undo
2127 2127
 		try {
2128 2128
 			$Connection = new Connection();
2129 2129
 			$sth = $Connection->db->prepare($query);
2130
-                        $sth->execute();
2131
-                } catch(PDOException $e) {
2132
-                        return "error : ".$e->getMessage();
2133
-                }
2134
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2135
-                if ($row['nb'] > 0) return false;
2136
-                else return true;
2130
+						$sth->execute();
2131
+				} catch(PDOException $e) {
2132
+						return "error : ".$e->getMessage();
2133
+				}
2134
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2135
+				if ($row['nb'] > 0) return false;
2136
+				else return true;
2137 2137
 	}
2138 2138
 
2139 2139
 	public static function insert_last_update() {
@@ -2142,10 +2142,10 @@  discard block
 block discarded – undo
2142 2142
 		try {
2143 2143
 			$Connection = new Connection();
2144 2144
 			$sth = $Connection->db->prepare($query);
2145
-                        $sth->execute();
2146
-                } catch(PDOException $e) {
2147
-                        return "error : ".$e->getMessage();
2148
-                }
2145
+						$sth->execute();
2146
+				} catch(PDOException $e) {
2147
+						return "error : ".$e->getMessage();
2148
+				}
2149 2149
 	}
2150 2150
 
2151 2151
 	public static function check_airspace_version($version) {
@@ -2153,13 +2153,13 @@  discard block
 block discarded – undo
2153 2153
 		try {
2154 2154
 			$Connection = new Connection();
2155 2155
 			$sth = $Connection->db->prepare($query);
2156
-                        $sth->execute(array(':version' => $version));
2157
-                } catch(PDOException $e) {
2158
-                        return "error : ".$e->getMessage();
2159
-                }
2160
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2161
-                if ($row['nb'] > 0) return true;
2162
-                else return false;
2156
+						$sth->execute(array(':version' => $version));
2157
+				} catch(PDOException $e) {
2158
+						return "error : ".$e->getMessage();
2159
+				}
2160
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2161
+				if ($row['nb'] > 0) return true;
2162
+				else return false;
2163 2163
 	}
2164 2164
 
2165 2165
 
@@ -2169,10 +2169,10 @@  discard block
 block discarded – undo
2169 2169
 		try {
2170 2170
 			$Connection = new Connection();
2171 2171
 			$sth = $Connection->db->prepare($query);
2172
-                        $sth->execute(array(':version' => $version));
2173
-                } catch(PDOException $e) {
2174
-                        return "error : ".$e->getMessage();
2175
-                }
2172
+						$sth->execute(array(':version' => $version));
2173
+				} catch(PDOException $e) {
2174
+						return "error : ".$e->getMessage();
2175
+				}
2176 2176
 	}
2177 2177
 
2178 2178
 	public static function check_last_notam_update() {
@@ -2185,13 +2185,13 @@  discard block
 block discarded – undo
2185 2185
 		try {
2186 2186
 			$Connection = new Connection();
2187 2187
 			$sth = $Connection->db->prepare($query);
2188
-                        $sth->execute();
2189
-                } catch(PDOException $e) {
2190
-                        return "error : ".$e->getMessage();
2191
-                }
2192
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2193
-                if ($row['nb'] > 0) return false;
2194
-                else return true;
2188
+						$sth->execute();
2189
+				} catch(PDOException $e) {
2190
+						return "error : ".$e->getMessage();
2191
+				}
2192
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2193
+				if ($row['nb'] > 0) return false;
2194
+				else return true;
2195 2195
 	}
2196 2196
 
2197 2197
 	public static function insert_last_notam_update() {
@@ -2200,10 +2200,10 @@  discard block
 block discarded – undo
2200 2200
 		try {
2201 2201
 			$Connection = new Connection();
2202 2202
 			$sth = $Connection->db->prepare($query);
2203
-                        $sth->execute();
2204
-                } catch(PDOException $e) {
2205
-                        return "error : ".$e->getMessage();
2206
-                }
2203
+						$sth->execute();
2204
+				} catch(PDOException $e) {
2205
+						return "error : ".$e->getMessage();
2206
+				}
2207 2207
 	}
2208 2208
 	public static function check_last_airspace_update() {
2209 2209
 		global $globalDBdriver;
@@ -2215,13 +2215,13 @@  discard block
 block discarded – undo
2215 2215
 		try {
2216 2216
 			$Connection = new Connection();
2217 2217
 			$sth = $Connection->db->prepare($query);
2218
-                        $sth->execute();
2219
-                } catch(PDOException $e) {
2220
-                        return "error : ".$e->getMessage();
2221
-                }
2222
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2223
-                if ($row['nb'] > 0) return false;
2224
-                else return true;
2218
+						$sth->execute();
2219
+				} catch(PDOException $e) {
2220
+						return "error : ".$e->getMessage();
2221
+				}
2222
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2223
+				if ($row['nb'] > 0) return false;
2224
+				else return true;
2225 2225
 	}
2226 2226
 
2227 2227
 	public static function insert_last_airspace_update() {
@@ -2230,10 +2230,10 @@  discard block
 block discarded – undo
2230 2230
 		try {
2231 2231
 			$Connection = new Connection();
2232 2232
 			$sth = $Connection->db->prepare($query);
2233
-                        $sth->execute();
2234
-                } catch(PDOException $e) {
2235
-                        return "error : ".$e->getMessage();
2236
-                }
2233
+						$sth->execute();
2234
+				} catch(PDOException $e) {
2235
+						return "error : ".$e->getMessage();
2236
+				}
2237 2237
 	}
2238 2238
 
2239 2239
 	public static function check_last_owner_update() {
@@ -2246,13 +2246,13 @@  discard block
 block discarded – undo
2246 2246
 		try {
2247 2247
 			$Connection = new Connection();
2248 2248
 			$sth = $Connection->db->prepare($query);
2249
-                        $sth->execute();
2250
-                } catch(PDOException $e) {
2251
-                        return "error : ".$e->getMessage();
2252
-                }
2253
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2254
-                if ($row['nb'] > 0) return false;
2255
-                else return true;
2249
+						$sth->execute();
2250
+				} catch(PDOException $e) {
2251
+						return "error : ".$e->getMessage();
2252
+				}
2253
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2254
+				if ($row['nb'] > 0) return false;
2255
+				else return true;
2256 2256
 	}
2257 2257
 
2258 2258
 	public static function insert_last_owner_update() {
@@ -2261,10 +2261,10 @@  discard block
 block discarded – undo
2261 2261
 		try {
2262 2262
 			$Connection = new Connection();
2263 2263
 			$sth = $Connection->db->prepare($query);
2264
-                        $sth->execute();
2265
-                } catch(PDOException $e) {
2266
-                        return "error : ".$e->getMessage();
2267
-                }
2264
+						$sth->execute();
2265
+				} catch(PDOException $e) {
2266
+						return "error : ".$e->getMessage();
2267
+				}
2268 2268
 	}
2269 2269
 	public static function check_last_schedules_update() {
2270 2270
 		global $globalDBdriver;
@@ -2276,13 +2276,13 @@  discard block
 block discarded – undo
2276 2276
 		try {
2277 2277
 			$Connection = new Connection();
2278 2278
 			$sth = $Connection->db->prepare($query);
2279
-                        $sth->execute();
2280
-                } catch(PDOException $e) {
2281
-                        return "error : ".$e->getMessage();
2282
-                }
2283
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2284
-                if ($row['nb'] > 0) return false;
2285
-                else return true;
2279
+						$sth->execute();
2280
+				} catch(PDOException $e) {
2281
+						return "error : ".$e->getMessage();
2282
+				}
2283
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2284
+				if ($row['nb'] > 0) return false;
2285
+				else return true;
2286 2286
 	}
2287 2287
 
2288 2288
 	public static function insert_last_schedules_update() {
@@ -2291,10 +2291,10 @@  discard block
 block discarded – undo
2291 2291
 		try {
2292 2292
 			$Connection = new Connection();
2293 2293
 			$sth = $Connection->db->prepare($query);
2294
-                        $sth->execute();
2295
-                } catch(PDOException $e) {
2296
-                        return "error : ".$e->getMessage();
2297
-                }
2294
+						$sth->execute();
2295
+				} catch(PDOException $e) {
2296
+						return "error : ".$e->getMessage();
2297
+				}
2298 2298
 	}
2299 2299
 	public static function check_last_tle_update() {
2300 2300
 		global $globalDBdriver;
@@ -2306,13 +2306,13 @@  discard block
 block discarded – undo
2306 2306
 		try {
2307 2307
 			$Connection = new Connection();
2308 2308
 			$sth = $Connection->db->prepare($query);
2309
-                        $sth->execute();
2310
-                } catch(PDOException $e) {
2311
-                        return "error : ".$e->getMessage();
2312
-                }
2313
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
2314
-                if ($row['nb'] > 0) return false;
2315
-                else return true;
2309
+						$sth->execute();
2310
+				} catch(PDOException $e) {
2311
+						return "error : ".$e->getMessage();
2312
+				}
2313
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
2314
+				if ($row['nb'] > 0) return false;
2315
+				else return true;
2316 2316
 	}
2317 2317
 
2318 2318
 	public static function insert_last_tle_update() {
@@ -2321,10 +2321,10 @@  discard block
 block discarded – undo
2321 2321
 		try {
2322 2322
 			$Connection = new Connection();
2323 2323
 			$sth = $Connection->db->prepare($query);
2324
-                        $sth->execute();
2325
-                } catch(PDOException $e) {
2326
-                        return "error : ".$e->getMessage();
2327
-                }
2324
+						$sth->execute();
2325
+				} catch(PDOException $e) {
2326
+						return "error : ".$e->getMessage();
2327
+				}
2328 2328
 	}
2329 2329
 	public static function delete_duplicatemodes() {
2330 2330
 		global $globalDBdriver;
@@ -2336,10 +2336,10 @@  discard block
 block discarded – undo
2336 2336
 		try {
2337 2337
 			$Connection = new Connection();
2338 2338
 			$sth = $Connection->db->prepare($query);
2339
-                        $sth->execute();
2340
-                } catch(PDOException $e) {
2341
-                        return "error : ".$e->getMessage();
2342
-                }
2339
+						$sth->execute();
2340
+				} catch(PDOException $e) {
2341
+						return "error : ".$e->getMessage();
2342
+				}
2343 2343
 	}
2344 2344
 	public static function delete_duplicateowner() {
2345 2345
 		global $globalDBdriver;
@@ -2351,10 +2351,10 @@  discard block
 block discarded – undo
2351 2351
 		try {
2352 2352
 			$Connection = new Connection();
2353 2353
 			$sth = $Connection->db->prepare($query);
2354
-                        $sth->execute();
2355
-                } catch(PDOException $e) {
2356
-                        return "error : ".$e->getMessage();
2357
-                }
2354
+						$sth->execute();
2355
+				} catch(PDOException $e) {
2356
+						return "error : ".$e->getMessage();
2357
+				}
2358 2358
 	}
2359 2359
 	
2360 2360
 	public static function update_all() {
Please login to merge, or discard this patch.
Spacing   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
 		fclose($fp);
25 25
 	}
26 26
 
27
-	public static function gunzip($in_file,$out_file_name = '') {
27
+	public static function gunzip($in_file, $out_file_name = '') {
28 28
 		//echo $in_file.' -> '.$out_file_name."\n";
29 29
 		$buffer_size = 4096; // read 4kb at a time
30 30
 		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
31 31
 		if ($in_file != '' && file_exists($in_file)) {
32 32
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
33
-			if (function_exists('gzopen')) $file = gzopen($in_file,'rb');
34
-			elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb');
33
+			if (function_exists('gzopen')) $file = gzopen($in_file, 'rb');
34
+			elseif (function_exists('gzopen64')) $file = gzopen64($in_file, 'rb');
35 35
 			else {
36 36
 				echo 'gzopen not available';
37 37
 				die;
38 38
 			}
39 39
 			$out_file = fopen($out_file_name, 'wb'); 
40
-			while(!gzeof($file)) {
40
+			while (!gzeof($file)) {
41 41
 				fwrite($out_file, gzread($file, $buffer_size));
42 42
 			}  
43 43
 			fclose($out_file);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		try {
62 62
 			self::$db_sqlite = new PDO('sqlite:'.$database);
63 63
 			self::$db_sqlite->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
64
-		} catch(PDOException $e) {
64
+		} catch (PDOException $e) {
65 65
 			return "error : ".$e->getMessage();
66 66
 		}
67 67
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			//$Connection = new Connection();
77 77
 			$sth = $Connection->db->prepare($query);
78 78
                         $sth->execute(array(':source' => $database_file));
79
-                } catch(PDOException $e) {
79
+                } catch (PDOException $e) {
80 80
                         return "error : ".$e->getMessage();
81 81
                 }
82 82
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		try {
88 88
                         $sth = update_db::$db_sqlite->prepare($query);
89 89
                         $sth->execute();
90
-                } catch(PDOException $e) {
90
+                } catch (PDOException $e) {
91 91
                         return "error : ".$e->getMessage();
92 92
                 }
93 93
 		//$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)';
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 			if ($globalTransaction) $Connection->db->beginTransaction();
99 99
             		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
100 100
 				//$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);
101
-				$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);
101
+				$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);
102 102
 				$sth_dest->execute($query_dest_values);
103 103
             		}
104 104
 			if ($globalTransaction) $Connection->db->commit();
105
-		} catch(PDOException $e) {
105
+		} catch (PDOException $e) {
106 106
 			if ($globalTransaction) $Connection->db->rollBack(); 
107 107
 			return "error : ".$e->getMessage();
108 108
 		}
@@ -118,26 +118,26 @@  discard block
 block discarded – undo
118 118
 			//$Connection = new Connection();
119 119
 			$sth = $Connection->db->prepare($query);
120 120
                         $sth->execute(array(':source' => 'oneworld'));
121
-                } catch(PDOException $e) {
121
+                } catch (PDOException $e) {
122 122
                         return "error : ".$e->getMessage();
123 123
                 }
124 124
 
125 125
     		if ($globalDebug) echo " - Add routes to DB -";
126 126
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
127 127
 		$Spotter = new Spotter();
128
-		if ($fh = fopen($database_file,"r")) {
128
+		if ($fh = fopen($database_file, "r")) {
129 129
 			$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)';
130 130
 			$Connection = new Connection();
131 131
 			$sth_dest = $Connection->db->prepare($query_dest);
132 132
 			if ($globalTransaction) $Connection->db->beginTransaction();
133 133
 			while (!feof($fh)) {
134
-				$line = fgetcsv($fh,9999,',');
134
+				$line = fgetcsv($fh, 9999, ',');
135 135
 				if ($line[0] != '') {
136 136
 					if (($line[2] == '-' || ($line[2] != '-' && (strtotime($line[2]) > time()))) && ($line[3] == '-' || ($line[3] != '-' && (strtotime($line[3]) < time())))) {
137 137
 						try {
138
-							$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');
138
+							$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');
139 139
 							$sth_dest->execute($query_dest_values);
140
-						} catch(PDOException $e) {
140
+						} catch (PDOException $e) {
141 141
 							if ($globalTransaction) $Connection->db->rollBack(); 
142 142
 							return "error : ".$e->getMessage();
143 143
 						}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			//$Connection = new Connection();
160 160
 			$sth = $Connection->db->prepare($query);
161 161
                         $sth->execute(array(':source' => 'skyteam'));
162
-                } catch(PDOException $e) {
162
+                } catch (PDOException $e) {
163 163
                         return "error : ".$e->getMessage();
164 164
                 }
165 165
 
@@ -167,24 +167,24 @@  discard block
 block discarded – undo
167 167
 
168 168
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
169 169
 		$Spotter = new Spotter();
170
-		if ($fh = fopen($database_file,"r")) {
170
+		if ($fh = fopen($database_file, "r")) {
171 171
 			$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)';
172 172
 			$Connection = new Connection();
173 173
 			$sth_dest = $Connection->db->prepare($query_dest);
174 174
 			try {
175 175
 				if ($globalTransaction) $Connection->db->beginTransaction();
176 176
 				while (!feof($fh)) {
177
-					$line = fgetcsv($fh,9999,',');
177
+					$line = fgetcsv($fh, 9999, ',');
178 178
 					if ($line[0] != '') {
179
-						$datebe = explode('  -  ',$line[2]);
179
+						$datebe = explode('  -  ', $line[2]);
180 180
 						if (strtotime($datebe[0]) > time() && strtotime($datebe[1]) < time()) {
181
-							$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');
181
+							$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');
182 182
 							$sth_dest->execute($query_dest_values);
183 183
 						}
184 184
 					}
185 185
 				}
186 186
 				if ($globalTransaction) $Connection->db->commit();
187
-			} catch(PDOException $e) {
187
+			} catch (PDOException $e) {
188 188
 				if ($globalTransaction) $Connection->db->rollBack(); 
189 189
 				return "error : ".$e->getMessage();
190 190
 			}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 			$Connection = new Connection();
200 200
 			$sth = $Connection->db->prepare($query);
201 201
                         $sth->execute(array(':source' => $database_file));
202
-                } catch(PDOException $e) {
202
+                } catch (PDOException $e) {
203 203
                         return "error : ".$e->getMessage();
204 204
                 }
205 205
 		$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source";
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			$Connection = new Connection();
208 208
 			$sth = $Connection->db->prepare($query);
209 209
                         $sth->execute(array(':source' => $database_file));
210
-                } catch(PDOException $e) {
210
+                } catch (PDOException $e) {
211 211
                         return "error : ".$e->getMessage();
212 212
                 }
213 213
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		try {
217 217
                         $sth = update_db::$db_sqlite->prepare($query);
218 218
                         $sth->execute();
219
-                } catch(PDOException $e) {
219
+                } catch (PDOException $e) {
220 220
                         return "error : ".$e->getMessage();
221 221
                 }
222 222
 		//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)';
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
 			//$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']);
234 234
 				if ($values['UserString4'] == 'M') $type = 'military';
235 235
 				else $type = null;
236
-				$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type);
236
+				$query_dest_values = array(':LastModified' => $values['LastModified'], ':ModeS' => $values['ModeS'], ':ModeSCountry' => $values['ModeSCountry'], ':Registration' => $values['Registration'], ':ICAOTypeCode' => $values['ICAOTypeCode'], ':source' => $database_file, ':type' => $type);
237 237
 				$sth_dest->execute($query_dest_values);
238 238
 				if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') {
239
-				    $query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']);
239
+				    $query_dest_owner_values = array(':registration' => $values['Registration'], ':source' => $database_file, ':owner' => $values['RegisteredOwners']);
240 240
 				    $sth_dest_owner->execute($query_dest_owner_values);
241 241
 				}
242 242
             		}
243 243
 			if ($globalTransaction) $Connection->db->commit();
244
-		} catch(PDOException $e) {
244
+		} catch (PDOException $e) {
245 245
 			return "error : ".$e->getMessage();
246 246
 		}
247 247
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 			$Connection = new Connection();
252 252
 			$sth = $Connection->db->prepare($query);
253 253
                         $sth->execute(array(':source' => $database_file));
254
-                } catch(PDOException $e) {
254
+                } catch (PDOException $e) {
255 255
                         return "error : ".$e->getMessage();
256 256
                 }
257 257
 		return '';
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
 			$Connection = new Connection();
267 267
 			$sth = $Connection->db->prepare($query);
268 268
                         $sth->execute(array(':source' => $database_file));
269
-                } catch(PDOException $e) {
269
+                } catch (PDOException $e) {
270 270
                         return "error : ".$e->getMessage();
271 271
                 }
272 272
 		
273
-		if ($fh = fopen($database_file,"r")) {
273
+		if ($fh = fopen($database_file, "r")) {
274 274
 			//$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)';
275 275
 			$query_dest = 'INSERT INTO aircraft_modes (ModeS,Registration,ICAOTypeCode,Source) VALUES (:ModeS,:Registration,:ICAOTypeCode,:source)';
276 276
 		
@@ -280,13 +280,13 @@  discard block
 block discarded – undo
280 280
 				if ($globalTransaction) $Connection->db->beginTransaction();
281 281
             			while (!feof($fh)) {
282 282
             				$values = array();
283
-            				$line = $Common->hex2str(fgets($fh,9999));
283
+            				$line = $Common->hex2str(fgets($fh, 9999));
284 284
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
285
-            				$values['ModeS'] = substr($line,0,6);
286
-            				$values['Registration'] = trim(substr($line,69,6));
287
-            				$aircraft_name = trim(substr($line,48,6));
285
+            				$values['ModeS'] = substr($line, 0, 6);
286
+            				$values['Registration'] = trim(substr($line, 69, 6));
287
+            				$aircraft_name = trim(substr($line, 48, 6));
288 288
             				// Check if we can find ICAO, else set it to GLID
289
-            				$aircraft_name_split = explode(' ',$aircraft_name);
289
+            				$aircraft_name_split = explode(' ', $aircraft_name);
290 290
             				$search_more = '';
291 291
             				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
292 292
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 	            				if (isset($result['icao']) && $result['icao'] != '') {
299 299
 	            				    $values['ICAOTypeCode'] = $result['icao'];
300 300
 	            				} 
301
-					} catch(PDOException $e) {
301
+					} catch (PDOException $e) {
302 302
 						return "error : ".$e->getMessage();
303 303
 					}
304 304
 					if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID';
305 305
 					// Add data to db
306 306
 					if ($values['Registration'] != '' && $values['Registration'] != '0000') {
307 307
 						//$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']);
308
-						$query_dest_values = array(':ModeS' => $values['ModeS'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file);
308
+						$query_dest_values = array(':ModeS' => $values['ModeS'], ':Registration' => $values['Registration'], ':ICAOTypeCode' => $values['ICAOTypeCode'], ':source' => $database_file);
309 309
 						//print_r($query_dest_values);
310 310
 						$sth_dest->execute($query_dest_values);
311 311
 					}
312 312
 				}
313 313
 				if ($globalTransaction) $Connection->db->commit();
314
-			} catch(PDOException $e) {
314
+			} catch (PDOException $e) {
315 315
 				return "error : ".$e->getMessage();
316 316
 			}
317 317
 		}
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 			$Connection = new Connection();
322 322
 			$sth = $Connection->db->prepare($query);
323 323
                         $sth->execute(array(':source' => $database_file));
324
-                } catch(PDOException $e) {
324
+                } catch (PDOException $e) {
325 325
                         return "error : ".$e->getMessage();
326 326
                 }
327 327
 		return '';
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
 			$Connection = new Connection();
336 336
 			$sth = $Connection->db->prepare($query);
337 337
                         $sth->execute(array(':source' => $database_file));
338
-                } catch(PDOException $e) {
338
+                } catch (PDOException $e) {
339 339
                         return "error : ".$e->getMessage();
340 340
                 }
341 341
 		
342
-		if ($fh = fopen($database_file,"r")) {
342
+		if ($fh = fopen($database_file, "r")) {
343 343
 			//$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)';
344 344
 			$query_dest = 'INSERT INTO aircraft_modes (ModeS,Registration,ICAOTypeCode,Source) VALUES (:ModeS,:Registration,:ICAOTypeCode,:source)';
345 345
 		
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
 			$sth_dest = $Connection->db->prepare($query_dest);
348 348
 			try {
349 349
 				if ($globalTransaction) $Connection->db->beginTransaction();
350
-				$tmp = fgetcsv($fh,9999,',',"'");
350
+				$tmp = fgetcsv($fh, 9999, ',', "'");
351 351
             			while (!feof($fh)) {
352
-            				$line = fgetcsv($fh,9999,',',"'");
352
+            				$line = fgetcsv($fh, 9999, ',', "'");
353 353
             				
354 354
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
355 355
 					//print_r($line);
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
             				$values['Registration'] = $line[3];
358 358
             				$aircraft_name = $line[2];
359 359
             				// Check if we can find ICAO, else set it to GLID
360
-            				$aircraft_name_split = explode(' ',$aircraft_name);
360
+            				$aircraft_name_split = explode(' ', $aircraft_name);
361 361
             				$search_more = '';
362 362
             				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
363 363
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
@@ -366,20 +366,20 @@  discard block
 block discarded – undo
366 366
                                     		$sth_search->execute();
367 367
 	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
368 368
 	            				if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
369
-					} catch(PDOException $e) {
369
+					} catch (PDOException $e) {
370 370
 						return "error : ".$e->getMessage();
371 371
 					}
372 372
 					//if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID';
373 373
 					// Add data to db
374 374
 					if ($values['Registration'] != '' && $values['Registration'] != '0000' && $values['ICAOTypeCode'] != '') {
375 375
 						//$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']);
376
-						$query_dest_values = array(':ModeS' => $values['ModeS'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file);
376
+						$query_dest_values = array(':ModeS' => $values['ModeS'], ':Registration' => $values['Registration'], ':ICAOTypeCode' => $values['ICAOTypeCode'], ':source' => $database_file);
377 377
 						//print_r($query_dest_values);
378 378
 						$sth_dest->execute($query_dest_values);
379 379
 					}
380 380
 				}
381 381
 				if ($globalTransaction) $Connection->db->commit();
382
-			} catch(PDOException $e) {
382
+			} catch (PDOException $e) {
383 383
 				return "error : ".$e->getMessage();
384 384
 			}
385 385
 		}
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
 			$Connection = new Connection();
390 390
 			$sth = $Connection->db->prepare($query);
391 391
                         $sth->execute(array(':source' => $database_file));
392
-                } catch(PDOException $e) {
392
+                } catch (PDOException $e) {
393 393
                         return "error : ".$e->getMessage();
394 394
                 }
395 395
 		return '';
396 396
 	}
397 397
 
398
-	public static function retrieve_owner($database_file,$country = 'F') {
398
+	public static function retrieve_owner($database_file, $country = 'F') {
399 399
 		global $globalTransaction;
400 400
 		//$query = 'TRUNCATE TABLE aircraft_modes';
401 401
 		$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source";
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
 			$Connection = new Connection();
404 404
 			$sth = $Connection->db->prepare($query);
405 405
                         $sth->execute(array(':source' => $database_file));
406
-                } catch(PDOException $e) {
406
+                } catch (PDOException $e) {
407 407
                         return "error : ".$e->getMessage();
408 408
                 }
409 409
 		
410
-		if ($fh = fopen($database_file,"r")) {
410
+		if ($fh = fopen($database_file, "r")) {
411 411
 			//$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)';
412 412
 			$query_dest = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)';
413 413
 		
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
 			$sth_dest = $Connection->db->prepare($query_dest);
416 416
 			try {
417 417
 				if ($globalTransaction) $Connection->db->beginTransaction();
418
-				$tmp = fgetcsv($fh,9999,',','"');
418
+				$tmp = fgetcsv($fh, 9999, ',', '"');
419 419
             			while (!feof($fh)) {
420
-            				$line = fgetcsv($fh,9999,',','"');
420
+            				$line = fgetcsv($fh, 9999, ',', '"');
421 421
             				$values = array();
422 422
             				//print_r($line);
423 423
             				if ($country == 'F') {
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
             				    $values['base'] = $line[4];
426 426
             				    $values['owner'] = $line[5];
427 427
             				    if ($line[6] == '') $values['date_first_reg'] = null;
428
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
428
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[6]));
429 429
 					    $values['cancel'] = $line[7];
430 430
 					} elseif ($country == 'EI') {
431 431
 					    // TODO : add modeS & reg to aircraft_modes
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
             				    $values['base'] = $line[3];
434 434
             				    $values['owner'] = $line[2];
435 435
             				    if ($line[1] == '') $values['date_first_reg'] = null;
436
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
436
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[1]));
437 437
 					    $values['cancel'] = '';
438 438
 					} elseif ($country == 'HB') {
439 439
 					    // TODO : add modeS & reg to aircraft_modes
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
             				    $values['base'] = null;
449 449
             				    $values['owner'] = $line[5];
450 450
             				    if ($line[18] == '') $values['date_first_reg'] = null;
451
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
451
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[18]));
452 452
 					    $values['cancel'] = '';
453 453
 					} elseif ($country == 'VH') {
454 454
 					    // TODO : add modeS & reg to aircraft_modes
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
             				    $values['base'] = null;
457 457
             				    $values['owner'] = $line[12];
458 458
             				    if ($line[28] == '') $values['date_first_reg'] = null;
459
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
459
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[28]));
460 460
 
461 461
 					    $values['cancel'] = $line[39];
462 462
 					} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') {
@@ -476,28 +476,28 @@  discard block
 block discarded – undo
476 476
             				    $values['base'] = null;
477 477
             				    $values['owner'] = $line[8];
478 478
             				    if ($line[7] == '') $values['date_first_reg'] = null;
479
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
479
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[7]));
480 480
 					    $values['cancel'] = '';
481 481
 					} elseif ($country == 'PP') {
482 482
             				    $values['registration'] = $line[0];
483 483
             				    $values['base'] = null;
484 484
             				    $values['owner'] = $line[4];
485 485
             				    if ($line[6] == '') $values['date_first_reg'] = null;
486
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
486
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[6]));
487 487
 					    $values['cancel'] = $line[7];
488 488
 					} elseif ($country == 'E7') {
489 489
             				    $values['registration'] = $line[0];
490 490
             				    $values['base'] = null;
491 491
             				    $values['owner'] = $line[4];
492 492
             				    if ($line[5] == '') $values['date_first_reg'] = null;
493
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
493
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[5]));
494 494
 					    $values['cancel'] = '';
495 495
 					} elseif ($country == '8Q') {
496 496
             				    $values['registration'] = $line[0];
497 497
             				    $values['base'] = null;
498 498
             				    $values['owner'] = $line[3];
499 499
             				    if ($line[7] == '') $values['date_first_reg'] = null;
500
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
500
+					    else $values['date_first_reg'] = date("Y-m-d", strtotime($line[7]));
501 501
 					    $values['cancel'] = '';
502 502
 					} elseif ($country == 'ZK' || $country == 'OM' || $country == 'TF') {
503 503
             				    $values['registration'] = $line[0];
@@ -507,12 +507,12 @@  discard block
 block discarded – undo
507 507
 					    $values['cancel'] = '';
508 508
 					}
509 509
 					if ($values['cancel'] == '' && $values['registration'] != null) {
510
-						$query_dest_values = array(':registration' => $values['registration'],':base' => $values['base'],':date_first_reg' => $values['date_first_reg'],':owner' => $values['owner'],':source' => $database_file);
510
+						$query_dest_values = array(':registration' => $values['registration'], ':base' => $values['base'], ':date_first_reg' => $values['date_first_reg'], ':owner' => $values['owner'], ':source' => $database_file);
511 511
 						$sth_dest->execute($query_dest_values);
512 512
 					}
513 513
 				}
514 514
 				if ($globalTransaction) $Connection->db->commit();
515
-			} catch(PDOException $e) {
515
+			} catch (PDOException $e) {
516 516
 				return "error : ".$e->getMessage();
517 517
 			}
518 518
 		}
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 			$Connection = new Connection();
628 628
 			$sth = $Connection->db->prepare($query);
629 629
                         $sth->execute();
630
-                } catch(PDOException $e) {
630
+                } catch (PDOException $e) {
631 631
                         return "error : ".$e->getMessage();
632 632
                 }
633 633
 
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 			$Connection = new Connection();
638 638
 			$sth = $Connection->db->prepare($query);
639 639
                         $sth->execute();
640
-                } catch(PDOException $e) {
640
+                } catch (PDOException $e) {
641 641
                         return "error : ".$e->getMessage();
642 642
                 }
643 643
 
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 		if ($globalTransaction) $Connection->db->beginTransaction();
649 649
   
650 650
 		$i = 0;
651
-		while($row = sparql_fetch_array($result))
651
+		while ($row = sparql_fetch_array($result))
652 652
 		{
653 653
 			if ($i >= 1) {
654 654
 			//print_r($row);
@@ -668,31 +668,31 @@  discard block
 block discarded – undo
668 668
 				$row['image'] = '';
669 669
 				$row['image_thumb'] = '';
670 670
 			} else {
671
-				$image = str_replace(' ','_',$row['image']);
671
+				$image = str_replace(' ', '_', $row['image']);
672 672
 				$digest = md5($image);
673
-				$folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . $image . '/220px-' . $image;
674
-				$row['image_thumb'] = 'http://upload.wikimedia.org/wikipedia/commons/thumb/' . $folder;
675
-				$folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . $image;
676
-				$row['image'] = 'http://upload.wikimedia.org/wikipedia/commons/' . $folder;
673
+				$folder = $digest[0].'/'.$digest[0].$digest[1].'/'.$image.'/220px-'.$image;
674
+				$row['image_thumb'] = 'http://upload.wikimedia.org/wikipedia/commons/thumb/'.$folder;
675
+				$folder = $digest[0].'/'.$digest[0].$digest[1].'/'.$image;
676
+				$row['image'] = 'http://upload.wikimedia.org/wikipedia/commons/'.$folder;
677 677
 			}
678 678
 			
679
-			$country = explode('-',$row['country']);
679
+			$country = explode('-', $row['country']);
680 680
 			$row['country'] = $country[0];
681 681
 			
682 682
 			$row['type'] = trim($row['type']);
683
-			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'])) {
683
+			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'])) {
684 684
 				$row['type'] = 'Military';
685 685
 			} 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') {
686 686
 				$row['type'] = 'small_airport';
687 687
 			}
688 688
 			
689
-			$row['city'] = urldecode(str_replace('_',' ',str_replace('http://dbpedia.org/resource/','',$row['city'])));
690
-			$query_dest_values = array(':airport_id' => $i, ':name' => $row['name'],':iata' => $row['iata'],':icao' => $row['icao'],':latitude' => $row['latitude'],':longitude' => $row['longitude'],':altitude' => $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']);
689
+			$row['city'] = urldecode(str_replace('_', ' ', str_replace('http://dbpedia.org/resource/', '', $row['city'])));
690
+			$query_dest_values = array(':airport_id' => $i, ':name' => $row['name'], ':iata' => $row['iata'], ':icao' => $row['icao'], ':latitude' => $row['latitude'], ':longitude' => $row['longitude'], ':altitude' => $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']);
691 691
 			//print_r($query_dest_values);
692 692
 			
693 693
 			try {
694 694
 				$sth_dest->execute($query_dest_values);
695
-			} catch(PDOException $e) {
695
+			} catch (PDOException $e) {
696 696
 				return "error : ".$e->getMessage();
697 697
 			}
698 698
 			}
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 			$Connection = new Connection();
707 707
 			$sth = $Connection->db->prepare($query);
708 708
                         $sth->execute();
709
-                } catch(PDOException $e) {
709
+                } catch (PDOException $e) {
710 710
                         return "error : ".$e->getMessage();
711 711
                 }
712 712
 
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
 		if ($globalDebug) echo "Insert Not available Airport...\n";
715 715
 		$query = "INSERT INTO airport (`airport_id`,`name`,`city`,`country`,`iata`,`icao`,`latitude`,`longitude`,`altitude`,`type`,`home_link`,`wikipedia_link`,`image`,`image_thumb`)
716 716
 		    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image, :image_thumb)";
717
-		$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' => '');
717
+		$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' => '');
718 718
 		try {
719 719
 			$Connection = new Connection();
720 720
 			$sth = $Connection->db->prepare($query);
721 721
                         $sth->execute($query_values);
722
-                } catch(PDOException $e) {
722
+                } catch (PDOException $e) {
723 723
                         return "error : ".$e->getMessage();
724 724
                 }
725 725
 		$i++;
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 		echo "Download data from ourairports.com...\n";
738 738
 		$delimiter = ',';
739 739
 		$out_file = $tmp_dir.'airports.csv';
740
-		update_db::download('http://ourairports.com/data/airports.csv',$out_file);
740
+		update_db::download('http://ourairports.com/data/airports.csv', $out_file);
741 741
 		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
742 742
 		echo "Add data from ourairports.com...\n";
743 743
 
@@ -748,32 +748,32 @@  discard block
 block discarded – undo
748 748
 			//$Connection->db->beginTransaction();
749 749
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
750 750
 			{
751
-				if(!$header) $header = $row;
751
+				if (!$header) $header = $row;
752 752
 				else {
753 753
 					$data = array();
754 754
 					$data = array_combine($header, $row);
755 755
 					try {
756 756
 						$sth = $Connection->db->prepare('SELECT COUNT(*) FROM airport WHERE `icao` = :icao');
757 757
 						$sth->execute(array(':icao' => $data['gps_code']));
758
-					} catch(PDOException $e) {
758
+					} catch (PDOException $e) {
759 759
 						return "error : ".$e->getMessage();
760 760
 					}
761 761
 					if ($sth->fetchColumn() > 0) {
762 762
 						$query = 'UPDATE airport SET `type` = :type WHERE icao = :icao';
763 763
 						try {
764 764
 							$sth = $Connection->db->prepare($query);
765
-							$sth->execute(array(':icao' => $data['gps_code'],':type' => $data['type']));
766
-						} catch(PDOException $e) {
765
+							$sth->execute(array(':icao' => $data['gps_code'], ':type' => $data['type']));
766
+						} catch (PDOException $e) {
767 767
 							return "error : ".$e->getMessage();
768 768
 						}
769 769
 					} else {
770 770
 						$query = "INSERT INTO airport (`airport_id`,`name`,`city`,`country`,`iata`,`icao`,`latitude`,`longitude`,`altitude`,`type`,`home_link`,`wikipedia_link`)
771 771
 						    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link)";
772
-						$query_values = array(':airport_id' => $i, ':name' => $data['name'],':iata' => $data['iata_code'],':icao' => $data['gps_code'],':latitude' => $data['latitude_deg'],':longitude' => $data['longitude_deg'],':altitude' => $data['elevation_ft'],':type' => $data['type'],':city' => $data['municipality'],':country' => $data['iso_country'],':home_link' => $data['home_link'],':wikipedia_link' => $data['wikipedia_link']);
772
+						$query_values = array(':airport_id' => $i, ':name' => $data['name'], ':iata' => $data['iata_code'], ':icao' => $data['gps_code'], ':latitude' => $data['latitude_deg'], ':longitude' => $data['longitude_deg'], ':altitude' => $data['elevation_ft'], ':type' => $data['type'], ':city' => $data['municipality'], ':country' => $data['iso_country'], ':home_link' => $data['home_link'], ':wikipedia_link' => $data['wikipedia_link']);
773 773
 						try {
774 774
 							$sth = $Connection->db->prepare($query);
775 775
 							$sth->execute($query_values);
776
-						} catch(PDOException $e) {
776
+						} catch (PDOException $e) {
777 777
 							return "error : ".$e->getMessage();
778 778
 						}
779 779
 						$i++;
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
 
787 787
 		echo "Download data from another free database...\n";
788 788
 		$out_file = $tmp_dir.'GlobalAirportDatabase.zip';
789
-		update_db::download('http://www.partow.net/downloads/GlobalAirportDatabase.zip',$out_file);
789
+		update_db::download('http://www.partow.net/downloads/GlobalAirportDatabase.zip', $out_file);
790 790
 		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
791 791
 		update_db::unzip($out_file);
792 792
 		$header = NULL;
@@ -798,15 +798,15 @@  discard block
 block discarded – undo
798 798
 			//$Connection->db->beginTransaction();
799 799
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
800 800
 			{
801
-				if(!$header) $header = $row;
801
+				if (!$header) $header = $row;
802 802
 				else {
803 803
 					$data = $row;
804 804
 
805 805
 					$query = 'UPDATE airport SET `city` = :city, `country` = :country WHERE icao = :icao';
806 806
 					try {
807 807
 						$sth = $Connection->db->prepare($query);
808
-						$sth->execute(array(':icao' => $data[0],':city' => ucwords(strtolower($data[3])),':country' => ucwords(strtolower($data[4]))));
809
-					} catch(PDOException $e) {
808
+						$sth->execute(array(':icao' => $data[0], ':city' => ucwords(strtolower($data[3])), ':country' => ucwords(strtolower($data[4]))));
809
+					} catch (PDOException $e) {
810 810
 						return "error : ".$e->getMessage();
811 811
 					}
812 812
 				}
@@ -820,15 +820,15 @@  discard block
 block discarded – undo
820 820
 		try {
821 821
 			$sth = $Connection->db->prepare("SELECT icao FROM airport WHERE `name` LIKE '%Air Base%'");
822 822
 			$sth->execute();
823
-		} catch(PDOException $e) {
823
+		} catch (PDOException $e) {
824 824
 			return "error : ".$e->getMessage();
825 825
 		}
826 826
 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
827 827
 			$query2 = 'UPDATE airport SET `type` = :type WHERE icao = :icao';
828 828
 			try {
829 829
 				$sth2 = $Connection->db->prepare($query2);
830
-				$sth2->execute(array(':icao' => $row['icao'],':type' => 'military'));
831
-			} catch(PDOException $e) {
830
+				$sth2->execute(array(':icao' => $row['icao'], ':type' => 'military'));
831
+			} catch (PDOException $e) {
832 832
 				return "error : ".$e->getMessage();
833 833
 			}
834 834
 		}
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 			$Connection = new Connection();
853 853
 			$sth = $Connection->db->prepare($query);
854 854
                         $sth->execute(array(':source' => 'translation.csv'));
855
-                } catch(PDOException $e) {
855
+                } catch (PDOException $e) {
856 856
                         return "error : ".$e->getMessage();
857 857
                 }
858 858
 
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
870 870
 			{
871 871
 				$i++;
872
-				if($i > 12) {
872
+				if ($i > 12) {
873 873
 					$data = $row;
874 874
 					$operator = $data[2];
875 875
 					if ($operator != '' && is_numeric(substr(substr($operator, 0, 3), -1, 1))) {
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
                                                 //echo substr($operator, 0, 2)."\n";;
878 878
                                                 if (count($airline_array) > 0) {
879 879
 							//print_r($airline_array);
880
-							$operator = $airline_array[0]['icao'].substr($operator,2);
880
+							$operator = $airline_array[0]['icao'].substr($operator, 2);
881 881
                                                 }
882 882
                                         }
883 883
 					
@@ -885,14 +885,14 @@  discard block
 block discarded – undo
885 885
 					if ($operator_correct != '' && is_numeric(substr(substr($operator_correct, 0, 3), -1, 1))) {
886 886
                                                 $airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2));
887 887
                                                 if (count($airline_array) > 0) {
888
-                                            		$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2);
888
+                                            		$operator_correct = $airline_array[0]['icao'].substr($operator_correct, 2);
889 889
                                             	}
890 890
                                         }
891 891
 					$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)';
892 892
 					try {
893 893
 						$sth = $Connection->db->prepare($query);
894
-						$sth->execute(array(':Reg' => $data[0],':Reg_correct' => $data[1],':Operator' => $operator,':Operator_correct' => $operator_correct, ':source' => 'translation.csv'));
895
-					} catch(PDOException $e) {
894
+						$sth->execute(array(':Reg' => $data[0], ':Reg_correct' => $data[1], ':Operator' => $operator, ':Operator_correct' => $operator_correct, ':source' => 'translation.csv'));
895
+					} catch (PDOException $e) {
896 896
 						return "error : ".$e->getMessage();
897 897
 					}
898 898
 				}
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 			$Connection = new Connection();
913 913
 			$sth = $Connection->db->prepare($query);
914 914
                         $sth->execute(array(':source' => 'website_fam'));
915
-                } catch(PDOException $e) {
915
+                } catch (PDOException $e) {
916 916
                         return "error : ".$e->getMessage();
917 917
                 }
918 918
 
@@ -932,8 +932,8 @@  discard block
 block discarded – undo
932 932
 					$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)';
933 933
 					try {
934 934
 						$sth = $Connection->db->prepare($query);
935
-						$sth->execute(array(':Reg' => $data[0],':Reg_correct' => $data[1],':Operator' => $data[2],':Operator_correct' => $data[3], ':source' => 'website_fam'));
936
-					} catch(PDOException $e) {
935
+						$sth->execute(array(':Reg' => $data[0], ':Reg_correct' => $data[1], ':Operator' => $data[2], ':Operator_correct' => $data[3], ':source' => 'website_fam'));
936
+					} catch (PDOException $e) {
937 937
 						return "error : ".$e->getMessage();
938 938
 					}
939 939
 				}
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 			$Connection = new Connection();
957 957
 			$sth = $Connection->db->prepare($query);
958 958
                         $sth->execute(array(':source' => 'website_faa'));
959
-                } catch(PDOException $e) {
959
+                } catch (PDOException $e) {
960 960
                         return "error : ".$e->getMessage();
961 961
                 }
962 962
 
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 			$Connection = new Connection();
966 966
 			$sth = $Connection->db->prepare($query);
967 967
                         $sth->execute(array(':source' => 'website_faa'));
968
-                } catch(PDOException $e) {
968
+                } catch (PDOException $e) {
969 969
                         return "error : ".$e->getMessage();
970 970
                 }
971 971
 
@@ -981,8 +981,8 @@  discard block
 block discarded – undo
981 981
 					$query_search = 'SELECT icaotypecode FROM aircraft_modes WHERE registration = :registration AND Source <> :source LIMIT 1';
982 982
 					try {
983 983
 						$sths = $Connection->db->prepare($query_search);
984
-						$sths->execute(array(':registration' => 'N'.$data[0],':source' => 'website_faa'));
985
-					} catch(PDOException $e) {
984
+						$sths->execute(array(':registration' => 'N'.$data[0], ':source' => 'website_faa'));
985
+					} catch (PDOException $e) {
986 986
 						return "error s : ".$e->getMessage();
987 987
 					}
988 988
 					$result_search = $sths->fetchAll(PDO::FETCH_ASSOC);
@@ -991,8 +991,8 @@  discard block
 block discarded – undo
991 991
 						$queryi = 'UPDATE aircraft SET mfr = :mfr WHERE icao = :icao';
992 992
 						try {
993 993
 							$sthi = $Connection->db->prepare($queryi);
994
-							$sthi->execute(array(':mfr' => $data[2],':icao' => $result_search[0]['icaotypecode']));
995
-						} catch(PDOException $e) {
994
+							$sthi->execute(array(':mfr' => $data[2], ':icao' => $result_search[0]['icaotypecode']));
995
+						} catch (PDOException $e) {
996 996
 							return "error u : ".$e->getMessage();
997 997
 						}
998 998
 					} else {
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 						try {
1001 1001
 							$sthsm = $Connection->db->prepare($query_search_mfr);
1002 1002
 							$sthsm->execute(array(':mfr' => $data[2]));
1003
-						} catch(PDOException $e) {
1003
+						} catch (PDOException $e) {
1004 1004
 							return "error mfr : ".$e->getMessage();
1005 1005
 						}
1006 1006
 						$result_search_mfr = $sthsm->fetchAll(PDO::FETCH_ASSOC);
@@ -1010,8 +1010,8 @@  discard block
 block discarded – undo
1010 1010
 							$queryf = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:source)';
1011 1011
 							try {
1012 1012
 								$sthf = $Connection->db->prepare($queryf);
1013
-								$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'));
1014
-							} catch(PDOException $e) {
1013
+								$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'));
1014
+							} catch (PDOException $e) {
1015 1015
 								return "error f : ".$e->getMessage();
1016 1016
 							}
1017 1017
 						}
@@ -1021,13 +1021,13 @@  discard block
 block discarded – undo
1021 1021
 						$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)';
1022 1022
 						try {
1023 1023
 							$sth = $Connection->db->prepare($query);
1024
-							$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'));
1025
-						} catch(PDOException $e) {
1024
+							$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'));
1025
+						} catch (PDOException $e) {
1026 1026
 							return "error i : ".$e->getMessage();
1027 1027
 						}
1028 1028
 					}
1029 1029
 				}
1030
-				if ($i % 90 == 0) {
1030
+				if ($i%90 == 0) {
1031 1031
 					if ($globalTransaction) $Connection->db->commit();
1032 1032
 					if ($globalTransaction) $Connection->db->beginTransaction();
1033 1033
 				}
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 			$Connection = new Connection();
1046 1046
 			$sth = $Connection->db->prepare($query);
1047 1047
                         $sth->execute(array(':source' => 'website_fam'));
1048
-                } catch(PDOException $e) {
1048
+                } catch (PDOException $e) {
1049 1049
                         return "error : ".$e->getMessage();
1050 1050
                 }
1051 1051
 
@@ -1065,8 +1065,8 @@  discard block
 block discarded – undo
1065 1065
 					$query = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type_flight,:source)';
1066 1066
 					try {
1067 1067
 						$sth = $Connection->db->prepare($query);
1068
-						$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'));
1069
-					} catch(PDOException $e) {
1068
+						$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'));
1069
+					} catch (PDOException $e) {
1070 1070
 						return "error : ".$e->getMessage();
1071 1071
 					}
1072 1072
 				}
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 			$Connection = new Connection();
1086 1086
 			$sth = $Connection->db->prepare($query);
1087 1087
                         $sth->execute(array(':source' => 'website_fam'));
1088
-                } catch(PDOException $e) {
1088
+                } catch (PDOException $e) {
1089 1089
                         return "error : ".$e->getMessage();
1090 1090
                 }
1091 1091
 
@@ -1101,8 +1101,8 @@  discard block
 block discarded – undo
1101 1101
 					$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,NULL,:source)';
1102 1102
 					try {
1103 1103
 						$sth = $Connection->db->prepare($query);
1104
-						$sth->execute(array(':registration' => $data[0],':base' => $data[1],':owner' => $data[2], ':source' => 'website_fam'));
1105
-					} catch(PDOException $e) {
1104
+						$sth->execute(array(':registration' => $data[0], ':base' => $data[1], ':owner' => $data[2], ':source' => 'website_fam'));
1105
+					} catch (PDOException $e) {
1106 1106
 						print_r($data);
1107 1107
 						return "error : ".$e->getMessage();
1108 1108
 					}
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 			$Connection = new Connection();
1123 1123
 			$sth = $Connection->db->prepare($query);
1124 1124
                         $sth->execute(array(':source' => 'website_fam'));
1125
-                } catch(PDOException $e) {
1125
+                } catch (PDOException $e) {
1126 1126
                         return "error : ".$e->getMessage();
1127 1127
                 }
1128 1128
 
@@ -1142,8 +1142,8 @@  discard block
 block discarded – undo
1142 1142
 					$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)';
1143 1143
 					try {
1144 1144
 						$sth = $Connection->db->prepare($query);
1145
-						$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'));
1146
-					} catch(PDOException $e) {
1145
+						$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'));
1146
+					} catch (PDOException $e) {
1147 1147
 						return "error : ".$e->getMessage();
1148 1148
 					}
1149 1149
 				}
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 		return '';
1156 1156
         }
1157 1157
 
1158
-	public static function tle($filename,$tletype) {
1158
+	public static function tle($filename, $tletype) {
1159 1159
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
1160 1160
 		global $tmp_dir, $globalTransaction;
1161 1161
 		//$Spotter = new Spotter();
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 			$Connection = new Connection();
1166 1166
 			$sth = $Connection->db->prepare($query);
1167 1167
                         $sth->execute(array(':source' => $filename));
1168
-                } catch(PDOException $e) {
1168
+                } catch (PDOException $e) {
1169 1169
                         return "error : ".$e->getMessage();
1170 1170
                 }
1171 1171
 		
@@ -1190,8 +1190,8 @@  discard block
 block discarded – undo
1190 1190
 					$query = 'INSERT INTO tle (tle_name,tle_tle1,tle_tle2,tle_type,tle_source) VALUES (:name, :tle1, :tle2, :type, :source)';
1191 1191
 					try {
1192 1192
 						$sth = $Connection->db->prepare($query);
1193
-						$sth->execute(array(':name' => $dbdata['name'],':tle1' => $dbdata['tle1'],':tle2' => $dbdata['tle2'], ':type' => $tletype,':source' => $filename));
1194
-					} catch(PDOException $e) {
1193
+						$sth->execute(array(':name' => $dbdata['name'], ':tle1' => $dbdata['tle1'], ':tle2' => $dbdata['tle2'], ':type' => $tletype, ':source' => $filename));
1194
+					} catch (PDOException $e) {
1195 1195
 						return "error : ".$e->getMessage();
1196 1196
 					}
1197 1197
 
@@ -1211,28 +1211,28 @@  discard block
 block discarded – undo
1211 1211
         */
1212 1212
         private static function table2array($data) {
1213 1213
                 $html = str_get_html($data);
1214
-                $tabledata=array();
1215
-                foreach($html->find('tr') as $element)
1214
+                $tabledata = array();
1215
+                foreach ($html->find('tr') as $element)
1216 1216
                 {
1217 1217
                         $td = array();
1218
-                        foreach( $element->find('th') as $row)
1218
+                        foreach ($element->find('th') as $row)
1219 1219
                         {
1220 1220
                                 $td [] = trim($row->plaintext);
1221 1221
                         }
1222
-                        $td=array_filter($td);
1222
+                        $td = array_filter($td);
1223 1223
                         $tabledata[] = $td;
1224 1224
 
1225 1225
                         $td = array();
1226 1226
                         $tdi = array();
1227
-                        foreach( $element->find('td') as $row)
1227
+                        foreach ($element->find('td') as $row)
1228 1228
                         {
1229 1229
                                 $td [] = trim($row->plaintext);
1230 1230
                                 $tdi [] = trim($row->innertext);
1231 1231
                         }
1232
-                        $td=array_filter($td);
1233
-                        $tdi=array_filter($tdi);
1232
+                        $td = array_filter($td);
1233
+                        $tdi = array_filter($tdi);
1234 1234
                     //    $tabledata[]=array_merge($td,$tdi);
1235
-                        $tabledata[]=$td;
1235
+                        $tabledata[] = $td;
1236 1236
                 }
1237 1237
                 return(array_filter($tabledata));
1238 1238
         }
@@ -1305,13 +1305,13 @@  discard block
 block discarded – undo
1305 1305
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1306 1306
 			{
1307 1307
 				$i++;
1308
-				if($i > 3 && count($row) > 2) {
1308
+				if ($i > 3 && count($row) > 2) {
1309 1309
 					$data = array_values(array_filter($row));
1310 1310
 					$cntdata = count($data);
1311 1311
 					if ($cntdata > 10) {
1312 1312
 						$value = $data[9];
1313 1313
 						
1314
-						for ($i =10;$i < $cntdata;$i++) {
1314
+						for ($i = 10; $i < $cntdata; $i++) {
1315 1315
 							$value .= ' '.$data[$i];
1316 1316
 						}
1317 1317
 						$data[9] = $value;
@@ -1321,8 +1321,8 @@  discard block
 block discarded – undo
1321 1321
 						$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)';
1322 1322
 						try {
1323 1323
 							$sth = $Connection->db->prepare($query);
1324
-							$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]));
1325
-						} catch(PDOException $e) {
1324
+							$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]));
1325
+						} catch (PDOException $e) {
1326 1326
 							return "error : ".$e->getMessage();
1327 1327
 						}
1328 1328
 					}
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 			$Connection = new Connection();
1344 1344
 			$sth = $Connection->db->prepare($query);
1345 1345
                         $sth->execute();
1346
-                } catch(PDOException $e) {
1346
+                } catch (PDOException $e) {
1347 1347
                         return "error : ".$e->getMessage();
1348 1348
                 }
1349 1349
 
@@ -1355,12 +1355,12 @@  discard block
 block discarded – undo
1355 1355
 			if ($globalTransaction) $Connection->db->beginTransaction();
1356 1356
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1357 1357
 			{
1358
-				if(count($row) > 1) {
1358
+				if (count($row) > 1) {
1359 1359
 					$query = "INSERT INTO airlines (name,icao,active,forsource) VALUES (:name, :icao, 'Y','ivao')";
1360 1360
 					try {
1361 1361
 						$sth = $Connection->db->prepare($query);
1362
-						$sth->execute(array(':name' => $row[1],':icao' => $row[0]));
1363
-					} catch(PDOException $e) {
1362
+						$sth->execute(array(':name' => $row[1], ':icao' => $row[0]));
1363
+					} catch (PDOException $e) {
1364 1364
 						return "error : ".$e->getMessage();
1365 1365
 					}
1366 1366
 				}
@@ -1380,21 +1380,21 @@  discard block
 block discarded – undo
1380 1380
 			try {
1381 1381
 				$sth = $Connection->db->prepare($query);
1382 1382
                     		$sth->execute();
1383
-	                } catch(PDOException $e) {
1383
+	                } catch (PDOException $e) {
1384 1384
 				return "error : ".$e->getMessage();
1385 1385
 	                }
1386 1386
 	        }
1387 1387
 
1388 1388
 
1389
-		if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
1389
+		if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz', $tmp_dir.'airspace.sql');
1390 1390
 		else {
1391
-			update_db::gunzip('../db/pgsql/airspace.sql.gz',$tmp_dir.'airspace.sql');
1391
+			update_db::gunzip('../db/pgsql/airspace.sql.gz', $tmp_dir.'airspace.sql');
1392 1392
 			$query = "CREATE EXTENSION postgis";
1393
-			$Connection = new Connection(null,null,$_SESSION['database_root'],$_SESSION['database_rootpass']);
1393
+			$Connection = new Connection(null, null, $_SESSION['database_root'], $_SESSION['database_rootpass']);
1394 1394
 			try {
1395 1395
 				$sth = $Connection->db->prepare($query);
1396 1396
 				$sth->execute();
1397
-			} catch(PDOException $e) {
1397
+			} catch (PDOException $e) {
1398 1398
 				return "error : ".$e->getMessage();
1399 1399
 			}
1400 1400
 		}
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
 		include_once('class.create_db.php');
1408 1408
 		require_once(dirname(__FILE__).'/../require/class.NOTAM.php');
1409 1409
 		if ($globalDebug) echo "NOTAM from FlightAirMap website : Download...";
1410
-		update_db::download('http://data.flightairmap.fr/data/notam.txt.gz',$tmp_dir.'notam.txt.gz');
1410
+		update_db::download('http://data.flightairmap.fr/data/notam.txt.gz', $tmp_dir.'notam.txt.gz');
1411 1411
 		$error = '';
1412 1412
 		if (file_exists($tmp_dir.'notam.txt.gz')) {
1413 1413
 			if ($globalDebug) echo "Gunzip...";
@@ -1439,14 +1439,14 @@  discard block
 block discarded – undo
1439 1439
 			try {
1440 1440
 				$sth = $Connection->db->prepare($query);
1441 1441
             	        	$sth->execute();
1442
-	                } catch(PDOException $e) {
1442
+	                } catch (PDOException $e) {
1443 1443
     	                	echo "error : ".$e->getMessage();
1444 1444
 	                }
1445 1445
 		}
1446 1446
 		if ($globalDBdriver == 'mysql') {
1447
-			update_db::gunzip('../db/countries.sql.gz',$tmp_dir.'countries.sql');
1447
+			update_db::gunzip('../db/countries.sql.gz', $tmp_dir.'countries.sql');
1448 1448
 		} else {
1449
-			update_db::gunzip('../db/pgsql/countries.sql.gz',$tmp_dir.'countries.sql');
1449
+			update_db::gunzip('../db/pgsql/countries.sql.gz', $tmp_dir.'countries.sql');
1450 1450
 		}
1451 1451
 		$error = create_db::import_file($tmp_dir.'countries.sql');
1452 1452
 		return $error;
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
 //		update_db::unzip($tmp_dir.'AptNav.zip');
1460 1460
 //		update_db::download('https://gitorious.org/fg/fgdata/raw/e81f8a15424a175a7b715f8f7eb8f4147b802a27:Navaids/awy.dat.gz',$tmp_dir.'awy.dat.gz');
1461 1461
 //		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');
1462
-		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');
1462
+		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');
1463 1463
 		update_db::gunzip($tmp_dir.'awy.dat.gz');
1464 1464
 		$error = update_db::waypoints($tmp_dir.'awy.dat');
1465 1465
 		return $error;
@@ -1479,7 +1479,7 @@  discard block
 block discarded – undo
1479 1479
 			update_db::ivao_airlines($tmp_dir.'data/airlines.dat');
1480 1480
 			if ($globalDebug) echo "Copy airlines logos to airlines images directory...";
1481 1481
 			if (is_writable(dirname(__FILE__).'/../images/airlines')) {
1482
-				if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) $error = "Failed to copy airlines logo.";
1482
+				if (!$Common->xcopy($tmp_dir.'logos/', dirname(__FILE__).'/../images/airlines/')) $error = "Failed to copy airlines logo.";
1483 1483
 			} else $error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable";
1484 1484
 		} else $error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed.";
1485 1485
 		if ($error != '') {
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
 		global $tmp_dir, $globalDebug;
1493 1493
 		$error = '';
1494 1494
 		if ($globalDebug) echo "Routes : Download...";
1495
-		update_db::download('http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz',$tmp_dir.'StandingData.sqb.gz');
1495
+		update_db::download('http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz', $tmp_dir.'StandingData.sqb.gz');
1496 1496
 		if (file_exists($tmp_dir.'StandingData.sqb.gz')) {
1497 1497
 			if ($globalDebug) echo "Gunzip...";
1498 1498
 			update_db::gunzip($tmp_dir.'StandingData.sqb.gz');
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 		global $tmp_dir, $globalDebug;
1509 1509
 		$error = '';
1510 1510
 		if ($globalDebug) echo "Schedules Oneworld : Download...";
1511
-		update_db::download('http://data.flightairmap.fr/data/schedules/oneworld.csv.gz',$tmp_dir.'oneworld.csv.gz');
1511
+		update_db::download('http://data.flightairmap.fr/data/schedules/oneworld.csv.gz', $tmp_dir.'oneworld.csv.gz');
1512 1512
 		if (file_exists($tmp_dir.'oneworld.csv.gz')) {
1513 1513
 			if ($globalDebug) echo "Gunzip...";
1514 1514
 			update_db::gunzip($tmp_dir.'oneworld.csv.gz');
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
 		global $tmp_dir, $globalDebug;
1525 1525
 		$error = '';
1526 1526
 		if ($globalDebug) echo "Schedules Skyteam : Download...";
1527
-		update_db::download('http://data.flightairmap.fr/data/schedules/skyteam.csv.gz',$tmp_dir.'skyteam.csv.gz');
1527
+		update_db::download('http://data.flightairmap.fr/data/schedules/skyteam.csv.gz', $tmp_dir.'skyteam.csv.gz');
1528 1528
 		if (file_exists($tmp_dir.'skyteam.csv.gz')) {
1529 1529
 			if ($globalDebug) echo "Gunzip...";
1530 1530
 			update_db::gunzip($tmp_dir.'skyteam.csv.gz');
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
 */
1553 1553
 		if ($globalDebug) echo "Modes : Download...";
1554 1554
 //		update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb');
1555
-		update_db::download('http://data.flightairmap.fr/data/BaseStation.sqb.gz',$tmp_dir.'BaseStation.sqb.gz');
1555
+		update_db::download('http://data.flightairmap.fr/data/BaseStation.sqb.gz', $tmp_dir.'BaseStation.sqb.gz');
1556 1556
 
1557 1557
 //		if (file_exists($tmp_dir.'basestation_latest.zip')) {
1558 1558
 		if (file_exists($tmp_dir.'BaseStation.sqb.gz')) {
@@ -1572,7 +1572,7 @@  discard block
 block discarded – undo
1572 1572
 	public static function update_ModeS_faa() {
1573 1573
 		global $tmp_dir, $globalDebug;
1574 1574
 		if ($globalDebug) echo "Modes FAA: Download...";
1575
-		update_db::download('http://registry.faa.gov/database/ReleasableAircraft.zip',$tmp_dir.'ReleasableAircraft.zip');
1575
+		update_db::download('http://registry.faa.gov/database/ReleasableAircraft.zip', $tmp_dir.'ReleasableAircraft.zip');
1576 1576
 		if (file_exists($tmp_dir.'ReleasableAircraft.zip')) {
1577 1577
 			if ($globalDebug) echo "Unzip...";
1578 1578
 			update_db::unzip($tmp_dir.'ReleasableAircraft.zip');
@@ -1588,7 +1588,7 @@  discard block
 block discarded – undo
1588 1588
 	public static function update_ModeS_flarm() {
1589 1589
 		global $tmp_dir, $globalDebug;
1590 1590
 		if ($globalDebug) echo "Modes Flarmnet: Download...";
1591
-		update_db::download('http://flarmnet.org/files/data.fln',$tmp_dir.'data.fln');
1591
+		update_db::download('http://flarmnet.org/files/data.fln', $tmp_dir.'data.fln');
1592 1592
 		if (file_exists($tmp_dir.'data.fln')) {
1593 1593
 			if ($globalDebug) echo "Add to DB...";
1594 1594
 			$error = update_db::retrieve_modes_flarmnet($tmp_dir.'data.fln');
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 	public static function update_ModeS_ogn() {
1603 1603
 		global $tmp_dir, $globalDebug;
1604 1604
 		if ($globalDebug) echo "Modes OGN: Download...";
1605
-		update_db::download('http://ddb.glidernet.org/download/',$tmp_dir.'ogn.csv');
1605
+		update_db::download('http://ddb.glidernet.org/download/', $tmp_dir.'ogn.csv');
1606 1606
 		if (file_exists($tmp_dir.'ogn.csv')) {
1607 1607
 			if ($globalDebug) echo "Add to DB...";
1608 1608
 			$error = update_db::retrieve_modes_ogn($tmp_dir.'ogn.csv');
@@ -1617,173 +1617,173 @@  discard block
 block discarded – undo
1617 1617
 		global $tmp_dir, $globalDebug;
1618 1618
 		
1619 1619
 		if ($globalDebug) echo "Owner France: Download...";
1620
-		update_db::download('http://antonakis.co.uk/registers/France.txt',$tmp_dir.'owner_f.csv');
1620
+		update_db::download('http://antonakis.co.uk/registers/France.txt', $tmp_dir.'owner_f.csv');
1621 1621
 		if (file_exists($tmp_dir.'owner_f.csv')) {
1622 1622
 			if ($globalDebug) echo "Add to DB...";
1623
-			$error = update_db::retrieve_owner($tmp_dir.'owner_f.csv','F');
1623
+			$error = update_db::retrieve_owner($tmp_dir.'owner_f.csv', 'F');
1624 1624
 		} else $error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed.";
1625 1625
 		if ($error != '') {
1626 1626
 			return $error;
1627 1627
 		} elseif ($globalDebug) echo "Done\n";
1628 1628
 		
1629 1629
 		if ($globalDebug) echo "Owner Ireland: Download...";
1630
-		update_db::download('http://antonakis.co.uk/registers/Ireland.txt',$tmp_dir.'owner_ei.csv');
1630
+		update_db::download('http://antonakis.co.uk/registers/Ireland.txt', $tmp_dir.'owner_ei.csv');
1631 1631
 		if (file_exists($tmp_dir.'owner_ei.csv')) {
1632 1632
 			if ($globalDebug) echo "Add to DB...";
1633
-			$error = update_db::retrieve_owner($tmp_dir.'owner_ei.csv','EI');
1633
+			$error = update_db::retrieve_owner($tmp_dir.'owner_ei.csv', 'EI');
1634 1634
 		} else $error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed.";
1635 1635
 		if ($error != '') {
1636 1636
 			return $error;
1637 1637
 		} elseif ($globalDebug) echo "Done\n";
1638 1638
 		if ($globalDebug) echo "Owner Switzerland: Download...";
1639
-		update_db::download('http://antonakis.co.uk/registers/Switzerland.txt',$tmp_dir.'owner_hb.csv');
1639
+		update_db::download('http://antonakis.co.uk/registers/Switzerland.txt', $tmp_dir.'owner_hb.csv');
1640 1640
 		if (file_exists($tmp_dir.'owner_hb.csv')) {
1641 1641
 			if ($globalDebug) echo "Add to DB...";
1642
-			$error = update_db::retrieve_owner($tmp_dir.'owner_hb.csv','HB');
1642
+			$error = update_db::retrieve_owner($tmp_dir.'owner_hb.csv', 'HB');
1643 1643
 		} else $error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed.";
1644 1644
 		if ($error != '') {
1645 1645
 			return $error;
1646 1646
 		} elseif ($globalDebug) echo "Done\n";
1647 1647
 		if ($globalDebug) echo "Owner Czech Republic: Download...";
1648
-		update_db::download('http://antonakis.co.uk/registers/CzechRepublic.txt',$tmp_dir.'owner_ok.csv');
1648
+		update_db::download('http://antonakis.co.uk/registers/CzechRepublic.txt', $tmp_dir.'owner_ok.csv');
1649 1649
 		if (file_exists($tmp_dir.'owner_ok.csv')) {
1650 1650
 			if ($globalDebug) echo "Add to DB...";
1651
-			$error = update_db::retrieve_owner($tmp_dir.'owner_ok.csv','OK');
1651
+			$error = update_db::retrieve_owner($tmp_dir.'owner_ok.csv', 'OK');
1652 1652
 		} else $error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed.";
1653 1653
 		if ($error != '') {
1654 1654
 			return $error;
1655 1655
 		} elseif ($globalDebug) echo "Done\n";
1656 1656
 		if ($globalDebug) echo "Owner Australia: Download...";
1657
-		update_db::download('http://antonakis.co.uk/registers/Australia.txt',$tmp_dir.'owner_vh.csv');
1657
+		update_db::download('http://antonakis.co.uk/registers/Australia.txt', $tmp_dir.'owner_vh.csv');
1658 1658
 		if (file_exists($tmp_dir.'owner_vh.csv')) {
1659 1659
 			if ($globalDebug) echo "Add to DB...";
1660
-			$error = update_db::retrieve_owner($tmp_dir.'owner_vh.csv','VH');
1660
+			$error = update_db::retrieve_owner($tmp_dir.'owner_vh.csv', 'VH');
1661 1661
 		} else $error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed.";
1662 1662
 		if ($error != '') {
1663 1663
 			return $error;
1664 1664
 		} elseif ($globalDebug) echo "Done\n";
1665 1665
 		if ($globalDebug) echo "Owner Austria: Download...";
1666
-		update_db::download('http://antonakis.co.uk/registers/Austria.txt',$tmp_dir.'owner_oe.csv');
1666
+		update_db::download('http://antonakis.co.uk/registers/Austria.txt', $tmp_dir.'owner_oe.csv');
1667 1667
 		if (file_exists($tmp_dir.'owner_oe.csv')) {
1668 1668
 			if ($globalDebug) echo "Add to DB...";
1669
-			$error = update_db::retrieve_owner($tmp_dir.'owner_oe.csv','OE');
1669
+			$error = update_db::retrieve_owner($tmp_dir.'owner_oe.csv', 'OE');
1670 1670
 		} else $error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed.";
1671 1671
 		if ($error != '') {
1672 1672
 			return $error;
1673 1673
 		} elseif ($globalDebug) echo "Done\n";
1674 1674
 		if ($globalDebug) echo "Owner Chile: Download...";
1675
-		update_db::download('http://antonakis.co.uk/registers/Chile.txt',$tmp_dir.'owner_cc.csv');
1675
+		update_db::download('http://antonakis.co.uk/registers/Chile.txt', $tmp_dir.'owner_cc.csv');
1676 1676
 		if (file_exists($tmp_dir.'owner_cc.csv')) {
1677 1677
 			if ($globalDebug) echo "Add to DB...";
1678
-			$error = update_db::retrieve_owner($tmp_dir.'owner_cc.csv','CC');
1678
+			$error = update_db::retrieve_owner($tmp_dir.'owner_cc.csv', 'CC');
1679 1679
 		} else $error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed.";
1680 1680
 		if ($error != '') {
1681 1681
 			return $error;
1682 1682
 		} elseif ($globalDebug) echo "Done\n";
1683 1683
 		if ($globalDebug) echo "Owner Colombia: Download...";
1684
-		update_db::download('http://antonakis.co.uk/registers/Colombia.txt',$tmp_dir.'owner_hj.csv');
1684
+		update_db::download('http://antonakis.co.uk/registers/Colombia.txt', $tmp_dir.'owner_hj.csv');
1685 1685
 		if (file_exists($tmp_dir.'owner_hj.csv')) {
1686 1686
 			if ($globalDebug) echo "Add to DB...";
1687
-			$error = update_db::retrieve_owner($tmp_dir.'owner_hj.csv','HJ');
1687
+			$error = update_db::retrieve_owner($tmp_dir.'owner_hj.csv', 'HJ');
1688 1688
 		} else $error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed.";
1689 1689
 		if ($error != '') {
1690 1690
 			return $error;
1691 1691
 		} elseif ($globalDebug) echo "Done\n";
1692 1692
 		if ($globalDebug) echo "Owner Bosnia Herzegobina: Download...";
1693
-		update_db::download('http://antonakis.co.uk/registers/BosniaHerzegovina.txt',$tmp_dir.'owner_e7.csv');
1693
+		update_db::download('http://antonakis.co.uk/registers/BosniaHerzegovina.txt', $tmp_dir.'owner_e7.csv');
1694 1694
 		if (file_exists($tmp_dir.'owner_e7.csv')) {
1695 1695
 			if ($globalDebug) echo "Add to DB...";
1696
-			$error = update_db::retrieve_owner($tmp_dir.'owner_e7.csv','E7');
1696
+			$error = update_db::retrieve_owner($tmp_dir.'owner_e7.csv', 'E7');
1697 1697
 		} else $error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed.";
1698 1698
 		if ($error != '') {
1699 1699
 			return $error;
1700 1700
 		} elseif ($globalDebug) echo "Done\n";
1701 1701
 		if ($globalDebug) echo "Owner Brazil: Download...";
1702
-		update_db::download('http://antonakis.co.uk/registers/Brazil.txt',$tmp_dir.'owner_pp.csv');
1702
+		update_db::download('http://antonakis.co.uk/registers/Brazil.txt', $tmp_dir.'owner_pp.csv');
1703 1703
 		if (file_exists($tmp_dir.'owner_pp.csv')) {
1704 1704
 			if ($globalDebug) echo "Add to DB...";
1705
-			$error = update_db::retrieve_owner($tmp_dir.'owner_pp.csv','PP');
1705
+			$error = update_db::retrieve_owner($tmp_dir.'owner_pp.csv', 'PP');
1706 1706
 		} else $error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed.";
1707 1707
 		if ($error != '') {
1708 1708
 			return $error;
1709 1709
 		} elseif ($globalDebug) echo "Done\n";
1710 1710
 		if ($globalDebug) echo "Owner Cayman Islands: Download...";
1711
-		update_db::download('http://antonakis.co.uk/registers/CaymanIslands.txt',$tmp_dir.'owner_vp.csv');
1711
+		update_db::download('http://antonakis.co.uk/registers/CaymanIslands.txt', $tmp_dir.'owner_vp.csv');
1712 1712
 		if (file_exists($tmp_dir.'owner_vp.csv')) {
1713 1713
 			if ($globalDebug) echo "Add to DB...";
1714
-			$error = update_db::retrieve_owner($tmp_dir.'owner_vp.csv','VP');
1714
+			$error = update_db::retrieve_owner($tmp_dir.'owner_vp.csv', 'VP');
1715 1715
 		} else $error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed.";
1716 1716
 		if ($error != '') {
1717 1717
 			return $error;
1718 1718
 		} elseif ($globalDebug) echo "Done\n";
1719 1719
 		if ($globalDebug) echo "Owner Croatia: Download...";
1720
-		update_db::download('http://antonakis.co.uk/registers/Croatia.txt',$tmp_dir.'owner_9a.csv');
1720
+		update_db::download('http://antonakis.co.uk/registers/Croatia.txt', $tmp_dir.'owner_9a.csv');
1721 1721
 		if (file_exists($tmp_dir.'owner_9a.csv')) {
1722 1722
 			if ($globalDebug) echo "Add to DB...";
1723
-			$error = update_db::retrieve_owner($tmp_dir.'owner_9a.csv','9A');
1723
+			$error = update_db::retrieve_owner($tmp_dir.'owner_9a.csv', '9A');
1724 1724
 		} else $error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed.";
1725 1725
 		if ($error != '') {
1726 1726
 			return $error;
1727 1727
 		} elseif ($globalDebug) echo "Done\n";
1728 1728
 		if ($globalDebug) echo "Owner Luxembourg: Download...";
1729
-		update_db::download('http://antonakis.co.uk/registers/Luxembourg.txt',$tmp_dir.'owner_lx.csv');
1729
+		update_db::download('http://antonakis.co.uk/registers/Luxembourg.txt', $tmp_dir.'owner_lx.csv');
1730 1730
 		if (file_exists($tmp_dir.'owner_lx.csv')) {
1731 1731
 			if ($globalDebug) echo "Add to DB...";
1732
-			$error = update_db::retrieve_owner($tmp_dir.'owner_lx.csv','LX');
1732
+			$error = update_db::retrieve_owner($tmp_dir.'owner_lx.csv', 'LX');
1733 1733
 		} else $error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed.";
1734 1734
 		if ($error != '') {
1735 1735
 			return $error;
1736 1736
 		} elseif ($globalDebug) echo "Done\n";
1737 1737
 		if ($globalDebug) echo "Owner Maldives: Download...";
1738
-		update_db::download('http://antonakis.co.uk/registers/Maldives.txt',$tmp_dir.'owner_8q.csv');
1738
+		update_db::download('http://antonakis.co.uk/registers/Maldives.txt', $tmp_dir.'owner_8q.csv');
1739 1739
 		if (file_exists($tmp_dir.'owner_8q.csv')) {
1740 1740
 			if ($globalDebug) echo "Add to DB...";
1741
-			$error = update_db::retrieve_owner($tmp_dir.'owner_8q.csv','8Q');
1741
+			$error = update_db::retrieve_owner($tmp_dir.'owner_8q.csv', '8Q');
1742 1742
 		} else $error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed.";
1743 1743
 		if ($error != '') {
1744 1744
 			return $error;
1745 1745
 		} elseif ($globalDebug) echo "Done\n";
1746 1746
 		if ($globalDebug) echo "Owner New Zealand: Download...";
1747
-		update_db::download('http://antonakis.co.uk/registers/NewZealand.txt',$tmp_dir.'owner_zk.csv');
1747
+		update_db::download('http://antonakis.co.uk/registers/NewZealand.txt', $tmp_dir.'owner_zk.csv');
1748 1748
 		if (file_exists($tmp_dir.'owner_zk.csv')) {
1749 1749
 			if ($globalDebug) echo "Add to DB...";
1750
-			$error = update_db::retrieve_owner($tmp_dir.'owner_zk.csv','ZK');
1750
+			$error = update_db::retrieve_owner($tmp_dir.'owner_zk.csv', 'ZK');
1751 1751
 		} else $error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed.";
1752 1752
 		if ($error != '') {
1753 1753
 			return $error;
1754 1754
 		} elseif ($globalDebug) echo "Done\n";
1755 1755
 		if ($globalDebug) echo "Owner Papua New Guinea: Download...";
1756
-		update_db::download('http://antonakis.co.uk/registers/PapuaNewGuinea.txt',$tmp_dir.'owner_p2.csv');
1756
+		update_db::download('http://antonakis.co.uk/registers/PapuaNewGuinea.txt', $tmp_dir.'owner_p2.csv');
1757 1757
 		if (file_exists($tmp_dir.'owner_p2.csv')) {
1758 1758
 			if ($globalDebug) echo "Add to DB...";
1759
-			$error = update_db::retrieve_owner($tmp_dir.'owner_p2.csv','P2');
1759
+			$error = update_db::retrieve_owner($tmp_dir.'owner_p2.csv', 'P2');
1760 1760
 		} else $error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed.";
1761 1761
 		if ($error != '') {
1762 1762
 			return $error;
1763 1763
 		} elseif ($globalDebug) echo "Done\n";
1764 1764
 		if ($globalDebug) echo "Owner Slovakia: Download...";
1765
-		update_db::download('http://antonakis.co.uk/registers/Slovakia.txt',$tmp_dir.'owner_om.csv');
1765
+		update_db::download('http://antonakis.co.uk/registers/Slovakia.txt', $tmp_dir.'owner_om.csv');
1766 1766
 		if (file_exists($tmp_dir.'owner_om.csv')) {
1767 1767
 			if ($globalDebug) echo "Add to DB...";
1768
-			$error = update_db::retrieve_owner($tmp_dir.'owner_om.csv','OM');
1768
+			$error = update_db::retrieve_owner($tmp_dir.'owner_om.csv', 'OM');
1769 1769
 		} else $error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed.";
1770 1770
 		if ($error != '') {
1771 1771
 			return $error;
1772 1772
 		} elseif ($globalDebug) echo "Done\n";
1773 1773
 		if ($globalDebug) echo "Owner Ecuador: Download...";
1774
-		update_db::download('http://antonakis.co.uk/registers/Ecuador.txt',$tmp_dir.'owner_hc.csv');
1774
+		update_db::download('http://antonakis.co.uk/registers/Ecuador.txt', $tmp_dir.'owner_hc.csv');
1775 1775
 		if (file_exists($tmp_dir.'owner_hc.csv')) {
1776 1776
 			if ($globalDebug) echo "Add to DB...";
1777
-			$error = update_db::retrieve_owner($tmp_dir.'owner_hc.csv','HC');
1777
+			$error = update_db::retrieve_owner($tmp_dir.'owner_hc.csv', 'HC');
1778 1778
 		} else $error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed.";
1779 1779
 		if ($error != '') {
1780 1780
 			return $error;
1781 1781
 		} elseif ($globalDebug) echo "Done\n";
1782 1782
 		if ($globalDebug) echo "Owner Iceland: Download...";
1783
-		update_db::download('http://antonakis.co.uk/registers/Iceland.txt',$tmp_dir.'owner_tf.csv');
1783
+		update_db::download('http://antonakis.co.uk/registers/Iceland.txt', $tmp_dir.'owner_tf.csv');
1784 1784
 		if (file_exists($tmp_dir.'owner_tf.csv')) {
1785 1785
 			if ($globalDebug) echo "Add to DB...";
1786
-			$error = update_db::retrieve_owner($tmp_dir.'owner_tf.csv','TF');
1786
+			$error = update_db::retrieve_owner($tmp_dir.'owner_tf.csv', 'TF');
1787 1787
 		} else $error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed.";
1788 1788
 		if ($error != '') {
1789 1789
 			return $error;
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
 		global $tmp_dir, $globalDebug;
1796 1796
 		$error = '';
1797 1797
 		if ($globalDebug) echo "Translation : Download...";
1798
-		update_db::download('http://www.acarsd.org/download/translation.php',$tmp_dir.'translation.zip');
1798
+		update_db::download('http://www.acarsd.org/download/translation.php', $tmp_dir.'translation.zip');
1799 1799
 		if (file_exists($tmp_dir.'translation.zip')) {
1800 1800
 			if ($globalDebug) echo "Unzip...";
1801 1801
 			update_db::unzip($tmp_dir.'translation.zip');
@@ -1811,7 +1811,7 @@  discard block
 block discarded – undo
1811 1811
 	public static function update_translation_fam() {
1812 1812
 		global $tmp_dir, $globalDebug;
1813 1813
 		if ($globalDebug) echo "Translation from FlightAirMap website : Download...";
1814
-		update_db::download('http://data.flightairmap.fr/data/translation.tsv.gz',$tmp_dir.'translation.tsv.gz');
1814
+		update_db::download('http://data.flightairmap.fr/data/translation.tsv.gz', $tmp_dir.'translation.tsv.gz');
1815 1815
 		if (file_exists($tmp_dir.'translation.tsv.gz')) {
1816 1816
 			if ($globalDebug) echo "Gunzip...";
1817 1817
 			update_db::gunzip($tmp_dir.'translation.tsv.gz');
@@ -1826,7 +1826,7 @@  discard block
 block discarded – undo
1826 1826
 	public static function update_ModeS_fam() {
1827 1827
 		global $tmp_dir, $globalDebug;
1828 1828
 		if ($globalDebug) echo "ModeS from FlightAirMap website : Download...";
1829
-		update_db::download('http://data.flightairmap.fr/data/modes.tsv.gz',$tmp_dir.'modes.tsv.gz');
1829
+		update_db::download('http://data.flightairmap.fr/data/modes.tsv.gz', $tmp_dir.'modes.tsv.gz');
1830 1830
 		if (file_exists($tmp_dir.'modes.tsv.gz')) {
1831 1831
 			if ($globalDebug) echo "Gunzip...";
1832 1832
 			update_db::gunzip($tmp_dir.'modes.tsv.gz');
@@ -1842,9 +1842,9 @@  discard block
 block discarded – undo
1842 1842
 		global $tmp_dir, $globalDebug, $globalOwner;
1843 1843
 		if ($globalDebug) echo "owner from FlightAirMap website : Download...";
1844 1844
 		if ($globalOwner === TRUE) {
1845
-			update_db::download('http://data.flightairmap.fr/data/owners_all.tsv.gz',$tmp_dir.'owners.tsv.gz');
1845
+			update_db::download('http://data.flightairmap.fr/data/owners_all.tsv.gz', $tmp_dir.'owners.tsv.gz');
1846 1846
 		} else {
1847
-			update_db::download('http://data.flightairmap.fr/data/owners.tsv.gz',$tmp_dir.'owners.tsv.gz');
1847
+			update_db::download('http://data.flightairmap.fr/data/owners.tsv.gz', $tmp_dir.'owners.tsv.gz');
1848 1848
 		}
1849 1849
 		if (file_exists($tmp_dir.'owners.tsv.gz')) {
1850 1850
 			if ($globalDebug) echo "Gunzip...";
@@ -1860,7 +1860,7 @@  discard block
 block discarded – undo
1860 1860
 	public static function update_routes_fam() {
1861 1861
 		global $tmp_dir, $globalDebug;
1862 1862
 		if ($globalDebug) echo "Routes from FlightAirMap website : Download...";
1863
-		update_db::download('http://data.flightairmap.fr/data/routes.tsv.gz',$tmp_dir.'routes.tsv.gz');
1863
+		update_db::download('http://data.flightairmap.fr/data/routes.tsv.gz', $tmp_dir.'routes.tsv.gz');
1864 1864
 		if (file_exists($tmp_dir.'routes.tsv.gz')) {
1865 1865
 			if ($globalDebug) echo "Gunzip...";
1866 1866
 			update_db::gunzip($tmp_dir.'routes.tsv.gz');
@@ -1879,18 +1879,18 @@  discard block
 block discarded – undo
1879 1879
 		$error = '';
1880 1880
 		if ($globalDebug) echo "Airspace from FlightAirMap website : Download...";
1881 1881
 		if ($globalDBdriver == 'mysql') {
1882
-			update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5');
1882
+			update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz.md5', $tmp_dir.'airspace.sql.gz.md5');
1883 1883
 		} else {
1884
-			update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5');
1884
+			update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz.md5', $tmp_dir.'airspace.sql.gz.md5');
1885 1885
 		}
1886 1886
 		if (file_exists($tmp_dir.'airspace.sql.gz.md5')) {
1887
-			$airspace_md5_file = explode(' ',file_get_contents($tmp_dir.'airspace.sql.gz.md5'));
1887
+			$airspace_md5_file = explode(' ', file_get_contents($tmp_dir.'airspace.sql.gz.md5'));
1888 1888
 			$airspace_md5 = $airspace_md5_file[0];
1889 1889
 			if (!update_db::check_airspace_version($airspace_md5)) {
1890 1890
 				if ($globalDBdriver == 'mysql') {
1891
-					update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz',$tmp_dir.'airspace.sql.gz');
1891
+					update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz', $tmp_dir.'airspace.sql.gz');
1892 1892
 				} else {
1893
-					update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz',$tmp_dir.'airspace.sql.gz');
1893
+					update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz', $tmp_dir.'airspace.sql.gz');
1894 1894
 				}
1895 1895
 				if (file_exists($tmp_dir.'airspace.sql.gz')) {
1896 1896
 					if ($globalDebug) echo "Gunzip...";
@@ -1902,7 +1902,7 @@  discard block
 block discarded – undo
1902 1902
 						try {
1903 1903
 							$sth = $Connection->db->prepare($query);
1904 1904
     	    	    					$sth->execute();
1905
-			            		} catch(PDOException $e) {
1905
+			            		} catch (PDOException $e) {
1906 1906
 							return "error : ".$e->getMessage();
1907 1907
 		            			}
1908 1908
 		    			}
@@ -1920,15 +1920,15 @@  discard block
 block discarded – undo
1920 1920
 	public static function update_tle() {
1921 1921
 		global $tmp_dir, $globalDebug;
1922 1922
 		if ($globalDebug) echo "Download TLE : Download...";
1923
-		$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',
1924
-		'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',
1925
-		'engineering.txt','education.txt','military.txt','radar.txt','cubesat.txt','other.txt','tle-new.txt');
1923
+		$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',
1924
+		'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',
1925
+		'engineering.txt', 'education.txt', 'military.txt', 'radar.txt', 'cubesat.txt', 'other.txt', 'tle-new.txt');
1926 1926
 		foreach ($alltle as $filename) {
1927 1927
 			if ($globalDebug) echo "downloading ".$filename.'...';
1928
-			update_db::download('http://celestrak.com/NORAD/elements/'.$filename,$tmp_dir.$filename);
1928
+			update_db::download('http://celestrak.com/NORAD/elements/'.$filename, $tmp_dir.$filename);
1929 1929
 			if (file_exists($tmp_dir.$filename)) {
1930 1930
 				if ($globalDebug) echo "Add to DB ".$filename."...";
1931
-				$error = update_db::tle($tmp_dir.$filename,str_replace('.txt','',$filename));
1931
+				$error = update_db::tle($tmp_dir.$filename, str_replace('.txt', '', $filename));
1932 1932
 			} else $error = "File ".$tmp_dir.$filename." doesn't exist. Download failed.";
1933 1933
 			if ($error != '') {
1934 1934
 				echo $error."\n";
@@ -1941,32 +1941,32 @@  discard block
 block discarded – undo
1941 1941
 		global $tmp_dir, $globalDebug;
1942 1942
 		$error = '';
1943 1943
 		if ($globalDebug) echo "Models from FlightAirMap website : Download...";
1944
-		update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',$tmp_dir.'models.md5sum');
1944
+		update_db::download('http://data.flightairmap.fr/data/models/models.md5sum', $tmp_dir.'models.md5sum');
1945 1945
 		if (file_exists($tmp_dir.'models.md5sum')) {
1946 1946
 			if ($globalDebug) echo "Check files...\n";
1947 1947
 			$newmodelsdb = array();
1948
-			if (($handle = fopen($tmp_dir.'models.md5sum','r')) !== FALSE) {
1949
-				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
1948
+			if (($handle = fopen($tmp_dir.'models.md5sum', 'r')) !== FALSE) {
1949
+				while (($row = fgetcsv($handle, 1000, " ")) !== FALSE) {
1950 1950
 					$model = trim($row[2]);
1951 1951
 					$newmodelsdb[$model] = trim($row[0]);
1952 1952
 				}
1953 1953
 			}
1954 1954
 			$modelsdb = array();
1955 1955
 			if (file_exists(dirname(__FILE__).'/../models/models.md5sum')) {
1956
-				if (($handle = fopen(dirname(__FILE__).'/../models/models.md5sum','r')) !== FALSE) {
1957
-					while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
1956
+				if (($handle = fopen(dirname(__FILE__).'/../models/models.md5sum', 'r')) !== FALSE) {
1957
+					while (($row = fgetcsv($handle, 1000, " ")) !== FALSE) {
1958 1958
 						$model = trim($row[2]);
1959 1959
 						$modelsdb[$model] = trim($row[0]);
1960 1960
 					}
1961 1961
 				}
1962 1962
 			}
1963
-			$diff = array_diff($newmodelsdb,$modelsdb);
1963
+			$diff = array_diff($newmodelsdb, $modelsdb);
1964 1964
 			foreach ($diff as $key => $value) {
1965 1965
 				if ($globalDebug) echo 'Downloading model '.$key.' ...'."\n";
1966
-				update_db::download('http://data.flightairmap.fr/data/models/'.$key,dirname(__FILE__).'/../models/'.$key);
1966
+				update_db::download('http://data.flightairmap.fr/data/models/'.$key, dirname(__FILE__).'/../models/'.$key);
1967 1967
 				
1968 1968
 			}
1969
-			update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',dirname(__FILE__).'/../models/models.md5sum');
1969
+			update_db::download('http://data.flightairmap.fr/data/models/models.md5sum', dirname(__FILE__).'/../models/models.md5sum');
1970 1970
 		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
1971 1971
 		if ($error != '') {
1972 1972
 			return $error;
@@ -1978,32 +1978,32 @@  discard block
 block discarded – undo
1978 1978
 		global $tmp_dir, $globalDebug;
1979 1979
 		$error = '';
1980 1980
 		if ($globalDebug) echo "Space models from FlightAirMap website : Download...";
1981
-		update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',$tmp_dir.'space_models.md5sum');
1981
+		update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum', $tmp_dir.'space_models.md5sum');
1982 1982
 		if (file_exists($tmp_dir.'space_models.md5sum')) {
1983 1983
 			if ($globalDebug) echo "Check files...\n";
1984 1984
 			$newmodelsdb = array();
1985
-			if (($handle = fopen($tmp_dir.'space_models.md5sum','r')) !== FALSE) {
1986
-				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
1985
+			if (($handle = fopen($tmp_dir.'space_models.md5sum', 'r')) !== FALSE) {
1986
+				while (($row = fgetcsv($handle, 1000, " ")) !== FALSE) {
1987 1987
 					$model = trim($row[2]);
1988 1988
 					$newmodelsdb[$model] = trim($row[0]);
1989 1989
 				}
1990 1990
 			}
1991 1991
 			$modelsdb = array();
1992 1992
 			if (file_exists(dirname(__FILE__).'/../models/space/space_models.md5sum')) {
1993
-				if (($handle = fopen(dirname(__FILE__).'/../models/space/space_models.md5sum','r')) !== FALSE) {
1994
-					while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
1993
+				if (($handle = fopen(dirname(__FILE__).'/../models/space/space_models.md5sum', 'r')) !== FALSE) {
1994
+					while (($row = fgetcsv($handle, 1000, " ")) !== FALSE) {
1995 1995
 						$model = trim($row[2]);
1996 1996
 						$modelsdb[$model] = trim($row[0]);
1997 1997
 					}
1998 1998
 				}
1999 1999
 			}
2000
-			$diff = array_diff($newmodelsdb,$modelsdb);
2000
+			$diff = array_diff($newmodelsdb, $modelsdb);
2001 2001
 			foreach ($diff as $key => $value) {
2002 2002
 				if ($globalDebug) echo 'Downloading space model '.$key.' ...'."\n";
2003
-				update_db::download('http://data.flightairmap.fr/data/models/space/'.$key,dirname(__FILE__).'/../models/space/'.$key);
2003
+				update_db::download('http://data.flightairmap.fr/data/models/space/'.$key, dirname(__FILE__).'/../models/space/'.$key);
2004 2004
 				
2005 2005
 			}
2006
-			update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',dirname(__FILE__).'/../models/space/space_models.md5sum');
2006
+			update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum', dirname(__FILE__).'/../models/space/space_models.md5sum');
2007 2007
 		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2008 2008
 		if ($error != '') {
2009 2009
 			return $error;
@@ -2026,8 +2026,8 @@  discard block
 block discarded – undo
2026 2026
 		*/
2027 2027
 		if (file_exists($tmp_dir.'aircrafts.html')) {
2028 2028
 		    //var_dump(file_get_html($tmp_dir.'aircrafts.html'));
2029
-		    $fh = fopen($tmp_dir.'aircrafts.html',"r");
2030
-		    $result = fread($fh,100000000);
2029
+		    $fh = fopen($tmp_dir.'aircrafts.html', "r");
2030
+		    $result = fread($fh, 100000000);
2031 2031
 		    //echo $result;
2032 2032
 		    //var_dump(str_get_html($result));
2033 2033
 		    //print_r(self::table2array($result));
@@ -2045,23 +2045,23 @@  discard block
 block discarded – undo
2045 2045
 			$Connection = new Connection();
2046 2046
 			$sth = $Connection->db->prepare($query);
2047 2047
                         $sth->execute();
2048
-                } catch(PDOException $e) {
2048
+                } catch (PDOException $e) {
2049 2049
                         return "error : ".$e->getMessage();
2050 2050
                 }
2051 2051
 
2052 2052
 		$error = '';
2053 2053
 		if ($globalDebug) echo "Notam : Download...";
2054
-		update_db::download($globalNOTAMSource,$tmp_dir.'notam.rss');
2054
+		update_db::download($globalNOTAMSource, $tmp_dir.'notam.rss');
2055 2055
 		if (file_exists($tmp_dir.'notam.rss')) {
2056
-			$notams = json_decode(json_encode(simplexml_load_file($tmp_dir.'notam.rss')),true);
2056
+			$notams = json_decode(json_encode(simplexml_load_file($tmp_dir.'notam.rss')), true);
2057 2057
 			foreach ($notams['channel']['item'] as $notam) {
2058
-				$title = explode(':',$notam['title']);
2058
+				$title = explode(':', $notam['title']);
2059 2059
 				$data['ref'] = trim($title[0]);
2060 2060
 				unset($title[0]);
2061
-				$data['title'] = trim(implode(':',$title));
2062
-				$description = strip_tags($notam['description'],'<pre>');
2063
-				preg_match(':^(.*?)<pre>:',$description,$match);
2064
-				$q = explode('/',$match[1]);
2061
+				$data['title'] = trim(implode(':', $title));
2062
+				$description = strip_tags($notam['description'], '<pre>');
2063
+				preg_match(':^(.*?)<pre>:', $description, $match);
2064
+				$q = explode('/', $match[1]);
2065 2065
 				$data['fir'] = $q[0];
2066 2066
 				$data['code'] = $q[1];
2067 2067
 				$ifrvfr = $q[2];
@@ -2077,30 +2077,30 @@  discard block
 block discarded – undo
2077 2077
 				$data['lower_limit'] = $q[5];
2078 2078
 				$data['upper_limit'] = $q[6];
2079 2079
 				$latlonrad = $q[7];
2080
-				sscanf($latlonrad,'%4c%c%5c%c%3d',$las,$lac,$lns,$lnc,$radius);
2081
-				$latitude = $Common->convertDec($las,'latitude');
2082
-				$longitude = $Common->convertDec($lns,'longitude');
2080
+				sscanf($latlonrad, '%4c%c%5c%c%3d', $las, $lac, $lns, $lnc, $radius);
2081
+				$latitude = $Common->convertDec($las, 'latitude');
2082
+				$longitude = $Common->convertDec($lns, 'longitude');
2083 2083
 				if ($lac == 'S') $latitude = '-'.$latitude;
2084 2084
 				if ($lnc == 'W') $longitude = '-'.$longitude;
2085 2085
 				$data['center_latitude'] = $latitude;
2086 2086
 				$data['center_longitude'] = $longitude;
2087 2087
 				$data['radius'] = intval($radius);
2088 2088
 				
2089
-				preg_match(':<pre>(.*?)</pre>:',$description,$match);
2089
+				preg_match(':<pre>(.*?)</pre>:', $description, $match);
2090 2090
 				$data['text'] = $match[1];
2091
-				preg_match(':</pre>(.*?)$:',$description,$match);
2091
+				preg_match(':</pre>(.*?)$:', $description, $match);
2092 2092
 				$fromto = $match[1];
2093
-				preg_match('#FROM:(.*?)TO:#',$fromto,$match);
2093
+				preg_match('#FROM:(.*?)TO:#', $fromto, $match);
2094 2094
 				$fromall = trim($match[1]);
2095
-				preg_match('#^(.*?) \((.*?)\)$#',$fromall,$match);
2095
+				preg_match('#^(.*?) \((.*?)\)$#', $fromall, $match);
2096 2096
 				$from = trim($match[1]);
2097
-				$data['date_begin'] = date("Y-m-d H:i:s",strtotime($from));
2098
-				preg_match('#TO:(.*?)$#',$fromto,$match);
2097
+				$data['date_begin'] = date("Y-m-d H:i:s", strtotime($from));
2098
+				preg_match('#TO:(.*?)$#', $fromto, $match);
2099 2099
 				$toall = trim($match[1]);
2100
-				if (!preg_match(':Permanent:',$toall)) {
2101
-					preg_match('#^(.*?) \((.*?)\)#',$toall,$match);
2100
+				if (!preg_match(':Permanent:', $toall)) {
2101
+					preg_match('#^(.*?) \((.*?)\)#', $toall, $match);
2102 2102
 					$to = trim($match[1]);
2103
-					$data['date_end'] = date("Y-m-d H:i:s",strtotime($to));
2103
+					$data['date_end'] = date("Y-m-d H:i:s", strtotime($to));
2104 2104
 					$data['permanent'] = 0;
2105 2105
 				} else {
2106 2106
 				    $data['date_end'] = NULL;
@@ -2108,7 +2108,7 @@  discard block
 block discarded – undo
2108 2108
 				}
2109 2109
 				$data['full_notam'] = $notam['title'].'<br>'.$notam['description'];
2110 2110
 				$NOTAM = new NOTAM();
2111
-				$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']);
2111
+				$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']);
2112 2112
 				unset($data);
2113 2113
 			} 
2114 2114
 		} else $error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed.";
@@ -2131,16 +2131,16 @@  discard block
 block discarded – undo
2131 2131
 				$Connection = new Connection();
2132 2132
 				$sth = $Connection->db->prepare($query);
2133 2133
 				$sth->execute();
2134
-			} catch(PDOException $e) {
2134
+			} catch (PDOException $e) {
2135 2135
 				return "error : ".$e->getMessage();
2136 2136
 			}
2137 2137
 		}
2138 2138
 		$Common = new Common();
2139 2139
 		$airspace_lst = $Common->getData('https://raw.githubusercontent.com/XCSoar/xcsoar-data-repository/master/data/airspace.json');
2140
-		$airspace_json = json_decode($airspace_lst,true);
2140
+		$airspace_json = json_decode($airspace_lst, true);
2141 2141
 		foreach ($airspace_json['records'] as $airspace) {
2142 2142
 			if ($globalDebug) echo $airspace['name']."...\n";
2143
-			update_db::download($airspace['uri'],$tmp_dir.$airspace['name']);
2143
+			update_db::download($airspace['uri'], $tmp_dir.$airspace['name']);
2144 2144
 			if (file_exists($tmp_dir.$airspace['name'])) {
2145 2145
 				file_put_contents($tmp_dir.$airspace['name'], utf8_encode(file_get_contents($tmp_dir.$airspace['name'])));
2146 2146
 				//system('recode l9..utf8 '.$tmp_dir.$airspace['name']);
@@ -2164,7 +2164,7 @@  discard block
 block discarded – undo
2164 2164
 			$Connection = new Connection();
2165 2165
 			$sth = $Connection->db->prepare($query);
2166 2166
                         $sth->execute();
2167
-                } catch(PDOException $e) {
2167
+                } catch (PDOException $e) {
2168 2168
                         return "error : ".$e->getMessage();
2169 2169
                 }
2170 2170
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2179,7 +2179,7 @@  discard block
 block discarded – undo
2179 2179
 			$Connection = new Connection();
2180 2180
 			$sth = $Connection->db->prepare($query);
2181 2181
                         $sth->execute();
2182
-                } catch(PDOException $e) {
2182
+                } catch (PDOException $e) {
2183 2183
                         return "error : ".$e->getMessage();
2184 2184
                 }
2185 2185
 	}
@@ -2190,7 +2190,7 @@  discard block
 block discarded – undo
2190 2190
 			$Connection = new Connection();
2191 2191
 			$sth = $Connection->db->prepare($query);
2192 2192
                         $sth->execute(array(':version' => $version));
2193
-                } catch(PDOException $e) {
2193
+                } catch (PDOException $e) {
2194 2194
                         return "error : ".$e->getMessage();
2195 2195
                 }
2196 2196
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2206,7 +2206,7 @@  discard block
 block discarded – undo
2206 2206
 			$Connection = new Connection();
2207 2207
 			$sth = $Connection->db->prepare($query);
2208 2208
                         $sth->execute(array(':version' => $version));
2209
-                } catch(PDOException $e) {
2209
+                } catch (PDOException $e) {
2210 2210
                         return "error : ".$e->getMessage();
2211 2211
                 }
2212 2212
 	}
@@ -2222,7 +2222,7 @@  discard block
 block discarded – undo
2222 2222
 			$Connection = new Connection();
2223 2223
 			$sth = $Connection->db->prepare($query);
2224 2224
                         $sth->execute();
2225
-                } catch(PDOException $e) {
2225
+                } catch (PDOException $e) {
2226 2226
                         return "error : ".$e->getMessage();
2227 2227
                 }
2228 2228
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
 			$Connection = new Connection();
2238 2238
 			$sth = $Connection->db->prepare($query);
2239 2239
                         $sth->execute();
2240
-                } catch(PDOException $e) {
2240
+                } catch (PDOException $e) {
2241 2241
                         return "error : ".$e->getMessage();
2242 2242
                 }
2243 2243
 	}
@@ -2252,7 +2252,7 @@  discard block
 block discarded – undo
2252 2252
 			$Connection = new Connection();
2253 2253
 			$sth = $Connection->db->prepare($query);
2254 2254
                         $sth->execute();
2255
-                } catch(PDOException $e) {
2255
+                } catch (PDOException $e) {
2256 2256
                         return "error : ".$e->getMessage();
2257 2257
                 }
2258 2258
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2267,7 +2267,7 @@  discard block
 block discarded – undo
2267 2267
 			$Connection = new Connection();
2268 2268
 			$sth = $Connection->db->prepare($query);
2269 2269
                         $sth->execute();
2270
-                } catch(PDOException $e) {
2270
+                } catch (PDOException $e) {
2271 2271
                         return "error : ".$e->getMessage();
2272 2272
                 }
2273 2273
 	}
@@ -2283,7 +2283,7 @@  discard block
 block discarded – undo
2283 2283
 			$Connection = new Connection();
2284 2284
 			$sth = $Connection->db->prepare($query);
2285 2285
                         $sth->execute();
2286
-                } catch(PDOException $e) {
2286
+                } catch (PDOException $e) {
2287 2287
                         return "error : ".$e->getMessage();
2288 2288
                 }
2289 2289
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2298,7 +2298,7 @@  discard block
 block discarded – undo
2298 2298
 			$Connection = new Connection();
2299 2299
 			$sth = $Connection->db->prepare($query);
2300 2300
                         $sth->execute();
2301
-                } catch(PDOException $e) {
2301
+                } catch (PDOException $e) {
2302 2302
                         return "error : ".$e->getMessage();
2303 2303
                 }
2304 2304
 	}
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
 			$Connection = new Connection();
2314 2314
 			$sth = $Connection->db->prepare($query);
2315 2315
                         $sth->execute();
2316
-                } catch(PDOException $e) {
2316
+                } catch (PDOException $e) {
2317 2317
                         return "error : ".$e->getMessage();
2318 2318
                 }
2319 2319
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2328,7 +2328,7 @@  discard block
 block discarded – undo
2328 2328
 			$Connection = new Connection();
2329 2329
 			$sth = $Connection->db->prepare($query);
2330 2330
                         $sth->execute();
2331
-                } catch(PDOException $e) {
2331
+                } catch (PDOException $e) {
2332 2332
                         return "error : ".$e->getMessage();
2333 2333
                 }
2334 2334
 	}
@@ -2343,7 +2343,7 @@  discard block
 block discarded – undo
2343 2343
 			$Connection = new Connection();
2344 2344
 			$sth = $Connection->db->prepare($query);
2345 2345
                         $sth->execute();
2346
-                } catch(PDOException $e) {
2346
+                } catch (PDOException $e) {
2347 2347
                         return "error : ".$e->getMessage();
2348 2348
                 }
2349 2349
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -2358,7 +2358,7 @@  discard block
 block discarded – undo
2358 2358
 			$Connection = new Connection();
2359 2359
 			$sth = $Connection->db->prepare($query);
2360 2360
                         $sth->execute();
2361
-                } catch(PDOException $e) {
2361
+                } catch (PDOException $e) {
2362 2362
                         return "error : ".$e->getMessage();
2363 2363
                 }
2364 2364
 	}
@@ -2373,7 +2373,7 @@  discard block
 block discarded – undo
2373 2373
 			$Connection = new Connection();
2374 2374
 			$sth = $Connection->db->prepare($query);
2375 2375
                         $sth->execute();
2376
-                } catch(PDOException $e) {
2376
+                } catch (PDOException $e) {
2377 2377
                         return "error : ".$e->getMessage();
2378 2378
                 }
2379 2379
 	}
@@ -2388,7 +2388,7 @@  discard block
 block discarded – undo
2388 2388
 			$Connection = new Connection();
2389 2389
 			$sth = $Connection->db->prepare($query);
2390 2390
                         $sth->execute();
2391
-                } catch(PDOException $e) {
2391
+                } catch (PDOException $e) {
2392 2392
                         return "error : ".$e->getMessage();
2393 2393
                 }
2394 2394
 	}
Please login to merge, or discard this patch.
Braces   +828 added lines, -287 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 		curl_setopt($ch, CURLOPT_URL, $url);
17 17
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
18 18
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
19
-		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
19
+		if ($referer != '') {
20
+			curl_setopt($ch, CURLOPT_REFERER, $referer);
21
+		}
20 22
 		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');
21 23
 		curl_setopt($ch, CURLOPT_FILE, $fp);
22 24
 		curl_exec($ch);
@@ -27,12 +29,16 @@  discard block
 block discarded – undo
27 29
 	public static function gunzip($in_file,$out_file_name = '') {
28 30
 		//echo $in_file.' -> '.$out_file_name."\n";
29 31
 		$buffer_size = 4096; // read 4kb at a time
30
-		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
32
+		if ($out_file_name == '') {
33
+			$out_file_name = str_replace('.gz', '', $in_file);
34
+		}
31 35
 		if ($in_file != '' && file_exists($in_file)) {
32 36
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
33
-			if (function_exists('gzopen')) $file = gzopen($in_file,'rb');
34
-			elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb');
35
-			else {
37
+			if (function_exists('gzopen')) {
38
+				$file = gzopen($in_file,'rb');
39
+			} elseif (function_exists('gzopen64')) {
40
+				$file = gzopen64($in_file,'rb');
41
+			} else {
36 42
 				echo 'gzopen not available';
37 43
 				die;
38 44
 			}
@@ -53,8 +59,12 @@  discard block
 block discarded – undo
53 59
 			if ($res === TRUE) {
54 60
 				$zip->extractTo($path);
55 61
 				$zip->close();
56
-			} else return false;
57
-		} else return false;
62
+			} else {
63
+				return false;
64
+			}
65
+		} else {
66
+			return false;
67
+		}
58 68
 	}
59 69
 	
60 70
 	public static function connect_sqlite($database) {
@@ -69,7 +79,9 @@  discard block
 block discarded – undo
69 79
 	public static function retrieve_route_sqlite_to_dest($database_file) {
70 80
 		global $globalDebug, $globalTransaction;
71 81
 		//$query = 'TRUNCATE TABLE routes';
72
-		if ($globalDebug) echo " - Delete previous routes from DB -";
82
+		if ($globalDebug) {
83
+			echo " - Delete previous routes from DB -";
84
+		}
73 85
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
74 86
 		$Connection = new Connection();
75 87
 		try {
@@ -80,7 +92,9 @@  discard block
 block discarded – undo
80 92
                         return "error : ".$e->getMessage();
81 93
                 }
82 94
 
83
-    		if ($globalDebug) echo " - Add routes to DB -";
95
+    		if ($globalDebug) {
96
+    			echo " - Add routes to DB -";
97
+    		}
84 98
     		update_db::connect_sqlite($database_file);
85 99
 		//$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';
86 100
 		$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";
@@ -95,15 +109,21 @@  discard block
 block discarded – undo
95 109
 		$Connection = new Connection();
96 110
 		$sth_dest = $Connection->db->prepare($query_dest);
97 111
 		try {
98
-			if ($globalTransaction) $Connection->db->beginTransaction();
112
+			if ($globalTransaction) {
113
+				$Connection->db->beginTransaction();
114
+			}
99 115
             		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
100 116
 				//$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);
101 117
 				$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);
102 118
 				$sth_dest->execute($query_dest_values);
103 119
             		}
104
-			if ($globalTransaction) $Connection->db->commit();
120
+			if ($globalTransaction) {
121
+				$Connection->db->commit();
122
+			}
105 123
 		} catch(PDOException $e) {
106
-			if ($globalTransaction) $Connection->db->rollBack(); 
124
+			if ($globalTransaction) {
125
+				$Connection->db->rollBack();
126
+			}
107 127
 			return "error : ".$e->getMessage();
108 128
 		}
109 129
                 return '';
@@ -111,7 +131,9 @@  discard block
 block discarded – undo
111 131
 	public static function retrieve_route_oneworld($database_file) {
112 132
 		global $globalDebug, $globalTransaction;
113 133
 		//$query = 'TRUNCATE TABLE routes';
114
-		if ($globalDebug) echo " - Delete previous routes from DB -";
134
+		if ($globalDebug) {
135
+			echo " - Delete previous routes from DB -";
136
+		}
115 137
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
116 138
 		$Connection = new Connection();
117 139
 		try {
@@ -122,14 +144,18 @@  discard block
 block discarded – undo
122 144
                         return "error : ".$e->getMessage();
123 145
                 }
124 146
 
125
-    		if ($globalDebug) echo " - Add routes to DB -";
147
+    		if ($globalDebug) {
148
+    			echo " - Add routes to DB -";
149
+    		}
126 150
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
127 151
 		$Spotter = new Spotter();
128 152
 		if ($fh = fopen($database_file,"r")) {
129 153
 			$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)';
130 154
 			$Connection = new Connection();
131 155
 			$sth_dest = $Connection->db->prepare($query_dest);
132
-			if ($globalTransaction) $Connection->db->beginTransaction();
156
+			if ($globalTransaction) {
157
+				$Connection->db->beginTransaction();
158
+			}
133 159
 			while (!feof($fh)) {
134 160
 				$line = fgetcsv($fh,9999,',');
135 161
 				if ($line[0] != '') {
@@ -138,13 +164,17 @@  discard block
 block discarded – undo
138 164
 							$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');
139 165
 							$sth_dest->execute($query_dest_values);
140 166
 						} catch(PDOException $e) {
141
-							if ($globalTransaction) $Connection->db->rollBack(); 
167
+							if ($globalTransaction) {
168
+								$Connection->db->rollBack();
169
+							}
142 170
 							return "error : ".$e->getMessage();
143 171
 						}
144 172
 					}
145 173
 				}
146 174
 			}
147
-			if ($globalTransaction) $Connection->db->commit();
175
+			if ($globalTransaction) {
176
+				$Connection->db->commit();
177
+			}
148 178
 		}
149 179
                 return '';
150 180
 	}
@@ -152,7 +182,9 @@  discard block
 block discarded – undo
152 182
 	public static function retrieve_route_skyteam($database_file) {
153 183
 		global $globalDebug, $globalTransaction;
154 184
 		//$query = 'TRUNCATE TABLE routes';
155
-		if ($globalDebug) echo " - Delete previous routes from DB -";
185
+		if ($globalDebug) {
186
+			echo " - Delete previous routes from DB -";
187
+		}
156 188
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
157 189
 		$Connection = new Connection();
158 190
 		try {
@@ -163,7 +195,9 @@  discard block
 block discarded – undo
163 195
                         return "error : ".$e->getMessage();
164 196
                 }
165 197
 
166
-    		if ($globalDebug) echo " - Add routes to DB -";
198
+    		if ($globalDebug) {
199
+    			echo " - Add routes to DB -";
200
+    		}
167 201
 
168 202
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
169 203
 		$Spotter = new Spotter();
@@ -172,7 +206,9 @@  discard block
 block discarded – undo
172 206
 			$Connection = new Connection();
173 207
 			$sth_dest = $Connection->db->prepare($query_dest);
174 208
 			try {
175
-				if ($globalTransaction) $Connection->db->beginTransaction();
209
+				if ($globalTransaction) {
210
+					$Connection->db->beginTransaction();
211
+				}
176 212
 				while (!feof($fh)) {
177 213
 					$line = fgetcsv($fh,9999,',');
178 214
 					if ($line[0] != '') {
@@ -183,9 +219,13 @@  discard block
 block discarded – undo
183 219
 						}
184 220
 					}
185 221
 				}
186
-				if ($globalTransaction) $Connection->db->commit();
222
+				if ($globalTransaction) {
223
+					$Connection->db->commit();
224
+				}
187 225
 			} catch(PDOException $e) {
188
-				if ($globalTransaction) $Connection->db->rollBack(); 
226
+				if ($globalTransaction) {
227
+					$Connection->db->rollBack();
228
+				}
189 229
 				return "error : ".$e->getMessage();
190 230
 			}
191 231
 		}
@@ -228,11 +268,16 @@  discard block
 block discarded – undo
228 268
 		$sth_dest = $Connection->db->prepare($query_dest);
229 269
 		$sth_dest_owner = $Connection->db->prepare($query_dest_owner);
230 270
 		try {
231
-			if ($globalTransaction) $Connection->db->beginTransaction();
271
+			if ($globalTransaction) {
272
+				$Connection->db->beginTransaction();
273
+			}
232 274
             		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
233 275
 			//$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']);
234
-				if ($values['UserString4'] == 'M') $type = 'military';
235
-				else $type = null;
276
+				if ($values['UserString4'] == 'M') {
277
+					$type = 'military';
278
+				} else {
279
+					$type = null;
280
+				}
236 281
 				$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type);
237 282
 				$sth_dest->execute($query_dest_values);
238 283
 				if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') {
@@ -240,7 +285,9 @@  discard block
 block discarded – undo
240 285
 				    $sth_dest_owner->execute($query_dest_owner_values);
241 286
 				}
242 287
             		}
243
-			if ($globalTransaction) $Connection->db->commit();
288
+			if ($globalTransaction) {
289
+				$Connection->db->commit();
290
+			}
244 291
 		} catch(PDOException $e) {
245 292
 			return "error : ".$e->getMessage();
246 293
 		}
@@ -277,7 +324,9 @@  discard block
 block discarded – undo
277 324
 			$Connection = new Connection();
278 325
 			$sth_dest = $Connection->db->prepare($query_dest);
279 326
 			try {
280
-				if ($globalTransaction) $Connection->db->beginTransaction();
327
+				if ($globalTransaction) {
328
+					$Connection->db->beginTransaction();
329
+				}
281 330
             			while (!feof($fh)) {
282 331
             				$values = array();
283 332
             				$line = $Common->hex2str(fgets($fh,9999));
@@ -288,7 +337,9 @@  discard block
 block discarded – undo
288 337
             				// Check if we can find ICAO, else set it to GLID
289 338
             				$aircraft_name_split = explode(' ',$aircraft_name);
290 339
             				$search_more = '';
291
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
340
+            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) {
341
+            					$search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
342
+            				}
292 343
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
293 344
             				$sth_search = $Connection->db->prepare($query_search);
294 345
 					try {
@@ -301,7 +352,9 @@  discard block
 block discarded – undo
301 352
 					} catch(PDOException $e) {
302 353
 						return "error : ".$e->getMessage();
303 354
 					}
304
-					if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID';
355
+					if (!isset($values['ICAOTypeCode'])) {
356
+						$values['ICAOTypeCode'] = 'GLID';
357
+					}
305 358
 					// Add data to db
306 359
 					if ($values['Registration'] != '' && $values['Registration'] != '0000') {
307 360
 						//$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']);
@@ -310,7 +363,9 @@  discard block
 block discarded – undo
310 363
 						$sth_dest->execute($query_dest_values);
311 364
 					}
312 365
 				}
313
-				if ($globalTransaction) $Connection->db->commit();
366
+				if ($globalTransaction) {
367
+					$Connection->db->commit();
368
+				}
314 369
 			} catch(PDOException $e) {
315 370
 				return "error : ".$e->getMessage();
316 371
 			}
@@ -346,7 +401,9 @@  discard block
 block discarded – undo
346 401
 			$Connection = new Connection();
347 402
 			$sth_dest = $Connection->db->prepare($query_dest);
348 403
 			try {
349
-				if ($globalTransaction) $Connection->db->beginTransaction();
404
+				if ($globalTransaction) {
405
+					$Connection->db->beginTransaction();
406
+				}
350 407
 				$tmp = fgetcsv($fh,9999,',',"'");
351 408
             			while (!feof($fh)) {
352 409
             				$line = fgetcsv($fh,9999,',',"'");
@@ -359,13 +416,17 @@  discard block
 block discarded – undo
359 416
             				// Check if we can find ICAO, else set it to GLID
360 417
             				$aircraft_name_split = explode(' ',$aircraft_name);
361 418
             				$search_more = '';
362
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
419
+            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) {
420
+            					$search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
421
+            				}
363 422
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
364 423
             				$sth_search = $Connection->db->prepare($query_search);
365 424
 					try {
366 425
                                     		$sth_search->execute();
367 426
 	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
368
-	            				if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
427
+	            				if (isset($result['icao']) && $result['icao'] != '') {
428
+	            					$values['ICAOTypeCode'] = $result['icao'];
429
+	            				}
369 430
 					} catch(PDOException $e) {
370 431
 						return "error : ".$e->getMessage();
371 432
 					}
@@ -378,7 +439,9 @@  discard block
 block discarded – undo
378 439
 						$sth_dest->execute($query_dest_values);
379 440
 					}
380 441
 				}
381
-				if ($globalTransaction) $Connection->db->commit();
442
+				if ($globalTransaction) {
443
+					$Connection->db->commit();
444
+				}
382 445
 			} catch(PDOException $e) {
383 446
 				return "error : ".$e->getMessage();
384 447
 			}
@@ -414,7 +477,9 @@  discard block
 block discarded – undo
414 477
 			$Connection = new Connection();
415 478
 			$sth_dest = $Connection->db->prepare($query_dest);
416 479
 			try {
417
-				if ($globalTransaction) $Connection->db->beginTransaction();
480
+				if ($globalTransaction) {
481
+					$Connection->db->beginTransaction();
482
+				}
418 483
 				$tmp = fgetcsv($fh,9999,',','"');
419 484
             			while (!feof($fh)) {
420 485
             				$line = fgetcsv($fh,9999,',','"');
@@ -424,16 +489,22 @@  discard block
 block discarded – undo
424 489
             				    $values['registration'] = $line[0];
425 490
             				    $values['base'] = $line[4];
426 491
             				    $values['owner'] = $line[5];
427
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
428
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
492
+            				    if ($line[6] == '') {
493
+            				    	$values['date_first_reg'] = null;
494
+            				    } else {
495
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
496
+					    }
429 497
 					    $values['cancel'] = $line[7];
430 498
 					} elseif ($country == 'EI') {
431 499
 					    // TODO : add modeS & reg to aircraft_modes
432 500
             				    $values['registration'] = $line[0];
433 501
             				    $values['base'] = $line[3];
434 502
             				    $values['owner'] = $line[2];
435
-            				    if ($line[1] == '') $values['date_first_reg'] = null;
436
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
503
+            				    if ($line[1] == '') {
504
+            				    	$values['date_first_reg'] = null;
505
+            				    } else {
506
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
507
+					    }
437 508
 					    $values['cancel'] = '';
438 509
 					} elseif ($country == 'HB') {
439 510
 					    // TODO : add modeS & reg to aircraft_modes
@@ -447,16 +518,22 @@  discard block
 block discarded – undo
447 518
             				    $values['registration'] = $line[3];
448 519
             				    $values['base'] = null;
449 520
             				    $values['owner'] = $line[5];
450
-            				    if ($line[18] == '') $values['date_first_reg'] = null;
451
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
521
+            				    if ($line[18] == '') {
522
+            				    	$values['date_first_reg'] = null;
523
+            				    } else {
524
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
525
+					    }
452 526
 					    $values['cancel'] = '';
453 527
 					} elseif ($country == 'VH') {
454 528
 					    // TODO : add modeS & reg to aircraft_modes
455 529
             				    $values['registration'] = $line[0];
456 530
             				    $values['base'] = null;
457 531
             				    $values['owner'] = $line[12];
458
-            				    if ($line[28] == '') $values['date_first_reg'] = null;
459
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
532
+            				    if ($line[28] == '') {
533
+            				    	$values['date_first_reg'] = null;
534
+            				    } else {
535
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
536
+					    }
460 537
 
461 538
 					    $values['cancel'] = $line[39];
462 539
 					} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') {
@@ -475,29 +552,41 @@  discard block
 block discarded – undo
475 552
             				    $values['registration'] = $line[0];
476 553
             				    $values['base'] = null;
477 554
             				    $values['owner'] = $line[8];
478
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
479
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
555
+            				    if ($line[7] == '') {
556
+            				    	$values['date_first_reg'] = null;
557
+            				    } else {
558
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
559
+					    }
480 560
 					    $values['cancel'] = '';
481 561
 					} elseif ($country == 'PP') {
482 562
             				    $values['registration'] = $line[0];
483 563
             				    $values['base'] = null;
484 564
             				    $values['owner'] = $line[4];
485
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
486
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
565
+            				    if ($line[6] == '') {
566
+            				    	$values['date_first_reg'] = null;
567
+            				    } else {
568
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
569
+					    }
487 570
 					    $values['cancel'] = $line[7];
488 571
 					} elseif ($country == 'E7') {
489 572
             				    $values['registration'] = $line[0];
490 573
             				    $values['base'] = null;
491 574
             				    $values['owner'] = $line[4];
492
-            				    if ($line[5] == '') $values['date_first_reg'] = null;
493
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
575
+            				    if ($line[5] == '') {
576
+            				    	$values['date_first_reg'] = null;
577
+            				    } else {
578
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
579
+					    }
494 580
 					    $values['cancel'] = '';
495 581
 					} elseif ($country == '8Q') {
496 582
             				    $values['registration'] = $line[0];
497 583
             				    $values['base'] = null;
498 584
             				    $values['owner'] = $line[3];
499
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
500
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
585
+            				    if ($line[7] == '') {
586
+            				    	$values['date_first_reg'] = null;
587
+            				    } else {
588
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
589
+					    }
501 590
 					    $values['cancel'] = '';
502 591
 					} elseif ($country == 'ZK' || $country == 'OM' || $country == 'TF') {
503 592
             				    $values['registration'] = $line[0];
@@ -511,7 +600,9 @@  discard block
 block discarded – undo
511 600
 						$sth_dest->execute($query_dest_values);
512 601
 					}
513 602
 				}
514
-				if ($globalTransaction) $Connection->db->commit();
603
+				if ($globalTransaction) {
604
+					$Connection->db->commit();
605
+				}
515 606
 			} catch(PDOException $e) {
516 607
 				return "error : ".$e->getMessage();
517 608
 			}
@@ -645,25 +736,45 @@  discard block
 block discarded – undo
645 736
 		    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image_thumb, :image)";
646 737
 		$Connection = new Connection();
647 738
 		$sth_dest = $Connection->db->prepare($query_dest);
648
-		if ($globalTransaction) $Connection->db->beginTransaction();
739
+		if ($globalTransaction) {
740
+			$Connection->db->beginTransaction();
741
+		}
649 742
   
650 743
 		$i = 0;
651 744
 		while($row = sparql_fetch_array($result))
652 745
 		{
653 746
 			if ($i >= 1) {
654 747
 			//print_r($row);
655
-			if (!isset($row['iata'])) $row['iata'] = '';
656
-			if (!isset($row['icao'])) $row['icao'] = '';
657
-			if (!isset($row['type'])) $row['type'] = '';
658
-			if (!isset($row['altitude'])) $row['altitude'] = '';
748
+			if (!isset($row['iata'])) {
749
+				$row['iata'] = '';
750
+			}
751
+			if (!isset($row['icao'])) {
752
+				$row['icao'] = '';
753
+			}
754
+			if (!isset($row['type'])) {
755
+				$row['type'] = '';
756
+			}
757
+			if (!isset($row['altitude'])) {
758
+				$row['altitude'] = '';
759
+			}
659 760
 			if (isset($row['city_bis'])) {
660 761
 				$row['city'] = $row['city_bis'];
661 762
 			}
662
-			if (!isset($row['city'])) $row['city'] = '';
663
-			if (!isset($row['country'])) $row['country'] = '';
664
-			if (!isset($row['homepage'])) $row['homepage'] = '';
665
-			if (!isset($row['wikipedia_page'])) $row['wikipedia_page'] = '';
666
-			if (!isset($row['name'])) continue;
763
+			if (!isset($row['city'])) {
764
+				$row['city'] = '';
765
+			}
766
+			if (!isset($row['country'])) {
767
+				$row['country'] = '';
768
+			}
769
+			if (!isset($row['homepage'])) {
770
+				$row['homepage'] = '';
771
+			}
772
+			if (!isset($row['wikipedia_page'])) {
773
+				$row['wikipedia_page'] = '';
774
+			}
775
+			if (!isset($row['name'])) {
776
+				continue;
777
+			}
667 778
 			if (!isset($row['image'])) {
668 779
 				$row['image'] = '';
669 780
 				$row['image_thumb'] = '';
@@ -699,7 +810,9 @@  discard block
 block discarded – undo
699 810
 
700 811
 			$i++;
701 812
 		}
702
-		if ($globalTransaction) $Connection->db->commit();
813
+		if ($globalTransaction) {
814
+			$Connection->db->commit();
815
+		}
703 816
 		echo "Delete duplicate rows...\n";
704 817
 		$query = 'ALTER IGNORE TABLE airport ADD UNIQUE INDEX icaoidx (icao)';
705 818
 		try {
@@ -711,7 +824,9 @@  discard block
 block discarded – undo
711 824
                 }
712 825
 
713 826
 
714
-		if ($globalDebug) echo "Insert Not available Airport...\n";
827
+		if ($globalDebug) {
828
+			echo "Insert Not available Airport...\n";
829
+		}
715 830
 		$query = "INSERT INTO airport (`airport_id`,`name`,`city`,`country`,`iata`,`icao`,`latitude`,`longitude`,`altitude`,`type`,`home_link`,`wikipedia_link`,`image`,`image_thumb`)
716 831
 		    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image, :image_thumb)";
717 832
 		$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' => '');
@@ -738,7 +853,9 @@  discard block
 block discarded – undo
738 853
 		$delimiter = ',';
739 854
 		$out_file = $tmp_dir.'airports.csv';
740 855
 		update_db::download('http://ourairports.com/data/airports.csv',$out_file);
741
-		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
856
+		if (!file_exists($out_file) || !is_readable($out_file)) {
857
+			return FALSE;
858
+		}
742 859
 		echo "Add data from ourairports.com...\n";
743 860
 
744 861
 		$header = NULL;
@@ -748,8 +865,9 @@  discard block
 block discarded – undo
748 865
 			//$Connection->db->beginTransaction();
749 866
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
750 867
 			{
751
-				if(!$header) $header = $row;
752
-				else {
868
+				if(!$header) {
869
+					$header = $row;
870
+				} else {
753 871
 					$data = array();
754 872
 					$data = array_combine($header, $row);
755 873
 					try {
@@ -787,7 +905,9 @@  discard block
 block discarded – undo
787 905
 		echo "Download data from another free database...\n";
788 906
 		$out_file = $tmp_dir.'GlobalAirportDatabase.zip';
789 907
 		update_db::download('http://www.partow.net/downloads/GlobalAirportDatabase.zip',$out_file);
790
-		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
908
+		if (!file_exists($out_file) || !is_readable($out_file)) {
909
+			return FALSE;
910
+		}
791 911
 		update_db::unzip($out_file);
792 912
 		$header = NULL;
793 913
 		echo "Add data from another free database...\n";
@@ -798,8 +918,9 @@  discard block
 block discarded – undo
798 918
 			//$Connection->db->beginTransaction();
799 919
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
800 920
 			{
801
-				if(!$header) $header = $row;
802
-				else {
921
+				if(!$header) {
922
+					$header = $row;
923
+				} else {
803 924
 					$data = $row;
804 925
 
805 926
 					$query = 'UPDATE airport SET `city` = :city, `country` = :country WHERE icao = :icao';
@@ -974,7 +1095,9 @@  discard block
 block discarded – undo
974 1095
 		if (($handle = fopen($tmp_dir.'MASTER.txt', 'r')) !== FALSE)
975 1096
 		{
976 1097
 			$i = 0;
977
-			if ($globalTransaction) $Connection->db->beginTransaction();
1098
+			if ($globalTransaction) {
1099
+				$Connection->db->beginTransaction();
1100
+			}
978 1101
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
979 1102
 			{
980 1103
 				if ($i > 0) {
@@ -987,7 +1110,9 @@  discard block
 block discarded – undo
987 1110
 					}
988 1111
 					$result_search = $sths->fetchAll(PDO::FETCH_ASSOC);
989 1112
 					if (!empty($result_search)) {
990
-						if ($globalDebug) echo '.';
1113
+						if ($globalDebug) {
1114
+							echo '.';
1115
+						}
991 1116
 						$queryi = 'UPDATE aircraft SET mfr = :mfr WHERE icao = :icao';
992 1117
 						try {
993 1118
 							$sthi = $Connection->db->prepare($queryi);
@@ -1005,8 +1130,12 @@  discard block
 block discarded – undo
1005 1130
 						}
1006 1131
 						$result_search_mfr = $sthsm->fetchAll(PDO::FETCH_ASSOC);
1007 1132
 						if (!empty($result_search_mfr)) {
1008
-							if (trim($data[16]) == '' && trim($data[23]) != '') $data[16] = $data[23];
1009
-							if (trim($data[16]) == '' && trim($data[15]) != '') $data[16] = $data[15];
1133
+							if (trim($data[16]) == '' && trim($data[23]) != '') {
1134
+								$data[16] = $data[23];
1135
+							}
1136
+							if (trim($data[16]) == '' && trim($data[15]) != '') {
1137
+								$data[16] = $data[15];
1138
+							}
1010 1139
 							$queryf = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:source)';
1011 1140
 							try {
1012 1141
 								$sthf = $Connection->db->prepare($queryf);
@@ -1017,7 +1146,9 @@  discard block
 block discarded – undo
1017 1146
 						}
1018 1147
 					}
1019 1148
 					if (strtotime($data[29]) > time()) {
1020
-						if ($globalDebug) echo 'i';
1149
+						if ($globalDebug) {
1150
+							echo 'i';
1151
+						}
1021 1152
 						$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)';
1022 1153
 						try {
1023 1154
 							$sth = $Connection->db->prepare($query);
@@ -1028,13 +1159,19 @@  discard block
 block discarded – undo
1028 1159
 					}
1029 1160
 				}
1030 1161
 				if ($i % 90 == 0) {
1031
-					if ($globalTransaction) $Connection->db->commit();
1032
-					if ($globalTransaction) $Connection->db->beginTransaction();
1162
+					if ($globalTransaction) {
1163
+						$Connection->db->commit();
1164
+					}
1165
+					if ($globalTransaction) {
1166
+						$Connection->db->beginTransaction();
1167
+					}
1033 1168
 				}
1034 1169
 				$i++;
1035 1170
 			}
1036 1171
 			fclose($handle);
1037
-			if ($globalTransaction) $Connection->db->commit();
1172
+			if ($globalTransaction) {
1173
+				$Connection->db->commit();
1174
+			}
1038 1175
 		}
1039 1176
 		return '';
1040 1177
         }
@@ -1058,7 +1195,9 @@  discard block
 block discarded – undo
1058 1195
 			$i = 0;
1059 1196
 			//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
1060 1197
 			//$Connection->db->beginTransaction();
1061
-			if ($globalTransaction) $Connection->db->beginTransaction();
1198
+			if ($globalTransaction) {
1199
+				$Connection->db->beginTransaction();
1200
+			}
1062 1201
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1063 1202
 			{
1064 1203
 				if ($i > 0) {
@@ -1073,7 +1212,9 @@  discard block
 block discarded – undo
1073 1212
 				$i++;
1074 1213
 			}
1075 1214
 			fclose($handle);
1076
-			if ($globalTransaction) $Connection->db->commit();
1215
+			if ($globalTransaction) {
1216
+				$Connection->db->commit();
1217
+			}
1077 1218
 		}
1078 1219
 		return '';
1079 1220
         }
@@ -1094,7 +1235,9 @@  discard block
 block discarded – undo
1094 1235
 		if (($handle = fopen($tmp_dir.'owners.tsv', 'r')) !== FALSE)
1095 1236
 		{
1096 1237
 			$i = 0;
1097
-			if ($globalTransaction) $Connection->db->beginTransaction();
1238
+			if ($globalTransaction) {
1239
+				$Connection->db->beginTransaction();
1240
+			}
1098 1241
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1099 1242
 			{
1100 1243
 				if ($i > 0) {
@@ -1110,7 +1253,9 @@  discard block
 block discarded – undo
1110 1253
 				$i++;
1111 1254
 			}
1112 1255
 			fclose($handle);
1113
-			if ($globalTransaction) $Connection->db->commit();
1256
+			if ($globalTransaction) {
1257
+				$Connection->db->commit();
1258
+			}
1114 1259
 		}
1115 1260
 		return '';
1116 1261
         }
@@ -1135,7 +1280,9 @@  discard block
 block discarded – undo
1135 1280
 			$i = 0;
1136 1281
 			//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
1137 1282
 			//$Connection->db->beginTransaction();
1138
-			if ($globalTransaction) $Connection->db->beginTransaction();
1283
+			if ($globalTransaction) {
1284
+				$Connection->db->beginTransaction();
1285
+			}
1139 1286
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1140 1287
 			{
1141 1288
 				if ($i > 0) {
@@ -1150,7 +1297,9 @@  discard block
 block discarded – undo
1150 1297
 				$i++;
1151 1298
 			}
1152 1299
 			fclose($handle);
1153
-			if ($globalTransaction) $Connection->db->commit();
1300
+			if ($globalTransaction) {
1301
+				$Connection->db->commit();
1302
+			}
1154 1303
 		}
1155 1304
 		return '';
1156 1305
         }
@@ -1301,7 +1450,9 @@  discard block
 block discarded – undo
1301 1450
 		if (($handle = fopen($filename, 'r')) !== FALSE)
1302 1451
 		{
1303 1452
 			$i = 0;
1304
-			if ($globalTransaction) $Connection->db->beginTransaction();
1453
+			if ($globalTransaction) {
1454
+				$Connection->db->beginTransaction();
1455
+			}
1305 1456
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1306 1457
 			{
1307 1458
 				$i++;
@@ -1329,7 +1480,9 @@  discard block
 block discarded – undo
1329 1480
 				}
1330 1481
 			}
1331 1482
 			fclose($handle);
1332
-			if ($globalTransaction) $Connection->db->commit();
1483
+			if ($globalTransaction) {
1484
+				$Connection->db->commit();
1485
+			}
1333 1486
 		}
1334 1487
 		return '';
1335 1488
         }
@@ -1352,7 +1505,9 @@  discard block
 block discarded – undo
1352 1505
 		$Connection = new Connection();
1353 1506
 		if (($handle = fopen($filename, 'r')) !== FALSE)
1354 1507
 		{
1355
-			if ($globalTransaction) $Connection->db->beginTransaction();
1508
+			if ($globalTransaction) {
1509
+				$Connection->db->beginTransaction();
1510
+			}
1356 1511
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1357 1512
 			{
1358 1513
 				if(count($row) > 1) {
@@ -1366,7 +1521,9 @@  discard block
 block discarded – undo
1366 1521
 				}
1367 1522
 			}
1368 1523
 			fclose($handle);
1369
-			if ($globalTransaction) $Connection->db->commit();
1524
+			if ($globalTransaction) {
1525
+				$Connection->db->commit();
1526
+			}
1370 1527
 		}
1371 1528
 		return '';
1372 1529
         }
@@ -1386,8 +1543,9 @@  discard block
 block discarded – undo
1386 1543
 	        }
1387 1544
 
1388 1545
 
1389
-		if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
1390
-		else {
1546
+		if ($globalDBdriver == 'mysql') {
1547
+			update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
1548
+		} else {
1391 1549
 			update_db::gunzip('../db/pgsql/airspace.sql.gz',$tmp_dir.'airspace.sql');
1392 1550
 			$query = "CREATE EXTENSION postgis";
1393 1551
 			$Connection = new Connection(null,null,$_SESSION['database_root'],$_SESSION['database_rootpass']);
@@ -1406,20 +1564,30 @@  discard block
 block discarded – undo
1406 1564
 		global $tmp_dir, $globalDebug;
1407 1565
 		include_once('class.create_db.php');
1408 1566
 		require_once(dirname(__FILE__).'/../require/class.NOTAM.php');
1409
-		if ($globalDebug) echo "NOTAM from FlightAirMap website : Download...";
1567
+		if ($globalDebug) {
1568
+			echo "NOTAM from FlightAirMap website : Download...";
1569
+		}
1410 1570
 		update_db::download('http://data.flightairmap.fr/data/notam.txt.gz',$tmp_dir.'notam.txt.gz');
1411 1571
 		$error = '';
1412 1572
 		if (file_exists($tmp_dir.'notam.txt.gz')) {
1413
-			if ($globalDebug) echo "Gunzip...";
1573
+			if ($globalDebug) {
1574
+				echo "Gunzip...";
1575
+			}
1414 1576
 			update_db::gunzip($tmp_dir.'notam.txt.gz');
1415
-			if ($globalDebug) echo "Add to DB...";
1577
+			if ($globalDebug) {
1578
+				echo "Add to DB...";
1579
+			}
1416 1580
 			//$error = create_db::import_file($tmp_dir.'notam.sql');
1417 1581
 			$NOTAM = new NOTAM();
1418 1582
 			$NOTAM->updateNOTAMfromTextFile($tmp_dir.'notam.txt');
1419
-		} else $error = "File ".$tmp_dir.'notam.txt.gz'." doesn't exist. Download failed.";
1583
+		} else {
1584
+			$error = "File ".$tmp_dir.'notam.txt.gz'." doesn't exist. Download failed.";
1585
+		}
1420 1586
 		if ($error != '') {
1421 1587
 			return $error;
1422
-		} elseif ($globalDebug) echo "Done\n";
1588
+		} elseif ($globalDebug) {
1589
+			echo "Done\n";
1590
+		}
1423 1591
 		return '';
1424 1592
 	}
1425 1593
 
@@ -1473,67 +1641,111 @@  discard block
 block discarded – undo
1473 1641
 		//if ($globalDebug) echo "IVAO : Download...";
1474 1642
 		//update_db::download('http://fr.mirror.ivao.aero/software/ivae_feb2013.zip',$tmp_dir.'ivae_feb2013.zip');
1475 1643
 		if (file_exists($tmp_dir.'ivae_feb2013.zip')) {
1476
-			if ($globalDebug) echo "Unzip...";
1644
+			if ($globalDebug) {
1645
+				echo "Unzip...";
1646
+			}
1477 1647
 			update_db::unzip($tmp_dir.'ivae_feb2013.zip');
1478
-			if ($globalDebug) echo "Add to DB...";
1648
+			if ($globalDebug) {
1649
+				echo "Add to DB...";
1650
+			}
1479 1651
 			update_db::ivao_airlines($tmp_dir.'data/airlines.dat');
1480
-			if ($globalDebug) echo "Copy airlines logos to airlines images directory...";
1652
+			if ($globalDebug) {
1653
+				echo "Copy airlines logos to airlines images directory...";
1654
+			}
1481 1655
 			if (is_writable(dirname(__FILE__).'/../images/airlines')) {
1482
-				if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) $error = "Failed to copy airlines logo.";
1483
-			} else $error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable";
1484
-		} else $error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed.";
1656
+				if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) {
1657
+					$error = "Failed to copy airlines logo.";
1658
+				}
1659
+			} else {
1660
+				$error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable";
1661
+			}
1662
+		} else {
1663
+			$error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed.";
1664
+		}
1485 1665
 		if ($error != '') {
1486 1666
 			return $error;
1487
-		} elseif ($globalDebug) echo "Done\n";
1667
+		} elseif ($globalDebug) {
1668
+			echo "Done\n";
1669
+		}
1488 1670
 		return '';
1489 1671
 	}
1490 1672
 
1491 1673
 	public static function update_routes() {
1492 1674
 		global $tmp_dir, $globalDebug;
1493 1675
 		$error = '';
1494
-		if ($globalDebug) echo "Routes : Download...";
1676
+		if ($globalDebug) {
1677
+			echo "Routes : Download...";
1678
+		}
1495 1679
 		update_db::download('http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz',$tmp_dir.'StandingData.sqb.gz');
1496 1680
 		if (file_exists($tmp_dir.'StandingData.sqb.gz')) {
1497
-			if ($globalDebug) echo "Gunzip...";
1681
+			if ($globalDebug) {
1682
+				echo "Gunzip...";
1683
+			}
1498 1684
 			update_db::gunzip($tmp_dir.'StandingData.sqb.gz');
1499
-			if ($globalDebug) echo "Add to DB...";
1685
+			if ($globalDebug) {
1686
+				echo "Add to DB...";
1687
+			}
1500 1688
 			$error = update_db::retrieve_route_sqlite_to_dest($tmp_dir.'StandingData.sqb');
1501
-		} else $error = "File ".$tmp_dir.'StandingData.sqb.gz'." doesn't exist. Download failed.";
1689
+		} else {
1690
+			$error = "File ".$tmp_dir.'StandingData.sqb.gz'." doesn't exist. Download failed.";
1691
+		}
1502 1692
 		if ($error != '') {
1503 1693
 			return $error;
1504
-		} elseif ($globalDebug) echo "Done\n";
1694
+		} elseif ($globalDebug) {
1695
+			echo "Done\n";
1696
+		}
1505 1697
 		return '';
1506 1698
 	}
1507 1699
 	public static function update_oneworld() {
1508 1700
 		global $tmp_dir, $globalDebug;
1509 1701
 		$error = '';
1510
-		if ($globalDebug) echo "Schedules Oneworld : Download...";
1702
+		if ($globalDebug) {
1703
+			echo "Schedules Oneworld : Download...";
1704
+		}
1511 1705
 		update_db::download('http://data.flightairmap.fr/data/schedules/oneworld.csv.gz',$tmp_dir.'oneworld.csv.gz');
1512 1706
 		if (file_exists($tmp_dir.'oneworld.csv.gz')) {
1513
-			if ($globalDebug) echo "Gunzip...";
1707
+			if ($globalDebug) {
1708
+				echo "Gunzip...";
1709
+			}
1514 1710
 			update_db::gunzip($tmp_dir.'oneworld.csv.gz');
1515
-			if ($globalDebug) echo "Add to DB...";
1711
+			if ($globalDebug) {
1712
+				echo "Add to DB...";
1713
+			}
1516 1714
 			$error = update_db::retrieve_route_oneworld($tmp_dir.'oneworld.csv');
1517
-		} else $error = "File ".$tmp_dir.'oneworld.csv.gz'." doesn't exist. Download failed.";
1715
+		} else {
1716
+			$error = "File ".$tmp_dir.'oneworld.csv.gz'." doesn't exist. Download failed.";
1717
+		}
1518 1718
 		if ($error != '') {
1519 1719
 			return $error;
1520
-		} elseif ($globalDebug) echo "Done\n";
1720
+		} elseif ($globalDebug) {
1721
+			echo "Done\n";
1722
+		}
1521 1723
 		return '';
1522 1724
 	}
1523 1725
 	public static function update_skyteam() {
1524 1726
 		global $tmp_dir, $globalDebug;
1525 1727
 		$error = '';
1526
-		if ($globalDebug) echo "Schedules Skyteam : Download...";
1728
+		if ($globalDebug) {
1729
+			echo "Schedules Skyteam : Download...";
1730
+		}
1527 1731
 		update_db::download('http://data.flightairmap.fr/data/schedules/skyteam.csv.gz',$tmp_dir.'skyteam.csv.gz');
1528 1732
 		if (file_exists($tmp_dir.'skyteam.csv.gz')) {
1529
-			if ($globalDebug) echo "Gunzip...";
1733
+			if ($globalDebug) {
1734
+				echo "Gunzip...";
1735
+			}
1530 1736
 			update_db::gunzip($tmp_dir.'skyteam.csv.gz');
1531
-			if ($globalDebug) echo "Add to DB...";
1737
+			if ($globalDebug) {
1738
+				echo "Add to DB...";
1739
+			}
1532 1740
 			$error = update_db::retrieve_route_skyteam($tmp_dir.'skyteam.csv');
1533
-		} else $error = "File ".$tmp_dir.'skyteam.csv.gz'." doesn't exist. Download failed.";
1741
+		} else {
1742
+			$error = "File ".$tmp_dir.'skyteam.csv.gz'." doesn't exist. Download failed.";
1743
+		}
1534 1744
 		if ($error != '') {
1535 1745
 			return $error;
1536
-		} elseif ($globalDebug) echo "Done\n";
1746
+		} elseif ($globalDebug) {
1747
+			echo "Done\n";
1748
+		}
1537 1749
 		return '';
1538 1750
 	}
1539 1751
 	public static function update_ModeS() {
@@ -1550,326 +1762,564 @@  discard block
 block discarded – undo
1550 1762
 			exit;
1551 1763
 		} elseif ($globalDebug) echo "Done\n";
1552 1764
 */
1553
-		if ($globalDebug) echo "Modes : Download...";
1554
-//		update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb');
1765
+		if ($globalDebug) {
1766
+			echo "Modes : Download...";
1767
+		}
1768
+		//		update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb');
1555 1769
 		update_db::download('http://data.flightairmap.fr/data/BaseStation.sqb.gz',$tmp_dir.'BaseStation.sqb.gz');
1556 1770
 
1557 1771
 //		if (file_exists($tmp_dir.'basestation_latest.zip')) {
1558 1772
 		if (file_exists($tmp_dir.'BaseStation.sqb.gz')) {
1559
-			if ($globalDebug) echo "Unzip...";
1560
-//			update_db::unzip($tmp_dir.'basestation_latest.zip');
1773
+			if ($globalDebug) {
1774
+				echo "Unzip...";
1775
+			}
1776
+			//			update_db::unzip($tmp_dir.'basestation_latest.zip');
1561 1777
 			update_db::gunzip($tmp_dir.'BaseStation.sqb.gz');
1562
-			if ($globalDebug) echo "Add to DB...";
1778
+			if ($globalDebug) {
1779
+				echo "Add to DB...";
1780
+			}
1563 1781
 			$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'BaseStation.sqb');
1564 1782
 //			$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'basestation.sqb');
1565
-		} else $error = "File ".$tmp_dir.'basestation_latest.zip'." doesn't exist. Download failed.";
1783
+		} else {
1784
+			$error = "File ".$tmp_dir.'basestation_latest.zip'." doesn't exist. Download failed.";
1785
+		}
1566 1786
 		if ($error != '') {
1567 1787
 			return $error;
1568
-		} elseif ($globalDebug) echo "Done\n";
1788
+		} elseif ($globalDebug) {
1789
+			echo "Done\n";
1790
+		}
1569 1791
 		return '';
1570 1792
 	}
1571 1793
 
1572 1794
 	public static function update_ModeS_faa() {
1573 1795
 		global $tmp_dir, $globalDebug;
1574
-		if ($globalDebug) echo "Modes FAA: Download...";
1796
+		if ($globalDebug) {
1797
+			echo "Modes FAA: Download...";
1798
+		}
1575 1799
 		update_db::download('http://registry.faa.gov/database/ReleasableAircraft.zip',$tmp_dir.'ReleasableAircraft.zip');
1576 1800
 		if (file_exists($tmp_dir.'ReleasableAircraft.zip')) {
1577
-			if ($globalDebug) echo "Unzip...";
1801
+			if ($globalDebug) {
1802
+				echo "Unzip...";
1803
+			}
1578 1804
 			update_db::unzip($tmp_dir.'ReleasableAircraft.zip');
1579
-			if ($globalDebug) echo "Add to DB...";
1805
+			if ($globalDebug) {
1806
+				echo "Add to DB...";
1807
+			}
1580 1808
 			$error = update_db::modes_faa();
1581
-		} else $error = "File ".$tmp_dir.'ReleasableAircraft.zip'." doesn't exist. Download failed.";
1809
+		} else {
1810
+			$error = "File ".$tmp_dir.'ReleasableAircraft.zip'." doesn't exist. Download failed.";
1811
+		}
1582 1812
 		if ($error != '') {
1583 1813
 			return $error;
1584
-		} elseif ($globalDebug) echo "Done\n";
1814
+		} elseif ($globalDebug) {
1815
+			echo "Done\n";
1816
+		}
1585 1817
 		return '';
1586 1818
 	}
1587 1819
 
1588 1820
 	public static function update_ModeS_flarm() {
1589 1821
 		global $tmp_dir, $globalDebug;
1590
-		if ($globalDebug) echo "Modes Flarmnet: Download...";
1822
+		if ($globalDebug) {
1823
+			echo "Modes Flarmnet: Download...";
1824
+		}
1591 1825
 		update_db::download('http://flarmnet.org/files/data.fln',$tmp_dir.'data.fln');
1592 1826
 		if (file_exists($tmp_dir.'data.fln')) {
1593
-			if ($globalDebug) echo "Add to DB...";
1827
+			if ($globalDebug) {
1828
+				echo "Add to DB...";
1829
+			}
1594 1830
 			$error = update_db::retrieve_modes_flarmnet($tmp_dir.'data.fln');
1595
-		} else $error = "File ".$tmp_dir.'data.fln'." doesn't exist. Download failed.";
1831
+		} else {
1832
+			$error = "File ".$tmp_dir.'data.fln'." doesn't exist. Download failed.";
1833
+		}
1596 1834
 		if ($error != '') {
1597 1835
 			return $error;
1598
-		} elseif ($globalDebug) echo "Done\n";
1836
+		} elseif ($globalDebug) {
1837
+			echo "Done\n";
1838
+		}
1599 1839
 		return '';
1600 1840
 	}
1601 1841
 
1602 1842
 	public static function update_ModeS_ogn() {
1603 1843
 		global $tmp_dir, $globalDebug;
1604
-		if ($globalDebug) echo "Modes OGN: Download...";
1844
+		if ($globalDebug) {
1845
+			echo "Modes OGN: Download...";
1846
+		}
1605 1847
 		update_db::download('http://ddb.glidernet.org/download/',$tmp_dir.'ogn.csv');
1606 1848
 		if (file_exists($tmp_dir.'ogn.csv')) {
1607
-			if ($globalDebug) echo "Add to DB...";
1849
+			if ($globalDebug) {
1850
+				echo "Add to DB...";
1851
+			}
1608 1852
 			$error = update_db::retrieve_modes_ogn($tmp_dir.'ogn.csv');
1609
-		} else $error = "File ".$tmp_dir.'ogn.csv'." doesn't exist. Download failed.";
1853
+		} else {
1854
+			$error = "File ".$tmp_dir.'ogn.csv'." doesn't exist. Download failed.";
1855
+		}
1610 1856
 		if ($error != '') {
1611 1857
 			return $error;
1612
-		} elseif ($globalDebug) echo "Done\n";
1858
+		} elseif ($globalDebug) {
1859
+			echo "Done\n";
1860
+		}
1613 1861
 		return '';
1614 1862
 	}
1615 1863
 
1616 1864
 	public static function update_owner() {
1617 1865
 		global $tmp_dir, $globalDebug;
1618 1866
 		
1619
-		if ($globalDebug) echo "Owner France: Download...";
1867
+		if ($globalDebug) {
1868
+			echo "Owner France: Download...";
1869
+		}
1620 1870
 		update_db::download('http://antonakis.co.uk/registers/France.txt',$tmp_dir.'owner_f.csv');
1621 1871
 		if (file_exists($tmp_dir.'owner_f.csv')) {
1622
-			if ($globalDebug) echo "Add to DB...";
1872
+			if ($globalDebug) {
1873
+				echo "Add to DB...";
1874
+			}
1623 1875
 			$error = update_db::retrieve_owner($tmp_dir.'owner_f.csv','F');
1624
-		} else $error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed.";
1876
+		} else {
1877
+			$error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed.";
1878
+		}
1625 1879
 		if ($error != '') {
1626 1880
 			return $error;
1627
-		} elseif ($globalDebug) echo "Done\n";
1881
+		} elseif ($globalDebug) {
1882
+			echo "Done\n";
1883
+		}
1628 1884
 		
1629
-		if ($globalDebug) echo "Owner Ireland: Download...";
1885
+		if ($globalDebug) {
1886
+			echo "Owner Ireland: Download...";
1887
+		}
1630 1888
 		update_db::download('http://antonakis.co.uk/registers/Ireland.txt',$tmp_dir.'owner_ei.csv');
1631 1889
 		if (file_exists($tmp_dir.'owner_ei.csv')) {
1632
-			if ($globalDebug) echo "Add to DB...";
1890
+			if ($globalDebug) {
1891
+				echo "Add to DB...";
1892
+			}
1633 1893
 			$error = update_db::retrieve_owner($tmp_dir.'owner_ei.csv','EI');
1634
-		} else $error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed.";
1894
+		} else {
1895
+			$error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed.";
1896
+		}
1635 1897
 		if ($error != '') {
1636 1898
 			return $error;
1637
-		} elseif ($globalDebug) echo "Done\n";
1638
-		if ($globalDebug) echo "Owner Switzerland: Download...";
1899
+		} elseif ($globalDebug) {
1900
+			echo "Done\n";
1901
+		}
1902
+		if ($globalDebug) {
1903
+			echo "Owner Switzerland: Download...";
1904
+		}
1639 1905
 		update_db::download('http://antonakis.co.uk/registers/Switzerland.txt',$tmp_dir.'owner_hb.csv');
1640 1906
 		if (file_exists($tmp_dir.'owner_hb.csv')) {
1641
-			if ($globalDebug) echo "Add to DB...";
1907
+			if ($globalDebug) {
1908
+				echo "Add to DB...";
1909
+			}
1642 1910
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hb.csv','HB');
1643
-		} else $error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed.";
1911
+		} else {
1912
+			$error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed.";
1913
+		}
1644 1914
 		if ($error != '') {
1645 1915
 			return $error;
1646
-		} elseif ($globalDebug) echo "Done\n";
1647
-		if ($globalDebug) echo "Owner Czech Republic: Download...";
1916
+		} elseif ($globalDebug) {
1917
+			echo "Done\n";
1918
+		}
1919
+		if ($globalDebug) {
1920
+			echo "Owner Czech Republic: Download...";
1921
+		}
1648 1922
 		update_db::download('http://antonakis.co.uk/registers/CzechRepublic.txt',$tmp_dir.'owner_ok.csv');
1649 1923
 		if (file_exists($tmp_dir.'owner_ok.csv')) {
1650
-			if ($globalDebug) echo "Add to DB...";
1924
+			if ($globalDebug) {
1925
+				echo "Add to DB...";
1926
+			}
1651 1927
 			$error = update_db::retrieve_owner($tmp_dir.'owner_ok.csv','OK');
1652
-		} else $error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed.";
1928
+		} else {
1929
+			$error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed.";
1930
+		}
1653 1931
 		if ($error != '') {
1654 1932
 			return $error;
1655
-		} elseif ($globalDebug) echo "Done\n";
1656
-		if ($globalDebug) echo "Owner Australia: Download...";
1933
+		} elseif ($globalDebug) {
1934
+			echo "Done\n";
1935
+		}
1936
+		if ($globalDebug) {
1937
+			echo "Owner Australia: Download...";
1938
+		}
1657 1939
 		update_db::download('http://antonakis.co.uk/registers/Australia.txt',$tmp_dir.'owner_vh.csv');
1658 1940
 		if (file_exists($tmp_dir.'owner_vh.csv')) {
1659
-			if ($globalDebug) echo "Add to DB...";
1941
+			if ($globalDebug) {
1942
+				echo "Add to DB...";
1943
+			}
1660 1944
 			$error = update_db::retrieve_owner($tmp_dir.'owner_vh.csv','VH');
1661
-		} else $error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed.";
1945
+		} else {
1946
+			$error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed.";
1947
+		}
1662 1948
 		if ($error != '') {
1663 1949
 			return $error;
1664
-		} elseif ($globalDebug) echo "Done\n";
1665
-		if ($globalDebug) echo "Owner Austria: Download...";
1950
+		} elseif ($globalDebug) {
1951
+			echo "Done\n";
1952
+		}
1953
+		if ($globalDebug) {
1954
+			echo "Owner Austria: Download...";
1955
+		}
1666 1956
 		update_db::download('http://antonakis.co.uk/registers/Austria.txt',$tmp_dir.'owner_oe.csv');
1667 1957
 		if (file_exists($tmp_dir.'owner_oe.csv')) {
1668
-			if ($globalDebug) echo "Add to DB...";
1958
+			if ($globalDebug) {
1959
+				echo "Add to DB...";
1960
+			}
1669 1961
 			$error = update_db::retrieve_owner($tmp_dir.'owner_oe.csv','OE');
1670
-		} else $error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed.";
1962
+		} else {
1963
+			$error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed.";
1964
+		}
1671 1965
 		if ($error != '') {
1672 1966
 			return $error;
1673
-		} elseif ($globalDebug) echo "Done\n";
1674
-		if ($globalDebug) echo "Owner Chile: Download...";
1967
+		} elseif ($globalDebug) {
1968
+			echo "Done\n";
1969
+		}
1970
+		if ($globalDebug) {
1971
+			echo "Owner Chile: Download...";
1972
+		}
1675 1973
 		update_db::download('http://antonakis.co.uk/registers/Chile.txt',$tmp_dir.'owner_cc.csv');
1676 1974
 		if (file_exists($tmp_dir.'owner_cc.csv')) {
1677
-			if ($globalDebug) echo "Add to DB...";
1975
+			if ($globalDebug) {
1976
+				echo "Add to DB...";
1977
+			}
1678 1978
 			$error = update_db::retrieve_owner($tmp_dir.'owner_cc.csv','CC');
1679
-		} else $error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed.";
1979
+		} else {
1980
+			$error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed.";
1981
+		}
1680 1982
 		if ($error != '') {
1681 1983
 			return $error;
1682
-		} elseif ($globalDebug) echo "Done\n";
1683
-		if ($globalDebug) echo "Owner Colombia: Download...";
1984
+		} elseif ($globalDebug) {
1985
+			echo "Done\n";
1986
+		}
1987
+		if ($globalDebug) {
1988
+			echo "Owner Colombia: Download...";
1989
+		}
1684 1990
 		update_db::download('http://antonakis.co.uk/registers/Colombia.txt',$tmp_dir.'owner_hj.csv');
1685 1991
 		if (file_exists($tmp_dir.'owner_hj.csv')) {
1686
-			if ($globalDebug) echo "Add to DB...";
1992
+			if ($globalDebug) {
1993
+				echo "Add to DB...";
1994
+			}
1687 1995
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hj.csv','HJ');
1688
-		} else $error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed.";
1996
+		} else {
1997
+			$error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed.";
1998
+		}
1689 1999
 		if ($error != '') {
1690 2000
 			return $error;
1691
-		} elseif ($globalDebug) echo "Done\n";
1692
-		if ($globalDebug) echo "Owner Bosnia Herzegobina: Download...";
2001
+		} elseif ($globalDebug) {
2002
+			echo "Done\n";
2003
+		}
2004
+		if ($globalDebug) {
2005
+			echo "Owner Bosnia Herzegobina: Download...";
2006
+		}
1693 2007
 		update_db::download('http://antonakis.co.uk/registers/BosniaHerzegovina.txt',$tmp_dir.'owner_e7.csv');
1694 2008
 		if (file_exists($tmp_dir.'owner_e7.csv')) {
1695
-			if ($globalDebug) echo "Add to DB...";
2009
+			if ($globalDebug) {
2010
+				echo "Add to DB...";
2011
+			}
1696 2012
 			$error = update_db::retrieve_owner($tmp_dir.'owner_e7.csv','E7');
1697
-		} else $error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed.";
2013
+		} else {
2014
+			$error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed.";
2015
+		}
1698 2016
 		if ($error != '') {
1699 2017
 			return $error;
1700
-		} elseif ($globalDebug) echo "Done\n";
1701
-		if ($globalDebug) echo "Owner Brazil: Download...";
2018
+		} elseif ($globalDebug) {
2019
+			echo "Done\n";
2020
+		}
2021
+		if ($globalDebug) {
2022
+			echo "Owner Brazil: Download...";
2023
+		}
1702 2024
 		update_db::download('http://antonakis.co.uk/registers/Brazil.txt',$tmp_dir.'owner_pp.csv');
1703 2025
 		if (file_exists($tmp_dir.'owner_pp.csv')) {
1704
-			if ($globalDebug) echo "Add to DB...";
2026
+			if ($globalDebug) {
2027
+				echo "Add to DB...";
2028
+			}
1705 2029
 			$error = update_db::retrieve_owner($tmp_dir.'owner_pp.csv','PP');
1706
-		} else $error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed.";
2030
+		} else {
2031
+			$error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed.";
2032
+		}
1707 2033
 		if ($error != '') {
1708 2034
 			return $error;
1709
-		} elseif ($globalDebug) echo "Done\n";
1710
-		if ($globalDebug) echo "Owner Cayman Islands: Download...";
2035
+		} elseif ($globalDebug) {
2036
+			echo "Done\n";
2037
+		}
2038
+		if ($globalDebug) {
2039
+			echo "Owner Cayman Islands: Download...";
2040
+		}
1711 2041
 		update_db::download('http://antonakis.co.uk/registers/CaymanIslands.txt',$tmp_dir.'owner_vp.csv');
1712 2042
 		if (file_exists($tmp_dir.'owner_vp.csv')) {
1713
-			if ($globalDebug) echo "Add to DB...";
2043
+			if ($globalDebug) {
2044
+				echo "Add to DB...";
2045
+			}
1714 2046
 			$error = update_db::retrieve_owner($tmp_dir.'owner_vp.csv','VP');
1715
-		} else $error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed.";
2047
+		} else {
2048
+			$error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed.";
2049
+		}
1716 2050
 		if ($error != '') {
1717 2051
 			return $error;
1718
-		} elseif ($globalDebug) echo "Done\n";
1719
-		if ($globalDebug) echo "Owner Croatia: Download...";
2052
+		} elseif ($globalDebug) {
2053
+			echo "Done\n";
2054
+		}
2055
+		if ($globalDebug) {
2056
+			echo "Owner Croatia: Download...";
2057
+		}
1720 2058
 		update_db::download('http://antonakis.co.uk/registers/Croatia.txt',$tmp_dir.'owner_9a.csv');
1721 2059
 		if (file_exists($tmp_dir.'owner_9a.csv')) {
1722
-			if ($globalDebug) echo "Add to DB...";
2060
+			if ($globalDebug) {
2061
+				echo "Add to DB...";
2062
+			}
1723 2063
 			$error = update_db::retrieve_owner($tmp_dir.'owner_9a.csv','9A');
1724
-		} else $error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed.";
2064
+		} else {
2065
+			$error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed.";
2066
+		}
1725 2067
 		if ($error != '') {
1726 2068
 			return $error;
1727
-		} elseif ($globalDebug) echo "Done\n";
1728
-		if ($globalDebug) echo "Owner Luxembourg: Download...";
2069
+		} elseif ($globalDebug) {
2070
+			echo "Done\n";
2071
+		}
2072
+		if ($globalDebug) {
2073
+			echo "Owner Luxembourg: Download...";
2074
+		}
1729 2075
 		update_db::download('http://antonakis.co.uk/registers/Luxembourg.txt',$tmp_dir.'owner_lx.csv');
1730 2076
 		if (file_exists($tmp_dir.'owner_lx.csv')) {
1731
-			if ($globalDebug) echo "Add to DB...";
2077
+			if ($globalDebug) {
2078
+				echo "Add to DB...";
2079
+			}
1732 2080
 			$error = update_db::retrieve_owner($tmp_dir.'owner_lx.csv','LX');
1733
-		} else $error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed.";
2081
+		} else {
2082
+			$error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed.";
2083
+		}
1734 2084
 		if ($error != '') {
1735 2085
 			return $error;
1736
-		} elseif ($globalDebug) echo "Done\n";
1737
-		if ($globalDebug) echo "Owner Maldives: Download...";
2086
+		} elseif ($globalDebug) {
2087
+			echo "Done\n";
2088
+		}
2089
+		if ($globalDebug) {
2090
+			echo "Owner Maldives: Download...";
2091
+		}
1738 2092
 		update_db::download('http://antonakis.co.uk/registers/Maldives.txt',$tmp_dir.'owner_8q.csv');
1739 2093
 		if (file_exists($tmp_dir.'owner_8q.csv')) {
1740
-			if ($globalDebug) echo "Add to DB...";
2094
+			if ($globalDebug) {
2095
+				echo "Add to DB...";
2096
+			}
1741 2097
 			$error = update_db::retrieve_owner($tmp_dir.'owner_8q.csv','8Q');
1742
-		} else $error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed.";
2098
+		} else {
2099
+			$error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed.";
2100
+		}
1743 2101
 		if ($error != '') {
1744 2102
 			return $error;
1745
-		} elseif ($globalDebug) echo "Done\n";
1746
-		if ($globalDebug) echo "Owner New Zealand: Download...";
2103
+		} elseif ($globalDebug) {
2104
+			echo "Done\n";
2105
+		}
2106
+		if ($globalDebug) {
2107
+			echo "Owner New Zealand: Download...";
2108
+		}
1747 2109
 		update_db::download('http://antonakis.co.uk/registers/NewZealand.txt',$tmp_dir.'owner_zk.csv');
1748 2110
 		if (file_exists($tmp_dir.'owner_zk.csv')) {
1749
-			if ($globalDebug) echo "Add to DB...";
2111
+			if ($globalDebug) {
2112
+				echo "Add to DB...";
2113
+			}
1750 2114
 			$error = update_db::retrieve_owner($tmp_dir.'owner_zk.csv','ZK');
1751
-		} else $error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed.";
2115
+		} else {
2116
+			$error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed.";
2117
+		}
1752 2118
 		if ($error != '') {
1753 2119
 			return $error;
1754
-		} elseif ($globalDebug) echo "Done\n";
1755
-		if ($globalDebug) echo "Owner Papua New Guinea: Download...";
2120
+		} elseif ($globalDebug) {
2121
+			echo "Done\n";
2122
+		}
2123
+		if ($globalDebug) {
2124
+			echo "Owner Papua New Guinea: Download...";
2125
+		}
1756 2126
 		update_db::download('http://antonakis.co.uk/registers/PapuaNewGuinea.txt',$tmp_dir.'owner_p2.csv');
1757 2127
 		if (file_exists($tmp_dir.'owner_p2.csv')) {
1758
-			if ($globalDebug) echo "Add to DB...";
2128
+			if ($globalDebug) {
2129
+				echo "Add to DB...";
2130
+			}
1759 2131
 			$error = update_db::retrieve_owner($tmp_dir.'owner_p2.csv','P2');
1760
-		} else $error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed.";
2132
+		} else {
2133
+			$error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed.";
2134
+		}
1761 2135
 		if ($error != '') {
1762 2136
 			return $error;
1763
-		} elseif ($globalDebug) echo "Done\n";
1764
-		if ($globalDebug) echo "Owner Slovakia: Download...";
2137
+		} elseif ($globalDebug) {
2138
+			echo "Done\n";
2139
+		}
2140
+		if ($globalDebug) {
2141
+			echo "Owner Slovakia: Download...";
2142
+		}
1765 2143
 		update_db::download('http://antonakis.co.uk/registers/Slovakia.txt',$tmp_dir.'owner_om.csv');
1766 2144
 		if (file_exists($tmp_dir.'owner_om.csv')) {
1767
-			if ($globalDebug) echo "Add to DB...";
2145
+			if ($globalDebug) {
2146
+				echo "Add to DB...";
2147
+			}
1768 2148
 			$error = update_db::retrieve_owner($tmp_dir.'owner_om.csv','OM');
1769
-		} else $error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed.";
2149
+		} else {
2150
+			$error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed.";
2151
+		}
1770 2152
 		if ($error != '') {
1771 2153
 			return $error;
1772
-		} elseif ($globalDebug) echo "Done\n";
1773
-		if ($globalDebug) echo "Owner Ecuador: Download...";
2154
+		} elseif ($globalDebug) {
2155
+			echo "Done\n";
2156
+		}
2157
+		if ($globalDebug) {
2158
+			echo "Owner Ecuador: Download...";
2159
+		}
1774 2160
 		update_db::download('http://antonakis.co.uk/registers/Ecuador.txt',$tmp_dir.'owner_hc.csv');
1775 2161
 		if (file_exists($tmp_dir.'owner_hc.csv')) {
1776
-			if ($globalDebug) echo "Add to DB...";
2162
+			if ($globalDebug) {
2163
+				echo "Add to DB...";
2164
+			}
1777 2165
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hc.csv','HC');
1778
-		} else $error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed.";
2166
+		} else {
2167
+			$error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed.";
2168
+		}
1779 2169
 		if ($error != '') {
1780 2170
 			return $error;
1781
-		} elseif ($globalDebug) echo "Done\n";
1782
-		if ($globalDebug) echo "Owner Iceland: Download...";
2171
+		} elseif ($globalDebug) {
2172
+			echo "Done\n";
2173
+		}
2174
+		if ($globalDebug) {
2175
+			echo "Owner Iceland: Download...";
2176
+		}
1783 2177
 		update_db::download('http://antonakis.co.uk/registers/Iceland.txt',$tmp_dir.'owner_tf.csv');
1784 2178
 		if (file_exists($tmp_dir.'owner_tf.csv')) {
1785
-			if ($globalDebug) echo "Add to DB...";
2179
+			if ($globalDebug) {
2180
+				echo "Add to DB...";
2181
+			}
1786 2182
 			$error = update_db::retrieve_owner($tmp_dir.'owner_tf.csv','TF');
1787
-		} else $error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed.";
2183
+		} else {
2184
+			$error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed.";
2185
+		}
1788 2186
 		if ($error != '') {
1789 2187
 			return $error;
1790
-		} elseif ($globalDebug) echo "Done\n";
2188
+		} elseif ($globalDebug) {
2189
+			echo "Done\n";
2190
+		}
1791 2191
 		return '';
1792 2192
 	}
1793 2193
 
1794 2194
 	public static function update_translation() {
1795 2195
 		global $tmp_dir, $globalDebug;
1796 2196
 		$error = '';
1797
-		if ($globalDebug) echo "Translation : Download...";
2197
+		if ($globalDebug) {
2198
+			echo "Translation : Download...";
2199
+		}
1798 2200
 		update_db::download('http://www.acarsd.org/download/translation.php',$tmp_dir.'translation.zip');
1799 2201
 		if (file_exists($tmp_dir.'translation.zip')) {
1800
-			if ($globalDebug) echo "Unzip...";
2202
+			if ($globalDebug) {
2203
+				echo "Unzip...";
2204
+			}
1801 2205
 			update_db::unzip($tmp_dir.'translation.zip');
1802
-			if ($globalDebug) echo "Add to DB...";
2206
+			if ($globalDebug) {
2207
+				echo "Add to DB...";
2208
+			}
1803 2209
 			$error = update_db::translation();
1804
-		} else $error = "File ".$tmp_dir.'translation.zip'." doesn't exist. Download failed.";
2210
+		} else {
2211
+			$error = "File ".$tmp_dir.'translation.zip'." doesn't exist. Download failed.";
2212
+		}
1805 2213
 		if ($error != '') {
1806 2214
 			return $error;
1807
-		} elseif ($globalDebug) echo "Done\n";
2215
+		} elseif ($globalDebug) {
2216
+			echo "Done\n";
2217
+		}
1808 2218
 		return '';
1809 2219
 	}
1810 2220
 
1811 2221
 	public static function update_translation_fam() {
1812 2222
 		global $tmp_dir, $globalDebug;
1813
-		if ($globalDebug) echo "Translation from FlightAirMap website : Download...";
2223
+		if ($globalDebug) {
2224
+			echo "Translation from FlightAirMap website : Download...";
2225
+		}
1814 2226
 		update_db::download('http://data.flightairmap.fr/data/translation.tsv.gz',$tmp_dir.'translation.tsv.gz');
1815 2227
 		if (file_exists($tmp_dir.'translation.tsv.gz')) {
1816
-			if ($globalDebug) echo "Gunzip...";
2228
+			if ($globalDebug) {
2229
+				echo "Gunzip...";
2230
+			}
1817 2231
 			update_db::gunzip($tmp_dir.'translation.tsv.gz');
1818
-			if ($globalDebug) echo "Add to DB...";
2232
+			if ($globalDebug) {
2233
+				echo "Add to DB...";
2234
+			}
1819 2235
 			$error = update_db::translation_fam();
1820
-		} else $error = "File ".$tmp_dir.'translation.tsv.gz'." doesn't exist. Download failed.";
2236
+		} else {
2237
+			$error = "File ".$tmp_dir.'translation.tsv.gz'." doesn't exist. Download failed.";
2238
+		}
1821 2239
 		if ($error != '') {
1822 2240
 			return $error;
1823
-		} elseif ($globalDebug) echo "Done\n";
2241
+		} elseif ($globalDebug) {
2242
+			echo "Done\n";
2243
+		}
1824 2244
 		return '';
1825 2245
 	}
1826 2246
 	public static function update_ModeS_fam() {
1827 2247
 		global $tmp_dir, $globalDebug;
1828
-		if ($globalDebug) echo "ModeS from FlightAirMap website : Download...";
2248
+		if ($globalDebug) {
2249
+			echo "ModeS from FlightAirMap website : Download...";
2250
+		}
1829 2251
 		update_db::download('http://data.flightairmap.fr/data/modes.tsv.gz',$tmp_dir.'modes.tsv.gz');
1830 2252
 		if (file_exists($tmp_dir.'modes.tsv.gz')) {
1831
-			if ($globalDebug) echo "Gunzip...";
2253
+			if ($globalDebug) {
2254
+				echo "Gunzip...";
2255
+			}
1832 2256
 			update_db::gunzip($tmp_dir.'modes.tsv.gz');
1833
-			if ($globalDebug) echo "Add to DB...";
2257
+			if ($globalDebug) {
2258
+				echo "Add to DB...";
2259
+			}
1834 2260
 			$error = update_db::modes_fam();
1835
-		} else $error = "File ".$tmp_dir.'modes.tsv.gz'." doesn't exist. Download failed.";
2261
+		} else {
2262
+			$error = "File ".$tmp_dir.'modes.tsv.gz'." doesn't exist. Download failed.";
2263
+		}
1836 2264
 		if ($error != '') {
1837 2265
 			return $error;
1838
-		} elseif ($globalDebug) echo "Done\n";
2266
+		} elseif ($globalDebug) {
2267
+			echo "Done\n";
2268
+		}
1839 2269
 		return '';
1840 2270
 	}
1841 2271
 	public static function update_owner_fam() {
1842 2272
 		global $tmp_dir, $globalDebug, $globalOwner;
1843
-		if ($globalDebug) echo "owner from FlightAirMap website : Download...";
2273
+		if ($globalDebug) {
2274
+			echo "owner from FlightAirMap website : Download...";
2275
+		}
1844 2276
 		if ($globalOwner === TRUE) {
1845 2277
 			update_db::download('http://data.flightairmap.fr/data/owners_all.tsv.gz',$tmp_dir.'owners.tsv.gz');
1846 2278
 		} else {
1847 2279
 			update_db::download('http://data.flightairmap.fr/data/owners.tsv.gz',$tmp_dir.'owners.tsv.gz');
1848 2280
 		}
1849 2281
 		if (file_exists($tmp_dir.'owners.tsv.gz')) {
1850
-			if ($globalDebug) echo "Gunzip...";
2282
+			if ($globalDebug) {
2283
+				echo "Gunzip...";
2284
+			}
1851 2285
 			update_db::gunzip($tmp_dir.'owners.tsv.gz');
1852
-			if ($globalDebug) echo "Add to DB...";
2286
+			if ($globalDebug) {
2287
+				echo "Add to DB...";
2288
+			}
1853 2289
 			$error = update_db::owner_fam();
1854
-		} else $error = "File ".$tmp_dir.'owners.tsv.gz'." doesn't exist. Download failed.";
2290
+		} else {
2291
+			$error = "File ".$tmp_dir.'owners.tsv.gz'." doesn't exist. Download failed.";
2292
+		}
1855 2293
 		if ($error != '') {
1856 2294
 			return $error;
1857
-		} elseif ($globalDebug) echo "Done\n";
2295
+		} elseif ($globalDebug) {
2296
+			echo "Done\n";
2297
+		}
1858 2298
 		return '';
1859 2299
 	}
1860 2300
 	public static function update_routes_fam() {
1861 2301
 		global $tmp_dir, $globalDebug;
1862
-		if ($globalDebug) echo "Routes from FlightAirMap website : Download...";
2302
+		if ($globalDebug) {
2303
+			echo "Routes from FlightAirMap website : Download...";
2304
+		}
1863 2305
 		update_db::download('http://data.flightairmap.fr/data/routes.tsv.gz',$tmp_dir.'routes.tsv.gz');
1864 2306
 		if (file_exists($tmp_dir.'routes.tsv.gz')) {
1865
-			if ($globalDebug) echo "Gunzip...";
2307
+			if ($globalDebug) {
2308
+				echo "Gunzip...";
2309
+			}
1866 2310
 			update_db::gunzip($tmp_dir.'routes.tsv.gz');
1867
-			if ($globalDebug) echo "Add to DB...";
2311
+			if ($globalDebug) {
2312
+				echo "Add to DB...";
2313
+			}
1868 2314
 			$error = update_db::routes_fam();
1869
-		} else $error = "File ".$tmp_dir.'routes.tsv.gz'." doesn't exist. Download failed.";
2315
+		} else {
2316
+			$error = "File ".$tmp_dir.'routes.tsv.gz'." doesn't exist. Download failed.";
2317
+		}
1870 2318
 		if ($error != '') {
1871 2319
 			return $error;
1872
-		} elseif ($globalDebug) echo "Done\n";
2320
+		} elseif ($globalDebug) {
2321
+			echo "Done\n";
2322
+		}
1873 2323
 		return '';
1874 2324
 	}
1875 2325
 
@@ -1877,7 +2327,9 @@  discard block
 block discarded – undo
1877 2327
 		global $tmp_dir, $globalDebug, $globalDBdriver;
1878 2328
 		include_once('class.create_db.php');
1879 2329
 		$error = '';
1880
-		if ($globalDebug) echo "Airspace from FlightAirMap website : Download...";
2330
+		if ($globalDebug) {
2331
+			echo "Airspace from FlightAirMap website : Download...";
2332
+		}
1881 2333
 		if ($globalDBdriver == 'mysql') {
1882 2334
 			update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5');
1883 2335
 		} else {
@@ -1893,9 +2345,13 @@  discard block
 block discarded – undo
1893 2345
 					update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz',$tmp_dir.'airspace.sql.gz');
1894 2346
 				}
1895 2347
 				if (file_exists($tmp_dir.'airspace.sql.gz')) {
1896
-					if ($globalDebug) echo "Gunzip...";
2348
+					if ($globalDebug) {
2349
+						echo "Gunzip...";
2350
+					}
1897 2351
 					update_db::gunzip($tmp_dir.'airspace.sql.gz');
1898
-					if ($globalDebug) echo "Add to DB...";
2352
+					if ($globalDebug) {
2353
+						echo "Add to DB...";
2354
+					}
1899 2355
 					$Connection = new Connection();
1900 2356
 					if ($Connection->tableExists('airspace')) {
1901 2357
 						$query = 'DROP TABLE airspace';
@@ -1908,31 +2364,47 @@  discard block
 block discarded – undo
1908 2364
 		    			}
1909 2365
 					$error = create_db::import_file($tmp_dir.'airspace.sql');
1910 2366
 					update_db::insert_airspace_version($airspace_md5);
1911
-				} else $error = "File ".$tmp_dir.'airpsace.sql.gz'." doesn't exist. Download failed.";
2367
+				} else {
2368
+					$error = "File ".$tmp_dir.'airpsace.sql.gz'." doesn't exist. Download failed.";
2369
+				}
1912 2370
 			}
1913
-		} else $error = "File ".$tmp_dir.'airpsace.sql.gz.md5'." doesn't exist. Download failed.";
2371
+		} else {
2372
+			$error = "File ".$tmp_dir.'airpsace.sql.gz.md5'." doesn't exist. Download failed.";
2373
+		}
1914 2374
 		if ($error != '') {
1915 2375
 			return $error;
1916
-		} elseif ($globalDebug) echo "Done\n";
2376
+		} elseif ($globalDebug) {
2377
+			echo "Done\n";
2378
+		}
1917 2379
 		return '';
1918 2380
 	}
1919 2381
 
1920 2382
 	public static function update_tle() {
1921 2383
 		global $tmp_dir, $globalDebug;
1922
-		if ($globalDebug) echo "Download TLE : Download...";
2384
+		if ($globalDebug) {
2385
+			echo "Download TLE : Download...";
2386
+		}
1923 2387
 		$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',
1924 2388
 		'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',
1925 2389
 		'engineering.txt','education.txt','military.txt','radar.txt','cubesat.txt','other.txt','tle-new.txt');
1926 2390
 		foreach ($alltle as $filename) {
1927
-			if ($globalDebug) echo "downloading ".$filename.'...';
2391
+			if ($globalDebug) {
2392
+				echo "downloading ".$filename.'...';
2393
+			}
1928 2394
 			update_db::download('http://celestrak.com/NORAD/elements/'.$filename,$tmp_dir.$filename);
1929 2395
 			if (file_exists($tmp_dir.$filename)) {
1930
-				if ($globalDebug) echo "Add to DB ".$filename."...";
2396
+				if ($globalDebug) {
2397
+					echo "Add to DB ".$filename."...";
2398
+				}
1931 2399
 				$error = update_db::tle($tmp_dir.$filename,str_replace('.txt','',$filename));
1932
-			} else $error = "File ".$tmp_dir.$filename." doesn't exist. Download failed.";
2400
+			} else {
2401
+				$error = "File ".$tmp_dir.$filename." doesn't exist. Download failed.";
2402
+			}
1933 2403
 			if ($error != '') {
1934 2404
 				echo $error."\n";
1935
-			} elseif ($globalDebug) echo "Done\n";
2405
+			} elseif ($globalDebug) {
2406
+				echo "Done\n";
2407
+			}
1936 2408
 		}
1937 2409
 		return '';
1938 2410
 	}
@@ -1940,10 +2412,14 @@  discard block
 block discarded – undo
1940 2412
 	public static function update_models() {
1941 2413
 		global $tmp_dir, $globalDebug;
1942 2414
 		$error = '';
1943
-		if ($globalDebug) echo "Models from FlightAirMap website : Download...";
2415
+		if ($globalDebug) {
2416
+			echo "Models from FlightAirMap website : Download...";
2417
+		}
1944 2418
 		update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',$tmp_dir.'models.md5sum');
1945 2419
 		if (file_exists($tmp_dir.'models.md5sum')) {
1946
-			if ($globalDebug) echo "Check files...\n";
2420
+			if ($globalDebug) {
2421
+				echo "Check files...\n";
2422
+			}
1947 2423
 			$newmodelsdb = array();
1948 2424
 			if (($handle = fopen($tmp_dir.'models.md5sum','r')) !== FALSE) {
1949 2425
 				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
@@ -1962,25 +2438,35 @@  discard block
 block discarded – undo
1962 2438
 			}
1963 2439
 			$diff = array_diff($newmodelsdb,$modelsdb);
1964 2440
 			foreach ($diff as $key => $value) {
1965
-				if ($globalDebug) echo 'Downloading model '.$key.' ...'."\n";
2441
+				if ($globalDebug) {
2442
+					echo 'Downloading model '.$key.' ...'."\n";
2443
+				}
1966 2444
 				update_db::download('http://data.flightairmap.fr/data/models/'.$key,dirname(__FILE__).'/../models/'.$key);
1967 2445
 				
1968 2446
 			}
1969 2447
 			update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',dirname(__FILE__).'/../models/models.md5sum');
1970
-		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2448
+		} else {
2449
+			$error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2450
+		}
1971 2451
 		if ($error != '') {
1972 2452
 			return $error;
1973
-		} elseif ($globalDebug) echo "Done\n";
2453
+		} elseif ($globalDebug) {
2454
+			echo "Done\n";
2455
+		}
1974 2456
 		return '';
1975 2457
 	}
1976 2458
 
1977 2459
 	public static function update_space_models() {
1978 2460
 		global $tmp_dir, $globalDebug;
1979 2461
 		$error = '';
1980
-		if ($globalDebug) echo "Space models from FlightAirMap website : Download...";
2462
+		if ($globalDebug) {
2463
+			echo "Space models from FlightAirMap website : Download...";
2464
+		}
1981 2465
 		update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',$tmp_dir.'space_models.md5sum');
1982 2466
 		if (file_exists($tmp_dir.'space_models.md5sum')) {
1983
-			if ($globalDebug) echo "Check files...\n";
2467
+			if ($globalDebug) {
2468
+				echo "Check files...\n";
2469
+			}
1984 2470
 			$newmodelsdb = array();
1985 2471
 			if (($handle = fopen($tmp_dir.'space_models.md5sum','r')) !== FALSE) {
1986 2472
 				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
@@ -1999,15 +2485,21 @@  discard block
 block discarded – undo
1999 2485
 			}
2000 2486
 			$diff = array_diff($newmodelsdb,$modelsdb);
2001 2487
 			foreach ($diff as $key => $value) {
2002
-				if ($globalDebug) echo 'Downloading space model '.$key.' ...'."\n";
2488
+				if ($globalDebug) {
2489
+					echo 'Downloading space model '.$key.' ...'."\n";
2490
+				}
2003 2491
 				update_db::download('http://data.flightairmap.fr/data/models/space/'.$key,dirname(__FILE__).'/../models/space/'.$key);
2004 2492
 				
2005 2493
 			}
2006 2494
 			update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',dirname(__FILE__).'/../models/space/space_models.md5sum');
2007
-		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2495
+		} else {
2496
+			$error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2497
+		}
2008 2498
 		if ($error != '') {
2009 2499
 			return $error;
2010
-		} elseif ($globalDebug) echo "Done\n";
2500
+		} elseif ($globalDebug) {
2501
+			echo "Done\n";
2502
+		}
2011 2503
 		return '';
2012 2504
 	}
2013 2505
 
@@ -2050,7 +2542,9 @@  discard block
 block discarded – undo
2050 2542
                 }
2051 2543
 
2052 2544
 		$error = '';
2053
-		if ($globalDebug) echo "Notam : Download...";
2545
+		if ($globalDebug) {
2546
+			echo "Notam : Download...";
2547
+		}
2054 2548
 		update_db::download($globalNOTAMSource,$tmp_dir.'notam.rss');
2055 2549
 		if (file_exists($tmp_dir.'notam.rss')) {
2056 2550
 			$notams = json_decode(json_encode(simplexml_load_file($tmp_dir.'notam.rss')),true);
@@ -2065,14 +2559,30 @@  discard block
 block discarded – undo
2065 2559
 				$data['fir'] = $q[0];
2066 2560
 				$data['code'] = $q[1];
2067 2561
 				$ifrvfr = $q[2];
2068
-				if ($ifrvfr == 'IV') $data['rules'] = 'IFR/VFR';
2069
-				if ($ifrvfr == 'I') $data['rules'] = 'IFR';
2070
-				if ($ifrvfr == 'V') $data['rules'] = 'VFR';
2071
-				if ($q[4] == 'A') $data['scope'] = 'Airport warning';
2072
-				if ($q[4] == 'E') $data['scope'] = 'Enroute warning';
2073
-				if ($q[4] == 'W') $data['scope'] = 'Navigation warning';
2074
-				if ($q[4] == 'AE') $data['scope'] = 'Airport/Enroute warning';
2075
-				if ($q[4] == 'AW') $data['scope'] = 'Airport/Navigation warning';
2562
+				if ($ifrvfr == 'IV') {
2563
+					$data['rules'] = 'IFR/VFR';
2564
+				}
2565
+				if ($ifrvfr == 'I') {
2566
+					$data['rules'] = 'IFR';
2567
+				}
2568
+				if ($ifrvfr == 'V') {
2569
+					$data['rules'] = 'VFR';
2570
+				}
2571
+				if ($q[4] == 'A') {
2572
+					$data['scope'] = 'Airport warning';
2573
+				}
2574
+				if ($q[4] == 'E') {
2575
+					$data['scope'] = 'Enroute warning';
2576
+				}
2577
+				if ($q[4] == 'W') {
2578
+					$data['scope'] = 'Navigation warning';
2579
+				}
2580
+				if ($q[4] == 'AE') {
2581
+					$data['scope'] = 'Airport/Enroute warning';
2582
+				}
2583
+				if ($q[4] == 'AW') {
2584
+					$data['scope'] = 'Airport/Navigation warning';
2585
+				}
2076 2586
 				//$data['scope'] = $q[4];
2077 2587
 				$data['lower_limit'] = $q[5];
2078 2588
 				$data['upper_limit'] = $q[6];
@@ -2080,8 +2590,12 @@  discard block
 block discarded – undo
2080 2590
 				sscanf($latlonrad,'%4c%c%5c%c%3d',$las,$lac,$lns,$lnc,$radius);
2081 2591
 				$latitude = $Common->convertDec($las,'latitude');
2082 2592
 				$longitude = $Common->convertDec($lns,'longitude');
2083
-				if ($lac == 'S') $latitude = '-'.$latitude;
2084
-				if ($lnc == 'W') $longitude = '-'.$longitude;
2593
+				if ($lac == 'S') {
2594
+					$latitude = '-'.$latitude;
2595
+				}
2596
+				if ($lnc == 'W') {
2597
+					$longitude = '-'.$longitude;
2598
+				}
2085 2599
 				$data['center_latitude'] = $latitude;
2086 2600
 				$data['center_longitude'] = $longitude;
2087 2601
 				$data['radius'] = intval($radius);
@@ -2111,10 +2625,14 @@  discard block
 block discarded – undo
2111 2625
 				$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']);
2112 2626
 				unset($data);
2113 2627
 			} 
2114
-		} else $error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed.";
2628
+		} else {
2629
+			$error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed.";
2630
+		}
2115 2631
 		if ($error != '') {
2116 2632
 			return $error;
2117
-		} elseif ($globalDebug) echo "Done\n";
2633
+		} elseif ($globalDebug) {
2634
+			echo "Done\n";
2635
+		}
2118 2636
 		return '';
2119 2637
 	}
2120 2638
 	
@@ -2139,7 +2657,9 @@  discard block
 block discarded – undo
2139 2657
 		$airspace_lst = $Common->getData('https://raw.githubusercontent.com/XCSoar/xcsoar-data-repository/master/data/airspace.json');
2140 2658
 		$airspace_json = json_decode($airspace_lst,true);
2141 2659
 		foreach ($airspace_json['records'] as $airspace) {
2142
-			if ($globalDebug) echo $airspace['name']."...\n";
2660
+			if ($globalDebug) {
2661
+				echo $airspace['name']."...\n";
2662
+			}
2143 2663
 			update_db::download($airspace['uri'],$tmp_dir.$airspace['name']);
2144 2664
 			if (file_exists($tmp_dir.$airspace['name'])) {
2145 2665
 				file_put_contents($tmp_dir.$airspace['name'], utf8_encode(file_get_contents($tmp_dir.$airspace['name'])));
@@ -2168,8 +2688,11 @@  discard block
 block discarded – undo
2168 2688
                         return "error : ".$e->getMessage();
2169 2689
                 }
2170 2690
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2171
-                if ($row['nb'] > 0) return false;
2172
-                else return true;
2691
+                if ($row['nb'] > 0) {
2692
+                	return false;
2693
+                } else {
2694
+                	return true;
2695
+                }
2173 2696
 	}
2174 2697
 
2175 2698
 	public static function insert_last_update() {
@@ -2194,8 +2717,11 @@  discard block
 block discarded – undo
2194 2717
                         return "error : ".$e->getMessage();
2195 2718
                 }
2196 2719
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2197
-                if ($row['nb'] > 0) return true;
2198
-                else return false;
2720
+                if ($row['nb'] > 0) {
2721
+                	return true;
2722
+                } else {
2723
+                	return false;
2724
+                }
2199 2725
 	}
2200 2726
 
2201 2727
 
@@ -2226,8 +2752,11 @@  discard block
 block discarded – undo
2226 2752
                         return "error : ".$e->getMessage();
2227 2753
                 }
2228 2754
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2229
-                if ($row['nb'] > 0) return false;
2230
-                else return true;
2755
+                if ($row['nb'] > 0) {
2756
+                	return false;
2757
+                } else {
2758
+                	return true;
2759
+                }
2231 2760
 	}
2232 2761
 
2233 2762
 	public static function insert_last_notam_update() {
@@ -2256,8 +2785,11 @@  discard block
 block discarded – undo
2256 2785
                         return "error : ".$e->getMessage();
2257 2786
                 }
2258 2787
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2259
-                if ($row['nb'] > 0) return false;
2260
-                else return true;
2788
+                if ($row['nb'] > 0) {
2789
+                	return false;
2790
+                } else {
2791
+                	return true;
2792
+                }
2261 2793
 	}
2262 2794
 
2263 2795
 	public static function insert_last_airspace_update() {
@@ -2287,8 +2819,11 @@  discard block
 block discarded – undo
2287 2819
                         return "error : ".$e->getMessage();
2288 2820
                 }
2289 2821
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2290
-                if ($row['nb'] > 0) return false;
2291
-                else return true;
2822
+                if ($row['nb'] > 0) {
2823
+                	return false;
2824
+                } else {
2825
+                	return true;
2826
+                }
2292 2827
 	}
2293 2828
 
2294 2829
 	public static function insert_last_owner_update() {
@@ -2317,8 +2852,11 @@  discard block
 block discarded – undo
2317 2852
                         return "error : ".$e->getMessage();
2318 2853
                 }
2319 2854
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2320
-                if ($row['nb'] > 0) return false;
2321
-                else return true;
2855
+                if ($row['nb'] > 0) {
2856
+                	return false;
2857
+                } else {
2858
+                	return true;
2859
+                }
2322 2860
 	}
2323 2861
 
2324 2862
 	public static function insert_last_schedules_update() {
@@ -2347,8 +2885,11 @@  discard block
 block discarded – undo
2347 2885
                         return "error : ".$e->getMessage();
2348 2886
                 }
2349 2887
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2350
-                if ($row['nb'] > 0) return false;
2351
-                else return true;
2888
+                if ($row['nb'] > 0) {
2889
+                	return false;
2890
+                } else {
2891
+                	return true;
2892
+                }
2352 2893
 	}
2353 2894
 
2354 2895
 	public static function insert_last_tle_update() {
Please login to merge, or discard this patch.
require/libs/Predict/Predict.php 4 patches
Doc Comments   +3 added lines, -17 removed lines patch added patch discarded remove patch
@@ -146,20 +146,6 @@  discard block
 block discarded – undo
146 146
 
147 147
     /** Predict first pass after a certain time.
148 148
      *
149
-     *  @param Predict_Sat $sat   The satellite data.
150
-     *  @param Predict_QTH $qth   The observer's location data.
151
-     *  @param float       $start Starting time.
152
-     *  @param int         $maxdt The maximum number of days to look ahead (0 for no limit).
153
-     *
154
-     *  @return Predict_Pass or NULL if there was an error.
155
-     *
156
-     * This function will find the first upcoming pass with AOS no earlier than
157
-     * t = start and no later than t = (start+maxdt).
158
-     *
159
-     *  note For no time limit use maxdt = 0.0
160
-     *
161
-     *  note the data in sat will be corrupt (future) and must be refreshed
162
-     *       by the caller, if the caller will need it later on
163 149
      */
164 150
     public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165 151
     {
@@ -407,7 +393,7 @@  discard block
 block discarded – undo
407 393
      *  @param Predict_QTH $qth   The observer's location (QTH) data.
408 394
      *  @param float       $start The julian date where calculation should start.
409 395
      *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
410
-     *  @return The julain date of the next AOS or 0.0 if the satellite has no AOS.
396
+     *  @return double julain date of the next AOS or 0.0 if the satellite has no AOS.
411 397
      *
412 398
      * This function finds the time of AOS for the first coming pass taking place
413 399
      * no earlier that start.
@@ -563,7 +549,7 @@  discard block
 block discarded – undo
563 549
      *  @param Predict_QTH $qth The QTH observer location data.
564 550
      *  @param float       $start The time where calculation should start. (Julian Date)
565 551
      *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
566
-     *  @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
552
+     *  @return double time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
567 553
      *
568 554
      * This function finds the time of LOS for the first coming pass taking place
569 555
      * no earlier that start.
@@ -648,7 +634,7 @@  discard block
 block discarded – undo
648 634
      *  @param Predict_Sat $sat   The satellite to find AOS for.
649 635
      *  @param Predict_QTH $qth   The ground station.
650 636
      *  @param float       $start Start time, prefereably now.
651
-     *  @return The time of the previous AOS or 0.0 if the satellite has no AOS.
637
+     *  @return double time of the previous AOS or 0.0 if the satellite has no AOS.
652 638
      *
653 639
      * This function can be used to find the AOS time in the past of the
654 640
      * current pass.
Please login to merge, or discard this patch.
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -52,824 +52,824 @@
 block discarded – undo
52 52
  */
53 53
 class Predict
54 54
 {
55
-    const de2ra    =  1.74532925E-2;   /* Degrees to Radians */
56
-    const pi       =  3.1415926535898; /* Pi */
57
-    const pio2     =  1.5707963267949; /* Pi/2 */
58
-    const x3pio2   =  4.71238898;      /* 3*Pi/2 */
59
-    const twopi    =  6.2831853071796; /* 2*Pi  */
60
-    const e6a      =  1.0E-6;
61
-    const tothrd   =  6.6666667E-1;    /* 2/3 */
62
-    const xj2      =  1.0826158E-3;    /* J2 Harmonic */
63
-    const xj3      = -2.53881E-6;      /* J3 Harmonic */
64
-    const xj4      = -1.65597E-6;      /* J4 Harmonic */
65
-    const xke      =  7.43669161E-2;
66
-    const xkmper   =  6.378135E3;      /* Earth radius km */
67
-    const xmnpda   =  1.44E3;          /* Minutes per day */
68
-    const km2mi    =  0.621371;        /* Kilometers per Mile */
69
-    const ae       =  1.0;
70
-    const ck2      =  5.413079E-4;
71
-    const ck4      =  6.209887E-7;
72
-    const __f      =  3.352779E-3;
73
-    const ge       =  3.986008E5;
74
-    const __s__    =  1.012229;
75
-    const qoms2t   =  1.880279E-09;
76
-    const secday   =  8.6400E4;        /* Seconds per day */
77
-    const omega_E  =  1.0027379;
78
-    const omega_ER =  6.3003879;
79
-    const zns      =  1.19459E-5;
80
-    const c1ss     =  2.9864797E-6;
81
-    const zes      =  1.675E-2;
82
-    const znl      =  1.5835218E-4;
83
-    const c1l      =  4.7968065E-7;
84
-    const zel      =  5.490E-2;
85
-    const zcosis   =  9.1744867E-1;
86
-    const zsinis   =  3.9785416E-1;
87
-    const zsings   = -9.8088458E-1;
88
-    const zcosgs   =  1.945905E-1;
89
-    const zcoshs   =  1;
90
-    const zsinhs   =  0;
91
-    const q22      =  1.7891679E-6;
92
-    const q31      =  2.1460748E-6;
93
-    const q33      =  2.2123015E-7;
94
-    const g22      =  5.7686396;
95
-    const g32      =  9.5240898E-1;
96
-    const g44      =  1.8014998;
97
-    const g52      =  1.0508330;
98
-    const g54      =  4.4108898;
99
-    const root22   =  1.7891679E-6;
100
-    const root32   =  3.7393792E-7;
101
-    const root44   =  7.3636953E-9;
102
-    const root52   =  1.1428639E-7;
103
-    const root54   =  2.1765803E-9;
104
-    const thdt     =  4.3752691E-3;
105
-    const rho      =  1.5696615E-1;
106
-    const mfactor  =  7.292115E-5;
107
-    const __sr__   =  6.96000E5;      /*Solar radius - kilometers (IAU 76)*/
108
-    const AU       =  1.49597870E8;   /*Astronomical unit - kilometers (IAU 76)*/
109
-
110
-    /* visibility constants */
111
-    const SAT_VIS_NONE     = 0;
112
-    const SAT_VIS_VISIBLE  = 1;
113
-    const SAT_VIS_DAYLIGHT = 2;
114
-    const SAT_VIS_ECLIPSED = 3;
115
-
116
-    /* preferences */
117
-    public $minEle     = 10; // Minimum elevation
118
-    public $timeRes    = 10; // Pass details: time resolution
119
-    public $numEntries = 20; // Pass details: number of entries
120
-    public $threshold  = -6; // Twilight threshold
121
-
122
-    /**
123
-     *  Predict the next pass.
124
-     *
125
-     * This function simply wraps the get_pass function using the current time
126
-     * as parameter.
127
-     *
128
-     * Note: the data in sat will be corrupt (future) and must be refreshed
129
-     *       by the caller, if the caller will need it later on (eg. if the caller
130
-     *       is GtkSatList).
131
-     *
132
-     * @param Predict_Sat $sat   The satellite data.
133
-     * @param Predict_QTH $qth   The observer data.
134
-     * @param int         $maxdt The maximum number of days to look ahead.
135
-     *
136
-     * @return Predict_Pass Pointer instance or NULL if no pass can be
137
-     *         found.
138
-     */
139
-    public function get_next_pass(Predict_Sat $sat, Predict_QTH $qth, $maxdt)
140
-    {
141
-        /* get the current time and call the get_pass function */
142
-        $now = Predict_Time::get_current_daynum();
143
-
144
-        return $this->get_pass($sat, $qth, $now, $maxdt);
145
-    }
146
-
147
-    /** Predict first pass after a certain time.
148
-     *
149
-     *  @param Predict_Sat $sat   The satellite data.
150
-     *  @param Predict_QTH $qth   The observer's location data.
151
-     *  @param float       $start Starting time.
152
-     *  @param int         $maxdt The maximum number of days to look ahead (0 for no limit).
153
-     *
154
-     *  @return Predict_Pass or NULL if there was an error.
155
-     *
156
-     * This function will find the first upcoming pass with AOS no earlier than
157
-     * t = start and no later than t = (start+maxdt).
158
-     *
159
-     *  note For no time limit use maxdt = 0.0
160
-     *
161
-     *  note the data in sat will be corrupt (future) and must be refreshed
162
-     *       by the caller, if the caller will need it later on
163
-     */
164
-    public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165
-    {
166
-        $aos = 0.0;    /* time of AOS */
167
-        $tca = 0.0;    /* time of TCA */
168
-        $los = 0.0;    /* time of LOS */
169
-        $dt = 0.0;     /* time diff */
170
-        $step = 0.0;   /* time step */
171
-        $t0 = $start;
172
-        $tres = 0.0;   /* required time resolution */
173
-        $max_el = 0.0; /* maximum elevation */
174
-        $pass = null;
175
-        $detail = null;
176
-        $done = false;
177
-        $iter = 0;      /* number of iterations */
178
-        /* FIXME: watchdog */
179
-
180
-        /*copy sat_in to a working structure*/
181
-        $sat         = clone $sat_in;
182
-        $sat_working = clone $sat_in;
183
-
184
-        /* get time resolution; sat-cfg stores it in seconds */
185
-        $tres = $this->timeRes / 86400.0;
186
-
187
-        /* loop until we find a pass with elevation > SAT_CFG_INT_PRED_MIN_EL
55
+	const de2ra    =  1.74532925E-2;   /* Degrees to Radians */
56
+	const pi       =  3.1415926535898; /* Pi */
57
+	const pio2     =  1.5707963267949; /* Pi/2 */
58
+	const x3pio2   =  4.71238898;      /* 3*Pi/2 */
59
+	const twopi    =  6.2831853071796; /* 2*Pi  */
60
+	const e6a      =  1.0E-6;
61
+	const tothrd   =  6.6666667E-1;    /* 2/3 */
62
+	const xj2      =  1.0826158E-3;    /* J2 Harmonic */
63
+	const xj3      = -2.53881E-6;      /* J3 Harmonic */
64
+	const xj4      = -1.65597E-6;      /* J4 Harmonic */
65
+	const xke      =  7.43669161E-2;
66
+	const xkmper   =  6.378135E3;      /* Earth radius km */
67
+	const xmnpda   =  1.44E3;          /* Minutes per day */
68
+	const km2mi    =  0.621371;        /* Kilometers per Mile */
69
+	const ae       =  1.0;
70
+	const ck2      =  5.413079E-4;
71
+	const ck4      =  6.209887E-7;
72
+	const __f      =  3.352779E-3;
73
+	const ge       =  3.986008E5;
74
+	const __s__    =  1.012229;
75
+	const qoms2t   =  1.880279E-09;
76
+	const secday   =  8.6400E4;        /* Seconds per day */
77
+	const omega_E  =  1.0027379;
78
+	const omega_ER =  6.3003879;
79
+	const zns      =  1.19459E-5;
80
+	const c1ss     =  2.9864797E-6;
81
+	const zes      =  1.675E-2;
82
+	const znl      =  1.5835218E-4;
83
+	const c1l      =  4.7968065E-7;
84
+	const zel      =  5.490E-2;
85
+	const zcosis   =  9.1744867E-1;
86
+	const zsinis   =  3.9785416E-1;
87
+	const zsings   = -9.8088458E-1;
88
+	const zcosgs   =  1.945905E-1;
89
+	const zcoshs   =  1;
90
+	const zsinhs   =  0;
91
+	const q22      =  1.7891679E-6;
92
+	const q31      =  2.1460748E-6;
93
+	const q33      =  2.2123015E-7;
94
+	const g22      =  5.7686396;
95
+	const g32      =  9.5240898E-1;
96
+	const g44      =  1.8014998;
97
+	const g52      =  1.0508330;
98
+	const g54      =  4.4108898;
99
+	const root22   =  1.7891679E-6;
100
+	const root32   =  3.7393792E-7;
101
+	const root44   =  7.3636953E-9;
102
+	const root52   =  1.1428639E-7;
103
+	const root54   =  2.1765803E-9;
104
+	const thdt     =  4.3752691E-3;
105
+	const rho      =  1.5696615E-1;
106
+	const mfactor  =  7.292115E-5;
107
+	const __sr__   =  6.96000E5;      /*Solar radius - kilometers (IAU 76)*/
108
+	const AU       =  1.49597870E8;   /*Astronomical unit - kilometers (IAU 76)*/
109
+
110
+	/* visibility constants */
111
+	const SAT_VIS_NONE     = 0;
112
+	const SAT_VIS_VISIBLE  = 1;
113
+	const SAT_VIS_DAYLIGHT = 2;
114
+	const SAT_VIS_ECLIPSED = 3;
115
+
116
+	/* preferences */
117
+	public $minEle     = 10; // Minimum elevation
118
+	public $timeRes    = 10; // Pass details: time resolution
119
+	public $numEntries = 20; // Pass details: number of entries
120
+	public $threshold  = -6; // Twilight threshold
121
+
122
+	/**
123
+	 *  Predict the next pass.
124
+	 *
125
+	 * This function simply wraps the get_pass function using the current time
126
+	 * as parameter.
127
+	 *
128
+	 * Note: the data in sat will be corrupt (future) and must be refreshed
129
+	 *       by the caller, if the caller will need it later on (eg. if the caller
130
+	 *       is GtkSatList).
131
+	 *
132
+	 * @param Predict_Sat $sat   The satellite data.
133
+	 * @param Predict_QTH $qth   The observer data.
134
+	 * @param int         $maxdt The maximum number of days to look ahead.
135
+	 *
136
+	 * @return Predict_Pass Pointer instance or NULL if no pass can be
137
+	 *         found.
138
+	 */
139
+	public function get_next_pass(Predict_Sat $sat, Predict_QTH $qth, $maxdt)
140
+	{
141
+		/* get the current time and call the get_pass function */
142
+		$now = Predict_Time::get_current_daynum();
143
+
144
+		return $this->get_pass($sat, $qth, $now, $maxdt);
145
+	}
146
+
147
+	/** Predict first pass after a certain time.
148
+	 *
149
+	 *  @param Predict_Sat $sat   The satellite data.
150
+	 *  @param Predict_QTH $qth   The observer's location data.
151
+	 *  @param float       $start Starting time.
152
+	 *  @param int         $maxdt The maximum number of days to look ahead (0 for no limit).
153
+	 *
154
+	 *  @return Predict_Pass or NULL if there was an error.
155
+	 *
156
+	 * This function will find the first upcoming pass with AOS no earlier than
157
+	 * t = start and no later than t = (start+maxdt).
158
+	 *
159
+	 *  note For no time limit use maxdt = 0.0
160
+	 *
161
+	 *  note the data in sat will be corrupt (future) and must be refreshed
162
+	 *       by the caller, if the caller will need it later on
163
+	 */
164
+	public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165
+	{
166
+		$aos = 0.0;    /* time of AOS */
167
+		$tca = 0.0;    /* time of TCA */
168
+		$los = 0.0;    /* time of LOS */
169
+		$dt = 0.0;     /* time diff */
170
+		$step = 0.0;   /* time step */
171
+		$t0 = $start;
172
+		$tres = 0.0;   /* required time resolution */
173
+		$max_el = 0.0; /* maximum elevation */
174
+		$pass = null;
175
+		$detail = null;
176
+		$done = false;
177
+		$iter = 0;      /* number of iterations */
178
+		/* FIXME: watchdog */
179
+
180
+		/*copy sat_in to a working structure*/
181
+		$sat         = clone $sat_in;
182
+		$sat_working = clone $sat_in;
183
+
184
+		/* get time resolution; sat-cfg stores it in seconds */
185
+		$tres = $this->timeRes / 86400.0;
186
+
187
+		/* loop until we find a pass with elevation > SAT_CFG_INT_PRED_MIN_EL
188 188
             or we run out of time
189 189
             FIXME: we should have a safety break
190 190
         */
191
-        while (!$done) {
192
-            /* Find los of next pass or of current pass */
193
-            $los = $this->find_los($sat, $qth, $t0, $maxdt); // See if a pass is ongoing
194
-            $aos = $this->find_aos($sat, $qth, $t0, $maxdt);
195
-            /* sat_log_log(SAT_LOG_LEVEL_MSG, "%s:%s:%d: found aos %f and los %f for t0=%f", */
196
-            /*          __FILE__,  */
197
-            /*          __FUNCTION__, */
198
-            /*          __LINE__, */
199
-            /*          aos, */
200
-            /*          los,  */
201
-            /*          t0); */
202
-            if ($aos > $los) {
203
-                // los is from an currently happening pass, find previous aos
204
-                $aos = $this->find_prev_aos($sat, $qth, $t0);
205
-            }
206
-
207
-            /* aos = 0.0 means no aos */
208
-            if ($aos == 0.0) {
209
-                $done = true;
210
-            } else if (($maxdt > 0.0) && ($aos > ($start + $maxdt)) ) {
211
-                /* check whether we are within time limits;
191
+		while (!$done) {
192
+			/* Find los of next pass or of current pass */
193
+			$los = $this->find_los($sat, $qth, $t0, $maxdt); // See if a pass is ongoing
194
+			$aos = $this->find_aos($sat, $qth, $t0, $maxdt);
195
+			/* sat_log_log(SAT_LOG_LEVEL_MSG, "%s:%s:%d: found aos %f and los %f for t0=%f", */
196
+			/*          __FILE__,  */
197
+			/*          __FUNCTION__, */
198
+			/*          __LINE__, */
199
+			/*          aos, */
200
+			/*          los,  */
201
+			/*          t0); */
202
+			if ($aos > $los) {
203
+				// los is from an currently happening pass, find previous aos
204
+				$aos = $this->find_prev_aos($sat, $qth, $t0);
205
+			}
206
+
207
+			/* aos = 0.0 means no aos */
208
+			if ($aos == 0.0) {
209
+				$done = true;
210
+			} else if (($maxdt > 0.0) && ($aos > ($start + $maxdt)) ) {
211
+				/* check whether we are within time limits;
212 212
                     maxdt = 0 mean no time limit.
213 213
                 */
214
-                $done = true;
215
-            } else {
216
-                //los = find_los (sat, qth, aos + 0.001, maxdt); // +1.5 min later
217
-                $dt = $los - $aos;
214
+				$done = true;
215
+			} else {
216
+				//los = find_los (sat, qth, aos + 0.001, maxdt); // +1.5 min later
217
+				$dt = $los - $aos;
218 218
 
219
-                /* get time step, which will give us the max number of entries */
220
-                $step = $dt / $this->numEntries;
219
+				/* get time step, which will give us the max number of entries */
220
+				$step = $dt / $this->numEntries;
221 221
 
222
-                /* but if this is smaller than the required resolution
222
+				/* but if this is smaller than the required resolution
223 223
                     we go with the resolution
224 224
                 */
225
-                if ($step < $tres) {
226
-                    $step = $tres;
227
-                }
228
-
229
-                /* create a pass_t entry; FIXME: g_try_new in 2.8 */
230
-                $pass = new Predict_Pass();
231
-
232
-                $pass->aos      = $aos;
233
-                $pass->los      = $los;
234
-                $pass->max_el   = 0.0;
235
-                $pass->aos_az   = 0.0;
236
-                $pass->los_az   = 0.0;
237
-                $pass->maxel_az = 0.0;
238
-                $pass->vis      = '---';
239
-                $pass->satname  = $sat->nickname;
240
-                $pass->details  = array();
241
-
242
-                /* iterate over each time step */
243
-                for ($t = $pass->aos; $t <= $pass->los; $t += $step) {
244
-
245
-                    /* calculate satellite data */
246
-                    $this->predict_calc($sat, $qth, $t);
247
-
248
-                    /* in the first iter we want to store
225
+				if ($step < $tres) {
226
+					$step = $tres;
227
+				}
228
+
229
+				/* create a pass_t entry; FIXME: g_try_new in 2.8 */
230
+				$pass = new Predict_Pass();
231
+
232
+				$pass->aos      = $aos;
233
+				$pass->los      = $los;
234
+				$pass->max_el   = 0.0;
235
+				$pass->aos_az   = 0.0;
236
+				$pass->los_az   = 0.0;
237
+				$pass->maxel_az = 0.0;
238
+				$pass->vis      = '---';
239
+				$pass->satname  = $sat->nickname;
240
+				$pass->details  = array();
241
+
242
+				/* iterate over each time step */
243
+				for ($t = $pass->aos; $t <= $pass->los; $t += $step) {
244
+
245
+					/* calculate satellite data */
246
+					$this->predict_calc($sat, $qth, $t);
247
+
248
+					/* in the first iter we want to store
249 249
                         pass->aos_az
250 250
                     */
251
-                    if ($t == $pass->aos) {
252
-                        $pass->aos_az = $sat->az;
253
-                        $pass->orbit  = $sat->orbit;
254
-                    }
255
-
256
-                    /* append details to sat->details */
257
-                    $detail             = new Predict_PassDetail();
258
-                    $detail->time       = $t;
259
-                    $detail->pos->x     = $sat->pos->x;
260
-                    $detail->pos->y     = $sat->pos->y;
261
-                    $detail->pos->z     = $sat->pos->z;
262
-                    $detail->pos->w     = $sat->pos->w;
263
-                    $detail->vel->x     = $sat->vel->x;
264
-                    $detail->vel->y     = $sat->vel->y;
265
-                    $detail->vel->z     = $sat->vel->z;
266
-                    $detail->vel->w     = $sat->vel->w;
267
-                    $detail->velo       = $sat->velo;
268
-                    $detail->az         = $sat->az;
269
-                    $detail->el         = $sat->el;
270
-                    $detail->range      = $sat->range;
271
-                    $detail->range_rate = $sat->range_rate;
272
-                    $detail->lat        = $sat->ssplat;
273
-                    $detail->lon        = $sat->ssplon;
274
-                    $detail->alt        = $sat->alt;
275
-                    $detail->ma         = $sat->ma;
276
-                    $detail->phase      = $sat->phase;
277
-                    $detail->footprint  = $sat->footprint;
278
-                    $detail->orbit      = $sat->orbit;
279
-                    $detail->vis        = $this->get_sat_vis($sat, $qth, $t);
280
-
281
-                    /* also store visibility "bit" */
282
-                    switch ($detail->vis) {
283
-                        case self::SAT_VIS_VISIBLE:
284
-                            $pass->vis[0] = 'V';
285
-                            break;
286
-                        case self::SAT_VIS_DAYLIGHT:
287
-                            $pass->vis[1] = 'D';
288
-                            break;
289
-                        case self::SAT_VIS_ECLIPSED:
290
-                            $pass->vis[2] = 'E';
291
-                            break;
292
-                        default:
293
-                            break;
294
-                    }
295
-
296
-                    // Using an array, no need to prepend and reverse the list
297
-                    // as gpredict does
298
-                    $pass->details[] = $detail;
299
-
300
-                    // Look up apparent magnitude if this is a visible pass
301
-                    if ($detail->vis === self::SAT_VIS_VISIBLE) {
302
-                        $apmag = $sat->calculateApparentMagnitude($t, $qth);
303
-                        if ($pass->max_apparent_magnitude === null || $apmag < $pass->max_apparent_magnitude) {
304
-                            $pass->max_apparent_magnitude = $apmag;
305
-                        }
306
-                    }
307
-
308
-                    /* store elevation if greater than the
251
+					if ($t == $pass->aos) {
252
+						$pass->aos_az = $sat->az;
253
+						$pass->orbit  = $sat->orbit;
254
+					}
255
+
256
+					/* append details to sat->details */
257
+					$detail             = new Predict_PassDetail();
258
+					$detail->time       = $t;
259
+					$detail->pos->x     = $sat->pos->x;
260
+					$detail->pos->y     = $sat->pos->y;
261
+					$detail->pos->z     = $sat->pos->z;
262
+					$detail->pos->w     = $sat->pos->w;
263
+					$detail->vel->x     = $sat->vel->x;
264
+					$detail->vel->y     = $sat->vel->y;
265
+					$detail->vel->z     = $sat->vel->z;
266
+					$detail->vel->w     = $sat->vel->w;
267
+					$detail->velo       = $sat->velo;
268
+					$detail->az         = $sat->az;
269
+					$detail->el         = $sat->el;
270
+					$detail->range      = $sat->range;
271
+					$detail->range_rate = $sat->range_rate;
272
+					$detail->lat        = $sat->ssplat;
273
+					$detail->lon        = $sat->ssplon;
274
+					$detail->alt        = $sat->alt;
275
+					$detail->ma         = $sat->ma;
276
+					$detail->phase      = $sat->phase;
277
+					$detail->footprint  = $sat->footprint;
278
+					$detail->orbit      = $sat->orbit;
279
+					$detail->vis        = $this->get_sat_vis($sat, $qth, $t);
280
+
281
+					/* also store visibility "bit" */
282
+					switch ($detail->vis) {
283
+						case self::SAT_VIS_VISIBLE:
284
+							$pass->vis[0] = 'V';
285
+							break;
286
+						case self::SAT_VIS_DAYLIGHT:
287
+							$pass->vis[1] = 'D';
288
+							break;
289
+						case self::SAT_VIS_ECLIPSED:
290
+							$pass->vis[2] = 'E';
291
+							break;
292
+						default:
293
+							break;
294
+					}
295
+
296
+					// Using an array, no need to prepend and reverse the list
297
+					// as gpredict does
298
+					$pass->details[] = $detail;
299
+
300
+					// Look up apparent magnitude if this is a visible pass
301
+					if ($detail->vis === self::SAT_VIS_VISIBLE) {
302
+						$apmag = $sat->calculateApparentMagnitude($t, $qth);
303
+						if ($pass->max_apparent_magnitude === null || $apmag < $pass->max_apparent_magnitude) {
304
+							$pass->max_apparent_magnitude = $apmag;
305
+						}
306
+					}
307
+
308
+					/* store elevation if greater than the
309 309
                         previously stored one
310 310
                     */
311
-                    if ($sat->el > $max_el) {
312
-                        $max_el         = $sat->el;
313
-                        $tca            = $t;
314
-                        $pass->maxel_az = $sat->az;
315
-                    }
316
-
317
-                    /*     g_print ("TIME: %f\tAZ: %f\tEL: %f (MAX: %f)\n", */
318
-                    /*           t, sat->az, sat->el, max_el); */
319
-                }
320
-
321
-                /* calculate satellite data */
322
-                $this->predict_calc($sat, $qth, $pass->los);
323
-                /* store los_az, max_el and tca */
324
-                $pass->los_az = $sat->az;
325
-                $pass->max_el = $max_el;
326
-                $pass->tca    = $tca;
327
-
328
-                /* check whether this pass is good */
329
-                if ($max_el >= $this->minEle) {
330
-                    $done = true;
331
-                } else {
332
-                    $done = false;
333
-                    $t0 = $los + 0.014; // +20 min
334
-                    $pass = null;
335
-                }
336
-
337
-                $iter++;
338
-            }
339
-        }
340
-
341
-        return $pass;
342
-    }
343
-
344
-    /**
345
-     * Calculate satellite visibility.
346
-     *
347
-     * @param Predict_Sat $sat     The satellite structure.
348
-     * @param Predict_QTH $qth     The QTH
349
-     * @param float       $jul_utc The time at which the visibility should be calculated.
350
-     *
351
-     * @return int The visiblity constant, 0, 1, 2, or 3 (see above)
352
-     */
353
-    public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc)
354
-    {
355
-        /* gboolean sat_sun_status;
311
+					if ($sat->el > $max_el) {
312
+						$max_el         = $sat->el;
313
+						$tca            = $t;
314
+						$pass->maxel_az = $sat->az;
315
+					}
316
+
317
+					/*     g_print ("TIME: %f\tAZ: %f\tEL: %f (MAX: %f)\n", */
318
+					/*           t, sat->az, sat->el, max_el); */
319
+				}
320
+
321
+				/* calculate satellite data */
322
+				$this->predict_calc($sat, $qth, $pass->los);
323
+				/* store los_az, max_el and tca */
324
+				$pass->los_az = $sat->az;
325
+				$pass->max_el = $max_el;
326
+				$pass->tca    = $tca;
327
+
328
+				/* check whether this pass is good */
329
+				if ($max_el >= $this->minEle) {
330
+					$done = true;
331
+				} else {
332
+					$done = false;
333
+					$t0 = $los + 0.014; // +20 min
334
+					$pass = null;
335
+				}
336
+
337
+				$iter++;
338
+			}
339
+		}
340
+
341
+		return $pass;
342
+	}
343
+
344
+	/**
345
+	 * Calculate satellite visibility.
346
+	 *
347
+	 * @param Predict_Sat $sat     The satellite structure.
348
+	 * @param Predict_QTH $qth     The QTH
349
+	 * @param float       $jul_utc The time at which the visibility should be calculated.
350
+	 *
351
+	 * @return int The visiblity constant, 0, 1, 2, or 3 (see above)
352
+	 */
353
+	public function get_sat_vis(Predict_Sat $sat, Predict_QTH $qth, $jul_utc)
354
+	{
355
+		/* gboolean sat_sun_status;
356 356
         gdouble  sun_el;
357 357
         gdouble  threshold;
358 358
         gdouble  eclipse_depth;
359 359
         sat_vis_t vis = SAT_VIS_NONE; */
360 360
 
361
-        $eclipse_depth  = 0.0;
362
-        $zero_vector    = new Predict_Vector();
363
-        $obs_geodetic   = new Predict_Geodetic();
364
-
365
-        /* Solar ECI position vector  */
366
-        $solar_vector = new Predict_Vector();
367
-
368
-        /* Solar observed az and el vector  */
369
-        $solar_set = new Predict_ObsSet();
370
-
371
-        /* FIXME: could be passed as parameter */
372
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
373
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
374
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
375
-        $obs_geodetic->theta = 0;
376
-
377
-        Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector);
378
-        Predict_SGPObs::Calculate_Obs($jul_utc, $solar_vector, $zero_vector, $obs_geodetic, $solar_set);
379
-
380
-        if (Predict_Solar::Sat_Eclipsed($sat->pos, $solar_vector, $eclipse_depth)) {
381
-            /* satellite is eclipsed */
382
-            $sat_sun_status = false;
383
-        } else {
384
-            /* satellite in sunlight => may be visible */
385
-            $sat_sun_status = true;
386
-        }
387
-
388
-        if ($sat_sun_status) {
389
-            $sun_el = Predict_Math::Degrees($solar_set->el);
390
-
391
-            if ($sun_el <= $this->threshold && $sat->el >= 0.0) {
392
-                $vis = self::SAT_VIS_VISIBLE;
393
-            } else {
394
-                $vis = self::SAT_VIS_DAYLIGHT;
395
-            }
396
-        } else {
397
-            $vis = self::SAT_VIS_ECLIPSED;
398
-        }
399
-
400
-        return $vis;
401
-    }
402
-
403
-    /** Find the AOS time of the next pass.
404
-     *  @author Alexandru Csete, OZ9AEC
405
-     *  @author John A. Magliacane, KD2BD
406
-     *  @param Predict_Sat $sat   The satellite data.
407
-     *  @param Predict_QTH $qth   The observer's location (QTH) data.
408
-     *  @param float       $start The julian date where calculation should start.
409
-     *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
410
-     *  @return The julain date of the next AOS or 0.0 if the satellite has no AOS.
411
-     *
412
-     * This function finds the time of AOS for the first coming pass taking place
413
-     * no earlier that start.
414
-     * If the satellite is currently within range, the function first calls
415
-     * find_los to get the next LOS time. Then the calculations are done using
416
-     * the new start time.
417
-     *
418
-     */
419
-    public function find_aos(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
420
-    {
421
-        $t = $start;
422
-        $aostime = 0.0;
423
-
424
-
425
-        /* make sure current sat values are
361
+		$eclipse_depth  = 0.0;
362
+		$zero_vector    = new Predict_Vector();
363
+		$obs_geodetic   = new Predict_Geodetic();
364
+
365
+		/* Solar ECI position vector  */
366
+		$solar_vector = new Predict_Vector();
367
+
368
+		/* Solar observed az and el vector  */
369
+		$solar_set = new Predict_ObsSet();
370
+
371
+		/* FIXME: could be passed as parameter */
372
+		$obs_geodetic->lon   = $qth->lon * self::de2ra;
373
+		$obs_geodetic->lat   = $qth->lat * self::de2ra;
374
+		$obs_geodetic->alt   = $qth->alt / 1000.0;
375
+		$obs_geodetic->theta = 0;
376
+
377
+		Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector);
378
+		Predict_SGPObs::Calculate_Obs($jul_utc, $solar_vector, $zero_vector, $obs_geodetic, $solar_set);
379
+
380
+		if (Predict_Solar::Sat_Eclipsed($sat->pos, $solar_vector, $eclipse_depth)) {
381
+			/* satellite is eclipsed */
382
+			$sat_sun_status = false;
383
+		} else {
384
+			/* satellite in sunlight => may be visible */
385
+			$sat_sun_status = true;
386
+		}
387
+
388
+		if ($sat_sun_status) {
389
+			$sun_el = Predict_Math::Degrees($solar_set->el);
390
+
391
+			if ($sun_el <= $this->threshold && $sat->el >= 0.0) {
392
+				$vis = self::SAT_VIS_VISIBLE;
393
+			} else {
394
+				$vis = self::SAT_VIS_DAYLIGHT;
395
+			}
396
+		} else {
397
+			$vis = self::SAT_VIS_ECLIPSED;
398
+		}
399
+
400
+		return $vis;
401
+	}
402
+
403
+	/** Find the AOS time of the next pass.
404
+	 *  @author Alexandru Csete, OZ9AEC
405
+	 *  @author John A. Magliacane, KD2BD
406
+	 *  @param Predict_Sat $sat   The satellite data.
407
+	 *  @param Predict_QTH $qth   The observer's location (QTH) data.
408
+	 *  @param float       $start The julian date where calculation should start.
409
+	 *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
410
+	 *  @return The julain date of the next AOS or 0.0 if the satellite has no AOS.
411
+	 *
412
+	 * This function finds the time of AOS for the first coming pass taking place
413
+	 * no earlier that start.
414
+	 * If the satellite is currently within range, the function first calls
415
+	 * find_los to get the next LOS time. Then the calculations are done using
416
+	 * the new start time.
417
+	 *
418
+	 */
419
+	public function find_aos(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
420
+	{
421
+		$t = $start;
422
+		$aostime = 0.0;
423
+
424
+
425
+		/* make sure current sat values are
426 426
             in sync with the time
427 427
         */
428
-        $this->predict_calc($sat, $qth, $start);
429
-
430
-        /* check whether satellite has aos */
431
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
432
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
433
-            !$this->has_aos($sat, $qth)) {
434
-
435
-            return 0.0;
436
-        }
437
-
438
-        if ($sat->el > 0.0) {
439
-            $t = $this->find_los($sat, $qth, $start, $maxdt) + 0.014; // +20 min
440
-        }
441
-
442
-        /* invalid time (potentially returned by find_los) */
443
-        if ($t < 0.1) {
444
-            return 0.0;
445
-        }
446
-
447
-        /* update satellite data */
448
-        $this->predict_calc($sat, $qth, $t);
449
-
450
-        /* use upper time limit */
451
-        if ($maxdt > 0.0) {
452
-
453
-            /* coarse time steps */
454
-            while (($sat->el < -1.0) && ($t <= ($start + $maxdt))) {
455
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
456
-                $this->predict_calc($sat, $qth, $t);
457
-            }
458
-
459
-            /* fine steps */
460
-            while (($aostime == 0.0) && ($t <= ($start + $maxdt))) {
461
-
462
-                if (abs($sat->el) < 0.005) {
463
-                    $aostime = $t;
464
-                } else {
465
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
466
-                    $this->predict_calc($sat, $qth, $t);
467
-                }
468
-            }
469
-        } else {
470
-            /* don't use upper time limit */
471
-
472
-            /* coarse time steps */
473
-            while ($sat->el < -1.0) {
474
-
475
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
476
-                $this->predict_calc($sat, $qth, $t);
477
-            }
478
-
479
-            /* fine steps */
480
-            while ($aostime == 0.0) {
481
-
482
-                if (abs($sat->el) < 0.005) {
483
-                    $aostime = $t;
484
-                } else {
485
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
486
-                    $this->predict_calc($sat, $qth, $t);
487
-                }
488
-
489
-            }
490
-        }
491
-
492
-        return $aostime;
493
-    }
494
-
495
-    /** SGP4SDP4 driver for doing AOS/LOS calculations.
496
-     *  @param Predict_Sat $sat The satellite data.
497
-     *  @param Predict_QTH $qth The QTH observer location data.
498
-     *  @param float       $t   The time for calculation (Julian Date)
499
-     *
500
-     */
501
-    public function predict_calc(Predict_Sat $sat, Predict_QTH $qth, $t)
502
-    {
503
-        $obs_set      = new Predict_ObsSet();
504
-        $sat_geodetic = new Predict_Geodetic();
505
-        $obs_geodetic = new Predict_Geodetic();
506
-
507
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
508
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
509
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
510
-        $obs_geodetic->theta = 0;
511
-
512
-        $sat->jul_utc = $t;
513
-        $sat->tsince = ($sat->jul_utc - $sat->jul_epoch) * self::xmnpda;
514
-
515
-        /* call the norad routines according to the deep-space flag */
516
-        $sgpsdp = Predict_SGPSDP::getInstance($sat);
517
-        if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
518
-            $sgpsdp->SDP4($sat, $sat->tsince);
519
-        } else {
520
-            $sgpsdp->SGP4($sat, $sat->tsince);
521
-        }
522
-
523
-        Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
524
-
525
-        /* get the velocity of the satellite */
526
-        $sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
527
-        $sat->velo = $sat->vel->w;
528
-        Predict_SGPObs::Calculate_Obs($sat->jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
529
-        Predict_SGPObs::Calculate_LatLonAlt($sat->jul_utc, $sat->pos, $sat_geodetic);
530
-
531
-        while ($sat_geodetic->lon < -self::pi) {
532
-            $sat_geodetic->lon += self::twopi;
533
-        }
534
-
535
-        while ($sat_geodetic->lon > (self::pi)) {
536
-            $sat_geodetic->lon -= self::twopi;
537
-        }
538
-
539
-        $sat->az = Predict_Math::Degrees($obs_set->az);
540
-        $sat->el = Predict_Math::Degrees($obs_set->el);
541
-        $sat->range = $obs_set->range;
542
-        $sat->range_rate = $obs_set->range_rate;
543
-        $sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
544
-        $sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
545
-        $sat->alt = $sat_geodetic->alt;
546
-        $sat->ma = Predict_Math::Degrees($sat->phase);
547
-        $sat->ma *= 256.0 / 360.0;
548
-        $sat->phase = Predict_Math::Degrees($sat->phase);
549
-
550
-        /* same formulas, but the one from predict is nicer */
551
-        //sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
552
-        $sat->footprint = 12756.33 * acos(self::xkmper / (self::xkmper + $sat->alt));
553
-        $age = $sat->jul_utc - $sat->jul_epoch;
554
-        $sat->orbit = floor(($sat->tle->xno * self::xmnpda / self::twopi +
555
-                        $age * $sat->tle->bstar * self::ae) * $age +
556
-                        $sat->tle->xmo / self::twopi) + $sat->tle->revnum - 1;
557
-    }
558
-
559
-    /** Find the LOS time of the next pass.
560
-     *  @author Alexandru Csete, OZ9AEC
561
-     *  @author John A. Magliacane, KD2BD
562
-     *  @param Predict_Sat $sat The satellite data.
563
-     *  @param Predict_QTH $qth The QTH observer location data.
564
-     *  @param float       $start The time where calculation should start. (Julian Date)
565
-     *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
566
-     *  @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
567
-     *
568
-     * This function finds the time of LOS for the first coming pass taking place
569
-     * no earlier that start.
570
-     * If the satellite is currently out of range, the function first calls
571
-     * find_aos to get the next AOS time. Then the calculations are done using
572
-     * the new start time.
573
-     * The function has a built-in watchdog to ensure that we don't end up in
574
-     * lengthy loops.
575
-     *
576
-     */
577
-    public function find_los(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
578
-    {
579
-        $t = $start;
580
-        $lostime = 0.0;
581
-
582
-
583
-        $this->predict_calc($sat, $qth, $start);
584
-
585
-        /* check whether satellite has aos */
586
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
587
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
588
-            !$this->has_aos ($sat, $qth)) {
589
-
590
-            return 0.0;
591
-        }
592
-
593
-        if ($sat->el < 0.0) {
594
-            $t = $this->find_aos($sat, $qth, $start, $maxdt) + 0.001; // +1.5 min
595
-        }
596
-
597
-        /* invalid time (potentially returned by find_aos) */
598
-        if ($t < 0.01) {
599
-            return 0.0;
600
-        }
601
-
602
-        /* update satellite data */
603
-        $this->predict_calc($sat, $qth, $t);
604
-
605
-        /* use upper time limit */
606
-        if ($maxdt > 0.0) {
607
-
608
-            /* coarse steps */
609
-            while (($sat->el >= 1.0) && ($t <= ($start + $maxdt))) {
610
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
611
-                $this->predict_calc($sat, $qth, $t);
612
-            }
613
-
614
-            /* fine steps */
615
-            while (($lostime == 0.0) && ($t <= ($start + $maxdt)))  {
616
-
617
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
618
-                $this->predict_calc($sat, $qth, $t);
619
-
620
-                if (abs($sat->el) < 0.005) {
621
-                    $lostime = $t;
622
-                }
623
-            }
624
-        } else {
625
-        /* don't use upper limit */
626
-
627
-            /* coarse steps */
628
-            while ($sat->el >= 1.0) {
629
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
630
-                $this->predict_calc($sat, $qth, $t);
631
-            }
632
-
633
-            /* fine steps */
634
-            while ($lostime == 0.0) {
635
-
636
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
637
-                $this->predict_calc($sat, $qth, $t);
638
-
639
-                if (abs($sat->el) < 0.005)
640
-                    $lostime = $t;
641
-            }
642
-        }
643
-
644
-        return $lostime;
645
-    }
646
-
647
-    /** Find AOS time of current pass.
648
-     *  @param Predict_Sat $sat   The satellite to find AOS for.
649
-     *  @param Predict_QTH $qth   The ground station.
650
-     *  @param float       $start Start time, prefereably now.
651
-     *  @return The time of the previous AOS or 0.0 if the satellite has no AOS.
652
-     *
653
-     * This function can be used to find the AOS time in the past of the
654
-     * current pass.
655
-     */
656
-    public function find_prev_aos(Predict_Sat $sat, Predict_QTH $qth, $start)
657
-    {
658
-        $aostime = $start;
659
-
660
-        /* make sure current sat values are
428
+		$this->predict_calc($sat, $qth, $start);
429
+
430
+		/* check whether satellite has aos */
431
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
432
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
433
+			!$this->has_aos($sat, $qth)) {
434
+
435
+			return 0.0;
436
+		}
437
+
438
+		if ($sat->el > 0.0) {
439
+			$t = $this->find_los($sat, $qth, $start, $maxdt) + 0.014; // +20 min
440
+		}
441
+
442
+		/* invalid time (potentially returned by find_los) */
443
+		if ($t < 0.1) {
444
+			return 0.0;
445
+		}
446
+
447
+		/* update satellite data */
448
+		$this->predict_calc($sat, $qth, $t);
449
+
450
+		/* use upper time limit */
451
+		if ($maxdt > 0.0) {
452
+
453
+			/* coarse time steps */
454
+			while (($sat->el < -1.0) && ($t <= ($start + $maxdt))) {
455
+				$t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
456
+				$this->predict_calc($sat, $qth, $t);
457
+			}
458
+
459
+			/* fine steps */
460
+			while (($aostime == 0.0) && ($t <= ($start + $maxdt))) {
461
+
462
+				if (abs($sat->el) < 0.005) {
463
+					$aostime = $t;
464
+				} else {
465
+					$t -= $sat->el * sqrt($sat->alt) / 530000.0;
466
+					$this->predict_calc($sat, $qth, $t);
467
+				}
468
+			}
469
+		} else {
470
+			/* don't use upper time limit */
471
+
472
+			/* coarse time steps */
473
+			while ($sat->el < -1.0) {
474
+
475
+				$t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
476
+				$this->predict_calc($sat, $qth, $t);
477
+			}
478
+
479
+			/* fine steps */
480
+			while ($aostime == 0.0) {
481
+
482
+				if (abs($sat->el) < 0.005) {
483
+					$aostime = $t;
484
+				} else {
485
+					$t -= $sat->el * sqrt($sat->alt) / 530000.0;
486
+					$this->predict_calc($sat, $qth, $t);
487
+				}
488
+
489
+			}
490
+		}
491
+
492
+		return $aostime;
493
+	}
494
+
495
+	/** SGP4SDP4 driver for doing AOS/LOS calculations.
496
+	 *  @param Predict_Sat $sat The satellite data.
497
+	 *  @param Predict_QTH $qth The QTH observer location data.
498
+	 *  @param float       $t   The time for calculation (Julian Date)
499
+	 *
500
+	 */
501
+	public function predict_calc(Predict_Sat $sat, Predict_QTH $qth, $t)
502
+	{
503
+		$obs_set      = new Predict_ObsSet();
504
+		$sat_geodetic = new Predict_Geodetic();
505
+		$obs_geodetic = new Predict_Geodetic();
506
+
507
+		$obs_geodetic->lon   = $qth->lon * self::de2ra;
508
+		$obs_geodetic->lat   = $qth->lat * self::de2ra;
509
+		$obs_geodetic->alt   = $qth->alt / 1000.0;
510
+		$obs_geodetic->theta = 0;
511
+
512
+		$sat->jul_utc = $t;
513
+		$sat->tsince = ($sat->jul_utc - $sat->jul_epoch) * self::xmnpda;
514
+
515
+		/* call the norad routines according to the deep-space flag */
516
+		$sgpsdp = Predict_SGPSDP::getInstance($sat);
517
+		if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
518
+			$sgpsdp->SDP4($sat, $sat->tsince);
519
+		} else {
520
+			$sgpsdp->SGP4($sat, $sat->tsince);
521
+		}
522
+
523
+		Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
524
+
525
+		/* get the velocity of the satellite */
526
+		$sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
527
+		$sat->velo = $sat->vel->w;
528
+		Predict_SGPObs::Calculate_Obs($sat->jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
529
+		Predict_SGPObs::Calculate_LatLonAlt($sat->jul_utc, $sat->pos, $sat_geodetic);
530
+
531
+		while ($sat_geodetic->lon < -self::pi) {
532
+			$sat_geodetic->lon += self::twopi;
533
+		}
534
+
535
+		while ($sat_geodetic->lon > (self::pi)) {
536
+			$sat_geodetic->lon -= self::twopi;
537
+		}
538
+
539
+		$sat->az = Predict_Math::Degrees($obs_set->az);
540
+		$sat->el = Predict_Math::Degrees($obs_set->el);
541
+		$sat->range = $obs_set->range;
542
+		$sat->range_rate = $obs_set->range_rate;
543
+		$sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
544
+		$sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
545
+		$sat->alt = $sat_geodetic->alt;
546
+		$sat->ma = Predict_Math::Degrees($sat->phase);
547
+		$sat->ma *= 256.0 / 360.0;
548
+		$sat->phase = Predict_Math::Degrees($sat->phase);
549
+
550
+		/* same formulas, but the one from predict is nicer */
551
+		//sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
552
+		$sat->footprint = 12756.33 * acos(self::xkmper / (self::xkmper + $sat->alt));
553
+		$age = $sat->jul_utc - $sat->jul_epoch;
554
+		$sat->orbit = floor(($sat->tle->xno * self::xmnpda / self::twopi +
555
+						$age * $sat->tle->bstar * self::ae) * $age +
556
+						$sat->tle->xmo / self::twopi) + $sat->tle->revnum - 1;
557
+	}
558
+
559
+	/** Find the LOS time of the next pass.
560
+	 *  @author Alexandru Csete, OZ9AEC
561
+	 *  @author John A. Magliacane, KD2BD
562
+	 *  @param Predict_Sat $sat The satellite data.
563
+	 *  @param Predict_QTH $qth The QTH observer location data.
564
+	 *  @param float       $start The time where calculation should start. (Julian Date)
565
+	 *  @param int         $maxdt The upper time limit in days (0.0 = no limit)
566
+	 *  @return The time (julian date) of the next LOS or 0.0 if the satellite has no LOS.
567
+	 *
568
+	 * This function finds the time of LOS for the first coming pass taking place
569
+	 * no earlier that start.
570
+	 * If the satellite is currently out of range, the function first calls
571
+	 * find_aos to get the next AOS time. Then the calculations are done using
572
+	 * the new start time.
573
+	 * The function has a built-in watchdog to ensure that we don't end up in
574
+	 * lengthy loops.
575
+	 *
576
+	 */
577
+	public function find_los(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt)
578
+	{
579
+		$t = $start;
580
+		$lostime = 0.0;
581
+
582
+
583
+		$this->predict_calc($sat, $qth, $start);
584
+
585
+		/* check whether satellite has aos */
586
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
587
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
588
+			!$this->has_aos ($sat, $qth)) {
589
+
590
+			return 0.0;
591
+		}
592
+
593
+		if ($sat->el < 0.0) {
594
+			$t = $this->find_aos($sat, $qth, $start, $maxdt) + 0.001; // +1.5 min
595
+		}
596
+
597
+		/* invalid time (potentially returned by find_aos) */
598
+		if ($t < 0.01) {
599
+			return 0.0;
600
+		}
601
+
602
+		/* update satellite data */
603
+		$this->predict_calc($sat, $qth, $t);
604
+
605
+		/* use upper time limit */
606
+		if ($maxdt > 0.0) {
607
+
608
+			/* coarse steps */
609
+			while (($sat->el >= 1.0) && ($t <= ($start + $maxdt))) {
610
+				$t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
611
+				$this->predict_calc($sat, $qth, $t);
612
+			}
613
+
614
+			/* fine steps */
615
+			while (($lostime == 0.0) && ($t <= ($start + $maxdt)))  {
616
+
617
+				$t += $sat->el * sqrt($sat->alt) / 502500.0;
618
+				$this->predict_calc($sat, $qth, $t);
619
+
620
+				if (abs($sat->el) < 0.005) {
621
+					$lostime = $t;
622
+				}
623
+			}
624
+		} else {
625
+		/* don't use upper limit */
626
+
627
+			/* coarse steps */
628
+			while ($sat->el >= 1.0) {
629
+				$t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
630
+				$this->predict_calc($sat, $qth, $t);
631
+			}
632
+
633
+			/* fine steps */
634
+			while ($lostime == 0.0) {
635
+
636
+				$t += $sat->el * sqrt($sat->alt) / 502500.0;
637
+				$this->predict_calc($sat, $qth, $t);
638
+
639
+				if (abs($sat->el) < 0.005)
640
+					$lostime = $t;
641
+			}
642
+		}
643
+
644
+		return $lostime;
645
+	}
646
+
647
+	/** Find AOS time of current pass.
648
+	 *  @param Predict_Sat $sat   The satellite to find AOS for.
649
+	 *  @param Predict_QTH $qth   The ground station.
650
+	 *  @param float       $start Start time, prefereably now.
651
+	 *  @return The time of the previous AOS or 0.0 if the satellite has no AOS.
652
+	 *
653
+	 * This function can be used to find the AOS time in the past of the
654
+	 * current pass.
655
+	 */
656
+	public function find_prev_aos(Predict_Sat $sat, Predict_QTH $qth, $start)
657
+	{
658
+		$aostime = $start;
659
+
660
+		/* make sure current sat values are
661 661
             in sync with the time
662 662
         */
663
-        $this->predict_calc($sat, $qth, $start);
664
-
665
-        /* check whether satellite has aos */
666
-        if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
667
-            ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
668
-            !$this->has_aos($sat, $qth)) {
669
-
670
-            return 0.0;
671
-        }
672
-
673
-        while ($sat->el >= 0.0) {
674
-            $aostime -= 0.0005; // 0.75 min
675
-            $this->predict_calc($sat, $qth, $aostime);
676
-        }
677
-
678
-        return $aostime;
679
-    }
680
-
681
-    /** Determine whether satellite ever reaches AOS.
682
-     *  @author John A. Magliacane, KD2BD
683
-     *  @author Alexandru Csete, OZ9AEC
684
-     *  @param Predict_Sat $sat The satellite data.
685
-     *  @param Predict_QTH $qth The observer's location data
686
-     *  @return bool true if the satellite will reach AOS, false otherwise.
687
-     *
688
-     */
689
-    public function has_aos(Predict_Sat $sat, Predict_QTH $qth)
690
-    {
691
-         $retcode = false;
692
-
693
-         /* FIXME */
694
-         if ($sat->meanmo == 0.0) {
695
-              $retcode = false;
696
-         } else {
697
-
698
-            /* xincl is already in RAD by select_ephemeris */
699
-            $lin = $sat->tle->xincl;
700
-            if ($lin >= self::pio2) {
701
-                $lin = self::pi - $lin;
702
-            }
703
-
704
-            $sma = 331.25 * exp(log(1440.0 / $sat->meanmo) * (2.0 / 3.0));
705
-            $apogee = $sma * (1.0 + $sat->tle->eo) - self::xkmper;
706
-
707
-            if ((acos(self::xkmper / ($apogee + self::xkmper)) + ($lin)) > abs($qth->lat * self::de2ra)) {
708
-                $retcode = true;
709
-            } else {
710
-                $retcode = false;
711
-            }
712
-        }
713
-
714
-        return $retcode;
715
-    }
716
-
717
-    /** Predict passes after a certain time.
718
-     *
719
-     *
720
-     * This function calculates num upcoming passes with AOS no earlier
721
-     * than t = start and not later that t = (start+maxdt). The function will
722
-     *  repeatedly call get_pass until
723
-     * the number of predicted passes is equal to num, the time has reached
724
-     * limit or the get_pass function returns NULL.
725
-     *
726
-     * note For no time limit use maxdt = 0.0
727
-     *
728
-     * note the data in sat will be corrupt (future) and must be refreshed
729
-     *      by the caller, if the caller will need it later on (eg. if the caller
730
-     *      is GtkSatList).
731
-     *
732
-     * note Prepending to a singly linked list is much faster than appending.
733
-     *      Therefore, the elements are prepended whereafter the GSList is
734
-     *      reversed
735
-     *
736
-     *
737
-     * @param Predict_Sat  $sat The satellite data
738
-     * @param Predict_QTH  $qth The observer's location data
739
-     * @param float $start The start julian date
740
-     * @param int   $maxdt The max # of days to look
741
-     * @param int   $num   The max # of passes to get
742
-     * @return array of Predict_Pass instances if found, empty array otherwise
743
-     */
744
-    public function get_passes(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt, $num = 0)
745
-    {
746
-        $passes = array();
747
-
748
-        /* if no number has been specified
663
+		$this->predict_calc($sat, $qth, $start);
664
+
665
+		/* check whether satellite has aos */
666
+		if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
667
+			($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
668
+			!$this->has_aos($sat, $qth)) {
669
+
670
+			return 0.0;
671
+		}
672
+
673
+		while ($sat->el >= 0.0) {
674
+			$aostime -= 0.0005; // 0.75 min
675
+			$this->predict_calc($sat, $qth, $aostime);
676
+		}
677
+
678
+		return $aostime;
679
+	}
680
+
681
+	/** Determine whether satellite ever reaches AOS.
682
+	 *  @author John A. Magliacane, KD2BD
683
+	 *  @author Alexandru Csete, OZ9AEC
684
+	 *  @param Predict_Sat $sat The satellite data.
685
+	 *  @param Predict_QTH $qth The observer's location data
686
+	 *  @return bool true if the satellite will reach AOS, false otherwise.
687
+	 *
688
+	 */
689
+	public function has_aos(Predict_Sat $sat, Predict_QTH $qth)
690
+	{
691
+		 $retcode = false;
692
+
693
+		 /* FIXME */
694
+		 if ($sat->meanmo == 0.0) {
695
+			  $retcode = false;
696
+		 } else {
697
+
698
+			/* xincl is already in RAD by select_ephemeris */
699
+			$lin = $sat->tle->xincl;
700
+			if ($lin >= self::pio2) {
701
+				$lin = self::pi - $lin;
702
+			}
703
+
704
+			$sma = 331.25 * exp(log(1440.0 / $sat->meanmo) * (2.0 / 3.0));
705
+			$apogee = $sma * (1.0 + $sat->tle->eo) - self::xkmper;
706
+
707
+			if ((acos(self::xkmper / ($apogee + self::xkmper)) + ($lin)) > abs($qth->lat * self::de2ra)) {
708
+				$retcode = true;
709
+			} else {
710
+				$retcode = false;
711
+			}
712
+		}
713
+
714
+		return $retcode;
715
+	}
716
+
717
+	/** Predict passes after a certain time.
718
+	 *
719
+	 *
720
+	 * This function calculates num upcoming passes with AOS no earlier
721
+	 * than t = start and not later that t = (start+maxdt). The function will
722
+	 *  repeatedly call get_pass until
723
+	 * the number of predicted passes is equal to num, the time has reached
724
+	 * limit or the get_pass function returns NULL.
725
+	 *
726
+	 * note For no time limit use maxdt = 0.0
727
+	 *
728
+	 * note the data in sat will be corrupt (future) and must be refreshed
729
+	 *      by the caller, if the caller will need it later on (eg. if the caller
730
+	 *      is GtkSatList).
731
+	 *
732
+	 * note Prepending to a singly linked list is much faster than appending.
733
+	 *      Therefore, the elements are prepended whereafter the GSList is
734
+	 *      reversed
735
+	 *
736
+	 *
737
+	 * @param Predict_Sat  $sat The satellite data
738
+	 * @param Predict_QTH  $qth The observer's location data
739
+	 * @param float $start The start julian date
740
+	 * @param int   $maxdt The max # of days to look
741
+	 * @param int   $num   The max # of passes to get
742
+	 * @return array of Predict_Pass instances if found, empty array otherwise
743
+	 */
744
+	public function get_passes(Predict_Sat $sat, Predict_QTH $qth, $start, $maxdt, $num = 0)
745
+	{
746
+		$passes = array();
747
+
748
+		/* if no number has been specified
749 749
             set it to something big */
750
-        if ($num == 0) {
751
-            $num = 100;
752
-        }
750
+		if ($num == 0) {
751
+			$num = 100;
752
+		}
753 753
 
754
-        $t = $start;
754
+		$t = $start;
755 755
 
756
-        for ($i = 0; $i < $num; $i++) {
757
-            $pass = $this->get_pass($sat, $qth, $t, $maxdt);
756
+		for ($i = 0; $i < $num; $i++) {
757
+			$pass = $this->get_pass($sat, $qth, $t, $maxdt);
758 758
 
759
-            if ($pass != null) {
760
-                $passes[] = $pass;
761
-                $t = $pass->los + 0.014; // +20 min
759
+			if ($pass != null) {
760
+				$passes[] = $pass;
761
+				$t = $pass->los + 0.014; // +20 min
762 762
 
763
-                /* if maxdt > 0.0 check whether we have reached t = start+maxdt
763
+				/* if maxdt > 0.0 check whether we have reached t = start+maxdt
764 764
                     if yes finish predictions
765 765
                 */
766
-                if (($maxdt > 0.0) && ($t >= ($start + $maxdt))) {
767
-                    $i = $num;
768
-                }
769
-            } else {
770
-                /* we can't get any more passes */
771
-                $i = $num;
772
-            }
773
-        }
774
-
775
-        return $passes;
776
-    }
777
-
778
-    /**
779
-     * Filters out visible passes and adds the visible aos, tca, los, and
780
-     * corresponding az and ele for each.
781
-     *
782
-     * @param array $passes The passes returned from get_passes()
783
-     *
784
-     * @author Bill Shupp
785
-     * @return array
786
-     */
787
-    public function filterVisiblePasses(array $passes)
788
-    {
789
-        $filtered = array();
790
-
791
-        foreach ($passes as $result) {
792
-            // Dummy check
793
-            if ($result->vis[0] != 'V') {
794
-                continue;
795
-            }
796
-
797
-            $aos    = false;
798
-            $aos_az = false;
799
-            $aos    = false;
800
-            $tca    = false;
801
-            $los_az = false;
802
-            $max_el = 0;
803
-
804
-            foreach ($result->details as $detail) {
805
-                if ($detail->vis != Predict::SAT_VIS_VISIBLE) {
806
-                    continue;
807
-                }
808
-                if ($detail->el < $this->minEle) {
809
-                    continue;
810
-                }
811
-
812
-                if ($aos == false) {
813
-                    $aos       = $detail->time;
814
-                    $aos_az    = $detail->az;
815
-                    $aos_el    = $detail->el;
816
-                    $tca       = $detail->time;
817
-                    $los       = $detail->time;
818
-                    $los_az    = $detail->az;
819
-                    $los_el    = $detail->el;
820
-                    $max_el    = $detail->el;
821
-                    $max_el_az = $detail->el;
822
-                    continue;
823
-                }
824
-                $los    = $detail->time;
825
-                $los_az = $detail->az;
826
-                $los_el = $detail->el;
827
-
828
-                if ($detail->el > $max_el) {
829
-                    $tca       = $detail->time;
830
-                    $max_el    = $detail->el;
831
-                    $max_el_az = $detail->az;
832
-                }
833
-            }
834
-
835
-            if ($aos === false) {
836
-                // Does not reach minimum elevation, skip
837
-                continue;
838
-            }
839
-
840
-            $result->visible_aos       = $aos;
841
-            $result->visible_aos_az    = $aos_az;
842
-            $result->visible_aos_el    = $aos_el;
843
-            $result->visible_tca       = $tca;
844
-            $result->visible_max_el    = $max_el;
845
-            $result->visible_max_el_az = $max_el_az;
846
-            $result->visible_los       = $los;
847
-            $result->visible_los_az    = $los_az;
848
-            $result->visible_los_el    = $los_el;
849
-
850
-            $filtered[] = $result;
851
-        }
852
-
853
-        return $filtered;
854
-    }
855
-
856
-    /**
857
-     * Translates aziumuth degrees to compass direction:
858
-     *
859
-     * N (0°), NNE (22.5°), NE (45°), ENE (67.5°), E (90°), ESE (112.5°),
860
-     * SE (135°), SSE (157.5°), S (180°), SSW (202.5°), SW (225°),
861
-     * WSW (247.5°), W (270°), WNW (292.5°), NW (315°), NNW (337.5°)
862
-     *
863
-     * @param int $az The azimuth in degrees, defaults to 0
864
-     *
865
-     * @return string
866
-     */
867
-    public function azDegreesToDirection($az = 0)
868
-    {
869
-        $i = floor($az / 22.5);
870
-        $m = (22.5 * (2 * $i + 1)) / 2;
871
-        $i = ($az >= $m) ? $i + 1 : $i;
872
-
873
-        return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i * 3, 3));
874
-    }
766
+				if (($maxdt > 0.0) && ($t >= ($start + $maxdt))) {
767
+					$i = $num;
768
+				}
769
+			} else {
770
+				/* we can't get any more passes */
771
+				$i = $num;
772
+			}
773
+		}
774
+
775
+		return $passes;
776
+	}
777
+
778
+	/**
779
+	 * Filters out visible passes and adds the visible aos, tca, los, and
780
+	 * corresponding az and ele for each.
781
+	 *
782
+	 * @param array $passes The passes returned from get_passes()
783
+	 *
784
+	 * @author Bill Shupp
785
+	 * @return array
786
+	 */
787
+	public function filterVisiblePasses(array $passes)
788
+	{
789
+		$filtered = array();
790
+
791
+		foreach ($passes as $result) {
792
+			// Dummy check
793
+			if ($result->vis[0] != 'V') {
794
+				continue;
795
+			}
796
+
797
+			$aos    = false;
798
+			$aos_az = false;
799
+			$aos    = false;
800
+			$tca    = false;
801
+			$los_az = false;
802
+			$max_el = 0;
803
+
804
+			foreach ($result->details as $detail) {
805
+				if ($detail->vis != Predict::SAT_VIS_VISIBLE) {
806
+					continue;
807
+				}
808
+				if ($detail->el < $this->minEle) {
809
+					continue;
810
+				}
811
+
812
+				if ($aos == false) {
813
+					$aos       = $detail->time;
814
+					$aos_az    = $detail->az;
815
+					$aos_el    = $detail->el;
816
+					$tca       = $detail->time;
817
+					$los       = $detail->time;
818
+					$los_az    = $detail->az;
819
+					$los_el    = $detail->el;
820
+					$max_el    = $detail->el;
821
+					$max_el_az = $detail->el;
822
+					continue;
823
+				}
824
+				$los    = $detail->time;
825
+				$los_az = $detail->az;
826
+				$los_el = $detail->el;
827
+
828
+				if ($detail->el > $max_el) {
829
+					$tca       = $detail->time;
830
+					$max_el    = $detail->el;
831
+					$max_el_az = $detail->az;
832
+				}
833
+			}
834
+
835
+			if ($aos === false) {
836
+				// Does not reach minimum elevation, skip
837
+				continue;
838
+			}
839
+
840
+			$result->visible_aos       = $aos;
841
+			$result->visible_aos_az    = $aos_az;
842
+			$result->visible_aos_el    = $aos_el;
843
+			$result->visible_tca       = $tca;
844
+			$result->visible_max_el    = $max_el;
845
+			$result->visible_max_el_az = $max_el_az;
846
+			$result->visible_los       = $los;
847
+			$result->visible_los_az    = $los_az;
848
+			$result->visible_los_el    = $los_el;
849
+
850
+			$filtered[] = $result;
851
+		}
852
+
853
+		return $filtered;
854
+	}
855
+
856
+	/**
857
+	 * Translates aziumuth degrees to compass direction:
858
+	 *
859
+	 * N (0°), NNE (22.5°), NE (45°), ENE (67.5°), E (90°), ESE (112.5°),
860
+	 * SE (135°), SSE (157.5°), S (180°), SSW (202.5°), SW (225°),
861
+	 * WSW (247.5°), W (270°), WNW (292.5°), NW (315°), NNW (337.5°)
862
+	 *
863
+	 * @param int $az The azimuth in degrees, defaults to 0
864
+	 *
865
+	 * @return string
866
+	 */
867
+	public function azDegreesToDirection($az = 0)
868
+	{
869
+		$i = floor($az / 22.5);
870
+		$m = (22.5 * (2 * $i + 1)) / 2;
871
+		$i = ($az >= $m) ? $i + 1 : $i;
872
+
873
+		return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i * 3, 3));
874
+	}
875 875
 }
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -52,60 +52,60 @@  discard block
 block discarded – undo
52 52
  */
53 53
 class Predict
54 54
 {
55
-    const de2ra    =  1.74532925E-2;   /* Degrees to Radians */
56
-    const pi       =  3.1415926535898; /* Pi */
57
-    const pio2     =  1.5707963267949; /* Pi/2 */
58
-    const x3pio2   =  4.71238898;      /* 3*Pi/2 */
59
-    const twopi    =  6.2831853071796; /* 2*Pi  */
60
-    const e6a      =  1.0E-6;
61
-    const tothrd   =  6.6666667E-1;    /* 2/3 */
62
-    const xj2      =  1.0826158E-3;    /* J2 Harmonic */
63
-    const xj3      = -2.53881E-6;      /* J3 Harmonic */
64
-    const xj4      = -1.65597E-6;      /* J4 Harmonic */
65
-    const xke      =  7.43669161E-2;
66
-    const xkmper   =  6.378135E3;      /* Earth radius km */
67
-    const xmnpda   =  1.44E3;          /* Minutes per day */
68
-    const km2mi    =  0.621371;        /* Kilometers per Mile */
69
-    const ae       =  1.0;
70
-    const ck2      =  5.413079E-4;
71
-    const ck4      =  6.209887E-7;
72
-    const __f      =  3.352779E-3;
73
-    const ge       =  3.986008E5;
74
-    const __s__    =  1.012229;
75
-    const qoms2t   =  1.880279E-09;
76
-    const secday   =  8.6400E4;        /* Seconds per day */
77
-    const omega_E  =  1.0027379;
78
-    const omega_ER =  6.3003879;
79
-    const zns      =  1.19459E-5;
80
-    const c1ss     =  2.9864797E-6;
81
-    const zes      =  1.675E-2;
82
-    const znl      =  1.5835218E-4;
83
-    const c1l      =  4.7968065E-7;
84
-    const zel      =  5.490E-2;
85
-    const zcosis   =  9.1744867E-1;
86
-    const zsinis   =  3.9785416E-1;
55
+    const de2ra    = 1.74532925E-2; /* Degrees to Radians */
56
+    const pi       = 3.1415926535898; /* Pi */
57
+    const pio2     = 1.5707963267949; /* Pi/2 */
58
+    const x3pio2   = 4.71238898; /* 3*Pi/2 */
59
+    const twopi    = 6.2831853071796; /* 2*Pi  */
60
+    const e6a      = 1.0E-6;
61
+    const tothrd   = 6.6666667E-1; /* 2/3 */
62
+    const xj2      = 1.0826158E-3; /* J2 Harmonic */
63
+    const xj3      = -2.53881E-6; /* J3 Harmonic */
64
+    const xj4      = -1.65597E-6; /* J4 Harmonic */
65
+    const xke      = 7.43669161E-2;
66
+    const xkmper   = 6.378135E3; /* Earth radius km */
67
+    const xmnpda   = 1.44E3; /* Minutes per day */
68
+    const km2mi    = 0.621371; /* Kilometers per Mile */
69
+    const ae       = 1.0;
70
+    const ck2      = 5.413079E-4;
71
+    const ck4      = 6.209887E-7;
72
+    const __f      = 3.352779E-3;
73
+    const ge       = 3.986008E5;
74
+    const __s__    = 1.012229;
75
+    const qoms2t   = 1.880279E-09;
76
+    const secday   = 8.6400E4; /* Seconds per day */
77
+    const omega_E  = 1.0027379;
78
+    const omega_ER = 6.3003879;
79
+    const zns      = 1.19459E-5;
80
+    const c1ss     = 2.9864797E-6;
81
+    const zes      = 1.675E-2;
82
+    const znl      = 1.5835218E-4;
83
+    const c1l      = 4.7968065E-7;
84
+    const zel      = 5.490E-2;
85
+    const zcosis   = 9.1744867E-1;
86
+    const zsinis   = 3.9785416E-1;
87 87
     const zsings   = -9.8088458E-1;
88
-    const zcosgs   =  1.945905E-1;
89
-    const zcoshs   =  1;
90
-    const zsinhs   =  0;
91
-    const q22      =  1.7891679E-6;
92
-    const q31      =  2.1460748E-6;
93
-    const q33      =  2.2123015E-7;
94
-    const g22      =  5.7686396;
95
-    const g32      =  9.5240898E-1;
96
-    const g44      =  1.8014998;
97
-    const g52      =  1.0508330;
98
-    const g54      =  4.4108898;
99
-    const root22   =  1.7891679E-6;
100
-    const root32   =  3.7393792E-7;
101
-    const root44   =  7.3636953E-9;
102
-    const root52   =  1.1428639E-7;
103
-    const root54   =  2.1765803E-9;
104
-    const thdt     =  4.3752691E-3;
105
-    const rho      =  1.5696615E-1;
106
-    const mfactor  =  7.292115E-5;
107
-    const __sr__   =  6.96000E5;      /*Solar radius - kilometers (IAU 76)*/
108
-    const AU       =  1.49597870E8;   /*Astronomical unit - kilometers (IAU 76)*/
88
+    const zcosgs   = 1.945905E-1;
89
+    const zcoshs   = 1;
90
+    const zsinhs   = 0;
91
+    const q22      = 1.7891679E-6;
92
+    const q31      = 2.1460748E-6;
93
+    const q33      = 2.2123015E-7;
94
+    const g22      = 5.7686396;
95
+    const g32      = 9.5240898E-1;
96
+    const g44      = 1.8014998;
97
+    const g52      = 1.0508330;
98
+    const g54      = 4.4108898;
99
+    const root22   = 1.7891679E-6;
100
+    const root32   = 3.7393792E-7;
101
+    const root44   = 7.3636953E-9;
102
+    const root52   = 1.1428639E-7;
103
+    const root54   = 2.1765803E-9;
104
+    const thdt     = 4.3752691E-3;
105
+    const rho      = 1.5696615E-1;
106
+    const mfactor  = 7.292115E-5;
107
+    const __sr__   = 6.96000E5; /*Solar radius - kilometers (IAU 76)*/
108
+    const AU       = 1.49597870E8; /*Astronomical unit - kilometers (IAU 76)*/
109 109
 
110 110
     /* visibility constants */
111 111
     const SAT_VIS_NONE     = 0;
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
      */
164 164
     public function get_pass(Predict_Sat $sat_in, Predict_QTH $qth, $start, $maxdt)
165 165
     {
166
-        $aos = 0.0;    /* time of AOS */
167
-        $tca = 0.0;    /* time of TCA */
168
-        $los = 0.0;    /* time of LOS */
169
-        $dt = 0.0;     /* time diff */
170
-        $step = 0.0;   /* time step */
166
+        $aos = 0.0; /* time of AOS */
167
+        $tca = 0.0; /* time of TCA */
168
+        $los = 0.0; /* time of LOS */
169
+        $dt = 0.0; /* time diff */
170
+        $step = 0.0; /* time step */
171 171
         $t0 = $start;
172
-        $tres = 0.0;   /* required time resolution */
172
+        $tres = 0.0; /* required time resolution */
173 173
         $max_el = 0.0; /* maximum elevation */
174 174
         $pass = null;
175 175
         $detail = null;
176 176
         $done = false;
177
-        $iter = 0;      /* number of iterations */
177
+        $iter = 0; /* number of iterations */
178 178
         /* FIXME: watchdog */
179 179
 
180 180
         /*copy sat_in to a working structure*/
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         $sat_working = clone $sat_in;
183 183
 
184 184
         /* get time resolution; sat-cfg stores it in seconds */
185
-        $tres = $this->timeRes / 86400.0;
185
+        $tres = $this->timeRes/86400.0;
186 186
 
187 187
         /* loop until we find a pass with elevation > SAT_CFG_INT_PRED_MIN_EL
188 188
             or we run out of time
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             /* aos = 0.0 means no aos */
208 208
             if ($aos == 0.0) {
209 209
                 $done = true;
210
-            } else if (($maxdt > 0.0) && ($aos > ($start + $maxdt)) ) {
210
+            } else if (($maxdt > 0.0) && ($aos > ($start + $maxdt))) {
211 211
                 /* check whether we are within time limits;
212 212
                     maxdt = 0 mean no time limit.
213 213
                 */
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
                 $dt = $los - $aos;
218 218
 
219 219
                 /* get time step, which will give us the max number of entries */
220
-                $step = $dt / $this->numEntries;
220
+                $step = $dt/$this->numEntries;
221 221
 
222 222
                 /* but if this is smaller than the required resolution
223 223
                     we go with the resolution
@@ -369,9 +369,9 @@  discard block
 block discarded – undo
369 369
         $solar_set = new Predict_ObsSet();
370 370
 
371 371
         /* FIXME: could be passed as parameter */
372
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
373
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
374
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
372
+        $obs_geodetic->lon   = $qth->lon*self::de2ra;
373
+        $obs_geodetic->lat   = $qth->lat*self::de2ra;
374
+        $obs_geodetic->alt   = $qth->alt/1000.0;
375 375
         $obs_geodetic->theta = 0;
376 376
 
377 377
         Predict_Solar::Calculate_Solar_Position($jul_utc, $solar_vector);
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 
453 453
             /* coarse time steps */
454 454
             while (($sat->el < -1.0) && ($t <= ($start + $maxdt))) {
455
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
455
+                $t -= 0.00035*($sat->el*(($sat->alt/8400.0) + 0.46) - 2.0);
456 456
                 $this->predict_calc($sat, $qth, $t);
457 457
             }
458 458
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
                 if (abs($sat->el) < 0.005) {
463 463
                     $aostime = $t;
464 464
                 } else {
465
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
465
+                    $t -= $sat->el*sqrt($sat->alt)/530000.0;
466 466
                     $this->predict_calc($sat, $qth, $t);
467 467
                 }
468 468
             }
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
             /* coarse time steps */
473 473
             while ($sat->el < -1.0) {
474 474
 
475
-                $t -= 0.00035 * ($sat->el * (($sat->alt / 8400.0) + 0.46) - 2.0);
475
+                $t -= 0.00035*($sat->el*(($sat->alt/8400.0) + 0.46) - 2.0);
476 476
                 $this->predict_calc($sat, $qth, $t);
477 477
             }
478 478
 
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
                 if (abs($sat->el) < 0.005) {
483 483
                     $aostime = $t;
484 484
                 } else {
485
-                    $t -= $sat->el * sqrt($sat->alt) / 530000.0;
485
+                    $t -= $sat->el*sqrt($sat->alt)/530000.0;
486 486
                     $this->predict_calc($sat, $qth, $t);
487 487
                 }
488 488
 
@@ -504,17 +504,17 @@  discard block
 block discarded – undo
504 504
         $sat_geodetic = new Predict_Geodetic();
505 505
         $obs_geodetic = new Predict_Geodetic();
506 506
 
507
-        $obs_geodetic->lon   = $qth->lon * self::de2ra;
508
-        $obs_geodetic->lat   = $qth->lat * self::de2ra;
509
-        $obs_geodetic->alt   = $qth->alt / 1000.0;
507
+        $obs_geodetic->lon   = $qth->lon*self::de2ra;
508
+        $obs_geodetic->lat   = $qth->lat*self::de2ra;
509
+        $obs_geodetic->alt   = $qth->alt/1000.0;
510 510
         $obs_geodetic->theta = 0;
511 511
 
512 512
         $sat->jul_utc = $t;
513
-        $sat->tsince = ($sat->jul_utc - $sat->jul_epoch) * self::xmnpda;
513
+        $sat->tsince = ($sat->jul_utc - $sat->jul_epoch)*self::xmnpda;
514 514
 
515 515
         /* call the norad routines according to the deep-space flag */
516 516
         $sgpsdp = Predict_SGPSDP::getInstance($sat);
517
-        if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
517
+        if ($sat->flags&Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
518 518
             $sgpsdp->SDP4($sat, $sat->tsince);
519 519
         } else {
520 520
             $sgpsdp->SGP4($sat, $sat->tsince);
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
524 524
 
525 525
         /* get the velocity of the satellite */
526
-        $sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
526
+        $sat->vel->w = sqrt($sat->vel->x*$sat->vel->x + $sat->vel->y*$sat->vel->y + $sat->vel->z*$sat->vel->z);
527 527
         $sat->velo = $sat->vel->w;
528 528
         Predict_SGPObs::Calculate_Obs($sat->jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
529 529
         Predict_SGPObs::Calculate_LatLonAlt($sat->jul_utc, $sat->pos, $sat_geodetic);
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
         $sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
545 545
         $sat->alt = $sat_geodetic->alt;
546 546
         $sat->ma = Predict_Math::Degrees($sat->phase);
547
-        $sat->ma *= 256.0 / 360.0;
547
+        $sat->ma *= 256.0/360.0;
548 548
         $sat->phase = Predict_Math::Degrees($sat->phase);
549 549
 
550 550
         /* same formulas, but the one from predict is nicer */
551 551
         //sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
552
-        $sat->footprint = 12756.33 * acos(self::xkmper / (self::xkmper + $sat->alt));
552
+        $sat->footprint = 12756.33*acos(self::xkmper/(self::xkmper + $sat->alt));
553 553
         $age = $sat->jul_utc - $sat->jul_epoch;
554
-        $sat->orbit = floor(($sat->tle->xno * self::xmnpda / self::twopi +
555
-                        $age * $sat->tle->bstar * self::ae) * $age +
556
-                        $sat->tle->xmo / self::twopi) + $sat->tle->revnum - 1;
554
+        $sat->orbit = floor(($sat->tle->xno*self::xmnpda/self::twopi +
555
+                        $age*$sat->tle->bstar*self::ae)*$age +
556
+                        $sat->tle->xmo/self::twopi) + $sat->tle->revnum - 1;
557 557
     }
558 558
 
559 559
     /** Find the LOS time of the next pass.
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         /* check whether satellite has aos */
586 586
         if (($sat->otype == Predict_SGPSDP::ORBIT_TYPE_GEO) ||
587 587
             ($sat->otype == Predict_SGPSDP::ORBIT_TYPE_DECAYED) ||
588
-            !$this->has_aos ($sat, $qth)) {
588
+            !$this->has_aos($sat, $qth)) {
589 589
 
590 590
             return 0.0;
591 591
         }
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 
608 608
             /* coarse steps */
609 609
             while (($sat->el >= 1.0) && ($t <= ($start + $maxdt))) {
610
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
610
+                $t += cos(($sat->el - 1.0)*self::de2ra)*sqrt($sat->alt)/25000.0;
611 611
                 $this->predict_calc($sat, $qth, $t);
612 612
             }
613 613
 
614 614
             /* fine steps */
615
-            while (($lostime == 0.0) && ($t <= ($start + $maxdt)))  {
615
+            while (($lostime == 0.0) && ($t <= ($start + $maxdt))) {
616 616
 
617
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
617
+                $t += $sat->el*sqrt($sat->alt)/502500.0;
618 618
                 $this->predict_calc($sat, $qth, $t);
619 619
 
620 620
                 if (abs($sat->el) < 0.005) {
@@ -626,14 +626,14 @@  discard block
 block discarded – undo
626 626
 
627 627
             /* coarse steps */
628 628
             while ($sat->el >= 1.0) {
629
-                $t += cos(($sat->el - 1.0) * self::de2ra) * sqrt($sat->alt) / 25000.0;
629
+                $t += cos(($sat->el - 1.0)*self::de2ra)*sqrt($sat->alt)/25000.0;
630 630
                 $this->predict_calc($sat, $qth, $t);
631 631
             }
632 632
 
633 633
             /* fine steps */
634 634
             while ($lostime == 0.0) {
635 635
 
636
-                $t += $sat->el * sqrt($sat->alt) / 502500.0;
636
+                $t += $sat->el*sqrt($sat->alt)/502500.0;
637 637
                 $this->predict_calc($sat, $qth, $t);
638 638
 
639 639
                 if (abs($sat->el) < 0.005)
@@ -701,10 +701,10 @@  discard block
 block discarded – undo
701 701
                 $lin = self::pi - $lin;
702 702
             }
703 703
 
704
-            $sma = 331.25 * exp(log(1440.0 / $sat->meanmo) * (2.0 / 3.0));
705
-            $apogee = $sma * (1.0 + $sat->tle->eo) - self::xkmper;
704
+            $sma = 331.25*exp(log(1440.0/$sat->meanmo)*(2.0/3.0));
705
+            $apogee = $sma*(1.0 + $sat->tle->eo) - self::xkmper;
706 706
 
707
-            if ((acos(self::xkmper / ($apogee + self::xkmper)) + ($lin)) > abs($qth->lat * self::de2ra)) {
707
+            if ((acos(self::xkmper/($apogee + self::xkmper)) + ($lin)) > abs($qth->lat*self::de2ra)) {
708 708
                 $retcode = true;
709 709
             } else {
710 710
                 $retcode = false;
@@ -866,10 +866,10 @@  discard block
 block discarded – undo
866 866
      */
867 867
     public function azDegreesToDirection($az = 0)
868 868
     {
869
-        $i = floor($az / 22.5);
870
-        $m = (22.5 * (2 * $i + 1)) / 2;
869
+        $i = floor($az/22.5);
870
+        $m = (22.5*(2*$i + 1))/2;
871 871
         $i = ($az >= $m) ? $i + 1 : $i;
872 872
 
873
-        return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i * 3, 3));
873
+        return trim(substr('N  NNENE ENEE  ESESE SSES  SSWSW WSWW  WNWNW NNWN  ', $i*3, 3));
874 874
     }
875 875
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -636,8 +636,9 @@
 block discarded – undo
636 636
                 $t += $sat->el * sqrt($sat->alt) / 502500.0;
637 637
                 $this->predict_calc($sat, $qth, $t);
638 638
 
639
-                if (abs($sat->el) < 0.005)
640
-                    $lostime = $t;
639
+                if (abs($sat->el) < 0.005) {
640
+                                    $lostime = $t;
641
+                }
641 642
             }
642 643
         }
643 644
 
Please login to merge, or discard this patch.
require/libs/Predict/Predict/Math.php 3 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -42,6 +42,10 @@  discard block
 block discarded – undo
42 42
     }
43 43
 
44 44
     /* Returns arccosine of rgument */
45
+
46
+    /**
47
+     * @param double $arg
48
+     */
45 49
     public static function ArcCos($arg)
46 50
     {
47 51
         return Predict::pio2 - self::ArcSin($arg);
@@ -68,6 +72,10 @@  discard block
 block discarded – undo
68 72
     }
69 73
 
70 74
     /* Multiplies the vector v1 by the scalar k to produce the vector v2 */
75
+
76
+    /**
77
+     * @param integer $k
78
+     */
71 79
     public static function Scalar_Multiply($k, Predict_Vector $v1, Predict_Vector $v2)
72 80
     {
73 81
         $v2->x = $k * $v1->x;
@@ -155,6 +163,10 @@  discard block
 block discarded – undo
155 163
     }
156 164
 
157 165
     /* Returns arg1 mod arg2 */
166
+
167
+    /**
168
+     * @param double $arg1
169
+     */
158 170
     public static function Modulus($arg1, $arg2)
159 171
     {
160 172
         $ret_val  = $arg1;
@@ -169,6 +181,10 @@  discard block
 block discarded – undo
169 181
     }
170 182
 
171 183
     /* Returns fractional part of double argument */
184
+
185
+    /**
186
+     * @param double $arg
187
+     */
172 188
     public static function Frac($arg)
173 189
     {
174 190
         return $arg - floor($arg);
Please login to merge, or discard this patch.
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -19,178 +19,178 @@
 block discarded – undo
19 19
  */
20 20
 class Predict_Math
21 21
 {
22
-    /* Returns sign of a float */
23
-    public static function Sign($arg)
24
-    {
25
-        if ($arg > 0 ) {
26
-            return 1;
27
-        } else if ($arg < 0 ) {
28
-            return -1;
29
-        } else {
30
-            return 0;
31
-        }
32
-    }
33
-
34
-    /* Returns the arcsine of the argument */
35
-    public static function ArcSin($arg)
36
-    {
37
-        if (abs($arg) >= 1 ) {
38
-            return (self::Sign($arg) * Predict::pio2);
39
-        } else {
40
-            return(atan($arg / sqrt(1 - $arg * $arg)));
41
-        }
42
-    }
43
-
44
-    /* Returns arccosine of rgument */
45
-    public static function ArcCos($arg)
46
-    {
47
-        return Predict::pio2 - self::ArcSin($arg);
48
-    }
49
-
50
-    /* Adds vectors v1 and v2 together to produce v3 */
51
-    public static function Vec_Add(Predict_Vector $v1, Predict_Vector $v2, Predict_Vector $v3)
52
-    {
53
-        $v3->x = $v1->x + $v2->x;
54
-        $v3->y = $v1->y + $v2->y;
55
-        $v3->z = $v1->z + $v2->z;
56
-
57
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
58
-    }
59
-
60
-    /* Subtracts vector v2 from v1 to produce v3 */
61
-    public static function Vec_Sub(Predict_Vector $v1, Predict_Vector $v2, Predict_Vector $v3)
62
-    {
63
-        $v3->x = $v1->x - $v2->x;
64
-        $v3->y = $v1->y - $v2->y;
65
-        $v3->z = $v1->z - $v2->z;
66
-
67
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
68
-    }
69
-
70
-    /* Multiplies the vector v1 by the scalar k to produce the vector v2 */
71
-    public static function Scalar_Multiply($k, Predict_Vector $v1, Predict_Vector $v2)
72
-    {
73
-        $v2->x = $k * $v1->x;
74
-        $v2->y = $k * $v1->y;
75
-        $v2->z = $k * $v1->z;
76
-        $v2->w = abs($k) * $v1->w;
77
-    }
78
-
79
-    /* Multiplies the vector v1 by the scalar k */
80
-    public static function Scale_Vector($k, Predict_Vector $v)
81
-    {
82
-        $v->x *= $k;
83
-        $v->y *= $k;
84
-        $v->z *= $k;
85
-
86
-        $v->w = sqrt($v->x * $v->x + $v->y * $v->y + $v->z * $v->z);
87
-    }
88
-
89
-    /* Returns the dot product of two vectors */
90
-    public static function Dot(Predict_Vector $v1, Predict_Vector $v2)
91
-    {
92
-        return ($v1->x * $v2->x + $v1->y * $v2->y + $v1->z * $v2->z);
93
-    }
94
-
95
-    /* Calculates the angle between vectors v1 and v2 */
96
-    public static function Angle(Predict_Vector $v1, Predict_Vector $v2)
97
-    {
98
-        $v1->w = sqrt($v1->x * $v1->x + $v1->y * $v1->y + $v1->z * $v1->z);
99
-        $v2->w = sqrt($v2->x * $v2->x + $v2->y * $v2->y + $v2->z * $v2->z);
100
-        return (self::ArcCos(self::Dot($v1, $v2) / ($v1->w * $v2->w)));
101
-    }
102
-
103
-    /* Produces cross product of v1 and v2, and returns in v3 */
104
-    public static function Cross(Predict_Vector $v1, Predict_Vector $v2 ,Predict_Vector $v3)
105
-    {
106
-        $v3->x = $v1->y * $v2->z - $v1->z * $v2->y;
107
-        $v3->y = $v1->z * $v2->x - $v1->x * $v2->z;
108
-        $v3->z = $v1->x * $v2->y - $v1->y * $v2->x;
109
-
110
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
111
-    }
112
-
113
-    /* Normalizes a vector */
114
-    public static function Normalize(Predict_Vector $v )
115
-    {
116
-        $v->x /= $v->w;
117
-        $v->y /= $v->w;
118
-        $v->z /= $v->w;
119
-    }
120
-
121
-    /* Four-quadrant arctan function */
122
-    public static function AcTan($sinx, $cosx)
123
-    {
124
-        if ($cosx == 0) {
125
-            if ($sinx > 0) {
126
-                return Predict::pio2;
127
-            } else {
128
-                return Predict::x3pio2;
129
-            }
130
-        } else {
131
-            if ($cosx > 0) {
132
-                if ($sinx > 0) {
133
-                    return atan($sinx / $cosx);
134
-                } else {
135
-                    return Predict::twopi + atan($sinx / $cosx);
136
-                }
137
-            } else {
138
-                return Predict::pi + atan($sinx / $cosx);
139
-            }
140
-        }
141
-    }
142
-
143
-    /* Returns mod 2pi of argument */
144
-    public static function FMod2p($x)
145
-    {
146
-        $ret_val  = $x;
147
-        $i        = (int) ($ret_val / Predict::twopi);
148
-        $ret_val -= $i * Predict::twopi;
149
-
150
-        if ($ret_val < 0) {
151
-            $ret_val += Predict::twopi;
152
-        }
153
-
154
-        return $ret_val;
155
-    }
156
-
157
-    /* Returns arg1 mod arg2 */
158
-    public static function Modulus($arg1, $arg2)
159
-    {
160
-        $ret_val  = $arg1;
161
-        $i        = (int) ($ret_val / $arg2);
162
-        $ret_val -= $i * $arg2;
163
-
164
-        if ($ret_val < 0) {
165
-            $ret_val += $arg2;
166
-        }
167
-
168
-        return $ret_val;
169
-    }
170
-
171
-    /* Returns fractional part of double argument */
172
-    public static function Frac($arg)
173
-    {
174
-        return $arg - floor($arg);
175
-    }
176
-
177
-    /* Converts the satellite's position and velocity  */
178
-    /* vectors from normalised values to km and km/sec */
179
-    public static function Convert_Sat_State(Predict_Vector $pos, Predict_Vector $vel)
180
-    {
181
-        self::Scale_Vector(Predict::xkmper, $pos);
182
-        self::Scale_Vector(Predict::xkmper * Predict::xmnpda / Predict::secday, $vel);
183
-    }
184
-
185
-    /* Returns angle in radians from arg in degrees */
186
-    public static function Radians($arg)
187
-    {
188
-        return $arg * Predict::de2ra;
189
-    }
190
-
191
-    /* Returns angle in degrees from arg in rads */
192
-    public static function Degrees($arg)
193
-    {
194
-      return $arg / Predict::de2ra;
195
-    }
22
+	/* Returns sign of a float */
23
+	public static function Sign($arg)
24
+	{
25
+		if ($arg > 0 ) {
26
+			return 1;
27
+		} else if ($arg < 0 ) {
28
+			return -1;
29
+		} else {
30
+			return 0;
31
+		}
32
+	}
33
+
34
+	/* Returns the arcsine of the argument */
35
+	public static function ArcSin($arg)
36
+	{
37
+		if (abs($arg) >= 1 ) {
38
+			return (self::Sign($arg) * Predict::pio2);
39
+		} else {
40
+			return(atan($arg / sqrt(1 - $arg * $arg)));
41
+		}
42
+	}
43
+
44
+	/* Returns arccosine of rgument */
45
+	public static function ArcCos($arg)
46
+	{
47
+		return Predict::pio2 - self::ArcSin($arg);
48
+	}
49
+
50
+	/* Adds vectors v1 and v2 together to produce v3 */
51
+	public static function Vec_Add(Predict_Vector $v1, Predict_Vector $v2, Predict_Vector $v3)
52
+	{
53
+		$v3->x = $v1->x + $v2->x;
54
+		$v3->y = $v1->y + $v2->y;
55
+		$v3->z = $v1->z + $v2->z;
56
+
57
+		$v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
58
+	}
59
+
60
+	/* Subtracts vector v2 from v1 to produce v3 */
61
+	public static function Vec_Sub(Predict_Vector $v1, Predict_Vector $v2, Predict_Vector $v3)
62
+	{
63
+		$v3->x = $v1->x - $v2->x;
64
+		$v3->y = $v1->y - $v2->y;
65
+		$v3->z = $v1->z - $v2->z;
66
+
67
+		$v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
68
+	}
69
+
70
+	/* Multiplies the vector v1 by the scalar k to produce the vector v2 */
71
+	public static function Scalar_Multiply($k, Predict_Vector $v1, Predict_Vector $v2)
72
+	{
73
+		$v2->x = $k * $v1->x;
74
+		$v2->y = $k * $v1->y;
75
+		$v2->z = $k * $v1->z;
76
+		$v2->w = abs($k) * $v1->w;
77
+	}
78
+
79
+	/* Multiplies the vector v1 by the scalar k */
80
+	public static function Scale_Vector($k, Predict_Vector $v)
81
+	{
82
+		$v->x *= $k;
83
+		$v->y *= $k;
84
+		$v->z *= $k;
85
+
86
+		$v->w = sqrt($v->x * $v->x + $v->y * $v->y + $v->z * $v->z);
87
+	}
88
+
89
+	/* Returns the dot product of two vectors */
90
+	public static function Dot(Predict_Vector $v1, Predict_Vector $v2)
91
+	{
92
+		return ($v1->x * $v2->x + $v1->y * $v2->y + $v1->z * $v2->z);
93
+	}
94
+
95
+	/* Calculates the angle between vectors v1 and v2 */
96
+	public static function Angle(Predict_Vector $v1, Predict_Vector $v2)
97
+	{
98
+		$v1->w = sqrt($v1->x * $v1->x + $v1->y * $v1->y + $v1->z * $v1->z);
99
+		$v2->w = sqrt($v2->x * $v2->x + $v2->y * $v2->y + $v2->z * $v2->z);
100
+		return (self::ArcCos(self::Dot($v1, $v2) / ($v1->w * $v2->w)));
101
+	}
102
+
103
+	/* Produces cross product of v1 and v2, and returns in v3 */
104
+	public static function Cross(Predict_Vector $v1, Predict_Vector $v2 ,Predict_Vector $v3)
105
+	{
106
+		$v3->x = $v1->y * $v2->z - $v1->z * $v2->y;
107
+		$v3->y = $v1->z * $v2->x - $v1->x * $v2->z;
108
+		$v3->z = $v1->x * $v2->y - $v1->y * $v2->x;
109
+
110
+		$v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
111
+	}
112
+
113
+	/* Normalizes a vector */
114
+	public static function Normalize(Predict_Vector $v )
115
+	{
116
+		$v->x /= $v->w;
117
+		$v->y /= $v->w;
118
+		$v->z /= $v->w;
119
+	}
120
+
121
+	/* Four-quadrant arctan function */
122
+	public static function AcTan($sinx, $cosx)
123
+	{
124
+		if ($cosx == 0) {
125
+			if ($sinx > 0) {
126
+				return Predict::pio2;
127
+			} else {
128
+				return Predict::x3pio2;
129
+			}
130
+		} else {
131
+			if ($cosx > 0) {
132
+				if ($sinx > 0) {
133
+					return atan($sinx / $cosx);
134
+				} else {
135
+					return Predict::twopi + atan($sinx / $cosx);
136
+				}
137
+			} else {
138
+				return Predict::pi + atan($sinx / $cosx);
139
+			}
140
+		}
141
+	}
142
+
143
+	/* Returns mod 2pi of argument */
144
+	public static function FMod2p($x)
145
+	{
146
+		$ret_val  = $x;
147
+		$i        = (int) ($ret_val / Predict::twopi);
148
+		$ret_val -= $i * Predict::twopi;
149
+
150
+		if ($ret_val < 0) {
151
+			$ret_val += Predict::twopi;
152
+		}
153
+
154
+		return $ret_val;
155
+	}
156
+
157
+	/* Returns arg1 mod arg2 */
158
+	public static function Modulus($arg1, $arg2)
159
+	{
160
+		$ret_val  = $arg1;
161
+		$i        = (int) ($ret_val / $arg2);
162
+		$ret_val -= $i * $arg2;
163
+
164
+		if ($ret_val < 0) {
165
+			$ret_val += $arg2;
166
+		}
167
+
168
+		return $ret_val;
169
+	}
170
+
171
+	/* Returns fractional part of double argument */
172
+	public static function Frac($arg)
173
+	{
174
+		return $arg - floor($arg);
175
+	}
176
+
177
+	/* Converts the satellite's position and velocity  */
178
+	/* vectors from normalised values to km and km/sec */
179
+	public static function Convert_Sat_State(Predict_Vector $pos, Predict_Vector $vel)
180
+	{
181
+		self::Scale_Vector(Predict::xkmper, $pos);
182
+		self::Scale_Vector(Predict::xkmper * Predict::xmnpda / Predict::secday, $vel);
183
+	}
184
+
185
+	/* Returns angle in radians from arg in degrees */
186
+	public static function Radians($arg)
187
+	{
188
+		return $arg * Predict::de2ra;
189
+	}
190
+
191
+	/* Returns angle in degrees from arg in rads */
192
+	public static function Degrees($arg)
193
+	{
194
+	  return $arg / Predict::de2ra;
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
     /* Returns sign of a float */
23 23
     public static function Sign($arg)
24 24
     {
25
-        if ($arg > 0 ) {
25
+        if ($arg > 0) {
26 26
             return 1;
27
-        } else if ($arg < 0 ) {
27
+        } else if ($arg < 0) {
28 28
             return -1;
29 29
         } else {
30 30
             return 0;
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
     /* Returns the arcsine of the argument */
35 35
     public static function ArcSin($arg)
36 36
     {
37
-        if (abs($arg) >= 1 ) {
38
-            return (self::Sign($arg) * Predict::pio2);
37
+        if (abs($arg) >= 1) {
38
+            return (self::Sign($arg)*Predict::pio2);
39 39
         } else {
40
-            return(atan($arg / sqrt(1 - $arg * $arg)));
40
+            return(atan($arg/sqrt(1 - $arg*$arg)));
41 41
         }
42 42
     }
43 43
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         $v3->y = $v1->y + $v2->y;
55 55
         $v3->z = $v1->z + $v2->z;
56 56
 
57
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
57
+        $v3->w = sqrt($v3->x*$v3->x + $v3->y*$v3->y + $v3->z*$v3->z);
58 58
     }
59 59
 
60 60
     /* Subtracts vector v2 from v1 to produce v3 */
@@ -64,16 +64,16 @@  discard block
 block discarded – undo
64 64
         $v3->y = $v1->y - $v2->y;
65 65
         $v3->z = $v1->z - $v2->z;
66 66
 
67
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
67
+        $v3->w = sqrt($v3->x*$v3->x + $v3->y*$v3->y + $v3->z*$v3->z);
68 68
     }
69 69
 
70 70
     /* Multiplies the vector v1 by the scalar k to produce the vector v2 */
71 71
     public static function Scalar_Multiply($k, Predict_Vector $v1, Predict_Vector $v2)
72 72
     {
73
-        $v2->x = $k * $v1->x;
74
-        $v2->y = $k * $v1->y;
75
-        $v2->z = $k * $v1->z;
76
-        $v2->w = abs($k) * $v1->w;
73
+        $v2->x = $k*$v1->x;
74
+        $v2->y = $k*$v1->y;
75
+        $v2->z = $k*$v1->z;
76
+        $v2->w = abs($k)*$v1->w;
77 77
     }
78 78
 
79 79
     /* Multiplies the vector v1 by the scalar k */
@@ -83,35 +83,35 @@  discard block
 block discarded – undo
83 83
         $v->y *= $k;
84 84
         $v->z *= $k;
85 85
 
86
-        $v->w = sqrt($v->x * $v->x + $v->y * $v->y + $v->z * $v->z);
86
+        $v->w = sqrt($v->x*$v->x + $v->y*$v->y + $v->z*$v->z);
87 87
     }
88 88
 
89 89
     /* Returns the dot product of two vectors */
90 90
     public static function Dot(Predict_Vector $v1, Predict_Vector $v2)
91 91
     {
92
-        return ($v1->x * $v2->x + $v1->y * $v2->y + $v1->z * $v2->z);
92
+        return ($v1->x*$v2->x + $v1->y*$v2->y + $v1->z*$v2->z);
93 93
     }
94 94
 
95 95
     /* Calculates the angle between vectors v1 and v2 */
96 96
     public static function Angle(Predict_Vector $v1, Predict_Vector $v2)
97 97
     {
98
-        $v1->w = sqrt($v1->x * $v1->x + $v1->y * $v1->y + $v1->z * $v1->z);
99
-        $v2->w = sqrt($v2->x * $v2->x + $v2->y * $v2->y + $v2->z * $v2->z);
100
-        return (self::ArcCos(self::Dot($v1, $v2) / ($v1->w * $v2->w)));
98
+        $v1->w = sqrt($v1->x*$v1->x + $v1->y*$v1->y + $v1->z*$v1->z);
99
+        $v2->w = sqrt($v2->x*$v2->x + $v2->y*$v2->y + $v2->z*$v2->z);
100
+        return (self::ArcCos(self::Dot($v1, $v2)/($v1->w*$v2->w)));
101 101
     }
102 102
 
103 103
     /* Produces cross product of v1 and v2, and returns in v3 */
104
-    public static function Cross(Predict_Vector $v1, Predict_Vector $v2 ,Predict_Vector $v3)
104
+    public static function Cross(Predict_Vector $v1, Predict_Vector $v2, Predict_Vector $v3)
105 105
     {
106
-        $v3->x = $v1->y * $v2->z - $v1->z * $v2->y;
107
-        $v3->y = $v1->z * $v2->x - $v1->x * $v2->z;
108
-        $v3->z = $v1->x * $v2->y - $v1->y * $v2->x;
106
+        $v3->x = $v1->y*$v2->z - $v1->z*$v2->y;
107
+        $v3->y = $v1->z*$v2->x - $v1->x*$v2->z;
108
+        $v3->z = $v1->x*$v2->y - $v1->y*$v2->x;
109 109
 
110
-        $v3->w = sqrt($v3->x * $v3->x + $v3->y * $v3->y + $v3->z * $v3->z);
110
+        $v3->w = sqrt($v3->x*$v3->x + $v3->y*$v3->y + $v3->z*$v3->z);
111 111
     }
112 112
 
113 113
     /* Normalizes a vector */
114
-    public static function Normalize(Predict_Vector $v )
114
+    public static function Normalize(Predict_Vector $v)
115 115
     {
116 116
         $v->x /= $v->w;
117 117
         $v->y /= $v->w;
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
         } else {
131 131
             if ($cosx > 0) {
132 132
                 if ($sinx > 0) {
133
-                    return atan($sinx / $cosx);
133
+                    return atan($sinx/$cosx);
134 134
                 } else {
135
-                    return Predict::twopi + atan($sinx / $cosx);
135
+                    return Predict::twopi + atan($sinx/$cosx);
136 136
                 }
137 137
             } else {
138
-                return Predict::pi + atan($sinx / $cosx);
138
+                return Predict::pi + atan($sinx/$cosx);
139 139
             }
140 140
         }
141 141
     }
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
     public static function FMod2p($x)
145 145
     {
146 146
         $ret_val  = $x;
147
-        $i        = (int) ($ret_val / Predict::twopi);
148
-        $ret_val -= $i * Predict::twopi;
147
+        $i        = (int) ($ret_val/Predict::twopi);
148
+        $ret_val -= $i*Predict::twopi;
149 149
 
150 150
         if ($ret_val < 0) {
151 151
             $ret_val += Predict::twopi;
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
     public static function Modulus($arg1, $arg2)
159 159
     {
160 160
         $ret_val  = $arg1;
161
-        $i        = (int) ($ret_val / $arg2);
162
-        $ret_val -= $i * $arg2;
161
+        $i        = (int) ($ret_val/$arg2);
162
+        $ret_val -= $i*$arg2;
163 163
 
164 164
         if ($ret_val < 0) {
165 165
             $ret_val += $arg2;
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
     public static function Convert_Sat_State(Predict_Vector $pos, Predict_Vector $vel)
180 180
     {
181 181
         self::Scale_Vector(Predict::xkmper, $pos);
182
-        self::Scale_Vector(Predict::xkmper * Predict::xmnpda / Predict::secday, $vel);
182
+        self::Scale_Vector(Predict::xkmper*Predict::xmnpda/Predict::secday, $vel);
183 183
     }
184 184
 
185 185
     /* Returns angle in radians from arg in degrees */
186 186
     public static function Radians($arg)
187 187
     {
188
-        return $arg * Predict::de2ra;
188
+        return $arg*Predict::de2ra;
189 189
     }
190 190
 
191 191
     /* Returns angle in degrees from arg in rads */
192 192
     public static function Degrees($arg)
193 193
     {
194
-      return $arg / Predict::de2ra;
194
+      return $arg/Predict::de2ra;
195 195
     }
196 196
 }
Please login to merge, or discard this patch.
require/libs/Predict/Predict/Sat.php 4 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     /** Initialise satellite data.
127
-     *  @param sat The satellite to initialise.
128
-     *  @param qth Optional QTH info, use (0,0) if NULL.
127
+     *  @param sat Predict_Sat satellite to initialise.
128
+     *  @param qth Predict_QTH QTH info, use (0,0) if NULL.
129 129
      *
130 130
      * This function calculates the satellite data at t = 0, ie. epoch time
131 131
      * The function is called automatically by gtk_sat_data_read_sat.
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 
217 217
     /** Determinte whether satellite is in geostationary orbit.
218 218
      *  @author John A. Magliacane, KD2BD
219
-     *  @param sat Pointer to satellite data.
220
-     *  @return TRUE if the satellite appears to be in geostationary orbit,
219
+     *  @param sat Predict_Sat to satellite data.
220
+     *  @return boolean if the satellite appears to be in geostationary orbit,
221 221
      *          FALSE otherwise.
222 222
      *
223 223
      * A satellite is in geostationary orbit if
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
     /** Determine whether satellite has decayed.
240 240
      *  @author John A. Magliacane, KD2BD
241 241
      *  @author Alexandru Csete, OZ9AEC
242
-     *  @param sat Pointer to satellite data.
243
-     *  @return TRUE if the satellite appears to have decayed, FALSE otherwise.
242
+     *  @param sat Predict_Sat to satellite data.
243
+     *  @return boolean if the satellite appears to have decayed, FALSE otherwise.
244 244
      *  @bug Modified version of the predict code but it is not tested.
245 245
      *
246 246
      * A satellite is decayed if
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * @param float       $time The daynum the satellite is calculated for
274 274
      * @param Predict_QTH $qth  The observer location
275 275
      *
276
-     * @return null on failure, float otherwise
276
+     * @return null|double on failure, float otherwise
277 277
      */
278 278
     public function calculateApparentMagnitude($time, Predict_QTH $qth)
279 279
     {
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -22,304 +22,304 @@
 block discarded – undo
22 22
  */
23 23
 class Predict_Sat
24 24
 {
25
-    // Fifth root of a hundred, used for magnitude calculation
26
-    const POGSONS_RATIO = 2.5118864315096;
27
-
28
-    public $name     = null;
29
-    public $nickname = null;
30
-    public $website  = null;
31
-
32
-    public $tle      = null;   /*!< Keplerian elements */
33
-    public $flags    = 0;      /*!< Flags for algo ctrl */
34
-    public $sgps     = null;
35
-    public $dps      = null;
36
-    public $deep_arg = null;
37
-    public $pos      = null;   /*!< Raw position and range */
38
-    public $vel      = null;   /*!< Raw velocity */
39
-
40
-    /*** FIXME: REMOVE */
41
-    public $bearing = null;   /*!< Az, El, range and vel */
42
-    public $astro   = null;   /*!< Ra and Decl */
43
-    /*** END */
44
-
45
-    /* time keeping fields */
46
-    public $jul_epoch = null;
47
-    public $jul_utc   = null;
48
-    public $tsince    = null;
49
-    public $aos       = null;    /*!< Next AOS. */
50
-    public $los       = null;    /*!< Next LOS */
51
-
52
-    public $az         = null;   /*!< Azimuth [deg] */
53
-    public $el         = null;   /*!< Elevation [deg] */
54
-    public $range      = null;   /*!< Range [km] */
55
-    public $range_rate = null;   /*!< Range Rate [km/sec] */
56
-    public $ra         = null;   /*!< Right Ascension [deg] */
57
-    public $dec        = null;   /*!< Declination [deg] */
58
-    public $ssplat     = null;   /*!< SSP latitude [deg] */
59
-    public $ssplon     = null;   /*!< SSP longitude [deg] */
60
-    public $alt        = null;   /*!< altitude [km] */
61
-    public $velo       = null;   /*!< velocity [km/s] */
62
-    public $ma         = null;   /*!< mean anomaly */
63
-    public $footprint  = null;   /*!< footprint */
64
-    public $phase      = null;   /*!< orbit phase */
65
-    public $meanmo     = null;   /*!< mean motion kept in rev/day */
66
-    public $orbit      = null;   /*!< orbit number */
67
-    public $otype      = null;   /*!< orbit type. */
68
-
69
-    public function __construct(Predict_TLE $tle)
70
-    {
71
-        $headerParts    = explode(' ', $tle->header);
72
-        $this->name     = $headerParts[0];
73
-        $this->nickname = $this->name;
74
-        $this->tle      = $tle;
75
-        $this->pos      = new Predict_Vector();
76
-        $this->vel      = new Predict_Vector();
77
-        $this->sgps     = new Predict_SGSDPStatic();
78
-        $this->deep_arg = new Predict_DeepArg();
79
-        $this->dps      = new Predict_DeepStatic();
80
-
81
-        $this->select_ephemeris();
82
-        $this->sat_data_init_sat($this);
83
-    }
84
-
85
-    /* Selects the apropriate ephemeris type to be used */
86
-    /* for predictions according to the data in the TLE */
87
-    /* It also processes values in the tle set so that  */
88
-    /* they are apropriate for the sgp4/sdp4 routines   */
89
-    public function select_ephemeris()
90
-    {
91
-        /* Preprocess tle set */
92
-        $this->tle->xnodeo *= Predict::de2ra;
93
-        $this->tle->omegao *= Predict::de2ra;
94
-        $this->tle->xmo    *= Predict::de2ra;
95
-        $this->tle->xincl  *= Predict::de2ra;
96
-        $temp = Predict::twopi / Predict::xmnpda / Predict::xmnpda;
97
-
98
-        /* store mean motion before conversion */
99
-        $this->meanmo       = $this->tle->xno;
100
-        $this->tle->xno     = $this->tle->xno * $temp * Predict::xmnpda;
101
-        $this->tle->xndt2o *= $temp;
102
-        $this->tle->xndd6o  = $this->tle->xndd6o * $temp / Predict::xmnpda;
103
-        $this->tle->bstar  /= Predict::ae;
104
-
105
-        /* Period > 225 minutes is deep space */
106
-        $dd1 = Predict::xke / $this->tle->xno;
107
-        $dd2 = Predict::tothrd;
108
-        $a1 = pow($dd1, $dd2);
109
-        $r1 = cos($this->tle->xincl);
110
-        $dd1 = 1.0 - $this->tle->eo * $this->tle->eo;
111
-        $temp = Predict::ck2 * 1.5 * ($r1 * $r1 * 3.0 - 1.0) / pow($dd1, 1.5);
112
-        $del1 = $temp / ($a1 * $a1);
113
-        $ao = $a1 * (1.0 - $del1 * (Predict::tothrd * 0.5 + $del1 *
114
-                                 ($del1 * 1.654320987654321 + 1.0)));
115
-        $delo = $temp / ($ao * $ao);
116
-        $xnodp = $this->tle->xno / ($delo + 1.0);
117
-
118
-        /* Select a deep-space/near-earth ephemeris */
119
-        if (Predict::twopi / $xnodp / Predict::xmnpda >= .15625) {
120
-            $this->flags |= Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
121
-        } else {
122
-            $this->flags &= ~Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
123
-        }
124
-    }
125
-
126
-    /** Initialise satellite data.
127
-     *  @param sat The satellite to initialise.
128
-     *  @param qth Optional QTH info, use (0,0) if NULL.
129
-     *
130
-     * This function calculates the satellite data at t = 0, ie. epoch time
131
-     * The function is called automatically by gtk_sat_data_read_sat.
132
-     */
133
-    public function sat_data_init_sat(Predict_Sat $sat, Predict_QTH $qth = null)
134
-    {
135
-        $obs_geodetic = new Predict_Geodetic();
136
-        $obs_set = new Predict_ObsSet();
137
-        $sat_geodetic = new Predict_Geodetic();
138
-        /* double jul_utc, age; */
139
-
140
-        $jul_utc = Predict_Time::Julian_Date_of_Epoch($sat->tle->epoch); // => tsince = 0.0
141
-        $sat->jul_epoch = $jul_utc;
142
-
143
-        /* initialise observer location */
144
-        if ($qth != null) {
145
-            $obs_geodetic->lon = $qth->lon * Predict::de2ra;
146
-            $obs_geodetic->lat = $qth->lat * Predict::de2ra;
147
-            $obs_geodetic->alt = $qth->alt / 1000.0;
148
-            $obs_geodetic->theta = 0;
149
-        }
150
-        else {
151
-            $obs_geodetic->lon = 0.0;
152
-            $obs_geodetic->lat = 0.0;
153
-            $obs_geodetic->alt = 0.0;
154
-            $obs_geodetic->theta = 0;
155
-        }
156
-
157
-        /* execute computations */
158
-        $sdpsgp = Predict_SGPSDP::getInstance($sat);
159
-        if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
160
-            $sdpsgp->SDP4($sat, 0.0);
161
-        } else {
162
-            $sdpsgp->SGP4($sat, 0.0);
163
-        }
164
-
165
-        /* scale position and velocity to km and km/sec */
166
-        Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
167
-
168
-        /* get the velocity of the satellite */
169
-        $sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
170
-        $sat->velo = $sat->vel->w;
171
-        Predict_SGPObs::Calculate_Obs($jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
172
-        Predict_SGPObs::Calculate_LatLonAlt($jul_utc, $sat->pos, $sat_geodetic);
173
-
174
-        while ($sat_geodetic->lon < -Predict::pi) {
175
-            $sat_geodetic->lon += Predict::twopi;
176
-        }
177
-
178
-        while ($sat_geodetic->lon > Predict::pi) {
179
-            $sat_geodetic->lon -= Predict::twopi;
180
-        }
181
-
182
-        $sat->az = Predict_Math::Degrees($obs_set->az);
183
-        $sat->el = Predict_Math::Degrees($obs_set->el);
184
-        $sat->range = $obs_set->range;
185
-        $sat->range_rate = $obs_set->range_rate;
186
-        $sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
187
-        $sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
188
-        $sat->alt = $sat_geodetic->alt;
189
-        $sat->ma = Predict_Math::Degrees($sat->phase);
190
-        $sat->ma *= 256.0 / 360.0;
191
-        $sat->footprint = 2.0 * Predict::xkmper * acos (Predict::xkmper/$sat->pos->w);
192
-        $age = 0.0;
193
-        $sat->orbit = floor(($sat->tle->xno * Predict::xmnpda / Predict::twopi +
194
-                                   $age * $sat->tle->bstar * Predict::ae) * $age +
195
-                                  $sat->tle->xmo / Predict::twopi) + $sat->tle->revnum - 1;
196
-
197
-        /* orbit type */
198
-        $sat->otype = $sat->get_orbit_type($sat);
199
-    }
200
-
201
-    public function get_orbit_type(Predict_Sat $sat)
202
-    {
203
-         $orbit = Predict_SGPSDP::ORBIT_TYPE_UNKNOWN;
204
-
205
-         if ($this->geostationary($sat)) {
206
-              $orbit = Predict_SGPSDP::ORBIT_TYPE_GEO;
207
-         } else if ($this->decayed($sat)) {
208
-              $orbit = Predict_SGPSDP::ORBIT_TYPE_DECAYED;
209
-         } else {
210
-              $orbit = Predict_SGPSDP::ORBIT_TYPE_UNKNOWN;
211
-         }
212
-
213
-         return $orbit;
214
-    }
215
-
216
-
217
-    /** Determinte whether satellite is in geostationary orbit.
218
-     *  @author John A. Magliacane, KD2BD
219
-     *  @param sat Pointer to satellite data.
220
-     *  @return TRUE if the satellite appears to be in geostationary orbit,
221
-     *          FALSE otherwise.
222
-     *
223
-     * A satellite is in geostationary orbit if
224
-     *
225
-     *     fabs (sat.meanmotion - 1.0027) < 0.0002
226
-     *
227
-     * Note: Appearantly, the mean motion can deviate much more from 1.0027 than 0.0002
228
-     */
229
-    public function geostationary(Predict_Sat $sat)
230
-    {
231
-         if (abs($sat->meanmo - 1.0027) < 0.0002) {
232
-              return true;
233
-         } else {
234
-              return false;
235
-        }
236
-    }
237
-
238
-
239
-    /** Determine whether satellite has decayed.
240
-     *  @author John A. Magliacane, KD2BD
241
-     *  @author Alexandru Csete, OZ9AEC
242
-     *  @param sat Pointer to satellite data.
243
-     *  @return TRUE if the satellite appears to have decayed, FALSE otherwise.
244
-     *  @bug Modified version of the predict code but it is not tested.
245
-     *
246
-     * A satellite is decayed if
247
-     *
248
-     *    satepoch + ((16.666666 - sat.meanmo) / (10.0*fabs(sat.drag))) < "now"
249
-     *
250
-     */
251
-    public function decayed(Predict_Sat $sat)
252
-    {
253
-        /* tle.xndt2o/(twopi/xmnpda/xmnpda) is the value before converted the
25
+	// Fifth root of a hundred, used for magnitude calculation
26
+	const POGSONS_RATIO = 2.5118864315096;
27
+
28
+	public $name     = null;
29
+	public $nickname = null;
30
+	public $website  = null;
31
+
32
+	public $tle      = null;   /*!< Keplerian elements */
33
+	public $flags    = 0;      /*!< Flags for algo ctrl */
34
+	public $sgps     = null;
35
+	public $dps      = null;
36
+	public $deep_arg = null;
37
+	public $pos      = null;   /*!< Raw position and range */
38
+	public $vel      = null;   /*!< Raw velocity */
39
+
40
+	/*** FIXME: REMOVE */
41
+	public $bearing = null;   /*!< Az, El, range and vel */
42
+	public $astro   = null;   /*!< Ra and Decl */
43
+	/*** END */
44
+
45
+	/* time keeping fields */
46
+	public $jul_epoch = null;
47
+	public $jul_utc   = null;
48
+	public $tsince    = null;
49
+	public $aos       = null;    /*!< Next AOS. */
50
+	public $los       = null;    /*!< Next LOS */
51
+
52
+	public $az         = null;   /*!< Azimuth [deg] */
53
+	public $el         = null;   /*!< Elevation [deg] */
54
+	public $range      = null;   /*!< Range [km] */
55
+	public $range_rate = null;   /*!< Range Rate [km/sec] */
56
+	public $ra         = null;   /*!< Right Ascension [deg] */
57
+	public $dec        = null;   /*!< Declination [deg] */
58
+	public $ssplat     = null;   /*!< SSP latitude [deg] */
59
+	public $ssplon     = null;   /*!< SSP longitude [deg] */
60
+	public $alt        = null;   /*!< altitude [km] */
61
+	public $velo       = null;   /*!< velocity [km/s] */
62
+	public $ma         = null;   /*!< mean anomaly */
63
+	public $footprint  = null;   /*!< footprint */
64
+	public $phase      = null;   /*!< orbit phase */
65
+	public $meanmo     = null;   /*!< mean motion kept in rev/day */
66
+	public $orbit      = null;   /*!< orbit number */
67
+	public $otype      = null;   /*!< orbit type. */
68
+
69
+	public function __construct(Predict_TLE $tle)
70
+	{
71
+		$headerParts    = explode(' ', $tle->header);
72
+		$this->name     = $headerParts[0];
73
+		$this->nickname = $this->name;
74
+		$this->tle      = $tle;
75
+		$this->pos      = new Predict_Vector();
76
+		$this->vel      = new Predict_Vector();
77
+		$this->sgps     = new Predict_SGSDPStatic();
78
+		$this->deep_arg = new Predict_DeepArg();
79
+		$this->dps      = new Predict_DeepStatic();
80
+
81
+		$this->select_ephemeris();
82
+		$this->sat_data_init_sat($this);
83
+	}
84
+
85
+	/* Selects the apropriate ephemeris type to be used */
86
+	/* for predictions according to the data in the TLE */
87
+	/* It also processes values in the tle set so that  */
88
+	/* they are apropriate for the sgp4/sdp4 routines   */
89
+	public function select_ephemeris()
90
+	{
91
+		/* Preprocess tle set */
92
+		$this->tle->xnodeo *= Predict::de2ra;
93
+		$this->tle->omegao *= Predict::de2ra;
94
+		$this->tle->xmo    *= Predict::de2ra;
95
+		$this->tle->xincl  *= Predict::de2ra;
96
+		$temp = Predict::twopi / Predict::xmnpda / Predict::xmnpda;
97
+
98
+		/* store mean motion before conversion */
99
+		$this->meanmo       = $this->tle->xno;
100
+		$this->tle->xno     = $this->tle->xno * $temp * Predict::xmnpda;
101
+		$this->tle->xndt2o *= $temp;
102
+		$this->tle->xndd6o  = $this->tle->xndd6o * $temp / Predict::xmnpda;
103
+		$this->tle->bstar  /= Predict::ae;
104
+
105
+		/* Period > 225 minutes is deep space */
106
+		$dd1 = Predict::xke / $this->tle->xno;
107
+		$dd2 = Predict::tothrd;
108
+		$a1 = pow($dd1, $dd2);
109
+		$r1 = cos($this->tle->xincl);
110
+		$dd1 = 1.0 - $this->tle->eo * $this->tle->eo;
111
+		$temp = Predict::ck2 * 1.5 * ($r1 * $r1 * 3.0 - 1.0) / pow($dd1, 1.5);
112
+		$del1 = $temp / ($a1 * $a1);
113
+		$ao = $a1 * (1.0 - $del1 * (Predict::tothrd * 0.5 + $del1 *
114
+								 ($del1 * 1.654320987654321 + 1.0)));
115
+		$delo = $temp / ($ao * $ao);
116
+		$xnodp = $this->tle->xno / ($delo + 1.0);
117
+
118
+		/* Select a deep-space/near-earth ephemeris */
119
+		if (Predict::twopi / $xnodp / Predict::xmnpda >= .15625) {
120
+			$this->flags |= Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
121
+		} else {
122
+			$this->flags &= ~Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
123
+		}
124
+	}
125
+
126
+	/** Initialise satellite data.
127
+	 *  @param sat The satellite to initialise.
128
+	 *  @param qth Optional QTH info, use (0,0) if NULL.
129
+	 *
130
+	 * This function calculates the satellite data at t = 0, ie. epoch time
131
+	 * The function is called automatically by gtk_sat_data_read_sat.
132
+	 */
133
+	public function sat_data_init_sat(Predict_Sat $sat, Predict_QTH $qth = null)
134
+	{
135
+		$obs_geodetic = new Predict_Geodetic();
136
+		$obs_set = new Predict_ObsSet();
137
+		$sat_geodetic = new Predict_Geodetic();
138
+		/* double jul_utc, age; */
139
+
140
+		$jul_utc = Predict_Time::Julian_Date_of_Epoch($sat->tle->epoch); // => tsince = 0.0
141
+		$sat->jul_epoch = $jul_utc;
142
+
143
+		/* initialise observer location */
144
+		if ($qth != null) {
145
+			$obs_geodetic->lon = $qth->lon * Predict::de2ra;
146
+			$obs_geodetic->lat = $qth->lat * Predict::de2ra;
147
+			$obs_geodetic->alt = $qth->alt / 1000.0;
148
+			$obs_geodetic->theta = 0;
149
+		}
150
+		else {
151
+			$obs_geodetic->lon = 0.0;
152
+			$obs_geodetic->lat = 0.0;
153
+			$obs_geodetic->alt = 0.0;
154
+			$obs_geodetic->theta = 0;
155
+		}
156
+
157
+		/* execute computations */
158
+		$sdpsgp = Predict_SGPSDP::getInstance($sat);
159
+		if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
160
+			$sdpsgp->SDP4($sat, 0.0);
161
+		} else {
162
+			$sdpsgp->SGP4($sat, 0.0);
163
+		}
164
+
165
+		/* scale position and velocity to km and km/sec */
166
+		Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
167
+
168
+		/* get the velocity of the satellite */
169
+		$sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
170
+		$sat->velo = $sat->vel->w;
171
+		Predict_SGPObs::Calculate_Obs($jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
172
+		Predict_SGPObs::Calculate_LatLonAlt($jul_utc, $sat->pos, $sat_geodetic);
173
+
174
+		while ($sat_geodetic->lon < -Predict::pi) {
175
+			$sat_geodetic->lon += Predict::twopi;
176
+		}
177
+
178
+		while ($sat_geodetic->lon > Predict::pi) {
179
+			$sat_geodetic->lon -= Predict::twopi;
180
+		}
181
+
182
+		$sat->az = Predict_Math::Degrees($obs_set->az);
183
+		$sat->el = Predict_Math::Degrees($obs_set->el);
184
+		$sat->range = $obs_set->range;
185
+		$sat->range_rate = $obs_set->range_rate;
186
+		$sat->ssplat = Predict_Math::Degrees($sat_geodetic->lat);
187
+		$sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
188
+		$sat->alt = $sat_geodetic->alt;
189
+		$sat->ma = Predict_Math::Degrees($sat->phase);
190
+		$sat->ma *= 256.0 / 360.0;
191
+		$sat->footprint = 2.0 * Predict::xkmper * acos (Predict::xkmper/$sat->pos->w);
192
+		$age = 0.0;
193
+		$sat->orbit = floor(($sat->tle->xno * Predict::xmnpda / Predict::twopi +
194
+								   $age * $sat->tle->bstar * Predict::ae) * $age +
195
+								  $sat->tle->xmo / Predict::twopi) + $sat->tle->revnum - 1;
196
+
197
+		/* orbit type */
198
+		$sat->otype = $sat->get_orbit_type($sat);
199
+	}
200
+
201
+	public function get_orbit_type(Predict_Sat $sat)
202
+	{
203
+		 $orbit = Predict_SGPSDP::ORBIT_TYPE_UNKNOWN;
204
+
205
+		 if ($this->geostationary($sat)) {
206
+			  $orbit = Predict_SGPSDP::ORBIT_TYPE_GEO;
207
+		 } else if ($this->decayed($sat)) {
208
+			  $orbit = Predict_SGPSDP::ORBIT_TYPE_DECAYED;
209
+		 } else {
210
+			  $orbit = Predict_SGPSDP::ORBIT_TYPE_UNKNOWN;
211
+		 }
212
+
213
+		 return $orbit;
214
+	}
215
+
216
+
217
+	/** Determinte whether satellite is in geostationary orbit.
218
+	 *  @author John A. Magliacane, KD2BD
219
+	 *  @param sat Pointer to satellite data.
220
+	 *  @return TRUE if the satellite appears to be in geostationary orbit,
221
+	 *          FALSE otherwise.
222
+	 *
223
+	 * A satellite is in geostationary orbit if
224
+	 *
225
+	 *     fabs (sat.meanmotion - 1.0027) < 0.0002
226
+	 *
227
+	 * Note: Appearantly, the mean motion can deviate much more from 1.0027 than 0.0002
228
+	 */
229
+	public function geostationary(Predict_Sat $sat)
230
+	{
231
+		 if (abs($sat->meanmo - 1.0027) < 0.0002) {
232
+			  return true;
233
+		 } else {
234
+			  return false;
235
+		}
236
+	}
237
+
238
+
239
+	/** Determine whether satellite has decayed.
240
+	 *  @author John A. Magliacane, KD2BD
241
+	 *  @author Alexandru Csete, OZ9AEC
242
+	 *  @param sat Pointer to satellite data.
243
+	 *  @return TRUE if the satellite appears to have decayed, FALSE otherwise.
244
+	 *  @bug Modified version of the predict code but it is not tested.
245
+	 *
246
+	 * A satellite is decayed if
247
+	 *
248
+	 *    satepoch + ((16.666666 - sat.meanmo) / (10.0*fabs(sat.drag))) < "now"
249
+	 *
250
+	 */
251
+	public function decayed(Predict_Sat $sat)
252
+	{
253
+		/* tle.xndt2o/(twopi/xmnpda/xmnpda) is the value before converted the
254 254
            value matches up with the value in predict 2.2.3 */
255
-        /*** FIXME decayed is treated as a static quantity.
255
+		/*** FIXME decayed is treated as a static quantity.
256 256
              It is time dependent. Also sat->jul_utc is often zero
257 257
              when this function is called
258 258
         ***/
259
-        if ((10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda))) == 0) {
260
-    		return true;
261
-    	} elseif ($sat->jul_epoch + ((16.666666 - $sat->meanmo) /
262
-                               (10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda)))) < $sat->jul_utc) {
263
-              return true;
264
-        } else {
265
-              return false;
266
-        }
267
-    }
268
-
269
-    /**
270
-     * Experimental attempt at calculating apparent magnitude.  Known intrinsic
271
-     * magnitudes are listed inside the function for now.
272
-     *
273
-     * @param float       $time The daynum the satellite is calculated for
274
-     * @param Predict_QTH $qth  The observer location
275
-     *
276
-     * @return null on failure, float otherwise
277
-     */
278
-    public function calculateApparentMagnitude($time, Predict_QTH $qth)
279
-    {
280
-        // Recorded intrinsic magnitudes and their respective
281
-        // illumination and distance from heavens-above.com
282
-        static $intrinsicMagnitudes = array(
283
-            '25544' => array(
284
-                'mag'      => -1.3,
285
-                'illum'    => .5,
286
-                'distance' => 1000,
287
-            )
288
-        );
289
-
290
-        // Return null if we don't have a record of the intrinsic mag
291
-        if (!isset($intrinsicMagnitudes[$this->tle->catnr])) {
292
-            return null;
293
-        }
294
-        $imag = $intrinsicMagnitudes[$this->tle->catnr];
295
-
296
-        // Convert the observer's geodetic info to radians and km so
297
-        // we can compare vectors
298
-        $observerGeo      = new Predict_Geodetic();
299
-        $observerGeo->lat = Predict_Math::Radians($qth->lat);
300
-        $observerGeo->lon = Predict_Math::Radians($qth->lon);
301
-        $observerGeo->alt = $qth->alt * 1000;
302
-
303
-        // Now determine the sun and observer positions
304
-        $observerPos      = new Predict_Vector();
305
-        $observerVel      = new Predict_Vector();
306
-        $solarVector      = new Predict_Vector();
307
-        Predict_Solar::Calculate_Solar_Position($time, $solarVector);
308
-        Predict_SGPObs::Calculate_User_PosVel($time, $observerGeo, $observerPos, $observerVel);
309
-
310
-        // Determine the solar phase and and thus the percent illumination
311
-        $observerSatPos = new Predict_Vector();
312
-        Predict_Math::Vec_Sub($this->pos, $observerPos, $observerSatPos);
313
-        $phaseAngle = Predict_Math::Degrees(Predict_Math::Angle($solarVector, $observerSatPos));
314
-        $illum      = $phaseAngle / 180;
315
-
316
-        $illuminationChange            = $illum / $imag['illum'];
317
-        $inverseSquareOfDistanceChange = pow(($imag['distance'] / $this->range), 2);
318
-        $changeInMagnitude             = log(
319
-            $illuminationChange * $inverseSquareOfDistanceChange,
320
-            self::POGSONS_RATIO
321
-        );
322
-
323
-        return $imag['mag'] - $changeInMagnitude;
324
-    }
259
+		if ((10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda))) == 0) {
260
+			return true;
261
+		} elseif ($sat->jul_epoch + ((16.666666 - $sat->meanmo) /
262
+							   (10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda)))) < $sat->jul_utc) {
263
+			  return true;
264
+		} else {
265
+			  return false;
266
+		}
267
+	}
268
+
269
+	/**
270
+	 * Experimental attempt at calculating apparent magnitude.  Known intrinsic
271
+	 * magnitudes are listed inside the function for now.
272
+	 *
273
+	 * @param float       $time The daynum the satellite is calculated for
274
+	 * @param Predict_QTH $qth  The observer location
275
+	 *
276
+	 * @return null on failure, float otherwise
277
+	 */
278
+	public function calculateApparentMagnitude($time, Predict_QTH $qth)
279
+	{
280
+		// Recorded intrinsic magnitudes and their respective
281
+		// illumination and distance from heavens-above.com
282
+		static $intrinsicMagnitudes = array(
283
+			'25544' => array(
284
+				'mag'      => -1.3,
285
+				'illum'    => .5,
286
+				'distance' => 1000,
287
+			)
288
+		);
289
+
290
+		// Return null if we don't have a record of the intrinsic mag
291
+		if (!isset($intrinsicMagnitudes[$this->tle->catnr])) {
292
+			return null;
293
+		}
294
+		$imag = $intrinsicMagnitudes[$this->tle->catnr];
295
+
296
+		// Convert the observer's geodetic info to radians and km so
297
+		// we can compare vectors
298
+		$observerGeo      = new Predict_Geodetic();
299
+		$observerGeo->lat = Predict_Math::Radians($qth->lat);
300
+		$observerGeo->lon = Predict_Math::Radians($qth->lon);
301
+		$observerGeo->alt = $qth->alt * 1000;
302
+
303
+		// Now determine the sun and observer positions
304
+		$observerPos      = new Predict_Vector();
305
+		$observerVel      = new Predict_Vector();
306
+		$solarVector      = new Predict_Vector();
307
+		Predict_Solar::Calculate_Solar_Position($time, $solarVector);
308
+		Predict_SGPObs::Calculate_User_PosVel($time, $observerGeo, $observerPos, $observerVel);
309
+
310
+		// Determine the solar phase and and thus the percent illumination
311
+		$observerSatPos = new Predict_Vector();
312
+		Predict_Math::Vec_Sub($this->pos, $observerPos, $observerSatPos);
313
+		$phaseAngle = Predict_Math::Degrees(Predict_Math::Angle($solarVector, $observerSatPos));
314
+		$illum      = $phaseAngle / 180;
315
+
316
+		$illuminationChange            = $illum / $imag['illum'];
317
+		$inverseSquareOfDistanceChange = pow(($imag['distance'] / $this->range), 2);
318
+		$changeInMagnitude             = log(
319
+			$illuminationChange * $inverseSquareOfDistanceChange,
320
+			self::POGSONS_RATIO
321
+		);
322
+
323
+		return $imag['mag'] - $changeInMagnitude;
324
+	}
325 325
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,42 +29,42 @@  discard block
 block discarded – undo
29 29
     public $nickname = null;
30 30
     public $website  = null;
31 31
 
32
-    public $tle      = null;   /*!< Keplerian elements */
33
-    public $flags    = 0;      /*!< Flags for algo ctrl */
32
+    public $tle      = null; /*!< Keplerian elements */
33
+    public $flags    = 0; /*!< Flags for algo ctrl */
34 34
     public $sgps     = null;
35 35
     public $dps      = null;
36 36
     public $deep_arg = null;
37
-    public $pos      = null;   /*!< Raw position and range */
38
-    public $vel      = null;   /*!< Raw velocity */
37
+    public $pos      = null; /*!< Raw position and range */
38
+    public $vel      = null; /*!< Raw velocity */
39 39
 
40 40
     /*** FIXME: REMOVE */
41
-    public $bearing = null;   /*!< Az, El, range and vel */
42
-    public $astro   = null;   /*!< Ra and Decl */
41
+    public $bearing = null; /*!< Az, El, range and vel */
42
+    public $astro   = null; /*!< Ra and Decl */
43 43
     /*** END */
44 44
 
45 45
     /* time keeping fields */
46 46
     public $jul_epoch = null;
47 47
     public $jul_utc   = null;
48 48
     public $tsince    = null;
49
-    public $aos       = null;    /*!< Next AOS. */
50
-    public $los       = null;    /*!< Next LOS */
51
-
52
-    public $az         = null;   /*!< Azimuth [deg] */
53
-    public $el         = null;   /*!< Elevation [deg] */
54
-    public $range      = null;   /*!< Range [km] */
55
-    public $range_rate = null;   /*!< Range Rate [km/sec] */
56
-    public $ra         = null;   /*!< Right Ascension [deg] */
57
-    public $dec        = null;   /*!< Declination [deg] */
58
-    public $ssplat     = null;   /*!< SSP latitude [deg] */
59
-    public $ssplon     = null;   /*!< SSP longitude [deg] */
60
-    public $alt        = null;   /*!< altitude [km] */
61
-    public $velo       = null;   /*!< velocity [km/s] */
62
-    public $ma         = null;   /*!< mean anomaly */
63
-    public $footprint  = null;   /*!< footprint */
64
-    public $phase      = null;   /*!< orbit phase */
65
-    public $meanmo     = null;   /*!< mean motion kept in rev/day */
66
-    public $orbit      = null;   /*!< orbit number */
67
-    public $otype      = null;   /*!< orbit type. */
49
+    public $aos       = null; /*!< Next AOS. */
50
+    public $los       = null; /*!< Next LOS */
51
+
52
+    public $az         = null; /*!< Azimuth [deg] */
53
+    public $el         = null; /*!< Elevation [deg] */
54
+    public $range      = null; /*!< Range [km] */
55
+    public $range_rate = null; /*!< Range Rate [km/sec] */
56
+    public $ra         = null; /*!< Right Ascension [deg] */
57
+    public $dec        = null; /*!< Declination [deg] */
58
+    public $ssplat     = null; /*!< SSP latitude [deg] */
59
+    public $ssplon     = null; /*!< SSP longitude [deg] */
60
+    public $alt        = null; /*!< altitude [km] */
61
+    public $velo       = null; /*!< velocity [km/s] */
62
+    public $ma         = null; /*!< mean anomaly */
63
+    public $footprint  = null; /*!< footprint */
64
+    public $phase      = null; /*!< orbit phase */
65
+    public $meanmo     = null; /*!< mean motion kept in rev/day */
66
+    public $orbit      = null; /*!< orbit number */
67
+    public $otype      = null; /*!< orbit type. */
68 68
 
69 69
     public function __construct(Predict_TLE $tle)
70 70
     {
@@ -93,30 +93,30 @@  discard block
 block discarded – undo
93 93
         $this->tle->omegao *= Predict::de2ra;
94 94
         $this->tle->xmo    *= Predict::de2ra;
95 95
         $this->tle->xincl  *= Predict::de2ra;
96
-        $temp = Predict::twopi / Predict::xmnpda / Predict::xmnpda;
96
+        $temp = Predict::twopi/Predict::xmnpda/Predict::xmnpda;
97 97
 
98 98
         /* store mean motion before conversion */
99 99
         $this->meanmo       = $this->tle->xno;
100
-        $this->tle->xno     = $this->tle->xno * $temp * Predict::xmnpda;
100
+        $this->tle->xno     = $this->tle->xno*$temp*Predict::xmnpda;
101 101
         $this->tle->xndt2o *= $temp;
102
-        $this->tle->xndd6o  = $this->tle->xndd6o * $temp / Predict::xmnpda;
102
+        $this->tle->xndd6o  = $this->tle->xndd6o*$temp/Predict::xmnpda;
103 103
         $this->tle->bstar  /= Predict::ae;
104 104
 
105 105
         /* Period > 225 minutes is deep space */
106
-        $dd1 = Predict::xke / $this->tle->xno;
106
+        $dd1 = Predict::xke/$this->tle->xno;
107 107
         $dd2 = Predict::tothrd;
108 108
         $a1 = pow($dd1, $dd2);
109 109
         $r1 = cos($this->tle->xincl);
110
-        $dd1 = 1.0 - $this->tle->eo * $this->tle->eo;
111
-        $temp = Predict::ck2 * 1.5 * ($r1 * $r1 * 3.0 - 1.0) / pow($dd1, 1.5);
112
-        $del1 = $temp / ($a1 * $a1);
113
-        $ao = $a1 * (1.0 - $del1 * (Predict::tothrd * 0.5 + $del1 *
114
-                                 ($del1 * 1.654320987654321 + 1.0)));
115
-        $delo = $temp / ($ao * $ao);
116
-        $xnodp = $this->tle->xno / ($delo + 1.0);
110
+        $dd1 = 1.0 - $this->tle->eo*$this->tle->eo;
111
+        $temp = Predict::ck2*1.5*($r1*$r1*3.0 - 1.0)/pow($dd1, 1.5);
112
+        $del1 = $temp/($a1*$a1);
113
+        $ao = $a1*(1.0 - $del1*(Predict::tothrd*0.5 + $del1*
114
+                                 ($del1*1.654320987654321 + 1.0)));
115
+        $delo = $temp/($ao*$ao);
116
+        $xnodp = $this->tle->xno/($delo + 1.0);
117 117
 
118 118
         /* Select a deep-space/near-earth ephemeris */
119
-        if (Predict::twopi / $xnodp / Predict::xmnpda >= .15625) {
119
+        if (Predict::twopi/$xnodp/Predict::xmnpda >= .15625) {
120 120
             $this->flags |= Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
121 121
         } else {
122 122
             $this->flags &= ~Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG;
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 
143 143
         /* initialise observer location */
144 144
         if ($qth != null) {
145
-            $obs_geodetic->lon = $qth->lon * Predict::de2ra;
146
-            $obs_geodetic->lat = $qth->lat * Predict::de2ra;
147
-            $obs_geodetic->alt = $qth->alt / 1000.0;
145
+            $obs_geodetic->lon = $qth->lon*Predict::de2ra;
146
+            $obs_geodetic->lat = $qth->lat*Predict::de2ra;
147
+            $obs_geodetic->alt = $qth->alt/1000.0;
148 148
             $obs_geodetic->theta = 0;
149 149
         }
150 150
         else {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 
157 157
         /* execute computations */
158 158
         $sdpsgp = Predict_SGPSDP::getInstance($sat);
159
-        if ($sat->flags & Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
159
+        if ($sat->flags&Predict_SGPSDP::DEEP_SPACE_EPHEM_FLAG) {
160 160
             $sdpsgp->SDP4($sat, 0.0);
161 161
         } else {
162 162
             $sdpsgp->SGP4($sat, 0.0);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
         Predict_Math::Convert_Sat_State($sat->pos, $sat->vel);
167 167
 
168 168
         /* get the velocity of the satellite */
169
-        $sat->vel->w = sqrt($sat->vel->x * $sat->vel->x + $sat->vel->y * $sat->vel->y + $sat->vel->z * $sat->vel->z);
169
+        $sat->vel->w = sqrt($sat->vel->x*$sat->vel->x + $sat->vel->y*$sat->vel->y + $sat->vel->z*$sat->vel->z);
170 170
         $sat->velo = $sat->vel->w;
171 171
         Predict_SGPObs::Calculate_Obs($jul_utc, $sat->pos, $sat->vel, $obs_geodetic, $obs_set);
172 172
         Predict_SGPObs::Calculate_LatLonAlt($jul_utc, $sat->pos, $sat_geodetic);
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
         $sat->ssplon = Predict_Math::Degrees($sat_geodetic->lon);
188 188
         $sat->alt = $sat_geodetic->alt;
189 189
         $sat->ma = Predict_Math::Degrees($sat->phase);
190
-        $sat->ma *= 256.0 / 360.0;
191
-        $sat->footprint = 2.0 * Predict::xkmper * acos (Predict::xkmper/$sat->pos->w);
190
+        $sat->ma *= 256.0/360.0;
191
+        $sat->footprint = 2.0*Predict::xkmper*acos(Predict::xkmper/$sat->pos->w);
192 192
         $age = 0.0;
193
-        $sat->orbit = floor(($sat->tle->xno * Predict::xmnpda / Predict::twopi +
194
-                                   $age * $sat->tle->bstar * Predict::ae) * $age +
195
-                                  $sat->tle->xmo / Predict::twopi) + $sat->tle->revnum - 1;
193
+        $sat->orbit = floor(($sat->tle->xno*Predict::xmnpda/Predict::twopi +
194
+                                   $age*$sat->tle->bstar*Predict::ae)*$age +
195
+                                  $sat->tle->xmo/Predict::twopi) + $sat->tle->revnum - 1;
196 196
 
197 197
         /* orbit type */
198 198
         $sat->otype = $sat->get_orbit_type($sat);
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
              It is time dependent. Also sat->jul_utc is often zero
257 257
              when this function is called
258 258
         ***/
259
-        if ((10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda))) == 0) {
259
+        if ((10.0*abs($sat->tle->xndt2o/(Predict::twopi/Predict::xmnpda/Predict::xmnpda))) == 0) {
260 260
     		return true;
261
-    	} elseif ($sat->jul_epoch + ((16.666666 - $sat->meanmo) /
262
-                               (10.0 * abs($sat->tle->xndt2o / (Predict::twopi / Predict::xmnpda / Predict::xmnpda)))) < $sat->jul_utc) {
261
+    	} elseif ($sat->jul_epoch + ((16.666666 - $sat->meanmo)/
262
+                               (10.0*abs($sat->tle->xndt2o/(Predict::twopi/Predict::xmnpda/Predict::xmnpda)))) < $sat->jul_utc) {
263 263
               return true;
264 264
         } else {
265 265
               return false;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $observerGeo      = new Predict_Geodetic();
299 299
         $observerGeo->lat = Predict_Math::Radians($qth->lat);
300 300
         $observerGeo->lon = Predict_Math::Radians($qth->lon);
301
-        $observerGeo->alt = $qth->alt * 1000;
301
+        $observerGeo->alt = $qth->alt*1000;
302 302
 
303 303
         // Now determine the sun and observer positions
304 304
         $observerPos      = new Predict_Vector();
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
         $observerSatPos = new Predict_Vector();
312 312
         Predict_Math::Vec_Sub($this->pos, $observerPos, $observerSatPos);
313 313
         $phaseAngle = Predict_Math::Degrees(Predict_Math::Angle($solarVector, $observerSatPos));
314
-        $illum      = $phaseAngle / 180;
314
+        $illum      = $phaseAngle/180;
315 315
 
316
-        $illuminationChange            = $illum / $imag['illum'];
317
-        $inverseSquareOfDistanceChange = pow(($imag['distance'] / $this->range), 2);
316
+        $illuminationChange            = $illum/$imag['illum'];
317
+        $inverseSquareOfDistanceChange = pow(($imag['distance']/$this->range), 2);
318 318
         $changeInMagnitude             = log(
319
-            $illuminationChange * $inverseSquareOfDistanceChange,
319
+            $illuminationChange*$inverseSquareOfDistanceChange,
320 320
             self::POGSONS_RATIO
321 321
         );
322 322
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,8 +146,7 @@
 block discarded – undo
146 146
             $obs_geodetic->lat = $qth->lat * Predict::de2ra;
147 147
             $obs_geodetic->alt = $qth->alt / 1000.0;
148 148
             $obs_geodetic->theta = 0;
149
-        }
150
-        else {
149
+        } else {
151 150
             $obs_geodetic->lon = 0.0;
152 151
             $obs_geodetic->lat = 0.0;
153 152
             $obs_geodetic->alt = 0.0;
Please login to merge, or discard this patch.
require/libs/Predict/Predict/SGPObs.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -56,6 +56,10 @@
 block discarded – undo
56 56
     /* It is intended to be used to determine the ground track of */
57 57
     /* a satellite.  The calculations  assume the earth to be an  */
58 58
     /* oblate spheroid as defined in WGS '72.                     */
59
+
60
+    /**
61
+     * @param double $_time
62
+     */
59 63
     public static function Calculate_LatLonAlt($_time, Predict_Vector $pos,  Predict_Geodetic $geodetic)
60 64
     {
61 65
         /* Reference:  The 1992 Astronomical Almanac, page K12. */
Please login to merge, or discard this patch.
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -25,131 +25,131 @@
 block discarded – undo
25 25
  */
26 26
 class Predict_SGPObs
27 27
 {
28
-    /* Procedure Calculate_User_PosVel passes the user's geodetic position */
29
-    /* and the time of interest and returns the ECI position and velocity  */
30
-    /* of the observer. The velocity calculation assumes the geodetic      */
31
-    /* position is stationary relative to the earth's surface.             */
32
-    public static function Calculate_User_PosVel(
33
-        $_time, Predict_Geodetic $geodetic, Predict_Vector $obs_pos, Predict_Vector $obs_vel
34
-    )
35
-    {
36
-        /* Reference:  The 1992 Astronomical Almanac, page K11. */
37
-
38
-        $sinGeodeticLat = sin($geodetic->lat); /* Only run sin($geodetic->lat) once */
39
-
40
-        $geodetic->theta = Predict_Math::FMod2p(Predict_Time::ThetaG_JD($_time) + $geodetic->lon);/*LMST*/
41
-        $c = 1 / sqrt(1 + Predict::__f * (Predict::__f - 2) * $sinGeodeticLat * $sinGeodeticLat);
42
-        $sq = (1 - Predict::__f) * (1 - Predict::__f) * $c;
43
-        $achcp = (Predict::xkmper * $c + $geodetic->alt) * cos($geodetic->lat);
44
-        $obs_pos->x = $achcp * cos($geodetic->theta); /*kilometers*/
45
-        $obs_pos->y = $achcp * sin($geodetic->theta);
46
-        $obs_pos->z = (Predict::xkmper * $sq + $geodetic->alt) * $sinGeodeticLat;
47
-        $obs_vel->x = -Predict::mfactor * $obs_pos->y; /*kilometers/second*/
48
-        $obs_vel->y =  Predict::mfactor * $obs_pos->x;
49
-        $obs_vel->z =  0;
50
-        $obs_pos->w = sqrt($obs_pos->x * $obs_pos->x + $obs_pos->y * $obs_pos->y + $obs_pos->z * $obs_pos->z);
51
-        $obs_vel->w = sqrt($obs_vel->x * $obs_vel->x + $obs_vel->y * $obs_vel->y + $obs_vel->z * $obs_vel->z);
52
-    }
53
-
54
-    /* Procedure Calculate_LatLonAlt will calculate the geodetic  */
55
-    /* position of an object given its ECI position pos and time. */
56
-    /* It is intended to be used to determine the ground track of */
57
-    /* a satellite.  The calculations  assume the earth to be an  */
58
-    /* oblate spheroid as defined in WGS '72.                     */
59
-    public static function Calculate_LatLonAlt($_time, Predict_Vector $pos,  Predict_Geodetic $geodetic)
60
-    {
61
-        /* Reference:  The 1992 Astronomical Almanac, page K12. */
62
-
63
-        /* double r,e2,phi,c; */
64
-
65
-        $geodetic->theta = Predict_Math::AcTan($pos->y, $pos->x); /*radians*/
66
-        $geodetic->lon = Predict_Math::FMod2p($geodetic->theta - Predict_Time::ThetaG_JD($_time)); /*radians*/
67
-        $r = sqrt(($pos->x * $pos->x) + ($pos->y * $pos->y));
68
-        $e2 = Predict::__f * (2 - Predict::__f);
69
-        $geodetic->lat = Predict_Math::AcTan($pos->z, $r); /*radians*/
70
-
71
-        do {
72
-            $phi    = $geodetic->lat;
73
-            $sinPhi = sin($phi);
74
-            $c      = 1 / sqrt(1 - $e2 * ($sinPhi * $sinPhi));
75
-            $geodetic->lat = Predict_Math::AcTan($pos->z + Predict::xkmper * $c * $e2 * $sinPhi, $r);
76
-        } while (abs($geodetic->lat - $phi) >= 1E-10);
77
-
78
-        $geodetic->alt = $r / cos($geodetic->lat) - Predict::xkmper * $c;/*kilometers*/
79
-
80
-        if ($geodetic->lat > Predict::pio2) {
81
-            $geodetic->lat -= Predict::twopi;
82
-        }
83
-    }
84
-
85
-    /* The procedures Calculate_Obs and Calculate_RADec calculate         */
86
-    /* the *topocentric* coordinates of the object with ECI position,     */
87
-    /* {pos}, and velocity, {vel}, from location {geodetic} at {time}.    */
88
-    /* The {obs_set} returned for Calculate_Obs consists of azimuth,      */
89
-    /* elevation, range, and range rate (in that order) with units of     */
90
-    /* radians, radians, kilometers, and kilometers/second, respectively. */
91
-    /* The WGS '72 geoid is used and the effect of atmospheric refraction */
92
-    /* (under standard temperature and pressure) is incorporated into the */
93
-    /* elevation calculation; the effect of atmospheric refraction on     */
94
-    /* range and range rate has not yet been quantified.                  */
95
-
96
-    /* The {obs_set} for Calculate_RADec consists of right ascension and  */
97
-    /* declination (in that order) in radians.  Again, calculations are   */
98
-    /* based on *topocentric* position using the WGS '72 geoid and        */
99
-    /* incorporating atmospheric refraction.                              */
100
-    public static function Calculate_Obs($_time, Predict_Vector $pos, Predict_Vector $vel, Predict_Geodetic $geodetic, Predict_ObsSet $obs_set)
101
-    {
102
-        $obs_pos = new Predict_Vector();
103
-        $obs_vel = new Predict_Vector();
104
-        $range   = new Predict_Vector();
105
-        $rgvel   = new Predict_Vector();
106
-
107
-        self::Calculate_User_PosVel($_time, $geodetic, $obs_pos, $obs_vel);
108
-
109
-        $range->x = $pos->x - $obs_pos->x;
110
-        $range->y = $pos->y - $obs_pos->y;
111
-        $range->z = $pos->z - $obs_pos->z;
112
-
113
-        $rgvel->x = $vel->x - $obs_vel->x;
114
-        $rgvel->y = $vel->y - $obs_vel->y;
115
-        $rgvel->z = $vel->z - $obs_vel->z;
116
-
117
-        $range->w = sqrt($range->x * $range->x + $range->y * $range->y + $range->z * $range->z);
118
-
119
-        $sin_lat   = sin($geodetic->lat);
120
-        $cos_lat   = cos($geodetic->lat);
121
-        $sin_theta = sin($geodetic->theta);
122
-        $cos_theta = cos($geodetic->theta);
123
-        $top_s = $sin_lat * $cos_theta * $range->x
124
-            + $sin_lat * $sin_theta * $range->y
125
-            - $cos_lat * $range->z;
126
-        $top_e = -$sin_theta * $range->x
127
-            + $cos_theta * $range->y;
128
-        $top_z = $cos_lat * $cos_theta * $range->x
129
-            + $cos_lat * $sin_theta * $range->y
130
-            + $sin_lat * $range->z;
131
-        $azim = atan(-$top_e / $top_s); /*Azimuth*/
132
-        if ($top_s > 0) {
133
-            $azim = $azim + Predict::pi;
134
-        }
135
-        if ($azim < 0 ) {
136
-            $azim = $azim + Predict::twopi;
137
-        }
138
-        $el = Predict_Math::ArcSin($top_z / $range->w);
139
-        $obs_set->az = $azim;        /* Azimuth (radians)  */
140
-        $obs_set->el = $el;          /* Elevation (radians)*/
141
-        $obs_set->range = $range->w; /* Range (kilometers) */
142
-
143
-        /* Range Rate (kilometers/second)*/
144
-        $obs_set->range_rate = Predict_Math::Dot($range, $rgvel) / $range->w;
145
-
146
-        /* Corrections for atmospheric refraction */
147
-        /* Reference:  Astronomical Algorithms by Jean Meeus, pp. 101-104    */
148
-        /* Correction is meaningless when apparent elevation is below horizon */
149
-        //	obs_set->el = obs_set->el + Radians((1.02/tan(Radians(Degrees(el)+
150
-        //							      10.3/(Degrees(el)+5.11))))/60);
151
-        if ($obs_set->el < 0) {
152
-            $obs_set->el = $el;  /*Reset to true elevation*/
153
-        }
154
-    }
28
+	/* Procedure Calculate_User_PosVel passes the user's geodetic position */
29
+	/* and the time of interest and returns the ECI position and velocity  */
30
+	/* of the observer. The velocity calculation assumes the geodetic      */
31
+	/* position is stationary relative to the earth's surface.             */
32
+	public static function Calculate_User_PosVel(
33
+		$_time, Predict_Geodetic $geodetic, Predict_Vector $obs_pos, Predict_Vector $obs_vel
34
+	)
35
+	{
36
+		/* Reference:  The 1992 Astronomical Almanac, page K11. */
37
+
38
+		$sinGeodeticLat = sin($geodetic->lat); /* Only run sin($geodetic->lat) once */
39
+
40
+		$geodetic->theta = Predict_Math::FMod2p(Predict_Time::ThetaG_JD($_time) + $geodetic->lon);/*LMST*/
41
+		$c = 1 / sqrt(1 + Predict::__f * (Predict::__f - 2) * $sinGeodeticLat * $sinGeodeticLat);
42
+		$sq = (1 - Predict::__f) * (1 - Predict::__f) * $c;
43
+		$achcp = (Predict::xkmper * $c + $geodetic->alt) * cos($geodetic->lat);
44
+		$obs_pos->x = $achcp * cos($geodetic->theta); /*kilometers*/
45
+		$obs_pos->y = $achcp * sin($geodetic->theta);
46
+		$obs_pos->z = (Predict::xkmper * $sq + $geodetic->alt) * $sinGeodeticLat;
47
+		$obs_vel->x = -Predict::mfactor * $obs_pos->y; /*kilometers/second*/
48
+		$obs_vel->y =  Predict::mfactor * $obs_pos->x;
49
+		$obs_vel->z =  0;
50
+		$obs_pos->w = sqrt($obs_pos->x * $obs_pos->x + $obs_pos->y * $obs_pos->y + $obs_pos->z * $obs_pos->z);
51
+		$obs_vel->w = sqrt($obs_vel->x * $obs_vel->x + $obs_vel->y * $obs_vel->y + $obs_vel->z * $obs_vel->z);
52
+	}
53
+
54
+	/* Procedure Calculate_LatLonAlt will calculate the geodetic  */
55
+	/* position of an object given its ECI position pos and time. */
56
+	/* It is intended to be used to determine the ground track of */
57
+	/* a satellite.  The calculations  assume the earth to be an  */
58
+	/* oblate spheroid as defined in WGS '72.                     */
59
+	public static function Calculate_LatLonAlt($_time, Predict_Vector $pos,  Predict_Geodetic $geodetic)
60
+	{
61
+		/* Reference:  The 1992 Astronomical Almanac, page K12. */
62
+
63
+		/* double r,e2,phi,c; */
64
+
65
+		$geodetic->theta = Predict_Math::AcTan($pos->y, $pos->x); /*radians*/
66
+		$geodetic->lon = Predict_Math::FMod2p($geodetic->theta - Predict_Time::ThetaG_JD($_time)); /*radians*/
67
+		$r = sqrt(($pos->x * $pos->x) + ($pos->y * $pos->y));
68
+		$e2 = Predict::__f * (2 - Predict::__f);
69
+		$geodetic->lat = Predict_Math::AcTan($pos->z, $r); /*radians*/
70
+
71
+		do {
72
+			$phi    = $geodetic->lat;
73
+			$sinPhi = sin($phi);
74
+			$c      = 1 / sqrt(1 - $e2 * ($sinPhi * $sinPhi));
75
+			$geodetic->lat = Predict_Math::AcTan($pos->z + Predict::xkmper * $c * $e2 * $sinPhi, $r);
76
+		} while (abs($geodetic->lat - $phi) >= 1E-10);
77
+
78
+		$geodetic->alt = $r / cos($geodetic->lat) - Predict::xkmper * $c;/*kilometers*/
79
+
80
+		if ($geodetic->lat > Predict::pio2) {
81
+			$geodetic->lat -= Predict::twopi;
82
+		}
83
+	}
84
+
85
+	/* The procedures Calculate_Obs and Calculate_RADec calculate         */
86
+	/* the *topocentric* coordinates of the object with ECI position,     */
87
+	/* {pos}, and velocity, {vel}, from location {geodetic} at {time}.    */
88
+	/* The {obs_set} returned for Calculate_Obs consists of azimuth,      */
89
+	/* elevation, range, and range rate (in that order) with units of     */
90
+	/* radians, radians, kilometers, and kilometers/second, respectively. */
91
+	/* The WGS '72 geoid is used and the effect of atmospheric refraction */
92
+	/* (under standard temperature and pressure) is incorporated into the */
93
+	/* elevation calculation; the effect of atmospheric refraction on     */
94
+	/* range and range rate has not yet been quantified.                  */
95
+
96
+	/* The {obs_set} for Calculate_RADec consists of right ascension and  */
97
+	/* declination (in that order) in radians.  Again, calculations are   */
98
+	/* based on *topocentric* position using the WGS '72 geoid and        */
99
+	/* incorporating atmospheric refraction.                              */
100
+	public static function Calculate_Obs($_time, Predict_Vector $pos, Predict_Vector $vel, Predict_Geodetic $geodetic, Predict_ObsSet $obs_set)
101
+	{
102
+		$obs_pos = new Predict_Vector();
103
+		$obs_vel = new Predict_Vector();
104
+		$range   = new Predict_Vector();
105
+		$rgvel   = new Predict_Vector();
106
+
107
+		self::Calculate_User_PosVel($_time, $geodetic, $obs_pos, $obs_vel);
108
+
109
+		$range->x = $pos->x - $obs_pos->x;
110
+		$range->y = $pos->y - $obs_pos->y;
111
+		$range->z = $pos->z - $obs_pos->z;
112
+
113
+		$rgvel->x = $vel->x - $obs_vel->x;
114
+		$rgvel->y = $vel->y - $obs_vel->y;
115
+		$rgvel->z = $vel->z - $obs_vel->z;
116
+
117
+		$range->w = sqrt($range->x * $range->x + $range->y * $range->y + $range->z * $range->z);
118
+
119
+		$sin_lat   = sin($geodetic->lat);
120
+		$cos_lat   = cos($geodetic->lat);
121
+		$sin_theta = sin($geodetic->theta);
122
+		$cos_theta = cos($geodetic->theta);
123
+		$top_s = $sin_lat * $cos_theta * $range->x
124
+			+ $sin_lat * $sin_theta * $range->y
125
+			- $cos_lat * $range->z;
126
+		$top_e = -$sin_theta * $range->x
127
+			+ $cos_theta * $range->y;
128
+		$top_z = $cos_lat * $cos_theta * $range->x
129
+			+ $cos_lat * $sin_theta * $range->y
130
+			+ $sin_lat * $range->z;
131
+		$azim = atan(-$top_e / $top_s); /*Azimuth*/
132
+		if ($top_s > 0) {
133
+			$azim = $azim + Predict::pi;
134
+		}
135
+		if ($azim < 0 ) {
136
+			$azim = $azim + Predict::twopi;
137
+		}
138
+		$el = Predict_Math::ArcSin($top_z / $range->w);
139
+		$obs_set->az = $azim;        /* Azimuth (radians)  */
140
+		$obs_set->el = $el;          /* Elevation (radians)*/
141
+		$obs_set->range = $range->w; /* Range (kilometers) */
142
+
143
+		/* Range Rate (kilometers/second)*/
144
+		$obs_set->range_rate = Predict_Math::Dot($range, $rgvel) / $range->w;
145
+
146
+		/* Corrections for atmospheric refraction */
147
+		/* Reference:  Astronomical Algorithms by Jean Meeus, pp. 101-104    */
148
+		/* Correction is meaningless when apparent elevation is below horizon */
149
+		//	obs_set->el = obs_set->el + Radians((1.02/tan(Radians(Degrees(el)+
150
+		//							      10.3/(Degrees(el)+5.11))))/60);
151
+		if ($obs_set->el < 0) {
152
+			$obs_set->el = $el;  /*Reset to true elevation*/
153
+		}
154
+	}
155 155
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -37,18 +37,18 @@  discard block
 block discarded – undo
37 37
 
38 38
         $sinGeodeticLat = sin($geodetic->lat); /* Only run sin($geodetic->lat) once */
39 39
 
40
-        $geodetic->theta = Predict_Math::FMod2p(Predict_Time::ThetaG_JD($_time) + $geodetic->lon);/*LMST*/
41
-        $c = 1 / sqrt(1 + Predict::__f * (Predict::__f - 2) * $sinGeodeticLat * $sinGeodeticLat);
42
-        $sq = (1 - Predict::__f) * (1 - Predict::__f) * $c;
43
-        $achcp = (Predict::xkmper * $c + $geodetic->alt) * cos($geodetic->lat);
44
-        $obs_pos->x = $achcp * cos($geodetic->theta); /*kilometers*/
45
-        $obs_pos->y = $achcp * sin($geodetic->theta);
46
-        $obs_pos->z = (Predict::xkmper * $sq + $geodetic->alt) * $sinGeodeticLat;
47
-        $obs_vel->x = -Predict::mfactor * $obs_pos->y; /*kilometers/second*/
48
-        $obs_vel->y =  Predict::mfactor * $obs_pos->x;
49
-        $obs_vel->z =  0;
50
-        $obs_pos->w = sqrt($obs_pos->x * $obs_pos->x + $obs_pos->y * $obs_pos->y + $obs_pos->z * $obs_pos->z);
51
-        $obs_vel->w = sqrt($obs_vel->x * $obs_vel->x + $obs_vel->y * $obs_vel->y + $obs_vel->z * $obs_vel->z);
40
+        $geodetic->theta = Predict_Math::FMod2p(Predict_Time::ThetaG_JD($_time) + $geodetic->lon); /*LMST*/
41
+        $c = 1/sqrt(1 + Predict::__f*(Predict::__f - 2)*$sinGeodeticLat*$sinGeodeticLat);
42
+        $sq = (1 - Predict::__f)*(1 - Predict::__f)*$c;
43
+        $achcp = (Predict::xkmper*$c + $geodetic->alt)*cos($geodetic->lat);
44
+        $obs_pos->x = $achcp*cos($geodetic->theta); /*kilometers*/
45
+        $obs_pos->y = $achcp*sin($geodetic->theta);
46
+        $obs_pos->z = (Predict::xkmper*$sq + $geodetic->alt)*$sinGeodeticLat;
47
+        $obs_vel->x = -Predict::mfactor*$obs_pos->y; /*kilometers/second*/
48
+        $obs_vel->y = Predict::mfactor*$obs_pos->x;
49
+        $obs_vel->z = 0;
50
+        $obs_pos->w = sqrt($obs_pos->x*$obs_pos->x + $obs_pos->y*$obs_pos->y + $obs_pos->z*$obs_pos->z);
51
+        $obs_vel->w = sqrt($obs_vel->x*$obs_vel->x + $obs_vel->y*$obs_vel->y + $obs_vel->z*$obs_vel->z);
52 52
     }
53 53
 
54 54
     /* Procedure Calculate_LatLonAlt will calculate the geodetic  */
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     /* It is intended to be used to determine the ground track of */
57 57
     /* a satellite.  The calculations  assume the earth to be an  */
58 58
     /* oblate spheroid as defined in WGS '72.                     */
59
-    public static function Calculate_LatLonAlt($_time, Predict_Vector $pos,  Predict_Geodetic $geodetic)
59
+    public static function Calculate_LatLonAlt($_time, Predict_Vector $pos, Predict_Geodetic $geodetic)
60 60
     {
61 61
         /* Reference:  The 1992 Astronomical Almanac, page K12. */
62 62
 
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
 
65 65
         $geodetic->theta = Predict_Math::AcTan($pos->y, $pos->x); /*radians*/
66 66
         $geodetic->lon = Predict_Math::FMod2p($geodetic->theta - Predict_Time::ThetaG_JD($_time)); /*radians*/
67
-        $r = sqrt(($pos->x * $pos->x) + ($pos->y * $pos->y));
68
-        $e2 = Predict::__f * (2 - Predict::__f);
67
+        $r = sqrt(($pos->x*$pos->x) + ($pos->y*$pos->y));
68
+        $e2 = Predict::__f*(2 - Predict::__f);
69 69
         $geodetic->lat = Predict_Math::AcTan($pos->z, $r); /*radians*/
70 70
 
71 71
         do {
72 72
             $phi    = $geodetic->lat;
73 73
             $sinPhi = sin($phi);
74
-            $c      = 1 / sqrt(1 - $e2 * ($sinPhi * $sinPhi));
75
-            $geodetic->lat = Predict_Math::AcTan($pos->z + Predict::xkmper * $c * $e2 * $sinPhi, $r);
74
+            $c      = 1/sqrt(1 - $e2*($sinPhi*$sinPhi));
75
+            $geodetic->lat = Predict_Math::AcTan($pos->z + Predict::xkmper*$c*$e2*$sinPhi, $r);
76 76
         } while (abs($geodetic->lat - $phi) >= 1E-10);
77 77
 
78
-        $geodetic->alt = $r / cos($geodetic->lat) - Predict::xkmper * $c;/*kilometers*/
78
+        $geodetic->alt = $r/cos($geodetic->lat) - Predict::xkmper*$c; /*kilometers*/
79 79
 
80 80
         if ($geodetic->lat > Predict::pio2) {
81 81
             $geodetic->lat -= Predict::twopi;
@@ -114,34 +114,34 @@  discard block
 block discarded – undo
114 114
         $rgvel->y = $vel->y - $obs_vel->y;
115 115
         $rgvel->z = $vel->z - $obs_vel->z;
116 116
 
117
-        $range->w = sqrt($range->x * $range->x + $range->y * $range->y + $range->z * $range->z);
117
+        $range->w = sqrt($range->x*$range->x + $range->y*$range->y + $range->z*$range->z);
118 118
 
119 119
         $sin_lat   = sin($geodetic->lat);
120 120
         $cos_lat   = cos($geodetic->lat);
121 121
         $sin_theta = sin($geodetic->theta);
122 122
         $cos_theta = cos($geodetic->theta);
123
-        $top_s = $sin_lat * $cos_theta * $range->x
124
-            + $sin_lat * $sin_theta * $range->y
125
-            - $cos_lat * $range->z;
126
-        $top_e = -$sin_theta * $range->x
127
-            + $cos_theta * $range->y;
128
-        $top_z = $cos_lat * $cos_theta * $range->x
129
-            + $cos_lat * $sin_theta * $range->y
130
-            + $sin_lat * $range->z;
131
-        $azim = atan(-$top_e / $top_s); /*Azimuth*/
123
+        $top_s = $sin_lat*$cos_theta*$range->x
124
+            + $sin_lat*$sin_theta*$range->y
125
+            - $cos_lat*$range->z;
126
+        $top_e = -$sin_theta*$range->x
127
+            + $cos_theta*$range->y;
128
+        $top_z = $cos_lat*$cos_theta*$range->x
129
+            + $cos_lat*$sin_theta*$range->y
130
+            + $sin_lat*$range->z;
131
+        $azim = atan(-$top_e/$top_s); /*Azimuth*/
132 132
         if ($top_s > 0) {
133 133
             $azim = $azim + Predict::pi;
134 134
         }
135
-        if ($azim < 0 ) {
135
+        if ($azim < 0) {
136 136
             $azim = $azim + Predict::twopi;
137 137
         }
138
-        $el = Predict_Math::ArcSin($top_z / $range->w);
139
-        $obs_set->az = $azim;        /* Azimuth (radians)  */
140
-        $obs_set->el = $el;          /* Elevation (radians)*/
138
+        $el = Predict_Math::ArcSin($top_z/$range->w);
139
+        $obs_set->az = $azim; /* Azimuth (radians)  */
140
+        $obs_set->el = $el; /* Elevation (radians)*/
141 141
         $obs_set->range = $range->w; /* Range (kilometers) */
142 142
 
143 143
         /* Range Rate (kilometers/second)*/
144
-        $obs_set->range_rate = Predict_Math::Dot($range, $rgvel) / $range->w;
144
+        $obs_set->range_rate = Predict_Math::Dot($range, $rgvel)/$range->w;
145 145
 
146 146
         /* Corrections for atmospheric refraction */
147 147
         /* Reference:  Astronomical Algorithms by Jean Meeus, pp. 101-104    */
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         //	obs_set->el = obs_set->el + Radians((1.02/tan(Radians(Degrees(el)+
150 150
         //							      10.3/(Degrees(el)+5.11))))/60);
151 151
         if ($obs_set->el < 0) {
152
-            $obs_set->el = $el;  /*Reset to true elevation*/
152
+            $obs_set->el = $el; /*Reset to true elevation*/
153 153
         }
154 154
     }
155 155
 }
Please login to merge, or discard this patch.