Completed
Push — master ( aba7aa...4c247d )
by Yannick
07:22
created
require/class.SpotterLive.php 1 patch
Braces   +80 added lines, -27 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -118,8 +120,11 @@  discard block
 block discarded – undo
118 120
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
119 121
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
120 122
 		}
121
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
122
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
123
+		if ($filter_query_where == '' && $where) {
124
+			$filter_query_where = ' WHERE';
125
+		} elseif ($filter_query_where != '' && $and) {
126
+			$filter_query_where .= ' AND';
127
+		}
123 128
 		if ($filter_query_where != '') {
124 129
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
125 130
 		}
@@ -161,7 +166,9 @@  discard block
 block discarded – undo
161 166
 			}
162 167
 		}
163 168
 
164
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
169
+		if (!isset($globalLiveInterval)) {
170
+			$globalLiveInterval = '200';
171
+		}
165 172
 		if ($globalDBdriver == 'mysql') {
166 173
 			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
167 174
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -184,7 +191,9 @@  discard block
 block discarded – undo
184 191
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
185 192
 		date_default_timezone_set('UTC');
186 193
 		$filter_query = $this->getFilter($filter,true,true);
187
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
194
+		if (!isset($globalLiveInterval)) {
195
+			$globalLiveInterval = '200';
196
+		}
188 197
 		if ($globalDBdriver == 'mysql') {
189 198
 			if (isset($globalArchive) && $globalArchive === TRUE) {
190 199
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -227,7 +236,9 @@  discard block
 block discarded – undo
227 236
 
228 237
 		$filter_query = $this->getFilter($filter,true,true);
229 238
 
230
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
239
+		if (!isset($globalLiveInterval)) {
240
+			$globalLiveInterval = '200';
241
+		}
231 242
 		if ($globalDBdriver == 'mysql') {
232 243
 /*
233 244
 			$query  = 'SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -271,7 +282,9 @@  discard block
 block discarded – undo
271 282
 		global $globalDBdriver, $globalLiveInterval;
272 283
 		$filter_query = $this->getFilter($filter,true,true);
273 284
 
274
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
285
+		if (!isset($globalLiveInterval)) {
286
+			$globalLiveInterval = '200';
287
+		}
275 288
 		if ($globalDBdriver == 'mysql') {
276 289
 			//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
277 290
 			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
@@ -301,7 +314,9 @@  discard block
 block discarded – undo
301 314
 	{
302 315
 		global $globalDBdriver, $globalLiveInterval;
303 316
 		$Spotter = new Spotter($this->db);
304
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
317
+		if (!isset($globalLiveInterval)) {
318
+			$globalLiveInterval = '200';
319
+		}
305 320
 		$filter_query = $this->getFilter($filter);
306 321
 
307 322
 		if (is_array($coord)) {
@@ -309,7 +324,9 @@  discard block
 block discarded – undo
309 324
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
310 325
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
311 326
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
312
-		} else return array();
327
+		} else {
328
+			return array();
329
+		}
313 330
 		if ($globalDBdriver == 'mysql') {
314 331
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
315 332
 		} else {
@@ -330,7 +347,9 @@  discard block
 block discarded – undo
330 347
 	{
331 348
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
332 349
 		$Spotter = new Spotter($this->db);
333
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
350
+		if (!isset($globalLiveInterval)) {
351
+			$globalLiveInterval = '200';
352
+		}
334 353
 		$filter_query = $this->getFilter($filter,true,true);
335 354
 
336 355
 		if (is_array($coord)) {
@@ -338,7 +357,9 @@  discard block
 block discarded – undo
338 357
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
339 358
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
340 359
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
341
-		} else return array();
360
+		} else {
361
+			return array();
362
+		}
342 363
 		if ($globalDBdriver == 'mysql') {
343 364
 			if (isset($globalArchive) && $globalArchive === TRUE) {
344 365
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -569,11 +590,15 @@  discard block
 block discarded – undo
569 590
 		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
570 591
 		if ($globalDBdriver == 'mysql') {
571 592
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
572
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
593
+			if ($liveinterval) {
594
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
595
+			}
573 596
 			$query .= ' ORDER BY date';
574 597
 		} else {
575 598
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
576
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
599
+			if ($liveinterval) {
600
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
601
+			}
577 602
 			$query .= ' ORDER BY date';
578 603
 		}
579 604
 
@@ -668,7 +693,9 @@  discard block
 block discarded – undo
668 693
 				$i++;
669 694
 				$j++;
670 695
 				if ($j == 30) {
671
-					if ($globalDebug) echo ".";
696
+					if ($globalDebug) {
697
+						echo ".";
698
+					}
672 699
 				    	try {
673 700
 						
674 701
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -975,7 +1002,9 @@  discard block
 block discarded – undo
975 1002
 			{
976 1003
 				return false;
977 1004
 			}
978
-		} else return '';
1005
+		} else {
1006
+			return '';
1007
+		}
979 1008
 
980 1009
 		if ($longitude != '')
981 1010
 		{
@@ -983,7 +1012,9 @@  discard block
 block discarded – undo
983 1012
 			{
984 1013
 				return false;
985 1014
 			}
986
-		} else return '';
1015
+		} else {
1016
+			return '';
1017
+		}
987 1018
 
988 1019
 		if ($waypoints != '')
989 1020
 		{
@@ -999,7 +1030,9 @@  discard block
 block discarded – undo
999 1030
 			{
1000 1031
 				return false;
1001 1032
 			}
1002
-		} else $altitude = 0;
1033
+		} else {
1034
+			$altitude = 0;
1035
+		}
1003 1036
 
1004 1037
 		if ($heading != '')
1005 1038
 		{
@@ -1007,7 +1040,9 @@  discard block
 block discarded – undo
1007 1040
 			{
1008 1041
 				return false;
1009 1042
 			}
1010
-		} else $heading = 0;
1043
+		} else {
1044
+			$heading = 0;
1045
+		}
1011 1046
 
1012 1047
 		if ($groundspeed != '')
1013 1048
 		{
@@ -1015,9 +1050,13 @@  discard block
 block discarded – undo
1015 1050
 			{
1016 1051
 				return false;
1017 1052
 			}
1018
-		} else $groundspeed = 0;
1053
+		} else {
1054
+			$groundspeed = 0;
1055
+		}
1019 1056
 		date_default_timezone_set('UTC');
1020
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1057
+		if ($date == '') {
1058
+			$date = date("Y-m-d H:i:s", time());
1059
+		}
1021 1060
 
1022 1061
         
1023 1062
 		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
@@ -1061,14 +1100,24 @@  discard block
 block discarded – undo
1061 1100
 		$arrival_airport_country = '';
1062 1101
 		
1063 1102
             	
1064
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1065
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1066
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1067
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1103
+            	if ($squawk == '' || $Common->isInteger($squawk) === false ) {
1104
+            		$squawk = NULL;
1105
+            	}
1106
+            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) {
1107
+            		$verticalrate = NULL;
1108
+            	}
1109
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1110
+            		$groundspeed = 0;
1111
+            	}
1112
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1113
+            		$heading = 0;
1114
+            	}
1068 1115
 		
1069 1116
 		$query = '';
1070 1117
 		if ($globalArchive) {
1071
-			if ($globalDebug) echo '-- Delete previous data -- ';
1118
+			if ($globalDebug) {
1119
+				echo '-- Delete previous data -- ';
1120
+			}
1072 1121
 			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1073 1122
 		}
1074 1123
 
@@ -1085,10 +1134,14 @@  discard block
 block discarded – undo
1085 1134
 			return "error : ".$e->getMessage();
1086 1135
 		}
1087 1136
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1088
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1137
+		    if ($globalDebug) {
1138
+		    	echo '(Add to SBS archive : ';
1139
+		    }
1089 1140
 		    $SpotterArchive = new SpotterArchive($this->db);
1090 1141
 		    $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);
1091
-		    if ($globalDebug) echo $result.')';
1142
+		    if ($globalDebug) {
1143
+		    	echo $result.')';
1144
+		    }
1092 1145
 		}
1093 1146
 		return "success";
1094 1147
 
Please login to merge, or discard this patch.