Completed
Push — master ( 4c247d...ce17c6 )
by Yannick
07:53
created
require/class.SpotterLive.php 1 patch
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 	}
129 129
 
130 130
 	/**
131
-	* Gets all the spotter information based on the latest data entry
132
-	*
133
-	* @return Array the spotter information
134
-	*
135
-	*/
131
+	 * Gets all the spotter information based on the latest data entry
132
+	 *
133
+	 * @return Array the spotter information
134
+	 *
135
+	 */
136 136
 	public function getLiveSpotterData($limit = '', $sort = '', $filter = array())
137 137
 	{
138 138
 		global $globalDBdriver, $globalLiveInterval;
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	}
175 175
 
176 176
 	/**
177
-	* Gets Minimal Live Spotter data
178
-	*
179
-	* @return Array the spotter information
180
-	*
181
-	*/
177
+	 * Gets Minimal Live Spotter data
178
+	 *
179
+	 * @return Array the spotter information
180
+	 *
181
+	 */
182 182
 	public function getMinLiveSpotterData($filter = array())
183 183
 	{
184 184
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
 	}
216 216
 
217 217
 	/**
218
-	* Gets Minimal Live Spotter data since xx seconds
219
-	*
220
-	* @return Array the spotter information
221
-	*
222
-	*/
218
+	 * Gets Minimal Live Spotter data since xx seconds
219
+	 *
220
+	 * @return Array the spotter information
221
+	 *
222
+	 */
223 223
 	public function getMinLastLiveSpotterData($filter = array())
224 224
 	{
225 225
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
239 239
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
240 240
 			}
241
-                } else {
241
+				} else {
242 242
 			if (isset($globalArchive) && $globalArchive === TRUE) {
243 243
 				$query  = "SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source 
244 244
 				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 			}
251 251
 		}
252 252
 
253
-    		try {
253
+			try {
254 254
 			$sth = $this->db->prepare($query);
255 255
 			$sth->execute();
256 256
 		} catch(PDOException $e) {
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 	}
263 263
 
264 264
 	/**
265
-	* Gets number of latest data entry
266
-	*
267
-	* @return String number of entry
268
-	*
269
-	*/
265
+	 * Gets number of latest data entry
266
+	 *
267
+	 * @return String number of entry
268
+	 *
269
+	 */
270 270
 	public function getLiveSpotterCount($filter = array())
271 271
 	{
272 272
 		global $globalDBdriver, $globalLiveInterval;
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
 	}
294 294
 
295 295
 	/**
296
-	* Gets all the spotter information based on the latest data entry and coord
297
-	*
298
-	* @return Array the spotter information
299
-	*
300
-	*/
296
+	 * Gets all the spotter information based on the latest data entry and coord
297
+	 *
298
+	 * @return Array the spotter information
299
+	 *
300
+	 */
301 301
 	public function getLiveSpotterDatabyCoord($coord, $filter = array())
302 302
 	{
303 303
 		global $globalDBdriver, $globalLiveInterval;
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	}
323 323
 
324 324
 	/**
325
-	* Gets all the spotter information based on the latest data entry and coord
326
-	*
327
-	* @return Array the spotter information
328
-	*
329
-	*/
325
+	 * Gets all the spotter information based on the latest data entry and coord
326
+	 *
327
+	 * @return Array the spotter information
328
+	 *
329
+	 */
330 330
 	public function getMinLiveSpotterDatabyCoord($coord, $filter = array())
331 331
 	{
332 332
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	}
392 392
 
393 393
 	/**
394
-	* Gets all the spotter information based on a user's latitude and longitude
395
-	*
396
-	* @return Array the spotter information
397
-	*
398
-	*/
394
+	 * Gets all the spotter information based on a user's latitude and longitude
395
+	 *
396
+	 * @return Array the spotter information
397
+	 *
398
+	 */
399 399
 	public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
400 400
 	{
401 401
 		$Spotter = new Spotter($this->db);
@@ -405,145 +405,145 @@  discard block
 block discarded – undo
405 405
 				return false;
406 406
 			}
407 407
 		}
408
-        if ($lng != '')
409
-                {
410
-                        if (!is_numeric($lng))
411
-                        {
412
-                                return false;
413
-                        }
414
-                }
415
-
416
-                if ($radius != '')
417
-                {
418
-                        if (!is_numeric($radius))
419
-                        {
420
-                                return false;
421
-                        }
422
-                }
408
+		if ($lng != '')
409
+				{
410
+						if (!is_numeric($lng))
411
+						{
412
+								return false;
413
+						}
414
+				}
415
+
416
+				if ($radius != '')
417
+				{
418
+						if (!is_numeric($radius))
419
+						{
420
+								return false;
421
+						}
422
+				}
423 423
 		$additional_query = '';
424
-        if ($interval != '')
425
-                {
426
-                        if (!is_string($interval))
427
-                        {
428
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
429
-			        return false;
430
-                        } else {
431
-                if ($interval == '1m')
432
-                {
433
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
434
-                } else if ($interval == '15m'){
435
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
436
-                } 
437
-            }
438
-                } else {
439
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
440
-        }
441
-
442
-                $query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
424
+		if ($interval != '')
425
+				{
426
+						if (!is_string($interval))
427
+						{
428
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
429
+					return false;
430
+						} else {
431
+				if ($interval == '1m')
432
+				{
433
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
434
+				} else if ($interval == '15m'){
435
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
436
+				} 
437
+			}
438
+				} else {
439
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
440
+		}
441
+
442
+				$query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
443 443
                    WHERE spotter_live.latitude <> '' 
444 444
                                    AND spotter_live.longitude <> '' 
445 445
                    ".$additional_query."
446 446
                    HAVING distance < :radius  
447 447
                                    ORDER BY distance";
448 448
 
449
-                $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
449
+				$spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
450 450
 
451
-                return $spotter_array;
452
-        }
451
+				return $spotter_array;
452
+		}
453 453
 
454 454
     
455
-        /**
456
-	* Gets all the spotter information based on a particular callsign
457
-	*
458
-	* @return Array the spotter information
459
-	*
460
-	*/
455
+		/**
456
+		 * Gets all the spotter information based on a particular callsign
457
+		 *
458
+		 * @return Array the spotter information
459
+		 *
460
+		 */
461 461
 	public function getLastLiveSpotterDataByIdent($ident)
462 462
 	{
463 463
 		$Spotter = new Spotter($this->db);
464 464
 		date_default_timezone_set('UTC');
465 465
 
466 466
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
467
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
467
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
468 468
 
469 469
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true);
470 470
 
471 471
 		return $spotter_array;
472 472
 	}
473 473
 
474
-        /**
475
-	* Gets all the spotter information based on a particular callsign
476
-	*
477
-	* @return Array the spotter information
478
-	*
479
-	*/
474
+		/**
475
+		 * Gets all the spotter information based on a particular callsign
476
+		 *
477
+		 * @return Array the spotter information
478
+		 *
479
+		 */
480 480
 	public function getDateLiveSpotterDataByIdent($ident,$date)
481 481
 	{
482 482
 		$Spotter = new Spotter($this->db);
483 483
 		date_default_timezone_set('UTC');
484 484
 
485 485
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
486
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
486
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
487 487
 
488
-                $date = date('c',$date);
488
+				$date = date('c',$date);
489 489
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
490 490
 
491 491
 		return $spotter_array;
492 492
 	}
493 493
 
494
-        /**
495
-	* Gets last spotter information based on a particular callsign
496
-	*
497
-	* @return Array the spotter information
498
-	*
499
-	*/
494
+		/**
495
+		 * Gets last spotter information based on a particular callsign
496
+		 *
497
+		 * @return Array the spotter information
498
+		 *
499
+		 */
500 500
 	public function getLastLiveSpotterDataById($id)
501 501
 	{
502 502
 		$Spotter = new Spotter($this->db);
503 503
 		date_default_timezone_set('UTC');
504 504
 
505 505
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
506
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
506
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
507 507
 
508 508
 		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true);
509 509
 
510 510
 		return $spotter_array;
511 511
 	}
512 512
 
513
-        /**
514
-	* Gets last spotter information based on a particular callsign
515
-	*
516
-	* @return Array the spotter information
517
-	*
518
-	*/
513
+		/**
514
+		 * Gets last spotter information based on a particular callsign
515
+		 *
516
+		 * @return Array the spotter information
517
+		 *
518
+		 */
519 519
 	public function getDateLiveSpotterDataById($id,$date)
520 520
 	{
521 521
 		$Spotter = new Spotter($this->db);
522 522
 		date_default_timezone_set('UTC');
523 523
 
524 524
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
525
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
526
-                $date = date('c',$date);
525
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
526
+				$date = date('c',$date);
527 527
 		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
528 528
 
529 529
 		return $spotter_array;
530 530
 	}
531 531
 
532
-        /**
533
-	* Gets altitude information based on a particular callsign
534
-	*
535
-	* @return Array the spotter information
536
-	*
537
-	*/
532
+		/**
533
+		 * Gets altitude information based on a particular callsign
534
+		 *
535
+		 * @return Array the spotter information
536
+		 *
537
+		 */
538 538
 	public function getAltitudeLiveSpotterDataByIdent($ident)
539 539
 	{
540 540
 
541 541
 		date_default_timezone_set('UTC');
542 542
 
543 543
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
544
-                $query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
544
+				$query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
545 545
 
546
-    		try {
546
+			try {
547 547
 			
548 548
 			$sth = $this->db->prepare($query);
549 549
 			$sth->execute(array(':ident' => $ident));
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
 		return $spotter_array;
557 557
 	}
558 558
 
559
-        /**
560
-	* Gets all the spotter information based on a particular id
561
-	*
562
-	* @return Array the spotter information
563
-	*
564
-	*/
559
+		/**
560
+		 * Gets all the spotter information based on a particular id
561
+		 *
562
+		 * @return Array the spotter information
563
+		 *
564
+		 */
565 565
 	public function getAllLiveSpotterDataById($id,$liveinterval = false)
566 566
 	{
567 567
 		global $globalDBdriver, $globalLiveInterval;
@@ -589,18 +589,18 @@  discard block
 block discarded – undo
589 589
 		return $spotter_array;
590 590
 	}
591 591
 
592
-        /**
593
-	* Gets all the spotter information based on a particular ident
594
-	*
595
-	* @return Array the spotter information
596
-	*
597
-	*/
592
+		/**
593
+		 * Gets all the spotter information based on a particular ident
594
+		 *
595
+		 * @return Array the spotter information
596
+		 *
597
+		 */
598 598
 	public function getAllLiveSpotterDataByIdent($ident)
599 599
 	{
600 600
 		date_default_timezone_set('UTC');
601 601
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
602 602
 		$query  = self::$global_query.' WHERE spotter_live.ident = :ident';
603
-    		try {
603
+			try {
604 604
 			
605 605
 			$sth = $this->db->prepare($query);
606 606
 			$sth->execute(array(':ident' => $ident));
@@ -614,23 +614,23 @@  discard block
 block discarded – undo
614 614
 
615 615
 
616 616
 	/**
617
-	* Deletes all info in the table
618
-	*
619
-	* @return String success or false
620
-	*
621
-	*/
617
+	 * Deletes all info in the table
618
+	 *
619
+	 * @return String success or false
620
+	 *
621
+	 */
622 622
 	public function deleteLiveSpotterData()
623 623
 	{
624 624
 		global $globalDBdriver;
625 625
 		if ($globalDBdriver == 'mysql') {
626 626
 			//$query  = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date";
627 627
 			$query  = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date';
628
-            		//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
628
+					//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
629 629
 		} else {
630 630
 			$query  = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date";
631 631
 		}
632 632
         
633
-    		try {
633
+			try {
634 634
 			
635 635
 			$sth = $this->db->prepare($query);
636 636
 			$sth->execute();
@@ -642,18 +642,18 @@  discard block
 block discarded – undo
642 642
 	}
643 643
 
644 644
 	/**
645
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
646
-	*
647
-	* @return String success or false
648
-	*
649
-	*/
645
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
646
+	 *
647
+	 * @return String success or false
648
+	 *
649
+	 */
650 650
 	public function deleteLiveSpotterDataNotUpdated()
651 651
 	{
652 652
 		global $globalDBdriver, $globalDebug;
653 653
 		if ($globalDBdriver == 'mysql') {
654 654
 			//$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0';
655
-    			$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0";
656
-    			try {
655
+				$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0";
656
+				try {
657 657
 				
658 658
 				$sth = $this->db->prepare($query);
659 659
 				$sth->execute();
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 				return "error";
662 662
 			}
663 663
 			$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
664
-                        $i = 0;
665
-                        $j =0;
664
+						$i = 0;
665
+						$j =0;
666 666
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
667 667
 			foreach($all as $row)
668 668
 			{
@@ -670,20 +670,20 @@  discard block
 block discarded – undo
670 670
 				$j++;
671 671
 				if ($j == 30) {
672 672
 					if ($globalDebug) echo ".";
673
-				    	try {
673
+						try {
674 674
 						
675 675
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
676 676
 						$sth->execute();
677 677
 					} catch(PDOException $e) {
678 678
 						return "error";
679 679
 					}
680
-                                	$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
681
-                                	$j = 0;
680
+									$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
681
+									$j = 0;
682 682
 				}
683 683
 				$query_delete .= "'".$row['flightaware_id']."',";
684 684
 			}
685 685
 			if ($i > 0) {
686
-    				try {
686
+					try {
687 687
 					
688 688
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
689 689
 					$sth->execute();
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 			return "success";
695 695
 		} elseif ($globalDBdriver == 'pgsql') {
696 696
 			//$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0";
697
-    			//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
698
-    			$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)";
699
-    			try {
697
+				//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
698
+				$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)";
699
+				try {
700 700
 				
701 701
 				$sth = $this->db->prepare($query);
702 702
 				$sth->execute();
@@ -740,17 +740,17 @@  discard block
 block discarded – undo
740 740
 	}
741 741
 
742 742
 	/**
743
-	* Deletes all info in the table for an ident
744
-	*
745
-	* @return String success or false
746
-	*
747
-	*/
743
+	 * Deletes all info in the table for an ident
744
+	 *
745
+	 * @return String success or false
746
+	 *
747
+	 */
748 748
 	public function deleteLiveSpotterDataByIdent($ident)
749 749
 	{
750 750
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
751 751
 		$query  = 'DELETE FROM spotter_live WHERE ident = :ident';
752 752
         
753
-    		try {
753
+			try {
754 754
 			
755 755
 			$sth = $this->db->prepare($query);
756 756
 			$sth->execute(array(':ident' => $ident));
@@ -762,17 +762,17 @@  discard block
 block discarded – undo
762 762
 	}
763 763
 
764 764
 	/**
765
-	* Deletes all info in the table for an id
766
-	*
767
-	* @return String success or false
768
-	*
769
-	*/
765
+	 * Deletes all info in the table for an id
766
+	 *
767
+	 * @return String success or false
768
+	 *
769
+	 */
770 770
 	public function deleteLiveSpotterDataById($id)
771 771
 	{
772 772
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
773 773
 		$query  = 'DELETE FROM spotter_live WHERE flightaware_id = :id';
774 774
         
775
-    		try {
775
+			try {
776 776
 			
777 777
 			$sth = $this->db->prepare($query);
778 778
 			$sth->execute(array(':id' => $id));
@@ -785,11 +785,11 @@  discard block
 block discarded – undo
785 785
 
786 786
 
787 787
 	/**
788
-	* Gets the aircraft ident within the last hour
789
-	*
790
-	* @return String the ident
791
-	*
792
-	*/
788
+	 * Gets the aircraft ident within the last hour
789
+	 *
790
+	 * @return String the ident
791
+	 *
792
+	 */
793 793
 	public function getIdentFromLastHour($ident)
794 794
 	{
795 795
 		global $globalDBdriver, $globalTimezone;
@@ -815,14 +815,14 @@  discard block
 block discarded – undo
815 815
 			$ident_result = $row['ident'];
816 816
 		}
817 817
 		return $ident_result;
818
-        }
818
+		}
819 819
 
820 820
 	/**
821
-	* Check recent aircraft
822
-	*
823
-	* @return String the ident
824
-	*
825
-	*/
821
+	 * Check recent aircraft
822
+	 *
823
+	 * @return String the ident
824
+	 *
825
+	 */
826 826
 	public function checkIdentRecent($ident)
827 827
 	{
828 828
 		global $globalDBdriver, $globalTimezone;
@@ -848,14 +848,14 @@  discard block
 block discarded – undo
848 848
 			$ident_result = $row['flightaware_id'];
849 849
 		}
850 850
 		return $ident_result;
851
-        }
851
+		}
852 852
 
853 853
 	/**
854
-	* Check recent aircraft by id
855
-	*
856
-	* @return String the ident
857
-	*
858
-	*/
854
+	 * Check recent aircraft by id
855
+	 *
856
+	 * @return String the ident
857
+	 *
858
+	 */
859 859
 	public function checkIdRecent($id)
860 860
 	{
861 861
 		global $globalDBdriver, $globalTimezone;
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
 			$ident_result = $row['flightaware_id'];
882 882
 		}
883 883
 		return $ident_result;
884
-        }
884
+		}
885 885
 
886 886
 	/**
887
-	* Check recent aircraft by ModeS
888
-	*
889
-	* @return String the ModeS
890
-	*
891
-	*/
887
+	 * Check recent aircraft by ModeS
888
+	 *
889
+	 * @return String the ModeS
890
+	 *
891
+	 */
892 892
 	public function checkModeSRecent($modes)
893 893
 	{
894 894
 		global $globalDBdriver, $globalTimezone;
@@ -915,19 +915,19 @@  discard block
 block discarded – undo
915 915
 			$ident_result = $row['flightaware_id'];
916 916
 		}
917 917
 		return $ident_result;
918
-        }
918
+		}
919 919
 
920 920
 	/**
921
-	* Adds a new spotter data
922
-	*
923
-	* @param String $flightaware_id the ID from flightaware
924
-	* @param String $ident the flight ident
925
-	* @param String $aircraft_icao the aircraft type
926
-	* @param String $departure_airport_icao the departure airport
927
-	* @param String $arrival_airport_icao the arrival airport
928
-	* @return String success or false
929
-	*
930
-	*/
921
+	 * Adds a new spotter data
922
+	 *
923
+	 * @param String $flightaware_id the ID from flightaware
924
+	 * @param String $ident the flight ident
925
+	 * @param String $aircraft_icao the aircraft type
926
+	 * @param String $departure_airport_icao the departure airport
927
+	 * @param String $arrival_airport_icao the arrival airport
928
+	 * @return String success or false
929
+	 *
930
+	 */
931 931
 	public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $altitude_real = '',$heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '')
932 932
 	{
933 933
 		global $globalURL, $globalArchive, $globalDebug;
@@ -1062,10 +1062,10 @@  discard block
 block discarded – undo
1062 1062
 		$arrival_airport_country = '';
1063 1063
 		
1064 1064
             	
1065
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1065
+				if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
+				if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1069 1069
 		
1070 1070
 		$query = '';
1071 1071
 		if ($globalArchive) {
@@ -1086,10 +1086,10 @@  discard block
 block discarded – undo
1086 1086
 			return "error : ".$e->getMessage();
1087 1087
 		}
1088 1088
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1089
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1090
-		    $SpotterArchive = new SpotterArchive($this->db);
1091
-		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
-		    if ($globalDebug) echo $result.')';
1089
+			if ($globalDebug) echo '(Add to SBS archive : ';
1090
+			$SpotterArchive = new SpotterArchive($this->db);
1091
+			$result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
+			if ($globalDebug) echo $result.')';
1093 1093
 		}
1094 1094
 		return "success";
1095 1095
 
Please login to merge, or discard this patch.