Completed
Push — master ( b8fcbd...e238bb )
by Yannick
05:29
created
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(' ','',$flight[5][1])));
438 495
 				if ($arrivalTime == 'Hora estimada de llegada') {
439 496
 					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$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.
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(' ','',$flight[3][2]))),0,5);
439
-				$arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1])));
438
+				$departureTime = substr(trim(str_replace(' lunes', '', str_replace(' ', '', $flight[3][2]))), 0, 5);
439
+				$arrivalTime = trim(str_replace(' lunes', '', str_replace(' ', '', $flight[5][1])));
440 440
 				if ($arrivalTime == 'Hora estimada de llegada') {
441
-					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$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(' ', '', $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.
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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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 FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND 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.
require/class.Common.php 4 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@  discard block
 block discarded – undo
6 6
 	//protected $cookies = array();
7 7
 	
8 8
 	/**
9
-	* Get data from form result
10
-	* @param String $url form URL
11
-	* @param String $type type of submit form method (get or post)
12
-	* @param String|Array $data values form post method
13
-	* @param Array $headers header to submit with the form
14
-	* @return String the result
15
-	*/
9
+	 * Get data from form result
10
+	 * @param String $url form URL
11
+	 * @param String $type type of submit form method (get or post)
12
+	 * @param String|Array $data values form post method
13
+	 * @param Array $headers header to submit with the form
14
+	 * @return String the result
15
+	 */
16 16
 	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
17 17
 		$ch = curl_init();
18 18
 		curl_setopt($ch, CURLOPT_URL, $url);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
68 68
 			}
69 69
 		} else {
70
-		    return $result;
70
+			return $result;
71 71
 		}
72 72
 	}
73 73
 	
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 	
82 82
 	/**
83
-	* Convert a HTML table to an array
84
-	* @param String $data HTML page
85
-	* @return Array array of the tables in HTML page
86
-	*/
83
+	 * Convert a HTML table to an array
84
+	 * @param String $data HTML page
85
+	 * @return Array array of the tables in HTML page
86
+	 */
87 87
 	public function table2array($data) {
88 88
 		if (!is_string($data)) return array();
89 89
 		if ($data == '') return array();
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	}
118 118
 	
119 119
 	/**
120
-	* Convert <p> part of a HTML page to an array
121
-	* @param String $data HTML page
122
-	* @return Array array of the <p> in HTML page
123
-	*/
120
+	 * Convert <p> part of a HTML page to an array
121
+	 * @param String $data HTML page
122
+	 * @return Array array of the <p> in HTML page
123
+	 */
124 124
 	public function text2array($data) {
125 125
 		$html = str_get_html($data);
126 126
 		if ($html === false) return array();
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
 	}
136 136
 
137 137
 	/**
138
-	* Give distance between 2 coordonnates
139
-	* @param Float $lat latitude of first point
140
-	* @param Float $lon longitude of first point
141
-	* @param Float $latc latitude of second point
142
-	* @param Float $lonc longitude of second point
143
-	* @param String $unit km else no unit used
144
-	* @return Float Distance in $unit
145
-	*/
138
+	 * Give distance between 2 coordonnates
139
+	 * @param Float $lat latitude of first point
140
+	 * @param Float $lon longitude of first point
141
+	 * @param Float $latc latitude of second point
142
+	 * @param Float $lonc longitude of second point
143
+	 * @param String $unit km else no unit used
144
+	 * @return Float Distance in $unit
145
+	 */
146 146
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
147 147
 		if ($lat == $latc && $lon == $lonc) return 0;
148 148
 		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 	}
161 161
 
162 162
 	/**
163
-	* Check is distance realistic
164
-	* @param int $timeDifference the time between the reception of both messages
165
-	* @param float $distance distance covered
166
-	* @return whether distance is realistic
167
-	*/
163
+	 * Check is distance realistic
164
+	 * @param int $timeDifference the time between the reception of both messages
165
+	 * @param float $distance distance covered
166
+	 * @return whether distance is realistic
167
+	 */
168 168
 	public function withinThreshold ($timeDifference, $distance) {
169 169
 		$x = abs($timeDifference);
170 170
 		$d = abs($distance);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	}
183 183
 
184 184
 	public function isInteger($input){
185
-	    return(ctype_digit(strval($input)));
185
+		return(ctype_digit(strval($input)));
186 186
 	}
187 187
 
188 188
 
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 	}
199 199
 	
200 200
 	/**
201
-	* Copy folder contents
202
-	* @param       string   $source    Source path
203
-	* @param       string   $dest      Destination path
204
-	* @return      bool     Returns true on success, false on failure
205
-	*/
201
+	 * Copy folder contents
202
+	 * @param       string   $source    Source path
203
+	 * @param       string   $dest      Destination path
204
+	 * @return      bool     Returns true on success, false on failure
205
+	 */
206 206
 	public function xcopy($source, $dest)
207 207
 	{
208 208
 		$files = glob($source.'*.*');
@@ -214,20 +214,20 @@  discard block
 block discarded – undo
214 214
 	}
215 215
 	
216 216
 	/**
217
-	* Check if an url exist
218
-	* @param	String $url url to check
219
-	* @return	bool Return true on succes false on failure
220
-	*/
217
+	 * Check if an url exist
218
+	 * @param	String $url url to check
219
+	 * @return	bool Return true on succes false on failure
220
+	 */
221 221
 	public function urlexist($url){
222 222
 		$headers=get_headers($url);
223 223
 		return stripos($headers[0],"200 OK")?true:false;
224 224
 	}
225 225
 	
226 226
 	/**
227
-	* Convert hexa to string
228
-	* @param	String $hex data in hexa
229
-	* @return	String Return result
230
-	*/
227
+	 * Convert hexa to string
228
+	 * @param	String $hex data in hexa
229
+	 * @return	String Return result
230
+	 */
231 231
 	public function hex2str($hex) {
232 232
 		$str = '';
233 233
 		$hexln = strlen($hex);
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 	}
276 276
 	
277 277
 	/**
278
-	* Returns list of available locales
279
-	*
280
-	* @return array
278
+	 * Returns list of available locales
279
+	 *
280
+	 * @return array
281 281
 	 */
282 282
 	public function listLocaleDir()
283 283
 	{
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
 	* @param Array $headers header to submit with the form
14 14
 	* @return String the result
15 15
 	*/
16
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
16
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') {
17 17
 		$ch = curl_init();
18 18
 		curl_setopt($ch, CURLOPT_URL, $url);
19 19
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20 20
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
21 21
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
22
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
22
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
23 23
 		//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');
24 24
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
25 25
 		if ($useragent == '') {
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 		}
30 30
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
31 31
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
32
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
32
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
33 33
 		if ($type == 'post') {
34 34
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
35 35
 			if (is_array($data)) {
36 36
 				curl_setopt($ch, CURLOPT_POST, count($data));
37 37
 				$data_string = '';
38
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
38
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
39 39
 				rtrim($data_string, '&');
40 40
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
41 41
 			} else {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		}
48 48
 		if ($cookie != '') {
49 49
 			if (is_array($cookie)) {
50
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
50
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
51 51
 			} else {
52 52
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
53 53
 			}
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 		$result = curl_exec($ch);
59 59
 		$info = curl_getinfo($ch);
60 60
 		curl_close($ch);
61
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
61
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
62 62
 			echo "Cloudflare Detected\n";
63 63
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
64 64
 			$useragent = UAgent::random();
65 65
 			cloudflare::useUserAgent($useragent);
66 66
 			if ($clearanceCookie = cloudflare::bypass($url)) {
67
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
67
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
68 68
 			}
69 69
 		} else {
70 70
 		    return $result;
@@ -89,27 +89,27 @@  discard block
 block discarded – undo
89 89
 		if ($data == '') return array();
90 90
 		$html = str_get_html($data);
91 91
 		if ($html === false) return array();
92
-		$tabledata=array();
93
-		foreach($html->find('tr') as $element)
92
+		$tabledata = array();
93
+		foreach ($html->find('tr') as $element)
94 94
 		{
95 95
 			$td = array();
96
-			foreach( $element->find('th') as $row)
96
+			foreach ($element->find('th') as $row)
97 97
 			{
98 98
 				$td [] = trim($row->plaintext);
99 99
 			}
100
-			$td=array_filter($td);
100
+			$td = array_filter($td);
101 101
 			$tabledata[] = $td;
102 102
 
103 103
 			$td = array();
104 104
 			$tdi = array();
105
-			foreach( $element->find('td') as $row)
105
+			foreach ($element->find('td') as $row)
106 106
 			{
107 107
 				$td [] = trim($row->plaintext);
108 108
 				$tdi [] = trim($row->innertext);
109 109
 			}
110
-			$td=array_filter($td);
111
-			$tdi=array_filter($tdi);
112
-			$tabledata[]=array_merge($td,$tdi);
110
+			$td = array_filter($td);
111
+			$tdi = array_filter($tdi);
112
+			$tabledata[] = array_merge($td, $tdi);
113 113
 		}
114 114
 		$html->clear();
115 115
 		unset($html);
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 	public function text2array($data) {
125 125
 		$html = str_get_html($data);
126 126
 		if ($html === false) return array();
127
-		$tabledata=array();
128
-		foreach($html->find('p') as $element)
127
+		$tabledata = array();
128
+		foreach ($html->find('p') as $element)
129 129
 		{
130 130
 			$tabledata [] = trim($element->plaintext);
131 131
 		}
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 	*/
146 146
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
147 147
 		if ($lat == $latc && $lon == $lonc) return 0;
148
-		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
148
+		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc))) + cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon) - floatval($lonc)))))*60*1.1515;
149 149
 		if ($unit == "km") {
150
-			return round($dist * 1.609344);
150
+			return round($dist*1.609344);
151 151
 		} elseif ($unit == "m") {
152
-			return round($dist * 1.609344 * 1000);
152
+			return round($dist*1.609344*1000);
153 153
 		} elseif ($unit == "mile" || $unit == "mi") {
154 154
 			return round($dist);
155 155
 		} elseif ($unit == "nm") {
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	* @param float $distance distance covered
166 166
 	* @return whether distance is realistic
167 167
 	*/
168
-	public function withinThreshold ($timeDifference, $distance) {
168
+	public function withinThreshold($timeDifference, $distance) {
169 169
 		$x = abs($timeDifference);
170 170
 		$d = abs($distance);
171 171
 		if ($x == 0 || $d == 0) return true;
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 		return ($array !== array_values($array));
182 182
 	}
183 183
 
184
-	public function isInteger($input){
184
+	public function isInteger($input) {
185 185
 	    return(ctype_digit(strval($input)));
186 186
 	}
187 187
 
188 188
 
189
-	public function convertDec($dms,$latlong) {
189
+	public function convertDec($dms, $latlong) {
190 190
 		if ($latlong == 'latitude') {
191 191
 			$deg = substr($dms, 0, 2);
192 192
 			$min = substr($dms, 2, 4);
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 			$deg = substr($dms, 0, 3);
195 195
 			$min = substr($dms, 3, 5);
196 196
 		}
197
-		return $deg+(($min*60)/3600);
197
+		return $deg + (($min*60)/3600);
198 198
 	}
199 199
 	
200 200
 	/**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	public function xcopy($source, $dest)
207 207
 	{
208 208
 		$files = glob($source.'*.*');
209
-		foreach($files as $file){
210
-			$file_to_go = str_replace($source,$dest,$file);
209
+		foreach ($files as $file) {
210
+			$file_to_go = str_replace($source, $dest, $file);
211 211
 			copy($file, $file_to_go);
212 212
 		}
213 213
 		return true;
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 	* @param	String $url url to check
219 219
 	* @return	bool Return true on succes false on failure
220 220
 	*/
221
-	public function urlexist($url){
222
-		$headers=get_headers($url);
223
-		return stripos($headers[0],"200 OK")?true:false;
221
+	public function urlexist($url) {
222
+		$headers = get_headers($url);
223
+		return stripos($headers[0], "200 OK") ? true : false;
224 224
 	}
225 225
 	
226 226
 	/**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	public function hex2str($hex) {
232 232
 		$str = '';
233 233
 		$hexln = strlen($hex);
234
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
234
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
235 235
 		return $str;
236 236
 	}
237 237
 	
@@ -240,33 +240,33 @@  discard block
 block discarded – undo
240 240
 		//difference in longitudinal coordinates
241 241
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
242 242
 		//difference in the phi of latitudinal coordinates
243
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
243
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
244 244
 		//we need to recalculate $dLon if it is greater than pi
245
-		if(abs($dLon) > pi()) {
246
-			if($dLon > 0) {
247
-				$dLon = (2 * pi() - $dLon) * -1;
245
+		if (abs($dLon) > pi()) {
246
+			if ($dLon > 0) {
247
+				$dLon = (2*pi() - $dLon)*-1;
248 248
 			} else {
249
-				$dLon = 2 * pi() + $dLon;
249
+				$dLon = 2*pi() + $dLon;
250 250
 			}
251 251
 		}
252 252
 		//return the angle, normalized
253
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
253
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
254 254
 	}
255 255
 	
256
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.1) {
256
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.1) {
257 257
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
258
-		$a = -($lon2-$lon1);
258
+		$a = -($lon2 - $lon1);
259 259
 		$b = $lat2 - $lat1;
260
-		$c = -($a*$lat1+$b*$lon1);
261
-		$d = $a*$lat3+$b*$lon3+$c;
260
+		$c = -($a*$lat1 + $b*$lon1);
261
+		$d = $a*$lat3 + $b*$lon3 + $c;
262 262
 		if ($d > -$approx && $d < $approx) return true;
263 263
 		else return false;
264 264
 	}
265 265
 	
266 266
 	public function array_merge_noappend() {
267 267
 		$output = array();
268
-		foreach(func_get_args() as $array) {
269
-			foreach($array as $key => $value) {
268
+		foreach (func_get_args() as $array) {
269
+			foreach ($array as $key => $value) {
270 270
 				$output[$key] = isset($output[$key]) ?
271 271
 				array_merge($output[$key], $value) : $value;
272 272
 			}
@@ -297,34 +297,34 @@  discard block
 block discarded – undo
297 297
 		return $result;
298 298
 	}
299 299
 
300
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
300
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
301 301
 		global $globalMapRefresh;
302 302
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
303 303
 		$r = 6378;
304 304
 		$latitude = deg2rad($latitude);
305 305
 		$longitude = deg2rad($longitude);
306 306
 		$bearing = deg2rad($heading); 
307
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
308
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
309
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
307
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
308
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
309
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
310 310
 	}
311 311
 	
312
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
312
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
313 313
 		// distance in meter
314 314
 		$R = 6378.14;
315
-		$latitude1 = $latitude * (M_PI/180);
316
-		$longitude1 = $longitude * (M_PI/180);
317
-		$brng = $bearing * (M_PI/180);
315
+		$latitude1 = $latitude*(M_PI/180);
316
+		$longitude1 = $longitude*(M_PI/180);
317
+		$brng = $bearing*(M_PI/180);
318 318
 		$d = $distance;
319 319
 
320 320
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
321
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
321
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
322 322
 
323
-		$latitude2 = $latitude2 * (180/M_PI);
324
-		$longitude2 = $longitude2 * (180/M_PI);
323
+		$latitude2 = $latitude2*(180/M_PI);
324
+		$longitude2 = $longitude2*(180/M_PI);
325 325
 
326
-		$flat = round ($latitude2,6);
327
-		$flong = round ($longitude2,6);
326
+		$flat = round($latitude2, 6);
327
+		$flong = round($longitude2, 6);
328 328
 /*
329 329
 		$dx = $distance*cos($bearing);
330 330
 		$dy = $distance*sin($bearing);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		$flong = $longitude + $dlong;
334 334
 		$flat = $latitude + $dlat;
335 335
 */
336
-		return array('latitude' => $flat,'longitude' => $flong);
336
+		return array('latitude' => $flat, 'longitude' => $flong);
337 337
 	}
338 338
 }
339 339
 ?>
340 340
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +9 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,6 +79,10 @@  discard block
 block discarded – undo
79 79
 		return strlen($headerLine); // Needed by curl
80 80
 	}
81 81
 
82
+	/**
83
+	 * @param string $url
84
+	 * @param string $file
85
+	 */
82 86
 	public static function download($url, $file, $referer = '') {
83 87
 		$fp = fopen($file, 'w+');
84 88
 		$ch = curl_init();
@@ -177,7 +181,7 @@  discard block
 block discarded – undo
177 181
 	* Check is distance realistic
178 182
 	* @param int $timeDifference the time between the reception of both messages
179 183
 	* @param float $distance distance covered
180
-	* @return whether distance is realistic
184
+	* @return boolean distance is realistic
181 185
 	*/
182 186
 	public function withinThreshold ($timeDifference, $distance) {
183 187
 		$x = abs($timeDifference);
@@ -200,6 +204,9 @@  discard block
 block discarded – undo
200 204
 	}
201 205
 
202 206
 
207
+	/**
208
+	 * @param string $latlong
209
+	 */
203 210
 	public function convertDec($dms,$latlong) {
204 211
 		if ($latlong == 'latitude') {
205 212
 			$deg = substr($dms, 0, 2);
@@ -301,7 +308,7 @@  discard block
 block discarded – undo
301 308
 	/**
302 309
 	* Returns list of available locales
303 310
 	*
304
-	* @return array
311
+	* @return string[]
305 312
 	 */
306 313
 	public function listLocaleDir()
307 314
 	{
Please login to merge, or discard this patch.
Braces   +49 added lines, -18 removed lines patch added patch discarded remove patch
@@ -27,8 +27,11 @@  discard block
 block discarded – undo
27 27
 		} else {
28 28
 			curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
29 29
 		}
30
-		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
31
-		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
30
+		if ($timeout == '') {
31
+			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
32
+		} else {
33
+			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
34
+		}
32 35
 		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
33 36
 		if ($type == 'post') {
34 37
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -74,8 +77,9 @@  discard block
 block discarded – undo
74 77
 	private function curlResponseHeaderCallback($ch, $headerLine) {
75 78
 		//global $cookies;
76 79
 		$cookies = array();
77
-		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
78
-			$cookies[] = $cookie;
80
+		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) {
81
+					$cookies[] = $cookie;
82
+		}
79 83
 		return strlen($headerLine); // Needed by curl
80 84
 	}
81 85
 
@@ -86,11 +90,15 @@  discard block
 block discarded – undo
86 90
 		curl_setopt($ch, CURLOPT_URL, $url);
87 91
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
88 92
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
89
-		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
93
+		if ($referer != '') {
94
+			curl_setopt($ch, CURLOPT_REFERER, $referer);
95
+		}
90 96
 		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');
91 97
 		curl_setopt($ch, CURLOPT_FILE, $fp);
92 98
 		curl_exec($ch);
93
-		if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch);
99
+		if (curl_errno($ch) && $globalDebug) {
100
+			echo 'Download error: '.curl_error($ch);
101
+		}
94 102
 		curl_close($ch);
95 103
 		fclose($fp);
96 104
 	}
@@ -101,10 +109,16 @@  discard block
 block discarded – undo
101 109
 	* @return Array array of the tables in HTML page
102 110
 	*/
103 111
 	public function table2array($data) {
104
-		if (!is_string($data)) return array();
105
-		if ($data == '') return array();
112
+		if (!is_string($data)) {
113
+			return array();
114
+		}
115
+		if ($data == '') {
116
+			return array();
117
+		}
106 118
 		$html = str_get_html($data);
107
-		if ($html === false) return array();
119
+		if ($html === false) {
120
+			return array();
121
+		}
108 122
 		$tabledata=array();
109 123
 		foreach($html->find('tr') as $element)
110 124
 		{
@@ -139,7 +153,9 @@  discard block
 block discarded – undo
139 153
 	*/
140 154
 	public function text2array($data) {
141 155
 		$html = str_get_html($data);
142
-		if ($html === false) return array();
156
+		if ($html === false) {
157
+			return array();
158
+		}
143 159
 		$tabledata=array();
144 160
 		foreach($html->find('p') as $element)
145 161
 		{
@@ -160,7 +176,9 @@  discard block
 block discarded – undo
160 176
 	* @return Float Distance in $unit
161 177
 	*/
162 178
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
163
-		if ($lat == $latc && $lon == $lonc) return 0;
179
+		if ($lat == $latc && $lon == $lonc) {
180
+			return 0;
181
+		}
164 182
 		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
165 183
 		if ($unit == "km") {
166 184
 			return round($dist * 1.609344);
@@ -184,10 +202,16 @@  discard block
 block discarded – undo
184 202
 	public function withinThreshold ($timeDifference, $distance) {
185 203
 		$x = abs($timeDifference);
186 204
 		$d = abs($distance);
187
-		if ($x == 0 || $d == 0) return true;
205
+		if ($x == 0 || $d == 0) {
206
+			return true;
207
+		}
188 208
 		// may be due to Internet jitter; distance is realistic
189
-		if ($x < 0.7 && $d < 2000) return true;
190
-		else return $d/$x < 1500*0.27778; // 1500 km/h max
209
+		if ($x < 0.7 && $d < 2000) {
210
+			return true;
211
+		} else {
212
+			return $d/$x < 1500*0.27778;
213
+		}
214
+		// 1500 km/h max
191 215
 	}
192 216
 
193 217
 
@@ -247,7 +271,9 @@  discard block
 block discarded – undo
247 271
 	public function hex2str($hex) {
248 272
 		$str = '';
249 273
 		$hexln = strlen($hex);
250
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
274
+		for($i=0;$i<$hexln;$i+=2) {
275
+			$str .= chr(hexdec(substr($hex,$i,2)));
276
+		}
251 277
 		return $str;
252 278
 	}
253 279
 	
@@ -275,8 +301,11 @@  discard block
 block discarded – undo
275 301
 		$b = $lat2 - $lat1;
276 302
 		$c = -($a*$lat1+$b*$lon1);
277 303
 		$d = $a*$lat3+$b*$lon3+$c;
278
-		if ($d > -$approx && $d < $approx) return true;
279
-		else return false;
304
+		if ($d > -$approx && $d < $approx) {
305
+			return true;
306
+		} else {
307
+			return false;
308
+		}
280 309
 	}
281 310
 	
282 311
 	public function array_merge_noappend() {
@@ -312,7 +341,9 @@  discard block
 block discarded – undo
312 341
 			return $result;
313 342
 		}
314 343
 		$handle = @opendir('./locale');
315
-		if ($handle === false) return $result;
344
+		if ($handle === false) {
345
+			return $result;
346
+		}
316 347
 		while (false !== ($file = readdir($handle))) {
317 348
 			$path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo';
318 349
 			if ($file != "." && $file != ".." && @file_exists($path)) {
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.
require/libs/Predict/Predict/SGPSDP.php 5 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -67,6 +67,10 @@  discard block
 block discarded – undo
67 67
     /* structure with Keplerian orbital elements and pos and vel    */
68 68
     /* are vector_t structures returning ECI satellite position and */
69 69
     /* velocity. Use Convert_Sat_State() to convert to km and km/s.*/
70
+
71
+    /**
72
+     * @param double $tsince
73
+     */
70 74
     public function SGP4(Predict_Sat $sat, $tsince)
71 75
     {
72 76
         /* Initialization */
@@ -312,6 +316,10 @@  discard block
 block discarded – undo
312 316
     /* structure with Keplerian orbital elements and pos and vel    */
313 317
     /* are vector_t structures returning ECI satellite position and */
314 318
     /* velocity. Use Convert_Sat_State() to convert to km and km/s. */
319
+
320
+    /**
321
+     * @param double $tsince
322
+     */
315 323
     public function SDP4(Predict_Sat $sat, $tsince)
316 324
     {
317 325
         /* Initialization */
@@ -538,6 +546,10 @@  discard block
 block discarded – undo
538 546
     /* DEEP */
539 547
     /* This function is used by SDP4 to add lunar and solar */
540 548
     /* perturbation effects to deep-space orbit objects.    */
549
+
550
+    /**
551
+     * @param integer $ientry
552
+     */
541 553
     public function Deep($ientry, Predict_Sat $sat)
542 554
     {
543 555
         switch ($ientry) {
Please login to merge, or discard this patch.
Indentation   +1031 added lines, -1031 removed lines patch added patch discarded remove patch
@@ -23,1037 +23,1037 @@
 block discarded – undo
23 23
  */
24 24
 class Predict_SGPSDP
25 25
 {
26
-    const ALL_FLAGS             = -1;
27
-    const SGP_INITIALIZED_FLAG  = 0x000001;
28
-    const SGP4_INITIALIZED_FLAG = 0x000002;
29
-    const SDP4_INITIALIZED_FLAG = 0x000004;
30
-    const SGP8_INITIALIZED_FLAG = 0x000008;
31
-    const SDP8_INITIALIZED_FLAG = 0x000010;
32
-    const SIMPLE_FLAG           = 0x000020;
33
-    const DEEP_SPACE_EPHEM_FLAG = 0x000040;
34
-    const LUNAR_TERMS_DONE_FLAG = 0x000080;
35
-    const NEW_EPHEMERIS_FLAG    = 0x000100;
36
-    const DO_LOOP_FLAG          = 0x000200;
37
-    const RESONANCE_FLAG        = 0x000400;
38
-    const SYNCHRONOUS_FLAG      = 0x000800;
39
-    const EPOCH_RESTART_FLAG    = 0x001000;
40
-    const VISIBLE_FLAG          = 0x002000;
41
-    const SAT_ECLIPSED_FLAG     = 0x004000;
42
-
43
-    /* orbit_type_t struct */
44
-    const ORBIT_TYPE_UNKNOWN = 0;
45
-    const ORBIT_TYPE_LEO     = 1;            /*!< Low Earth orbit, up to 1200 km. */
46
-    const ORBIT_TYPE_ICO     = 2;            /*!< Intermediate Circular Orbit, up to 1400 km. */
47
-    const ORBIT_TYPE_GEO     = 3;            /*!< Geostationary. */
48
-    const ORBIT_TYPE_GSO     = 4;            /*!< Geosynchronuous. */
49
-    const ORBIT_TYPE_MOLNIYA = 5;
50
-    const ORBIT_TYPE_TUNDRA  = 6;
51
-    const ORBIT_TYPE_POLAR   = 7;
52
-    const ORBIT_TYPE_SUNSYNC = 8;
53
-    const ORBIT_TYPE_DECAYED = 9;
54
-
55
-
56
-
57
-    /* Entry points of Deep()
26
+	const ALL_FLAGS             = -1;
27
+	const SGP_INITIALIZED_FLAG  = 0x000001;
28
+	const SGP4_INITIALIZED_FLAG = 0x000002;
29
+	const SDP4_INITIALIZED_FLAG = 0x000004;
30
+	const SGP8_INITIALIZED_FLAG = 0x000008;
31
+	const SDP8_INITIALIZED_FLAG = 0x000010;
32
+	const SIMPLE_FLAG           = 0x000020;
33
+	const DEEP_SPACE_EPHEM_FLAG = 0x000040;
34
+	const LUNAR_TERMS_DONE_FLAG = 0x000080;
35
+	const NEW_EPHEMERIS_FLAG    = 0x000100;
36
+	const DO_LOOP_FLAG          = 0x000200;
37
+	const RESONANCE_FLAG        = 0x000400;
38
+	const SYNCHRONOUS_FLAG      = 0x000800;
39
+	const EPOCH_RESTART_FLAG    = 0x001000;
40
+	const VISIBLE_FLAG          = 0x002000;
41
+	const SAT_ECLIPSED_FLAG     = 0x004000;
42
+
43
+	/* orbit_type_t struct */
44
+	const ORBIT_TYPE_UNKNOWN = 0;
45
+	const ORBIT_TYPE_LEO     = 1;            /*!< Low Earth orbit, up to 1200 km. */
46
+	const ORBIT_TYPE_ICO     = 2;            /*!< Intermediate Circular Orbit, up to 1400 km. */
47
+	const ORBIT_TYPE_GEO     = 3;            /*!< Geostationary. */
48
+	const ORBIT_TYPE_GSO     = 4;            /*!< Geosynchronuous. */
49
+	const ORBIT_TYPE_MOLNIYA = 5;
50
+	const ORBIT_TYPE_TUNDRA  = 6;
51
+	const ORBIT_TYPE_POLAR   = 7;
52
+	const ORBIT_TYPE_SUNSYNC = 8;
53
+	const ORBIT_TYPE_DECAYED = 9;
54
+
55
+
56
+
57
+	/* Entry points of Deep()
58 58
     // FIXME: Change to enu */
59
-    const dpinit = 1; /* Deep-space initialization code */
60
-    const dpsec  = 2; /* Deep-space secular code        */
61
-    const dpper  = 3; /* Deep-space periodic code       */
62
-
63
-    /* SGP4 */
64
-    /* This function is used to calculate the position and velocity */
65
-    /* of near-earth (period < 225 minutes) satellites. tsince is   */
66
-    /* time since epoch in minutes, tle is a pointer to a tle_t     */
67
-    /* structure with Keplerian orbital elements and pos and vel    */
68
-    /* are vector_t structures returning ECI satellite position and */
69
-    /* velocity. Use Convert_Sat_State() to convert to km and km/s.*/
70
-    public function SGP4(Predict_Sat $sat, $tsince)
71
-    {
72
-        /* Initialization */
73
-        if (~$sat->flags & self::SGP4_INITIALIZED_FLAG) {
74
-            $sat->flags |= self::SGP4_INITIALIZED_FLAG;
75
-
76
-            /* Recover original mean motion (xnodp) and   */
77
-            /* semimajor axis (aodp) from input elements. */
78
-            $a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
79
-            $sat->sgps->cosio = cos($sat->tle->xincl);
80
-            $theta2 = $sat->sgps->cosio * $sat->sgps->cosio;
81
-            $sat->sgps->x3thm1 = 3 * $theta2 - 1.0;
82
-            $eosq = $sat->tle->eo * $sat->tle->eo;
83
-            $betao2 = 1 - $eosq;
84
-            $betao = sqrt($betao2);
85
-            $del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($a1 * $a1 * $betao * $betao2);
86
-            $ao = $a1 * (1 - $del1 * (0.5 * Predict::tothrd + $del1 * (1 + 134.0 / 81.0 * $del1)));
87
-            $delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($ao * $ao * $betao * $betao2);
88
-            $sat->sgps->xnodp = $sat->tle->xno / (1.0 + $delo);
89
-            $sat->sgps->aodp = $ao / (1.0 - $delo);
90
-
91
-            /* For perigee less than 220 kilometers, the "simple" flag is set */
92
-            /* and the equations are truncated to linear variation in sqrt a  */
93
-            /* and quadratic variation in mean anomaly.  Also, the c3 term,   */
94
-            /* the delta omega term, and the delta m term are dropped.        */
95
-            if (($sat->sgps->aodp * (1.0 - $sat->tle->eo) / Predict::ae) < (220.0 / Predict::xkmper + Predict::ae)) {
96
-                $sat->flags |= self::SIMPLE_FLAG;
97
-            } else {
98
-                $sat->flags &= ~self::SIMPLE_FLAG;
99
-            }
100
-
101
-            /* For perigee below 156 km, the       */
102
-            /* values of s and qoms2t are altered. */
103
-            $s4 = Predict::__s__;
104
-            $qoms24 = Predict::qoms2t;
105
-            $perige = ($sat->sgps->aodp * (1 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
106
-            if ($perige < 156.0) {
107
-                if ($perige <= 98.0) {
108
-                    $s4 = 20.0;
109
-                } else {
110
-                    $s4 = $perige - 78.0;
111
-                }
112
-                $qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
113
-                $s4 = $s4 / Predict::xkmper + Predict::ae;
114
-            }; /* FIXME FIXME: End of if(perige <= 98) NO WAY!!!! */
115
-
116
-            $pinvsq = 1.0 / ($sat->sgps->aodp * $sat->sgps->aodp * $betao2 * $betao2);
117
-            $tsi = 1.0 / ($sat->sgps->aodp - $s4);
118
-            $sat->sgps->eta = $sat->sgps->aodp * $sat->tle->eo * $tsi;
119
-            $etasq = $sat->sgps->eta * $sat->sgps->eta;
120
-            $eeta = $sat->tle->eo * $sat->sgps->eta;
121
-            $psisq = abs(1.0 - $etasq);
122
-            $coef = $qoms24 * pow($tsi, 4);
123
-            $coef1 = $coef / pow($psisq, 3.5);
124
-            $c2 = $coef1 * $sat->sgps->xnodp * ($sat->sgps->aodp *
125
-                            (1.0 + 1.5 * $etasq + $eeta * (4.0 + $etasq)) +
126
-                            0.75 * Predict::ck2 * $tsi / $psisq * $sat->sgps->x3thm1 *
127
-                            (8.0 + 3.0 * $etasq * (8 + $etasq)));
128
-            $sat->sgps->c1 = $c2 * $sat->tle->bstar;
129
-            $sat->sgps->sinio = sin($sat->tle->xincl);
130
-            $a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
131
-            $c3 = $coef * $tsi * $a3ovk2 * $sat->sgps->xnodp * Predict::ae * $sat->sgps->sinio / $sat->tle->eo;
132
-            $sat->sgps->x1mth2 = 1.0 - $theta2;
133
-            $sat->sgps->c4 = 2.0 * $sat->sgps->xnodp * $coef1 * $sat->sgps->aodp * $betao2 *
134
-                ($sat->sgps->eta * (2.0 + 0.5 * $etasq) +
135
-                 $sat->tle->eo * (0.5 + 2.0 * $etasq) -
136
-                 2.0 * Predict::ck2 * $tsi / ($sat->sgps->aodp * $psisq) *
137
-                 (-3.0 * $sat->sgps->x3thm1 * (1.0 - 2.0 * $eeta + $etasq * (1.5 - 0.5 * $eeta)) +
138
-                  0.75 * $sat->sgps->x1mth2 * (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
139
-                  cos(2.0 * $sat->tle->omegao)));
140
-            $sat->sgps->c5 = 2.0 * $coef1 * $sat->sgps->aodp * $betao2 *
141
-                (1.0 + 2.75 * ($etasq + $eeta) + $eeta * $etasq);
142
-            $theta4 = $theta2 * $theta2;
143
-            $temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->sgps->xnodp;
144
-            $temp2 = $temp1 * Predict::ck2 * $pinvsq;
145
-            $temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->sgps->xnodp;
146
-            $sat->sgps->xmdot = $sat->sgps->xnodp + 0.5 * $temp1 * $betao * $sat->sgps->x3thm1 +
147
-                0.0625 * $temp2 * $betao * (13.0 - 78.0 * $theta2 + 137.0 * $theta4);
148
-            $x1m5th = 1.0 - 5.0 * $theta2;
149
-            $sat->sgps->omgdot = -0.5 * $temp1 * $x1m5th +
150
-                0.0625 * $temp2 * (7.0 - 114.0 * $theta2 + 395.0 * $theta4) +
151
-                $temp3 * (3.0 - 36.0 * $theta2 + 49.0 * $theta4);
152
-            $xhdot1 = -$temp1 * $sat->sgps->cosio;
153
-            $sat->sgps->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $theta2) +
154
-                             2.0 * $temp3 * (3.0 - 7.0 * $theta2)) * $sat->sgps->cosio;
155
-            $sat->sgps->omgcof = $sat->tle->bstar * $c3 * cos($sat->tle->omegao);
156
-            $sat->sgps->xmcof = -Predict::tothrd * $coef * $sat->tle->bstar * Predict::ae / $eeta;
157
-            $sat->sgps->xnodcf = 3.5 * $betao2 * $xhdot1 * $sat->sgps->c1;
158
-            $sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
159
-            $sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->sgps->sinio *
160
-                (3.0 + 5.0 * $sat->sgps->cosio) / (1.0 + $sat->sgps->cosio);
161
-            $sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->sgps->sinio;
162
-            $sat->sgps->delmo = pow(1.0 + $sat->sgps->eta * cos($sat->tle->xmo), 3);
163
-            $sat->sgps->sinmo = sin($sat->tle->xmo);
164
-            $sat->sgps->x7thm1 = 7.0 * $theta2 - 1.0;
165
-            if (~$sat->flags & self::SIMPLE_FLAG) {
166
-                $c1sq = $sat->sgps->c1 * $sat->sgps->c1;
167
-                $sat->sgps->d2 = 4.0 * $sat->sgps->aodp * $tsi * $c1sq;
168
-                $temp = $sat->sgps->d2 * $tsi * $sat->sgps->c1 / 3.0;
169
-                $sat->sgps->d3 = (17.0 * $sat->sgps->aodp + $s4) * $temp;
170
-                $sat->sgps->d4 = 0.5 * $temp * $sat->sgps->aodp * $tsi *
171
-                    (221.0 * $sat->sgps->aodp + 31.0 * $s4) * $sat->sgps->c1;
172
-                $sat->sgps->t3cof = $sat->sgps->d2 + 2.0 * $c1sq;
173
-                $sat->sgps->t4cof = 0.25 * (3.0 * $sat->sgps->d3 + $sat->sgps->c1 *
174
-                              (12.0 * $sat->sgps->d2 + 10.0 * $c1sq));
175
-                $sat->sgps->t5cof = 0.2 * (3.0 * $sat->sgps->d4 +
176
-                             12.0 * $sat->sgps->c1 * $sat->sgps->d3 +
177
-                             6.0 * $sat->sgps->d2 * $sat->sgps->d2 +
178
-                             15.0 * $c1sq * (2.0 * $sat->sgps->d2 + $c1sq));
179
-            }; /* End of if (isFlagClear(SIMPLE_FLAG)) */
180
-        }; /* End of SGP4() initialization */
181
-
182
-        /* Update for secular gravity and atmospheric drag. */
183
-        $xmdf = $sat->tle->xmo + $sat->sgps->xmdot * $tsince;
184
-        $omgadf = $sat->tle->omegao + $sat->sgps->omgdot * $tsince;
185
-        $xnoddf = $sat->tle->xnodeo + $sat->sgps->xnodot * $tsince;
186
-        $omega = $omgadf;
187
-        $xmp = $xmdf;
188
-        $tsq = $tsince * $tsince;
189
-        $xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
190
-        $tempa = 1.0 - $sat->sgps->c1 * $tsince;
191
-        $tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
192
-        $templ = $sat->sgps->t2cof * $tsq;
193
-        if (~$sat->flags & self::SIMPLE_FLAG) {
194
-            $delomg = $sat->sgps->omgcof * $tsince;
195
-            $delm = $sat->sgps->xmcof * (pow(1 + $sat->sgps->eta * cos($xmdf), 3) - $sat->sgps->delmo);
196
-            $temp = $delomg + $delm;
197
-            $xmp = $xmdf + $temp;
198
-            $omega = $omgadf - $temp;
199
-            $tcube = $tsq * $tsince;
200
-            $tfour = $tsince * $tcube;
201
-            $tempa = $tempa - $sat->sgps->d2 * $tsq - $sat->sgps->d3 * $tcube - $sat->sgps->d4 * $tfour;
202
-            $tempe = $tempe + $sat->tle->bstar * $sat->sgps->c5 * (sin($xmp) - $sat->sgps->sinmo);
203
-            $templ = $templ + $sat->sgps->t3cof * $tcube + $tfour *
204
-                ($sat->sgps->t4cof + $tsince * $sat->sgps->t5cof);
205
-        }; /* End of if (isFlagClear(SIMPLE_FLAG)) */
206
-
207
-        $a = $sat->sgps->aodp * pow($tempa, 2);
208
-        $e = $sat->tle->eo - $tempe;
209
-        $xl = $xmp + $omega + $xnode + $sat->sgps->xnodp * $templ;
210
-        $beta = sqrt(1.0 - ($e * $e));
211
-        $xn = Predict::xke / pow($a, 1.5);
212
-
213
-        /* Long period periodics */
214
-        $axn = $e * cos($omega);
215
-        $temp = 1.0 / ($a * $beta * $beta);
216
-        $xll = $temp * $sat->sgps->xlcof * $axn;
217
-        $aynl = $temp * $sat->sgps->aycof;
218
-        $xlt = $xl + $xll;
219
-        $ayn = $e * sin($omega) + $aynl;
220
-
221
-        /* Solve Kepler's' Equation */
222
-        $capu = Predict_Math::FMod2p($xlt - $xnode);
223
-        $temp2 = $capu;
224
-
225
-        $i = 0;
226
-        do {
227
-            $sinepw = sin($temp2);
228
-            $cosepw = cos($temp2);
229
-            $temp3 = $axn * $sinepw;
230
-            $temp4 = $ayn * $cosepw;
231
-            $temp5 = $axn * $cosepw;
232
-            $temp6 = $ayn * $sinepw;
233
-            $epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
234
-            if (abs($epw - $temp2) <= Predict::e6a) {
235
-                break;
236
-            }
237
-            $temp2 = $epw;
238
-        } while ($i++ < 10);
239
-
240
-        /* Short period preliminary quantities */
241
-        $ecose = $temp5 + $temp6;
242
-        $esine = $temp3 - $temp4;
243
-        $elsq = $axn * $axn + $ayn * $ayn;
244
-        $temp = 1.0 - $elsq;
245
-        $pl = $a * $temp;
246
-        $r = $a * (1.0 - $ecose);
247
-        $temp1 = 1.0 / $r;
248
-        $rdot = Predict::xke * sqrt($a) * $esine * $temp1;
249
-        $rfdot = Predict::xke * sqrt($pl) * $temp1;
250
-        $temp2 = $a * $temp1;
251
-        $betal = sqrt($temp);
252
-        $temp3 = 1.0 / (1.0 + $betal);
253
-        $cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
254
-        $sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
255
-        $u = Predict_Math::AcTan($sinu, $cosu);
256
-        $sin2u = 2.0 * $sinu * $cosu;
257
-        $cos2u = 2.0 * $cosu * $cosu - 1.0;
258
-        $temp = 1.0 / $pl;
259
-        $temp1 = Predict::ck2 * $temp;
260
-        $temp2 = $temp1 * $temp;
261
-
262
-        /* Update for short periodics */
263
-        $rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
264
-            0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
265
-        $uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
266
-        $xnodek = $xnode + 1.5 * $temp2 * $sat->sgps->cosio * $sin2u;
267
-        $xinck = $sat->tle->xincl + 1.5 * $temp2 * $sat->sgps->cosio * $sat->sgps->sinio * $cos2u;
268
-        $rdotk = $rdot - $xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
269
-        $rfdotk = $rfdot + $xn * $temp1 * ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
270
-
271
-
272
-        /* Orientation vectors */
273
-        $sinuk = sin($uk);
274
-        $cosuk = cos($uk);
275
-        $sinik = sin($xinck);
276
-        $cosik = cos($xinck);
277
-        $sinnok = sin($xnodek);
278
-        $cosnok = cos($xnodek);
279
-        $xmx = -$sinnok * $cosik;
280
-        $xmy = $cosnok * $cosik;
281
-        $ux = $xmx * $sinuk + $cosnok * $cosuk;
282
-        $uy = $xmy * $sinuk + $sinnok * $cosuk;
283
-        $uz = $sinik * $sinuk;
284
-        $vx = $xmx * $cosuk - $cosnok * $sinuk;
285
-        $vy = $xmy * $cosuk - $sinnok * $sinuk;
286
-        $vz = $sinik * $cosuk;
287
-
288
-        /* Position and velocity */
289
-        $sat->pos->x = $rk * $ux;
290
-        $sat->pos->y = $rk * $uy;
291
-        $sat->pos->z = $rk * $uz;
292
-        $sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
293
-        $sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
294
-        $sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
295
-
296
-        $sat->phase = $xlt - $xnode - $omgadf + Predict::twopi;
297
-        if ($sat->phase < 0) {
298
-            $sat->phase += Predict::twopi;
299
-        }
300
-        $sat->phase = Predict_Math::FMod2p($sat->phase);
301
-
302
-        $sat->tle->omegao1 = $omega;
303
-        $sat->tle->xincl1  = $xinck;
304
-        $sat->tle->xnodeo1 = $xnodek;
305
-
306
-    } /*SGP4*/
307
-
308
-    /* SDP4 */
309
-    /* This function is used to calculate the position and velocity */
310
-    /* of deep-space (period > 225 minutes) satellites. tsince is   */
311
-    /* time since epoch in minutes, tle is a pointer to a tle_t     */
312
-    /* structure with Keplerian orbital elements and pos and vel    */
313
-    /* are vector_t structures returning ECI satellite position and */
314
-    /* velocity. Use Convert_Sat_State() to convert to km and km/s. */
315
-    public function SDP4(Predict_Sat $sat, $tsince)
316
-    {
317
-        /* Initialization */
318
-        if (~$sat->flags & self::SDP4_INITIALIZED_FLAG) {
319
-
320
-            $sat->flags |= self::SDP4_INITIALIZED_FLAG;
321
-
322
-            /* Recover original mean motion (xnodp) and   */
323
-            /* semimajor axis (aodp) from input elements. */
324
-            $a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
325
-            $sat->deep_arg->cosio = cos($sat->tle->xincl);
326
-            $sat->deep_arg->theta2 = $sat->deep_arg->cosio * $sat->deep_arg->cosio;
327
-            $sat->sgps->x3thm1 = 3.0 * $sat->deep_arg->theta2 - 1.0;
328
-            $sat->deep_arg->eosq = $sat->tle->eo * $sat->tle->eo;
329
-            $sat->deep_arg->betao2 = 1.0 - $sat->deep_arg->eosq;
330
-            $sat->deep_arg->betao = sqrt($sat->deep_arg->betao2);
331
-            $del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
332
-                ($a1 * $a1 * $sat->deep_arg->betao * $sat->deep_arg->betao2);
333
-            $ao = $a1 * (1.0 - $del1 * (0.5 * Predict::tothrd + $del1 * (1.0 + 134.0 / 81.0 * $del1)));
334
-            $delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
335
-                ($ao * $ao * $sat->deep_arg->betao * $sat->deep_arg->betao2);
336
-            $sat->deep_arg->xnodp = $sat->tle->xno / (1.0 + $delo);
337
-            $sat->deep_arg->aodp = $ao / (1.0 - $delo);
338
-
339
-            /* For perigee below 156 km, the values */
340
-            /* of s and qoms2t are altered.         */
341
-            $s4 = Predict::__s__;
342
-            $qoms24 = Predict::qoms2t;
343
-            $perige = ($sat->deep_arg->aodp * (1.0 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
344
-            if ($perige < 156.0) {
345
-                if ($perige <= 98.0) {
346
-                    $s4 = 20.0;
347
-                } else {
348
-                    $s4 = $perige - 78.0;
349
-                }
350
-                $qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
351
-                $s4 = $s4 / Predict::xkmper + Predict::ae;
352
-            }
353
-            $pinvsq = 1.0 / ($sat->deep_arg->aodp * $sat->deep_arg->aodp *
354
-                    $sat->deep_arg->betao2 * $sat->deep_arg->betao2);
355
-            $sat->deep_arg->sing = sin($sat->tle->omegao);
356
-            $sat->deep_arg->cosg = cos($sat->tle->omegao);
357
-            $tsi = 1.0 / ($sat->deep_arg->aodp - $s4);
358
-            $eta = $sat->deep_arg->aodp * $sat->tle->eo * $tsi;
359
-            $etasq = $eta * $eta;
360
-            $eeta = $sat->tle->eo * $eta;
361
-            $psisq = abs(1.0 - $etasq);
362
-            $coef = $qoms24 * pow($tsi, 4);
363
-            $coef1 = $coef / pow($psisq, 3.5);
364
-            $c2 = $coef1 * $sat->deep_arg->xnodp * ($sat->deep_arg->aodp *
365
-                                (1.0 + 1.5 * $etasq + $eeta *
366
-                                 (4.0 + $etasq)) + 0.75 * Predict::ck2 * $tsi / $psisq *
367
-                                $sat->sgps->x3thm1 * (8.0 + 3.0 * $etasq *
368
-                                        (8.0 + $etasq)));
369
-            $sat->sgps->c1 = $sat->tle->bstar * $c2;
370
-            $sat->deep_arg->sinio = sin($sat->tle->xincl);
371
-            $a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
372
-            $sat->sgps->x1mth2 = 1.0 - $sat->deep_arg->theta2;
373
-            $sat->sgps->c4 = 2.0 * $sat->deep_arg->xnodp * $coef1 *
374
-                $sat->deep_arg->aodp * $sat->deep_arg->betao2 *
375
-                ($eta * (2.0 + 0.5 * $etasq) + $sat->tle->eo *
376
-                 (0.5 + 2.0 * $etasq) - 2.0 * Predict::ck2 * $tsi /
377
-                 ($sat->deep_arg->aodp * $psisq) * (-3.0 * $sat->sgps->x3thm1 *
378
-                                 (1.0 - 2.0 * $eeta + $etasq *
379
-                                  (1.5 - 0.5 * $eeta)) +
380
-                                 0.75 * $sat->sgps->x1mth2 *
381
-                                 (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
382
-                                 cos(2.0 * $sat->tle->omegao)));
383
-            $theta4 = $sat->deep_arg->theta2 * $sat->deep_arg->theta2;
384
-            $temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->deep_arg->xnodp;
385
-            $temp2 = $temp1 * Predict::ck2 * $pinvsq;
386
-            $temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->deep_arg->xnodp;
387
-            $sat->deep_arg->xmdot = $sat->deep_arg->xnodp + 0.5 * $temp1 * $sat->deep_arg->betao *
388
-                $sat->sgps->x3thm1 + 0.0625 * $temp2 * $sat->deep_arg->betao *
389
-                (13.0 - 78.0 * $sat->deep_arg->theta2 + 137.0 * $theta4);
390
-            $x1m5th = 1.0 - 5.0 * $sat->deep_arg->theta2;
391
-            $sat->deep_arg->omgdot = -0.5 * $temp1 * $x1m5th + 0.0625 * $temp2 *
392
-                            (7.0 - 114.0 * $sat->deep_arg->theta2 + 395.0 * $theta4) +
393
-                        $temp3 * (3.0 - 36.0 * $sat->deep_arg->theta2 + 49.0 * $theta4);
394
-            $xhdot1 = -$temp1 * $sat->deep_arg->cosio;
395
-            $sat->deep_arg->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $sat->deep_arg->theta2) +
396
-                             2.0 * $temp3 * (3.0 - 7.0 * $sat->deep_arg->theta2)) *
397
-                $sat->deep_arg->cosio;
398
-            $sat->sgps->xnodcf = 3.5 * $sat->deep_arg->betao2 * $xhdot1 * $sat->sgps->c1;
399
-            $sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
400
-            $sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->deep_arg->sinio *
401
-                (3.0 + 5.0 * $sat->deep_arg->cosio) / (1.0 + $sat->deep_arg->cosio);
402
-            $sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->deep_arg->sinio;
403
-            $sat->sgps->x7thm1 = 7.0 * $sat->deep_arg->theta2 - 1.0;
404
-
405
-            /* initialize Deep() */
406
-            $this->Deep(self::dpinit, $sat);
407
-        }; /*End of SDP4() initialization */
408
-
409
-        /* Update for secular gravity and atmospheric drag */
410
-        $xmdf = $sat->tle->xmo + $sat->deep_arg->xmdot * $tsince;
411
-        $sat->deep_arg->omgadf = $sat->tle->omegao + $sat->deep_arg->omgdot * $tsince;
412
-        $xnoddf = $sat->tle->xnodeo + $sat->deep_arg->xnodot * $tsince;
413
-        $tsq = $tsince * $tsince;
414
-        $sat->deep_arg->xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
415
-        $tempa = 1.0 - $sat->sgps->c1 * $tsince;
416
-        $tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
417
-        $templ = $sat->sgps->t2cof * $tsq;
418
-        $sat->deep_arg->xn = $sat->deep_arg->xnodp;
419
-
420
-        /* Update for deep-space secular effects */
421
-        $sat->deep_arg->xll = $xmdf;
422
-        $sat->deep_arg->t = $tsince;
423
-
424
-        $this->Deep(self::dpsec, $sat);
425
-
426
-        $xmdf = $sat->deep_arg->xll;
427
-        $a = pow(Predict::xke / $sat->deep_arg->xn, Predict::tothrd) * $tempa * $tempa;
428
-        $sat->deep_arg->em = $sat->deep_arg->em - $tempe;
429
-        $xmam = $xmdf + $sat->deep_arg->xnodp * $templ;
430
-
431
-        /* Update for deep-space periodic effects */
432
-        $sat->deep_arg->xll = $xmam;
433
-
434
-        $this->Deep(self::dpper, $sat);
435
-
436
-        $xmam = $sat->deep_arg->xll;
437
-        $xl = $xmam + $sat->deep_arg->omgadf + $sat->deep_arg->xnode;
438
-        $beta = sqrt(1.0 - $sat->deep_arg->em * $sat->deep_arg->em);
439
-        $sat->deep_arg->xn = Predict::xke / pow($a, 1.5);
440
-
441
-        /* Long period periodics */
442
-        $axn = $sat->deep_arg->em * cos($sat->deep_arg->omgadf);
443
-        $temp = 1.0 / ($a * $beta * $beta);
444
-        $xll = $temp * $sat->sgps->xlcof * $axn;
445
-        $aynl = $temp * $sat->sgps->aycof;
446
-        $xlt = $xl + $xll;
447
-        $ayn = $sat->deep_arg->em * sin($sat->deep_arg->omgadf) + $aynl;
448
-
449
-        /* Solve Kepler's Equation */
450
-        $capu = Predict_Math::FMod2p ($xlt - $sat->deep_arg->xnode);
451
-        $temp2 = $capu;
452
-
453
-        $i = 0;
454
-        do {
455
-            $sinepw = sin($temp2);
456
-            $cosepw = cos($temp2);
457
-            $temp3 = $axn * $sinepw;
458
-            $temp4 = $ayn * $cosepw;
459
-            $temp5 = $axn * $cosepw;
460
-            $temp6 = $ayn * $sinepw;
461
-            $epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
462
-            if (abs($epw - $temp2) <= Predict::e6a) {
463
-                break;
464
-            }
465
-            $temp2 = $epw;
466
-        } while ($i++ < 10);
467
-
468
-        /* Short period preliminary quantities */
469
-        $ecose = $temp5 + $temp6;
470
-        $esine = $temp3 - $temp4;
471
-        $elsq = $axn * $axn + $ayn * $ayn;
472
-        $temp = 1.0 - $elsq;
473
-        $pl = $a * $temp;
474
-        $r = $a * (1.0 - $ecose);
475
-        $temp1 = 1.0 / $r;
476
-        $rdot = Predict::xke * sqrt($a) * $esine * $temp1;
477
-        $rfdot = Predict::xke * sqrt($pl) * $temp1;
478
-        $temp2 = $a * $temp1;
479
-        $betal = sqrt($temp);
480
-        $temp3 = 1.0 / (1.0 + $betal);
481
-        $cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
482
-        $sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
483
-        $u = Predict_Math::AcTan($sinu, $cosu);
484
-        $sin2u = 2.0 * $sinu * $cosu;
485
-        $cos2u = 2.0 * $cosu * $cosu - 1.0;
486
-        $temp = 1.0 / $pl;
487
-        $temp1 = Predict::ck2 * $temp;
488
-        $temp2 = $temp1 * $temp;
489
-
490
-        /* Update for short periodics */
491
-        $rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
492
-             0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
493
-        $uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
494
-        $xnodek = $sat->deep_arg->xnode + 1.5 * $temp2 * $sat->deep_arg->cosio * $sin2u;
495
-        $xinck = $sat->deep_arg->xinc + 1.5 * $temp2 *
496
-             $sat->deep_arg->cosio * $sat->deep_arg->sinio * $cos2u;
497
-        $rdotk = $rdot - $sat->deep_arg->xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
498
-        $rfdotk = $rfdot + $sat->deep_arg->xn * $temp1 *
499
-             ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
500
-
501
-        /* Orientation vectors */
502
-        $sinuk = sin($uk);
503
-        $cosuk = cos($uk);
504
-        $sinik = sin($xinck);
505
-        $cosik = cos($xinck);
506
-        $sinnok = sin($xnodek);
507
-        $cosnok = cos($xnodek);
508
-        $xmx = -$sinnok * $cosik;
509
-        $xmy = $cosnok * $cosik;
510
-        $ux = $xmx * $sinuk + $cosnok * $cosuk;
511
-        $uy = $xmy * $sinuk + $sinnok * $cosuk;
512
-        $uz = $sinik * $sinuk;
513
-        $vx = $xmx * $cosuk - $cosnok * $sinuk;
514
-        $vy = $xmy * $cosuk - $sinnok * $sinuk;
515
-        $vz = $sinik * $cosuk;
516
-
517
-        /* Position and velocity */
518
-        $sat->pos->x = $rk * $ux;
519
-        $sat->pos->y = $rk * $uy;
520
-        $sat->pos->z = $rk * $uz;
521
-        $sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
522
-        $sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
523
-        $sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
524
-
525
-        /* Phase in rads */
526
-        $sat->phase = $xlt - $sat->deep_arg->xnode - $sat->deep_arg->omgadf + Predict::twopi;
527
-        if ($sat->phase < 0.0) {
528
-            $sat->phase += Predict::twopi;
529
-        }
530
-        $sat->phase = Predict_Math::FMod2p ($sat->phase);
531
-
532
-        $sat->tle->omegao1 = $sat->deep_arg->omgadf;
533
-        $sat->tle->xincl1  = $sat->deep_arg->xinc;
534
-        $sat->tle->xnodeo1 = $sat->deep_arg->xnode;
535
-    } /* SDP4 */
536
-
537
-
538
-    /* DEEP */
539
-    /* This function is used by SDP4 to add lunar and solar */
540
-    /* perturbation effects to deep-space orbit objects.    */
541
-    public function Deep($ientry, Predict_Sat $sat)
542
-    {
543
-        switch ($ientry) {
544
-        case self::dpinit : /* Entrance for deep space initialization */
545
-            $sat->dps->thgr = Predict_Time::ThetaG($sat->tle->epoch, $sat->deep_arg);
546
-            $eq = $sat->tle->eo;
547
-            $sat->dps->xnq = $sat->deep_arg->xnodp;
548
-            $aqnv = 1.0 / $sat->deep_arg->aodp;
549
-            $sat->dps->xqncl = $sat->tle->xincl;
550
-            $xmao = $sat->tle->xmo;
551
-            $xpidot = $sat->deep_arg->omgdot + $sat->deep_arg->xnodot;
552
-            $sinq = sin($sat->tle->xnodeo);
553
-            $cosq = cos($sat->tle->xnodeo);
554
-            $sat->dps->omegaq = $sat->tle->omegao;
555
-            $sat->dps->preep = 0;
556
-
557
-            /* Initialize lunar solar terms */
558
-            $day = $sat->deep_arg->ds50 + 18261.5;  /* Days since 1900 Jan 0.5 */
559
-            if ($day != $sat->dps->preep) {
560
-                $sat->dps->preep = $day;
561
-                $xnodce = 4.5236020 - 9.2422029E-4 * $day;
562
-                $stem = sin($xnodce);
563
-                $ctem = cos($xnodce);
564
-                $sat->dps->zcosil = 0.91375164 - 0.03568096 * $ctem;
565
-                $sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil * $sat->dps->zcosil);
566
-                $sat->dps->zsinhl = 0.089683511 * $stem / $sat->dps->zsinil;
567
-                $sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl * $sat->dps->zsinhl);
568
-                $c = 4.7199672 + 0.22997150 * $day;
569
-                $gam = 5.8351514 + 0.0019443680 * $day;
570
-                $sat->dps->zmol = Predict_Math::FMod2p($c - $gam);
571
-                $zx = 0.39785416 * $stem / $sat->dps->zsinil;
572
-                $zy = $sat->dps->zcoshl * $ctem + 0.91744867 * $sat->dps->zsinhl * $stem;
573
-                $zx = Predict_Math::AcTan($zx, $zy);
574
-                $zx = $gam + $zx - $xnodce;
575
-                $sat->dps->zcosgl = cos($zx);
576
-                $sat->dps->zsingl = sin($zx);
577
-                $sat->dps->zmos = 6.2565837 + 0.017201977 * $day;
578
-                $sat->dps->zmos = Predict_Math::FMod2p($sat->dps->zmos);
579
-            } /* End if(day != preep) */
580
-
581
-            /* Do solar terms */
582
-            $sat->dps->savtsn = 1E20;
583
-            $zcosg = Predict::zcosgs;
584
-            $zsing = Predict::zsings;
585
-            $zcosi = Predict::zcosis;
586
-            $zsini = Predict::zsinis;
587
-            $zcosh = $cosq;
588
-            $zsinh = $sinq;
589
-            $cc = Predict::c1ss;
590
-            $zn = Predict::zns;
591
-            $ze = Predict::zes;
592
-            $zmo = $sat->dps->zmos;
593
-            $xnoi = 1.0 / $sat->dps->xnq;
594
-
595
-            /* Loop breaks when Solar terms are done a second */
596
-            /* time, after Lunar terms are initialized        */
597
-            for(;;) {
598
-                /* Solar terms done again after Lunar terms are done */
599
-                $a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
600
-                $a3 = -$zsing * $zcosh + $zcosg * $zcosi * $zsinh;
601
-                $a7 = -$zcosg * $zsinh + $zsing * $zcosi * $zcosh;
602
-                $a8 = $zsing * $zsini;
603
-                $a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
604
-                $a10 = $zcosg * $zsini;
605
-                $a2 = $sat->deep_arg->cosio * $a7 + $sat->deep_arg->sinio * $a8;
606
-                $a4 = $sat->deep_arg->cosio * $a9 + $sat->deep_arg->sinio * $a10;
607
-                $a5 = -$sat->deep_arg->sinio * $a7 + $sat->deep_arg->cosio * $a8;
608
-                $a6 = -$sat->deep_arg->sinio * $a9 + $sat->deep_arg->cosio * $a10;
609
-                $x1 = $a1 * $sat->deep_arg->cosg + $a2 * $sat->deep_arg->sing;
610
-                $x2 = $a3 * $sat->deep_arg->cosg + $a4 * $sat->deep_arg->sing;
611
-                $x3 = -$a1 * $sat->deep_arg->sing + $a2 * $sat->deep_arg->cosg;
612
-                $x4 = -$a3 * $sat->deep_arg->sing + $a4 * $sat->deep_arg->cosg;
613
-                $x5 = $a5 * $sat->deep_arg->sing;
614
-                $x6 = $a6 * $sat->deep_arg->sing;
615
-                $x7 = $a5 * $sat->deep_arg->cosg;
616
-                $x8 = $a6 * $sat->deep_arg->cosg;
617
-                $z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
618
-                $z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
619
-                $z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
620
-                $z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $sat->deep_arg->eosq;
621
-                $z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $sat->deep_arg->eosq;
622
-                $z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $sat->deep_arg->eosq;
623
-                $z11 = -6 * $a1 * $a5 + $sat->deep_arg->eosq * (-24 * $x1 * $x7 - 6 * $x3 * $x5);
624
-                $z12 = -6 * ($a1 * $a6 + $a3 * $a5) + $sat->deep_arg->eosq *
625
-                    (-24 * ($x2 * $x7 + $x1 * $x8) - 6 * ($x3 * $x6 + $x4 * $x5));
626
-                $z13 = -6 * $a3 * $a6 + $sat->deep_arg->eosq * (-24 * $x2 * $x8 - 6 * $x4 * $x6);
627
-                $z21 = 6 * $a2 * $a5 + $sat->deep_arg->eosq * (24 * $x1 * $x5 - 6 * $x3 * $x7);
628
-                $z22 = 6 * ($a4 * $a5 + $a2 * $a6) + $sat->deep_arg->eosq *
629
-                    (24 * ($x2 * $x5 + $x1 * $x6) - 6 * ($x4 * $x7 + $x3 * $x8));
630
-                $z23 = 6 * $a4 * $a6 + $sat->deep_arg->eosq * (24 * $x2 * $x6 - 6 * $x4 * $x8);
631
-                $z1 = $z1 + $z1 + $sat->deep_arg->betao2 * $z31;
632
-                $z2 = $z2 + $z2 + $sat->deep_arg->betao2 * $z32;
633
-                $z3 = $z3 + $z3 + $sat->deep_arg->betao2 * $z33;
634
-                $s3 = $cc * $xnoi;
635
-                $s2 = -0.5 * $s3 / $sat->deep_arg->betao;
636
-                $s4 = $s3 * $sat->deep_arg->betao;
637
-                $s1 = -15 * $eq * $s4;
638
-                $s5 = $x1 * $x3 + $x2 * $x4;
639
-                $s6 = $x2 * $x3 + $x1 * $x4;
640
-                $s7 = $x2 * $x4 - $x1 * $x3;
641
-                $se = $s1 * $zn * $s5;
642
-                $si = $s2 * $zn * ($z11 + $z13);
643
-                $sl = -$zn * $s3 * ($z1 + $z3 - 14 - 6 * $sat->deep_arg->eosq);
644
-                $sgh = $s4 * $zn * ($z31 + $z33 - 6);
645
-                $sh = -$zn * $s2 * ($z21 + $z23);
646
-                if ($sat->dps->xqncl < 5.2359877E-2) {
647
-                    $sh = 0;
648
-                }
649
-                $sat->dps->ee2 = 2 * $s1 * $s6;
650
-                $sat->dps->e3 = 2 * $s1 * $s7;
651
-                $sat->dps->xi2 = 2 * $s2 * $z12;
652
-                $sat->dps->xi3 = 2 * $s2 * ($z13 - $z11);
653
-                $sat->dps->xl2 = -2 * $s3 * $z2;
654
-                $sat->dps->xl3 = -2 * $s3 * ($z3 - $z1);
655
-                $sat->dps->xl4 = -2 * $s3 * (-21 - 9 * $sat->deep_arg->eosq) * $ze;
656
-                $sat->dps->xgh2 = 2 * $s4 * $z32;
657
-                $sat->dps->xgh3 = 2 * $s4 * ($z33 - $z31);
658
-                $sat->dps->xgh4 = -18 * $s4 * $ze;
659
-                $sat->dps->xh2 = -2 * $s2 * $z22;
660
-                $sat->dps->xh3 = -2 * $s2 * ($z23 - $z21);
661
-
662
-                if ($sat->flags & self::LUNAR_TERMS_DONE_FLAG) {
663
-                    break;
664
-                }
665
-
666
-                /* Do lunar terms */
667
-                $sat->dps->sse = $se;
668
-                $sat->dps->ssi = $si;
669
-                $sat->dps->ssl = $sl;
670
-                $sat->dps->ssh = $sh / $sat->deep_arg->sinio;
671
-                $sat->dps->ssg = $sgh - $sat->deep_arg->cosio * $sat->dps->ssh;
672
-                $sat->dps->se2 = $sat->dps->ee2;
673
-                $sat->dps->si2 = $sat->dps->xi2;
674
-                $sat->dps->sl2 = $sat->dps->xl2;
675
-                $sat->dps->sgh2 = $sat->dps->xgh2;
676
-                $sat->dps->sh2 = $sat->dps->xh2;
677
-                $sat->dps->se3 = $sat->dps->e3;
678
-                $sat->dps->si3 = $sat->dps->xi3;
679
-                $sat->dps->sl3 = $sat->dps->xl3;
680
-                $sat->dps->sgh3 = $sat->dps->xgh3;
681
-                $sat->dps->sh3 = $sat->dps->xh3;
682
-                $sat->dps->sl4 = $sat->dps->xl4;
683
-                $sat->dps->sgh4 = $sat->dps->xgh4;
684
-                $zcosg = $sat->dps->zcosgl;
685
-                $zsing = $sat->dps->zsingl;
686
-                $zcosi = $sat->dps->zcosil;
687
-                $zsini = $sat->dps->zsinil;
688
-                $zcosh = $sat->dps->zcoshl * $cosq + $sat->dps->zsinhl * $sinq;
689
-                $zsinh = $sinq * $sat->dps->zcoshl - $cosq * $sat->dps->zsinhl;
690
-                $zn = Predict::znl;
691
-                $cc = Predict::c1l;
692
-                $ze = Predict::zel;
693
-                $zmo = $sat->dps->zmol;
694
-                $sat->flags |= self::LUNAR_TERMS_DONE_FLAG;
695
-            } /* End of for(;;) */
696
-
697
-            $sat->dps->sse = $sat->dps->sse + $se;
698
-            $sat->dps->ssi = $sat->dps->ssi + $si;
699
-            $sat->dps->ssl = $sat->dps->ssl + $sl;
700
-            $sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio / $sat->deep_arg->sinio * $sh;
701
-            $sat->dps->ssh = $sat->dps->ssh + $sh / $sat->deep_arg->sinio;
702
-
703
-            /* Geopotential resonance initialization for 12 hour orbits */
704
-            $sat->flags &= ~self::RESONANCE_FLAG;
705
-            $sat->flags &= ~self::SYNCHRONOUS_FLAG;
706
-
707
-            if (!(($sat->dps->xnq < 0.0052359877) && ($sat->dps->xnq > 0.0034906585))) {
708
-                if( ($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924) ) {
709
-                    return;
710
-                }
711
-                if ($eq < 0.5) {
712
-                    return;
713
-                }
714
-                $sat->flags |= self::RESONANCE_FLAG;
715
-                $eoc = $eq * $sat->deep_arg->eosq;
716
-                $g201 = -0.306 - ($eq - 0.64) * 0.440;
717
-                if ($eq <= 0.65) {
718
-                    $g211 = 3.616 - 13.247 * $eq + 16.290 * $sat->deep_arg->eosq;
719
-                    $g310 = -19.302 + 117.390 * $eq - 228.419 *
720
-                        $sat->deep_arg->eosq + 156.591 * $eoc;
721
-                    $g322 = -18.9068 + 109.7927 * $eq - 214.6334 *
722
-                        $sat->deep_arg->eosq + 146.5816 * $eoc;
723
-                    $g410 = -41.122 + 242.694 * $eq - 471.094 *
724
-                        $sat->deep_arg->eosq + 313.953 * $eoc;
725
-                    $g422 = -146.407 + 841.880 * $eq - 1629.014 *
726
-                        $sat->deep_arg->eosq + 1083.435 * $eoc;
727
-                    $g520 = -532.114 + 3017.977 * $eq - 5740 *
728
-                        $sat->deep_arg->eosq + 3708.276 * $eoc;
729
-                } else {
730
-                    $g211 = -72.099 + 331.819 * $eq - 508.738 *
731
-                        $sat->deep_arg->eosq + 266.724 * $eoc;
732
-                    $g310 = -346.844 + 1582.851 * $eq - 2415.925 *
733
-                        $sat->deep_arg->eosq + 1246.113 * $eoc;
734
-                    $g322 = -342.585 + 1554.908 * $eq - 2366.899 *
735
-                        $sat->deep_arg->eosq + 1215.972 * $eoc;
736
-                    $g410 = -1052.797 + 4758.686 * $eq - 7193.992 *
737
-                        $sat->deep_arg->eosq + 3651.957 * $eoc;
738
-                    $g422 = -3581.69 + 16178.11 * $eq - 24462.77 *
739
-                        $sat->deep_arg->eosq+ 12422.52 * $eoc;
740
-                    if ($eq <= 0.715) {
741
-                        $g520 = 1464.74 - 4664.75 * $eq + 3763.64 * $sat->deep_arg->eosq;
742
-                    } else {
743
-                        $g520 = -5149.66 + 29936.92 * $eq - 54087.36 *
744
-                            $sat->deep_arg->eosq + 31324.56 * $eoc;
745
-                    }
746
-                } /* End if (eq <= 0.65) */
747
-
748
-                if ($eq < 0.7) {
749
-                    $g533 = -919.2277 + 4988.61 * $eq - 9064.77 *
750
-                        $sat->deep_arg->eosq + 5542.21 * $eoc;
751
-                    $g521 = -822.71072 + 4568.6173 * $eq - 8491.4146 *
752
-                        $sat->deep_arg->eosq + 5337.524 * $eoc;
753
-                    $g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754
-                        $sat->deep_arg->eosq + 5341.4 * $eoc;
755
-                }
756
-                else {
757
-                    $g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758
-                        $sat->deep_arg->eosq + 109377.94 * $eoc;
759
-                    $g521 = -51752.104 + 218913.95 * $eq - 309468.16*
760
-                        $sat->deep_arg->eosq + 146349.42 * $eoc;
761
-                    $g532 = -40023.88 + 170470.89 * $eq - 242699.48*
762
-                        $sat->deep_arg->eosq + 115605.82 * $eoc;
763
-                } /* End if (eq <= 0.7) */
764
-
765
-                $sini2 = $sat->deep_arg->sinio * $sat->deep_arg->sinio;
766
-                $f220 = 0.75 * (1 + 2 * $sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
-                $f221 = 1.5 * $sini2;
768
-                $f321 = 1.875 * $sat->deep_arg->sinio * (1 - 2 *
769
-                                  $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
770
-                $f322 = -1.875 * $sat->deep_arg->sinio * (1 + 2*
771
-                                   $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
772
-                $f441 = 35 * $sini2 * $f220;
773
-                $f442 = 39.3750 * $sini2 * $sini2;
774
-                $f522 = 9.84375 * $sat->deep_arg->sinio * ($sini2 * (1 - 2 * $sat->deep_arg->cosio - 5 *
775
-                                       $sat->deep_arg->theta2) + 0.33333333 * (-2 + 4 * $sat->deep_arg->cosio +
776
-                                                     6 * $sat->deep_arg->theta2));
777
-                $f523 = $sat->deep_arg->sinio * (4.92187512 * $sini2 * (-2 - 4 *
778
-                                      $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2) + 6.56250012
779
-                            * (1 + 2 * $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2));
780
-                $f542 = 29.53125 * $sat->deep_arg->sinio * (2 - 8 *
781
-                                 $sat->deep_arg->cosio + $sat->deep_arg->theta2 *
782
-                                 (-12 + 8 * $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2));
783
-                $f543 = 29.53125 * $sat->deep_arg->sinio * (-2 - 8 * $sat->deep_arg->cosio +
784
-                                 $sat->deep_arg->theta2 * (12 + 8 * $sat->deep_arg->cosio - 10 *
785
-                                           $sat->deep_arg->theta2));
786
-                $xno2 = $sat->dps->xnq * $sat->dps->xnq;
787
-                $ainv2 = $aqnv * $aqnv;
788
-                $temp1 = 3 * $xno2 * $ainv2;
789
-                $temp = $temp1 * Predict::root22;
790
-                $sat->dps->d2201 = $temp * $f220 * $g201;
791
-                $sat->dps->d2211 = $temp * $f221 * $g211;
792
-                $temp1 = $temp1 * $aqnv;
793
-                $temp = $temp1 * Predict::root32;
794
-                $sat->dps->d3210 = $temp * $f321 * $g310;
795
-                $sat->dps->d3222 = $temp * $f322 * $g322;
796
-                $temp1 = $temp1 * $aqnv;
797
-                $temp = 2 * $temp1 * Predict::root44;
798
-                $sat->dps->d4410 = $temp * $f441 * $g410;
799
-                $sat->dps->d4422 = $temp * $f442 * $g422;
800
-                $temp1 = $temp1 * $aqnv;
801
-                $temp = $temp1 * Predict::root52;
802
-                $sat->dps->d5220 = $temp * $f522 * $g520;
803
-                $sat->dps->d5232 = $temp * $f523 * $g532;
804
-                $temp = 2 * $temp1 * Predict::root54;
805
-                $sat->dps->d5421 = $temp * $f542 * $g521;
806
-                $sat->dps->d5433 = $temp * $f543 * $g533;
807
-                $sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->xnodeo - $sat->dps->thgr - $sat->dps->thgr;
808
-                $bfact = $sat->deep_arg->xmdot + $sat->deep_arg->xnodot +
809
-                    $sat->deep_arg->xnodot - Predict::thdt - Predict::thdt;
810
-                $bfact = $bfact + $sat->dps->ssl + $sat->dps->ssh + $sat->dps->ssh;
811
-            } else {
812
-                $sat->flags |= self::RESONANCE_FLAG;
813
-                $sat->flags |= self::SYNCHRONOUS_FLAG;
814
-                /* Synchronous resonance terms initialization */
815
-                $g200 = 1 + $sat->deep_arg->eosq * (-2.5 + 0.8125 * $sat->deep_arg->eosq);
816
-                $g310 = 1 + 2 * $sat->deep_arg->eosq;
817
-                $g300 = 1 + $sat->deep_arg->eosq * (-6 + 6.60937 * $sat->deep_arg->eosq);
818
-                $f220 = 0.75 * (1 + $sat->deep_arg->cosio) * (1 + $sat->deep_arg->cosio);
819
-                $f311 = 0.9375 * $sat->deep_arg->sinio * $sat->deep_arg->sinio *
820
-                    (1 + 3 * $sat->deep_arg->cosio) - 0.75 * (1 + $sat->deep_arg->cosio);
821
-                $f330 = 1 + $sat->deep_arg->cosio;
822
-                $f330 = 1.875 * $f330 * $f330 * $f330;
823
-                $sat->dps->del1 = 3 * $sat->dps->xnq * $sat->dps->xnq * $aqnv * $aqnv;
824
-                $sat->dps->del2 = 2 * $sat->dps->del1 * $f220 * $g200 * Predict::q22;
825
-                $sat->dps->del3 = 3 * $sat->dps->del1 * $f330 * $g300 * Predict::q33 * $aqnv;
826
-                $sat->dps->del1 = $sat->dps->del1 * $f311 * $g310 * Predict::q31 * $aqnv;
827
-                $sat->dps->fasx2 = 0.13130908;
828
-                $sat->dps->fasx4 = 2.8843198;
829
-                $sat->dps->fasx6 = 0.37448087;
830
-                $sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->omegao - $sat->dps->thgr;
831
-                $bfact = $sat->deep_arg->xmdot + $xpidot - Predict::thdt;
832
-                $bfact = $bfact + $sat->dps->ssl + $sat->dps->ssg + $sat->dps->ssh;
833
-            } /* End if( !(xnq < 0.0052359877) && (xnq > 0.0034906585) ) */
834
-
835
-            $sat->dps->xfact = $bfact - $sat->dps->xnq;
836
-
837
-            /* Initialize integrator */
838
-            $sat->dps->xli = $sat->dps->xlamo;
839
-            $sat->dps->xni = $sat->dps->xnq;
840
-            $sat->dps->atime = 0;
841
-            $sat->dps->stepp = 720;
842
-            $sat->dps->stepn = -720;
843
-            $sat->dps->step2 = 259200;
844
-            /* End case self::dpinit: */
845
-            return;
846
-
847
-        case self::dpsec: /* Entrance for deep space secular effects */
848
-            $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl * $sat->deep_arg->t;
849
-            $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg * $sat->deep_arg->t;
850
-            $sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh * $sat->deep_arg->t;
851
-            $sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse * $sat->deep_arg->t;
852
-            $sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi * $sat->deep_arg->t;
853
-            if ($sat->deep_arg->xinc < 0) {
854
-                $sat->deep_arg->xinc = -$sat->deep_arg->xinc;
855
-                $sat->deep_arg->xnode = $sat->deep_arg->xnode + Predict::pi;
856
-                $sat->deep_arg->omgadf = $sat->deep_arg->omgadf - Predict::pi;
857
-            }
858
-            if(~$sat->flags & self::RESONANCE_FLAG ) {
859
-                return;
860
-            }
861
-
862
-            do {
863
-                if ( ($sat->dps->atime == 0) ||
864
-                    (($sat->deep_arg->t >= 0) && ($sat->dps->atime < 0)) ||
865
-                    (($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0)) ) {
866
-                    /* Epoch restart */
867
-                    if ($sat->deep_arg->t >= 0) {
868
-                        $delt = $sat->dps->stepp;
869
-                    } else {
870
-                        $delt = $sat->dps->stepn;
871
-                    }
872
-
873
-                    $sat->dps->atime = 0;
874
-                    $sat->dps->xni = $sat->dps->xnq;
875
-                    $sat->dps->xli = $sat->dps->xlamo;
876
-                } else {
877
-                    if (abs($sat->deep_arg->t) >= abs($sat->dps->atime)) {
878
-                        if ($sat->deep_arg->t > 0) {
879
-                            $delt = $sat->dps->stepp;
880
-                        } else {
881
-                            $delt = $sat->dps->stepn;
882
-                        }
883
-                    }
884
-                }
885
-
886
-                do {
887
-                    if (abs($sat->deep_arg->t - $sat->dps->atime) >= $sat->dps->stepp) {
888
-                        $sat->flags |= self::DO_LOOP_FLAG;
889
-                        $sat->flags &= ~self::EPOCH_RESTART_FLAG;
890
-                    }
891
-                    else {
892
-                        $ft = $sat->deep_arg->t - $sat->dps->atime;
893
-                        $sat->flags &= ~self::DO_LOOP_FLAG;
894
-                    }
895
-
896
-                    if (abs($sat->deep_arg->t) < abs($sat->dps->atime)) {
897
-                        if ($sat->deep_arg->t >= 0) {
898
-                            $delt = $sat->dps->stepn;
899
-                        } else {
900
-                            $delt = $sat->dps->stepp;
901
-                        }
902
-                        $sat->flags |= (self::DO_LOOP_FLAG | self::EPOCH_RESTART_FLAG);
903
-                    }
904
-
905
-                    /* Dot terms calculated */
906
-                    if ($sat->flags & self::SYNCHRONOUS_FLAG) {
907
-                        $xndot = $sat->dps->del1 * sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2 * sin(2 * ($sat->dps->xli - $sat->dps->fasx4))
908
-                            + $sat->dps->del3 * sin(3 * ($sat->dps->xli - $sat->dps->fasx6));
909
-                        $xnddt = $sat->dps->del1 * cos($sat->dps->xli - $sat->dps->fasx2) + 2 * $sat->dps->del2 * cos(2 * ($sat->dps->xli - $sat->dps->fasx4))
910
-                            + 3 * $sat->dps->del3 * cos(3 * ($sat->dps->xli - $sat->dps->fasx6));
911
-                    } else {
912
-                        $xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot * $sat->dps->atime;
913
-                        $x2omi = $xomi + $xomi;
914
-                        $x2li = $sat->dps->xli + $sat->dps->xli;
915
-                        $xndot = $sat->dps->d2201 * sin($x2omi + $sat->dps->xli - Predict::g22)
916
-                            + $sat->dps->d2211 * sin($sat->dps->xli - Predict::g22)
917
-                            + $sat->dps->d3210 * sin($xomi + $sat->dps->xli - Predict::g32)
918
-                            + $sat->dps->d3222 * sin(-$xomi + $sat->dps->xli - Predict::g32)
919
-                            + $sat->dps->d4410 * sin($x2omi + $x2li- Predict::g44)
920
-                            + $sat->dps->d4422 * sin($x2li- Predict::g44)
921
-                            + $sat->dps->d5220 * sin($xomi + $sat->dps->xli- Predict::g52)
922
-                            + $sat->dps->d5232 * sin(-$xomi + $sat->dps->xli- Predict::g52)
923
-                            + $sat->dps->d5421 * sin($xomi + $x2li - Predict::g54)
924
-                            + $sat->dps->d5433 * sin(-$xomi + $x2li - Predict::g54);
925
-                        $xnddt = $sat->dps->d2201 * cos($x2omi + $sat->dps->xli- Predict::g22)
926
-                            + $sat->dps->d2211 * cos($sat->dps->xli - Predict::g22)
927
-                            + $sat->dps->d3210 * cos($xomi + $sat->dps->xli - Predict::g32)
928
-                            + $sat->dps->d3222 * cos(-$xomi + $sat->dps->xli - Predict::g32)
929
-                            + $sat->dps->d5220 * cos($xomi + $sat->dps->xli - Predict::g52)
930
-                            + $sat->dps->d5232 * cos(-$xomi + $sat->dps->xli - Predict::g52)
931
-                            + 2 * ($sat->dps->d4410 * cos($x2omi + $x2li - Predict::g44)
932
-                                + $sat->dps->d4422 * cos($x2li - Predict::g44)
933
-                                + $sat->dps->d5421 * cos($xomi + $x2li - Predict::g54)
934
-                                + $sat->dps->d5433 * cos(-$xomi + $x2li - Predict::g54));
935
-                    } /* End of if (isFlagSet(SYNCHRONOUS_FLAG)) */
936
-
937
-                    $xldot = $sat->dps->xni + $sat->dps->xfact;
938
-                    $xnddt = $xnddt * $xldot;
939
-
940
-                    if ($sat->flags & self::DO_LOOP_FLAG) {
941
-                        $sat->dps->xli = $sat->dps->xli + $xldot * $delt + $xndot * $sat->dps->step2;
942
-                        $sat->dps->xni = $sat->dps->xni + $xndot * $delt + $xnddt * $sat->dps->step2;
943
-                        $sat->dps->atime = $sat->dps->atime + $delt;
944
-                    }
945
-                } while (($sat->flags & self::DO_LOOP_FLAG) &&
946
-                        (~$sat->flags & self::EPOCH_RESTART_FLAG));
947
-            }
948
-            while (($sat->flags & self::DO_LOOP_FLAG) && ($sat->flags & self::EPOCH_RESTART_FLAG));
949
-
950
-            $sat->deep_arg->xn = $sat->dps->xni + $xndot * $ft + $xnddt * $ft * $ft * 0.5;
951
-            $xl = $sat->dps->xli + $xldot * $ft + $xndot * $ft * $ft * 0.5;
952
-            $temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t * Predict::thdt;
953
-
954
-            if (~$sat->flags & self::SYNCHRONOUS_FLAG) {
955
-                $sat->deep_arg->xll = $xl + $temp + $temp;
956
-            } else {
957
-                $sat->deep_arg->xll = $xl - $sat->deep_arg->omgadf + $temp;
958
-            }
959
-
960
-            return;
961
-            /* End case dpsec: */
962
-
963
-        case self::dpper: /* Entrance for lunar-solar periodics */
964
-            $sinis = sin($sat->deep_arg->xinc);
965
-            $cosis = cos($sat->deep_arg->xinc);
966
-            if (abs($sat->dps->savtsn - $sat->deep_arg->t) >= 30) {
967
-                $sat->dps->savtsn = $sat->deep_arg->t;
968
-                $zm = $sat->dps->zmos + Predict::zns * $sat->deep_arg->t;
969
-                $zf = $zm + 2 * Predict::zes * sin($zm);
970
-                $sinzf = sin($zf);
971
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
972
-                $f3 = -0.5 * $sinzf * cos($zf);
973
-                $ses = $sat->dps->se2 * $f2 + $sat->dps->se3 * $f3;
974
-                $sis = $sat->dps->si2 * $f2 + $sat->dps->si3 * $f3;
975
-                $sls = $sat->dps->sl2 * $f2 + $sat->dps->sl3 * $f3 + $sat->dps->sl4 * $sinzf;
976
-                $sat->dps->sghs = $sat->dps->sgh2 * $f2 + $sat->dps->sgh3 * $f3 + $sat->dps->sgh4 * $sinzf;
977
-                $sat->dps->shs = $sat->dps->sh2 * $f2 + $sat->dps->sh3 * $f3;
978
-                $zm = $sat->dps->zmol + Predict::znl * $sat->deep_arg->t;
979
-                $zf = $zm + 2 * Predict::zel * sin($zm);
980
-                $sinzf = sin($zf);
981
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
982
-                $f3 = -0.5 * $sinzf * cos($zf);
983
-                $sel = $sat->dps->ee2 * $f2 + $sat->dps->e3 * $f3;
984
-                $sil = $sat->dps->xi2 * $f2 + $sat->dps->xi3 * $f3;
985
-                $sll = $sat->dps->xl2 * $f2 + $sat->dps->xl3 * $f3 + $sat->dps->xl4 * $sinzf;
986
-                $sat->dps->sghl = $sat->dps->xgh2 * $f2 + $sat->dps->xgh3 * $f3 + $sat->dps->xgh4 * $sinzf;
987
-                $sat->dps->sh1 = $sat->dps->xh2 * $f2 + $sat->dps->xh3 * $f3;
988
-                $sat->dps->pe = $ses + $sel;
989
-                $sat->dps->pinc = $sis + $sil;
990
-                $sat->dps->pl = $sls + $sll;
991
-            }
992
-
993
-            $pgh = $sat->dps->sghs + $sat->dps->sghl;
994
-            $ph = $sat->dps->shs + $sat->dps->sh1;
995
-            $sat->deep_arg->xinc = $sat->deep_arg->xinc + $sat->dps->pinc;
996
-            $sat->deep_arg->em = $sat->deep_arg->em + $sat->dps->pe;
997
-
998
-            if ($sat->dps->xqncl >= 0.2) {
999
-                /* Apply periodics directly */
1000
-                $ph = $ph / $sat->deep_arg->sinio;
1001
-                $pgh = $pgh - $sat->deep_arg->cosio * $ph;
1002
-                $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $pgh;
1003
-                $sat->deep_arg->xnode = $sat->deep_arg->xnode + $ph;
1004
-                $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1005
-            } else {
1006
-                /* Apply periodics with Lyddane modification */
1007
-                $sinok = sin($sat->deep_arg->xnode);
1008
-                $cosok = cos($sat->deep_arg->xnode);
1009
-                $alfdp = $sinis * $sinok;
1010
-                $betdp = $sinis * $cosok;
1011
-                $dalf = $ph * $cosok + $sat->dps->pinc * $cosis * $sinok;
1012
-                $dbet = -$ph * $sinok + $sat->dps->pinc * $cosis * $cosok;
1013
-                $alfdp = $alfdp + $dalf;
1014
-                $betdp = $betdp + $dbet;
1015
-                $sat->deep_arg->xnode = Predict_Math::FMod2p($sat->deep_arg->xnode);
1016
-                $xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis * $sat->deep_arg->xnode;
1017
-                $dls = $sat->dps->pl + $pgh - $sat->dps->pinc * $sat->deep_arg->xnode * $sinis;
1018
-                $xls = $xls + $dls;
1019
-                $xnoh = $sat->deep_arg->xnode;
1020
-                $sat->deep_arg->xnode = Predict_Math::AcTan($alfdp, $betdp);
1021
-
1022
-                /* This is a patch to Lyddane modification */
1023
-                /* suggested by Rob Matson. */
1024
-                if(abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1025
-                    if ($sat->deep_arg->xnode < $xnoh) {
1026
-                        $sat->deep_arg->xnode += Predict::twopi;
1027
-                    } else {
1028
-                        $sat->deep_arg->xnode -= Predict::twopi;
1029
-                    }
1030
-                }
1031
-
1032
-                $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1033
-                $sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc) *
1034
-                    $sat->deep_arg->xnode;
1035
-            } /* End case dpper: */
1036
-            return;
1037
-
1038
-        } /* End switch(ientry) */
1039
-
1040
-    } /* End of Deep() */
1041
-
1042
-    /**
1043
-     * Singleton
1044
-     *
1045
-     * @param Predict_Sat $sat The current satellite data instance
1046
-     *
1047
-     * @return Predict_SGPSDP
1048
-     */
1049
-    public static function getInstance(Predict_Sat $sat)
1050
-    {
1051
-        static $instances = array();
1052
-        $catnr = $sat->tle->catnr;
1053
-        if (!isset($instances[$catnr])) {
1054
-            $instances[$catnr] = new self();
1055
-        }
1056
-        return $instances[$catnr];
1057
-    }
59
+	const dpinit = 1; /* Deep-space initialization code */
60
+	const dpsec  = 2; /* Deep-space secular code        */
61
+	const dpper  = 3; /* Deep-space periodic code       */
62
+
63
+	/* SGP4 */
64
+	/* This function is used to calculate the position and velocity */
65
+	/* of near-earth (period < 225 minutes) satellites. tsince is   */
66
+	/* time since epoch in minutes, tle is a pointer to a tle_t     */
67
+	/* structure with Keplerian orbital elements and pos and vel    */
68
+	/* are vector_t structures returning ECI satellite position and */
69
+	/* velocity. Use Convert_Sat_State() to convert to km and km/s.*/
70
+	public function SGP4(Predict_Sat $sat, $tsince)
71
+	{
72
+		/* Initialization */
73
+		if (~$sat->flags & self::SGP4_INITIALIZED_FLAG) {
74
+			$sat->flags |= self::SGP4_INITIALIZED_FLAG;
75
+
76
+			/* Recover original mean motion (xnodp) and   */
77
+			/* semimajor axis (aodp) from input elements. */
78
+			$a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
79
+			$sat->sgps->cosio = cos($sat->tle->xincl);
80
+			$theta2 = $sat->sgps->cosio * $sat->sgps->cosio;
81
+			$sat->sgps->x3thm1 = 3 * $theta2 - 1.0;
82
+			$eosq = $sat->tle->eo * $sat->tle->eo;
83
+			$betao2 = 1 - $eosq;
84
+			$betao = sqrt($betao2);
85
+			$del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($a1 * $a1 * $betao * $betao2);
86
+			$ao = $a1 * (1 - $del1 * (0.5 * Predict::tothrd + $del1 * (1 + 134.0 / 81.0 * $del1)));
87
+			$delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($ao * $ao * $betao * $betao2);
88
+			$sat->sgps->xnodp = $sat->tle->xno / (1.0 + $delo);
89
+			$sat->sgps->aodp = $ao / (1.0 - $delo);
90
+
91
+			/* For perigee less than 220 kilometers, the "simple" flag is set */
92
+			/* and the equations are truncated to linear variation in sqrt a  */
93
+			/* and quadratic variation in mean anomaly.  Also, the c3 term,   */
94
+			/* the delta omega term, and the delta m term are dropped.        */
95
+			if (($sat->sgps->aodp * (1.0 - $sat->tle->eo) / Predict::ae) < (220.0 / Predict::xkmper + Predict::ae)) {
96
+				$sat->flags |= self::SIMPLE_FLAG;
97
+			} else {
98
+				$sat->flags &= ~self::SIMPLE_FLAG;
99
+			}
100
+
101
+			/* For perigee below 156 km, the       */
102
+			/* values of s and qoms2t are altered. */
103
+			$s4 = Predict::__s__;
104
+			$qoms24 = Predict::qoms2t;
105
+			$perige = ($sat->sgps->aodp * (1 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
106
+			if ($perige < 156.0) {
107
+				if ($perige <= 98.0) {
108
+					$s4 = 20.0;
109
+				} else {
110
+					$s4 = $perige - 78.0;
111
+				}
112
+				$qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
113
+				$s4 = $s4 / Predict::xkmper + Predict::ae;
114
+			}; /* FIXME FIXME: End of if(perige <= 98) NO WAY!!!! */
115
+
116
+			$pinvsq = 1.0 / ($sat->sgps->aodp * $sat->sgps->aodp * $betao2 * $betao2);
117
+			$tsi = 1.0 / ($sat->sgps->aodp - $s4);
118
+			$sat->sgps->eta = $sat->sgps->aodp * $sat->tle->eo * $tsi;
119
+			$etasq = $sat->sgps->eta * $sat->sgps->eta;
120
+			$eeta = $sat->tle->eo * $sat->sgps->eta;
121
+			$psisq = abs(1.0 - $etasq);
122
+			$coef = $qoms24 * pow($tsi, 4);
123
+			$coef1 = $coef / pow($psisq, 3.5);
124
+			$c2 = $coef1 * $sat->sgps->xnodp * ($sat->sgps->aodp *
125
+							(1.0 + 1.5 * $etasq + $eeta * (4.0 + $etasq)) +
126
+							0.75 * Predict::ck2 * $tsi / $psisq * $sat->sgps->x3thm1 *
127
+							(8.0 + 3.0 * $etasq * (8 + $etasq)));
128
+			$sat->sgps->c1 = $c2 * $sat->tle->bstar;
129
+			$sat->sgps->sinio = sin($sat->tle->xincl);
130
+			$a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
131
+			$c3 = $coef * $tsi * $a3ovk2 * $sat->sgps->xnodp * Predict::ae * $sat->sgps->sinio / $sat->tle->eo;
132
+			$sat->sgps->x1mth2 = 1.0 - $theta2;
133
+			$sat->sgps->c4 = 2.0 * $sat->sgps->xnodp * $coef1 * $sat->sgps->aodp * $betao2 *
134
+				($sat->sgps->eta * (2.0 + 0.5 * $etasq) +
135
+				 $sat->tle->eo * (0.5 + 2.0 * $etasq) -
136
+				 2.0 * Predict::ck2 * $tsi / ($sat->sgps->aodp * $psisq) *
137
+				 (-3.0 * $sat->sgps->x3thm1 * (1.0 - 2.0 * $eeta + $etasq * (1.5 - 0.5 * $eeta)) +
138
+				  0.75 * $sat->sgps->x1mth2 * (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
139
+				  cos(2.0 * $sat->tle->omegao)));
140
+			$sat->sgps->c5 = 2.0 * $coef1 * $sat->sgps->aodp * $betao2 *
141
+				(1.0 + 2.75 * ($etasq + $eeta) + $eeta * $etasq);
142
+			$theta4 = $theta2 * $theta2;
143
+			$temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->sgps->xnodp;
144
+			$temp2 = $temp1 * Predict::ck2 * $pinvsq;
145
+			$temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->sgps->xnodp;
146
+			$sat->sgps->xmdot = $sat->sgps->xnodp + 0.5 * $temp1 * $betao * $sat->sgps->x3thm1 +
147
+				0.0625 * $temp2 * $betao * (13.0 - 78.0 * $theta2 + 137.0 * $theta4);
148
+			$x1m5th = 1.0 - 5.0 * $theta2;
149
+			$sat->sgps->omgdot = -0.5 * $temp1 * $x1m5th +
150
+				0.0625 * $temp2 * (7.0 - 114.0 * $theta2 + 395.0 * $theta4) +
151
+				$temp3 * (3.0 - 36.0 * $theta2 + 49.0 * $theta4);
152
+			$xhdot1 = -$temp1 * $sat->sgps->cosio;
153
+			$sat->sgps->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $theta2) +
154
+							 2.0 * $temp3 * (3.0 - 7.0 * $theta2)) * $sat->sgps->cosio;
155
+			$sat->sgps->omgcof = $sat->tle->bstar * $c3 * cos($sat->tle->omegao);
156
+			$sat->sgps->xmcof = -Predict::tothrd * $coef * $sat->tle->bstar * Predict::ae / $eeta;
157
+			$sat->sgps->xnodcf = 3.5 * $betao2 * $xhdot1 * $sat->sgps->c1;
158
+			$sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
159
+			$sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->sgps->sinio *
160
+				(3.0 + 5.0 * $sat->sgps->cosio) / (1.0 + $sat->sgps->cosio);
161
+			$sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->sgps->sinio;
162
+			$sat->sgps->delmo = pow(1.0 + $sat->sgps->eta * cos($sat->tle->xmo), 3);
163
+			$sat->sgps->sinmo = sin($sat->tle->xmo);
164
+			$sat->sgps->x7thm1 = 7.0 * $theta2 - 1.0;
165
+			if (~$sat->flags & self::SIMPLE_FLAG) {
166
+				$c1sq = $sat->sgps->c1 * $sat->sgps->c1;
167
+				$sat->sgps->d2 = 4.0 * $sat->sgps->aodp * $tsi * $c1sq;
168
+				$temp = $sat->sgps->d2 * $tsi * $sat->sgps->c1 / 3.0;
169
+				$sat->sgps->d3 = (17.0 * $sat->sgps->aodp + $s4) * $temp;
170
+				$sat->sgps->d4 = 0.5 * $temp * $sat->sgps->aodp * $tsi *
171
+					(221.0 * $sat->sgps->aodp + 31.0 * $s4) * $sat->sgps->c1;
172
+				$sat->sgps->t3cof = $sat->sgps->d2 + 2.0 * $c1sq;
173
+				$sat->sgps->t4cof = 0.25 * (3.0 * $sat->sgps->d3 + $sat->sgps->c1 *
174
+							  (12.0 * $sat->sgps->d2 + 10.0 * $c1sq));
175
+				$sat->sgps->t5cof = 0.2 * (3.0 * $sat->sgps->d4 +
176
+							 12.0 * $sat->sgps->c1 * $sat->sgps->d3 +
177
+							 6.0 * $sat->sgps->d2 * $sat->sgps->d2 +
178
+							 15.0 * $c1sq * (2.0 * $sat->sgps->d2 + $c1sq));
179
+			}; /* End of if (isFlagClear(SIMPLE_FLAG)) */
180
+		}; /* End of SGP4() initialization */
181
+
182
+		/* Update for secular gravity and atmospheric drag. */
183
+		$xmdf = $sat->tle->xmo + $sat->sgps->xmdot * $tsince;
184
+		$omgadf = $sat->tle->omegao + $sat->sgps->omgdot * $tsince;
185
+		$xnoddf = $sat->tle->xnodeo + $sat->sgps->xnodot * $tsince;
186
+		$omega = $omgadf;
187
+		$xmp = $xmdf;
188
+		$tsq = $tsince * $tsince;
189
+		$xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
190
+		$tempa = 1.0 - $sat->sgps->c1 * $tsince;
191
+		$tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
192
+		$templ = $sat->sgps->t2cof * $tsq;
193
+		if (~$sat->flags & self::SIMPLE_FLAG) {
194
+			$delomg = $sat->sgps->omgcof * $tsince;
195
+			$delm = $sat->sgps->xmcof * (pow(1 + $sat->sgps->eta * cos($xmdf), 3) - $sat->sgps->delmo);
196
+			$temp = $delomg + $delm;
197
+			$xmp = $xmdf + $temp;
198
+			$omega = $omgadf - $temp;
199
+			$tcube = $tsq * $tsince;
200
+			$tfour = $tsince * $tcube;
201
+			$tempa = $tempa - $sat->sgps->d2 * $tsq - $sat->sgps->d3 * $tcube - $sat->sgps->d4 * $tfour;
202
+			$tempe = $tempe + $sat->tle->bstar * $sat->sgps->c5 * (sin($xmp) - $sat->sgps->sinmo);
203
+			$templ = $templ + $sat->sgps->t3cof * $tcube + $tfour *
204
+				($sat->sgps->t4cof + $tsince * $sat->sgps->t5cof);
205
+		}; /* End of if (isFlagClear(SIMPLE_FLAG)) */
206
+
207
+		$a = $sat->sgps->aodp * pow($tempa, 2);
208
+		$e = $sat->tle->eo - $tempe;
209
+		$xl = $xmp + $omega + $xnode + $sat->sgps->xnodp * $templ;
210
+		$beta = sqrt(1.0 - ($e * $e));
211
+		$xn = Predict::xke / pow($a, 1.5);
212
+
213
+		/* Long period periodics */
214
+		$axn = $e * cos($omega);
215
+		$temp = 1.0 / ($a * $beta * $beta);
216
+		$xll = $temp * $sat->sgps->xlcof * $axn;
217
+		$aynl = $temp * $sat->sgps->aycof;
218
+		$xlt = $xl + $xll;
219
+		$ayn = $e * sin($omega) + $aynl;
220
+
221
+		/* Solve Kepler's' Equation */
222
+		$capu = Predict_Math::FMod2p($xlt - $xnode);
223
+		$temp2 = $capu;
224
+
225
+		$i = 0;
226
+		do {
227
+			$sinepw = sin($temp2);
228
+			$cosepw = cos($temp2);
229
+			$temp3 = $axn * $sinepw;
230
+			$temp4 = $ayn * $cosepw;
231
+			$temp5 = $axn * $cosepw;
232
+			$temp6 = $ayn * $sinepw;
233
+			$epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
234
+			if (abs($epw - $temp2) <= Predict::e6a) {
235
+				break;
236
+			}
237
+			$temp2 = $epw;
238
+		} while ($i++ < 10);
239
+
240
+		/* Short period preliminary quantities */
241
+		$ecose = $temp5 + $temp6;
242
+		$esine = $temp3 - $temp4;
243
+		$elsq = $axn * $axn + $ayn * $ayn;
244
+		$temp = 1.0 - $elsq;
245
+		$pl = $a * $temp;
246
+		$r = $a * (1.0 - $ecose);
247
+		$temp1 = 1.0 / $r;
248
+		$rdot = Predict::xke * sqrt($a) * $esine * $temp1;
249
+		$rfdot = Predict::xke * sqrt($pl) * $temp1;
250
+		$temp2 = $a * $temp1;
251
+		$betal = sqrt($temp);
252
+		$temp3 = 1.0 / (1.0 + $betal);
253
+		$cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
254
+		$sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
255
+		$u = Predict_Math::AcTan($sinu, $cosu);
256
+		$sin2u = 2.0 * $sinu * $cosu;
257
+		$cos2u = 2.0 * $cosu * $cosu - 1.0;
258
+		$temp = 1.0 / $pl;
259
+		$temp1 = Predict::ck2 * $temp;
260
+		$temp2 = $temp1 * $temp;
261
+
262
+		/* Update for short periodics */
263
+		$rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
264
+			0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
265
+		$uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
266
+		$xnodek = $xnode + 1.5 * $temp2 * $sat->sgps->cosio * $sin2u;
267
+		$xinck = $sat->tle->xincl + 1.5 * $temp2 * $sat->sgps->cosio * $sat->sgps->sinio * $cos2u;
268
+		$rdotk = $rdot - $xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
269
+		$rfdotk = $rfdot + $xn * $temp1 * ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
270
+
271
+
272
+		/* Orientation vectors */
273
+		$sinuk = sin($uk);
274
+		$cosuk = cos($uk);
275
+		$sinik = sin($xinck);
276
+		$cosik = cos($xinck);
277
+		$sinnok = sin($xnodek);
278
+		$cosnok = cos($xnodek);
279
+		$xmx = -$sinnok * $cosik;
280
+		$xmy = $cosnok * $cosik;
281
+		$ux = $xmx * $sinuk + $cosnok * $cosuk;
282
+		$uy = $xmy * $sinuk + $sinnok * $cosuk;
283
+		$uz = $sinik * $sinuk;
284
+		$vx = $xmx * $cosuk - $cosnok * $sinuk;
285
+		$vy = $xmy * $cosuk - $sinnok * $sinuk;
286
+		$vz = $sinik * $cosuk;
287
+
288
+		/* Position and velocity */
289
+		$sat->pos->x = $rk * $ux;
290
+		$sat->pos->y = $rk * $uy;
291
+		$sat->pos->z = $rk * $uz;
292
+		$sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
293
+		$sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
294
+		$sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
295
+
296
+		$sat->phase = $xlt - $xnode - $omgadf + Predict::twopi;
297
+		if ($sat->phase < 0) {
298
+			$sat->phase += Predict::twopi;
299
+		}
300
+		$sat->phase = Predict_Math::FMod2p($sat->phase);
301
+
302
+		$sat->tle->omegao1 = $omega;
303
+		$sat->tle->xincl1  = $xinck;
304
+		$sat->tle->xnodeo1 = $xnodek;
305
+
306
+	} /*SGP4*/
307
+
308
+	/* SDP4 */
309
+	/* This function is used to calculate the position and velocity */
310
+	/* of deep-space (period > 225 minutes) satellites. tsince is   */
311
+	/* time since epoch in minutes, tle is a pointer to a tle_t     */
312
+	/* structure with Keplerian orbital elements and pos and vel    */
313
+	/* are vector_t structures returning ECI satellite position and */
314
+	/* velocity. Use Convert_Sat_State() to convert to km and km/s. */
315
+	public function SDP4(Predict_Sat $sat, $tsince)
316
+	{
317
+		/* Initialization */
318
+		if (~$sat->flags & self::SDP4_INITIALIZED_FLAG) {
319
+
320
+			$sat->flags |= self::SDP4_INITIALIZED_FLAG;
321
+
322
+			/* Recover original mean motion (xnodp) and   */
323
+			/* semimajor axis (aodp) from input elements. */
324
+			$a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
325
+			$sat->deep_arg->cosio = cos($sat->tle->xincl);
326
+			$sat->deep_arg->theta2 = $sat->deep_arg->cosio * $sat->deep_arg->cosio;
327
+			$sat->sgps->x3thm1 = 3.0 * $sat->deep_arg->theta2 - 1.0;
328
+			$sat->deep_arg->eosq = $sat->tle->eo * $sat->tle->eo;
329
+			$sat->deep_arg->betao2 = 1.0 - $sat->deep_arg->eosq;
330
+			$sat->deep_arg->betao = sqrt($sat->deep_arg->betao2);
331
+			$del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
332
+				($a1 * $a1 * $sat->deep_arg->betao * $sat->deep_arg->betao2);
333
+			$ao = $a1 * (1.0 - $del1 * (0.5 * Predict::tothrd + $del1 * (1.0 + 134.0 / 81.0 * $del1)));
334
+			$delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
335
+				($ao * $ao * $sat->deep_arg->betao * $sat->deep_arg->betao2);
336
+			$sat->deep_arg->xnodp = $sat->tle->xno / (1.0 + $delo);
337
+			$sat->deep_arg->aodp = $ao / (1.0 - $delo);
338
+
339
+			/* For perigee below 156 km, the values */
340
+			/* of s and qoms2t are altered.         */
341
+			$s4 = Predict::__s__;
342
+			$qoms24 = Predict::qoms2t;
343
+			$perige = ($sat->deep_arg->aodp * (1.0 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
344
+			if ($perige < 156.0) {
345
+				if ($perige <= 98.0) {
346
+					$s4 = 20.0;
347
+				} else {
348
+					$s4 = $perige - 78.0;
349
+				}
350
+				$qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
351
+				$s4 = $s4 / Predict::xkmper + Predict::ae;
352
+			}
353
+			$pinvsq = 1.0 / ($sat->deep_arg->aodp * $sat->deep_arg->aodp *
354
+					$sat->deep_arg->betao2 * $sat->deep_arg->betao2);
355
+			$sat->deep_arg->sing = sin($sat->tle->omegao);
356
+			$sat->deep_arg->cosg = cos($sat->tle->omegao);
357
+			$tsi = 1.0 / ($sat->deep_arg->aodp - $s4);
358
+			$eta = $sat->deep_arg->aodp * $sat->tle->eo * $tsi;
359
+			$etasq = $eta * $eta;
360
+			$eeta = $sat->tle->eo * $eta;
361
+			$psisq = abs(1.0 - $etasq);
362
+			$coef = $qoms24 * pow($tsi, 4);
363
+			$coef1 = $coef / pow($psisq, 3.5);
364
+			$c2 = $coef1 * $sat->deep_arg->xnodp * ($sat->deep_arg->aodp *
365
+								(1.0 + 1.5 * $etasq + $eeta *
366
+								 (4.0 + $etasq)) + 0.75 * Predict::ck2 * $tsi / $psisq *
367
+								$sat->sgps->x3thm1 * (8.0 + 3.0 * $etasq *
368
+										(8.0 + $etasq)));
369
+			$sat->sgps->c1 = $sat->tle->bstar * $c2;
370
+			$sat->deep_arg->sinio = sin($sat->tle->xincl);
371
+			$a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
372
+			$sat->sgps->x1mth2 = 1.0 - $sat->deep_arg->theta2;
373
+			$sat->sgps->c4 = 2.0 * $sat->deep_arg->xnodp * $coef1 *
374
+				$sat->deep_arg->aodp * $sat->deep_arg->betao2 *
375
+				($eta * (2.0 + 0.5 * $etasq) + $sat->tle->eo *
376
+				 (0.5 + 2.0 * $etasq) - 2.0 * Predict::ck2 * $tsi /
377
+				 ($sat->deep_arg->aodp * $psisq) * (-3.0 * $sat->sgps->x3thm1 *
378
+								 (1.0 - 2.0 * $eeta + $etasq *
379
+								  (1.5 - 0.5 * $eeta)) +
380
+								 0.75 * $sat->sgps->x1mth2 *
381
+								 (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
382
+								 cos(2.0 * $sat->tle->omegao)));
383
+			$theta4 = $sat->deep_arg->theta2 * $sat->deep_arg->theta2;
384
+			$temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->deep_arg->xnodp;
385
+			$temp2 = $temp1 * Predict::ck2 * $pinvsq;
386
+			$temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->deep_arg->xnodp;
387
+			$sat->deep_arg->xmdot = $sat->deep_arg->xnodp + 0.5 * $temp1 * $sat->deep_arg->betao *
388
+				$sat->sgps->x3thm1 + 0.0625 * $temp2 * $sat->deep_arg->betao *
389
+				(13.0 - 78.0 * $sat->deep_arg->theta2 + 137.0 * $theta4);
390
+			$x1m5th = 1.0 - 5.0 * $sat->deep_arg->theta2;
391
+			$sat->deep_arg->omgdot = -0.5 * $temp1 * $x1m5th + 0.0625 * $temp2 *
392
+							(7.0 - 114.0 * $sat->deep_arg->theta2 + 395.0 * $theta4) +
393
+						$temp3 * (3.0 - 36.0 * $sat->deep_arg->theta2 + 49.0 * $theta4);
394
+			$xhdot1 = -$temp1 * $sat->deep_arg->cosio;
395
+			$sat->deep_arg->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $sat->deep_arg->theta2) +
396
+							 2.0 * $temp3 * (3.0 - 7.0 * $sat->deep_arg->theta2)) *
397
+				$sat->deep_arg->cosio;
398
+			$sat->sgps->xnodcf = 3.5 * $sat->deep_arg->betao2 * $xhdot1 * $sat->sgps->c1;
399
+			$sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
400
+			$sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->deep_arg->sinio *
401
+				(3.0 + 5.0 * $sat->deep_arg->cosio) / (1.0 + $sat->deep_arg->cosio);
402
+			$sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->deep_arg->sinio;
403
+			$sat->sgps->x7thm1 = 7.0 * $sat->deep_arg->theta2 - 1.0;
404
+
405
+			/* initialize Deep() */
406
+			$this->Deep(self::dpinit, $sat);
407
+		}; /*End of SDP4() initialization */
408
+
409
+		/* Update for secular gravity and atmospheric drag */
410
+		$xmdf = $sat->tle->xmo + $sat->deep_arg->xmdot * $tsince;
411
+		$sat->deep_arg->omgadf = $sat->tle->omegao + $sat->deep_arg->omgdot * $tsince;
412
+		$xnoddf = $sat->tle->xnodeo + $sat->deep_arg->xnodot * $tsince;
413
+		$tsq = $tsince * $tsince;
414
+		$sat->deep_arg->xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
415
+		$tempa = 1.0 - $sat->sgps->c1 * $tsince;
416
+		$tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
417
+		$templ = $sat->sgps->t2cof * $tsq;
418
+		$sat->deep_arg->xn = $sat->deep_arg->xnodp;
419
+
420
+		/* Update for deep-space secular effects */
421
+		$sat->deep_arg->xll = $xmdf;
422
+		$sat->deep_arg->t = $tsince;
423
+
424
+		$this->Deep(self::dpsec, $sat);
425
+
426
+		$xmdf = $sat->deep_arg->xll;
427
+		$a = pow(Predict::xke / $sat->deep_arg->xn, Predict::tothrd) * $tempa * $tempa;
428
+		$sat->deep_arg->em = $sat->deep_arg->em - $tempe;
429
+		$xmam = $xmdf + $sat->deep_arg->xnodp * $templ;
430
+
431
+		/* Update for deep-space periodic effects */
432
+		$sat->deep_arg->xll = $xmam;
433
+
434
+		$this->Deep(self::dpper, $sat);
435
+
436
+		$xmam = $sat->deep_arg->xll;
437
+		$xl = $xmam + $sat->deep_arg->omgadf + $sat->deep_arg->xnode;
438
+		$beta = sqrt(1.0 - $sat->deep_arg->em * $sat->deep_arg->em);
439
+		$sat->deep_arg->xn = Predict::xke / pow($a, 1.5);
440
+
441
+		/* Long period periodics */
442
+		$axn = $sat->deep_arg->em * cos($sat->deep_arg->omgadf);
443
+		$temp = 1.0 / ($a * $beta * $beta);
444
+		$xll = $temp * $sat->sgps->xlcof * $axn;
445
+		$aynl = $temp * $sat->sgps->aycof;
446
+		$xlt = $xl + $xll;
447
+		$ayn = $sat->deep_arg->em * sin($sat->deep_arg->omgadf) + $aynl;
448
+
449
+		/* Solve Kepler's Equation */
450
+		$capu = Predict_Math::FMod2p ($xlt - $sat->deep_arg->xnode);
451
+		$temp2 = $capu;
452
+
453
+		$i = 0;
454
+		do {
455
+			$sinepw = sin($temp2);
456
+			$cosepw = cos($temp2);
457
+			$temp3 = $axn * $sinepw;
458
+			$temp4 = $ayn * $cosepw;
459
+			$temp5 = $axn * $cosepw;
460
+			$temp6 = $ayn * $sinepw;
461
+			$epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
462
+			if (abs($epw - $temp2) <= Predict::e6a) {
463
+				break;
464
+			}
465
+			$temp2 = $epw;
466
+		} while ($i++ < 10);
467
+
468
+		/* Short period preliminary quantities */
469
+		$ecose = $temp5 + $temp6;
470
+		$esine = $temp3 - $temp4;
471
+		$elsq = $axn * $axn + $ayn * $ayn;
472
+		$temp = 1.0 - $elsq;
473
+		$pl = $a * $temp;
474
+		$r = $a * (1.0 - $ecose);
475
+		$temp1 = 1.0 / $r;
476
+		$rdot = Predict::xke * sqrt($a) * $esine * $temp1;
477
+		$rfdot = Predict::xke * sqrt($pl) * $temp1;
478
+		$temp2 = $a * $temp1;
479
+		$betal = sqrt($temp);
480
+		$temp3 = 1.0 / (1.0 + $betal);
481
+		$cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
482
+		$sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
483
+		$u = Predict_Math::AcTan($sinu, $cosu);
484
+		$sin2u = 2.0 * $sinu * $cosu;
485
+		$cos2u = 2.0 * $cosu * $cosu - 1.0;
486
+		$temp = 1.0 / $pl;
487
+		$temp1 = Predict::ck2 * $temp;
488
+		$temp2 = $temp1 * $temp;
489
+
490
+		/* Update for short periodics */
491
+		$rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
492
+			 0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
493
+		$uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
494
+		$xnodek = $sat->deep_arg->xnode + 1.5 * $temp2 * $sat->deep_arg->cosio * $sin2u;
495
+		$xinck = $sat->deep_arg->xinc + 1.5 * $temp2 *
496
+			 $sat->deep_arg->cosio * $sat->deep_arg->sinio * $cos2u;
497
+		$rdotk = $rdot - $sat->deep_arg->xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
498
+		$rfdotk = $rfdot + $sat->deep_arg->xn * $temp1 *
499
+			 ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
500
+
501
+		/* Orientation vectors */
502
+		$sinuk = sin($uk);
503
+		$cosuk = cos($uk);
504
+		$sinik = sin($xinck);
505
+		$cosik = cos($xinck);
506
+		$sinnok = sin($xnodek);
507
+		$cosnok = cos($xnodek);
508
+		$xmx = -$sinnok * $cosik;
509
+		$xmy = $cosnok * $cosik;
510
+		$ux = $xmx * $sinuk + $cosnok * $cosuk;
511
+		$uy = $xmy * $sinuk + $sinnok * $cosuk;
512
+		$uz = $sinik * $sinuk;
513
+		$vx = $xmx * $cosuk - $cosnok * $sinuk;
514
+		$vy = $xmy * $cosuk - $sinnok * $sinuk;
515
+		$vz = $sinik * $cosuk;
516
+
517
+		/* Position and velocity */
518
+		$sat->pos->x = $rk * $ux;
519
+		$sat->pos->y = $rk * $uy;
520
+		$sat->pos->z = $rk * $uz;
521
+		$sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
522
+		$sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
523
+		$sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
524
+
525
+		/* Phase in rads */
526
+		$sat->phase = $xlt - $sat->deep_arg->xnode - $sat->deep_arg->omgadf + Predict::twopi;
527
+		if ($sat->phase < 0.0) {
528
+			$sat->phase += Predict::twopi;
529
+		}
530
+		$sat->phase = Predict_Math::FMod2p ($sat->phase);
531
+
532
+		$sat->tle->omegao1 = $sat->deep_arg->omgadf;
533
+		$sat->tle->xincl1  = $sat->deep_arg->xinc;
534
+		$sat->tle->xnodeo1 = $sat->deep_arg->xnode;
535
+	} /* SDP4 */
536
+
537
+
538
+	/* DEEP */
539
+	/* This function is used by SDP4 to add lunar and solar */
540
+	/* perturbation effects to deep-space orbit objects.    */
541
+	public function Deep($ientry, Predict_Sat $sat)
542
+	{
543
+		switch ($ientry) {
544
+		case self::dpinit : /* Entrance for deep space initialization */
545
+			$sat->dps->thgr = Predict_Time::ThetaG($sat->tle->epoch, $sat->deep_arg);
546
+			$eq = $sat->tle->eo;
547
+			$sat->dps->xnq = $sat->deep_arg->xnodp;
548
+			$aqnv = 1.0 / $sat->deep_arg->aodp;
549
+			$sat->dps->xqncl = $sat->tle->xincl;
550
+			$xmao = $sat->tle->xmo;
551
+			$xpidot = $sat->deep_arg->omgdot + $sat->deep_arg->xnodot;
552
+			$sinq = sin($sat->tle->xnodeo);
553
+			$cosq = cos($sat->tle->xnodeo);
554
+			$sat->dps->omegaq = $sat->tle->omegao;
555
+			$sat->dps->preep = 0;
556
+
557
+			/* Initialize lunar solar terms */
558
+			$day = $sat->deep_arg->ds50 + 18261.5;  /* Days since 1900 Jan 0.5 */
559
+			if ($day != $sat->dps->preep) {
560
+				$sat->dps->preep = $day;
561
+				$xnodce = 4.5236020 - 9.2422029E-4 * $day;
562
+				$stem = sin($xnodce);
563
+				$ctem = cos($xnodce);
564
+				$sat->dps->zcosil = 0.91375164 - 0.03568096 * $ctem;
565
+				$sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil * $sat->dps->zcosil);
566
+				$sat->dps->zsinhl = 0.089683511 * $stem / $sat->dps->zsinil;
567
+				$sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl * $sat->dps->zsinhl);
568
+				$c = 4.7199672 + 0.22997150 * $day;
569
+				$gam = 5.8351514 + 0.0019443680 * $day;
570
+				$sat->dps->zmol = Predict_Math::FMod2p($c - $gam);
571
+				$zx = 0.39785416 * $stem / $sat->dps->zsinil;
572
+				$zy = $sat->dps->zcoshl * $ctem + 0.91744867 * $sat->dps->zsinhl * $stem;
573
+				$zx = Predict_Math::AcTan($zx, $zy);
574
+				$zx = $gam + $zx - $xnodce;
575
+				$sat->dps->zcosgl = cos($zx);
576
+				$sat->dps->zsingl = sin($zx);
577
+				$sat->dps->zmos = 6.2565837 + 0.017201977 * $day;
578
+				$sat->dps->zmos = Predict_Math::FMod2p($sat->dps->zmos);
579
+			} /* End if(day != preep) */
580
+
581
+			/* Do solar terms */
582
+			$sat->dps->savtsn = 1E20;
583
+			$zcosg = Predict::zcosgs;
584
+			$zsing = Predict::zsings;
585
+			$zcosi = Predict::zcosis;
586
+			$zsini = Predict::zsinis;
587
+			$zcosh = $cosq;
588
+			$zsinh = $sinq;
589
+			$cc = Predict::c1ss;
590
+			$zn = Predict::zns;
591
+			$ze = Predict::zes;
592
+			$zmo = $sat->dps->zmos;
593
+			$xnoi = 1.0 / $sat->dps->xnq;
594
+
595
+			/* Loop breaks when Solar terms are done a second */
596
+			/* time, after Lunar terms are initialized        */
597
+			for(;;) {
598
+				/* Solar terms done again after Lunar terms are done */
599
+				$a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
600
+				$a3 = -$zsing * $zcosh + $zcosg * $zcosi * $zsinh;
601
+				$a7 = -$zcosg * $zsinh + $zsing * $zcosi * $zcosh;
602
+				$a8 = $zsing * $zsini;
603
+				$a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
604
+				$a10 = $zcosg * $zsini;
605
+				$a2 = $sat->deep_arg->cosio * $a7 + $sat->deep_arg->sinio * $a8;
606
+				$a4 = $sat->deep_arg->cosio * $a9 + $sat->deep_arg->sinio * $a10;
607
+				$a5 = -$sat->deep_arg->sinio * $a7 + $sat->deep_arg->cosio * $a8;
608
+				$a6 = -$sat->deep_arg->sinio * $a9 + $sat->deep_arg->cosio * $a10;
609
+				$x1 = $a1 * $sat->deep_arg->cosg + $a2 * $sat->deep_arg->sing;
610
+				$x2 = $a3 * $sat->deep_arg->cosg + $a4 * $sat->deep_arg->sing;
611
+				$x3 = -$a1 * $sat->deep_arg->sing + $a2 * $sat->deep_arg->cosg;
612
+				$x4 = -$a3 * $sat->deep_arg->sing + $a4 * $sat->deep_arg->cosg;
613
+				$x5 = $a5 * $sat->deep_arg->sing;
614
+				$x6 = $a6 * $sat->deep_arg->sing;
615
+				$x7 = $a5 * $sat->deep_arg->cosg;
616
+				$x8 = $a6 * $sat->deep_arg->cosg;
617
+				$z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
618
+				$z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
619
+				$z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
620
+				$z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $sat->deep_arg->eosq;
621
+				$z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $sat->deep_arg->eosq;
622
+				$z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $sat->deep_arg->eosq;
623
+				$z11 = -6 * $a1 * $a5 + $sat->deep_arg->eosq * (-24 * $x1 * $x7 - 6 * $x3 * $x5);
624
+				$z12 = -6 * ($a1 * $a6 + $a3 * $a5) + $sat->deep_arg->eosq *
625
+					(-24 * ($x2 * $x7 + $x1 * $x8) - 6 * ($x3 * $x6 + $x4 * $x5));
626
+				$z13 = -6 * $a3 * $a6 + $sat->deep_arg->eosq * (-24 * $x2 * $x8 - 6 * $x4 * $x6);
627
+				$z21 = 6 * $a2 * $a5 + $sat->deep_arg->eosq * (24 * $x1 * $x5 - 6 * $x3 * $x7);
628
+				$z22 = 6 * ($a4 * $a5 + $a2 * $a6) + $sat->deep_arg->eosq *
629
+					(24 * ($x2 * $x5 + $x1 * $x6) - 6 * ($x4 * $x7 + $x3 * $x8));
630
+				$z23 = 6 * $a4 * $a6 + $sat->deep_arg->eosq * (24 * $x2 * $x6 - 6 * $x4 * $x8);
631
+				$z1 = $z1 + $z1 + $sat->deep_arg->betao2 * $z31;
632
+				$z2 = $z2 + $z2 + $sat->deep_arg->betao2 * $z32;
633
+				$z3 = $z3 + $z3 + $sat->deep_arg->betao2 * $z33;
634
+				$s3 = $cc * $xnoi;
635
+				$s2 = -0.5 * $s3 / $sat->deep_arg->betao;
636
+				$s4 = $s3 * $sat->deep_arg->betao;
637
+				$s1 = -15 * $eq * $s4;
638
+				$s5 = $x1 * $x3 + $x2 * $x4;
639
+				$s6 = $x2 * $x3 + $x1 * $x4;
640
+				$s7 = $x2 * $x4 - $x1 * $x3;
641
+				$se = $s1 * $zn * $s5;
642
+				$si = $s2 * $zn * ($z11 + $z13);
643
+				$sl = -$zn * $s3 * ($z1 + $z3 - 14 - 6 * $sat->deep_arg->eosq);
644
+				$sgh = $s4 * $zn * ($z31 + $z33 - 6);
645
+				$sh = -$zn * $s2 * ($z21 + $z23);
646
+				if ($sat->dps->xqncl < 5.2359877E-2) {
647
+					$sh = 0;
648
+				}
649
+				$sat->dps->ee2 = 2 * $s1 * $s6;
650
+				$sat->dps->e3 = 2 * $s1 * $s7;
651
+				$sat->dps->xi2 = 2 * $s2 * $z12;
652
+				$sat->dps->xi3 = 2 * $s2 * ($z13 - $z11);
653
+				$sat->dps->xl2 = -2 * $s3 * $z2;
654
+				$sat->dps->xl3 = -2 * $s3 * ($z3 - $z1);
655
+				$sat->dps->xl4 = -2 * $s3 * (-21 - 9 * $sat->deep_arg->eosq) * $ze;
656
+				$sat->dps->xgh2 = 2 * $s4 * $z32;
657
+				$sat->dps->xgh3 = 2 * $s4 * ($z33 - $z31);
658
+				$sat->dps->xgh4 = -18 * $s4 * $ze;
659
+				$sat->dps->xh2 = -2 * $s2 * $z22;
660
+				$sat->dps->xh3 = -2 * $s2 * ($z23 - $z21);
661
+
662
+				if ($sat->flags & self::LUNAR_TERMS_DONE_FLAG) {
663
+					break;
664
+				}
665
+
666
+				/* Do lunar terms */
667
+				$sat->dps->sse = $se;
668
+				$sat->dps->ssi = $si;
669
+				$sat->dps->ssl = $sl;
670
+				$sat->dps->ssh = $sh / $sat->deep_arg->sinio;
671
+				$sat->dps->ssg = $sgh - $sat->deep_arg->cosio * $sat->dps->ssh;
672
+				$sat->dps->se2 = $sat->dps->ee2;
673
+				$sat->dps->si2 = $sat->dps->xi2;
674
+				$sat->dps->sl2 = $sat->dps->xl2;
675
+				$sat->dps->sgh2 = $sat->dps->xgh2;
676
+				$sat->dps->sh2 = $sat->dps->xh2;
677
+				$sat->dps->se3 = $sat->dps->e3;
678
+				$sat->dps->si3 = $sat->dps->xi3;
679
+				$sat->dps->sl3 = $sat->dps->xl3;
680
+				$sat->dps->sgh3 = $sat->dps->xgh3;
681
+				$sat->dps->sh3 = $sat->dps->xh3;
682
+				$sat->dps->sl4 = $sat->dps->xl4;
683
+				$sat->dps->sgh4 = $sat->dps->xgh4;
684
+				$zcosg = $sat->dps->zcosgl;
685
+				$zsing = $sat->dps->zsingl;
686
+				$zcosi = $sat->dps->zcosil;
687
+				$zsini = $sat->dps->zsinil;
688
+				$zcosh = $sat->dps->zcoshl * $cosq + $sat->dps->zsinhl * $sinq;
689
+				$zsinh = $sinq * $sat->dps->zcoshl - $cosq * $sat->dps->zsinhl;
690
+				$zn = Predict::znl;
691
+				$cc = Predict::c1l;
692
+				$ze = Predict::zel;
693
+				$zmo = $sat->dps->zmol;
694
+				$sat->flags |= self::LUNAR_TERMS_DONE_FLAG;
695
+			} /* End of for(;;) */
696
+
697
+			$sat->dps->sse = $sat->dps->sse + $se;
698
+			$sat->dps->ssi = $sat->dps->ssi + $si;
699
+			$sat->dps->ssl = $sat->dps->ssl + $sl;
700
+			$sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio / $sat->deep_arg->sinio * $sh;
701
+			$sat->dps->ssh = $sat->dps->ssh + $sh / $sat->deep_arg->sinio;
702
+
703
+			/* Geopotential resonance initialization for 12 hour orbits */
704
+			$sat->flags &= ~self::RESONANCE_FLAG;
705
+			$sat->flags &= ~self::SYNCHRONOUS_FLAG;
706
+
707
+			if (!(($sat->dps->xnq < 0.0052359877) && ($sat->dps->xnq > 0.0034906585))) {
708
+				if( ($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924) ) {
709
+					return;
710
+				}
711
+				if ($eq < 0.5) {
712
+					return;
713
+				}
714
+				$sat->flags |= self::RESONANCE_FLAG;
715
+				$eoc = $eq * $sat->deep_arg->eosq;
716
+				$g201 = -0.306 - ($eq - 0.64) * 0.440;
717
+				if ($eq <= 0.65) {
718
+					$g211 = 3.616 - 13.247 * $eq + 16.290 * $sat->deep_arg->eosq;
719
+					$g310 = -19.302 + 117.390 * $eq - 228.419 *
720
+						$sat->deep_arg->eosq + 156.591 * $eoc;
721
+					$g322 = -18.9068 + 109.7927 * $eq - 214.6334 *
722
+						$sat->deep_arg->eosq + 146.5816 * $eoc;
723
+					$g410 = -41.122 + 242.694 * $eq - 471.094 *
724
+						$sat->deep_arg->eosq + 313.953 * $eoc;
725
+					$g422 = -146.407 + 841.880 * $eq - 1629.014 *
726
+						$sat->deep_arg->eosq + 1083.435 * $eoc;
727
+					$g520 = -532.114 + 3017.977 * $eq - 5740 *
728
+						$sat->deep_arg->eosq + 3708.276 * $eoc;
729
+				} else {
730
+					$g211 = -72.099 + 331.819 * $eq - 508.738 *
731
+						$sat->deep_arg->eosq + 266.724 * $eoc;
732
+					$g310 = -346.844 + 1582.851 * $eq - 2415.925 *
733
+						$sat->deep_arg->eosq + 1246.113 * $eoc;
734
+					$g322 = -342.585 + 1554.908 * $eq - 2366.899 *
735
+						$sat->deep_arg->eosq + 1215.972 * $eoc;
736
+					$g410 = -1052.797 + 4758.686 * $eq - 7193.992 *
737
+						$sat->deep_arg->eosq + 3651.957 * $eoc;
738
+					$g422 = -3581.69 + 16178.11 * $eq - 24462.77 *
739
+						$sat->deep_arg->eosq+ 12422.52 * $eoc;
740
+					if ($eq <= 0.715) {
741
+						$g520 = 1464.74 - 4664.75 * $eq + 3763.64 * $sat->deep_arg->eosq;
742
+					} else {
743
+						$g520 = -5149.66 + 29936.92 * $eq - 54087.36 *
744
+							$sat->deep_arg->eosq + 31324.56 * $eoc;
745
+					}
746
+				} /* End if (eq <= 0.65) */
747
+
748
+				if ($eq < 0.7) {
749
+					$g533 = -919.2277 + 4988.61 * $eq - 9064.77 *
750
+						$sat->deep_arg->eosq + 5542.21 * $eoc;
751
+					$g521 = -822.71072 + 4568.6173 * $eq - 8491.4146 *
752
+						$sat->deep_arg->eosq + 5337.524 * $eoc;
753
+					$g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754
+						$sat->deep_arg->eosq + 5341.4 * $eoc;
755
+				}
756
+				else {
757
+					$g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758
+						$sat->deep_arg->eosq + 109377.94 * $eoc;
759
+					$g521 = -51752.104 + 218913.95 * $eq - 309468.16*
760
+						$sat->deep_arg->eosq + 146349.42 * $eoc;
761
+					$g532 = -40023.88 + 170470.89 * $eq - 242699.48*
762
+						$sat->deep_arg->eosq + 115605.82 * $eoc;
763
+				} /* End if (eq <= 0.7) */
764
+
765
+				$sini2 = $sat->deep_arg->sinio * $sat->deep_arg->sinio;
766
+				$f220 = 0.75 * (1 + 2 * $sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
+				$f221 = 1.5 * $sini2;
768
+				$f321 = 1.875 * $sat->deep_arg->sinio * (1 - 2 *
769
+								  $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
770
+				$f322 = -1.875 * $sat->deep_arg->sinio * (1 + 2*
771
+								   $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
772
+				$f441 = 35 * $sini2 * $f220;
773
+				$f442 = 39.3750 * $sini2 * $sini2;
774
+				$f522 = 9.84375 * $sat->deep_arg->sinio * ($sini2 * (1 - 2 * $sat->deep_arg->cosio - 5 *
775
+									   $sat->deep_arg->theta2) + 0.33333333 * (-2 + 4 * $sat->deep_arg->cosio +
776
+													 6 * $sat->deep_arg->theta2));
777
+				$f523 = $sat->deep_arg->sinio * (4.92187512 * $sini2 * (-2 - 4 *
778
+									  $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2) + 6.56250012
779
+							* (1 + 2 * $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2));
780
+				$f542 = 29.53125 * $sat->deep_arg->sinio * (2 - 8 *
781
+								 $sat->deep_arg->cosio + $sat->deep_arg->theta2 *
782
+								 (-12 + 8 * $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2));
783
+				$f543 = 29.53125 * $sat->deep_arg->sinio * (-2 - 8 * $sat->deep_arg->cosio +
784
+								 $sat->deep_arg->theta2 * (12 + 8 * $sat->deep_arg->cosio - 10 *
785
+										   $sat->deep_arg->theta2));
786
+				$xno2 = $sat->dps->xnq * $sat->dps->xnq;
787
+				$ainv2 = $aqnv * $aqnv;
788
+				$temp1 = 3 * $xno2 * $ainv2;
789
+				$temp = $temp1 * Predict::root22;
790
+				$sat->dps->d2201 = $temp * $f220 * $g201;
791
+				$sat->dps->d2211 = $temp * $f221 * $g211;
792
+				$temp1 = $temp1 * $aqnv;
793
+				$temp = $temp1 * Predict::root32;
794
+				$sat->dps->d3210 = $temp * $f321 * $g310;
795
+				$sat->dps->d3222 = $temp * $f322 * $g322;
796
+				$temp1 = $temp1 * $aqnv;
797
+				$temp = 2 * $temp1 * Predict::root44;
798
+				$sat->dps->d4410 = $temp * $f441 * $g410;
799
+				$sat->dps->d4422 = $temp * $f442 * $g422;
800
+				$temp1 = $temp1 * $aqnv;
801
+				$temp = $temp1 * Predict::root52;
802
+				$sat->dps->d5220 = $temp * $f522 * $g520;
803
+				$sat->dps->d5232 = $temp * $f523 * $g532;
804
+				$temp = 2 * $temp1 * Predict::root54;
805
+				$sat->dps->d5421 = $temp * $f542 * $g521;
806
+				$sat->dps->d5433 = $temp * $f543 * $g533;
807
+				$sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->xnodeo - $sat->dps->thgr - $sat->dps->thgr;
808
+				$bfact = $sat->deep_arg->xmdot + $sat->deep_arg->xnodot +
809
+					$sat->deep_arg->xnodot - Predict::thdt - Predict::thdt;
810
+				$bfact = $bfact + $sat->dps->ssl + $sat->dps->ssh + $sat->dps->ssh;
811
+			} else {
812
+				$sat->flags |= self::RESONANCE_FLAG;
813
+				$sat->flags |= self::SYNCHRONOUS_FLAG;
814
+				/* Synchronous resonance terms initialization */
815
+				$g200 = 1 + $sat->deep_arg->eosq * (-2.5 + 0.8125 * $sat->deep_arg->eosq);
816
+				$g310 = 1 + 2 * $sat->deep_arg->eosq;
817
+				$g300 = 1 + $sat->deep_arg->eosq * (-6 + 6.60937 * $sat->deep_arg->eosq);
818
+				$f220 = 0.75 * (1 + $sat->deep_arg->cosio) * (1 + $sat->deep_arg->cosio);
819
+				$f311 = 0.9375 * $sat->deep_arg->sinio * $sat->deep_arg->sinio *
820
+					(1 + 3 * $sat->deep_arg->cosio) - 0.75 * (1 + $sat->deep_arg->cosio);
821
+				$f330 = 1 + $sat->deep_arg->cosio;
822
+				$f330 = 1.875 * $f330 * $f330 * $f330;
823
+				$sat->dps->del1 = 3 * $sat->dps->xnq * $sat->dps->xnq * $aqnv * $aqnv;
824
+				$sat->dps->del2 = 2 * $sat->dps->del1 * $f220 * $g200 * Predict::q22;
825
+				$sat->dps->del3 = 3 * $sat->dps->del1 * $f330 * $g300 * Predict::q33 * $aqnv;
826
+				$sat->dps->del1 = $sat->dps->del1 * $f311 * $g310 * Predict::q31 * $aqnv;
827
+				$sat->dps->fasx2 = 0.13130908;
828
+				$sat->dps->fasx4 = 2.8843198;
829
+				$sat->dps->fasx6 = 0.37448087;
830
+				$sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->omegao - $sat->dps->thgr;
831
+				$bfact = $sat->deep_arg->xmdot + $xpidot - Predict::thdt;
832
+				$bfact = $bfact + $sat->dps->ssl + $sat->dps->ssg + $sat->dps->ssh;
833
+			} /* End if( !(xnq < 0.0052359877) && (xnq > 0.0034906585) ) */
834
+
835
+			$sat->dps->xfact = $bfact - $sat->dps->xnq;
836
+
837
+			/* Initialize integrator */
838
+			$sat->dps->xli = $sat->dps->xlamo;
839
+			$sat->dps->xni = $sat->dps->xnq;
840
+			$sat->dps->atime = 0;
841
+			$sat->dps->stepp = 720;
842
+			$sat->dps->stepn = -720;
843
+			$sat->dps->step2 = 259200;
844
+			/* End case self::dpinit: */
845
+			return;
846
+
847
+		case self::dpsec: /* Entrance for deep space secular effects */
848
+			$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl * $sat->deep_arg->t;
849
+			$sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg * $sat->deep_arg->t;
850
+			$sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh * $sat->deep_arg->t;
851
+			$sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse * $sat->deep_arg->t;
852
+			$sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi * $sat->deep_arg->t;
853
+			if ($sat->deep_arg->xinc < 0) {
854
+				$sat->deep_arg->xinc = -$sat->deep_arg->xinc;
855
+				$sat->deep_arg->xnode = $sat->deep_arg->xnode + Predict::pi;
856
+				$sat->deep_arg->omgadf = $sat->deep_arg->omgadf - Predict::pi;
857
+			}
858
+			if(~$sat->flags & self::RESONANCE_FLAG ) {
859
+				return;
860
+			}
861
+
862
+			do {
863
+				if ( ($sat->dps->atime == 0) ||
864
+					(($sat->deep_arg->t >= 0) && ($sat->dps->atime < 0)) ||
865
+					(($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0)) ) {
866
+					/* Epoch restart */
867
+					if ($sat->deep_arg->t >= 0) {
868
+						$delt = $sat->dps->stepp;
869
+					} else {
870
+						$delt = $sat->dps->stepn;
871
+					}
872
+
873
+					$sat->dps->atime = 0;
874
+					$sat->dps->xni = $sat->dps->xnq;
875
+					$sat->dps->xli = $sat->dps->xlamo;
876
+				} else {
877
+					if (abs($sat->deep_arg->t) >= abs($sat->dps->atime)) {
878
+						if ($sat->deep_arg->t > 0) {
879
+							$delt = $sat->dps->stepp;
880
+						} else {
881
+							$delt = $sat->dps->stepn;
882
+						}
883
+					}
884
+				}
885
+
886
+				do {
887
+					if (abs($sat->deep_arg->t - $sat->dps->atime) >= $sat->dps->stepp) {
888
+						$sat->flags |= self::DO_LOOP_FLAG;
889
+						$sat->flags &= ~self::EPOCH_RESTART_FLAG;
890
+					}
891
+					else {
892
+						$ft = $sat->deep_arg->t - $sat->dps->atime;
893
+						$sat->flags &= ~self::DO_LOOP_FLAG;
894
+					}
895
+
896
+					if (abs($sat->deep_arg->t) < abs($sat->dps->atime)) {
897
+						if ($sat->deep_arg->t >= 0) {
898
+							$delt = $sat->dps->stepn;
899
+						} else {
900
+							$delt = $sat->dps->stepp;
901
+						}
902
+						$sat->flags |= (self::DO_LOOP_FLAG | self::EPOCH_RESTART_FLAG);
903
+					}
904
+
905
+					/* Dot terms calculated */
906
+					if ($sat->flags & self::SYNCHRONOUS_FLAG) {
907
+						$xndot = $sat->dps->del1 * sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2 * sin(2 * ($sat->dps->xli - $sat->dps->fasx4))
908
+							+ $sat->dps->del3 * sin(3 * ($sat->dps->xli - $sat->dps->fasx6));
909
+						$xnddt = $sat->dps->del1 * cos($sat->dps->xli - $sat->dps->fasx2) + 2 * $sat->dps->del2 * cos(2 * ($sat->dps->xli - $sat->dps->fasx4))
910
+							+ 3 * $sat->dps->del3 * cos(3 * ($sat->dps->xli - $sat->dps->fasx6));
911
+					} else {
912
+						$xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot * $sat->dps->atime;
913
+						$x2omi = $xomi + $xomi;
914
+						$x2li = $sat->dps->xli + $sat->dps->xli;
915
+						$xndot = $sat->dps->d2201 * sin($x2omi + $sat->dps->xli - Predict::g22)
916
+							+ $sat->dps->d2211 * sin($sat->dps->xli - Predict::g22)
917
+							+ $sat->dps->d3210 * sin($xomi + $sat->dps->xli - Predict::g32)
918
+							+ $sat->dps->d3222 * sin(-$xomi + $sat->dps->xli - Predict::g32)
919
+							+ $sat->dps->d4410 * sin($x2omi + $x2li- Predict::g44)
920
+							+ $sat->dps->d4422 * sin($x2li- Predict::g44)
921
+							+ $sat->dps->d5220 * sin($xomi + $sat->dps->xli- Predict::g52)
922
+							+ $sat->dps->d5232 * sin(-$xomi + $sat->dps->xli- Predict::g52)
923
+							+ $sat->dps->d5421 * sin($xomi + $x2li - Predict::g54)
924
+							+ $sat->dps->d5433 * sin(-$xomi + $x2li - Predict::g54);
925
+						$xnddt = $sat->dps->d2201 * cos($x2omi + $sat->dps->xli- Predict::g22)
926
+							+ $sat->dps->d2211 * cos($sat->dps->xli - Predict::g22)
927
+							+ $sat->dps->d3210 * cos($xomi + $sat->dps->xli - Predict::g32)
928
+							+ $sat->dps->d3222 * cos(-$xomi + $sat->dps->xli - Predict::g32)
929
+							+ $sat->dps->d5220 * cos($xomi + $sat->dps->xli - Predict::g52)
930
+							+ $sat->dps->d5232 * cos(-$xomi + $sat->dps->xli - Predict::g52)
931
+							+ 2 * ($sat->dps->d4410 * cos($x2omi + $x2li - Predict::g44)
932
+								+ $sat->dps->d4422 * cos($x2li - Predict::g44)
933
+								+ $sat->dps->d5421 * cos($xomi + $x2li - Predict::g54)
934
+								+ $sat->dps->d5433 * cos(-$xomi + $x2li - Predict::g54));
935
+					} /* End of if (isFlagSet(SYNCHRONOUS_FLAG)) */
936
+
937
+					$xldot = $sat->dps->xni + $sat->dps->xfact;
938
+					$xnddt = $xnddt * $xldot;
939
+
940
+					if ($sat->flags & self::DO_LOOP_FLAG) {
941
+						$sat->dps->xli = $sat->dps->xli + $xldot * $delt + $xndot * $sat->dps->step2;
942
+						$sat->dps->xni = $sat->dps->xni + $xndot * $delt + $xnddt * $sat->dps->step2;
943
+						$sat->dps->atime = $sat->dps->atime + $delt;
944
+					}
945
+				} while (($sat->flags & self::DO_LOOP_FLAG) &&
946
+						(~$sat->flags & self::EPOCH_RESTART_FLAG));
947
+			}
948
+			while (($sat->flags & self::DO_LOOP_FLAG) && ($sat->flags & self::EPOCH_RESTART_FLAG));
949
+
950
+			$sat->deep_arg->xn = $sat->dps->xni + $xndot * $ft + $xnddt * $ft * $ft * 0.5;
951
+			$xl = $sat->dps->xli + $xldot * $ft + $xndot * $ft * $ft * 0.5;
952
+			$temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t * Predict::thdt;
953
+
954
+			if (~$sat->flags & self::SYNCHRONOUS_FLAG) {
955
+				$sat->deep_arg->xll = $xl + $temp + $temp;
956
+			} else {
957
+				$sat->deep_arg->xll = $xl - $sat->deep_arg->omgadf + $temp;
958
+			}
959
+
960
+			return;
961
+			/* End case dpsec: */
962
+
963
+		case self::dpper: /* Entrance for lunar-solar periodics */
964
+			$sinis = sin($sat->deep_arg->xinc);
965
+			$cosis = cos($sat->deep_arg->xinc);
966
+			if (abs($sat->dps->savtsn - $sat->deep_arg->t) >= 30) {
967
+				$sat->dps->savtsn = $sat->deep_arg->t;
968
+				$zm = $sat->dps->zmos + Predict::zns * $sat->deep_arg->t;
969
+				$zf = $zm + 2 * Predict::zes * sin($zm);
970
+				$sinzf = sin($zf);
971
+				$f2 = 0.5 * $sinzf * $sinzf - 0.25;
972
+				$f3 = -0.5 * $sinzf * cos($zf);
973
+				$ses = $sat->dps->se2 * $f2 + $sat->dps->se3 * $f3;
974
+				$sis = $sat->dps->si2 * $f2 + $sat->dps->si3 * $f3;
975
+				$sls = $sat->dps->sl2 * $f2 + $sat->dps->sl3 * $f3 + $sat->dps->sl4 * $sinzf;
976
+				$sat->dps->sghs = $sat->dps->sgh2 * $f2 + $sat->dps->sgh3 * $f3 + $sat->dps->sgh4 * $sinzf;
977
+				$sat->dps->shs = $sat->dps->sh2 * $f2 + $sat->dps->sh3 * $f3;
978
+				$zm = $sat->dps->zmol + Predict::znl * $sat->deep_arg->t;
979
+				$zf = $zm + 2 * Predict::zel * sin($zm);
980
+				$sinzf = sin($zf);
981
+				$f2 = 0.5 * $sinzf * $sinzf - 0.25;
982
+				$f3 = -0.5 * $sinzf * cos($zf);
983
+				$sel = $sat->dps->ee2 * $f2 + $sat->dps->e3 * $f3;
984
+				$sil = $sat->dps->xi2 * $f2 + $sat->dps->xi3 * $f3;
985
+				$sll = $sat->dps->xl2 * $f2 + $sat->dps->xl3 * $f3 + $sat->dps->xl4 * $sinzf;
986
+				$sat->dps->sghl = $sat->dps->xgh2 * $f2 + $sat->dps->xgh3 * $f3 + $sat->dps->xgh4 * $sinzf;
987
+				$sat->dps->sh1 = $sat->dps->xh2 * $f2 + $sat->dps->xh3 * $f3;
988
+				$sat->dps->pe = $ses + $sel;
989
+				$sat->dps->pinc = $sis + $sil;
990
+				$sat->dps->pl = $sls + $sll;
991
+			}
992
+
993
+			$pgh = $sat->dps->sghs + $sat->dps->sghl;
994
+			$ph = $sat->dps->shs + $sat->dps->sh1;
995
+			$sat->deep_arg->xinc = $sat->deep_arg->xinc + $sat->dps->pinc;
996
+			$sat->deep_arg->em = $sat->deep_arg->em + $sat->dps->pe;
997
+
998
+			if ($sat->dps->xqncl >= 0.2) {
999
+				/* Apply periodics directly */
1000
+				$ph = $ph / $sat->deep_arg->sinio;
1001
+				$pgh = $pgh - $sat->deep_arg->cosio * $ph;
1002
+				$sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $pgh;
1003
+				$sat->deep_arg->xnode = $sat->deep_arg->xnode + $ph;
1004
+				$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1005
+			} else {
1006
+				/* Apply periodics with Lyddane modification */
1007
+				$sinok = sin($sat->deep_arg->xnode);
1008
+				$cosok = cos($sat->deep_arg->xnode);
1009
+				$alfdp = $sinis * $sinok;
1010
+				$betdp = $sinis * $cosok;
1011
+				$dalf = $ph * $cosok + $sat->dps->pinc * $cosis * $sinok;
1012
+				$dbet = -$ph * $sinok + $sat->dps->pinc * $cosis * $cosok;
1013
+				$alfdp = $alfdp + $dalf;
1014
+				$betdp = $betdp + $dbet;
1015
+				$sat->deep_arg->xnode = Predict_Math::FMod2p($sat->deep_arg->xnode);
1016
+				$xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis * $sat->deep_arg->xnode;
1017
+				$dls = $sat->dps->pl + $pgh - $sat->dps->pinc * $sat->deep_arg->xnode * $sinis;
1018
+				$xls = $xls + $dls;
1019
+				$xnoh = $sat->deep_arg->xnode;
1020
+				$sat->deep_arg->xnode = Predict_Math::AcTan($alfdp, $betdp);
1021
+
1022
+				/* This is a patch to Lyddane modification */
1023
+				/* suggested by Rob Matson. */
1024
+				if(abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1025
+					if ($sat->deep_arg->xnode < $xnoh) {
1026
+						$sat->deep_arg->xnode += Predict::twopi;
1027
+					} else {
1028
+						$sat->deep_arg->xnode -= Predict::twopi;
1029
+					}
1030
+				}
1031
+
1032
+				$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1033
+				$sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc) *
1034
+					$sat->deep_arg->xnode;
1035
+			} /* End case dpper: */
1036
+			return;
1037
+
1038
+		} /* End switch(ientry) */
1039
+
1040
+	} /* End of Deep() */
1041
+
1042
+	/**
1043
+	 * Singleton
1044
+	 *
1045
+	 * @param Predict_Sat $sat The current satellite data instance
1046
+	 *
1047
+	 * @return Predict_SGPSDP
1048
+	 */
1049
+	public static function getInstance(Predict_Sat $sat)
1050
+	{
1051
+		static $instances = array();
1052
+		$catnr = $sat->tle->catnr;
1053
+		if (!isset($instances[$catnr])) {
1054
+			$instances[$catnr] = new self();
1055
+		}
1056
+		return $instances[$catnr];
1057
+	}
1058 1058
 }
1059 1059
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +493 added lines, -493 removed lines patch added patch discarded remove patch
@@ -541,499 +541,499 @@
 block discarded – undo
541 541
     public function Deep($ientry, Predict_Sat $sat)
542 542
     {
543 543
         switch ($ientry) {
544
-        case self::dpinit : /* Entrance for deep space initialization */
545
-            $sat->dps->thgr = Predict_Time::ThetaG($sat->tle->epoch, $sat->deep_arg);
546
-            $eq = $sat->tle->eo;
547
-            $sat->dps->xnq = $sat->deep_arg->xnodp;
548
-            $aqnv = 1.0 / $sat->deep_arg->aodp;
549
-            $sat->dps->xqncl = $sat->tle->xincl;
550
-            $xmao = $sat->tle->xmo;
551
-            $xpidot = $sat->deep_arg->omgdot + $sat->deep_arg->xnodot;
552
-            $sinq = sin($sat->tle->xnodeo);
553
-            $cosq = cos($sat->tle->xnodeo);
554
-            $sat->dps->omegaq = $sat->tle->omegao;
555
-            $sat->dps->preep = 0;
556
-
557
-            /* Initialize lunar solar terms */
558
-            $day = $sat->deep_arg->ds50 + 18261.5;  /* Days since 1900 Jan 0.5 */
559
-            if ($day != $sat->dps->preep) {
560
-                $sat->dps->preep = $day;
561
-                $xnodce = 4.5236020 - 9.2422029E-4 * $day;
562
-                $stem = sin($xnodce);
563
-                $ctem = cos($xnodce);
564
-                $sat->dps->zcosil = 0.91375164 - 0.03568096 * $ctem;
565
-                $sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil * $sat->dps->zcosil);
566
-                $sat->dps->zsinhl = 0.089683511 * $stem / $sat->dps->zsinil;
567
-                $sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl * $sat->dps->zsinhl);
568
-                $c = 4.7199672 + 0.22997150 * $day;
569
-                $gam = 5.8351514 + 0.0019443680 * $day;
570
-                $sat->dps->zmol = Predict_Math::FMod2p($c - $gam);
571
-                $zx = 0.39785416 * $stem / $sat->dps->zsinil;
572
-                $zy = $sat->dps->zcoshl * $ctem + 0.91744867 * $sat->dps->zsinhl * $stem;
573
-                $zx = Predict_Math::AcTan($zx, $zy);
574
-                $zx = $gam + $zx - $xnodce;
575
-                $sat->dps->zcosgl = cos($zx);
576
-                $sat->dps->zsingl = sin($zx);
577
-                $sat->dps->zmos = 6.2565837 + 0.017201977 * $day;
578
-                $sat->dps->zmos = Predict_Math::FMod2p($sat->dps->zmos);
579
-            } /* End if(day != preep) */
580
-
581
-            /* Do solar terms */
582
-            $sat->dps->savtsn = 1E20;
583
-            $zcosg = Predict::zcosgs;
584
-            $zsing = Predict::zsings;
585
-            $zcosi = Predict::zcosis;
586
-            $zsini = Predict::zsinis;
587
-            $zcosh = $cosq;
588
-            $zsinh = $sinq;
589
-            $cc = Predict::c1ss;
590
-            $zn = Predict::zns;
591
-            $ze = Predict::zes;
592
-            $zmo = $sat->dps->zmos;
593
-            $xnoi = 1.0 / $sat->dps->xnq;
594
-
595
-            /* Loop breaks when Solar terms are done a second */
596
-            /* time, after Lunar terms are initialized        */
597
-            for(;;) {
598
-                /* Solar terms done again after Lunar terms are done */
599
-                $a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
600
-                $a3 = -$zsing * $zcosh + $zcosg * $zcosi * $zsinh;
601
-                $a7 = -$zcosg * $zsinh + $zsing * $zcosi * $zcosh;
602
-                $a8 = $zsing * $zsini;
603
-                $a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
604
-                $a10 = $zcosg * $zsini;
605
-                $a2 = $sat->deep_arg->cosio * $a7 + $sat->deep_arg->sinio * $a8;
606
-                $a4 = $sat->deep_arg->cosio * $a9 + $sat->deep_arg->sinio * $a10;
607
-                $a5 = -$sat->deep_arg->sinio * $a7 + $sat->deep_arg->cosio * $a8;
608
-                $a6 = -$sat->deep_arg->sinio * $a9 + $sat->deep_arg->cosio * $a10;
609
-                $x1 = $a1 * $sat->deep_arg->cosg + $a2 * $sat->deep_arg->sing;
610
-                $x2 = $a3 * $sat->deep_arg->cosg + $a4 * $sat->deep_arg->sing;
611
-                $x3 = -$a1 * $sat->deep_arg->sing + $a2 * $sat->deep_arg->cosg;
612
-                $x4 = -$a3 * $sat->deep_arg->sing + $a4 * $sat->deep_arg->cosg;
613
-                $x5 = $a5 * $sat->deep_arg->sing;
614
-                $x6 = $a6 * $sat->deep_arg->sing;
615
-                $x7 = $a5 * $sat->deep_arg->cosg;
616
-                $x8 = $a6 * $sat->deep_arg->cosg;
617
-                $z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
618
-                $z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
619
-                $z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
620
-                $z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $sat->deep_arg->eosq;
621
-                $z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $sat->deep_arg->eosq;
622
-                $z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $sat->deep_arg->eosq;
623
-                $z11 = -6 * $a1 * $a5 + $sat->deep_arg->eosq * (-24 * $x1 * $x7 - 6 * $x3 * $x5);
624
-                $z12 = -6 * ($a1 * $a6 + $a3 * $a5) + $sat->deep_arg->eosq *
625
-                    (-24 * ($x2 * $x7 + $x1 * $x8) - 6 * ($x3 * $x6 + $x4 * $x5));
626
-                $z13 = -6 * $a3 * $a6 + $sat->deep_arg->eosq * (-24 * $x2 * $x8 - 6 * $x4 * $x6);
627
-                $z21 = 6 * $a2 * $a5 + $sat->deep_arg->eosq * (24 * $x1 * $x5 - 6 * $x3 * $x7);
628
-                $z22 = 6 * ($a4 * $a5 + $a2 * $a6) + $sat->deep_arg->eosq *
629
-                    (24 * ($x2 * $x5 + $x1 * $x6) - 6 * ($x4 * $x7 + $x3 * $x8));
630
-                $z23 = 6 * $a4 * $a6 + $sat->deep_arg->eosq * (24 * $x2 * $x6 - 6 * $x4 * $x8);
631
-                $z1 = $z1 + $z1 + $sat->deep_arg->betao2 * $z31;
632
-                $z2 = $z2 + $z2 + $sat->deep_arg->betao2 * $z32;
633
-                $z3 = $z3 + $z3 + $sat->deep_arg->betao2 * $z33;
634
-                $s3 = $cc * $xnoi;
635
-                $s2 = -0.5 * $s3 / $sat->deep_arg->betao;
636
-                $s4 = $s3 * $sat->deep_arg->betao;
637
-                $s1 = -15 * $eq * $s4;
638
-                $s5 = $x1 * $x3 + $x2 * $x4;
639
-                $s6 = $x2 * $x3 + $x1 * $x4;
640
-                $s7 = $x2 * $x4 - $x1 * $x3;
641
-                $se = $s1 * $zn * $s5;
642
-                $si = $s2 * $zn * ($z11 + $z13);
643
-                $sl = -$zn * $s3 * ($z1 + $z3 - 14 - 6 * $sat->deep_arg->eosq);
644
-                $sgh = $s4 * $zn * ($z31 + $z33 - 6);
645
-                $sh = -$zn * $s2 * ($z21 + $z23);
646
-                if ($sat->dps->xqncl < 5.2359877E-2) {
647
-                    $sh = 0;
648
-                }
649
-                $sat->dps->ee2 = 2 * $s1 * $s6;
650
-                $sat->dps->e3 = 2 * $s1 * $s7;
651
-                $sat->dps->xi2 = 2 * $s2 * $z12;
652
-                $sat->dps->xi3 = 2 * $s2 * ($z13 - $z11);
653
-                $sat->dps->xl2 = -2 * $s3 * $z2;
654
-                $sat->dps->xl3 = -2 * $s3 * ($z3 - $z1);
655
-                $sat->dps->xl4 = -2 * $s3 * (-21 - 9 * $sat->deep_arg->eosq) * $ze;
656
-                $sat->dps->xgh2 = 2 * $s4 * $z32;
657
-                $sat->dps->xgh3 = 2 * $s4 * ($z33 - $z31);
658
-                $sat->dps->xgh4 = -18 * $s4 * $ze;
659
-                $sat->dps->xh2 = -2 * $s2 * $z22;
660
-                $sat->dps->xh3 = -2 * $s2 * ($z23 - $z21);
661
-
662
-                if ($sat->flags & self::LUNAR_TERMS_DONE_FLAG) {
663
-                    break;
664
-                }
665
-
666
-                /* Do lunar terms */
667
-                $sat->dps->sse = $se;
668
-                $sat->dps->ssi = $si;
669
-                $sat->dps->ssl = $sl;
670
-                $sat->dps->ssh = $sh / $sat->deep_arg->sinio;
671
-                $sat->dps->ssg = $sgh - $sat->deep_arg->cosio * $sat->dps->ssh;
672
-                $sat->dps->se2 = $sat->dps->ee2;
673
-                $sat->dps->si2 = $sat->dps->xi2;
674
-                $sat->dps->sl2 = $sat->dps->xl2;
675
-                $sat->dps->sgh2 = $sat->dps->xgh2;
676
-                $sat->dps->sh2 = $sat->dps->xh2;
677
-                $sat->dps->se3 = $sat->dps->e3;
678
-                $sat->dps->si3 = $sat->dps->xi3;
679
-                $sat->dps->sl3 = $sat->dps->xl3;
680
-                $sat->dps->sgh3 = $sat->dps->xgh3;
681
-                $sat->dps->sh3 = $sat->dps->xh3;
682
-                $sat->dps->sl4 = $sat->dps->xl4;
683
-                $sat->dps->sgh4 = $sat->dps->xgh4;
684
-                $zcosg = $sat->dps->zcosgl;
685
-                $zsing = $sat->dps->zsingl;
686
-                $zcosi = $sat->dps->zcosil;
687
-                $zsini = $sat->dps->zsinil;
688
-                $zcosh = $sat->dps->zcoshl * $cosq + $sat->dps->zsinhl * $sinq;
689
-                $zsinh = $sinq * $sat->dps->zcoshl - $cosq * $sat->dps->zsinhl;
690
-                $zn = Predict::znl;
691
-                $cc = Predict::c1l;
692
-                $ze = Predict::zel;
693
-                $zmo = $sat->dps->zmol;
694
-                $sat->flags |= self::LUNAR_TERMS_DONE_FLAG;
695
-            } /* End of for(;;) */
696
-
697
-            $sat->dps->sse = $sat->dps->sse + $se;
698
-            $sat->dps->ssi = $sat->dps->ssi + $si;
699
-            $sat->dps->ssl = $sat->dps->ssl + $sl;
700
-            $sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio / $sat->deep_arg->sinio * $sh;
701
-            $sat->dps->ssh = $sat->dps->ssh + $sh / $sat->deep_arg->sinio;
702
-
703
-            /* Geopotential resonance initialization for 12 hour orbits */
704
-            $sat->flags &= ~self::RESONANCE_FLAG;
705
-            $sat->flags &= ~self::SYNCHRONOUS_FLAG;
706
-
707
-            if (!(($sat->dps->xnq < 0.0052359877) && ($sat->dps->xnq > 0.0034906585))) {
708
-                if( ($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924) ) {
709
-                    return;
710
-                }
711
-                if ($eq < 0.5) {
712
-                    return;
713
-                }
714
-                $sat->flags |= self::RESONANCE_FLAG;
715
-                $eoc = $eq * $sat->deep_arg->eosq;
716
-                $g201 = -0.306 - ($eq - 0.64) * 0.440;
717
-                if ($eq <= 0.65) {
718
-                    $g211 = 3.616 - 13.247 * $eq + 16.290 * $sat->deep_arg->eosq;
719
-                    $g310 = -19.302 + 117.390 * $eq - 228.419 *
720
-                        $sat->deep_arg->eosq + 156.591 * $eoc;
721
-                    $g322 = -18.9068 + 109.7927 * $eq - 214.6334 *
722
-                        $sat->deep_arg->eosq + 146.5816 * $eoc;
723
-                    $g410 = -41.122 + 242.694 * $eq - 471.094 *
724
-                        $sat->deep_arg->eosq + 313.953 * $eoc;
725
-                    $g422 = -146.407 + 841.880 * $eq - 1629.014 *
726
-                        $sat->deep_arg->eosq + 1083.435 * $eoc;
727
-                    $g520 = -532.114 + 3017.977 * $eq - 5740 *
728
-                        $sat->deep_arg->eosq + 3708.276 * $eoc;
729
-                } else {
730
-                    $g211 = -72.099 + 331.819 * $eq - 508.738 *
731
-                        $sat->deep_arg->eosq + 266.724 * $eoc;
732
-                    $g310 = -346.844 + 1582.851 * $eq - 2415.925 *
733
-                        $sat->deep_arg->eosq + 1246.113 * $eoc;
734
-                    $g322 = -342.585 + 1554.908 * $eq - 2366.899 *
735
-                        $sat->deep_arg->eosq + 1215.972 * $eoc;
736
-                    $g410 = -1052.797 + 4758.686 * $eq - 7193.992 *
737
-                        $sat->deep_arg->eosq + 3651.957 * $eoc;
738
-                    $g422 = -3581.69 + 16178.11 * $eq - 24462.77 *
739
-                        $sat->deep_arg->eosq+ 12422.52 * $eoc;
740
-                    if ($eq <= 0.715) {
741
-                        $g520 = 1464.74 - 4664.75 * $eq + 3763.64 * $sat->deep_arg->eosq;
742
-                    } else {
743
-                        $g520 = -5149.66 + 29936.92 * $eq - 54087.36 *
744
-                            $sat->deep_arg->eosq + 31324.56 * $eoc;
745
-                    }
746
-                } /* End if (eq <= 0.65) */
747
-
748
-                if ($eq < 0.7) {
749
-                    $g533 = -919.2277 + 4988.61 * $eq - 9064.77 *
750
-                        $sat->deep_arg->eosq + 5542.21 * $eoc;
751
-                    $g521 = -822.71072 + 4568.6173 * $eq - 8491.4146 *
752
-                        $sat->deep_arg->eosq + 5337.524 * $eoc;
753
-                    $g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754
-                        $sat->deep_arg->eosq + 5341.4 * $eoc;
755
-                }
756
-                else {
757
-                    $g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758
-                        $sat->deep_arg->eosq + 109377.94 * $eoc;
759
-                    $g521 = -51752.104 + 218913.95 * $eq - 309468.16*
760
-                        $sat->deep_arg->eosq + 146349.42 * $eoc;
761
-                    $g532 = -40023.88 + 170470.89 * $eq - 242699.48*
762
-                        $sat->deep_arg->eosq + 115605.82 * $eoc;
763
-                } /* End if (eq <= 0.7) */
764
-
765
-                $sini2 = $sat->deep_arg->sinio * $sat->deep_arg->sinio;
766
-                $f220 = 0.75 * (1 + 2 * $sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
-                $f221 = 1.5 * $sini2;
768
-                $f321 = 1.875 * $sat->deep_arg->sinio * (1 - 2 *
769
-                                  $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
770
-                $f322 = -1.875 * $sat->deep_arg->sinio * (1 + 2*
771
-                                   $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
772
-                $f441 = 35 * $sini2 * $f220;
773
-                $f442 = 39.3750 * $sini2 * $sini2;
774
-                $f522 = 9.84375 * $sat->deep_arg->sinio * ($sini2 * (1 - 2 * $sat->deep_arg->cosio - 5 *
775
-                                       $sat->deep_arg->theta2) + 0.33333333 * (-2 + 4 * $sat->deep_arg->cosio +
776
-                                                     6 * $sat->deep_arg->theta2));
777
-                $f523 = $sat->deep_arg->sinio * (4.92187512 * $sini2 * (-2 - 4 *
778
-                                      $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2) + 6.56250012
779
-                            * (1 + 2 * $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2));
780
-                $f542 = 29.53125 * $sat->deep_arg->sinio * (2 - 8 *
781
-                                 $sat->deep_arg->cosio + $sat->deep_arg->theta2 *
782
-                                 (-12 + 8 * $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2));
783
-                $f543 = 29.53125 * $sat->deep_arg->sinio * (-2 - 8 * $sat->deep_arg->cosio +
784
-                                 $sat->deep_arg->theta2 * (12 + 8 * $sat->deep_arg->cosio - 10 *
785
-                                           $sat->deep_arg->theta2));
786
-                $xno2 = $sat->dps->xnq * $sat->dps->xnq;
787
-                $ainv2 = $aqnv * $aqnv;
788
-                $temp1 = 3 * $xno2 * $ainv2;
789
-                $temp = $temp1 * Predict::root22;
790
-                $sat->dps->d2201 = $temp * $f220 * $g201;
791
-                $sat->dps->d2211 = $temp * $f221 * $g211;
792
-                $temp1 = $temp1 * $aqnv;
793
-                $temp = $temp1 * Predict::root32;
794
-                $sat->dps->d3210 = $temp * $f321 * $g310;
795
-                $sat->dps->d3222 = $temp * $f322 * $g322;
796
-                $temp1 = $temp1 * $aqnv;
797
-                $temp = 2 * $temp1 * Predict::root44;
798
-                $sat->dps->d4410 = $temp * $f441 * $g410;
799
-                $sat->dps->d4422 = $temp * $f442 * $g422;
800
-                $temp1 = $temp1 * $aqnv;
801
-                $temp = $temp1 * Predict::root52;
802
-                $sat->dps->d5220 = $temp * $f522 * $g520;
803
-                $sat->dps->d5232 = $temp * $f523 * $g532;
804
-                $temp = 2 * $temp1 * Predict::root54;
805
-                $sat->dps->d5421 = $temp * $f542 * $g521;
806
-                $sat->dps->d5433 = $temp * $f543 * $g533;
807
-                $sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->xnodeo - $sat->dps->thgr - $sat->dps->thgr;
808
-                $bfact = $sat->deep_arg->xmdot + $sat->deep_arg->xnodot +
809
-                    $sat->deep_arg->xnodot - Predict::thdt - Predict::thdt;
810
-                $bfact = $bfact + $sat->dps->ssl + $sat->dps->ssh + $sat->dps->ssh;
811
-            } else {
812
-                $sat->flags |= self::RESONANCE_FLAG;
813
-                $sat->flags |= self::SYNCHRONOUS_FLAG;
814
-                /* Synchronous resonance terms initialization */
815
-                $g200 = 1 + $sat->deep_arg->eosq * (-2.5 + 0.8125 * $sat->deep_arg->eosq);
816
-                $g310 = 1 + 2 * $sat->deep_arg->eosq;
817
-                $g300 = 1 + $sat->deep_arg->eosq * (-6 + 6.60937 * $sat->deep_arg->eosq);
818
-                $f220 = 0.75 * (1 + $sat->deep_arg->cosio) * (1 + $sat->deep_arg->cosio);
819
-                $f311 = 0.9375 * $sat->deep_arg->sinio * $sat->deep_arg->sinio *
820
-                    (1 + 3 * $sat->deep_arg->cosio) - 0.75 * (1 + $sat->deep_arg->cosio);
821
-                $f330 = 1 + $sat->deep_arg->cosio;
822
-                $f330 = 1.875 * $f330 * $f330 * $f330;
823
-                $sat->dps->del1 = 3 * $sat->dps->xnq * $sat->dps->xnq * $aqnv * $aqnv;
824
-                $sat->dps->del2 = 2 * $sat->dps->del1 * $f220 * $g200 * Predict::q22;
825
-                $sat->dps->del3 = 3 * $sat->dps->del1 * $f330 * $g300 * Predict::q33 * $aqnv;
826
-                $sat->dps->del1 = $sat->dps->del1 * $f311 * $g310 * Predict::q31 * $aqnv;
827
-                $sat->dps->fasx2 = 0.13130908;
828
-                $sat->dps->fasx4 = 2.8843198;
829
-                $sat->dps->fasx6 = 0.37448087;
830
-                $sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->omegao - $sat->dps->thgr;
831
-                $bfact = $sat->deep_arg->xmdot + $xpidot - Predict::thdt;
832
-                $bfact = $bfact + $sat->dps->ssl + $sat->dps->ssg + $sat->dps->ssh;
833
-            } /* End if( !(xnq < 0.0052359877) && (xnq > 0.0034906585) ) */
834
-
835
-            $sat->dps->xfact = $bfact - $sat->dps->xnq;
836
-
837
-            /* Initialize integrator */
838
-            $sat->dps->xli = $sat->dps->xlamo;
839
-            $sat->dps->xni = $sat->dps->xnq;
840
-            $sat->dps->atime = 0;
841
-            $sat->dps->stepp = 720;
842
-            $sat->dps->stepn = -720;
843
-            $sat->dps->step2 = 259200;
844
-            /* End case self::dpinit: */
845
-            return;
846
-
847
-        case self::dpsec: /* Entrance for deep space secular effects */
848
-            $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl * $sat->deep_arg->t;
849
-            $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg * $sat->deep_arg->t;
850
-            $sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh * $sat->deep_arg->t;
851
-            $sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse * $sat->deep_arg->t;
852
-            $sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi * $sat->deep_arg->t;
853
-            if ($sat->deep_arg->xinc < 0) {
854
-                $sat->deep_arg->xinc = -$sat->deep_arg->xinc;
855
-                $sat->deep_arg->xnode = $sat->deep_arg->xnode + Predict::pi;
856
-                $sat->deep_arg->omgadf = $sat->deep_arg->omgadf - Predict::pi;
857
-            }
858
-            if(~$sat->flags & self::RESONANCE_FLAG ) {
859
-                return;
860
-            }
861
-
862
-            do {
863
-                if ( ($sat->dps->atime == 0) ||
864
-                    (($sat->deep_arg->t >= 0) && ($sat->dps->atime < 0)) ||
865
-                    (($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0)) ) {
866
-                    /* Epoch restart */
867
-                    if ($sat->deep_arg->t >= 0) {
868
-                        $delt = $sat->dps->stepp;
869
-                    } else {
870
-                        $delt = $sat->dps->stepn;
871
-                    }
872
-
873
-                    $sat->dps->atime = 0;
874
-                    $sat->dps->xni = $sat->dps->xnq;
875
-                    $sat->dps->xli = $sat->dps->xlamo;
876
-                } else {
877
-                    if (abs($sat->deep_arg->t) >= abs($sat->dps->atime)) {
878
-                        if ($sat->deep_arg->t > 0) {
879
-                            $delt = $sat->dps->stepp;
880
-                        } else {
881
-                            $delt = $sat->dps->stepn;
882
-                        }
883
-                    }
884
-                }
885
-
886
-                do {
887
-                    if (abs($sat->deep_arg->t - $sat->dps->atime) >= $sat->dps->stepp) {
888
-                        $sat->flags |= self::DO_LOOP_FLAG;
889
-                        $sat->flags &= ~self::EPOCH_RESTART_FLAG;
890
-                    }
891
-                    else {
892
-                        $ft = $sat->deep_arg->t - $sat->dps->atime;
893
-                        $sat->flags &= ~self::DO_LOOP_FLAG;
894
-                    }
895
-
896
-                    if (abs($sat->deep_arg->t) < abs($sat->dps->atime)) {
897
-                        if ($sat->deep_arg->t >= 0) {
898
-                            $delt = $sat->dps->stepn;
899
-                        } else {
900
-                            $delt = $sat->dps->stepp;
901
-                        }
902
-                        $sat->flags |= (self::DO_LOOP_FLAG | self::EPOCH_RESTART_FLAG);
903
-                    }
904
-
905
-                    /* Dot terms calculated */
906
-                    if ($sat->flags & self::SYNCHRONOUS_FLAG) {
907
-                        $xndot = $sat->dps->del1 * sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2 * sin(2 * ($sat->dps->xli - $sat->dps->fasx4))
908
-                            + $sat->dps->del3 * sin(3 * ($sat->dps->xli - $sat->dps->fasx6));
909
-                        $xnddt = $sat->dps->del1 * cos($sat->dps->xli - $sat->dps->fasx2) + 2 * $sat->dps->del2 * cos(2 * ($sat->dps->xli - $sat->dps->fasx4))
910
-                            + 3 * $sat->dps->del3 * cos(3 * ($sat->dps->xli - $sat->dps->fasx6));
911
-                    } else {
912
-                        $xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot * $sat->dps->atime;
913
-                        $x2omi = $xomi + $xomi;
914
-                        $x2li = $sat->dps->xli + $sat->dps->xli;
915
-                        $xndot = $sat->dps->d2201 * sin($x2omi + $sat->dps->xli - Predict::g22)
916
-                            + $sat->dps->d2211 * sin($sat->dps->xli - Predict::g22)
917
-                            + $sat->dps->d3210 * sin($xomi + $sat->dps->xli - Predict::g32)
918
-                            + $sat->dps->d3222 * sin(-$xomi + $sat->dps->xli - Predict::g32)
919
-                            + $sat->dps->d4410 * sin($x2omi + $x2li- Predict::g44)
920
-                            + $sat->dps->d4422 * sin($x2li- Predict::g44)
921
-                            + $sat->dps->d5220 * sin($xomi + $sat->dps->xli- Predict::g52)
922
-                            + $sat->dps->d5232 * sin(-$xomi + $sat->dps->xli- Predict::g52)
923
-                            + $sat->dps->d5421 * sin($xomi + $x2li - Predict::g54)
924
-                            + $sat->dps->d5433 * sin(-$xomi + $x2li - Predict::g54);
925
-                        $xnddt = $sat->dps->d2201 * cos($x2omi + $sat->dps->xli- Predict::g22)
926
-                            + $sat->dps->d2211 * cos($sat->dps->xli - Predict::g22)
927
-                            + $sat->dps->d3210 * cos($xomi + $sat->dps->xli - Predict::g32)
928
-                            + $sat->dps->d3222 * cos(-$xomi + $sat->dps->xli - Predict::g32)
929
-                            + $sat->dps->d5220 * cos($xomi + $sat->dps->xli - Predict::g52)
930
-                            + $sat->dps->d5232 * cos(-$xomi + $sat->dps->xli - Predict::g52)
931
-                            + 2 * ($sat->dps->d4410 * cos($x2omi + $x2li - Predict::g44)
932
-                                + $sat->dps->d4422 * cos($x2li - Predict::g44)
933
-                                + $sat->dps->d5421 * cos($xomi + $x2li - Predict::g54)
934
-                                + $sat->dps->d5433 * cos(-$xomi + $x2li - Predict::g54));
935
-                    } /* End of if (isFlagSet(SYNCHRONOUS_FLAG)) */
936
-
937
-                    $xldot = $sat->dps->xni + $sat->dps->xfact;
938
-                    $xnddt = $xnddt * $xldot;
939
-
940
-                    if ($sat->flags & self::DO_LOOP_FLAG) {
941
-                        $sat->dps->xli = $sat->dps->xli + $xldot * $delt + $xndot * $sat->dps->step2;
942
-                        $sat->dps->xni = $sat->dps->xni + $xndot * $delt + $xnddt * $sat->dps->step2;
943
-                        $sat->dps->atime = $sat->dps->atime + $delt;
944
-                    }
945
-                } while (($sat->flags & self::DO_LOOP_FLAG) &&
946
-                        (~$sat->flags & self::EPOCH_RESTART_FLAG));
947
-            }
948
-            while (($sat->flags & self::DO_LOOP_FLAG) && ($sat->flags & self::EPOCH_RESTART_FLAG));
949
-
950
-            $sat->deep_arg->xn = $sat->dps->xni + $xndot * $ft + $xnddt * $ft * $ft * 0.5;
951
-            $xl = $sat->dps->xli + $xldot * $ft + $xndot * $ft * $ft * 0.5;
952
-            $temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t * Predict::thdt;
953
-
954
-            if (~$sat->flags & self::SYNCHRONOUS_FLAG) {
955
-                $sat->deep_arg->xll = $xl + $temp + $temp;
956
-            } else {
957
-                $sat->deep_arg->xll = $xl - $sat->deep_arg->omgadf + $temp;
958
-            }
959
-
960
-            return;
961
-            /* End case dpsec: */
962
-
963
-        case self::dpper: /* Entrance for lunar-solar periodics */
964
-            $sinis = sin($sat->deep_arg->xinc);
965
-            $cosis = cos($sat->deep_arg->xinc);
966
-            if (abs($sat->dps->savtsn - $sat->deep_arg->t) >= 30) {
967
-                $sat->dps->savtsn = $sat->deep_arg->t;
968
-                $zm = $sat->dps->zmos + Predict::zns * $sat->deep_arg->t;
969
-                $zf = $zm + 2 * Predict::zes * sin($zm);
970
-                $sinzf = sin($zf);
971
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
972
-                $f3 = -0.5 * $sinzf * cos($zf);
973
-                $ses = $sat->dps->se2 * $f2 + $sat->dps->se3 * $f3;
974
-                $sis = $sat->dps->si2 * $f2 + $sat->dps->si3 * $f3;
975
-                $sls = $sat->dps->sl2 * $f2 + $sat->dps->sl3 * $f3 + $sat->dps->sl4 * $sinzf;
976
-                $sat->dps->sghs = $sat->dps->sgh2 * $f2 + $sat->dps->sgh3 * $f3 + $sat->dps->sgh4 * $sinzf;
977
-                $sat->dps->shs = $sat->dps->sh2 * $f2 + $sat->dps->sh3 * $f3;
978
-                $zm = $sat->dps->zmol + Predict::znl * $sat->deep_arg->t;
979
-                $zf = $zm + 2 * Predict::zel * sin($zm);
980
-                $sinzf = sin($zf);
981
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
982
-                $f3 = -0.5 * $sinzf * cos($zf);
983
-                $sel = $sat->dps->ee2 * $f2 + $sat->dps->e3 * $f3;
984
-                $sil = $sat->dps->xi2 * $f2 + $sat->dps->xi3 * $f3;
985
-                $sll = $sat->dps->xl2 * $f2 + $sat->dps->xl3 * $f3 + $sat->dps->xl4 * $sinzf;
986
-                $sat->dps->sghl = $sat->dps->xgh2 * $f2 + $sat->dps->xgh3 * $f3 + $sat->dps->xgh4 * $sinzf;
987
-                $sat->dps->sh1 = $sat->dps->xh2 * $f2 + $sat->dps->xh3 * $f3;
988
-                $sat->dps->pe = $ses + $sel;
989
-                $sat->dps->pinc = $sis + $sil;
990
-                $sat->dps->pl = $sls + $sll;
991
-            }
992
-
993
-            $pgh = $sat->dps->sghs + $sat->dps->sghl;
994
-            $ph = $sat->dps->shs + $sat->dps->sh1;
995
-            $sat->deep_arg->xinc = $sat->deep_arg->xinc + $sat->dps->pinc;
996
-            $sat->deep_arg->em = $sat->deep_arg->em + $sat->dps->pe;
997
-
998
-            if ($sat->dps->xqncl >= 0.2) {
999
-                /* Apply periodics directly */
1000
-                $ph = $ph / $sat->deep_arg->sinio;
1001
-                $pgh = $pgh - $sat->deep_arg->cosio * $ph;
1002
-                $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $pgh;
1003
-                $sat->deep_arg->xnode = $sat->deep_arg->xnode + $ph;
1004
-                $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1005
-            } else {
1006
-                /* Apply periodics with Lyddane modification */
1007
-                $sinok = sin($sat->deep_arg->xnode);
1008
-                $cosok = cos($sat->deep_arg->xnode);
1009
-                $alfdp = $sinis * $sinok;
1010
-                $betdp = $sinis * $cosok;
1011
-                $dalf = $ph * $cosok + $sat->dps->pinc * $cosis * $sinok;
1012
-                $dbet = -$ph * $sinok + $sat->dps->pinc * $cosis * $cosok;
1013
-                $alfdp = $alfdp + $dalf;
1014
-                $betdp = $betdp + $dbet;
1015
-                $sat->deep_arg->xnode = Predict_Math::FMod2p($sat->deep_arg->xnode);
1016
-                $xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis * $sat->deep_arg->xnode;
1017
-                $dls = $sat->dps->pl + $pgh - $sat->dps->pinc * $sat->deep_arg->xnode * $sinis;
1018
-                $xls = $xls + $dls;
1019
-                $xnoh = $sat->deep_arg->xnode;
1020
-                $sat->deep_arg->xnode = Predict_Math::AcTan($alfdp, $betdp);
1021
-
1022
-                /* This is a patch to Lyddane modification */
1023
-                /* suggested by Rob Matson. */
1024
-                if(abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1025
-                    if ($sat->deep_arg->xnode < $xnoh) {
1026
-                        $sat->deep_arg->xnode += Predict::twopi;
1027
-                    } else {
1028
-                        $sat->deep_arg->xnode -= Predict::twopi;
1029
-                    }
1030
-                }
1031
-
1032
-                $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1033
-                $sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc) *
1034
-                    $sat->deep_arg->xnode;
1035
-            } /* End case dpper: */
1036
-            return;
544
+        	case self::dpinit : /* Entrance for deep space initialization */
545
+            	$sat->dps->thgr = Predict_Time::ThetaG($sat->tle->epoch, $sat->deep_arg);
546
+            	$eq = $sat->tle->eo;
547
+            	$sat->dps->xnq = $sat->deep_arg->xnodp;
548
+            	$aqnv = 1.0 / $sat->deep_arg->aodp;
549
+            	$sat->dps->xqncl = $sat->tle->xincl;
550
+            	$xmao = $sat->tle->xmo;
551
+            	$xpidot = $sat->deep_arg->omgdot + $sat->deep_arg->xnodot;
552
+            	$sinq = sin($sat->tle->xnodeo);
553
+            	$cosq = cos($sat->tle->xnodeo);
554
+            	$sat->dps->omegaq = $sat->tle->omegao;
555
+            	$sat->dps->preep = 0;
556
+
557
+            	/* Initialize lunar solar terms */
558
+            	$day = $sat->deep_arg->ds50 + 18261.5;  /* Days since 1900 Jan 0.5 */
559
+            	if ($day != $sat->dps->preep) {
560
+                	$sat->dps->preep = $day;
561
+                	$xnodce = 4.5236020 - 9.2422029E-4 * $day;
562
+                	$stem = sin($xnodce);
563
+                	$ctem = cos($xnodce);
564
+                	$sat->dps->zcosil = 0.91375164 - 0.03568096 * $ctem;
565
+                	$sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil * $sat->dps->zcosil);
566
+                	$sat->dps->zsinhl = 0.089683511 * $stem / $sat->dps->zsinil;
567
+                	$sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl * $sat->dps->zsinhl);
568
+                	$c = 4.7199672 + 0.22997150 * $day;
569
+                	$gam = 5.8351514 + 0.0019443680 * $day;
570
+                	$sat->dps->zmol = Predict_Math::FMod2p($c - $gam);
571
+                	$zx = 0.39785416 * $stem / $sat->dps->zsinil;
572
+                	$zy = $sat->dps->zcoshl * $ctem + 0.91744867 * $sat->dps->zsinhl * $stem;
573
+                	$zx = Predict_Math::AcTan($zx, $zy);
574
+                	$zx = $gam + $zx - $xnodce;
575
+                	$sat->dps->zcosgl = cos($zx);
576
+                	$sat->dps->zsingl = sin($zx);
577
+                	$sat->dps->zmos = 6.2565837 + 0.017201977 * $day;
578
+                	$sat->dps->zmos = Predict_Math::FMod2p($sat->dps->zmos);
579
+            	} /* End if(day != preep) */
580
+
581
+            	/* Do solar terms */
582
+            	$sat->dps->savtsn = 1E20;
583
+            	$zcosg = Predict::zcosgs;
584
+            	$zsing = Predict::zsings;
585
+            	$zcosi = Predict::zcosis;
586
+            	$zsini = Predict::zsinis;
587
+            	$zcosh = $cosq;
588
+            	$zsinh = $sinq;
589
+            	$cc = Predict::c1ss;
590
+            	$zn = Predict::zns;
591
+            	$ze = Predict::zes;
592
+            	$zmo = $sat->dps->zmos;
593
+            	$xnoi = 1.0 / $sat->dps->xnq;
594
+
595
+            	/* Loop breaks when Solar terms are done a second */
596
+            	/* time, after Lunar terms are initialized        */
597
+            	for(;;) {
598
+                	/* Solar terms done again after Lunar terms are done */
599
+                	$a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
600
+                	$a3 = -$zsing * $zcosh + $zcosg * $zcosi * $zsinh;
601
+                	$a7 = -$zcosg * $zsinh + $zsing * $zcosi * $zcosh;
602
+                	$a8 = $zsing * $zsini;
603
+                	$a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
604
+                	$a10 = $zcosg * $zsini;
605
+                	$a2 = $sat->deep_arg->cosio * $a7 + $sat->deep_arg->sinio * $a8;
606
+                	$a4 = $sat->deep_arg->cosio * $a9 + $sat->deep_arg->sinio * $a10;
607
+                	$a5 = -$sat->deep_arg->sinio * $a7 + $sat->deep_arg->cosio * $a8;
608
+                	$a6 = -$sat->deep_arg->sinio * $a9 + $sat->deep_arg->cosio * $a10;
609
+                	$x1 = $a1 * $sat->deep_arg->cosg + $a2 * $sat->deep_arg->sing;
610
+                	$x2 = $a3 * $sat->deep_arg->cosg + $a4 * $sat->deep_arg->sing;
611
+                	$x3 = -$a1 * $sat->deep_arg->sing + $a2 * $sat->deep_arg->cosg;
612
+                	$x4 = -$a3 * $sat->deep_arg->sing + $a4 * $sat->deep_arg->cosg;
613
+                	$x5 = $a5 * $sat->deep_arg->sing;
614
+                	$x6 = $a6 * $sat->deep_arg->sing;
615
+                	$x7 = $a5 * $sat->deep_arg->cosg;
616
+                	$x8 = $a6 * $sat->deep_arg->cosg;
617
+                	$z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
618
+                	$z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
619
+                	$z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
620
+                	$z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $sat->deep_arg->eosq;
621
+                	$z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $sat->deep_arg->eosq;
622
+                	$z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $sat->deep_arg->eosq;
623
+                	$z11 = -6 * $a1 * $a5 + $sat->deep_arg->eosq * (-24 * $x1 * $x7 - 6 * $x3 * $x5);
624
+                	$z12 = -6 * ($a1 * $a6 + $a3 * $a5) + $sat->deep_arg->eosq *
625
+                    	(-24 * ($x2 * $x7 + $x1 * $x8) - 6 * ($x3 * $x6 + $x4 * $x5));
626
+                	$z13 = -6 * $a3 * $a6 + $sat->deep_arg->eosq * (-24 * $x2 * $x8 - 6 * $x4 * $x6);
627
+                	$z21 = 6 * $a2 * $a5 + $sat->deep_arg->eosq * (24 * $x1 * $x5 - 6 * $x3 * $x7);
628
+                	$z22 = 6 * ($a4 * $a5 + $a2 * $a6) + $sat->deep_arg->eosq *
629
+                    	(24 * ($x2 * $x5 + $x1 * $x6) - 6 * ($x4 * $x7 + $x3 * $x8));
630
+                	$z23 = 6 * $a4 * $a6 + $sat->deep_arg->eosq * (24 * $x2 * $x6 - 6 * $x4 * $x8);
631
+                	$z1 = $z1 + $z1 + $sat->deep_arg->betao2 * $z31;
632
+                	$z2 = $z2 + $z2 + $sat->deep_arg->betao2 * $z32;
633
+                	$z3 = $z3 + $z3 + $sat->deep_arg->betao2 * $z33;
634
+                	$s3 = $cc * $xnoi;
635
+                	$s2 = -0.5 * $s3 / $sat->deep_arg->betao;
636
+                	$s4 = $s3 * $sat->deep_arg->betao;
637
+                	$s1 = -15 * $eq * $s4;
638
+                	$s5 = $x1 * $x3 + $x2 * $x4;
639
+                	$s6 = $x2 * $x3 + $x1 * $x4;
640
+                	$s7 = $x2 * $x4 - $x1 * $x3;
641
+                	$se = $s1 * $zn * $s5;
642
+                	$si = $s2 * $zn * ($z11 + $z13);
643
+                	$sl = -$zn * $s3 * ($z1 + $z3 - 14 - 6 * $sat->deep_arg->eosq);
644
+                	$sgh = $s4 * $zn * ($z31 + $z33 - 6);
645
+                	$sh = -$zn * $s2 * ($z21 + $z23);
646
+                	if ($sat->dps->xqncl < 5.2359877E-2) {
647
+                    	$sh = 0;
648
+                	}
649
+                	$sat->dps->ee2 = 2 * $s1 * $s6;
650
+                	$sat->dps->e3 = 2 * $s1 * $s7;
651
+                	$sat->dps->xi2 = 2 * $s2 * $z12;
652
+                	$sat->dps->xi3 = 2 * $s2 * ($z13 - $z11);
653
+                	$sat->dps->xl2 = -2 * $s3 * $z2;
654
+                	$sat->dps->xl3 = -2 * $s3 * ($z3 - $z1);
655
+                	$sat->dps->xl4 = -2 * $s3 * (-21 - 9 * $sat->deep_arg->eosq) * $ze;
656
+                	$sat->dps->xgh2 = 2 * $s4 * $z32;
657
+                	$sat->dps->xgh3 = 2 * $s4 * ($z33 - $z31);
658
+                	$sat->dps->xgh4 = -18 * $s4 * $ze;
659
+                	$sat->dps->xh2 = -2 * $s2 * $z22;
660
+                	$sat->dps->xh3 = -2 * $s2 * ($z23 - $z21);
661
+
662
+                	if ($sat->flags & self::LUNAR_TERMS_DONE_FLAG) {
663
+                    	break;
664
+                	}
665
+
666
+                	/* Do lunar terms */
667
+                	$sat->dps->sse = $se;
668
+                	$sat->dps->ssi = $si;
669
+                	$sat->dps->ssl = $sl;
670
+                	$sat->dps->ssh = $sh / $sat->deep_arg->sinio;
671
+                	$sat->dps->ssg = $sgh - $sat->deep_arg->cosio * $sat->dps->ssh;
672
+                	$sat->dps->se2 = $sat->dps->ee2;
673
+                	$sat->dps->si2 = $sat->dps->xi2;
674
+                	$sat->dps->sl2 = $sat->dps->xl2;
675
+                	$sat->dps->sgh2 = $sat->dps->xgh2;
676
+                	$sat->dps->sh2 = $sat->dps->xh2;
677
+                	$sat->dps->se3 = $sat->dps->e3;
678
+                	$sat->dps->si3 = $sat->dps->xi3;
679
+                	$sat->dps->sl3 = $sat->dps->xl3;
680
+                	$sat->dps->sgh3 = $sat->dps->xgh3;
681
+                	$sat->dps->sh3 = $sat->dps->xh3;
682
+                	$sat->dps->sl4 = $sat->dps->xl4;
683
+                	$sat->dps->sgh4 = $sat->dps->xgh4;
684
+                	$zcosg = $sat->dps->zcosgl;
685
+                	$zsing = $sat->dps->zsingl;
686
+                	$zcosi = $sat->dps->zcosil;
687
+                	$zsini = $sat->dps->zsinil;
688
+                	$zcosh = $sat->dps->zcoshl * $cosq + $sat->dps->zsinhl * $sinq;
689
+                	$zsinh = $sinq * $sat->dps->zcoshl - $cosq * $sat->dps->zsinhl;
690
+                	$zn = Predict::znl;
691
+                	$cc = Predict::c1l;
692
+                	$ze = Predict::zel;
693
+                	$zmo = $sat->dps->zmol;
694
+                	$sat->flags |= self::LUNAR_TERMS_DONE_FLAG;
695
+            	} /* End of for(;;) */
696
+
697
+            	$sat->dps->sse = $sat->dps->sse + $se;
698
+            	$sat->dps->ssi = $sat->dps->ssi + $si;
699
+            	$sat->dps->ssl = $sat->dps->ssl + $sl;
700
+            	$sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio / $sat->deep_arg->sinio * $sh;
701
+            	$sat->dps->ssh = $sat->dps->ssh + $sh / $sat->deep_arg->sinio;
702
+
703
+            	/* Geopotential resonance initialization for 12 hour orbits */
704
+            	$sat->flags &= ~self::RESONANCE_FLAG;
705
+            	$sat->flags &= ~self::SYNCHRONOUS_FLAG;
706
+
707
+            	if (!(($sat->dps->xnq < 0.0052359877) && ($sat->dps->xnq > 0.0034906585))) {
708
+                	if( ($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924) ) {
709
+                    	return;
710
+                	}
711
+                	if ($eq < 0.5) {
712
+                    	return;
713
+                	}
714
+                	$sat->flags |= self::RESONANCE_FLAG;
715
+                	$eoc = $eq * $sat->deep_arg->eosq;
716
+                	$g201 = -0.306 - ($eq - 0.64) * 0.440;
717
+                	if ($eq <= 0.65) {
718
+                    	$g211 = 3.616 - 13.247 * $eq + 16.290 * $sat->deep_arg->eosq;
719
+                    	$g310 = -19.302 + 117.390 * $eq - 228.419 *
720
+                        	$sat->deep_arg->eosq + 156.591 * $eoc;
721
+                    	$g322 = -18.9068 + 109.7927 * $eq - 214.6334 *
722
+                        	$sat->deep_arg->eosq + 146.5816 * $eoc;
723
+                    	$g410 = -41.122 + 242.694 * $eq - 471.094 *
724
+                        	$sat->deep_arg->eosq + 313.953 * $eoc;
725
+                    	$g422 = -146.407 + 841.880 * $eq - 1629.014 *
726
+                        	$sat->deep_arg->eosq + 1083.435 * $eoc;
727
+                    	$g520 = -532.114 + 3017.977 * $eq - 5740 *
728
+                        	$sat->deep_arg->eosq + 3708.276 * $eoc;
729
+                	} else {
730
+                    	$g211 = -72.099 + 331.819 * $eq - 508.738 *
731
+                        	$sat->deep_arg->eosq + 266.724 * $eoc;
732
+                    	$g310 = -346.844 + 1582.851 * $eq - 2415.925 *
733
+                        	$sat->deep_arg->eosq + 1246.113 * $eoc;
734
+                    	$g322 = -342.585 + 1554.908 * $eq - 2366.899 *
735
+                        	$sat->deep_arg->eosq + 1215.972 * $eoc;
736
+                    	$g410 = -1052.797 + 4758.686 * $eq - 7193.992 *
737
+                        	$sat->deep_arg->eosq + 3651.957 * $eoc;
738
+                    	$g422 = -3581.69 + 16178.11 * $eq - 24462.77 *
739
+                        	$sat->deep_arg->eosq+ 12422.52 * $eoc;
740
+                    	if ($eq <= 0.715) {
741
+                        	$g520 = 1464.74 - 4664.75 * $eq + 3763.64 * $sat->deep_arg->eosq;
742
+                    	} else {
743
+                        	$g520 = -5149.66 + 29936.92 * $eq - 54087.36 *
744
+                            	$sat->deep_arg->eosq + 31324.56 * $eoc;
745
+                    	}
746
+                	} /* End if (eq <= 0.65) */
747
+
748
+                	if ($eq < 0.7) {
749
+                    	$g533 = -919.2277 + 4988.61 * $eq - 9064.77 *
750
+                        	$sat->deep_arg->eosq + 5542.21 * $eoc;
751
+                    	$g521 = -822.71072 + 4568.6173 * $eq - 8491.4146 *
752
+                        	$sat->deep_arg->eosq + 5337.524 * $eoc;
753
+                    	$g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754
+                        	$sat->deep_arg->eosq + 5341.4 * $eoc;
755
+                	}
756
+                	else {
757
+                    	$g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758
+                        	$sat->deep_arg->eosq + 109377.94 * $eoc;
759
+                    	$g521 = -51752.104 + 218913.95 * $eq - 309468.16*
760
+                        	$sat->deep_arg->eosq + 146349.42 * $eoc;
761
+                    	$g532 = -40023.88 + 170470.89 * $eq - 242699.48*
762
+                        	$sat->deep_arg->eosq + 115605.82 * $eoc;
763
+                	} /* End if (eq <= 0.7) */
764
+
765
+                	$sini2 = $sat->deep_arg->sinio * $sat->deep_arg->sinio;
766
+                	$f220 = 0.75 * (1 + 2 * $sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
+                	$f221 = 1.5 * $sini2;
768
+                	$f321 = 1.875 * $sat->deep_arg->sinio * (1 - 2 *
769
+                                  	$sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
770
+                	$f322 = -1.875 * $sat->deep_arg->sinio * (1 + 2*
771
+                                   	$sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
772
+                	$f441 = 35 * $sini2 * $f220;
773
+                	$f442 = 39.3750 * $sini2 * $sini2;
774
+                	$f522 = 9.84375 * $sat->deep_arg->sinio * ($sini2 * (1 - 2 * $sat->deep_arg->cosio - 5 *
775
+                                       	$sat->deep_arg->theta2) + 0.33333333 * (-2 + 4 * $sat->deep_arg->cosio +
776
+                                                     	6 * $sat->deep_arg->theta2));
777
+                	$f523 = $sat->deep_arg->sinio * (4.92187512 * $sini2 * (-2 - 4 *
778
+                                      	$sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2) + 6.56250012
779
+                            	* (1 + 2 * $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2));
780
+                	$f542 = 29.53125 * $sat->deep_arg->sinio * (2 - 8 *
781
+                                 	$sat->deep_arg->cosio + $sat->deep_arg->theta2 *
782
+                                 	(-12 + 8 * $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2));
783
+                	$f543 = 29.53125 * $sat->deep_arg->sinio * (-2 - 8 * $sat->deep_arg->cosio +
784
+                                 	$sat->deep_arg->theta2 * (12 + 8 * $sat->deep_arg->cosio - 10 *
785
+                                           	$sat->deep_arg->theta2));
786
+                	$xno2 = $sat->dps->xnq * $sat->dps->xnq;
787
+                	$ainv2 = $aqnv * $aqnv;
788
+                	$temp1 = 3 * $xno2 * $ainv2;
789
+                	$temp = $temp1 * Predict::root22;
790
+                	$sat->dps->d2201 = $temp * $f220 * $g201;
791
+                	$sat->dps->d2211 = $temp * $f221 * $g211;
792
+                	$temp1 = $temp1 * $aqnv;
793
+                	$temp = $temp1 * Predict::root32;
794
+                	$sat->dps->d3210 = $temp * $f321 * $g310;
795
+                	$sat->dps->d3222 = $temp * $f322 * $g322;
796
+                	$temp1 = $temp1 * $aqnv;
797
+                	$temp = 2 * $temp1 * Predict::root44;
798
+                	$sat->dps->d4410 = $temp * $f441 * $g410;
799
+                	$sat->dps->d4422 = $temp * $f442 * $g422;
800
+                	$temp1 = $temp1 * $aqnv;
801
+                	$temp = $temp1 * Predict::root52;
802
+                	$sat->dps->d5220 = $temp * $f522 * $g520;
803
+                	$sat->dps->d5232 = $temp * $f523 * $g532;
804
+                	$temp = 2 * $temp1 * Predict::root54;
805
+                	$sat->dps->d5421 = $temp * $f542 * $g521;
806
+                	$sat->dps->d5433 = $temp * $f543 * $g533;
807
+                	$sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->xnodeo - $sat->dps->thgr - $sat->dps->thgr;
808
+                	$bfact = $sat->deep_arg->xmdot + $sat->deep_arg->xnodot +
809
+                    	$sat->deep_arg->xnodot - Predict::thdt - Predict::thdt;
810
+                	$bfact = $bfact + $sat->dps->ssl + $sat->dps->ssh + $sat->dps->ssh;
811
+            	} else {
812
+                	$sat->flags |= self::RESONANCE_FLAG;
813
+                	$sat->flags |= self::SYNCHRONOUS_FLAG;
814
+                	/* Synchronous resonance terms initialization */
815
+                	$g200 = 1 + $sat->deep_arg->eosq * (-2.5 + 0.8125 * $sat->deep_arg->eosq);
816
+                	$g310 = 1 + 2 * $sat->deep_arg->eosq;
817
+                	$g300 = 1 + $sat->deep_arg->eosq * (-6 + 6.60937 * $sat->deep_arg->eosq);
818
+                	$f220 = 0.75 * (1 + $sat->deep_arg->cosio) * (1 + $sat->deep_arg->cosio);
819
+                	$f311 = 0.9375 * $sat->deep_arg->sinio * $sat->deep_arg->sinio *
820
+                    	(1 + 3 * $sat->deep_arg->cosio) - 0.75 * (1 + $sat->deep_arg->cosio);
821
+                	$f330 = 1 + $sat->deep_arg->cosio;
822
+                	$f330 = 1.875 * $f330 * $f330 * $f330;
823
+                	$sat->dps->del1 = 3 * $sat->dps->xnq * $sat->dps->xnq * $aqnv * $aqnv;
824
+                	$sat->dps->del2 = 2 * $sat->dps->del1 * $f220 * $g200 * Predict::q22;
825
+                	$sat->dps->del3 = 3 * $sat->dps->del1 * $f330 * $g300 * Predict::q33 * $aqnv;
826
+                	$sat->dps->del1 = $sat->dps->del1 * $f311 * $g310 * Predict::q31 * $aqnv;
827
+                	$sat->dps->fasx2 = 0.13130908;
828
+                	$sat->dps->fasx4 = 2.8843198;
829
+                	$sat->dps->fasx6 = 0.37448087;
830
+                	$sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->omegao - $sat->dps->thgr;
831
+                	$bfact = $sat->deep_arg->xmdot + $xpidot - Predict::thdt;
832
+                	$bfact = $bfact + $sat->dps->ssl + $sat->dps->ssg + $sat->dps->ssh;
833
+            	} /* End if( !(xnq < 0.0052359877) && (xnq > 0.0034906585) ) */
834
+
835
+            	$sat->dps->xfact = $bfact - $sat->dps->xnq;
836
+
837
+            	/* Initialize integrator */
838
+            	$sat->dps->xli = $sat->dps->xlamo;
839
+            	$sat->dps->xni = $sat->dps->xnq;
840
+            	$sat->dps->atime = 0;
841
+            	$sat->dps->stepp = 720;
842
+            	$sat->dps->stepn = -720;
843
+            	$sat->dps->step2 = 259200;
844
+            	/* End case self::dpinit: */
845
+            	return;
846
+
847
+        	case self::dpsec: /* Entrance for deep space secular effects */
848
+            	$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl * $sat->deep_arg->t;
849
+            	$sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg * $sat->deep_arg->t;
850
+            	$sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh * $sat->deep_arg->t;
851
+            	$sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse * $sat->deep_arg->t;
852
+            	$sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi * $sat->deep_arg->t;
853
+            	if ($sat->deep_arg->xinc < 0) {
854
+                	$sat->deep_arg->xinc = -$sat->deep_arg->xinc;
855
+                	$sat->deep_arg->xnode = $sat->deep_arg->xnode + Predict::pi;
856
+                	$sat->deep_arg->omgadf = $sat->deep_arg->omgadf - Predict::pi;
857
+            	}
858
+            	if(~$sat->flags & self::RESONANCE_FLAG ) {
859
+                	return;
860
+            	}
861
+
862
+            	do {
863
+                	if ( ($sat->dps->atime == 0) ||
864
+                    	(($sat->deep_arg->t >= 0) && ($sat->dps->atime < 0)) ||
865
+                    	(($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0)) ) {
866
+                    	/* Epoch restart */
867
+                    	if ($sat->deep_arg->t >= 0) {
868
+                        	$delt = $sat->dps->stepp;
869
+                    	} else {
870
+                        	$delt = $sat->dps->stepn;
871
+                    	}
872
+
873
+                    	$sat->dps->atime = 0;
874
+                    	$sat->dps->xni = $sat->dps->xnq;
875
+                    	$sat->dps->xli = $sat->dps->xlamo;
876
+                	} else {
877
+                    	if (abs($sat->deep_arg->t) >= abs($sat->dps->atime)) {
878
+                        	if ($sat->deep_arg->t > 0) {
879
+                            	$delt = $sat->dps->stepp;
880
+                        	} else {
881
+                            	$delt = $sat->dps->stepn;
882
+                        	}
883
+                    	}
884
+                	}
885
+
886
+                	do {
887
+                    	if (abs($sat->deep_arg->t - $sat->dps->atime) >= $sat->dps->stepp) {
888
+                        	$sat->flags |= self::DO_LOOP_FLAG;
889
+                        	$sat->flags &= ~self::EPOCH_RESTART_FLAG;
890
+                    	}
891
+                    	else {
892
+                        	$ft = $sat->deep_arg->t - $sat->dps->atime;
893
+                        	$sat->flags &= ~self::DO_LOOP_FLAG;
894
+                    	}
895
+
896
+                    	if (abs($sat->deep_arg->t) < abs($sat->dps->atime)) {
897
+                        	if ($sat->deep_arg->t >= 0) {
898
+                            	$delt = $sat->dps->stepn;
899
+                        	} else {
900
+                            	$delt = $sat->dps->stepp;
901
+                        	}
902
+                        	$sat->flags |= (self::DO_LOOP_FLAG | self::EPOCH_RESTART_FLAG);
903
+                    	}
904
+
905
+                    	/* Dot terms calculated */
906
+                    	if ($sat->flags & self::SYNCHRONOUS_FLAG) {
907
+                        	$xndot = $sat->dps->del1 * sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2 * sin(2 * ($sat->dps->xli - $sat->dps->fasx4))
908
+                            	+ $sat->dps->del3 * sin(3 * ($sat->dps->xli - $sat->dps->fasx6));
909
+                        	$xnddt = $sat->dps->del1 * cos($sat->dps->xli - $sat->dps->fasx2) + 2 * $sat->dps->del2 * cos(2 * ($sat->dps->xli - $sat->dps->fasx4))
910
+                            	+ 3 * $sat->dps->del3 * cos(3 * ($sat->dps->xli - $sat->dps->fasx6));
911
+                    	} else {
912
+                        	$xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot * $sat->dps->atime;
913
+                        	$x2omi = $xomi + $xomi;
914
+                        	$x2li = $sat->dps->xli + $sat->dps->xli;
915
+                        	$xndot = $sat->dps->d2201 * sin($x2omi + $sat->dps->xli - Predict::g22)
916
+                            	+ $sat->dps->d2211 * sin($sat->dps->xli - Predict::g22)
917
+                            	+ $sat->dps->d3210 * sin($xomi + $sat->dps->xli - Predict::g32)
918
+                            	+ $sat->dps->d3222 * sin(-$xomi + $sat->dps->xli - Predict::g32)
919
+                            	+ $sat->dps->d4410 * sin($x2omi + $x2li- Predict::g44)
920
+                            	+ $sat->dps->d4422 * sin($x2li- Predict::g44)
921
+                            	+ $sat->dps->d5220 * sin($xomi + $sat->dps->xli- Predict::g52)
922
+                            	+ $sat->dps->d5232 * sin(-$xomi + $sat->dps->xli- Predict::g52)
923
+                            	+ $sat->dps->d5421 * sin($xomi + $x2li - Predict::g54)
924
+                            	+ $sat->dps->d5433 * sin(-$xomi + $x2li - Predict::g54);
925
+                        	$xnddt = $sat->dps->d2201 * cos($x2omi + $sat->dps->xli- Predict::g22)
926
+                            	+ $sat->dps->d2211 * cos($sat->dps->xli - Predict::g22)
927
+                            	+ $sat->dps->d3210 * cos($xomi + $sat->dps->xli - Predict::g32)
928
+                            	+ $sat->dps->d3222 * cos(-$xomi + $sat->dps->xli - Predict::g32)
929
+                            	+ $sat->dps->d5220 * cos($xomi + $sat->dps->xli - Predict::g52)
930
+                            	+ $sat->dps->d5232 * cos(-$xomi + $sat->dps->xli - Predict::g52)
931
+                            	+ 2 * ($sat->dps->d4410 * cos($x2omi + $x2li - Predict::g44)
932
+                                	+ $sat->dps->d4422 * cos($x2li - Predict::g44)
933
+                                	+ $sat->dps->d5421 * cos($xomi + $x2li - Predict::g54)
934
+                                	+ $sat->dps->d5433 * cos(-$xomi + $x2li - Predict::g54));
935
+                    	} /* End of if (isFlagSet(SYNCHRONOUS_FLAG)) */
936
+
937
+                    	$xldot = $sat->dps->xni + $sat->dps->xfact;
938
+                    	$xnddt = $xnddt * $xldot;
939
+
940
+                    	if ($sat->flags & self::DO_LOOP_FLAG) {
941
+                        	$sat->dps->xli = $sat->dps->xli + $xldot * $delt + $xndot * $sat->dps->step2;
942
+                        	$sat->dps->xni = $sat->dps->xni + $xndot * $delt + $xnddt * $sat->dps->step2;
943
+                        	$sat->dps->atime = $sat->dps->atime + $delt;
944
+                    	}
945
+                	} while (($sat->flags & self::DO_LOOP_FLAG) &&
946
+                        	(~$sat->flags & self::EPOCH_RESTART_FLAG));
947
+            	}
948
+            	while (($sat->flags & self::DO_LOOP_FLAG) && ($sat->flags & self::EPOCH_RESTART_FLAG));
949
+
950
+            	$sat->deep_arg->xn = $sat->dps->xni + $xndot * $ft + $xnddt * $ft * $ft * 0.5;
951
+            	$xl = $sat->dps->xli + $xldot * $ft + $xndot * $ft * $ft * 0.5;
952
+            	$temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t * Predict::thdt;
953
+
954
+            	if (~$sat->flags & self::SYNCHRONOUS_FLAG) {
955
+                	$sat->deep_arg->xll = $xl + $temp + $temp;
956
+            	} else {
957
+                	$sat->deep_arg->xll = $xl - $sat->deep_arg->omgadf + $temp;
958
+            	}
959
+
960
+            	return;
961
+            	/* End case dpsec: */
962
+
963
+        	case self::dpper: /* Entrance for lunar-solar periodics */
964
+            	$sinis = sin($sat->deep_arg->xinc);
965
+            	$cosis = cos($sat->deep_arg->xinc);
966
+            	if (abs($sat->dps->savtsn - $sat->deep_arg->t) >= 30) {
967
+                	$sat->dps->savtsn = $sat->deep_arg->t;
968
+                	$zm = $sat->dps->zmos + Predict::zns * $sat->deep_arg->t;
969
+                	$zf = $zm + 2 * Predict::zes * sin($zm);
970
+                	$sinzf = sin($zf);
971
+                	$f2 = 0.5 * $sinzf * $sinzf - 0.25;
972
+                	$f3 = -0.5 * $sinzf * cos($zf);
973
+                	$ses = $sat->dps->se2 * $f2 + $sat->dps->se3 * $f3;
974
+                	$sis = $sat->dps->si2 * $f2 + $sat->dps->si3 * $f3;
975
+                	$sls = $sat->dps->sl2 * $f2 + $sat->dps->sl3 * $f3 + $sat->dps->sl4 * $sinzf;
976
+                	$sat->dps->sghs = $sat->dps->sgh2 * $f2 + $sat->dps->sgh3 * $f3 + $sat->dps->sgh4 * $sinzf;
977
+                	$sat->dps->shs = $sat->dps->sh2 * $f2 + $sat->dps->sh3 * $f3;
978
+                	$zm = $sat->dps->zmol + Predict::znl * $sat->deep_arg->t;
979
+                	$zf = $zm + 2 * Predict::zel * sin($zm);
980
+                	$sinzf = sin($zf);
981
+                	$f2 = 0.5 * $sinzf * $sinzf - 0.25;
982
+                	$f3 = -0.5 * $sinzf * cos($zf);
983
+                	$sel = $sat->dps->ee2 * $f2 + $sat->dps->e3 * $f3;
984
+                	$sil = $sat->dps->xi2 * $f2 + $sat->dps->xi3 * $f3;
985
+                	$sll = $sat->dps->xl2 * $f2 + $sat->dps->xl3 * $f3 + $sat->dps->xl4 * $sinzf;
986
+                	$sat->dps->sghl = $sat->dps->xgh2 * $f2 + $sat->dps->xgh3 * $f3 + $sat->dps->xgh4 * $sinzf;
987
+                	$sat->dps->sh1 = $sat->dps->xh2 * $f2 + $sat->dps->xh3 * $f3;
988
+                	$sat->dps->pe = $ses + $sel;
989
+                	$sat->dps->pinc = $sis + $sil;
990
+                	$sat->dps->pl = $sls + $sll;
991
+            	}
992
+
993
+            	$pgh = $sat->dps->sghs + $sat->dps->sghl;
994
+            	$ph = $sat->dps->shs + $sat->dps->sh1;
995
+            	$sat->deep_arg->xinc = $sat->deep_arg->xinc + $sat->dps->pinc;
996
+            	$sat->deep_arg->em = $sat->deep_arg->em + $sat->dps->pe;
997
+
998
+            	if ($sat->dps->xqncl >= 0.2) {
999
+                	/* Apply periodics directly */
1000
+                	$ph = $ph / $sat->deep_arg->sinio;
1001
+                	$pgh = $pgh - $sat->deep_arg->cosio * $ph;
1002
+                	$sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $pgh;
1003
+                	$sat->deep_arg->xnode = $sat->deep_arg->xnode + $ph;
1004
+                	$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1005
+            	} else {
1006
+                	/* Apply periodics with Lyddane modification */
1007
+                	$sinok = sin($sat->deep_arg->xnode);
1008
+                	$cosok = cos($sat->deep_arg->xnode);
1009
+                	$alfdp = $sinis * $sinok;
1010
+                	$betdp = $sinis * $cosok;
1011
+                	$dalf = $ph * $cosok + $sat->dps->pinc * $cosis * $sinok;
1012
+                	$dbet = -$ph * $sinok + $sat->dps->pinc * $cosis * $cosok;
1013
+                	$alfdp = $alfdp + $dalf;
1014
+                	$betdp = $betdp + $dbet;
1015
+                	$sat->deep_arg->xnode = Predict_Math::FMod2p($sat->deep_arg->xnode);
1016
+                	$xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis * $sat->deep_arg->xnode;
1017
+                	$dls = $sat->dps->pl + $pgh - $sat->dps->pinc * $sat->deep_arg->xnode * $sinis;
1018
+                	$xls = $xls + $dls;
1019
+                	$xnoh = $sat->deep_arg->xnode;
1020
+                	$sat->deep_arg->xnode = Predict_Math::AcTan($alfdp, $betdp);
1021
+
1022
+                	/* This is a patch to Lyddane modification */
1023
+                	/* suggested by Rob Matson. */
1024
+                	if(abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1025
+                    	if ($sat->deep_arg->xnode < $xnoh) {
1026
+                        	$sat->deep_arg->xnode += Predict::twopi;
1027
+                    	} else {
1028
+                        	$sat->deep_arg->xnode -= Predict::twopi;
1029
+                    	}
1030
+                	}
1031
+
1032
+                	$sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1033
+                	$sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc) *
1034
+                    	$sat->deep_arg->xnode;
1035
+            	} /* End case dpper: */
1036
+            	return;
1037 1037
 
1038 1038
         } /* End switch(ientry) */
1039 1039
 
Please login to merge, or discard this patch.
Spacing   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 
43 43
     /* orbit_type_t struct */
44 44
     const ORBIT_TYPE_UNKNOWN = 0;
45
-    const ORBIT_TYPE_LEO     = 1;            /*!< Low Earth orbit, up to 1200 km. */
46
-    const ORBIT_TYPE_ICO     = 2;            /*!< Intermediate Circular Orbit, up to 1400 km. */
47
-    const ORBIT_TYPE_GEO     = 3;            /*!< Geostationary. */
48
-    const ORBIT_TYPE_GSO     = 4;            /*!< Geosynchronuous. */
45
+    const ORBIT_TYPE_LEO     = 1; /*!< Low Earth orbit, up to 1200 km. */
46
+    const ORBIT_TYPE_ICO     = 2; /*!< Intermediate Circular Orbit, up to 1400 km. */
47
+    const ORBIT_TYPE_GEO     = 3; /*!< Geostationary. */
48
+    const ORBIT_TYPE_GSO     = 4; /*!< Geosynchronuous. */
49 49
     const ORBIT_TYPE_MOLNIYA = 5;
50 50
     const ORBIT_TYPE_TUNDRA  = 6;
51 51
     const ORBIT_TYPE_POLAR   = 7;
@@ -70,29 +70,29 @@  discard block
 block discarded – undo
70 70
     public function SGP4(Predict_Sat $sat, $tsince)
71 71
     {
72 72
         /* Initialization */
73
-        if (~$sat->flags & self::SGP4_INITIALIZED_FLAG) {
73
+        if (~$sat->flags&self::SGP4_INITIALIZED_FLAG) {
74 74
             $sat->flags |= self::SGP4_INITIALIZED_FLAG;
75 75
 
76 76
             /* Recover original mean motion (xnodp) and   */
77 77
             /* semimajor axis (aodp) from input elements. */
78
-            $a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
78
+            $a1 = pow(Predict::xke/$sat->tle->xno, Predict::tothrd);
79 79
             $sat->sgps->cosio = cos($sat->tle->xincl);
80
-            $theta2 = $sat->sgps->cosio * $sat->sgps->cosio;
81
-            $sat->sgps->x3thm1 = 3 * $theta2 - 1.0;
82
-            $eosq = $sat->tle->eo * $sat->tle->eo;
80
+            $theta2 = $sat->sgps->cosio*$sat->sgps->cosio;
81
+            $sat->sgps->x3thm1 = 3*$theta2 - 1.0;
82
+            $eosq = $sat->tle->eo*$sat->tle->eo;
83 83
             $betao2 = 1 - $eosq;
84 84
             $betao = sqrt($betao2);
85
-            $del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($a1 * $a1 * $betao * $betao2);
86
-            $ao = $a1 * (1 - $del1 * (0.5 * Predict::tothrd + $del1 * (1 + 134.0 / 81.0 * $del1)));
87
-            $delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 / ($ao * $ao * $betao * $betao2);
88
-            $sat->sgps->xnodp = $sat->tle->xno / (1.0 + $delo);
89
-            $sat->sgps->aodp = $ao / (1.0 - $delo);
85
+            $del1 = 1.5*Predict::ck2*$sat->sgps->x3thm1/($a1*$a1*$betao*$betao2);
86
+            $ao = $a1*(1 - $del1*(0.5*Predict::tothrd + $del1*(1 + 134.0/81.0*$del1)));
87
+            $delo = 1.5*Predict::ck2*$sat->sgps->x3thm1/($ao*$ao*$betao*$betao2);
88
+            $sat->sgps->xnodp = $sat->tle->xno/(1.0 + $delo);
89
+            $sat->sgps->aodp = $ao/(1.0 - $delo);
90 90
 
91 91
             /* For perigee less than 220 kilometers, the "simple" flag is set */
92 92
             /* and the equations are truncated to linear variation in sqrt a  */
93 93
             /* and quadratic variation in mean anomaly.  Also, the c3 term,   */
94 94
             /* the delta omega term, and the delta m term are dropped.        */
95
-            if (($sat->sgps->aodp * (1.0 - $sat->tle->eo) / Predict::ae) < (220.0 / Predict::xkmper + Predict::ae)) {
95
+            if (($sat->sgps->aodp*(1.0 - $sat->tle->eo)/Predict::ae) < (220.0/Predict::xkmper + Predict::ae)) {
96 96
                 $sat->flags |= self::SIMPLE_FLAG;
97 97
             } else {
98 98
                 $sat->flags &= ~self::SIMPLE_FLAG;
@@ -102,121 +102,121 @@  discard block
 block discarded – undo
102 102
             /* values of s and qoms2t are altered. */
103 103
             $s4 = Predict::__s__;
104 104
             $qoms24 = Predict::qoms2t;
105
-            $perige = ($sat->sgps->aodp * (1 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
105
+            $perige = ($sat->sgps->aodp*(1 - $sat->tle->eo) - Predict::ae)*Predict::xkmper;
106 106
             if ($perige < 156.0) {
107 107
                 if ($perige <= 98.0) {
108 108
                     $s4 = 20.0;
109 109
                 } else {
110 110
                     $s4 = $perige - 78.0;
111 111
                 }
112
-                $qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
113
-                $s4 = $s4 / Predict::xkmper + Predict::ae;
112
+                $qoms24 = pow((120.0 - $s4)*Predict::ae/Predict::xkmper, 4);
113
+                $s4 = $s4/Predict::xkmper + Predict::ae;
114 114
             }; /* FIXME FIXME: End of if(perige <= 98) NO WAY!!!! */
115 115
 
116
-            $pinvsq = 1.0 / ($sat->sgps->aodp * $sat->sgps->aodp * $betao2 * $betao2);
117
-            $tsi = 1.0 / ($sat->sgps->aodp - $s4);
118
-            $sat->sgps->eta = $sat->sgps->aodp * $sat->tle->eo * $tsi;
119
-            $etasq = $sat->sgps->eta * $sat->sgps->eta;
120
-            $eeta = $sat->tle->eo * $sat->sgps->eta;
116
+            $pinvsq = 1.0/($sat->sgps->aodp*$sat->sgps->aodp*$betao2*$betao2);
117
+            $tsi = 1.0/($sat->sgps->aodp - $s4);
118
+            $sat->sgps->eta = $sat->sgps->aodp*$sat->tle->eo*$tsi;
119
+            $etasq = $sat->sgps->eta*$sat->sgps->eta;
120
+            $eeta = $sat->tle->eo*$sat->sgps->eta;
121 121
             $psisq = abs(1.0 - $etasq);
122
-            $coef = $qoms24 * pow($tsi, 4);
123
-            $coef1 = $coef / pow($psisq, 3.5);
124
-            $c2 = $coef1 * $sat->sgps->xnodp * ($sat->sgps->aodp *
125
-                            (1.0 + 1.5 * $etasq + $eeta * (4.0 + $etasq)) +
126
-                            0.75 * Predict::ck2 * $tsi / $psisq * $sat->sgps->x3thm1 *
127
-                            (8.0 + 3.0 * $etasq * (8 + $etasq)));
128
-            $sat->sgps->c1 = $c2 * $sat->tle->bstar;
122
+            $coef = $qoms24*pow($tsi, 4);
123
+            $coef1 = $coef/pow($psisq, 3.5);
124
+            $c2 = $coef1*$sat->sgps->xnodp*($sat->sgps->aodp*
125
+                            (1.0 + 1.5*$etasq + $eeta*(4.0 + $etasq)) +
126
+                            0.75*Predict::ck2*$tsi/$psisq*$sat->sgps->x3thm1*
127
+                            (8.0 + 3.0*$etasq*(8 + $etasq)));
128
+            $sat->sgps->c1 = $c2*$sat->tle->bstar;
129 129
             $sat->sgps->sinio = sin($sat->tle->xincl);
130
-            $a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
131
-            $c3 = $coef * $tsi * $a3ovk2 * $sat->sgps->xnodp * Predict::ae * $sat->sgps->sinio / $sat->tle->eo;
130
+            $a3ovk2 = -Predict::xj3/Predict::ck2*pow(Predict::ae, 3);
131
+            $c3 = $coef*$tsi*$a3ovk2*$sat->sgps->xnodp*Predict::ae*$sat->sgps->sinio/$sat->tle->eo;
132 132
             $sat->sgps->x1mth2 = 1.0 - $theta2;
133
-            $sat->sgps->c4 = 2.0 * $sat->sgps->xnodp * $coef1 * $sat->sgps->aodp * $betao2 *
134
-                ($sat->sgps->eta * (2.0 + 0.5 * $etasq) +
135
-                 $sat->tle->eo * (0.5 + 2.0 * $etasq) -
136
-                 2.0 * Predict::ck2 * $tsi / ($sat->sgps->aodp * $psisq) *
137
-                 (-3.0 * $sat->sgps->x3thm1 * (1.0 - 2.0 * $eeta + $etasq * (1.5 - 0.5 * $eeta)) +
138
-                  0.75 * $sat->sgps->x1mth2 * (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
139
-                  cos(2.0 * $sat->tle->omegao)));
140
-            $sat->sgps->c5 = 2.0 * $coef1 * $sat->sgps->aodp * $betao2 *
141
-                (1.0 + 2.75 * ($etasq + $eeta) + $eeta * $etasq);
142
-            $theta4 = $theta2 * $theta2;
143
-            $temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->sgps->xnodp;
144
-            $temp2 = $temp1 * Predict::ck2 * $pinvsq;
145
-            $temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->sgps->xnodp;
146
-            $sat->sgps->xmdot = $sat->sgps->xnodp + 0.5 * $temp1 * $betao * $sat->sgps->x3thm1 +
147
-                0.0625 * $temp2 * $betao * (13.0 - 78.0 * $theta2 + 137.0 * $theta4);
148
-            $x1m5th = 1.0 - 5.0 * $theta2;
149
-            $sat->sgps->omgdot = -0.5 * $temp1 * $x1m5th +
150
-                0.0625 * $temp2 * (7.0 - 114.0 * $theta2 + 395.0 * $theta4) +
151
-                $temp3 * (3.0 - 36.0 * $theta2 + 49.0 * $theta4);
152
-            $xhdot1 = -$temp1 * $sat->sgps->cosio;
153
-            $sat->sgps->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $theta2) +
154
-                             2.0 * $temp3 * (3.0 - 7.0 * $theta2)) * $sat->sgps->cosio;
155
-            $sat->sgps->omgcof = $sat->tle->bstar * $c3 * cos($sat->tle->omegao);
156
-            $sat->sgps->xmcof = -Predict::tothrd * $coef * $sat->tle->bstar * Predict::ae / $eeta;
157
-            $sat->sgps->xnodcf = 3.5 * $betao2 * $xhdot1 * $sat->sgps->c1;
158
-            $sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
159
-            $sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->sgps->sinio *
160
-                (3.0 + 5.0 * $sat->sgps->cosio) / (1.0 + $sat->sgps->cosio);
161
-            $sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->sgps->sinio;
162
-            $sat->sgps->delmo = pow(1.0 + $sat->sgps->eta * cos($sat->tle->xmo), 3);
133
+            $sat->sgps->c4 = 2.0*$sat->sgps->xnodp*$coef1*$sat->sgps->aodp*$betao2*
134
+                ($sat->sgps->eta*(2.0 + 0.5*$etasq) +
135
+                 $sat->tle->eo*(0.5 + 2.0*$etasq) -
136
+                 2.0*Predict::ck2*$tsi/($sat->sgps->aodp*$psisq)*
137
+                 (-3.0*$sat->sgps->x3thm1*(1.0 - 2.0*$eeta + $etasq*(1.5 - 0.5*$eeta)) +
138
+                  0.75*$sat->sgps->x1mth2*(2.0*$etasq - $eeta*(1.0 + $etasq))*
139
+                  cos(2.0*$sat->tle->omegao)));
140
+            $sat->sgps->c5 = 2.0*$coef1*$sat->sgps->aodp*$betao2*
141
+                (1.0 + 2.75*($etasq + $eeta) + $eeta*$etasq);
142
+            $theta4 = $theta2*$theta2;
143
+            $temp1 = 3.0*Predict::ck2*$pinvsq*$sat->sgps->xnodp;
144
+            $temp2 = $temp1*Predict::ck2*$pinvsq;
145
+            $temp3 = 1.25*Predict::ck4*$pinvsq*$pinvsq*$sat->sgps->xnodp;
146
+            $sat->sgps->xmdot = $sat->sgps->xnodp + 0.5*$temp1*$betao*$sat->sgps->x3thm1 +
147
+                0.0625*$temp2*$betao*(13.0 - 78.0*$theta2 + 137.0*$theta4);
148
+            $x1m5th = 1.0 - 5.0*$theta2;
149
+            $sat->sgps->omgdot = -0.5*$temp1*$x1m5th +
150
+                0.0625*$temp2*(7.0 - 114.0*$theta2 + 395.0*$theta4) +
151
+                $temp3*(3.0 - 36.0*$theta2 + 49.0*$theta4);
152
+            $xhdot1 = -$temp1*$sat->sgps->cosio;
153
+            $sat->sgps->xnodot = $xhdot1 + (0.5*$temp2*(4.0 - 19.0*$theta2) +
154
+                             2.0*$temp3*(3.0 - 7.0*$theta2))*$sat->sgps->cosio;
155
+            $sat->sgps->omgcof = $sat->tle->bstar*$c3*cos($sat->tle->omegao);
156
+            $sat->sgps->xmcof = -Predict::tothrd*$coef*$sat->tle->bstar*Predict::ae/$eeta;
157
+            $sat->sgps->xnodcf = 3.5*$betao2*$xhdot1*$sat->sgps->c1;
158
+            $sat->sgps->t2cof = 1.5*$sat->sgps->c1;
159
+            $sat->sgps->xlcof = 0.125*$a3ovk2*$sat->sgps->sinio*
160
+                (3.0 + 5.0*$sat->sgps->cosio)/(1.0 + $sat->sgps->cosio);
161
+            $sat->sgps->aycof = 0.25*$a3ovk2*$sat->sgps->sinio;
162
+            $sat->sgps->delmo = pow(1.0 + $sat->sgps->eta*cos($sat->tle->xmo), 3);
163 163
             $sat->sgps->sinmo = sin($sat->tle->xmo);
164
-            $sat->sgps->x7thm1 = 7.0 * $theta2 - 1.0;
165
-            if (~$sat->flags & self::SIMPLE_FLAG) {
166
-                $c1sq = $sat->sgps->c1 * $sat->sgps->c1;
167
-                $sat->sgps->d2 = 4.0 * $sat->sgps->aodp * $tsi * $c1sq;
168
-                $temp = $sat->sgps->d2 * $tsi * $sat->sgps->c1 / 3.0;
169
-                $sat->sgps->d3 = (17.0 * $sat->sgps->aodp + $s4) * $temp;
170
-                $sat->sgps->d4 = 0.5 * $temp * $sat->sgps->aodp * $tsi *
171
-                    (221.0 * $sat->sgps->aodp + 31.0 * $s4) * $sat->sgps->c1;
172
-                $sat->sgps->t3cof = $sat->sgps->d2 + 2.0 * $c1sq;
173
-                $sat->sgps->t4cof = 0.25 * (3.0 * $sat->sgps->d3 + $sat->sgps->c1 *
174
-                              (12.0 * $sat->sgps->d2 + 10.0 * $c1sq));
175
-                $sat->sgps->t5cof = 0.2 * (3.0 * $sat->sgps->d4 +
176
-                             12.0 * $sat->sgps->c1 * $sat->sgps->d3 +
177
-                             6.0 * $sat->sgps->d2 * $sat->sgps->d2 +
178
-                             15.0 * $c1sq * (2.0 * $sat->sgps->d2 + $c1sq));
164
+            $sat->sgps->x7thm1 = 7.0*$theta2 - 1.0;
165
+            if (~$sat->flags&self::SIMPLE_FLAG) {
166
+                $c1sq = $sat->sgps->c1*$sat->sgps->c1;
167
+                $sat->sgps->d2 = 4.0*$sat->sgps->aodp*$tsi*$c1sq;
168
+                $temp = $sat->sgps->d2*$tsi*$sat->sgps->c1/3.0;
169
+                $sat->sgps->d3 = (17.0*$sat->sgps->aodp + $s4)*$temp;
170
+                $sat->sgps->d4 = 0.5*$temp*$sat->sgps->aodp*$tsi*
171
+                    (221.0*$sat->sgps->aodp + 31.0*$s4)*$sat->sgps->c1;
172
+                $sat->sgps->t3cof = $sat->sgps->d2 + 2.0*$c1sq;
173
+                $sat->sgps->t4cof = 0.25*(3.0*$sat->sgps->d3 + $sat->sgps->c1*
174
+                              (12.0*$sat->sgps->d2 + 10.0*$c1sq));
175
+                $sat->sgps->t5cof = 0.2*(3.0*$sat->sgps->d4 +
176
+                             12.0*$sat->sgps->c1*$sat->sgps->d3 +
177
+                             6.0*$sat->sgps->d2*$sat->sgps->d2 +
178
+                             15.0*$c1sq*(2.0*$sat->sgps->d2 + $c1sq));
179 179
             }; /* End of if (isFlagClear(SIMPLE_FLAG)) */
180 180
         }; /* End of SGP4() initialization */
181 181
 
182 182
         /* Update for secular gravity and atmospheric drag. */
183
-        $xmdf = $sat->tle->xmo + $sat->sgps->xmdot * $tsince;
184
-        $omgadf = $sat->tle->omegao + $sat->sgps->omgdot * $tsince;
185
-        $xnoddf = $sat->tle->xnodeo + $sat->sgps->xnodot * $tsince;
183
+        $xmdf = $sat->tle->xmo + $sat->sgps->xmdot*$tsince;
184
+        $omgadf = $sat->tle->omegao + $sat->sgps->omgdot*$tsince;
185
+        $xnoddf = $sat->tle->xnodeo + $sat->sgps->xnodot*$tsince;
186 186
         $omega = $omgadf;
187 187
         $xmp = $xmdf;
188
-        $tsq = $tsince * $tsince;
189
-        $xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
190
-        $tempa = 1.0 - $sat->sgps->c1 * $tsince;
191
-        $tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
192
-        $templ = $sat->sgps->t2cof * $tsq;
193
-        if (~$sat->flags & self::SIMPLE_FLAG) {
194
-            $delomg = $sat->sgps->omgcof * $tsince;
195
-            $delm = $sat->sgps->xmcof * (pow(1 + $sat->sgps->eta * cos($xmdf), 3) - $sat->sgps->delmo);
188
+        $tsq = $tsince*$tsince;
189
+        $xnode = $xnoddf + $sat->sgps->xnodcf*$tsq;
190
+        $tempa = 1.0 - $sat->sgps->c1*$tsince;
191
+        $tempe = $sat->tle->bstar*$sat->sgps->c4*$tsince;
192
+        $templ = $sat->sgps->t2cof*$tsq;
193
+        if (~$sat->flags&self::SIMPLE_FLAG) {
194
+            $delomg = $sat->sgps->omgcof*$tsince;
195
+            $delm = $sat->sgps->xmcof*(pow(1 + $sat->sgps->eta*cos($xmdf), 3) - $sat->sgps->delmo);
196 196
             $temp = $delomg + $delm;
197 197
             $xmp = $xmdf + $temp;
198 198
             $omega = $omgadf - $temp;
199
-            $tcube = $tsq * $tsince;
200
-            $tfour = $tsince * $tcube;
201
-            $tempa = $tempa - $sat->sgps->d2 * $tsq - $sat->sgps->d3 * $tcube - $sat->sgps->d4 * $tfour;
202
-            $tempe = $tempe + $sat->tle->bstar * $sat->sgps->c5 * (sin($xmp) - $sat->sgps->sinmo);
203
-            $templ = $templ + $sat->sgps->t3cof * $tcube + $tfour *
204
-                ($sat->sgps->t4cof + $tsince * $sat->sgps->t5cof);
199
+            $tcube = $tsq*$tsince;
200
+            $tfour = $tsince*$tcube;
201
+            $tempa = $tempa - $sat->sgps->d2*$tsq - $sat->sgps->d3*$tcube - $sat->sgps->d4*$tfour;
202
+            $tempe = $tempe + $sat->tle->bstar*$sat->sgps->c5*(sin($xmp) - $sat->sgps->sinmo);
203
+            $templ = $templ + $sat->sgps->t3cof*$tcube + $tfour*
204
+                ($sat->sgps->t4cof + $tsince*$sat->sgps->t5cof);
205 205
         }; /* End of if (isFlagClear(SIMPLE_FLAG)) */
206 206
 
207
-        $a = $sat->sgps->aodp * pow($tempa, 2);
207
+        $a = $sat->sgps->aodp*pow($tempa, 2);
208 208
         $e = $sat->tle->eo - $tempe;
209
-        $xl = $xmp + $omega + $xnode + $sat->sgps->xnodp * $templ;
210
-        $beta = sqrt(1.0 - ($e * $e));
211
-        $xn = Predict::xke / pow($a, 1.5);
209
+        $xl = $xmp + $omega + $xnode + $sat->sgps->xnodp*$templ;
210
+        $beta = sqrt(1.0 - ($e*$e));
211
+        $xn = Predict::xke/pow($a, 1.5);
212 212
 
213 213
         /* Long period periodics */
214
-        $axn = $e * cos($omega);
215
-        $temp = 1.0 / ($a * $beta * $beta);
216
-        $xll = $temp * $sat->sgps->xlcof * $axn;
217
-        $aynl = $temp * $sat->sgps->aycof;
214
+        $axn = $e*cos($omega);
215
+        $temp = 1.0/($a*$beta*$beta);
216
+        $xll = $temp*$sat->sgps->xlcof*$axn;
217
+        $aynl = $temp*$sat->sgps->aycof;
218 218
         $xlt = $xl + $xll;
219
-        $ayn = $e * sin($omega) + $aynl;
219
+        $ayn = $e*sin($omega) + $aynl;
220 220
 
221 221
         /* Solve Kepler's' Equation */
222 222
         $capu = Predict_Math::FMod2p($xlt - $xnode);
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
         do {
227 227
             $sinepw = sin($temp2);
228 228
             $cosepw = cos($temp2);
229
-            $temp3 = $axn * $sinepw;
230
-            $temp4 = $ayn * $cosepw;
231
-            $temp5 = $axn * $cosepw;
232
-            $temp6 = $ayn * $sinepw;
233
-            $epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
229
+            $temp3 = $axn*$sinepw;
230
+            $temp4 = $ayn*$cosepw;
231
+            $temp5 = $axn*$cosepw;
232
+            $temp6 = $ayn*$sinepw;
233
+            $epw = ($capu - $temp4 + $temp3 - $temp2)/(1.0 - $temp5 - $temp6) + $temp2;
234 234
             if (abs($epw - $temp2) <= Predict::e6a) {
235 235
                 break;
236 236
             }
@@ -240,33 +240,33 @@  discard block
 block discarded – undo
240 240
         /* Short period preliminary quantities */
241 241
         $ecose = $temp5 + $temp6;
242 242
         $esine = $temp3 - $temp4;
243
-        $elsq = $axn * $axn + $ayn * $ayn;
243
+        $elsq = $axn*$axn + $ayn*$ayn;
244 244
         $temp = 1.0 - $elsq;
245
-        $pl = $a * $temp;
246
-        $r = $a * (1.0 - $ecose);
247
-        $temp1 = 1.0 / $r;
248
-        $rdot = Predict::xke * sqrt($a) * $esine * $temp1;
249
-        $rfdot = Predict::xke * sqrt($pl) * $temp1;
250
-        $temp2 = $a * $temp1;
245
+        $pl = $a*$temp;
246
+        $r = $a*(1.0 - $ecose);
247
+        $temp1 = 1.0/$r;
248
+        $rdot = Predict::xke*sqrt($a)*$esine*$temp1;
249
+        $rfdot = Predict::xke*sqrt($pl)*$temp1;
250
+        $temp2 = $a*$temp1;
251 251
         $betal = sqrt($temp);
252
-        $temp3 = 1.0 / (1.0 + $betal);
253
-        $cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
254
-        $sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
252
+        $temp3 = 1.0/(1.0 + $betal);
253
+        $cosu = $temp2*($cosepw - $axn + $ayn*$esine*$temp3);
254
+        $sinu = $temp2*($sinepw - $ayn - $axn*$esine*$temp3);
255 255
         $u = Predict_Math::AcTan($sinu, $cosu);
256
-        $sin2u = 2.0 * $sinu * $cosu;
257
-        $cos2u = 2.0 * $cosu * $cosu - 1.0;
258
-        $temp = 1.0 / $pl;
259
-        $temp1 = Predict::ck2 * $temp;
260
-        $temp2 = $temp1 * $temp;
256
+        $sin2u = 2.0*$sinu*$cosu;
257
+        $cos2u = 2.0*$cosu*$cosu - 1.0;
258
+        $temp = 1.0/$pl;
259
+        $temp1 = Predict::ck2*$temp;
260
+        $temp2 = $temp1*$temp;
261 261
 
262 262
         /* Update for short periodics */
263
-        $rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
264
-            0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
265
-        $uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
266
-        $xnodek = $xnode + 1.5 * $temp2 * $sat->sgps->cosio * $sin2u;
267
-        $xinck = $sat->tle->xincl + 1.5 * $temp2 * $sat->sgps->cosio * $sat->sgps->sinio * $cos2u;
268
-        $rdotk = $rdot - $xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
269
-        $rfdotk = $rfdot + $xn * $temp1 * ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
263
+        $rk = $r*(1.0 - 1.5*$temp2*$betal*$sat->sgps->x3thm1) +
264
+            0.5*$temp1*$sat->sgps->x1mth2*$cos2u;
265
+        $uk = $u - 0.25*$temp2*$sat->sgps->x7thm1*$sin2u;
266
+        $xnodek = $xnode + 1.5*$temp2*$sat->sgps->cosio*$sin2u;
267
+        $xinck = $sat->tle->xincl + 1.5*$temp2*$sat->sgps->cosio*$sat->sgps->sinio*$cos2u;
268
+        $rdotk = $rdot - $xn*$temp1*$sat->sgps->x1mth2*$sin2u;
269
+        $rfdotk = $rfdot + $xn*$temp1*($sat->sgps->x1mth2*$cos2u + 1.5*$sat->sgps->x3thm1);
270 270
 
271 271
 
272 272
         /* Orientation vectors */
@@ -276,22 +276,22 @@  discard block
 block discarded – undo
276 276
         $cosik = cos($xinck);
277 277
         $sinnok = sin($xnodek);
278 278
         $cosnok = cos($xnodek);
279
-        $xmx = -$sinnok * $cosik;
280
-        $xmy = $cosnok * $cosik;
281
-        $ux = $xmx * $sinuk + $cosnok * $cosuk;
282
-        $uy = $xmy * $sinuk + $sinnok * $cosuk;
283
-        $uz = $sinik * $sinuk;
284
-        $vx = $xmx * $cosuk - $cosnok * $sinuk;
285
-        $vy = $xmy * $cosuk - $sinnok * $sinuk;
286
-        $vz = $sinik * $cosuk;
279
+        $xmx = -$sinnok*$cosik;
280
+        $xmy = $cosnok*$cosik;
281
+        $ux = $xmx*$sinuk + $cosnok*$cosuk;
282
+        $uy = $xmy*$sinuk + $sinnok*$cosuk;
283
+        $uz = $sinik*$sinuk;
284
+        $vx = $xmx*$cosuk - $cosnok*$sinuk;
285
+        $vy = $xmy*$cosuk - $sinnok*$sinuk;
286
+        $vz = $sinik*$cosuk;
287 287
 
288 288
         /* Position and velocity */
289
-        $sat->pos->x = $rk * $ux;
290
-        $sat->pos->y = $rk * $uy;
291
-        $sat->pos->z = $rk * $uz;
292
-        $sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
293
-        $sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
294
-        $sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
289
+        $sat->pos->x = $rk*$ux;
290
+        $sat->pos->y = $rk*$uy;
291
+        $sat->pos->z = $rk*$uz;
292
+        $sat->vel->x = $rdotk*$ux + $rfdotk*$vx;
293
+        $sat->vel->y = $rdotk*$uy + $rfdotk*$vy;
294
+        $sat->vel->z = $rdotk*$uz + $rfdotk*$vz;
295 295
 
296 296
         $sat->phase = $xlt - $xnode - $omgadf + Predict::twopi;
297 297
         if ($sat->phase < 0) {
@@ -315,106 +315,106 @@  discard block
 block discarded – undo
315 315
     public function SDP4(Predict_Sat $sat, $tsince)
316 316
     {
317 317
         /* Initialization */
318
-        if (~$sat->flags & self::SDP4_INITIALIZED_FLAG) {
318
+        if (~$sat->flags&self::SDP4_INITIALIZED_FLAG) {
319 319
 
320 320
             $sat->flags |= self::SDP4_INITIALIZED_FLAG;
321 321
 
322 322
             /* Recover original mean motion (xnodp) and   */
323 323
             /* semimajor axis (aodp) from input elements. */
324
-            $a1 = pow(Predict::xke / $sat->tle->xno, Predict::tothrd);
324
+            $a1 = pow(Predict::xke/$sat->tle->xno, Predict::tothrd);
325 325
             $sat->deep_arg->cosio = cos($sat->tle->xincl);
326
-            $sat->deep_arg->theta2 = $sat->deep_arg->cosio * $sat->deep_arg->cosio;
327
-            $sat->sgps->x3thm1 = 3.0 * $sat->deep_arg->theta2 - 1.0;
328
-            $sat->deep_arg->eosq = $sat->tle->eo * $sat->tle->eo;
326
+            $sat->deep_arg->theta2 = $sat->deep_arg->cosio*$sat->deep_arg->cosio;
327
+            $sat->sgps->x3thm1 = 3.0*$sat->deep_arg->theta2 - 1.0;
328
+            $sat->deep_arg->eosq = $sat->tle->eo*$sat->tle->eo;
329 329
             $sat->deep_arg->betao2 = 1.0 - $sat->deep_arg->eosq;
330 330
             $sat->deep_arg->betao = sqrt($sat->deep_arg->betao2);
331
-            $del1 = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
332
-                ($a1 * $a1 * $sat->deep_arg->betao * $sat->deep_arg->betao2);
333
-            $ao = $a1 * (1.0 - $del1 * (0.5 * Predict::tothrd + $del1 * (1.0 + 134.0 / 81.0 * $del1)));
334
-            $delo = 1.5 * Predict::ck2 * $sat->sgps->x3thm1 /
335
-                ($ao * $ao * $sat->deep_arg->betao * $sat->deep_arg->betao2);
336
-            $sat->deep_arg->xnodp = $sat->tle->xno / (1.0 + $delo);
337
-            $sat->deep_arg->aodp = $ao / (1.0 - $delo);
331
+            $del1 = 1.5*Predict::ck2*$sat->sgps->x3thm1/
332
+                ($a1*$a1*$sat->deep_arg->betao*$sat->deep_arg->betao2);
333
+            $ao = $a1*(1.0 - $del1*(0.5*Predict::tothrd + $del1*(1.0 + 134.0/81.0*$del1)));
334
+            $delo = 1.5*Predict::ck2*$sat->sgps->x3thm1/
335
+                ($ao*$ao*$sat->deep_arg->betao*$sat->deep_arg->betao2);
336
+            $sat->deep_arg->xnodp = $sat->tle->xno/(1.0 + $delo);
337
+            $sat->deep_arg->aodp = $ao/(1.0 - $delo);
338 338
 
339 339
             /* For perigee below 156 km, the values */
340 340
             /* of s and qoms2t are altered.         */
341 341
             $s4 = Predict::__s__;
342 342
             $qoms24 = Predict::qoms2t;
343
-            $perige = ($sat->deep_arg->aodp * (1.0 - $sat->tle->eo) - Predict::ae) * Predict::xkmper;
343
+            $perige = ($sat->deep_arg->aodp*(1.0 - $sat->tle->eo) - Predict::ae)*Predict::xkmper;
344 344
             if ($perige < 156.0) {
345 345
                 if ($perige <= 98.0) {
346 346
                     $s4 = 20.0;
347 347
                 } else {
348 348
                     $s4 = $perige - 78.0;
349 349
                 }
350
-                $qoms24 = pow((120.0 - $s4) * Predict::ae / Predict::xkmper, 4);
351
-                $s4 = $s4 / Predict::xkmper + Predict::ae;
350
+                $qoms24 = pow((120.0 - $s4)*Predict::ae/Predict::xkmper, 4);
351
+                $s4 = $s4/Predict::xkmper + Predict::ae;
352 352
             }
353
-            $pinvsq = 1.0 / ($sat->deep_arg->aodp * $sat->deep_arg->aodp *
354
-                    $sat->deep_arg->betao2 * $sat->deep_arg->betao2);
353
+            $pinvsq = 1.0/($sat->deep_arg->aodp*$sat->deep_arg->aodp*
354
+                    $sat->deep_arg->betao2*$sat->deep_arg->betao2);
355 355
             $sat->deep_arg->sing = sin($sat->tle->omegao);
356 356
             $sat->deep_arg->cosg = cos($sat->tle->omegao);
357
-            $tsi = 1.0 / ($sat->deep_arg->aodp - $s4);
358
-            $eta = $sat->deep_arg->aodp * $sat->tle->eo * $tsi;
359
-            $etasq = $eta * $eta;
360
-            $eeta = $sat->tle->eo * $eta;
357
+            $tsi = 1.0/($sat->deep_arg->aodp - $s4);
358
+            $eta = $sat->deep_arg->aodp*$sat->tle->eo*$tsi;
359
+            $etasq = $eta*$eta;
360
+            $eeta = $sat->tle->eo*$eta;
361 361
             $psisq = abs(1.0 - $etasq);
362
-            $coef = $qoms24 * pow($tsi, 4);
363
-            $coef1 = $coef / pow($psisq, 3.5);
364
-            $c2 = $coef1 * $sat->deep_arg->xnodp * ($sat->deep_arg->aodp *
365
-                                (1.0 + 1.5 * $etasq + $eeta *
366
-                                 (4.0 + $etasq)) + 0.75 * Predict::ck2 * $tsi / $psisq *
367
-                                $sat->sgps->x3thm1 * (8.0 + 3.0 * $etasq *
362
+            $coef = $qoms24*pow($tsi, 4);
363
+            $coef1 = $coef/pow($psisq, 3.5);
364
+            $c2 = $coef1*$sat->deep_arg->xnodp*($sat->deep_arg->aodp*
365
+                                (1.0 + 1.5*$etasq + $eeta*
366
+                                 (4.0 + $etasq)) + 0.75*Predict::ck2*$tsi/$psisq*
367
+                                $sat->sgps->x3thm1*(8.0 + 3.0*$etasq*
368 368
                                         (8.0 + $etasq)));
369
-            $sat->sgps->c1 = $sat->tle->bstar * $c2;
369
+            $sat->sgps->c1 = $sat->tle->bstar*$c2;
370 370
             $sat->deep_arg->sinio = sin($sat->tle->xincl);
371
-            $a3ovk2 = -Predict::xj3 / Predict::ck2 * pow(Predict::ae, 3);
371
+            $a3ovk2 = -Predict::xj3/Predict::ck2*pow(Predict::ae, 3);
372 372
             $sat->sgps->x1mth2 = 1.0 - $sat->deep_arg->theta2;
373
-            $sat->sgps->c4 = 2.0 * $sat->deep_arg->xnodp * $coef1 *
374
-                $sat->deep_arg->aodp * $sat->deep_arg->betao2 *
375
-                ($eta * (2.0 + 0.5 * $etasq) + $sat->tle->eo *
376
-                 (0.5 + 2.0 * $etasq) - 2.0 * Predict::ck2 * $tsi /
377
-                 ($sat->deep_arg->aodp * $psisq) * (-3.0 * $sat->sgps->x3thm1 *
378
-                                 (1.0 - 2.0 * $eeta + $etasq *
379
-                                  (1.5 - 0.5 * $eeta)) +
380
-                                 0.75 * $sat->sgps->x1mth2 *
381
-                                 (2.0 * $etasq - $eeta * (1.0 + $etasq)) *
382
-                                 cos(2.0 * $sat->tle->omegao)));
383
-            $theta4 = $sat->deep_arg->theta2 * $sat->deep_arg->theta2;
384
-            $temp1 = 3.0 * Predict::ck2 * $pinvsq * $sat->deep_arg->xnodp;
385
-            $temp2 = $temp1 * Predict::ck2 * $pinvsq;
386
-            $temp3 = 1.25 * Predict::ck4 * $pinvsq * $pinvsq * $sat->deep_arg->xnodp;
387
-            $sat->deep_arg->xmdot = $sat->deep_arg->xnodp + 0.5 * $temp1 * $sat->deep_arg->betao *
388
-                $sat->sgps->x3thm1 + 0.0625 * $temp2 * $sat->deep_arg->betao *
389
-                (13.0 - 78.0 * $sat->deep_arg->theta2 + 137.0 * $theta4);
390
-            $x1m5th = 1.0 - 5.0 * $sat->deep_arg->theta2;
391
-            $sat->deep_arg->omgdot = -0.5 * $temp1 * $x1m5th + 0.0625 * $temp2 *
392
-                            (7.0 - 114.0 * $sat->deep_arg->theta2 + 395.0 * $theta4) +
393
-                        $temp3 * (3.0 - 36.0 * $sat->deep_arg->theta2 + 49.0 * $theta4);
394
-            $xhdot1 = -$temp1 * $sat->deep_arg->cosio;
395
-            $sat->deep_arg->xnodot = $xhdot1 + (0.5 * $temp2 * (4.0 - 19.0 * $sat->deep_arg->theta2) +
396
-                             2.0 * $temp3 * (3.0 - 7.0 * $sat->deep_arg->theta2)) *
373
+            $sat->sgps->c4 = 2.0*$sat->deep_arg->xnodp*$coef1*
374
+                $sat->deep_arg->aodp*$sat->deep_arg->betao2*
375
+                ($eta*(2.0 + 0.5*$etasq) + $sat->tle->eo*
376
+                 (0.5 + 2.0*$etasq) - 2.0*Predict::ck2*$tsi/
377
+                 ($sat->deep_arg->aodp*$psisq)*(-3.0*$sat->sgps->x3thm1*
378
+                                 (1.0 - 2.0*$eeta + $etasq*
379
+                                  (1.5 - 0.5*$eeta)) +
380
+                                 0.75*$sat->sgps->x1mth2*
381
+                                 (2.0*$etasq - $eeta*(1.0 + $etasq))*
382
+                                 cos(2.0*$sat->tle->omegao)));
383
+            $theta4 = $sat->deep_arg->theta2*$sat->deep_arg->theta2;
384
+            $temp1 = 3.0*Predict::ck2*$pinvsq*$sat->deep_arg->xnodp;
385
+            $temp2 = $temp1*Predict::ck2*$pinvsq;
386
+            $temp3 = 1.25*Predict::ck4*$pinvsq*$pinvsq*$sat->deep_arg->xnodp;
387
+            $sat->deep_arg->xmdot = $sat->deep_arg->xnodp + 0.5*$temp1*$sat->deep_arg->betao*
388
+                $sat->sgps->x3thm1 + 0.0625*$temp2*$sat->deep_arg->betao*
389
+                (13.0 - 78.0*$sat->deep_arg->theta2 + 137.0*$theta4);
390
+            $x1m5th = 1.0 - 5.0*$sat->deep_arg->theta2;
391
+            $sat->deep_arg->omgdot = -0.5*$temp1*$x1m5th + 0.0625*$temp2*
392
+                            (7.0 - 114.0*$sat->deep_arg->theta2 + 395.0*$theta4) +
393
+                        $temp3*(3.0 - 36.0*$sat->deep_arg->theta2 + 49.0*$theta4);
394
+            $xhdot1 = -$temp1*$sat->deep_arg->cosio;
395
+            $sat->deep_arg->xnodot = $xhdot1 + (0.5*$temp2*(4.0 - 19.0*$sat->deep_arg->theta2) +
396
+                             2.0*$temp3*(3.0 - 7.0*$sat->deep_arg->theta2))*
397 397
                 $sat->deep_arg->cosio;
398
-            $sat->sgps->xnodcf = 3.5 * $sat->deep_arg->betao2 * $xhdot1 * $sat->sgps->c1;
399
-            $sat->sgps->t2cof = 1.5 * $sat->sgps->c1;
400
-            $sat->sgps->xlcof = 0.125 * $a3ovk2 * $sat->deep_arg->sinio *
401
-                (3.0 + 5.0 * $sat->deep_arg->cosio) / (1.0 + $sat->deep_arg->cosio);
402
-            $sat->sgps->aycof = 0.25 * $a3ovk2 * $sat->deep_arg->sinio;
403
-            $sat->sgps->x7thm1 = 7.0 * $sat->deep_arg->theta2 - 1.0;
398
+            $sat->sgps->xnodcf = 3.5*$sat->deep_arg->betao2*$xhdot1*$sat->sgps->c1;
399
+            $sat->sgps->t2cof = 1.5*$sat->sgps->c1;
400
+            $sat->sgps->xlcof = 0.125*$a3ovk2*$sat->deep_arg->sinio*
401
+                (3.0 + 5.0*$sat->deep_arg->cosio)/(1.0 + $sat->deep_arg->cosio);
402
+            $sat->sgps->aycof = 0.25*$a3ovk2*$sat->deep_arg->sinio;
403
+            $sat->sgps->x7thm1 = 7.0*$sat->deep_arg->theta2 - 1.0;
404 404
 
405 405
             /* initialize Deep() */
406 406
             $this->Deep(self::dpinit, $sat);
407 407
         }; /*End of SDP4() initialization */
408 408
 
409 409
         /* Update for secular gravity and atmospheric drag */
410
-        $xmdf = $sat->tle->xmo + $sat->deep_arg->xmdot * $tsince;
411
-        $sat->deep_arg->omgadf = $sat->tle->omegao + $sat->deep_arg->omgdot * $tsince;
412
-        $xnoddf = $sat->tle->xnodeo + $sat->deep_arg->xnodot * $tsince;
413
-        $tsq = $tsince * $tsince;
414
-        $sat->deep_arg->xnode = $xnoddf + $sat->sgps->xnodcf * $tsq;
415
-        $tempa = 1.0 - $sat->sgps->c1 * $tsince;
416
-        $tempe = $sat->tle->bstar * $sat->sgps->c4 * $tsince;
417
-        $templ = $sat->sgps->t2cof * $tsq;
410
+        $xmdf = $sat->tle->xmo + $sat->deep_arg->xmdot*$tsince;
411
+        $sat->deep_arg->omgadf = $sat->tle->omegao + $sat->deep_arg->omgdot*$tsince;
412
+        $xnoddf = $sat->tle->xnodeo + $sat->deep_arg->xnodot*$tsince;
413
+        $tsq = $tsince*$tsince;
414
+        $sat->deep_arg->xnode = $xnoddf + $sat->sgps->xnodcf*$tsq;
415
+        $tempa = 1.0 - $sat->sgps->c1*$tsince;
416
+        $tempe = $sat->tle->bstar*$sat->sgps->c4*$tsince;
417
+        $templ = $sat->sgps->t2cof*$tsq;
418 418
         $sat->deep_arg->xn = $sat->deep_arg->xnodp;
419 419
 
420 420
         /* Update for deep-space secular effects */
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
         $this->Deep(self::dpsec, $sat);
425 425
 
426 426
         $xmdf = $sat->deep_arg->xll;
427
-        $a = pow(Predict::xke / $sat->deep_arg->xn, Predict::tothrd) * $tempa * $tempa;
427
+        $a = pow(Predict::xke/$sat->deep_arg->xn, Predict::tothrd)*$tempa*$tempa;
428 428
         $sat->deep_arg->em = $sat->deep_arg->em - $tempe;
429
-        $xmam = $xmdf + $sat->deep_arg->xnodp * $templ;
429
+        $xmam = $xmdf + $sat->deep_arg->xnodp*$templ;
430 430
 
431 431
         /* Update for deep-space periodic effects */
432 432
         $sat->deep_arg->xll = $xmam;
@@ -435,30 +435,30 @@  discard block
 block discarded – undo
435 435
 
436 436
         $xmam = $sat->deep_arg->xll;
437 437
         $xl = $xmam + $sat->deep_arg->omgadf + $sat->deep_arg->xnode;
438
-        $beta = sqrt(1.0 - $sat->deep_arg->em * $sat->deep_arg->em);
439
-        $sat->deep_arg->xn = Predict::xke / pow($a, 1.5);
438
+        $beta = sqrt(1.0 - $sat->deep_arg->em*$sat->deep_arg->em);
439
+        $sat->deep_arg->xn = Predict::xke/pow($a, 1.5);
440 440
 
441 441
         /* Long period periodics */
442
-        $axn = $sat->deep_arg->em * cos($sat->deep_arg->omgadf);
443
-        $temp = 1.0 / ($a * $beta * $beta);
444
-        $xll = $temp * $sat->sgps->xlcof * $axn;
445
-        $aynl = $temp * $sat->sgps->aycof;
442
+        $axn = $sat->deep_arg->em*cos($sat->deep_arg->omgadf);
443
+        $temp = 1.0/($a*$beta*$beta);
444
+        $xll = $temp*$sat->sgps->xlcof*$axn;
445
+        $aynl = $temp*$sat->sgps->aycof;
446 446
         $xlt = $xl + $xll;
447
-        $ayn = $sat->deep_arg->em * sin($sat->deep_arg->omgadf) + $aynl;
447
+        $ayn = $sat->deep_arg->em*sin($sat->deep_arg->omgadf) + $aynl;
448 448
 
449 449
         /* Solve Kepler's Equation */
450
-        $capu = Predict_Math::FMod2p ($xlt - $sat->deep_arg->xnode);
450
+        $capu = Predict_Math::FMod2p($xlt - $sat->deep_arg->xnode);
451 451
         $temp2 = $capu;
452 452
 
453 453
         $i = 0;
454 454
         do {
455 455
             $sinepw = sin($temp2);
456 456
             $cosepw = cos($temp2);
457
-            $temp3 = $axn * $sinepw;
458
-            $temp4 = $ayn * $cosepw;
459
-            $temp5 = $axn * $cosepw;
460
-            $temp6 = $ayn * $sinepw;
461
-            $epw = ($capu - $temp4 + $temp3 - $temp2) / (1.0 - $temp5 - $temp6) + $temp2;
457
+            $temp3 = $axn*$sinepw;
458
+            $temp4 = $ayn*$cosepw;
459
+            $temp5 = $axn*$cosepw;
460
+            $temp6 = $ayn*$sinepw;
461
+            $epw = ($capu - $temp4 + $temp3 - $temp2)/(1.0 - $temp5 - $temp6) + $temp2;
462 462
             if (abs($epw - $temp2) <= Predict::e6a) {
463 463
                 break;
464 464
             }
@@ -468,35 +468,35 @@  discard block
 block discarded – undo
468 468
         /* Short period preliminary quantities */
469 469
         $ecose = $temp5 + $temp6;
470 470
         $esine = $temp3 - $temp4;
471
-        $elsq = $axn * $axn + $ayn * $ayn;
471
+        $elsq = $axn*$axn + $ayn*$ayn;
472 472
         $temp = 1.0 - $elsq;
473
-        $pl = $a * $temp;
474
-        $r = $a * (1.0 - $ecose);
475
-        $temp1 = 1.0 / $r;
476
-        $rdot = Predict::xke * sqrt($a) * $esine * $temp1;
477
-        $rfdot = Predict::xke * sqrt($pl) * $temp1;
478
-        $temp2 = $a * $temp1;
473
+        $pl = $a*$temp;
474
+        $r = $a*(1.0 - $ecose);
475
+        $temp1 = 1.0/$r;
476
+        $rdot = Predict::xke*sqrt($a)*$esine*$temp1;
477
+        $rfdot = Predict::xke*sqrt($pl)*$temp1;
478
+        $temp2 = $a*$temp1;
479 479
         $betal = sqrt($temp);
480
-        $temp3 = 1.0 / (1.0 + $betal);
481
-        $cosu = $temp2 * ($cosepw - $axn + $ayn * $esine * $temp3);
482
-        $sinu = $temp2 * ($sinepw - $ayn - $axn * $esine * $temp3);
480
+        $temp3 = 1.0/(1.0 + $betal);
481
+        $cosu = $temp2*($cosepw - $axn + $ayn*$esine*$temp3);
482
+        $sinu = $temp2*($sinepw - $ayn - $axn*$esine*$temp3);
483 483
         $u = Predict_Math::AcTan($sinu, $cosu);
484
-        $sin2u = 2.0 * $sinu * $cosu;
485
-        $cos2u = 2.0 * $cosu * $cosu - 1.0;
486
-        $temp = 1.0 / $pl;
487
-        $temp1 = Predict::ck2 * $temp;
488
-        $temp2 = $temp1 * $temp;
484
+        $sin2u = 2.0*$sinu*$cosu;
485
+        $cos2u = 2.0*$cosu*$cosu - 1.0;
486
+        $temp = 1.0/$pl;
487
+        $temp1 = Predict::ck2*$temp;
488
+        $temp2 = $temp1*$temp;
489 489
 
490 490
         /* Update for short periodics */
491
-        $rk = $r * (1.0 - 1.5 * $temp2 * $betal * $sat->sgps->x3thm1) +
492
-             0.5 * $temp1 * $sat->sgps->x1mth2 * $cos2u;
493
-        $uk = $u - 0.25 * $temp2 * $sat->sgps->x7thm1 * $sin2u;
494
-        $xnodek = $sat->deep_arg->xnode + 1.5 * $temp2 * $sat->deep_arg->cosio * $sin2u;
495
-        $xinck = $sat->deep_arg->xinc + 1.5 * $temp2 *
496
-             $sat->deep_arg->cosio * $sat->deep_arg->sinio * $cos2u;
497
-        $rdotk = $rdot - $sat->deep_arg->xn * $temp1 * $sat->sgps->x1mth2 * $sin2u;
498
-        $rfdotk = $rfdot + $sat->deep_arg->xn * $temp1 *
499
-             ($sat->sgps->x1mth2 * $cos2u + 1.5 * $sat->sgps->x3thm1);
491
+        $rk = $r*(1.0 - 1.5*$temp2*$betal*$sat->sgps->x3thm1) +
492
+             0.5*$temp1*$sat->sgps->x1mth2*$cos2u;
493
+        $uk = $u - 0.25*$temp2*$sat->sgps->x7thm1*$sin2u;
494
+        $xnodek = $sat->deep_arg->xnode + 1.5*$temp2*$sat->deep_arg->cosio*$sin2u;
495
+        $xinck = $sat->deep_arg->xinc + 1.5*$temp2*
496
+             $sat->deep_arg->cosio*$sat->deep_arg->sinio*$cos2u;
497
+        $rdotk = $rdot - $sat->deep_arg->xn*$temp1*$sat->sgps->x1mth2*$sin2u;
498
+        $rfdotk = $rfdot + $sat->deep_arg->xn*$temp1*
499
+             ($sat->sgps->x1mth2*$cos2u + 1.5*$sat->sgps->x3thm1);
500 500
 
501 501
         /* Orientation vectors */
502 502
         $sinuk = sin($uk);
@@ -505,29 +505,29 @@  discard block
 block discarded – undo
505 505
         $cosik = cos($xinck);
506 506
         $sinnok = sin($xnodek);
507 507
         $cosnok = cos($xnodek);
508
-        $xmx = -$sinnok * $cosik;
509
-        $xmy = $cosnok * $cosik;
510
-        $ux = $xmx * $sinuk + $cosnok * $cosuk;
511
-        $uy = $xmy * $sinuk + $sinnok * $cosuk;
512
-        $uz = $sinik * $sinuk;
513
-        $vx = $xmx * $cosuk - $cosnok * $sinuk;
514
-        $vy = $xmy * $cosuk - $sinnok * $sinuk;
515
-        $vz = $sinik * $cosuk;
508
+        $xmx = -$sinnok*$cosik;
509
+        $xmy = $cosnok*$cosik;
510
+        $ux = $xmx*$sinuk + $cosnok*$cosuk;
511
+        $uy = $xmy*$sinuk + $sinnok*$cosuk;
512
+        $uz = $sinik*$sinuk;
513
+        $vx = $xmx*$cosuk - $cosnok*$sinuk;
514
+        $vy = $xmy*$cosuk - $sinnok*$sinuk;
515
+        $vz = $sinik*$cosuk;
516 516
 
517 517
         /* Position and velocity */
518
-        $sat->pos->x = $rk * $ux;
519
-        $sat->pos->y = $rk * $uy;
520
-        $sat->pos->z = $rk * $uz;
521
-        $sat->vel->x = $rdotk * $ux + $rfdotk * $vx;
522
-        $sat->vel->y = $rdotk * $uy + $rfdotk * $vy;
523
-        $sat->vel->z = $rdotk * $uz + $rfdotk * $vz;
518
+        $sat->pos->x = $rk*$ux;
519
+        $sat->pos->y = $rk*$uy;
520
+        $sat->pos->z = $rk*$uz;
521
+        $sat->vel->x = $rdotk*$ux + $rfdotk*$vx;
522
+        $sat->vel->y = $rdotk*$uy + $rfdotk*$vy;
523
+        $sat->vel->z = $rdotk*$uz + $rfdotk*$vz;
524 524
 
525 525
         /* Phase in rads */
526 526
         $sat->phase = $xlt - $sat->deep_arg->xnode - $sat->deep_arg->omgadf + Predict::twopi;
527 527
         if ($sat->phase < 0.0) {
528 528
             $sat->phase += Predict::twopi;
529 529
         }
530
-        $sat->phase = Predict_Math::FMod2p ($sat->phase);
530
+        $sat->phase = Predict_Math::FMod2p($sat->phase);
531 531
 
532 532
         $sat->tle->omegao1 = $sat->deep_arg->omgadf;
533 533
         $sat->tle->xincl1  = $sat->deep_arg->xinc;
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
             $sat->dps->thgr = Predict_Time::ThetaG($sat->tle->epoch, $sat->deep_arg);
546 546
             $eq = $sat->tle->eo;
547 547
             $sat->dps->xnq = $sat->deep_arg->xnodp;
548
-            $aqnv = 1.0 / $sat->deep_arg->aodp;
548
+            $aqnv = 1.0/$sat->deep_arg->aodp;
549 549
             $sat->dps->xqncl = $sat->tle->xincl;
550 550
             $xmao = $sat->tle->xmo;
551 551
             $xpidot = $sat->deep_arg->omgdot + $sat->deep_arg->xnodot;
@@ -555,26 +555,26 @@  discard block
 block discarded – undo
555 555
             $sat->dps->preep = 0;
556 556
 
557 557
             /* Initialize lunar solar terms */
558
-            $day = $sat->deep_arg->ds50 + 18261.5;  /* Days since 1900 Jan 0.5 */
558
+            $day = $sat->deep_arg->ds50 + 18261.5; /* Days since 1900 Jan 0.5 */
559 559
             if ($day != $sat->dps->preep) {
560 560
                 $sat->dps->preep = $day;
561
-                $xnodce = 4.5236020 - 9.2422029E-4 * $day;
561
+                $xnodce = 4.5236020 - 9.2422029E-4*$day;
562 562
                 $stem = sin($xnodce);
563 563
                 $ctem = cos($xnodce);
564
-                $sat->dps->zcosil = 0.91375164 - 0.03568096 * $ctem;
565
-                $sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil * $sat->dps->zcosil);
566
-                $sat->dps->zsinhl = 0.089683511 * $stem / $sat->dps->zsinil;
567
-                $sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl * $sat->dps->zsinhl);
568
-                $c = 4.7199672 + 0.22997150 * $day;
569
-                $gam = 5.8351514 + 0.0019443680 * $day;
564
+                $sat->dps->zcosil = 0.91375164 - 0.03568096*$ctem;
565
+                $sat->dps->zsinil = sqrt(1.0 - $sat->dps->zcosil*$sat->dps->zcosil);
566
+                $sat->dps->zsinhl = 0.089683511*$stem/$sat->dps->zsinil;
567
+                $sat->dps->zcoshl = sqrt(1.0 - $sat->dps->zsinhl*$sat->dps->zsinhl);
568
+                $c = 4.7199672 + 0.22997150*$day;
569
+                $gam = 5.8351514 + 0.0019443680*$day;
570 570
                 $sat->dps->zmol = Predict_Math::FMod2p($c - $gam);
571
-                $zx = 0.39785416 * $stem / $sat->dps->zsinil;
572
-                $zy = $sat->dps->zcoshl * $ctem + 0.91744867 * $sat->dps->zsinhl * $stem;
571
+                $zx = 0.39785416*$stem/$sat->dps->zsinil;
572
+                $zy = $sat->dps->zcoshl*$ctem + 0.91744867*$sat->dps->zsinhl*$stem;
573 573
                 $zx = Predict_Math::AcTan($zx, $zy);
574 574
                 $zx = $gam + $zx - $xnodce;
575 575
                 $sat->dps->zcosgl = cos($zx);
576 576
                 $sat->dps->zsingl = sin($zx);
577
-                $sat->dps->zmos = 6.2565837 + 0.017201977 * $day;
577
+                $sat->dps->zmos = 6.2565837 + 0.017201977*$day;
578 578
                 $sat->dps->zmos = Predict_Math::FMod2p($sat->dps->zmos);
579 579
             } /* End if(day != preep) */
580 580
 
@@ -590,76 +590,76 @@  discard block
 block discarded – undo
590 590
             $zn = Predict::zns;
591 591
             $ze = Predict::zes;
592 592
             $zmo = $sat->dps->zmos;
593
-            $xnoi = 1.0 / $sat->dps->xnq;
593
+            $xnoi = 1.0/$sat->dps->xnq;
594 594
 
595 595
             /* Loop breaks when Solar terms are done a second */
596 596
             /* time, after Lunar terms are initialized        */
597
-            for(;;) {
597
+            for (;;) {
598 598
                 /* Solar terms done again after Lunar terms are done */
599
-                $a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
600
-                $a3 = -$zsing * $zcosh + $zcosg * $zcosi * $zsinh;
601
-                $a7 = -$zcosg * $zsinh + $zsing * $zcosi * $zcosh;
602
-                $a8 = $zsing * $zsini;
603
-                $a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
604
-                $a10 = $zcosg * $zsini;
605
-                $a2 = $sat->deep_arg->cosio * $a7 + $sat->deep_arg->sinio * $a8;
606
-                $a4 = $sat->deep_arg->cosio * $a9 + $sat->deep_arg->sinio * $a10;
607
-                $a5 = -$sat->deep_arg->sinio * $a7 + $sat->deep_arg->cosio * $a8;
608
-                $a6 = -$sat->deep_arg->sinio * $a9 + $sat->deep_arg->cosio * $a10;
609
-                $x1 = $a1 * $sat->deep_arg->cosg + $a2 * $sat->deep_arg->sing;
610
-                $x2 = $a3 * $sat->deep_arg->cosg + $a4 * $sat->deep_arg->sing;
611
-                $x3 = -$a1 * $sat->deep_arg->sing + $a2 * $sat->deep_arg->cosg;
612
-                $x4 = -$a3 * $sat->deep_arg->sing + $a4 * $sat->deep_arg->cosg;
613
-                $x5 = $a5 * $sat->deep_arg->sing;
614
-                $x6 = $a6 * $sat->deep_arg->sing;
615
-                $x7 = $a5 * $sat->deep_arg->cosg;
616
-                $x8 = $a6 * $sat->deep_arg->cosg;
617
-                $z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
618
-                $z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
619
-                $z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
620
-                $z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $sat->deep_arg->eosq;
621
-                $z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $sat->deep_arg->eosq;
622
-                $z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $sat->deep_arg->eosq;
623
-                $z11 = -6 * $a1 * $a5 + $sat->deep_arg->eosq * (-24 * $x1 * $x7 - 6 * $x3 * $x5);
624
-                $z12 = -6 * ($a1 * $a6 + $a3 * $a5) + $sat->deep_arg->eosq *
625
-                    (-24 * ($x2 * $x7 + $x1 * $x8) - 6 * ($x3 * $x6 + $x4 * $x5));
626
-                $z13 = -6 * $a3 * $a6 + $sat->deep_arg->eosq * (-24 * $x2 * $x8 - 6 * $x4 * $x6);
627
-                $z21 = 6 * $a2 * $a5 + $sat->deep_arg->eosq * (24 * $x1 * $x5 - 6 * $x3 * $x7);
628
-                $z22 = 6 * ($a4 * $a5 + $a2 * $a6) + $sat->deep_arg->eosq *
629
-                    (24 * ($x2 * $x5 + $x1 * $x6) - 6 * ($x4 * $x7 + $x3 * $x8));
630
-                $z23 = 6 * $a4 * $a6 + $sat->deep_arg->eosq * (24 * $x2 * $x6 - 6 * $x4 * $x8);
631
-                $z1 = $z1 + $z1 + $sat->deep_arg->betao2 * $z31;
632
-                $z2 = $z2 + $z2 + $sat->deep_arg->betao2 * $z32;
633
-                $z3 = $z3 + $z3 + $sat->deep_arg->betao2 * $z33;
634
-                $s3 = $cc * $xnoi;
635
-                $s2 = -0.5 * $s3 / $sat->deep_arg->betao;
636
-                $s4 = $s3 * $sat->deep_arg->betao;
637
-                $s1 = -15 * $eq * $s4;
638
-                $s5 = $x1 * $x3 + $x2 * $x4;
639
-                $s6 = $x2 * $x3 + $x1 * $x4;
640
-                $s7 = $x2 * $x4 - $x1 * $x3;
641
-                $se = $s1 * $zn * $s5;
642
-                $si = $s2 * $zn * ($z11 + $z13);
643
-                $sl = -$zn * $s3 * ($z1 + $z3 - 14 - 6 * $sat->deep_arg->eosq);
644
-                $sgh = $s4 * $zn * ($z31 + $z33 - 6);
645
-                $sh = -$zn * $s2 * ($z21 + $z23);
599
+                $a1 = $zcosg*$zcosh + $zsing*$zcosi*$zsinh;
600
+                $a3 = -$zsing*$zcosh + $zcosg*$zcosi*$zsinh;
601
+                $a7 = -$zcosg*$zsinh + $zsing*$zcosi*$zcosh;
602
+                $a8 = $zsing*$zsini;
603
+                $a9 = $zsing*$zsinh + $zcosg*$zcosi*$zcosh;
604
+                $a10 = $zcosg*$zsini;
605
+                $a2 = $sat->deep_arg->cosio*$a7 + $sat->deep_arg->sinio*$a8;
606
+                $a4 = $sat->deep_arg->cosio*$a9 + $sat->deep_arg->sinio*$a10;
607
+                $a5 = -$sat->deep_arg->sinio*$a7 + $sat->deep_arg->cosio*$a8;
608
+                $a6 = -$sat->deep_arg->sinio*$a9 + $sat->deep_arg->cosio*$a10;
609
+                $x1 = $a1*$sat->deep_arg->cosg + $a2*$sat->deep_arg->sing;
610
+                $x2 = $a3*$sat->deep_arg->cosg + $a4*$sat->deep_arg->sing;
611
+                $x3 = -$a1*$sat->deep_arg->sing + $a2*$sat->deep_arg->cosg;
612
+                $x4 = -$a3*$sat->deep_arg->sing + $a4*$sat->deep_arg->cosg;
613
+                $x5 = $a5*$sat->deep_arg->sing;
614
+                $x6 = $a6*$sat->deep_arg->sing;
615
+                $x7 = $a5*$sat->deep_arg->cosg;
616
+                $x8 = $a6*$sat->deep_arg->cosg;
617
+                $z31 = 12*$x1*$x1 - 3*$x3*$x3;
618
+                $z32 = 24*$x1*$x2 - 6*$x3*$x4;
619
+                $z33 = 12*$x2*$x2 - 3*$x4*$x4;
620
+                $z1 = 3*($a1*$a1 + $a2*$a2) + $z31*$sat->deep_arg->eosq;
621
+                $z2 = 6*($a1*$a3 + $a2*$a4) + $z32*$sat->deep_arg->eosq;
622
+                $z3 = 3*($a3*$a3 + $a4*$a4) + $z33*$sat->deep_arg->eosq;
623
+                $z11 = -6*$a1*$a5 + $sat->deep_arg->eosq*(-24*$x1*$x7 - 6*$x3*$x5);
624
+                $z12 = -6*($a1*$a6 + $a3*$a5) + $sat->deep_arg->eosq*
625
+                    (-24*($x2*$x7 + $x1*$x8) - 6*($x3*$x6 + $x4*$x5));
626
+                $z13 = -6*$a3*$a6 + $sat->deep_arg->eosq*(-24*$x2*$x8 - 6*$x4*$x6);
627
+                $z21 = 6*$a2*$a5 + $sat->deep_arg->eosq*(24*$x1*$x5 - 6*$x3*$x7);
628
+                $z22 = 6*($a4*$a5 + $a2*$a6) + $sat->deep_arg->eosq*
629
+                    (24*($x2*$x5 + $x1*$x6) - 6*($x4*$x7 + $x3*$x8));
630
+                $z23 = 6*$a4*$a6 + $sat->deep_arg->eosq*(24*$x2*$x6 - 6*$x4*$x8);
631
+                $z1 = $z1 + $z1 + $sat->deep_arg->betao2*$z31;
632
+                $z2 = $z2 + $z2 + $sat->deep_arg->betao2*$z32;
633
+                $z3 = $z3 + $z3 + $sat->deep_arg->betao2*$z33;
634
+                $s3 = $cc*$xnoi;
635
+                $s2 = -0.5*$s3/$sat->deep_arg->betao;
636
+                $s4 = $s3*$sat->deep_arg->betao;
637
+                $s1 = -15*$eq*$s4;
638
+                $s5 = $x1*$x3 + $x2*$x4;
639
+                $s6 = $x2*$x3 + $x1*$x4;
640
+                $s7 = $x2*$x4 - $x1*$x3;
641
+                $se = $s1*$zn*$s5;
642
+                $si = $s2*$zn*($z11 + $z13);
643
+                $sl = -$zn*$s3*($z1 + $z3 - 14 - 6*$sat->deep_arg->eosq);
644
+                $sgh = $s4*$zn*($z31 + $z33 - 6);
645
+                $sh = -$zn*$s2*($z21 + $z23);
646 646
                 if ($sat->dps->xqncl < 5.2359877E-2) {
647 647
                     $sh = 0;
648 648
                 }
649
-                $sat->dps->ee2 = 2 * $s1 * $s6;
650
-                $sat->dps->e3 = 2 * $s1 * $s7;
651
-                $sat->dps->xi2 = 2 * $s2 * $z12;
652
-                $sat->dps->xi3 = 2 * $s2 * ($z13 - $z11);
653
-                $sat->dps->xl2 = -2 * $s3 * $z2;
654
-                $sat->dps->xl3 = -2 * $s3 * ($z3 - $z1);
655
-                $sat->dps->xl4 = -2 * $s3 * (-21 - 9 * $sat->deep_arg->eosq) * $ze;
656
-                $sat->dps->xgh2 = 2 * $s4 * $z32;
657
-                $sat->dps->xgh3 = 2 * $s4 * ($z33 - $z31);
658
-                $sat->dps->xgh4 = -18 * $s4 * $ze;
659
-                $sat->dps->xh2 = -2 * $s2 * $z22;
660
-                $sat->dps->xh3 = -2 * $s2 * ($z23 - $z21);
661
-
662
-                if ($sat->flags & self::LUNAR_TERMS_DONE_FLAG) {
649
+                $sat->dps->ee2 = 2*$s1*$s6;
650
+                $sat->dps->e3 = 2*$s1*$s7;
651
+                $sat->dps->xi2 = 2*$s2*$z12;
652
+                $sat->dps->xi3 = 2*$s2*($z13 - $z11);
653
+                $sat->dps->xl2 = -2*$s3*$z2;
654
+                $sat->dps->xl3 = -2*$s3*($z3 - $z1);
655
+                $sat->dps->xl4 = -2*$s3*(-21 - 9*$sat->deep_arg->eosq)*$ze;
656
+                $sat->dps->xgh2 = 2*$s4*$z32;
657
+                $sat->dps->xgh3 = 2*$s4*($z33 - $z31);
658
+                $sat->dps->xgh4 = -18*$s4*$ze;
659
+                $sat->dps->xh2 = -2*$s2*$z22;
660
+                $sat->dps->xh3 = -2*$s2*($z23 - $z21);
661
+
662
+                if ($sat->flags&self::LUNAR_TERMS_DONE_FLAG) {
663 663
                     break;
664 664
                 }
665 665
 
@@ -667,8 +667,8 @@  discard block
 block discarded – undo
667 667
                 $sat->dps->sse = $se;
668 668
                 $sat->dps->ssi = $si;
669 669
                 $sat->dps->ssl = $sl;
670
-                $sat->dps->ssh = $sh / $sat->deep_arg->sinio;
671
-                $sat->dps->ssg = $sgh - $sat->deep_arg->cosio * $sat->dps->ssh;
670
+                $sat->dps->ssh = $sh/$sat->deep_arg->sinio;
671
+                $sat->dps->ssg = $sgh - $sat->deep_arg->cosio*$sat->dps->ssh;
672 672
                 $sat->dps->se2 = $sat->dps->ee2;
673 673
                 $sat->dps->si2 = $sat->dps->xi2;
674 674
                 $sat->dps->sl2 = $sat->dps->xl2;
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
                 $zsing = $sat->dps->zsingl;
686 686
                 $zcosi = $sat->dps->zcosil;
687 687
                 $zsini = $sat->dps->zsinil;
688
-                $zcosh = $sat->dps->zcoshl * $cosq + $sat->dps->zsinhl * $sinq;
689
-                $zsinh = $sinq * $sat->dps->zcoshl - $cosq * $sat->dps->zsinhl;
688
+                $zcosh = $sat->dps->zcoshl*$cosq + $sat->dps->zsinhl*$sinq;
689
+                $zsinh = $sinq*$sat->dps->zcoshl - $cosq*$sat->dps->zsinhl;
690 690
                 $zn = Predict::znl;
691 691
                 $cc = Predict::c1l;
692 692
                 $ze = Predict::zel;
@@ -697,113 +697,113 @@  discard block
 block discarded – undo
697 697
             $sat->dps->sse = $sat->dps->sse + $se;
698 698
             $sat->dps->ssi = $sat->dps->ssi + $si;
699 699
             $sat->dps->ssl = $sat->dps->ssl + $sl;
700
-            $sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio / $sat->deep_arg->sinio * $sh;
701
-            $sat->dps->ssh = $sat->dps->ssh + $sh / $sat->deep_arg->sinio;
700
+            $sat->dps->ssg = $sat->dps->ssg + $sgh - $sat->deep_arg->cosio/$sat->deep_arg->sinio*$sh;
701
+            $sat->dps->ssh = $sat->dps->ssh + $sh/$sat->deep_arg->sinio;
702 702
 
703 703
             /* Geopotential resonance initialization for 12 hour orbits */
704 704
             $sat->flags &= ~self::RESONANCE_FLAG;
705 705
             $sat->flags &= ~self::SYNCHRONOUS_FLAG;
706 706
 
707 707
             if (!(($sat->dps->xnq < 0.0052359877) && ($sat->dps->xnq > 0.0034906585))) {
708
-                if( ($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924) ) {
708
+                if (($sat->dps->xnq < 0.00826) || ($sat->dps->xnq > 0.00924)) {
709 709
                     return;
710 710
                 }
711 711
                 if ($eq < 0.5) {
712 712
                     return;
713 713
                 }
714 714
                 $sat->flags |= self::RESONANCE_FLAG;
715
-                $eoc = $eq * $sat->deep_arg->eosq;
716
-                $g201 = -0.306 - ($eq - 0.64) * 0.440;
715
+                $eoc = $eq*$sat->deep_arg->eosq;
716
+                $g201 = -0.306 - ($eq - 0.64)*0.440;
717 717
                 if ($eq <= 0.65) {
718
-                    $g211 = 3.616 - 13.247 * $eq + 16.290 * $sat->deep_arg->eosq;
719
-                    $g310 = -19.302 + 117.390 * $eq - 228.419 *
720
-                        $sat->deep_arg->eosq + 156.591 * $eoc;
721
-                    $g322 = -18.9068 + 109.7927 * $eq - 214.6334 *
722
-                        $sat->deep_arg->eosq + 146.5816 * $eoc;
723
-                    $g410 = -41.122 + 242.694 * $eq - 471.094 *
724
-                        $sat->deep_arg->eosq + 313.953 * $eoc;
725
-                    $g422 = -146.407 + 841.880 * $eq - 1629.014 *
726
-                        $sat->deep_arg->eosq + 1083.435 * $eoc;
727
-                    $g520 = -532.114 + 3017.977 * $eq - 5740 *
728
-                        $sat->deep_arg->eosq + 3708.276 * $eoc;
718
+                    $g211 = 3.616 - 13.247*$eq + 16.290*$sat->deep_arg->eosq;
719
+                    $g310 = -19.302 + 117.390*$eq - 228.419*
720
+                        $sat->deep_arg->eosq + 156.591*$eoc;
721
+                    $g322 = -18.9068 + 109.7927*$eq - 214.6334*
722
+                        $sat->deep_arg->eosq + 146.5816*$eoc;
723
+                    $g410 = -41.122 + 242.694*$eq - 471.094*
724
+                        $sat->deep_arg->eosq + 313.953*$eoc;
725
+                    $g422 = -146.407 + 841.880*$eq - 1629.014*
726
+                        $sat->deep_arg->eosq + 1083.435*$eoc;
727
+                    $g520 = -532.114 + 3017.977*$eq - 5740*
728
+                        $sat->deep_arg->eosq + 3708.276*$eoc;
729 729
                 } else {
730
-                    $g211 = -72.099 + 331.819 * $eq - 508.738 *
731
-                        $sat->deep_arg->eosq + 266.724 * $eoc;
732
-                    $g310 = -346.844 + 1582.851 * $eq - 2415.925 *
733
-                        $sat->deep_arg->eosq + 1246.113 * $eoc;
734
-                    $g322 = -342.585 + 1554.908 * $eq - 2366.899 *
735
-                        $sat->deep_arg->eosq + 1215.972 * $eoc;
736
-                    $g410 = -1052.797 + 4758.686 * $eq - 7193.992 *
737
-                        $sat->deep_arg->eosq + 3651.957 * $eoc;
738
-                    $g422 = -3581.69 + 16178.11 * $eq - 24462.77 *
739
-                        $sat->deep_arg->eosq+ 12422.52 * $eoc;
730
+                    $g211 = -72.099 + 331.819*$eq - 508.738*
731
+                        $sat->deep_arg->eosq + 266.724*$eoc;
732
+                    $g310 = -346.844 + 1582.851*$eq - 2415.925*
733
+                        $sat->deep_arg->eosq + 1246.113*$eoc;
734
+                    $g322 = -342.585 + 1554.908*$eq - 2366.899*
735
+                        $sat->deep_arg->eosq + 1215.972*$eoc;
736
+                    $g410 = -1052.797 + 4758.686*$eq - 7193.992*
737
+                        $sat->deep_arg->eosq + 3651.957*$eoc;
738
+                    $g422 = -3581.69 + 16178.11*$eq - 24462.77*
739
+                        $sat->deep_arg->eosq + 12422.52*$eoc;
740 740
                     if ($eq <= 0.715) {
741
-                        $g520 = 1464.74 - 4664.75 * $eq + 3763.64 * $sat->deep_arg->eosq;
741
+                        $g520 = 1464.74 - 4664.75*$eq + 3763.64*$sat->deep_arg->eosq;
742 742
                     } else {
743
-                        $g520 = -5149.66 + 29936.92 * $eq - 54087.36 *
744
-                            $sat->deep_arg->eosq + 31324.56 * $eoc;
743
+                        $g520 = -5149.66 + 29936.92*$eq - 54087.36*
744
+                            $sat->deep_arg->eosq + 31324.56*$eoc;
745 745
                     }
746 746
                 } /* End if (eq <= 0.65) */
747 747
 
748 748
                 if ($eq < 0.7) {
749
-                    $g533 = -919.2277 + 4988.61 * $eq - 9064.77 *
750
-                        $sat->deep_arg->eosq + 5542.21 * $eoc;
751
-                    $g521 = -822.71072 + 4568.6173 * $eq - 8491.4146 *
752
-                        $sat->deep_arg->eosq + 5337.524 * $eoc;
753
-                    $g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754
-                        $sat->deep_arg->eosq + 5341.4 * $eoc;
749
+                    $g533 = -919.2277 + 4988.61*$eq - 9064.77*
750
+                        $sat->deep_arg->eosq + 5542.21*$eoc;
751
+                    $g521 = -822.71072 + 4568.6173*$eq - 8491.4146*
752
+                        $sat->deep_arg->eosq + 5337.524*$eoc;
753
+                    $g532 = -853.666 + 4690.25*$eq - 8624.77*
754
+                        $sat->deep_arg->eosq + 5341.4*$eoc;
755 755
                 }
756 756
                 else {
757
-                    $g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758
-                        $sat->deep_arg->eosq + 109377.94 * $eoc;
759
-                    $g521 = -51752.104 + 218913.95 * $eq - 309468.16*
760
-                        $sat->deep_arg->eosq + 146349.42 * $eoc;
761
-                    $g532 = -40023.88 + 170470.89 * $eq - 242699.48*
762
-                        $sat->deep_arg->eosq + 115605.82 * $eoc;
757
+                    $g533 = -37995.78 + 161616.52*$eq - 229838.2*
758
+                        $sat->deep_arg->eosq + 109377.94*$eoc;
759
+                    $g521 = -51752.104 + 218913.95*$eq - 309468.16*
760
+                        $sat->deep_arg->eosq + 146349.42*$eoc;
761
+                    $g532 = -40023.88 + 170470.89*$eq - 242699.48*
762
+                        $sat->deep_arg->eosq + 115605.82*$eoc;
763 763
                 } /* End if (eq <= 0.7) */
764 764
 
765
-                $sini2 = $sat->deep_arg->sinio * $sat->deep_arg->sinio;
766
-                $f220 = 0.75 * (1 + 2 * $sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
-                $f221 = 1.5 * $sini2;
768
-                $f321 = 1.875 * $sat->deep_arg->sinio * (1 - 2 *
769
-                                  $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
770
-                $f322 = -1.875 * $sat->deep_arg->sinio * (1 + 2*
771
-                                   $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2);
772
-                $f441 = 35 * $sini2 * $f220;
773
-                $f442 = 39.3750 * $sini2 * $sini2;
774
-                $f522 = 9.84375 * $sat->deep_arg->sinio * ($sini2 * (1 - 2 * $sat->deep_arg->cosio - 5 *
775
-                                       $sat->deep_arg->theta2) + 0.33333333 * (-2 + 4 * $sat->deep_arg->cosio +
776
-                                                     6 * $sat->deep_arg->theta2));
777
-                $f523 = $sat->deep_arg->sinio * (4.92187512 * $sini2 * (-2 - 4 *
778
-                                      $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2) + 6.56250012
779
-                            * (1 + 2 * $sat->deep_arg->cosio - 3 * $sat->deep_arg->theta2));
780
-                $f542 = 29.53125 * $sat->deep_arg->sinio * (2 - 8 *
781
-                                 $sat->deep_arg->cosio + $sat->deep_arg->theta2 *
782
-                                 (-12 + 8 * $sat->deep_arg->cosio + 10 * $sat->deep_arg->theta2));
783
-                $f543 = 29.53125 * $sat->deep_arg->sinio * (-2 - 8 * $sat->deep_arg->cosio +
784
-                                 $sat->deep_arg->theta2 * (12 + 8 * $sat->deep_arg->cosio - 10 *
765
+                $sini2 = $sat->deep_arg->sinio*$sat->deep_arg->sinio;
766
+                $f220 = 0.75*(1 + 2*$sat->deep_arg->cosio + $sat->deep_arg->theta2);
767
+                $f221 = 1.5*$sini2;
768
+                $f321 = 1.875*$sat->deep_arg->sinio*(1 - 2*
769
+                                  $sat->deep_arg->cosio - 3*$sat->deep_arg->theta2);
770
+                $f322 = -1.875*$sat->deep_arg->sinio*(1 + 2*
771
+                                   $sat->deep_arg->cosio - 3*$sat->deep_arg->theta2);
772
+                $f441 = 35*$sini2*$f220;
773
+                $f442 = 39.3750*$sini2*$sini2;
774
+                $f522 = 9.84375*$sat->deep_arg->sinio*($sini2*(1 - 2*$sat->deep_arg->cosio - 5*
775
+                                       $sat->deep_arg->theta2) + 0.33333333*(-2 + 4*$sat->deep_arg->cosio +
776
+                                                     6*$sat->deep_arg->theta2));
777
+                $f523 = $sat->deep_arg->sinio*(4.92187512*$sini2*(-2 - 4*
778
+                                      $sat->deep_arg->cosio + 10*$sat->deep_arg->theta2) + 6.56250012
779
+                            * (1 + 2*$sat->deep_arg->cosio - 3*$sat->deep_arg->theta2));
780
+                $f542 = 29.53125*$sat->deep_arg->sinio*(2 - 8*
781
+                                 $sat->deep_arg->cosio + $sat->deep_arg->theta2*
782
+                                 (-12 + 8*$sat->deep_arg->cosio + 10*$sat->deep_arg->theta2));
783
+                $f543 = 29.53125*$sat->deep_arg->sinio*(-2 - 8*$sat->deep_arg->cosio +
784
+                                 $sat->deep_arg->theta2*(12 + 8*$sat->deep_arg->cosio - 10*
785 785
                                            $sat->deep_arg->theta2));
786
-                $xno2 = $sat->dps->xnq * $sat->dps->xnq;
787
-                $ainv2 = $aqnv * $aqnv;
788
-                $temp1 = 3 * $xno2 * $ainv2;
789
-                $temp = $temp1 * Predict::root22;
790
-                $sat->dps->d2201 = $temp * $f220 * $g201;
791
-                $sat->dps->d2211 = $temp * $f221 * $g211;
792
-                $temp1 = $temp1 * $aqnv;
793
-                $temp = $temp1 * Predict::root32;
794
-                $sat->dps->d3210 = $temp * $f321 * $g310;
795
-                $sat->dps->d3222 = $temp * $f322 * $g322;
796
-                $temp1 = $temp1 * $aqnv;
797
-                $temp = 2 * $temp1 * Predict::root44;
798
-                $sat->dps->d4410 = $temp * $f441 * $g410;
799
-                $sat->dps->d4422 = $temp * $f442 * $g422;
800
-                $temp1 = $temp1 * $aqnv;
801
-                $temp = $temp1 * Predict::root52;
802
-                $sat->dps->d5220 = $temp * $f522 * $g520;
803
-                $sat->dps->d5232 = $temp * $f523 * $g532;
804
-                $temp = 2 * $temp1 * Predict::root54;
805
-                $sat->dps->d5421 = $temp * $f542 * $g521;
806
-                $sat->dps->d5433 = $temp * $f543 * $g533;
786
+                $xno2 = $sat->dps->xnq*$sat->dps->xnq;
787
+                $ainv2 = $aqnv*$aqnv;
788
+                $temp1 = 3*$xno2*$ainv2;
789
+                $temp = $temp1*Predict::root22;
790
+                $sat->dps->d2201 = $temp*$f220*$g201;
791
+                $sat->dps->d2211 = $temp*$f221*$g211;
792
+                $temp1 = $temp1*$aqnv;
793
+                $temp = $temp1*Predict::root32;
794
+                $sat->dps->d3210 = $temp*$f321*$g310;
795
+                $sat->dps->d3222 = $temp*$f322*$g322;
796
+                $temp1 = $temp1*$aqnv;
797
+                $temp = 2*$temp1*Predict::root44;
798
+                $sat->dps->d4410 = $temp*$f441*$g410;
799
+                $sat->dps->d4422 = $temp*$f442*$g422;
800
+                $temp1 = $temp1*$aqnv;
801
+                $temp = $temp1*Predict::root52;
802
+                $sat->dps->d5220 = $temp*$f522*$g520;
803
+                $sat->dps->d5232 = $temp*$f523*$g532;
804
+                $temp = 2*$temp1*Predict::root54;
805
+                $sat->dps->d5421 = $temp*$f542*$g521;
806
+                $sat->dps->d5433 = $temp*$f543*$g533;
807 807
                 $sat->dps->xlamo = $xmao + $sat->tle->xnodeo + $sat->tle->xnodeo - $sat->dps->thgr - $sat->dps->thgr;
808 808
                 $bfact = $sat->deep_arg->xmdot + $sat->deep_arg->xnodot +
809 809
                     $sat->deep_arg->xnodot - Predict::thdt - Predict::thdt;
@@ -812,18 +812,18 @@  discard block
 block discarded – undo
812 812
                 $sat->flags |= self::RESONANCE_FLAG;
813 813
                 $sat->flags |= self::SYNCHRONOUS_FLAG;
814 814
                 /* Synchronous resonance terms initialization */
815
-                $g200 = 1 + $sat->deep_arg->eosq * (-2.5 + 0.8125 * $sat->deep_arg->eosq);
816
-                $g310 = 1 + 2 * $sat->deep_arg->eosq;
817
-                $g300 = 1 + $sat->deep_arg->eosq * (-6 + 6.60937 * $sat->deep_arg->eosq);
818
-                $f220 = 0.75 * (1 + $sat->deep_arg->cosio) * (1 + $sat->deep_arg->cosio);
819
-                $f311 = 0.9375 * $sat->deep_arg->sinio * $sat->deep_arg->sinio *
820
-                    (1 + 3 * $sat->deep_arg->cosio) - 0.75 * (1 + $sat->deep_arg->cosio);
815
+                $g200 = 1 + $sat->deep_arg->eosq*(-2.5 + 0.8125*$sat->deep_arg->eosq);
816
+                $g310 = 1 + 2*$sat->deep_arg->eosq;
817
+                $g300 = 1 + $sat->deep_arg->eosq*(-6 + 6.60937*$sat->deep_arg->eosq);
818
+                $f220 = 0.75*(1 + $sat->deep_arg->cosio)*(1 + $sat->deep_arg->cosio);
819
+                $f311 = 0.9375*$sat->deep_arg->sinio*$sat->deep_arg->sinio*
820
+                    (1 + 3*$sat->deep_arg->cosio) - 0.75*(1 + $sat->deep_arg->cosio);
821 821
                 $f330 = 1 + $sat->deep_arg->cosio;
822
-                $f330 = 1.875 * $f330 * $f330 * $f330;
823
-                $sat->dps->del1 = 3 * $sat->dps->xnq * $sat->dps->xnq * $aqnv * $aqnv;
824
-                $sat->dps->del2 = 2 * $sat->dps->del1 * $f220 * $g200 * Predict::q22;
825
-                $sat->dps->del3 = 3 * $sat->dps->del1 * $f330 * $g300 * Predict::q33 * $aqnv;
826
-                $sat->dps->del1 = $sat->dps->del1 * $f311 * $g310 * Predict::q31 * $aqnv;
822
+                $f330 = 1.875*$f330*$f330*$f330;
823
+                $sat->dps->del1 = 3*$sat->dps->xnq*$sat->dps->xnq*$aqnv*$aqnv;
824
+                $sat->dps->del2 = 2*$sat->dps->del1*$f220*$g200*Predict::q22;
825
+                $sat->dps->del3 = 3*$sat->dps->del1*$f330*$g300*Predict::q33*$aqnv;
826
+                $sat->dps->del1 = $sat->dps->del1*$f311*$g310*Predict::q31*$aqnv;
827 827
                 $sat->dps->fasx2 = 0.13130908;
828 828
                 $sat->dps->fasx4 = 2.8843198;
829 829
                 $sat->dps->fasx6 = 0.37448087;
@@ -845,24 +845,24 @@  discard block
 block discarded – undo
845 845
             return;
846 846
 
847 847
         case self::dpsec: /* Entrance for deep space secular effects */
848
-            $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl * $sat->deep_arg->t;
849
-            $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg * $sat->deep_arg->t;
850
-            $sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh * $sat->deep_arg->t;
851
-            $sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse * $sat->deep_arg->t;
852
-            $sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi * $sat->deep_arg->t;
848
+            $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->ssl*$sat->deep_arg->t;
849
+            $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $sat->dps->ssg*$sat->deep_arg->t;
850
+            $sat->deep_arg->xnode = $sat->deep_arg->xnode + $sat->dps->ssh*$sat->deep_arg->t;
851
+            $sat->deep_arg->em = $sat->tle->eo + $sat->dps->sse*$sat->deep_arg->t;
852
+            $sat->deep_arg->xinc = $sat->tle->xincl + $sat->dps->ssi*$sat->deep_arg->t;
853 853
             if ($sat->deep_arg->xinc < 0) {
854 854
                 $sat->deep_arg->xinc = -$sat->deep_arg->xinc;
855 855
                 $sat->deep_arg->xnode = $sat->deep_arg->xnode + Predict::pi;
856 856
                 $sat->deep_arg->omgadf = $sat->deep_arg->omgadf - Predict::pi;
857 857
             }
858
-            if(~$sat->flags & self::RESONANCE_FLAG ) {
858
+            if (~$sat->flags&self::RESONANCE_FLAG) {
859 859
                 return;
860 860
             }
861 861
 
862 862
             do {
863
-                if ( ($sat->dps->atime == 0) ||
863
+                if (($sat->dps->atime == 0) ||
864 864
                     (($sat->deep_arg->t >= 0) && ($sat->dps->atime < 0)) ||
865
-                    (($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0)) ) {
865
+                    (($sat->deep_arg->t < 0) && ($sat->dps->atime >= 0))) {
866 866
                     /* Epoch restart */
867 867
                     if ($sat->deep_arg->t >= 0) {
868 868
                         $delt = $sat->dps->stepp;
@@ -899,59 +899,59 @@  discard block
 block discarded – undo
899 899
                         } else {
900 900
                             $delt = $sat->dps->stepp;
901 901
                         }
902
-                        $sat->flags |= (self::DO_LOOP_FLAG | self::EPOCH_RESTART_FLAG);
902
+                        $sat->flags |= (self::DO_LOOP_FLAG|self::EPOCH_RESTART_FLAG);
903 903
                     }
904 904
 
905 905
                     /* Dot terms calculated */
906
-                    if ($sat->flags & self::SYNCHRONOUS_FLAG) {
907
-                        $xndot = $sat->dps->del1 * sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2 * sin(2 * ($sat->dps->xli - $sat->dps->fasx4))
908
-                            + $sat->dps->del3 * sin(3 * ($sat->dps->xli - $sat->dps->fasx6));
909
-                        $xnddt = $sat->dps->del1 * cos($sat->dps->xli - $sat->dps->fasx2) + 2 * $sat->dps->del2 * cos(2 * ($sat->dps->xli - $sat->dps->fasx4))
910
-                            + 3 * $sat->dps->del3 * cos(3 * ($sat->dps->xli - $sat->dps->fasx6));
906
+                    if ($sat->flags&self::SYNCHRONOUS_FLAG) {
907
+                        $xndot = $sat->dps->del1*sin($sat->dps->xli - $sat->dps->fasx2) + $sat->dps->del2*sin(2*($sat->dps->xli - $sat->dps->fasx4))
908
+                            + $sat->dps->del3*sin(3*($sat->dps->xli - $sat->dps->fasx6));
909
+                        $xnddt = $sat->dps->del1*cos($sat->dps->xli - $sat->dps->fasx2) + 2*$sat->dps->del2*cos(2*($sat->dps->xli - $sat->dps->fasx4))
910
+                            + 3*$sat->dps->del3*cos(3*($sat->dps->xli - $sat->dps->fasx6));
911 911
                     } else {
912
-                        $xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot * $sat->dps->atime;
912
+                        $xomi = $sat->dps->omegaq + $sat->deep_arg->omgdot*$sat->dps->atime;
913 913
                         $x2omi = $xomi + $xomi;
914 914
                         $x2li = $sat->dps->xli + $sat->dps->xli;
915
-                        $xndot = $sat->dps->d2201 * sin($x2omi + $sat->dps->xli - Predict::g22)
916
-                            + $sat->dps->d2211 * sin($sat->dps->xli - Predict::g22)
917
-                            + $sat->dps->d3210 * sin($xomi + $sat->dps->xli - Predict::g32)
918
-                            + $sat->dps->d3222 * sin(-$xomi + $sat->dps->xli - Predict::g32)
919
-                            + $sat->dps->d4410 * sin($x2omi + $x2li- Predict::g44)
920
-                            + $sat->dps->d4422 * sin($x2li- Predict::g44)
921
-                            + $sat->dps->d5220 * sin($xomi + $sat->dps->xli- Predict::g52)
922
-                            + $sat->dps->d5232 * sin(-$xomi + $sat->dps->xli- Predict::g52)
923
-                            + $sat->dps->d5421 * sin($xomi + $x2li - Predict::g54)
924
-                            + $sat->dps->d5433 * sin(-$xomi + $x2li - Predict::g54);
925
-                        $xnddt = $sat->dps->d2201 * cos($x2omi + $sat->dps->xli- Predict::g22)
926
-                            + $sat->dps->d2211 * cos($sat->dps->xli - Predict::g22)
927
-                            + $sat->dps->d3210 * cos($xomi + $sat->dps->xli - Predict::g32)
928
-                            + $sat->dps->d3222 * cos(-$xomi + $sat->dps->xli - Predict::g32)
929
-                            + $sat->dps->d5220 * cos($xomi + $sat->dps->xli - Predict::g52)
930
-                            + $sat->dps->d5232 * cos(-$xomi + $sat->dps->xli - Predict::g52)
931
-                            + 2 * ($sat->dps->d4410 * cos($x2omi + $x2li - Predict::g44)
932
-                                + $sat->dps->d4422 * cos($x2li - Predict::g44)
933
-                                + $sat->dps->d5421 * cos($xomi + $x2li - Predict::g54)
934
-                                + $sat->dps->d5433 * cos(-$xomi + $x2li - Predict::g54));
915
+                        $xndot = $sat->dps->d2201*sin($x2omi + $sat->dps->xli - Predict::g22)
916
+                            + $sat->dps->d2211*sin($sat->dps->xli - Predict::g22)
917
+                            + $sat->dps->d3210*sin($xomi + $sat->dps->xli - Predict::g32)
918
+                            + $sat->dps->d3222*sin(-$xomi + $sat->dps->xli - Predict::g32)
919
+                            + $sat->dps->d4410*sin($x2omi + $x2li - Predict::g44)
920
+                            + $sat->dps->d4422*sin($x2li - Predict::g44)
921
+                            + $sat->dps->d5220*sin($xomi + $sat->dps->xli - Predict::g52)
922
+                            + $sat->dps->d5232*sin(-$xomi + $sat->dps->xli - Predict::g52)
923
+                            + $sat->dps->d5421*sin($xomi + $x2li - Predict::g54)
924
+                            + $sat->dps->d5433*sin(-$xomi + $x2li - Predict::g54);
925
+                        $xnddt = $sat->dps->d2201*cos($x2omi + $sat->dps->xli - Predict::g22)
926
+                            + $sat->dps->d2211*cos($sat->dps->xli - Predict::g22)
927
+                            + $sat->dps->d3210*cos($xomi + $sat->dps->xli - Predict::g32)
928
+                            + $sat->dps->d3222*cos(-$xomi + $sat->dps->xli - Predict::g32)
929
+                            + $sat->dps->d5220*cos($xomi + $sat->dps->xli - Predict::g52)
930
+                            + $sat->dps->d5232*cos(-$xomi + $sat->dps->xli - Predict::g52)
931
+                            + 2*($sat->dps->d4410*cos($x2omi + $x2li - Predict::g44)
932
+                                + $sat->dps->d4422*cos($x2li - Predict::g44)
933
+                                + $sat->dps->d5421*cos($xomi + $x2li - Predict::g54)
934
+                                + $sat->dps->d5433*cos(-$xomi + $x2li - Predict::g54));
935 935
                     } /* End of if (isFlagSet(SYNCHRONOUS_FLAG)) */
936 936
 
937 937
                     $xldot = $sat->dps->xni + $sat->dps->xfact;
938
-                    $xnddt = $xnddt * $xldot;
938
+                    $xnddt = $xnddt*$xldot;
939 939
 
940
-                    if ($sat->flags & self::DO_LOOP_FLAG) {
941
-                        $sat->dps->xli = $sat->dps->xli + $xldot * $delt + $xndot * $sat->dps->step2;
942
-                        $sat->dps->xni = $sat->dps->xni + $xndot * $delt + $xnddt * $sat->dps->step2;
940
+                    if ($sat->flags&self::DO_LOOP_FLAG) {
941
+                        $sat->dps->xli = $sat->dps->xli + $xldot*$delt + $xndot*$sat->dps->step2;
942
+                        $sat->dps->xni = $sat->dps->xni + $xndot*$delt + $xnddt*$sat->dps->step2;
943 943
                         $sat->dps->atime = $sat->dps->atime + $delt;
944 944
                     }
945
-                } while (($sat->flags & self::DO_LOOP_FLAG) &&
946
-                        (~$sat->flags & self::EPOCH_RESTART_FLAG));
945
+                } while (($sat->flags&self::DO_LOOP_FLAG) &&
946
+                        (~$sat->flags&self::EPOCH_RESTART_FLAG));
947 947
             }
948
-            while (($sat->flags & self::DO_LOOP_FLAG) && ($sat->flags & self::EPOCH_RESTART_FLAG));
948
+            while (($sat->flags&self::DO_LOOP_FLAG) && ($sat->flags&self::EPOCH_RESTART_FLAG));
949 949
 
950
-            $sat->deep_arg->xn = $sat->dps->xni + $xndot * $ft + $xnddt * $ft * $ft * 0.5;
951
-            $xl = $sat->dps->xli + $xldot * $ft + $xndot * $ft * $ft * 0.5;
952
-            $temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t * Predict::thdt;
950
+            $sat->deep_arg->xn = $sat->dps->xni + $xndot*$ft + $xnddt*$ft*$ft*0.5;
951
+            $xl = $sat->dps->xli + $xldot*$ft + $xndot*$ft*$ft*0.5;
952
+            $temp = -$sat->deep_arg->xnode + $sat->dps->thgr + $sat->deep_arg->t*Predict::thdt;
953 953
 
954
-            if (~$sat->flags & self::SYNCHRONOUS_FLAG) {
954
+            if (~$sat->flags&self::SYNCHRONOUS_FLAG) {
955 955
                 $sat->deep_arg->xll = $xl + $temp + $temp;
956 956
             } else {
957 957
                 $sat->deep_arg->xll = $xl - $sat->deep_arg->omgadf + $temp;
@@ -965,26 +965,26 @@  discard block
 block discarded – undo
965 965
             $cosis = cos($sat->deep_arg->xinc);
966 966
             if (abs($sat->dps->savtsn - $sat->deep_arg->t) >= 30) {
967 967
                 $sat->dps->savtsn = $sat->deep_arg->t;
968
-                $zm = $sat->dps->zmos + Predict::zns * $sat->deep_arg->t;
969
-                $zf = $zm + 2 * Predict::zes * sin($zm);
968
+                $zm = $sat->dps->zmos + Predict::zns*$sat->deep_arg->t;
969
+                $zf = $zm + 2*Predict::zes*sin($zm);
970 970
                 $sinzf = sin($zf);
971
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
972
-                $f3 = -0.5 * $sinzf * cos($zf);
973
-                $ses = $sat->dps->se2 * $f2 + $sat->dps->se3 * $f3;
974
-                $sis = $sat->dps->si2 * $f2 + $sat->dps->si3 * $f3;
975
-                $sls = $sat->dps->sl2 * $f2 + $sat->dps->sl3 * $f3 + $sat->dps->sl4 * $sinzf;
976
-                $sat->dps->sghs = $sat->dps->sgh2 * $f2 + $sat->dps->sgh3 * $f3 + $sat->dps->sgh4 * $sinzf;
977
-                $sat->dps->shs = $sat->dps->sh2 * $f2 + $sat->dps->sh3 * $f3;
978
-                $zm = $sat->dps->zmol + Predict::znl * $sat->deep_arg->t;
979
-                $zf = $zm + 2 * Predict::zel * sin($zm);
971
+                $f2 = 0.5*$sinzf*$sinzf - 0.25;
972
+                $f3 = -0.5*$sinzf*cos($zf);
973
+                $ses = $sat->dps->se2*$f2 + $sat->dps->se3*$f3;
974
+                $sis = $sat->dps->si2*$f2 + $sat->dps->si3*$f3;
975
+                $sls = $sat->dps->sl2*$f2 + $sat->dps->sl3*$f3 + $sat->dps->sl4*$sinzf;
976
+                $sat->dps->sghs = $sat->dps->sgh2*$f2 + $sat->dps->sgh3*$f3 + $sat->dps->sgh4*$sinzf;
977
+                $sat->dps->shs = $sat->dps->sh2*$f2 + $sat->dps->sh3*$f3;
978
+                $zm = $sat->dps->zmol + Predict::znl*$sat->deep_arg->t;
979
+                $zf = $zm + 2*Predict::zel*sin($zm);
980 980
                 $sinzf = sin($zf);
981
-                $f2 = 0.5 * $sinzf * $sinzf - 0.25;
982
-                $f3 = -0.5 * $sinzf * cos($zf);
983
-                $sel = $sat->dps->ee2 * $f2 + $sat->dps->e3 * $f3;
984
-                $sil = $sat->dps->xi2 * $f2 + $sat->dps->xi3 * $f3;
985
-                $sll = $sat->dps->xl2 * $f2 + $sat->dps->xl3 * $f3 + $sat->dps->xl4 * $sinzf;
986
-                $sat->dps->sghl = $sat->dps->xgh2 * $f2 + $sat->dps->xgh3 * $f3 + $sat->dps->xgh4 * $sinzf;
987
-                $sat->dps->sh1 = $sat->dps->xh2 * $f2 + $sat->dps->xh3 * $f3;
981
+                $f2 = 0.5*$sinzf*$sinzf - 0.25;
982
+                $f3 = -0.5*$sinzf*cos($zf);
983
+                $sel = $sat->dps->ee2*$f2 + $sat->dps->e3*$f3;
984
+                $sil = $sat->dps->xi2*$f2 + $sat->dps->xi3*$f3;
985
+                $sll = $sat->dps->xl2*$f2 + $sat->dps->xl3*$f3 + $sat->dps->xl4*$sinzf;
986
+                $sat->dps->sghl = $sat->dps->xgh2*$f2 + $sat->dps->xgh3*$f3 + $sat->dps->xgh4*$sinzf;
987
+                $sat->dps->sh1 = $sat->dps->xh2*$f2 + $sat->dps->xh3*$f3;
988 988
                 $sat->dps->pe = $ses + $sel;
989 989
                 $sat->dps->pinc = $sis + $sil;
990 990
                 $sat->dps->pl = $sls + $sll;
@@ -997,8 +997,8 @@  discard block
 block discarded – undo
997 997
 
998 998
             if ($sat->dps->xqncl >= 0.2) {
999 999
                 /* Apply periodics directly */
1000
-                $ph = $ph / $sat->deep_arg->sinio;
1001
-                $pgh = $pgh - $sat->deep_arg->cosio * $ph;
1000
+                $ph = $ph/$sat->deep_arg->sinio;
1001
+                $pgh = $pgh - $sat->deep_arg->cosio*$ph;
1002 1002
                 $sat->deep_arg->omgadf = $sat->deep_arg->omgadf + $pgh;
1003 1003
                 $sat->deep_arg->xnode = $sat->deep_arg->xnode + $ph;
1004 1004
                 $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
@@ -1006,22 +1006,22 @@  discard block
 block discarded – undo
1006 1006
                 /* Apply periodics with Lyddane modification */
1007 1007
                 $sinok = sin($sat->deep_arg->xnode);
1008 1008
                 $cosok = cos($sat->deep_arg->xnode);
1009
-                $alfdp = $sinis * $sinok;
1010
-                $betdp = $sinis * $cosok;
1011
-                $dalf = $ph * $cosok + $sat->dps->pinc * $cosis * $sinok;
1012
-                $dbet = -$ph * $sinok + $sat->dps->pinc * $cosis * $cosok;
1009
+                $alfdp = $sinis*$sinok;
1010
+                $betdp = $sinis*$cosok;
1011
+                $dalf = $ph*$cosok + $sat->dps->pinc*$cosis*$sinok;
1012
+                $dbet = -$ph*$sinok + $sat->dps->pinc*$cosis*$cosok;
1013 1013
                 $alfdp = $alfdp + $dalf;
1014 1014
                 $betdp = $betdp + $dbet;
1015 1015
                 $sat->deep_arg->xnode = Predict_Math::FMod2p($sat->deep_arg->xnode);
1016
-                $xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis * $sat->deep_arg->xnode;
1017
-                $dls = $sat->dps->pl + $pgh - $sat->dps->pinc * $sat->deep_arg->xnode * $sinis;
1016
+                $xls = $sat->deep_arg->xll + $sat->deep_arg->omgadf + $cosis*$sat->deep_arg->xnode;
1017
+                $dls = $sat->dps->pl + $pgh - $sat->dps->pinc*$sat->deep_arg->xnode*$sinis;
1018 1018
                 $xls = $xls + $dls;
1019 1019
                 $xnoh = $sat->deep_arg->xnode;
1020 1020
                 $sat->deep_arg->xnode = Predict_Math::AcTan($alfdp, $betdp);
1021 1021
 
1022 1022
                 /* This is a patch to Lyddane modification */
1023 1023
                 /* suggested by Rob Matson. */
1024
-                if(abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1024
+                if (abs($xnoh - $sat->deep_arg->xnode) > Predict::pi) {
1025 1025
                     if ($sat->deep_arg->xnode < $xnoh) {
1026 1026
                         $sat->deep_arg->xnode += Predict::twopi;
1027 1027
                     } else {
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
                 }
1031 1031
 
1032 1032
                 $sat->deep_arg->xll = $sat->deep_arg->xll + $sat->dps->pl;
1033
-                $sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc) *
1033
+                $sat->deep_arg->omgadf = $xls - $sat->deep_arg->xll - cos($sat->deep_arg->xinc)*
1034 1034
                     $sat->deep_arg->xnode;
1035 1035
             } /* End case dpper: */
1036 1036
             return;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -752,8 +752,7 @@  discard block
 block discarded – undo
752 752
                         $sat->deep_arg->eosq + 5337.524 * $eoc;
753 753
                     $g532 = -853.666 + 4690.25 * $eq - 8624.77 *
754 754
                         $sat->deep_arg->eosq + 5341.4 * $eoc;
755
-                }
756
-                else {
755
+                } else {
757 756
                     $g533 = -37995.78 + 161616.52 * $eq - 229838.2*
758 757
                         $sat->deep_arg->eosq + 109377.94 * $eoc;
759 758
                     $g521 = -51752.104 + 218913.95 * $eq - 309468.16*
@@ -887,8 +886,7 @@  discard block
 block discarded – undo
887 886
                     if (abs($sat->deep_arg->t - $sat->dps->atime) >= $sat->dps->stepp) {
888 887
                         $sat->flags |= self::DO_LOOP_FLAG;
889 888
                         $sat->flags &= ~self::EPOCH_RESTART_FLAG;
890
-                    }
891
-                    else {
889
+                    } else {
892 890
                         $ft = $sat->deep_arg->t - $sat->dps->atime;
893 891
                         $sat->flags &= ~self::DO_LOOP_FLAG;
894 892
                     }
Please login to merge, or discard this patch.