Completed
Push — master ( 56221e...3c95ac )
by Yannick
07:57
created
require/class.APRS.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -88,6 +88,10 @@  discard block
 block discarded – undo
88 88
 	'y' => 'Yagi At QTH');
89 89
 	
90 90
 
91
+    /**
92
+     * @param integer $n
93
+     * @param integer $s
94
+     */
91 95
     private function urshift($n, $s) {
92 96
 	return ($n >= 0) ? ($n >> $s) :
93 97
 	    (($n & 0x7fffffff) >> $s) | 
@@ -442,6 +446,9 @@  discard block
 block discarded – undo
442 446
 	}
443 447
     }
444 448
     
449
+    /**
450
+     * @param string $data
451
+     */
445 452
     function send($data) {
446 453
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447 454
 	if ($send === FALSE) $this->connect();
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
5
+	private $socket;
6 6
 
7
-    protected $symbols = array('!' => 'Police',
7
+	protected $symbols = array('!' => 'Police',
8 8
 	'#' => 'DIGI',
9 9
 	'$' => 'Phone',
10 10
 	'%' => 'DX Cluster',
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 	'y' => 'Yagi At QTH');
89 89
 	
90 90
 
91
-    private function urshift($n, $s) {
91
+	private function urshift($n, $s) {
92 92
 	return ($n >= 0) ? ($n >> $s) :
93
-	    (($n & 0x7fffffff) >> $s) | 
93
+		(($n & 0x7fffffff) >> $s) | 
94 94
 		(0x40000000 >> ($s - 1));
95
-    }
95
+	}
96 96
 
97
-    public function parse($input) {
97
+	public function parse($input) {
98 98
 	global $globalDebug;
99 99
 	$debug = false;
100 100
 	$result = array();
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	
107 107
 	/* Check that end was found and body has at least one byte. */
108 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
109
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
-	    return false;
109
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+		return false;
111 111
 	}
112 112
 	
113 113
 	if ($debug) echo 'input : '.$input."\n";
@@ -121,23 +121,23 @@  discard block
 block discarded – undo
121 121
 	/* Parse source, target and path. */
122 122
 	//FLRDF0A52>APRS,qAS,LSTB
123 123
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
124
-	    $ident = $matches[1];
125
-	    $all_elements = $matches[2];
126
-	    if ($debug) echo 'ident : '.$ident."\n";
127
-	    $result['ident'] = $ident;
124
+		$ident = $matches[1];
125
+		$all_elements = $matches[2];
126
+		if ($debug) echo 'ident : '.$ident."\n";
127
+		$result['ident'] = $ident;
128 128
 	} else return false;
129 129
 	$elements = explode(',',$all_elements);
130 130
 	$source = end($elements);
131 131
 	$result['source'] = $source;
132 132
 	foreach ($elements as $element) {
133
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
134
-	        //echo "ok";
135
-	        //if ($element == 'TCPIP*') return false;
136
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
133
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
134
+			//echo "ok";
135
+			//if ($element == 'TCPIP*') return false;
136
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
137 137
 		if ($debug) echo 'element : '.$element."\n";
138 138
 		return false;
139
-	    }
140
-	    /*
139
+		}
140
+		/*
141 141
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
142 142
 		//echo "ok";
143 143
 	    } else {
@@ -160,49 +160,49 @@  discard block
 block discarded – undo
160 160
 	$body_parse = substr($body,1);
161 161
 	//echo 'Body : '.$body."\n";
162 162
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
163
-	    $body_parse = substr($body_parse,10);
164
-	    $find = true;
165
-	    //echo $body_parse."\n";
163
+		$body_parse = substr($body_parse,10);
164
+		$find = true;
165
+		//echo $body_parse."\n";
166 166
 	}
167 167
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
168
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
169
-	    $find = true;
170
-	    //echo $body_parse."\n";
168
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
169
+		$find = true;
170
+		//echo $body_parse."\n";
171 171
 	}
172 172
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
173
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
174
-	    $find = true;
175
-	    //echo $body_parse."\n";
173
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
174
+		$find = true;
175
+		//echo $body_parse."\n";
176 176
 	}
177 177
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
178
-	    $find = true;
179
-	    //print_r($matches);
180
-	    $timestamp = $matches[0];
181
-	    if ($matches[4] == 'h') {
178
+		$find = true;
179
+		//print_r($matches);
180
+		$timestamp = $matches[0];
181
+		if ($matches[4] == 'h') {
182 182
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
183 183
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
184 184
 		/*
185 185
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
186 186
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
187 187
 		*/
188
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
188
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
189 189
 		// This work or not ?
190 190
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
191
-	    }
192
-	    $body_parse = substr($body_parse,7);
193
-	    $result['timestamp'] = $timestamp;
194
-	    //echo date('Ymd H:i:s',$timestamp);
191
+		}
192
+		$body_parse = substr($body_parse,7);
193
+		$result['timestamp'] = $timestamp;
194
+		//echo date('Ymd H:i:s',$timestamp);
195 195
 	}
196 196
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
197
-	    $find = true;
198
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
-	    $body_parse = substr($body_parse,8);
200
-	    $result['timestamp'] = $timestamp;
201
-	    //echo date('Ymd H:i:s',$timestamp);
197
+		$find = true;
198
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
+		$body_parse = substr($body_parse,8);
200
+		$result['timestamp'] = $timestamp;
201
+		//echo date('Ymd H:i:s',$timestamp);
202 202
 	}
203 203
 	//if (strlen($body_parse) > 19) {
204
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
205
-	    $find = true;
204
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
205
+		$find = true;
206 206
 		// 4658.70N/00707.78Ez
207 207
 		//print_r(str_split($body_parse));
208 208
 		
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		$lon = intval($lon_deg);
220 220
 		if ($lat > 89 || $lon > 179) return false;
221 221
 	    
222
-	    /*
222
+		/*
223 223
 	    $tmp_5b = str_replace('.','',$lat_min);
224 224
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
225 225
 	        print_r($matches);
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 		$result['longitude'] = $longitude;
234 234
 		$body_parse = substr($body_parse,18);
235 235
 		$body_parse_len = strlen($body_parse);
236
-	    }
237
-	    $body_parse_len = strlen($body_parse);
238
-	    if ($body_parse_len > 0) {
236
+		}
237
+		$body_parse_len = strlen($body_parse);
238
+		if ($body_parse_len > 0) {
239 239
 		/*
240 240
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
241 241
 			$body_split = str_split($body);
@@ -264,73 +264,73 @@  discard block
 block discarded – undo
264 264
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
265 265
 			if ($symbol_code != '_') {
266 266
 			}
267
-		    //$body_parse = substr($body_parse,1);
268
-		    //$body_parse = trim($body_parse);
269
-		    //$body_parse_len = strlen($body_parse);
270
-		    if ($body_parse_len >= 7) {
267
+			//$body_parse = substr($body_parse,1);
268
+			//$body_parse = trim($body_parse);
269
+			//$body_parse_len = strlen($body_parse);
270
+			if ($body_parse_len >= 7) {
271 271
 			
272
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
-		    	    $course = substr($body_parse,0,3);
274
-		    	    $tmp_s = intval($course);
275
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
-		    	    $speed = substr($body_parse,4,3);
277
-		    	    if ($speed != '...') {
278
-		    		    $result['speed'] = round($speed*1.852);
279
-		    	    }
280
-		    	    $body_parse = substr($body_parse,7);
281
-		        }
282
-		        // Check PHGR, PHG, RNG
283
-		    } 
284
-		    /*
272
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
+					$course = substr($body_parse,0,3);
274
+					$tmp_s = intval($course);
275
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
+					$speed = substr($body_parse,4,3);
277
+					if ($speed != '...') {
278
+						$result['speed'] = round($speed*1.852);
279
+					}
280
+					$body_parse = substr($body_parse,7);
281
+				}
282
+				// Check PHGR, PHG, RNG
283
+			} 
284
+			/*
285 285
 		    else if ($body_parse_len > 0) {
286 286
 			$rest = $body_parse;
287 287
 		    }
288 288
 		    */
289
-		    if (strlen($body_parse) > 0) {
290
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
291
-		            $altitude = intval($matches[1]);
292
-		            //$result['altitude'] = round($altitude*0.3048);
293
-		            $result['altitude'] = $altitude;
294
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
296
-		        }
297
-		    }
289
+			if (strlen($body_parse) > 0) {
290
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
291
+					$altitude = intval($matches[1]);
292
+					//$result['altitude'] = round($altitude*0.3048);
293
+					$result['altitude'] = $altitude;
294
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
296
+				}
297
+			}
298 298
 		    
299
-		    // Telemetry
300
-		    /*
299
+			// Telemetry
300
+			/*
301 301
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
302 302
 		        // Nothing yet...
303 303
 		    }
304 304
 		    */
305
-		    // DAO
306
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
307
-			    $dao = $matches[1];
308
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
305
+			// DAO
306
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
307
+				$dao = $matches[1];
308
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
309 309
 				$dao_split = str_split($dao);
310
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
310
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
312 312
 			    
313 313
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314 314
 				else $result['latitude'] += $lat_off;
315 315
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316 316
 				else $result['longitude'] += $lon_off;
317
-			    }
318
-		            $body_parse = substr($body_parse,6);
319
-		    }
317
+				}
318
+					$body_parse = substr($body_parse,6);
319
+			}
320 320
 		    
321
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
321
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
322 322
 			$result['callsign'] = $matches[1];
323
-		    }
324
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
323
+			}
324
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
325 325
 			$result['squawk'] = $matches[1];
326
-		    }
327
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
326
+			}
327
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
328 328
 			$result['aircraft_icao'] = $matches[1];
329
-		    }
330
-		    // OGN comment
329
+			}
330
+			// OGN comment
331 331
 		   // echo "Before OGN : ".$body_parse."\n";
332
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
332
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
334 334
 			$id = $matches[1];
335 335
 			//$mode = substr($id,0,2);
336 336
 			$address = substr($id,2);
@@ -360,53 +360,53 @@  discard block
 block discarded – undo
360 360
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
361 361
 			$result['stealth'] = $stealth;
362 362
 			$result['address'] = $address;
363
-		    }
363
+			}
364 364
 		    
365
-		    //Comment
366
-		    $result['comment'] = trim($body_parse);
365
+			//Comment
366
+			$result['comment'] = trim($body_parse);
367 367
 		} else {
368
-		    // parse weather
369
-		    //$body_parse = substr($body_parse,1);
370
-		    //$body_parse_len = strlen($body_parse);
368
+			// parse weather
369
+			//$body_parse = substr($body_parse,1);
370
+			//$body_parse_len = strlen($body_parse);
371 371
 
372
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
-			    $result['wind_dir'] = intval($matches[1]);
374
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
378
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
372
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
+				$result['wind_dir'] = intval($matches[1]);
374
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
378
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
379 379
 			$result['wind_dir'] = intval($matches[1]);
380 380
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
381 381
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
382 382
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
383
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
384
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
383
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
384
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
385 385
 			$result['wind_dir'] = intval($matches[1]);
386 386
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
387 387
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
388
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
389
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
388
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
389
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
390 390
 			$result['wind_dir'] = intval($matches[1]);
391 391
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
392 392
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
393
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
394
-		    }
395
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
393
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
394
+			}
395
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
396 396
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
397
-		    }
397
+			}
398 398
 		}
399 399
 		} else $result['comment'] = trim($body_parse);
400 400
 
401
-	    }
401
+		}
402 402
 	//}
403 403
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404 404
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
405 405
 	if ($debug) print_r($result);
406 406
 	return $result;
407
-    }
407
+	}
408 408
     
409
-    function connect() {
409
+	function connect() {
410 410
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
411 411
 	$aprs_connect = 0;
412 412
 	$aprs_keep = 120;
@@ -430,22 +430,22 @@  discard block
 block discarded – undo
430 430
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
431 431
 			echo $msgin."\n";
432 432
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
433
-			    echo 'Verified !';
434
-			    return true;
435
-			    break;
433
+				echo 'Verified !';
434
+				return true;
435
+				break;
436 436
 			}
437 437
 			if (time()-$authstart > 5) {
438
-			    echo 'Timeout';
439
-			    break;
438
+				echo 'Timeout';
439
+				break;
440 440
 			}
441 441
 		}
442 442
 	}
443
-    }
443
+	}
444 444
     
445
-    function send($data) {
445
+	function send($data) {
446 446
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447 447
 	if ($send === FALSE) $this->connect();
448
-    }
448
+	}
449 449
 }
450 450
 
451 451
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Spacing   +90 added lines, -91 removed lines patch added patch discarded remove patch
@@ -89,8 +89,7 @@  discard block
 block discarded – undo
89 89
 	
90 90
 
91 91
     private function urshift($n, $s) {
92
-	return ($n >= 0) ? ($n >> $s) :
93
-	    (($n & 0x7fffffff) >> $s) | 
92
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
94 93
 		(0x40000000 >> ($s - 1));
95 94
     }
96 95
 
@@ -102,7 +101,7 @@  discard block
 block discarded – undo
102 101
 	//$split_input = str_split($input);
103 102
 
104 103
 	/* Find the end of header checking for NULL bytes while doing it. */
105
-	$splitpos = strpos($input,':');
104
+	$splitpos = strpos($input, ':');
106 105
 	
107 106
 	/* Check that end was found and body has at least one byte. */
108 107
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -112,28 +111,28 @@  discard block
 block discarded – undo
112 111
 	
113 112
 	if ($debug) echo 'input : '.$input."\n";
114 113
 	/* Save header and body. */
115
-	$body = substr($input,$splitpos+1,$input_len);
114
+	$body = substr($input, $splitpos + 1, $input_len);
116 115
 	$body_len = strlen($body);
117
-	$header = substr($input,0,$splitpos);
116
+	$header = substr($input, 0, $splitpos);
118 117
 	//$header_len = strlen($header);
119 118
 	if ($debug) echo 'header : '.$header."\n";
120 119
 	
121 120
 	/* Parse source, target and path. */
122 121
 	//FLRDF0A52>APRS,qAS,LSTB
123
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
122
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
124 123
 	    $ident = $matches[1];
125 124
 	    $all_elements = $matches[2];
126 125
 	    if ($debug) echo 'ident : '.$ident."\n";
127 126
 	    $result['ident'] = $ident;
128 127
 	} else return false;
129
-	$elements = explode(',',$all_elements);
128
+	$elements = explode(',', $all_elements);
130 129
 	$source = end($elements);
131 130
 	$result['source'] = $source;
132 131
 	foreach ($elements as $element) {
133
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
132
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
134 133
 	        //echo "ok";
135 134
 	        //if ($element == 'TCPIP*') return false;
136
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
135
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
137 136
 		if ($debug) echo 'element : '.$element."\n";
138 137
 		return false;
139 138
 	    }
@@ -146,10 +145,10 @@  discard block
 block discarded – undo
146 145
 	    */
147 146
 	}
148 147
 	
149
-	$type = substr($body,0,1);
148
+	$type = substr($body, 0, 1);
150 149
 	if ($debug) echo 'type : '.$type."\n";
151 150
 	if ($type == ';') {
152
-		$result['ident'] = trim(substr($body,1,9));
151
+		$result['ident'] = trim(substr($body, 1, 9));
153 152
 	} elseif ($type == ',') {
154 153
 		// Invalid data or test data
155 154
 		return false;
@@ -157,24 +156,24 @@  discard block
 block discarded – undo
157 156
 	
158 157
 	// Check for Timestamp
159 158
 	$find = false;
160
-	$body_parse = substr($body,1);
159
+	$body_parse = substr($body, 1);
161 160
 	//echo 'Body : '.$body."\n";
162
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
163
-	    $body_parse = substr($body_parse,10);
161
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
162
+	    $body_parse = substr($body_parse, 10);
164 163
 	    $find = true;
165 164
 	    //echo $body_parse."\n";
166 165
 	}
167
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
168
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
166
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
167
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
169 168
 	    $find = true;
170 169
 	    //echo $body_parse."\n";
171 170
 	}
172
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
173
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
171
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
172
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
174 173
 	    $find = true;
175 174
 	    //echo $body_parse."\n";
176 175
 	}
177
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
176
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
178 177
 	    $find = true;
179 178
 	    //print_r($matches);
180 179
 	    $timestamp = $matches[0];
@@ -189,19 +188,19 @@  discard block
 block discarded – undo
189 188
 		// This work or not ?
190 189
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
191 190
 	    }
192
-	    $body_parse = substr($body_parse,7);
191
+	    $body_parse = substr($body_parse, 7);
193 192
 	    $result['timestamp'] = $timestamp;
194 193
 	    //echo date('Ymd H:i:s',$timestamp);
195 194
 	}
196
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
195
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
197 196
 	    $find = true;
198 197
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
-	    $body_parse = substr($body_parse,8);
198
+	    $body_parse = substr($body_parse, 8);
200 199
 	    $result['timestamp'] = $timestamp;
201 200
 	    //echo date('Ymd H:i:s',$timestamp);
202 201
 	}
203 202
 	//if (strlen($body_parse) > 19) {
204
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
203
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
205 204
 	    $find = true;
206 205
 		// 4658.70N/00707.78Ez
207 206
 		//print_r(str_split($body_parse));
@@ -227,11 +226,11 @@  discard block
 block discarded – undo
227 226
 	    */
228 227
 		$latitude = $lat + floatval($lat_min)/60;
229 228
 		$longitude = $lon + floatval($lon_min)/60;
230
-		if ($sind == 'S') $latitude = 0-$latitude;
231
-		if ($wind == 'W') $longitude = 0-$longitude;
229
+		if ($sind == 'S') $latitude = 0 - $latitude;
230
+		if ($wind == 'W') $longitude = 0 - $longitude;
232 231
 		$result['latitude'] = $latitude;
233 232
 		$result['longitude'] = $longitude;
234
-		$body_parse = substr($body_parse,18);
233
+		$body_parse = substr($body_parse, 18);
235 234
 		$body_parse_len = strlen($body_parse);
236 235
 	    }
237 236
 	    $body_parse_len = strlen($body_parse);
@@ -258,7 +257,7 @@  discard block
 block discarded – undo
258 257
 		//}
259 258
 		//echo $body_parse;
260 259
 			if ($type != ';' && $type != '>') {
261
-			$body_parse = substr($body_parse,1);
260
+			$body_parse = substr($body_parse, 1);
262 261
 			$body_parse_len = strlen($body_parse);
263 262
 			$result['symbol_code'] = $symbol_code;
264 263
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
@@ -269,15 +268,15 @@  discard block
 block discarded – undo
269 268
 		    //$body_parse_len = strlen($body_parse);
270 269
 		    if ($body_parse_len >= 7) {
271 270
 			
272
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
-		    	    $course = substr($body_parse,0,3);
271
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
272
+		    	    $course = substr($body_parse, 0, 3);
274 273
 		    	    $tmp_s = intval($course);
275 274
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
-		    	    $speed = substr($body_parse,4,3);
275
+		    	    $speed = substr($body_parse, 4, 3);
277 276
 		    	    if ($speed != '...') {
278 277
 		    		    $result['speed'] = round($speed*1.852);
279 278
 		    	    }
280
-		    	    $body_parse = substr($body_parse,7);
279
+		    	    $body_parse = substr($body_parse, 7);
281 280
 		        }
282 281
 		        // Check PHGR, PHG, RNG
283 282
 		    } 
@@ -287,12 +286,12 @@  discard block
 block discarded – undo
287 286
 		    }
288 287
 		    */
289 288
 		    if (strlen($body_parse) > 0) {
290
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
289
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
291 290
 		            $altitude = intval($matches[1]);
292 291
 		            //$result['altitude'] = round($altitude*0.3048);
293 292
 		            $result['altitude'] = $altitude;
294 293
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
294
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
296 295
 		        }
297 296
 		    }
298 297
 		    
@@ -303,44 +302,44 @@  discard block
 block discarded – undo
303 302
 		    }
304 303
 		    */
305 304
 		    // DAO
306
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
305
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
307 306
 			    $dao = $matches[1];
308
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
307
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
309 308
 				$dao_split = str_split($dao);
310
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
309
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
310
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
312 311
 			    
313 312
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314 313
 				else $result['latitude'] += $lat_off;
315 314
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316 315
 				else $result['longitude'] += $lon_off;
317 316
 			    }
318
-		            $body_parse = substr($body_parse,6);
317
+		            $body_parse = substr($body_parse, 6);
319 318
 		    }
320 319
 		    
321
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
320
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
322 321
 			$result['callsign'] = $matches[1];
323 322
 		    }
324
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
323
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
325 324
 			$result['squawk'] = $matches[1];
326 325
 		    }
327
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
326
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
328 327
 			$result['aircraft_icao'] = $matches[1];
329 328
 		    }
330 329
 		    // OGN comment
331 330
 		   // echo "Before OGN : ".$body_parse."\n";
332 331
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
332
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
334 333
 			$id = $matches[1];
335 334
 			//$mode = substr($id,0,2);
336
-			$address = substr($id,2);
335
+			$address = substr($id, 2);
337 336
 			//print_r($matches);
338
-			$addressType = (intval(substr($id,0,2),16))&3;
337
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
339 338
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
340 339
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
341 340
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
342 341
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
343
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
342
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
344 343
 			$result['aircrafttype_code'] = $aircraftType;
345 344
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
346 345
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -357,7 +356,7 @@  discard block
 block discarded – undo
357 356
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
358 357
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
359 358
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
360
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
359
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
361 360
 			$result['stealth'] = $stealth;
362 361
 			$result['address'] = $address;
363 362
 		    }
@@ -369,72 +368,72 @@  discard block
 block discarded – undo
369 368
 		    //$body_parse = substr($body_parse,1);
370 369
 		    //$body_parse_len = strlen($body_parse);
371 370
 
372
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
371
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
373 372
 			    $result['wind_dir'] = intval($matches[1]);
374
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
378
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
374
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
375
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
376
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
377
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
379 378
 			$result['wind_dir'] = intval($matches[1]);
380
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
381
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
382
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
383
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
384
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
379
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
380
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
381
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
382
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
383
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
385 384
 			$result['wind_dir'] = intval($matches[1]);
386
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
387
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
388
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
389
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
385
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
386
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
387
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
388
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
390 389
 			$result['wind_dir'] = intval($matches[1]);
391
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
392
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
393
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
390
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
391
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
392
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
394 393
 		    }
395
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
396
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
394
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
395
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
397 396
 		    }
398 397
 		}
399 398
 		} else $result['comment'] = trim($body_parse);
400 399
 
401 400
 	    }
402 401
 	//}
403
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
402
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
403
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
405 404
 	if ($debug) print_r($result);
406 405
 	return $result;
407 406
     }
408 407
     
409 408
     function connect() {
410
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
409
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
411 410
 	$aprs_connect = 0;
412 411
 	$aprs_keep = 120;
413 412
 	$aprs_last_tx = time();
414 413
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
415
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
414
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
416 415
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
417
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
416
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
418 417
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
419 418
 	else $aprs_pass = '-1';
420 419
 	
421
-	$aprs_filter  = '';
420
+	$aprs_filter = '';
422 421
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
423 422
 	$Common = new Common();
424
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
423
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
425 424
 	if ($s !== false) {
426 425
 		echo 'Connected to APRS server! '."\n";
427 426
 		$authstart = time();
428 427
 		$this->socket = $s;
429
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
430
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
428
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
429
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
431 430
 			echo $msgin."\n";
432 431
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
433 432
 			    echo 'Verified !';
434 433
 			    return true;
435 434
 			    break;
436 435
 			}
437
-			if (time()-$authstart > 5) {
436
+			if (time() - $authstart > 5) {
438 437
 			    echo 'Timeout';
439 438
 			    break;
440 439
 			}
@@ -443,20 +442,20 @@  discard block
 block discarded – undo
443 442
     }
444 443
     
445 444
     function send($data) {
446
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
445
+	$send = socket_send($this->socket, $data, strlen($data), 0);
447 446
 	if ($send === FALSE) $this->connect();
448 447
     }
449 448
 }
450 449
 
451 450
 class APRSSpotter extends APRS {
452
-	function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
451
+	function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
453 452
 		$Common = new Common();
454 453
 		if ($latitude != '' && $longitude != '') {
455
-		$latitude = $Common->convertDM($latitude,'latitude');
456
-		$longitude = $Common->convertDM($longitude,'longitude');
457
-		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
458
-		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
459
-		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
454
+		$latitude = $Common->convertDM($latitude, 'latitude');
455
+		$longitude = $Common->convertDM($longitude, 'longitude');
456
+		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
457
+		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
458
+		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
460 459
 		$w = $w1.$w2;
461 460
 		//$w = '00';
462 461
 		$custom = '';
@@ -473,19 +472,19 @@  discard block
 block discarded – undo
473 472
 			$custom .= 'AI='.$aircraft_icao;
474 473
 		}
475 474
 		if ($custom != '') $custom = ' '.$custom;
476
-			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
475
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
477 476
 		}
478 477
 	}
479 478
 }
480 479
 class APRSMarine extends APRS {
481
-	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
480
+	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
482 481
 		$Common = new Common();
483 482
 		if ($latitude != '' && $longitude != '') {
484
-		$latitude = $Common->convertDM($latitude,'latitude');
485
-		$longitude = $Common->convertDM($longitude,'longitude');
486
-		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
487
-		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
488
-		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
483
+		$latitude = $Common->convertDM($latitude, 'latitude');
484
+		$longitude = $Common->convertDM($longitude, 'longitude');
485
+		$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
486
+		$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
487
+		$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
489 488
 		$w = $w1.$w2;
490 489
 		//$w = '00';
491 490
 		$custom = '';
@@ -511,7 +510,7 @@  discard block
 block discarded – undo
511 510
 		}
512 511
 		if ($custom != '') $custom = ' '.$custom;
513 512
 		$altitude = 0;
514
-			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
513
+			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
515 514
 		}
516 515
 	}
517 516
 }
Please login to merge, or discard this patch.
Braces   +146 added lines, -56 removed lines patch added patch discarded remove patch
@@ -106,26 +106,36 @@  discard block
 block discarded – undo
106 106
 	
107 107
 	/* Check that end was found and body has at least one byte. */
108 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
109
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
109
+	    if ($globalDebug) {
110
+	    	echo '!!! APRS invalid : '.$input."\n";
111
+	    }
110 112
 	    return false;
111 113
 	}
112 114
 	
113
-	if ($debug) echo 'input : '.$input."\n";
115
+	if ($debug) {
116
+		echo 'input : '.$input."\n";
117
+	}
114 118
 	/* Save header and body. */
115 119
 	$body = substr($input,$splitpos+1,$input_len);
116 120
 	$body_len = strlen($body);
117 121
 	$header = substr($input,0,$splitpos);
118 122
 	//$header_len = strlen($header);
119
-	if ($debug) echo 'header : '.$header."\n";
123
+	if ($debug) {
124
+		echo 'header : '.$header."\n";
125
+	}
120 126
 	
121 127
 	/* Parse source, target and path. */
122 128
 	//FLRDF0A52>APRS,qAS,LSTB
123 129
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
124 130
 	    $ident = $matches[1];
125 131
 	    $all_elements = $matches[2];
126
-	    if ($debug) echo 'ident : '.$ident."\n";
132
+	    if ($debug) {
133
+	    	echo 'ident : '.$ident."\n";
134
+	    }
127 135
 	    $result['ident'] = $ident;
128
-	} else return false;
136
+	} else {
137
+		return false;
138
+	}
129 139
 	$elements = explode(',',$all_elements);
130 140
 	$source = end($elements);
131 141
 	$result['source'] = $source;
@@ -134,7 +144,9 @@  discard block
 block discarded – undo
134 144
 	        //echo "ok";
135 145
 	        //if ($element == 'TCPIP*') return false;
136 146
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
137
-		if ($debug) echo 'element : '.$element."\n";
147
+		if ($debug) {
148
+			echo 'element : '.$element."\n";
149
+		}
138 150
 		return false;
139 151
 	    }
140 152
 	    /*
@@ -147,7 +159,9 @@  discard block
 block discarded – undo
147 159
 	}
148 160
 	
149 161
 	$type = substr($body,0,1);
150
-	if ($debug) echo 'type : '.$type."\n";
162
+	if ($debug) {
163
+		echo 'type : '.$type."\n";
164
+	}
151 165
 	if ($type == ';') {
152 166
 		$result['ident'] = trim(substr($body,1,9));
153 167
 	} elseif ($type == ',') {
@@ -217,7 +231,9 @@  discard block
 block discarded – undo
217 231
 		//$symbol_table = $matches[4];
218 232
 		$lat = intval($lat_deg);
219 233
 		$lon = intval($lon_deg);
220
-		if ($lat > 89 || $lon > 179) return false;
234
+		if ($lat > 89 || $lon > 179) {
235
+			return false;
236
+		}
221 237
 	    
222 238
 	    /*
223 239
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -227,8 +243,12 @@  discard block
 block discarded – undo
227 243
 	    */
228 244
 		$latitude = $lat + floatval($lat_min)/60;
229 245
 		$longitude = $lon + floatval($lon_min)/60;
230
-		if ($sind == 'S') $latitude = 0-$latitude;
231
-		if ($wind == 'W') $longitude = 0-$longitude;
246
+		if ($sind == 'S') {
247
+			$latitude = 0-$latitude;
248
+		}
249
+		if ($wind == 'W') {
250
+			$longitude = 0-$longitude;
251
+		}
232 252
 		$result['latitude'] = $latitude;
233 253
 		$result['longitude'] = $longitude;
234 254
 		$body_parse = substr($body_parse,18);
@@ -261,7 +281,9 @@  discard block
 block discarded – undo
261 281
 			$body_parse = substr($body_parse,1);
262 282
 			$body_parse_len = strlen($body_parse);
263 283
 			$result['symbol_code'] = $symbol_code;
264
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
284
+			if (isset($this->symbols[$symbol_code])) {
285
+				$result['symbol'] = $this->symbols[$symbol_code];
286
+			}
265 287
 			if ($symbol_code != '_') {
266 288
 			}
267 289
 		    //$body_parse = substr($body_parse,1);
@@ -272,7 +294,9 @@  discard block
 block discarded – undo
272 294
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273 295
 		    	    $course = substr($body_parse,0,3);
274 296
 		    	    $tmp_s = intval($course);
275
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
297
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
298
+		    	    	$result['heading'] = intval($course);
299
+		    	    }
276 300
 		    	    $speed = substr($body_parse,4,3);
277 301
 		    	    if ($speed != '...') {
278 302
 		    		    $result['speed'] = round($speed*1.852);
@@ -310,10 +334,16 @@  discard block
 block discarded – undo
310 334
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311 335
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
312 336
 			    
313
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314
-				else $result['latitude'] += $lat_off;
315
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316
-				else $result['longitude'] += $lon_off;
337
+				if ($result['latitude'] < 0) {
338
+					$result['latitude'] -= $lat_off;
339
+				} else {
340
+					$result['latitude'] += $lat_off;
341
+				}
342
+				if ($result['longitude'] < 0) {
343
+					$result['longitude'] -= $lon_off;
344
+				} else {
345
+					$result['longitude'] += $lon_off;
346
+				}
317 347
 			    }
318 348
 		            $body_parse = substr($body_parse,6);
319 349
 		    }
@@ -336,27 +366,48 @@  discard block
 block discarded – undo
336 366
 			$address = substr($id,2);
337 367
 			//print_r($matches);
338 368
 			$addressType = (intval(substr($id,0,2),16))&3;
339
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
340
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
341
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
342
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
369
+			if ($addressType == 0) {
370
+				$result['addresstype'] = "RANDOM";
371
+			} elseif ($addressType == 1) {
372
+				$result['addresstype'] = "ICAO";
373
+			} elseif ($addressType == 2) {
374
+				$result['addresstype'] = "FLARM";
375
+			} elseif ($addressType == 3) {
376
+				$result['addresstype'] = "OGN";
377
+			}
343 378
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
344 379
 			$result['aircrafttype_code'] = $aircraftType;
345
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
346
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
347
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
348
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
349
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
350
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
351
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
352
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
353
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
354
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
355
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
356
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
357
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
358
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
359
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
380
+			if ($aircraftType == 0) {
381
+				$result['aircrafttype'] = "UNKNOWN";
382
+			} elseif ($aircraftType == 1) {
383
+				$result['aircrafttype'] = "GLIDER";
384
+			} elseif ($aircraftType == 2) {
385
+				$result['aircrafttype'] = "TOW_PLANE";
386
+			} elseif ($aircraftType == 3) {
387
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
388
+			} elseif ($aircraftType == 4) {
389
+				$result['aircrafttype'] = "PARACHUTE";
390
+			} elseif ($aircraftType == 5) {
391
+				$result['aircrafttype'] = "DROP_PLANE";
392
+			} elseif ($aircraftType == 6) {
393
+				$result['aircrafttype'] = "HANG_GLIDER";
394
+			} elseif ($aircraftType == 7) {
395
+				$result['aircrafttype'] = "PARA_GLIDER";
396
+			} elseif ($aircraftType == 8) {
397
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
398
+			} elseif ($aircraftType == 9) {
399
+				$result['aircrafttype'] = "JET_AIRCRAFT";
400
+			} elseif ($aircraftType == 10) {
401
+				$result['aircrafttype'] = "UFO";
402
+			} elseif ($aircraftType == 11) {
403
+				$result['aircrafttype'] = "BALLOON";
404
+			} elseif ($aircraftType == 12) {
405
+				$result['aircrafttype'] = "AIRSHIP";
406
+			} elseif ($aircraftType == 13) {
407
+				$result['aircrafttype'] = "UAV";
408
+			} elseif ($aircraftType == 15) {
409
+				$result['aircrafttype'] = "STATIC_OBJECT";
410
+			}
360 411
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
361 412
 			$result['stealth'] = $stealth;
362 413
 			$result['address'] = $address;
@@ -396,13 +447,21 @@  discard block
 block discarded – undo
396 447
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
397 448
 		    }
398 449
 		}
399
-		} else $result['comment'] = trim($body_parse);
450
+		} else {
451
+			$result['comment'] = trim($body_parse);
452
+		}
400 453
 
401 454
 	    }
402 455
 	//}
403
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
405
-	if ($debug) print_r($result);
456
+	if (isset($result['latitude'])) {
457
+		$result['latitude'] = round($result['latitude'],4);
458
+	}
459
+	if (isset($result['longitude'])) {
460
+		$result['longitude'] = round($result['longitude'],4);
461
+	}
462
+	if ($debug) {
463
+		print_r($result);
464
+	}
406 465
 	return $result;
407 466
     }
408 467
     
@@ -411,12 +470,21 @@  discard block
 block discarded – undo
411 470
 	$aprs_connect = 0;
412 471
 	$aprs_keep = 120;
413 472
 	$aprs_last_tx = time();
414
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
415
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
416
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
417
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
418
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
419
-	else $aprs_pass = '-1';
473
+	if (isset($globalAPRSversion)) {
474
+		$aprs_version = $globalAPRSversion;
475
+	} else {
476
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
477
+	}
478
+	if (isset($globalServerAPRSssid)) {
479
+		$aprs_ssid = $globalServerAPRSssid;
480
+	} else {
481
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
482
+	}
483
+	if (isset($globalServerAPRSpass)) {
484
+		$aprs_pass = $globalServerAPRSpass;
485
+	} else {
486
+		$aprs_pass = '-1';
487
+	}
420 488
 	
421 489
 	$aprs_filter  = '';
422 490
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -444,7 +512,9 @@  discard block
 block discarded – undo
444 512
     
445 513
     function send($data) {
446 514
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447
-	if ($send === FALSE) $this->connect();
515
+	if ($send === FALSE) {
516
+		$this->connect();
517
+	}
448 518
     }
449 519
 }
450 520
 
@@ -461,18 +531,26 @@  discard block
 block discarded – undo
461 531
 		//$w = '00';
462 532
 		$custom = '';
463 533
 		if ($ident != '') {
464
-			if ($custom != '') $custom .= '/';
534
+			if ($custom != '') {
535
+				$custom .= '/';
536
+			}
465 537
 			$custom .= 'CS='.$ident;
466 538
 		}
467 539
 		if ($squawk != '') {
468
-			if ($custom != '') $custom .= '/';
540
+			if ($custom != '') {
541
+				$custom .= '/';
542
+			}
469 543
 			$custom .= 'SQ='.$squawk;
470 544
 		}
471 545
 		if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
472
-			if ($custom != '') $custom .= '/';
546
+			if ($custom != '') {
547
+				$custom .= '/';
548
+			}
473 549
 			$custom .= 'AI='.$aircraft_icao;
474 550
 		}
475
-		if ($custom != '') $custom = ' '.$custom;
551
+		if ($custom != '') {
552
+			$custom = ' '.$custom;
553
+		}
476 554
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
477 555
 		}
478 556
 	}
@@ -490,26 +568,38 @@  discard block
 block discarded – undo
490 568
 		//$w = '00';
491 569
 		$custom = '';
492 570
 		if ($ident != '') {
493
-			if ($custom != '') $custom .= '/';
571
+			if ($custom != '') {
572
+				$custom .= '/';
573
+			}
494 574
 			$custom .= 'CS='.$ident;
495 575
 		}
496 576
 		if ($typeid != '') {
497
-			if ($custom != '') $custom .= '/';
577
+			if ($custom != '') {
578
+				$custom .= '/';
579
+			}
498 580
 			$custom .= 'TI='.$typeid;
499 581
 		}
500 582
 		if ($imo != '') {
501
-			if ($custom != '') $custom .= '/';
583
+			if ($custom != '') {
584
+				$custom .= '/';
585
+			}
502 586
 			$custom .= 'IMO='.$imo;
503 587
 		}
504 588
 		if ($arrival_date != '') {
505
-			if ($custom != '') $custom .= '/';
589
+			if ($custom != '') {
590
+				$custom .= '/';
591
+			}
506 592
 			$custom .= 'AD='.$arrival_date;
507 593
 		}
508 594
 		if ($arrival_code != '') {
509
-			if ($custom != '') $custom .= '/';
595
+			if ($custom != '') {
596
+				$custom .= '/';
597
+			}
510 598
 			$custom .= 'AC='.$arrival_code;
511 599
 		}
512
-		if ($custom != '') $custom = ' '.$custom;
600
+		if ($custom != '') {
601
+			$custom = ' '.$custom;
602
+		}
513 603
 		$altitude = 0;
514 604
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
515 605
 		}
Please login to merge, or discard this patch.
require/class.Common.php 4 patches
Doc Comments   +12 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,6 +90,10 @@  discard block
 block discarded – undo
90 90
 		return strlen($headerLine); // Needed by curl
91 91
 	}
92 92
 
93
+	/**
94
+	 * @param string $url
95
+	 * @param string $file
96
+	 */
93 97
 	public static function download($url, $file, $referer = '') {
94 98
 		global $globalDebug;
95 99
 		$fp = fopen($file, 'w');
@@ -190,7 +194,7 @@  discard block
 block discarded – undo
190 194
 	* Check is distance realistic
191 195
 	* @param int $timeDifference the time between the reception of both messages
192 196
 	* @param float $distance distance covered
193
-	* @return whether distance is realistic
197
+	* @return boolean distance is realistic
194 198
 	*/
195 199
 	public function withinThreshold ($timeDifference, $distance) {
196 200
 		$x = abs($timeDifference);
@@ -213,6 +217,9 @@  discard block
 block discarded – undo
213 217
 	}
214 218
 
215 219
 
220
+	/**
221
+	 * @param string $latlong
222
+	 */
216 223
 	public function convertDec($dms,$latlong) {
217 224
 		if ($latlong == 'latitude') {
218 225
 			$deg = substr($dms, 0, 2);
@@ -224,6 +231,9 @@  discard block
 block discarded – undo
224 231
 		return $deg+(($min*60)/3600);
225 232
 	}
226 233
 	
234
+	/**
235
+	 * @param string $latlong
236
+	 */
227 237
 	public function convertDM($coord,$latlong) {
228 238
 		if ($latlong == 'latitude') {
229 239
 			if ($coord < 0) $NSEW = 'S';
@@ -352,7 +362,7 @@  discard block
 block discarded – undo
352 362
 	/**
353 363
 	* Returns list of available locales
354 364
 	*
355
-	* @return array
365
+	* @return string[]
356 366
 	 */
357 367
 	public function listLocaleDir()
358 368
 	{
Please login to merge, or discard this patch.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 	//protected $cookies = array();
8 8
 	
9 9
 	/**
10
-	* Get data from form result
11
-	* @param String $url form URL
12
-	* @param String $type type of submit form method (get or post)
13
-	* @param String|Array $data values form post method
14
-	* @param Array $headers header to submit with the form
15
-	* @return String the result
16
-	*/
10
+	 * Get data from form result
11
+	 * @param String $url form URL
12
+	 * @param String $type type of submit form method (get or post)
13
+	 * @param String|Array $data values form post method
14
+	 * @param Array $headers header to submit with the form
15
+	 * @return String the result
16
+	 */
17 17
 	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	}
108 108
 	
109 109
 	/**
110
-	* Convert a HTML table to an array
111
-	* @param String $data HTML page
112
-	* @return Array array of the tables in HTML page
113
-	*/
110
+	 * Convert a HTML table to an array
111
+	 * @param String $data HTML page
112
+	 * @return Array array of the tables in HTML page
113
+	 */
114 114
 	public function table2array($data) {
115 115
 		if (!is_string($data)) return array();
116 116
 		if ($data == '') return array();
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 	
146 146
 	/**
147
-	* Convert <p> part of a HTML page to an array
148
-	* @param String $data HTML page
149
-	* @return Array array of the <p> in HTML page
150
-	*/
147
+	 * Convert <p> part of a HTML page to an array
148
+	 * @param String $data HTML page
149
+	 * @return Array array of the <p> in HTML page
150
+	 */
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
@@ -162,14 +162,14 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 
164 164
 	/**
165
-	* Give distance between 2 coordonnates
166
-	* @param Float $lat latitude of first point
167
-	* @param Float $lon longitude of first point
168
-	* @param Float $latc latitude of second point
169
-	* @param Float $lonc longitude of second point
170
-	* @param String $unit km else no unit used
171
-	* @return Float Distance in $unit
172
-	*/
165
+	 * Give distance between 2 coordonnates
166
+	 * @param Float $lat latitude of first point
167
+	 * @param Float $lon longitude of first point
168
+	 * @param Float $latc latitude of second point
169
+	 * @param Float $lonc longitude of second point
170
+	 * @param String $unit km else no unit used
171
+	 * @return Float Distance in $unit
172
+	 */
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175 175
 		$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;
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 	}
188 188
 
189 189
 	/**
190
-	* Check is distance realistic
191
-	* @param int $timeDifference the time between the reception of both messages
192
-	* @param float $distance distance covered
193
-	* @return whether distance is realistic
194
-	*/
190
+	 * Check is distance realistic
191
+	 * @param int $timeDifference the time between the reception of both messages
192
+	 * @param float $distance distance covered
193
+	 * @return whether distance is realistic
194
+	 */
195 195
 	public function withinThreshold ($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	}
210 210
 
211 211
 	public function isInteger($input){
212
-	    return(ctype_digit(strval($input)));
212
+		return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 	}
241 241
 	
242 242
 	/**
243
-	* Copy folder contents
244
-	* @param       string   $source    Source path
245
-	* @param       string   $dest      Destination path
246
-	* @return      bool     Returns true on success, false on failure
247
-	*/
243
+	 * Copy folder contents
244
+	 * @param       string   $source    Source path
245
+	 * @param       string   $dest      Destination path
246
+	 * @return      bool     Returns true on success, false on failure
247
+	 */
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
@@ -256,20 +256,20 @@  discard block
 block discarded – undo
256 256
 	}
257 257
 	
258 258
 	/**
259
-	* Check if an url exist
260
-	* @param	String $url url to check
261
-	* @return	bool Return true on succes false on failure
262
-	*/
259
+	 * Check if an url exist
260
+	 * @param	String $url url to check
261
+	 * @return	bool Return true on succes false on failure
262
+	 */
263 263
 	public function urlexist($url){
264 264
 		$headers=get_headers($url);
265 265
 		return stripos($headers[0],"200 OK")?true:false;
266 266
 	}
267 267
 	
268 268
 	/**
269
-	* Convert hexa to string
270
-	* @param	String $hex data in hexa
271
-	* @return	String Return result
272
-	*/
269
+	 * Convert hexa to string
270
+	 * @param	String $hex data in hexa
271
+	 * @return	String Return result
272
+	 */
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	}
351 351
 	
352 352
 	/**
353
-	* Returns list of available locales
354
-	*
355
-	* @return array
353
+	 * Returns list of available locales
354
+	 *
355
+	 * @return array
356 356
 	 */
357 357
 	public function listLocaleDir()
358 358
 	{
@@ -447,100 +447,100 @@  discard block
 block discarded – undo
447 447
 	public function remove_accents($string) {
448 448
 		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
449 449
 		$chars = array(
450
-		    // Decompositions for Latin-1 Supplement
451
-		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
-		    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
-		    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
-		    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
-		    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
-		    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
-		    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
-		    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
-		    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
-		    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
-		    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
-		    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
-		    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
-		    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
-		    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
-		    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
-		    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
-		    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
-		    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
-		    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
-		    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
-		    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
-		    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
-		    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
-		    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
-		    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
-		    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
-		    chr(195).chr(191) => 'y',
479
-		    // Decompositions for Latin Extended-A
480
-		    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
-		    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
-		    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
-		    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
-		    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
-		    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
-		    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
-		    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
-		    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
-		    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
-		    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
-		    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
-		    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
-		    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
-		    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
-		    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
-		    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
-		    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
-		    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
-		    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
-		    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
-		    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
-		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
-		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
-		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
-		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
-		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
-		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
-		    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
-		    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
-		    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
-		    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
-		    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
-		    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
-		    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
-		    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
-		    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
-		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
-		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
-		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
-		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
-		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
-		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
-		    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
-		    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
-		    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
-		    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
-		    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
-		    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
-		    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
-		    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
-		    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
-		    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
-		    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
-		    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
-		    chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
450
+			// Decompositions for Latin-1 Supplement
451
+			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
+			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
+			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
+			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
+			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
+			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
+			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
+			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
+			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
+			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
+			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
+			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
+			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
+			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
+			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
+			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
+			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
+			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
+			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
+			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
+			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
+			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
+			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
+			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
+			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
+			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
+			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
+			chr(195).chr(191) => 'y',
479
+			// Decompositions for Latin Extended-A
480
+			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
+			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
+			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
+			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
+			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
+			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
+			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
+			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
+			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
+			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
+			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
+			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
+			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
+			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
+			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
+			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
+			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
+			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
+			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
+			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
+			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
+			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
+			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
+			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
+			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
+			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
+			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
+			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
+			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
+			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
+			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
+			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
+			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
+			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
+			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
+			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
+			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
+			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
+			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
+			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
+			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
+			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
+			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
+			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
+			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
+			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
+			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
+			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
+			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
+			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
+			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
+			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
+			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
+			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
+			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
+			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
+			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
+			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
+			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
+			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
+			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
+			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
+			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
+			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
544 544
 		);
545 545
 		$string = strtr($string, $chars);
546 546
 		return $string;
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
 	* @param Array $headers header to submit with the form
15 15
 	* @return String the result
16 16
 	*/
17
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
17
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
20 20
 		curl_setopt($ch, CURLOPT_URL, $url);
21 21
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
22
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
23 23
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 24
 			}
25 25
 		}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30 30
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31 31
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
32
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
33 33
 		//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');
34 34
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35 35
 		if ($useragent == '') {
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41 41
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
42
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
43 43
 		if ($type == 'post') {
44 44
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45 45
 			if (is_array($data)) {
46 46
 				curl_setopt($ch, CURLOPT_POST, count($data));
47 47
 				$data_string = '';
48
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
48
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49 49
 				rtrim($data_string, '&');
50 50
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51 51
 			} else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($cookie != '') {
59 59
 			if (is_array($cookie)) {
60
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
60
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
61 61
 			} else {
62 62
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63 63
 			}
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 		$info = curl_getinfo($ch);
70 70
 		//var_dump($info);
71 71
 		curl_close($ch);
72
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
72
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
73 73
 			echo "Cloudflare Detected\n";
74 74
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
75 75
 			$useragent = UAgent::random();
76 76
 			cloudflare::useUserAgent($useragent);
77 77
 			if ($clearanceCookie = cloudflare::bypass($url)) {
78
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
78
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
79 79
 			}
80 80
 		} else {
81 81
 			return $result;
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
 		if ($data == '') return array();
117 117
 		$html = str_get_html($data);
118 118
 		if ($html === false) return array();
119
-		$tabledata=array();
120
-		foreach($html->find('tr') as $element)
119
+		$tabledata = array();
120
+		foreach ($html->find('tr') as $element)
121 121
 		{
122 122
 			$td = array();
123
-			foreach( $element->find('th') as $row)
123
+			foreach ($element->find('th') as $row)
124 124
 			{
125 125
 				$td [] = trim($row->plaintext);
126 126
 			}
127
-			$td=array_filter($td);
127
+			$td = array_filter($td);
128 128
 			$tabledata[] = $td;
129 129
 
130 130
 			$td = array();
131 131
 			$tdi = array();
132
-			foreach( $element->find('td') as $row)
132
+			foreach ($element->find('td') as $row)
133 133
 			{
134 134
 				$td [] = trim($row->plaintext);
135 135
 				$tdi [] = trim($row->innertext);
136 136
 			}
137
-			$td=array_filter($td);
138
-			$tdi=array_filter($tdi);
139
-			$tabledata[]=array_merge($td,$tdi);
137
+			$td = array_filter($td);
138
+			$tdi = array_filter($tdi);
139
+			$tabledata[] = array_merge($td, $tdi);
140 140
 		}
141 141
 		$html->clear();
142 142
 		unset($html);
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
154
-		$tabledata=array();
155
-		foreach($html->find('p') as $element)
154
+		$tabledata = array();
155
+		foreach ($html->find('p') as $element)
156 156
 		{
157 157
 			$tabledata [] = trim($element->plaintext);
158 158
 		}
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	*/
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175
-		$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;
175
+		$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;
176 176
 		if ($unit == "km") {
177
-			return round($dist * 1.609344);
177
+			return round($dist*1.609344);
178 178
 		} elseif ($unit == "m") {
179
-			return round($dist * 1.609344 * 1000);
179
+			return round($dist*1.609344*1000);
180 180
 		} elseif ($unit == "mile" || $unit == "mi") {
181 181
 			return round($dist);
182 182
 		} elseif ($unit == "nm") {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	* @param float $distance distance covered
193 193
 	* @return whether distance is realistic
194 194
 	*/
195
-	public function withinThreshold ($timeDifference, $distance) {
195
+	public function withinThreshold($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
198 198
 		if ($x == 0 || $d == 0) return true;
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 		return ($array !== array_values($array));
209 209
 	}
210 210
 
211
-	public function isInteger($input){
211
+	public function isInteger($input) {
212 212
 	    return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
216
-	public function convertDec($dms,$latlong) {
216
+	public function convertDec($dms, $latlong) {
217 217
 		if ($latlong == 'latitude') {
218 218
 			$deg = substr($dms, 0, 2);
219 219
 			$min = substr($dms, 2, 4);
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 			$deg = substr($dms, 0, 3);
222 222
 			$min = substr($dms, 3, 5);
223 223
 		}
224
-		return $deg+(($min*60)/3600);
224
+		return $deg + (($min*60)/3600);
225 225
 	}
226 226
 	
227
-	public function convertDM($coord,$latlong) {
227
+	public function convertDM($coord, $latlong) {
228 228
 		if ($latlong == 'latitude') {
229 229
 			if ($coord < 0) $NSEW = 'S';
230 230
 			else $NSEW = 'N';
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 		$coord = abs($coord);
236 236
 		$deg = floor($coord);
237
-		$coord = ($coord-$deg)*60;
237
+		$coord = ($coord - $deg)*60;
238 238
 		$min = $coord;
239
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
239
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
240 240
 	}
241 241
 	
242 242
 	/**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
251
-		foreach($files as $file){
252
-			$file_to_go = str_replace($source,$dest,$file);
251
+		foreach ($files as $file) {
252
+			$file_to_go = str_replace($source, $dest, $file);
253 253
 			copy($file, $file_to_go);
254 254
 		}
255 255
 		return true;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	* @param	String $url url to check
261 261
 	* @return	bool Return true on succes false on failure
262 262
 	*/
263
-	public function urlexist($url){
264
-		$headers=get_headers($url);
265
-		return stripos($headers[0],"200 OK")?true:false;
263
+	public function urlexist($url) {
264
+		$headers = get_headers($url);
265
+		return stripos($headers[0], "200 OK") ? true : false;
266 266
 	}
267 267
 	
268 268
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
276
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
276
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
277 277
 		return $str;
278 278
 	}
279 279
 	
@@ -282,33 +282,33 @@  discard block
 block discarded – undo
282 282
 		//difference in longitudinal coordinates
283 283
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
284 284
 		//difference in the phi of latitudinal coordinates
285
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
285
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
286 286
 		//we need to recalculate $dLon if it is greater than pi
287
-		if(abs($dLon) > pi()) {
288
-			if($dLon > 0) {
289
-				$dLon = (2 * pi() - $dLon) * -1;
287
+		if (abs($dLon) > pi()) {
288
+			if ($dLon > 0) {
289
+				$dLon = (2*pi() - $dLon)*-1;
290 290
 			} else {
291
-				$dLon = 2 * pi() + $dLon;
291
+				$dLon = 2*pi() + $dLon;
292 292
 			}
293 293
 		}
294 294
 		//return the angle, normalized
295
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
295
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
296 296
 	}
297 297
 	
298
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
298
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.2) {
299 299
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
300
-		$a = -($lon2-$lon1);
300
+		$a = -($lon2 - $lon1);
301 301
 		$b = $lat2 - $lat1;
302
-		$c = -($a*$lat1+$b*$lon1);
303
-		$d = $a*$lat3+$b*$lon3+$c;
302
+		$c = -($a*$lat1 + $b*$lon1);
303
+		$d = $a*$lat3 + $b*$lon3 + $c;
304 304
 		if ($d > -$approx && $d < $approx) return true;
305 305
 		else return false;
306 306
 	}
307 307
 	
308 308
 	public function array_merge_noappend() {
309 309
 		$output = array();
310
-		foreach(func_get_args() as $array) {
311
-			foreach($array as $key => $value) {
310
+		foreach (func_get_args() as $array) {
311
+			foreach ($array as $key => $value) {
312 312
 				$output[$key] = isset($output[$key]) ?
313 313
 				array_merge($output[$key], $value) : $value;
314 314
 			}
@@ -372,34 +372,34 @@  discard block
 block discarded – undo
372 372
 		return $result;
373 373
 	}
374 374
 
375
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
375
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
376 376
 		global $globalMapRefresh;
377 377
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
378 378
 		$r = 6378;
379 379
 		$latitude = deg2rad($latitude);
380 380
 		$longitude = deg2rad($longitude);
381 381
 		$bearing = deg2rad($heading); 
382
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
383
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
384
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
382
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
383
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
384
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
385 385
 	}
386 386
 	
387
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
387
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
388 388
 		// distance in meter
389 389
 		$R = 6378.14;
390
-		$latitude1 = $latitude * (M_PI/180);
391
-		$longitude1 = $longitude * (M_PI/180);
392
-		$brng = $bearing * (M_PI/180);
390
+		$latitude1 = $latitude*(M_PI/180);
391
+		$longitude1 = $longitude*(M_PI/180);
392
+		$brng = $bearing*(M_PI/180);
393 393
 		$d = $distance;
394 394
 
395 395
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
396
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
396
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
397 397
 
398
-		$latitude2 = $latitude2 * (180/M_PI);
399
-		$longitude2 = $longitude2 * (180/M_PI);
398
+		$latitude2 = $latitude2*(180/M_PI);
399
+		$longitude2 = $longitude2*(180/M_PI);
400 400
 
401
-		$flat = round ($latitude2,6);
402
-		$flong = round ($longitude2,6);
401
+		$flat = round($latitude2, 6);
402
+		$flong = round($longitude2, 6);
403 403
 /*
404 404
 		$dx = $distance*cos($bearing);
405 405
 		$dy = $distance*sin($bearing);
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		$flong = $longitude + $dlong;
409 409
 		$flat = $latitude + $dlat;
410 410
 */
411
-		return array('latitude' => $flat,'longitude' => $flong);
411
+		return array('latitude' => $flat, 'longitude' => $flong);
412 412
 	}
413 413
 
414 414
 	/**
@@ -422,14 +422,14 @@  discard block
 block discarded – undo
422 422
 	 * @param integer $level GZIP compression level (default: 9)
423 423
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
424 424
 	 */
425
-	public function gzCompressFile($source, $level = 9){ 
426
-		$dest = $source . '.gz'; 
427
-		$mode = 'wb' . $level; 
425
+	public function gzCompressFile($source, $level = 9) { 
426
+		$dest = $source.'.gz'; 
427
+		$mode = 'wb'.$level; 
428 428
 		$error = false; 
429 429
 		if ($fp_out = gzopen($dest, $mode)) { 
430
-			if ($fp_in = fopen($source,'rb')) { 
430
+			if ($fp_in = fopen($source, 'rb')) { 
431 431
 				while (!feof($fp_in)) 
432
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
432
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
433 433
 				fclose($fp_in); 
434 434
 			} else {
435 435
 				$error = true; 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	} 
446 446
 	
447 447
 	public function remove_accents($string) {
448
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
448
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
449 449
 		$chars = array(
450 450
 		    // Decompositions for Latin-1 Supplement
451 451
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503 503
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504 504
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
505
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
506 506
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507 507
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508 508
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519 519
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520 520
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
521
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
522
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
523
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
524
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
525
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
526
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
527
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
528 528
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529 529
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530 530
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
559 559
 			if (is_numeric($string[$i]) && $concat_flag) {
560 560
 				$int .= $string[$i];
561
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
561
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
562 562
 				$concat_flag = false;
563 563
 			}
564 564
 		}
Please login to merge, or discard this patch.
Braces   +73 added lines, -30 removed lines patch added patch discarded remove patch
@@ -37,8 +37,11 @@  discard block
 block discarded – undo
37 37
 		} else {
38 38
 			curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
39 39
 		}
40
-		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41
-		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
40
+		if ($timeout == '') {
41
+			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
42
+		} else {
43
+			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
44
+		}
42 45
 		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
43 46
 		if ($type == 'post') {
44 47
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -85,8 +88,9 @@  discard block
 block discarded – undo
85 88
 	private function curlResponseHeaderCallback($ch, $headerLine) {
86 89
 		//global $cookies;
87 90
 		$cookies = array();
88
-		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
89
-			$cookies[] = $cookie;
91
+		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) {
92
+					$cookies[] = $cookie;
93
+		}
90 94
 		return strlen($headerLine); // Needed by curl
91 95
 	}
92 96
 
@@ -97,11 +101,15 @@  discard block
 block discarded – undo
97 101
 		curl_setopt($ch, CURLOPT_URL, $url);
98 102
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
99 103
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
100
-		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
104
+		if ($referer != '') {
105
+			curl_setopt($ch, CURLOPT_REFERER, $referer);
106
+		}
101 107
 		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');
102 108
 		curl_setopt($ch, CURLOPT_FILE, $fp);
103 109
 		curl_exec($ch);
104
-		if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch);
110
+		if (curl_errno($ch) && $globalDebug) {
111
+			echo 'Download error: '.curl_error($ch);
112
+		}
105 113
 		curl_close($ch);
106 114
 		fclose($fp);
107 115
 	}
@@ -112,10 +120,16 @@  discard block
 block discarded – undo
112 120
 	* @return Array array of the tables in HTML page
113 121
 	*/
114 122
 	public function table2array($data) {
115
-		if (!is_string($data)) return array();
116
-		if ($data == '') return array();
123
+		if (!is_string($data)) {
124
+			return array();
125
+		}
126
+		if ($data == '') {
127
+			return array();
128
+		}
117 129
 		$html = str_get_html($data);
118
-		if ($html === false) return array();
130
+		if ($html === false) {
131
+			return array();
132
+		}
119 133
 		$tabledata=array();
120 134
 		foreach($html->find('tr') as $element)
121 135
 		{
@@ -150,7 +164,9 @@  discard block
 block discarded – undo
150 164
 	*/
151 165
 	public function text2array($data) {
152 166
 		$html = str_get_html($data);
153
-		if ($html === false) return array();
167
+		if ($html === false) {
168
+			return array();
169
+		}
154 170
 		$tabledata=array();
155 171
 		foreach($html->find('p') as $element)
156 172
 		{
@@ -171,7 +187,9 @@  discard block
 block discarded – undo
171 187
 	* @return Float Distance in $unit
172 188
 	*/
173 189
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174
-		if ($lat == $latc && $lon == $lonc) return 0;
190
+		if ($lat == $latc && $lon == $lonc) {
191
+			return 0;
192
+		}
175 193
 		$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;
176 194
 		if ($unit == "km") {
177 195
 			return round($dist * 1.609344);
@@ -195,10 +213,16 @@  discard block
 block discarded – undo
195 213
 	public function withinThreshold ($timeDifference, $distance) {
196 214
 		$x = abs($timeDifference);
197 215
 		$d = abs($distance);
198
-		if ($x == 0 || $d == 0) return true;
216
+		if ($x == 0 || $d == 0) {
217
+			return true;
218
+		}
199 219
 		// may be due to Internet jitter; distance is realistic
200
-		if ($x < 0.7 && $d < 2000) return true;
201
-		else return $d/$x < 1500*0.27778; // 1500 km/h max
220
+		if ($x < 0.7 && $d < 2000) {
221
+			return true;
222
+		} else {
223
+			return $d/$x < 1500*0.27778;
224
+		}
225
+		// 1500 km/h max
202 226
 	}
203 227
 
204 228
 
@@ -226,11 +250,17 @@  discard block
 block discarded – undo
226 250
 	
227 251
 	public function convertDM($coord,$latlong) {
228 252
 		if ($latlong == 'latitude') {
229
-			if ($coord < 0) $NSEW = 'S';
230
-			else $NSEW = 'N';
253
+			if ($coord < 0) {
254
+				$NSEW = 'S';
255
+			} else {
256
+				$NSEW = 'N';
257
+			}
231 258
 		} elseif ($latlong == 'longitude') {
232
-			if ($coord < 0) $NSEW = 'W';
233
-			else $NSEW = 'E';
259
+			if ($coord < 0) {
260
+				$NSEW = 'W';
261
+			} else {
262
+				$NSEW = 'E';
263
+			}
234 264
 		}
235 265
 		$coord = abs($coord);
236 266
 		$deg = floor($coord);
@@ -273,7 +303,9 @@  discard block
 block discarded – undo
273 303
 	public function hex2str($hex) {
274 304
 		$str = '';
275 305
 		$hexln = strlen($hex);
276
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
306
+		for($i=0;$i<$hexln;$i+=2) {
307
+			$str .= chr(hexdec(substr($hex,$i,2)));
308
+		}
277 309
 		return $str;
278 310
 	}
279 311
 	
@@ -301,8 +333,11 @@  discard block
 block discarded – undo
301 333
 		$b = $lat2 - $lat1;
302 334
 		$c = -($a*$lat1+$b*$lon1);
303 335
 		$d = $a*$lat3+$b*$lon3+$c;
304
-		if ($d > -$approx && $d < $approx) return true;
305
-		else return false;
336
+		if ($d > -$approx && $d < $approx) {
337
+			return true;
338
+		} else {
339
+			return false;
340
+		}
306 341
 	}
307 342
 	
308 343
 	public function array_merge_noappend() {
@@ -361,7 +396,9 @@  discard block
 block discarded – undo
361 396
 			return $result;
362 397
 		}
363 398
 		$handle = @opendir('./locale');
364
-		if ($handle === false) return $result;
399
+		if ($handle === false) {
400
+			return $result;
401
+		}
365 402
 		while (false !== ($file = readdir($handle))) {
366 403
 			$path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo';
367 404
 			if ($file != "." && $file != ".." && @file_exists($path)) {
@@ -428,8 +465,9 @@  discard block
 block discarded – undo
428 465
 		$error = false; 
429 466
 		if ($fp_out = gzopen($dest, $mode)) { 
430 467
 			if ($fp_in = fopen($source,'rb')) { 
431
-				while (!feof($fp_in)) 
432
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
468
+				while (!feof($fp_in)) {
469
+									gzwrite($fp_out, fread($fp_in, 1024 * 512));
470
+				}
433 471
 				fclose($fp_in); 
434 472
 			} else {
435 473
 				$error = true; 
@@ -438,14 +476,17 @@  discard block
 block discarded – undo
438 476
 		} else {
439 477
 			$error = true; 
440 478
 		}
441
-		if ($error)
442
-			return false; 
443
-		else
444
-			return $dest; 
479
+		if ($error) {
480
+					return false;
481
+		} else {
482
+					return $dest;
483
+		}
445 484
 	} 
446 485
 	
447 486
 	public function remove_accents($string) {
448
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
487
+		if ( !preg_match('/[\x80-\xff]/', $string) ) {
488
+			return $string;
489
+		}
449 490
 		$chars = array(
450 491
 		    // Decompositions for Latin-1 Supplement
451 492
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -569,7 +610,9 @@  discard block
 block discarded – undo
569 610
 		$ip = gethostbyname($host);
570 611
 		$s = socket_create(AF_INET, SOCK_STREAM, 0);
571 612
 		$r = @socket_connect($s, $ip, $port);
572
-		if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
613
+		if (!socket_set_nonblock($s)) {
614
+			echo "Unable to set nonblock on socket\n";
615
+		}
573 616
 		if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
574 617
 			return $s;
575 618
 		}
Please login to merge, or discard this patch.
require/class.Marine.php 3 patches
Doc Comments   +2 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	* Get SQL query part for filter used
17 17
 	* @param Array $filter the filter
18
-	* @return Array the SQL part
18
+	* @return string the SQL part
19 19
 	*/
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
@@ -552,25 +552,6 @@  discard block
 block discarded – undo
552 552
 	*
553 553
 	* @param String $fammarine_id the ID
554 554
 	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574 555
 	*/
575 556
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 557
 	{
@@ -1444,7 +1425,7 @@  discard block
 block discarded – undo
1444 1425
 	/**
1445 1426
 	* Parses the direction degrees to working
1446 1427
 	*
1447
-	* @param Float $direction the direction in degrees
1428
+	* @param integer $direction the direction in degrees
1448 1429
 	* @return Array the direction information
1449 1430
 	*
1450 1431
 	*/
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	/**
83
-	* Executes the SQL statements to get the spotter information
84
-	*
85
-	* @param String $query the SQL query
86
-	* @param Array $params parameter of the query
87
-	* @param String $limitQuery the limit query
88
-	* @return Array the spotter information
89
-	*
90
-	*/
83
+	 * Executes the SQL statements to get the spotter information
84
+	 *
85
+	 * @param String $query the SQL query
86
+	 * @param Array $params parameter of the query
87
+	 * @param String $limitQuery the limit query
88
+	 * @return Array the spotter information
89
+	 *
90
+	 */
91 91
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	
200 200
 	
201 201
 	/**
202
-	* Gets all the spotter information based on the latest data entry
203
-	*
204
-	* @return Array the spotter information
205
-	*
206
-	*/
202
+	 * Gets all the spotter information based on the latest data entry
203
+	 *
204
+	 * @return Array the spotter information
205
+	 *
206
+	 */
207 207
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
208 208
 	{
209 209
 		global $global_query;
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	/**
264
-	* Gets all the spotter information based on the callsign
265
-	*
266
-	* @return Array the spotter information
267
-	*
268
-	*/
264
+	 * Gets all the spotter information based on the callsign
265
+	 *
266
+	 * @return Array the spotter information
267
+	 *
268
+	 */
269 269
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
270 270
 	{
271 271
 		global $global_query;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 
378 378
 	/**
379
-	* Gets all source name
380
-	*
381
-	* @param String type format of source
382
-	* @return Array list of source name
383
-	*
384
-	*/
379
+	 * Gets all source name
380
+	 *
381
+	 * @param String type format of source
382
+	 * @return Array list of source name
383
+	 *
384
+	 */
385 385
 	public function getAllSourceName($type = '',$filters = array())
386 386
 	{
387 387
 		$filter_query = $this->getFilter($filters,true,true);
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 	/**
414
-	* Gets a list of all idents/callsigns
415
-	*
416
-	* @return Array list of ident/callsign names
417
-	*
418
-	*/
414
+	 * Gets a list of all idents/callsigns
415
+	 *
416
+	 * @return Array list of ident/callsign names
417
+	 *
418
+	 */
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421 421
 		$filter_query = $this->getFilter($filters,true,true);
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 
441 441
 	/**
442
-	* Gets all info from a mmsi
443
-	*
444
-	* @return Array list of mmsi info
445
-	*
446
-	*/
442
+	 * Gets all info from a mmsi
443
+	 *
444
+	 * @return Array list of mmsi info
445
+	 *
446
+	 */
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449 449
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	
502 502
 	/**
503
-	* Update ident tracker data
504
-	*
505
-	* @param String $fammarine_id the ID
506
-	* @param String $ident the marine ident
507
-	* @return String success or false
508
-	*
509
-	*/	
503
+	 * Update ident tracker data
504
+	 *
505
+	 * @param String $fammarine_id the ID
506
+	 * @param String $ident the marine ident
507
+	 * @return String success or false
508
+	 *
509
+	 */	
510 510
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
 	}
526 526
 	/**
527
-	* Update latest marine data
528
-	*
529
-	* @param String $fammarine_id the ID
530
-	* @param String $ident the marine ident
531
-	* @return String success or false
532
-	*
533
-	*/	
527
+	 * Update latest marine data
528
+	 *
529
+	 * @param String $fammarine_id the ID
530
+	 * @param String $ident the marine ident
531
+	 * @return String success or false
532
+	 *
533
+	 */	
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+				$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -548,30 +548,30 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 
550 550
 	/**
551
-	* Adds a new spotter data
552
-	*
553
-	* @param String $fammarine_id the ID
554
-	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574
-	*/
551
+	 * Adds a new spotter data
552
+	 *
553
+	 * @param String $fammarine_id the ID
554
+	 * @param String $ident the marine ident
555
+	 * @param String $departure_airport_icao the departure airport
556
+	 * @param String $arrival_airport_icao the arrival airport
557
+	 * @param String $latitude latitude of flight
558
+	 * @param String $longitude latitude of flight
559
+	 * @param String $waypoints waypoints of flight
560
+	 * @param String $heading heading of flight
561
+	 * @param String $groundspeed speed of flight
562
+	 * @param String $date date of flight
563
+	 * @param String $departure_airport_time departure time of flight
564
+	 * @param String $arrival_airport_time arrival time of flight
565
+	 * @param String $squawk squawk code of flight
566
+	 * @param String $route_stop route stop of flight
567
+	 * @param String $highlight highlight or not
568
+	 * @param String $ModeS ModesS code of flight
569
+	 * @param String $registration registration code of flight
570
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
571
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
572
+	 * @param String $verticalrate vertival rate of flight
573
+	 * @return String success or false
574
+	 */
575 575
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660 660
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
661 661
 	
662
-                if ($latitude == '' && $longitude == '') {
663
-            		$latitude = 0;
664
-            		$longitude = 0;
665
-            	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
662
+				if ($latitude == '' && $longitude == '') {
663
+					$latitude = 0;
664
+					$longitude = 0;
665
+				}
666
+				if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
+				if ($arrival_date == '') $arrival_date = NULL;
669 669
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			$sth->execute($query_values);
677 677
 			$this->db = null;
678 678
 		} catch (PDOException $e) {
679
-		    return "error : ".$e->getMessage();
679
+			return "error : ".$e->getMessage();
680 680
 		}
681 681
 		
682 682
 		return "success";
@@ -685,11 +685,11 @@  discard block
 block discarded – undo
685 685
 	
686 686
   
687 687
 	/**
688
-	* Gets the aircraft ident within the last hour
689
-	*
690
-	* @return String the ident
691
-	*
692
-	*/
688
+	 * Gets the aircraft ident within the last hour
689
+	 *
690
+	 * @return String the ident
691
+	 *
692
+	 */
693 693
 	public function getIdentFromLastHour($ident)
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
@@ -705,11 +705,11 @@  discard block
 block discarded – undo
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
707 707
 			$query_data = array(':ident' => $ident);
708
-    		}
708
+			}
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
712
+			$ident_result='';
713 713
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	
721 721
 	
722 722
 	/**
723
-	* Gets the aircraft data from the last 20 seconds
724
-	*
725
-	* @return Array the spotter data
726
-	*
727
-	*/
723
+	 * Gets the aircraft data from the last 20 seconds
724
+	 *
725
+	 * @return Array the spotter data
726
+	 *
727
+	 */
728 728
 	public function getRealTimeData($q = '')
729 729
 	{
730 730
 		global $globalDBdriver;
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 	
763 763
 
764 764
 	/**
765
-	* Gets all number of flight over countries
766
-	*
767
-	* @return Array the airline country list
768
-	*
769
-	*/
765
+	 * Gets all number of flight over countries
766
+	 *
767
+	 * @return Array the airline country list
768
+	 *
769
+	 */
770 770
 /*
771 771
 	public function countAllTrackedOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
772 772
 	{
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	
818 818
 	
819 819
 	/**
820
-	* Gets all callsigns that have flown over
821
-	*
822
-	* @return Array the callsign list
823
-	*
824
-	*/
820
+	 * Gets all callsigns that have flown over
821
+	 *
822
+	 * @return Array the callsign list
823
+	 *
824
+	 */
825 825
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
@@ -888,11 +888,11 @@  discard block
 block discarded – undo
888 888
 
889 889
 
890 890
 	/**
891
-	* Counts all dates
892
-	*
893
-	* @return Array the date list
894
-	*
895
-	*/
891
+	 * Counts all dates
892
+	 *
893
+	 * @return Array the date list
894
+	 *
895
+	 */
896 896
 	public function countAllDates($filters = array())
897 897
 	{
898 898
 		global $globalTimezone, $globalDBdriver;
@@ -938,11 +938,11 @@  discard block
 block discarded – undo
938 938
 	
939 939
 	
940 940
 	/**
941
-	* Counts all dates during the last 7 days
942
-	*
943
-	* @return Array the date list
944
-	*
945
-	*/
941
+	 * Counts all dates during the last 7 days
942
+	 *
943
+	 * @return Array the date list
944
+	 *
945
+	 */
946 946
 	public function countAllDatesLast7Days($filters = array())
947 947
 	{
948 948
 		global $globalTimezone, $globalDBdriver;
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 			$query .= " GROUP BY date_name 
965 965
 								ORDER BY date_name ASC";
966 966
 			$query_data = array(':offset' => $offset);
967
-    		}
967
+			}
968 968
 		
969 969
 		$sth = $this->db->prepare($query);
970 970
 		$sth->execute($query_data);
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
 	}
985 985
 
986 986
 	/**
987
-	* Counts all dates during the last month
988
-	*
989
-	* @return Array the date list
990
-	*
991
-	*/
987
+	 * Counts all dates during the last month
988
+	 *
989
+	 * @return Array the date list
990
+	 *
991
+	 */
992 992
 	public function countAllDatesLastMonth($filters = array())
993 993
 	{
994 994
 		global $globalTimezone, $globalDBdriver;
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 			$query .= " GROUP BY date_name 
1011 1011
 								ORDER BY date_name ASC";
1012 1012
 			$query_data = array(':offset' => $offset);
1013
-    		}
1013
+			}
1014 1014
 		
1015 1015
 		$sth = $this->db->prepare($query);
1016 1016
 		$sth->execute($query_data);
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 
1034 1034
 	/**
1035
-	* Counts all month
1036
-	*
1037
-	* @return Array the month list
1038
-	*
1039
-	*/
1035
+	 * Counts all month
1036
+	 *
1037
+	 * @return Array the month list
1038
+	 *
1039
+	 */
1040 1040
 	public function countAllMonths($filters = array())
1041 1041
 	{
1042 1042
 		global $globalTimezone, $globalDBdriver;
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
 	
1082 1082
 
1083 1083
 	/**
1084
-	* Counts all dates during the last year
1085
-	*
1086
-	* @return Array the date list
1087
-	*
1088
-	*/
1084
+	 * Counts all dates during the last year
1085
+	 *
1086
+	 * @return Array the date list
1087
+	 *
1088
+	 */
1089 1089
 	public function countAllMonthsLastYear($filters)
1090 1090
 	{
1091 1091
 		global $globalTimezone, $globalDBdriver;
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			$query .= " GROUP BY year_name, month_name
1108 1108
 								ORDER BY year_name, month_name ASC";
1109 1109
 			$query_data = array(':offset' => $offset);
1110
-    		}
1110
+			}
1111 1111
 		
1112 1112
 		$sth = $this->db->prepare($query);
1113 1113
 		$sth->execute($query_data);
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 	
1131 1131
 	
1132 1132
 	/**
1133
-	* Counts all hours
1134
-	*
1135
-	* @return Array the hour list
1136
-	*
1137
-	*/
1133
+	 * Counts all hours
1134
+	 *
1135
+	 * @return Array the hour list
1136
+	 *
1137
+	 */
1138 1138
 	public function countAllHours($orderby,$filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
@@ -1197,11 +1197,11 @@  discard block
 block discarded – undo
1197 1197
 	
1198 1198
 	
1199 1199
 	/**
1200
-	* Counts all hours by date
1201
-	*
1202
-	* @return Array the hour list
1203
-	*
1204
-	*/
1200
+	 * Counts all hours by date
1201
+	 *
1202
+	 * @return Array the hour list
1203
+	 *
1204
+	 */
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
@@ -1245,11 +1245,11 @@  discard block
 block discarded – undo
1245 1245
 	
1246 1246
 	
1247 1247
 	/**
1248
-	* Counts all hours by a ident/callsign
1249
-	*
1250
-	* @return Array the hour list
1251
-	*
1252
-	*/
1248
+	 * Counts all hours by a ident/callsign
1249
+	 *
1250
+	 * @return Array the hour list
1251
+	 *
1252
+	 */
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
@@ -1294,11 +1294,11 @@  discard block
 block discarded – undo
1294 1294
 	
1295 1295
 	
1296 1296
 	/**
1297
-	* Counts all flights that have flown over
1298
-	*
1299
-	* @return Integer the number of flights
1300
-	*
1301
-	*/
1297
+	 * Counts all flights that have flown over
1298
+	 *
1299
+	 * @return Integer the number of flights
1300
+	 *
1301
+	 */
1302 1302
 	public function countOverallTracked($filters = array(),$year = '',$month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
@@ -1333,11 +1333,11 @@  discard block
 block discarded – undo
1333 1333
 	
1334 1334
   
1335 1335
 	/**
1336
-	* Counts all hours of today
1337
-	*
1338
-	* @return Array the hour list
1339
-	*
1340
-	*/
1336
+	 * Counts all hours of today
1337
+	 *
1338
+	 * @return Array the hour list
1339
+	 *
1340
+	 */
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
@@ -1377,12 +1377,12 @@  discard block
 block discarded – undo
1377 1377
 	}
1378 1378
     
1379 1379
     
1380
-     /**
1381
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1382
-	*
1383
-	* @return Integer the Barrie Spotter ID
1380
+	 /**
1381
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1382
+	  *
1383
+	  * @return Integer the Barrie Spotter ID
1384 1384
 q	*
1385
-	*/
1385
+	  */
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388 1388
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1403,13 +1403,13 @@  discard block
 block discarded – undo
1403 1403
   
1404 1404
  
1405 1405
 	/**
1406
-	* Parses a date string
1407
-	*
1408
-	* @param String $dateString the date string
1409
-	* @param String $timezone the timezone of a user
1410
-	* @return Array the time information
1411
-	*
1412
-	*/
1406
+	 * Parses a date string
1407
+	 *
1408
+	 * @param String $dateString the date string
1409
+	 * @param String $timezone the timezone of a user
1410
+	 * @return Array the time information
1411
+	 *
1412
+	 */
1413 1413
 	public function parseDateString($dateString, $timezone = '')
1414 1414
 	{
1415 1415
 		$time_array = array();
@@ -1442,12 +1442,12 @@  discard block
 block discarded – undo
1442 1442
 	}
1443 1443
 	
1444 1444
 	/**
1445
-	* Parses the direction degrees to working
1446
-	*
1447
-	* @param Float $direction the direction in degrees
1448
-	* @return Array the direction information
1449
-	*
1450
-	*/
1445
+	 * Parses the direction degrees to working
1446
+	 *
1447
+	 * @param Float $direction the direction in degrees
1448
+	 * @return Array the direction information
1449
+	 *
1450
+	 */
1451 1451
 	public function parseDirection($direction = 0)
1452 1452
 	{
1453 1453
 		if ($direction == '') $direction = 0;
@@ -1526,12 +1526,12 @@  discard block
 block discarded – undo
1526 1526
 	
1527 1527
 	
1528 1528
 	/**
1529
-	* Gets Country from latitude/longitude
1530
-	*
1531
-	* @param Float $latitude latitute of the flight
1532
-	* @param Float $longitude longitute of the flight
1533
-	* @return String the countrie
1534
-	*/
1529
+	 * Gets Country from latitude/longitude
1530
+	 *
1531
+	 * @param Float $latitude latitute of the flight
1532
+	 * @param Float $longitude longitute of the flight
1533
+	 * @return String the countrie
1534
+	 */
1535 1535
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
@@ -1568,11 +1568,11 @@  discard block
 block discarded – undo
1568 1568
 	}
1569 1569
 
1570 1570
 	/**
1571
-	* Gets Country from iso2
1572
-	*
1573
-	* @param String $iso2 ISO2 country code
1574
-	* @return String the countrie
1575
-	*/
1571
+	 * Gets Country from iso2
1572
+	 *
1573
+	 * @param String $iso2 ISO2 country code
1574
+	 * @return String the countrie
1575
+	 */
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
@@ -1601,12 +1601,12 @@  discard block
 block discarded – undo
1601 1601
 
1602 1602
 	
1603 1603
 	/**
1604
-	* Gets the short url from bit.ly
1605
-	*
1606
-	* @param String $url the full url
1607
-	* @return String the bit.ly url
1608
-	*
1609
-	*/
1604
+	 * Gets the short url from bit.ly
1605
+	 *
1606
+	 * @param String $url the full url
1607
+	 * @return String the bit.ly url
1608
+	 *
1609
+	 */
1610 1610
 	public function getBitlyURL($url)
1611 1611
 	{
1612 1612
 		global $globalBitlyAccessToken;
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 require_once(dirname(__FILE__).'/class.Image.php');
5 5
 $global_query = "SELECT marine_output.* FROM marine_output";
6 6
 
7
-class Marine{
7
+class Marine {
8 8
 	public $db;
9 9
 	
10 10
 	public function __construct($dbc = null) {
@@ -18,33 +18,33 @@  discard block
 block discarded – undo
18 18
 	* @return Array the SQL part
19 19
 	*/
20 20
 	
21
-	public function getFilter($filter = array(),$where = false,$and = false) {
21
+	public function getFilter($filter = array(), $where = false, $and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
23 23
 		$filters = array();
24 24
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
25 25
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
26 26
 				$filters = $globalStatsFilters[$globalFilterName];
27 27
 			} else {
28
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
28
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
29 29
 			}
30 30
 		}
31 31
 		if (isset($filter[0]['source'])) {
32
-			$filters = array_merge($filters,$filter);
32
+			$filters = array_merge($filters, $filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
35 35
 		$filter_query_join = '';
36 36
 		$filter_query_where = '';
37
-		foreach($filters as $flt) {
37
+		foreach ($filters as $flt) {
38 38
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
39 39
 				if (isset($flt['source'])) {
40
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
40
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_output.format_source IN ('".implode("','", $flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
41 41
 				} else {
42
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
42
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
43 43
 				}
44 44
 			}
45 45
 		}
46 46
 		if (isset($filter['source']) && !empty($filter['source'])) {
47
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
47
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
48 48
 		}
49 49
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
50 50
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74 74
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75 75
 		if ($filter_query_where != '') {
76
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
76
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
77 77
 		}
78 78
 		$filter_query = $filter_query_join.$filter_query_where;
79 79
 		return $filter_query;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	* @return Array the spotter information
89 89
 	*
90 90
 	*/
91
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
91
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
94 94
 		if (!is_string($query))
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 			$sth = $this->db->prepare($query.$limitQuery);
109 109
 			$sth->execute($params);
110 110
 		} catch (PDOException $e) {
111
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
111
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
112 112
 			exit();
113 113
 		}
114 114
 		
115 115
 		$num_rows = 0;
116 116
 		$spotter_array = array();
117
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
117
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
118 118
 		{
119 119
 			$num_rows++;
120 120
 			$temp_array = array();
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
 				{
170 170
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
171 171
 				} else {
172
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
172
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
173 173
 				}
174 174
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
175
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
176
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
175
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
176
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
177 177
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
178 178
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
179 179
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
180 180
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
181
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
182
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
181
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
182
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
183 183
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
184 184
 					}
185 185
 				}
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 		{
217 217
 			$limit_array = explode(",", $limit);
218 218
 			
219
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
220
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
219
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
220
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
221 221
 			
222 222
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
223 223
 			{
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 			$orderby_query = " ORDER BY marine_output.date DESC";
235 235
 		}
236 236
 
237
-		$query  = $global_query.$filter_query." ".$orderby_query;
237
+		$query = $global_query.$filter_query." ".$orderby_query;
238 238
 
239
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
239
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
240 240
 
241 241
 		return $spotter_array;
242 242
 	}
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 		if ($id == '') return array();
256 256
 		$additional_query = "marine_output.fammarine_id = :id";
257 257
 		$query_values = array(':id' => $id);
258
-		$query  = $global_query." WHERE ".$additional_query." ";
259
-		$spotter_array = $this->getDataFromDB($query,$query_values);
258
+		$query = $global_query." WHERE ".$additional_query." ";
259
+		$spotter_array = $this->getDataFromDB($query, $query_values);
260 260
 		return $spotter_array;
261 261
 	}
262 262
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		$query_values = array();
276 276
 		$limit_query = '';
277 277
 		$additional_query = '';
278
-		$filter_query = $this->getFilter($filter,true,true);
278
+		$filter_query = $this->getFilter($filter, true, true);
279 279
 		if ($ident != "")
280 280
 		{
281 281
 			if (!is_string($ident))
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 		{
292 292
 			$limit_array = explode(",", $limit);
293 293
 			
294
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
295
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
294
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
295
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
296 296
 			
297 297
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
298 298
 			{
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		return $spotter_array;
317 317
 	}
318 318
 	
319
-	public function getSpotterDataByDate($date = '', $limit = '', $sort = '',$filter = array())
319
+	public function getSpotterDataByDate($date = '', $limit = '', $sort = '', $filter = array())
320 320
 	{
321 321
 		global $global_query, $globalTimezone, $globalDBdriver;
322 322
 		
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 		$limit_query = '';
325 325
 		$additional_query = '';
326 326
 
327
-		$filter_query = $this->getFilter($filter,true,true);
327
+		$filter_query = $this->getFilter($filter, true, true);
328 328
 		
329 329
 		if ($date != "")
330 330
 		{
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 		{
351 351
 			$limit_array = explode(",", $limit);
352 352
 			
353
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
354
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
353
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
354
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
355 355
 			
356 356
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
357 357
 			{
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	* @return Array list of source name
383 383
 	*
384 384
 	*/
385
-	public function getAllSourceName($type = '',$filters = array())
385
+	public function getAllSourceName($type = '', $filters = array())
386 386
 	{
387
-		$filter_query = $this->getFilter($filters,true,true);
387
+		$filter_query = $this->getFilter($filters, true, true);
388 388
 		$query_values = array();
389
-		$query  = "SELECT DISTINCT marine_output.source_name 
389
+		$query = "SELECT DISTINCT marine_output.source_name 
390 390
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
391 391
 		if ($type != '') {
392 392
 			$query_values = array(':type' => $type);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 		$source_array = array();
402 402
 		$temp_array = array();
403 403
 		
404
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
404
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
405 405
 		{
406 406
 			$temp_array['source_name'] = $row['source_name'];
407 407
 			$source_array[] = $temp_array;
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	*/
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421
-		$filter_query = $this->getFilter($filters,true,true);
422
-		$query  = "SELECT DISTINCT marine_output.ident
421
+		$filter_query = $this->getFilter($filters, true, true);
422
+		$query = "SELECT DISTINCT marine_output.ident
423 423
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
424 424
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
425 425
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		$ident_array = array();
430 430
 		$temp_array = array();
431 431
 		
432
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
432
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
433 433
 		{
434 434
 			$temp_array['ident'] = $row['ident'];
435 435
 			$ident_array[] = $temp_array;
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	*/
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
449
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
450 450
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
451 451
 		$sth = $this->db->prepare($query);
452 452
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -471,12 +471,12 @@  discard block
 block discarded – undo
471 471
 		} else $offset = '+00:00';
472 472
 
473 473
 		if ($globalDBdriver == 'mysql') {
474
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
474
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
475 475
 								FROM marine_output
476 476
 								WHERE marine_output.date <> '' 
477 477
 								ORDER BY marine_output.date ASC LIMIT 0,200";
478 478
 		} else {
479
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
479
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
480 480
 								FROM marine_output
481 481
 								WHERE marine_output.date <> '' 
482 482
 								ORDER BY marine_output.date ASC LIMIT 0,200";
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		$date_array = array();
489 489
 		$temp_array = array();
490 490
 		
491
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
491
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
492 492
 		{
493 493
 			$temp_array['date'] = $row['date'];
494 494
 
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
 	* @return String success or false
508 508
 	*
509 509
 	*/	
510
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
510
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+                $query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	* @param String $verticalrate vertival rate of flight
573 573
 	* @return String success or false
574 574
 	*/
575
-	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
575
+	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
578 578
 		
@@ -639,25 +639,25 @@  discard block
 block discarded – undo
639 639
 		}
640 640
 
641 641
     
642
-		if ($date == "" || strtotime($date) < time()-20*60)
642
+		if ($date == "" || strtotime($date) < time() - 20*60)
643 643
 		{
644 644
 			$date = date("Y-m-d H:i:s", time());
645 645
 		}
646 646
 
647
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
648
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
649
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
650
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
651
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
652
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
653
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
654
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
655
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
656
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
657
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
658
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
659
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
647
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
648
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
649
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
650
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
651
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
652
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
653
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
654
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
655
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
656
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
657
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
658
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
659
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
660
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
661 661
 	
662 662
                 if ($latitude == '' && $longitude == '') {
663 663
             		$latitude = 0;
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
                 if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667 667
                 if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668 668
                 if ($arrival_date == '') $arrival_date = NULL;
669
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
669
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
672
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
672
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
673 673
 		try {
674 674
 		        
675 675
 			$sth = $this->db->prepare($query);
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
696 696
 		if ($globalDBdriver == 'mysql') {
697
-			$query  = "SELECT marine_output.ident FROM marine_output 
697
+			$query = "SELECT marine_output.ident FROM marine_output 
698 698
 								WHERE marine_output.ident = :ident 
699 699
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
700 700
 								AND marine_output.date < UTC_TIMESTAMP()";
701 701
 			$query_data = array(':ident' => $ident);
702 702
 		} else {
703
-			$query  = "SELECT marine_output.ident FROM marine_output 
703
+			$query = "SELECT marine_output.ident FROM marine_output 
704 704
 								WHERE marine_output.ident = :ident 
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -709,8 +709,8 @@  discard block
 block discarded – undo
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
713
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
712
+    		$ident_result = '';
713
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
716 716
 		}
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 				return false;
737 737
 			} else {
738 738
 				$q_array = explode(" ", $q);
739
-				foreach ($q_array as $q_item){
740
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
739
+				foreach ($q_array as $q_item) {
740
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
741 741
 					$additional_query .= " AND (";
742 742
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
743 743
 					$additional_query .= ")";
@@ -745,11 +745,11 @@  discard block
 block discarded – undo
745 745
 			}
746 746
 		}
747 747
 		if ($globalDBdriver == 'mysql') {
748
-			$query  = "SELECT marine_output.* FROM marine_output 
748
+			$query = "SELECT marine_output.* FROM marine_output 
749 749
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
750 750
 				AND marine_output.date < UTC_TIMESTAMP()";
751 751
 		} else {
752
-			$query  = "SELECT marine_output.* FROM marine_output 
752
+			$query = "SELECT marine_output.* FROM marine_output 
753 753
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
754 754
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
755 755
 		}
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
 	* @return Array the callsign list
823 823
 	*
824 824
 	*/
825
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
825
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
828
-		$filter_query = $this->getFilter($filters,true,true);
829
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
828
+		$filter_query = $this->getFilter($filters, true, true);
829
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
830 830
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
831 831
 		 if ($olderthanmonths > 0) {
832 832
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -840,28 +840,28 @@  discard block
 block discarded – undo
840 840
 		if ($year != '') {
841 841
 			if ($globalDBdriver == 'mysql') {
842 842
 				$query .= " AND YEAR(marine_output.date) = :year";
843
-				$query_values = array_merge($query_values,array(':year' => $year));
843
+				$query_values = array_merge($query_values, array(':year' => $year));
844 844
 			} else {
845 845
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
846
-				$query_values = array_merge($query_values,array(':year' => $year));
846
+				$query_values = array_merge($query_values, array(':year' => $year));
847 847
 			}
848 848
 		}
849 849
 		if ($month != '') {
850 850
 			if ($globalDBdriver == 'mysql') {
851 851
 				$query .= " AND MONTH(marine_output.date) = :month";
852
-				$query_values = array_merge($query_values,array(':month' => $month));
852
+				$query_values = array_merge($query_values, array(':month' => $month));
853 853
 			} else {
854 854
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
855
-				$query_values = array_merge($query_values,array(':month' => $month));
855
+				$query_values = array_merge($query_values, array(':month' => $month));
856 856
 			}
857 857
 		}
858 858
 		if ($day != '') {
859 859
 			if ($globalDBdriver == 'mysql') {
860 860
 				$query .= " AND DAY(marine_output.date) = :day";
861
-				$query_values = array_merge($query_values,array(':day' => $day));
861
+				$query_values = array_merge($query_values, array(':day' => $day));
862 862
 			} else {
863 863
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
864
-				$query_values = array_merge($query_values,array(':day' => $day));
864
+				$query_values = array_merge($query_values, array(':day' => $day));
865 865
 			}
866 866
 		}
867 867
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		$callsign_array = array();
874 874
 		$temp_array = array();
875 875
         
876
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
876
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
877 877
 		{
878 878
 			$temp_array['callsign_icao'] = $row['ident'];
879 879
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		$date_array = array();
926 926
 		$temp_array = array();
927 927
         
928
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
928
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
929 929
 		{
930 930
 			$temp_array['date_name'] = $row['date_name'];
931 931
 			$temp_array['date_count'] = $row['date_count'];
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 			$datetime = new DateTime();
952 952
 			$offset = $datetime->format('P');
953 953
 		} else $offset = '+00:00';
954
-		$filter_query = $this->getFilter($filters,true,true);
954
+		$filter_query = $this->getFilter($filters, true, true);
955 955
 		if ($globalDBdriver == 'mysql') {
956 956
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
957 957
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
 		$date_array = array();
973 973
 		$temp_array = array();
974 974
         
975
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
975
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
976 976
 		{
977 977
 			$temp_array['date_name'] = $row['date_name'];
978 978
 			$temp_array['date_count'] = $row['date_count'];
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 			$datetime = new DateTime();
998 998
 			$offset = $datetime->format('P');
999 999
 		} else $offset = '+00:00';
1000
-		$filter_query = $this->getFilter($filters,true,true);
1000
+		$filter_query = $this->getFilter($filters, true, true);
1001 1001
 		if ($globalDBdriver == 'mysql') {
1002 1002
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1003 1003
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 		$date_array = array();
1019 1019
 		$temp_array = array();
1020 1020
         
1021
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1021
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1022 1022
 		{
1023 1023
 			$temp_array['date_name'] = $row['date_name'];
1024 1024
 			$temp_array['date_count'] = $row['date_count'];
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 		$date_array = array();
1066 1066
 		$temp_array = array();
1067 1067
         
1068
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1068
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1069 1069
 		{
1070 1070
 			$temp_array['month_name'] = $row['month_name'];
1071 1071
 			$temp_array['year_name'] = $row['year_name'];
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 			$datetime = new DateTime();
1095 1095
 			$offset = $datetime->format('P');
1096 1096
 		} else $offset = '+00:00';
1097
-		$filter_query = $this->getFilter($filters,true,true);
1097
+		$filter_query = $this->getFilter($filters, true, true);
1098 1098
 		if ($globalDBdriver == 'mysql') {
1099 1099
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
1100 1100
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 		$date_array = array();
1116 1116
 		$temp_array = array();
1117 1117
         
1118
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1118
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1119 1119
 		{
1120 1120
 			$temp_array['year_name'] = $row['year_name'];
1121 1121
 			$temp_array['month_name'] = $row['month_name'];
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 	* @return Array the hour list
1136 1136
 	*
1137 1137
 	*/
1138
-	public function countAllHours($orderby,$filters = array())
1138
+	public function countAllHours($orderby, $filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
1141 1141
 		if ($globalTimezone != '') {
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 		$hour_array = array();
1184 1184
 		$temp_array = array();
1185 1185
         
1186
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1186
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1187 1187
 		{
1188 1188
 			$temp_array['hour_name'] = $row['hour_name'];
1189 1189
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1205,8 +1205,8 @@  discard block
 block discarded – undo
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
1208
-		$filter_query = $this->getFilter($filters,true,true);
1209
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1208
+		$filter_query = $this->getFilter($filters, true, true);
1209
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1210 1210
 		if ($globalTimezone != '') {
1211 1211
 			date_default_timezone_set($globalTimezone);
1212 1212
 			$datetime = new DateTime($date);
@@ -1214,12 +1214,12 @@  discard block
 block discarded – undo
1214 1214
 		} else $offset = '+00:00';
1215 1215
 
1216 1216
 		if ($globalDBdriver == 'mysql') {
1217
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1217
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1218 1218
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1219 1219
 								GROUP BY hour_name 
1220 1220
 								ORDER BY hour_name ASC";
1221 1221
 		} else {
1222
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1222
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1223 1223
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1224 1224
 								GROUP BY hour_name 
1225 1225
 								ORDER BY hour_name ASC";
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 		$hour_array = array();
1232 1232
 		$temp_array = array();
1233 1233
         
1234
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1234
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1235 1235
 		{
1236 1236
 			$temp_array['hour_name'] = $row['hour_name'];
1237 1237
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
1256
-		$filter_query = $this->getFilter($filters,true,true);
1257
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1256
+		$filter_query = $this->getFilter($filters, true, true);
1257
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1258 1258
 		if ($globalTimezone != '') {
1259 1259
 			date_default_timezone_set($globalTimezone);
1260 1260
 			$datetime = new DateTime();
@@ -1262,12 +1262,12 @@  discard block
 block discarded – undo
1262 1262
 		} else $offset = '+00:00';
1263 1263
 
1264 1264
 		if ($globalDBdriver == 'mysql') {
1265
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1265
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1266 1266
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1267 1267
 								GROUP BY hour_name 
1268 1268
 								ORDER BY hour_name ASC";
1269 1269
 		} else {
1270
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1270
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1271 1271
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1272 1272
 								GROUP BY hour_name 
1273 1273
 								ORDER BY hour_name ASC";
@@ -1275,12 +1275,12 @@  discard block
 block discarded – undo
1275 1275
       
1276 1276
 		
1277 1277
 		$sth = $this->db->prepare($query);
1278
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1278
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1279 1279
       
1280 1280
 		$hour_array = array();
1281 1281
 		$temp_array = array();
1282 1282
         
1283
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1283
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1284 1284
 		{
1285 1285
 			$temp_array['hour_name'] = $row['hour_name'];
1286 1286
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1299,32 +1299,32 @@  discard block
 block discarded – undo
1299 1299
 	* @return Integer the number of flights
1300 1300
 	*
1301 1301
 	*/
1302
-	public function countOverallTracked($filters = array(),$year = '',$month = '')
1302
+	public function countOverallTracked($filters = array(), $year = '', $month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
1305
-		$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1305
+		$queryi = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1306 1306
 		$query_values = array();
1307 1307
 		$query = '';
1308 1308
 		if ($year != '') {
1309 1309
 			if ($globalDBdriver == 'mysql') {
1310 1310
 				$query .= " AND YEAR(marine_output.date) = :year";
1311
-				$query_values = array_merge($query_values,array(':year' => $year));
1311
+				$query_values = array_merge($query_values, array(':year' => $year));
1312 1312
 			} else {
1313 1313
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1314
-				$query_values = array_merge($query_values,array(':year' => $year));
1314
+				$query_values = array_merge($query_values, array(':year' => $year));
1315 1315
 			}
1316 1316
 		}
1317 1317
 		if ($month != '') {
1318 1318
 			if ($globalDBdriver == 'mysql') {
1319 1319
 				$query .= " AND MONTH(marine_output.date) = :month";
1320
-				$query_values = array_merge($query_values,array(':month' => $month));
1320
+				$query_values = array_merge($query_values, array(':month' => $month));
1321 1321
 			} else {
1322 1322
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1323
-				$query_values = array_merge($query_values,array(':month' => $month));
1323
+				$query_values = array_merge($query_values, array(':month' => $month));
1324 1324
 			}
1325 1325
 		}
1326 1326
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1327
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1327
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1328 1328
 		
1329 1329
 		$sth = $this->db->prepare($queryi);
1330 1330
 		$sth->execute($query_values);
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
1344
-		$filter_query = $this->getFilter($filters,true,true);
1344
+		$filter_query = $this->getFilter($filters, true, true);
1345 1345
 		if ($globalTimezone != '') {
1346 1346
 			date_default_timezone_set($globalTimezone);
1347 1347
 			$datetime = new DateTime();
@@ -1349,12 +1349,12 @@  discard block
 block discarded – undo
1349 1349
 		} else $offset = '+00:00';
1350 1350
 
1351 1351
 		if ($globalDBdriver == 'mysql') {
1352
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1352
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1353 1353
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1354 1354
 								GROUP BY hour_name 
1355 1355
 								ORDER BY hour_name ASC";
1356 1356
 		} else {
1357
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1357
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1358 1358
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1359 1359
 								GROUP BY hour_name 
1360 1360
 								ORDER BY hour_name ASC";
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 		$hour_array = array();
1367 1367
 		$temp_array = array();
1368 1368
         
1369
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1369
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1370 1370
 		{
1371 1371
 			$temp_array['hour_name'] = $row['hour_name'];
1372 1372
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1385,9 +1385,9 @@  discard block
 block discarded – undo
1385 1385
 	*/
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1388
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1389 1389
 
1390
-		$query  = "SELECT marine_output.marine_id
1390
+		$query = "SELECT marine_output.marine_id
1391 1391
 				FROM marine_output 
1392 1392
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1393 1393
         
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
 		$sth = $this->db->prepare($query);
1396 1396
 		$sth->execute();
1397 1397
 
1398
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1398
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1399 1399
 		{
1400 1400
 			return $row['marine_id'];
1401 1401
 		}
@@ -1420,23 +1420,23 @@  discard block
 block discarded – undo
1420 1420
 		}
1421 1421
 		
1422 1422
 		$current_date = date("Y-m-d H:i:s");
1423
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1423
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1424 1424
 		
1425 1425
 		$diff = abs(strtotime($current_date) - strtotime($date));
1426 1426
 
1427
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1427
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1428 1428
 		$years = $time_array['years'];
1429 1429
 		
1430
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1430
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1431 1431
 		$months = $time_array['months'];
1432 1432
 		
1433
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1433
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1434 1434
 		$days = $time_array['days'];
1435
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1435
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1436 1436
 		$hours = $time_array['hours'];
1437
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1437
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1438 1438
 		$minutes = $time_array['minutes'];
1439
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1439
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1440 1440
 		
1441 1441
 		return $time_array;
1442 1442
 	}
@@ -1459,63 +1459,63 @@  discard block
 block discarded – undo
1459 1459
 			$temp_array['direction_degree'] = $direction;
1460 1460
 			$temp_array['direction_shortname'] = "N";
1461 1461
 			$temp_array['direction_fullname'] = "North";
1462
-		} elseif ($direction >= 22.5 && $direction < 45){
1462
+		} elseif ($direction >= 22.5 && $direction < 45) {
1463 1463
 			$temp_array['direction_degree'] = $direction;
1464 1464
 			$temp_array['direction_shortname'] = "NNE";
1465 1465
 			$temp_array['direction_fullname'] = "North-Northeast";
1466
-		} elseif ($direction >= 45 && $direction < 67.5){
1466
+		} elseif ($direction >= 45 && $direction < 67.5) {
1467 1467
 			$temp_array['direction_degree'] = $direction;
1468 1468
 			$temp_array['direction_shortname'] = "NE";
1469 1469
 			$temp_array['direction_fullname'] = "Northeast";
1470
-		} elseif ($direction >= 67.5 && $direction < 90){
1470
+		} elseif ($direction >= 67.5 && $direction < 90) {
1471 1471
 			$temp_array['direction_degree'] = $direction;
1472 1472
 			$temp_array['direction_shortname'] = "ENE";
1473 1473
 			$temp_array['direction_fullname'] = "East-Northeast";
1474
-		} elseif ($direction >= 90 && $direction < 112.5){
1474
+		} elseif ($direction >= 90 && $direction < 112.5) {
1475 1475
 			$temp_array['direction_degree'] = $direction;
1476 1476
 			$temp_array['direction_shortname'] = "E";
1477 1477
 			$temp_array['direction_fullname'] = "East";
1478
-		} elseif ($direction >= 112.5 && $direction < 135){
1478
+		} elseif ($direction >= 112.5 && $direction < 135) {
1479 1479
 			$temp_array['direction_degree'] = $direction;
1480 1480
 			$temp_array['direction_shortname'] = "ESE";
1481 1481
 			$temp_array['direction_fullname'] = "East-Southeast";
1482
-		} elseif ($direction >= 135 && $direction < 157.5){
1482
+		} elseif ($direction >= 135 && $direction < 157.5) {
1483 1483
 			$temp_array['direction_degree'] = $direction;
1484 1484
 			$temp_array['direction_shortname'] = "SE";
1485 1485
 			$temp_array['direction_fullname'] = "Southeast";
1486
-		} elseif ($direction >= 157.5 && $direction < 180){
1486
+		} elseif ($direction >= 157.5 && $direction < 180) {
1487 1487
 			$temp_array['direction_degree'] = $direction;
1488 1488
 			$temp_array['direction_shortname'] = "SSE";
1489 1489
 			$temp_array['direction_fullname'] = "South-Southeast";
1490
-		} elseif ($direction >= 180 && $direction < 202.5){
1490
+		} elseif ($direction >= 180 && $direction < 202.5) {
1491 1491
 			$temp_array['direction_degree'] = $direction;
1492 1492
 			$temp_array['direction_shortname'] = "S";
1493 1493
 			$temp_array['direction_fullname'] = "South";
1494
-		} elseif ($direction >= 202.5 && $direction < 225){
1494
+		} elseif ($direction >= 202.5 && $direction < 225) {
1495 1495
 			$temp_array['direction_degree'] = $direction;
1496 1496
 			$temp_array['direction_shortname'] = "SSW";
1497 1497
 			$temp_array['direction_fullname'] = "South-Southwest";
1498
-		} elseif ($direction >= 225 && $direction < 247.5){
1498
+		} elseif ($direction >= 225 && $direction < 247.5) {
1499 1499
 			$temp_array['direction_degree'] = $direction;
1500 1500
 			$temp_array['direction_shortname'] = "SW";
1501 1501
 			$temp_array['direction_fullname'] = "Southwest";
1502
-		} elseif ($direction >= 247.5 && $direction < 270){
1502
+		} elseif ($direction >= 247.5 && $direction < 270) {
1503 1503
 			$temp_array['direction_degree'] = $direction;
1504 1504
 			$temp_array['direction_shortname'] = "WSW";
1505 1505
 			$temp_array['direction_fullname'] = "West-Southwest";
1506
-		} elseif ($direction >= 270 && $direction < 292.5){
1506
+		} elseif ($direction >= 270 && $direction < 292.5) {
1507 1507
 			$temp_array['direction_degree'] = $direction;
1508 1508
 			$temp_array['direction_shortname'] = "W";
1509 1509
 			$temp_array['direction_fullname'] = "West";
1510
-		} elseif ($direction >= 292.5 && $direction < 315){
1510
+		} elseif ($direction >= 292.5 && $direction < 315) {
1511 1511
 			$temp_array['direction_degree'] = $direction;
1512 1512
 			$temp_array['direction_shortname'] = "WNW";
1513 1513
 			$temp_array['direction_fullname'] = "West-Northwest";
1514
-		} elseif ($direction >= 315 && $direction < 337.5){
1514
+		} elseif ($direction >= 315 && $direction < 337.5) {
1515 1515
 			$temp_array['direction_degree'] = $direction;
1516 1516
 			$temp_array['direction_shortname'] = "NW";
1517 1517
 			$temp_array['direction_fullname'] = "Northwest";
1518
-		} elseif ($direction >= 337.5 && $direction < 360){
1518
+		} elseif ($direction >= 337.5 && $direction < 360) {
1519 1519
 			$temp_array['direction_degree'] = $direction;
1520 1520
 			$temp_array['direction_shortname'] = "NNW";
1521 1521
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1532,11 +1532,11 @@  discard block
 block discarded – undo
1532 1532
 	* @param Float $longitude longitute of the flight
1533 1533
 	* @return String the countrie
1534 1534
 	*/
1535
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1535
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
1538
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1539
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1538
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1539
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1540 1540
 	
1541 1541
 		$Connection = new Connection($this->db);
1542 1542
 		if (!$Connection->tableExists('countries')) return '';
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
1579
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1579
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1580 1580
 	
1581 1581
 		$Connection = new Connection($this->db);
1582 1582
 		if (!$Connection->tableExists('countries')) return '';
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		
1625 1625
 		$bitly_data = json_decode($bitly_data);
1626 1626
 		$bitly_url = '';
1627
-		if ($bitly_data->status_txt = "OK"){
1627
+		if ($bitly_data->status_txt = "OK") {
1628 1628
 			$bitly_url = $bitly_data->data->url;
1629 1629
 		}
1630 1630
 
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 
1635 1635
 	public function getOrderBy()
1636 1636
 	{
1637
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
1637
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"), "distance_asc" => array("key" => "distance_asc", "value" => "Distance - ASC", "sql" => "ORDER BY distance ASC"), "distance_desc" => array("key" => "distance_desc", "value" => "Distance - DESC", "sql" => "ORDER BY distance DESC"));
1638 1638
 		
1639 1639
 		return $orderby;
1640 1640
 		
Please login to merge, or discard this patch.
require/class.MarineLive.php 3 patches
Doc Comments   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	* Get SQL query part for filter used
16 16
 	* @param Array $filter the filter
17
-	* @return Array the SQL part
17
+	* @return string the SQL part
18 18
 	*/
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -762,10 +762,6 @@  discard block
 block discarded – undo
762 762
 	*
763 763
 	* @param String $fammarine_id the ID from flightaware
764 764
 	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769 765
 	*
770 766
 	*/
771 767
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
Please login to merge, or discard this patch.
Indentation   +187 added lines, -187 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();
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	/**
89
-	* Gets all the spotter information based on the latest data entry
90
-	*
91
-	* @return Array the spotter information
92
-	*
93
-	*/
89
+	 * Gets all the spotter information based on the latest data entry
90
+	 *
91
+	 * @return Array the spotter information
92
+	 *
93
+	 */
94 94
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
95 95
 	{
96 96
 		global $globalDBdriver, $globalLiveInterval;
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Gets Minimal Live Spotter data
136
-	*
137
-	* @return Array the spotter information
138
-	*
139
-	*/
135
+	 * Gets Minimal Live Spotter data
136
+	 *
137
+	 * @return Array the spotter information
138
+	 *
139
+	 */
140 140
 	public function getMinLiveMarineData($filter = array())
141 141
 	{
142 142
 		global $globalDBdriver, $globalLiveInterval;
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 	/**
169
-	* Gets Minimal Live Spotter data since xx seconds
170
-	*
171
-	* @return Array the spotter information
172
-	*
173
-	*/
169
+	 * Gets Minimal Live Spotter data since xx seconds
170
+	 *
171
+	 * @return Array the spotter information
172
+	 *
173
+	 */
174 174
 	public function getMinLastLiveMarineData($filter = array())
175 175
 	{
176 176
 		global $globalDBdriver, $globalLiveInterval;
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186
-                } else {
186
+				} else {
187 187
 			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
191 191
 
192
-    		try {
192
+			try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195 195
 		} catch(PDOException $e) {
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 	}
202 202
 
203 203
 	/**
204
-	* Gets number of latest data entry
205
-	*
206
-	* @return String number of entry
207
-	*
208
-	*/
204
+	 * Gets number of latest data entry
205
+	 *
206
+	 * @return String number of entry
207
+	 *
208
+	 */
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 
232 232
 	/**
233
-	* Gets all the spotter information based on the latest data entry and coord
234
-	*
235
-	* @return Array the spotter information
236
-	*
237
-	*/
233
+	 * Gets all the spotter information based on the latest data entry and coord
234
+	 *
235
+	 * @return Array the spotter information
236
+	 *
237
+	 */
238 238
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
239 239
 	{
240 240
 		global $globalDBdriver, $globalLiveInterval;
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Gets all the spotter information based on a user's latitude and longitude
262
-	*
263
-	* @return Array the spotter information
264
-	*
265
-	*/
261
+	 * Gets all the spotter information based on a user's latitude and longitude
262
+	 *
263
+	 * @return Array the spotter information
264
+	 *
265
+	 */
266 266
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
267 267
 	{
268 268
 		$Marine = new Marine($this->db);
@@ -275,134 +275,134 @@  discard block
 block discarded – undo
275 275
 		if ($lng != '')
276 276
 		{
277 277
 			if (!is_numeric($lng))
278
-                        {
279
-                                return false;
280
-                        }
281
-                }
282
-
283
-                if ($radius != '')
284
-                {
285
-                        if (!is_numeric($radius))
286
-                        {
287
-                                return false;
288
-                        }
289
-                }
278
+						{
279
+								return false;
280
+						}
281
+				}
282
+
283
+				if ($radius != '')
284
+				{
285
+						if (!is_numeric($radius))
286
+						{
287
+								return false;
288
+						}
289
+				}
290 290
 		$additional_query = '';
291 291
 		if ($interval != '')
292
-                {
293
-                        if (!is_string($interval))
294
-                        {
295
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
-			        return false;
297
-                        } else {
298
-                if ($interval == '1m')
299
-                {
300
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
302
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
-                } 
304
-            }
305
-                } else {
306
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
-        }
308
-
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
292
+				{
293
+						if (!is_string($interval))
294
+						{
295
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
+					return false;
297
+						} else {
298
+				if ($interval == '1m')
299
+				{
300
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
+				} else if ($interval == '15m'){
302
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
+				} 
304
+			}
305
+				} else {
306
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
+		}
308
+
309
+				$query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+				$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
317 317
 
318
-                return $spotter_array;
319
-        }
318
+				return $spotter_array;
319
+		}
320 320
 
321 321
     
322
-        /**
323
-	* Gets all the spotter information based on a particular callsign
324
-	*
325
-	* @return Array the spotter information
326
-	*
327
-	*/
322
+		/**
323
+		 * Gets all the spotter information based on a particular callsign
324
+		 *
325
+		 * @return Array the spotter information
326
+		 *
327
+		 */
328 328
 	public function getLastLiveMarineDataByIdent($ident)
329 329
 	{
330 330
 		$Marine = new Marine($this->db);
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336 336
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
340 340
 
341
-        /**
342
-	* Gets all the spotter information based on a particular callsign
343
-	*
344
-	* @return Array the spotter information
345
-	*
346
-	*/
341
+		/**
342
+		 * Gets all the spotter information based on a particular callsign
343
+		 *
344
+		 * @return Array the spotter information
345
+		 *
346
+		 */
347 347
 	public function getDateLiveMarineDataByIdent($ident,$date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
355
+				$date = date('c',$date);
356 356
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
360 360
 
361
-        /**
362
-	* Gets last spotter information based on a particular callsign
363
-	*
364
-	* @return Array the spotter information
365
-	*
366
-	*/
361
+		/**
362
+		 * Gets last spotter information based on a particular callsign
363
+		 *
364
+		 * @return Array the spotter information
365
+		 *
366
+		 */
367 367
 	public function getLastLiveMarineDataById($id)
368 368
 	{
369 369
 		$Marine = new Marine($this->db);
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375 375
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
379 379
 
380
-        /**
381
-	* Gets last spotter information based on a particular callsign
382
-	*
383
-	* @return Array the spotter information
384
-	*
385
-	*/
380
+		/**
381
+		 * Gets last spotter information based on a particular callsign
382
+		 *
383
+		 * @return Array the spotter information
384
+		 *
385
+		 */
386 386
 	public function getDateLiveMarineDataById($id,$date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
392
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+				$date = date('c',$date);
394 394
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
398 398
 
399 399
 
400
-        /**
401
-	* Gets all the spotter information based on a particular id
402
-	*
403
-	* @return Array the spotter information
404
-	*
405
-	*/
400
+		/**
401
+		 * Gets all the spotter information based on a particular id
402
+		 *
403
+		 * @return Array the spotter information
404
+		 *
405
+		 */
406 406
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
 		return $spotter_array;
431 431
 	}
432 432
 
433
-        /**
434
-	* Gets all the spotter information based on a particular ident
435
-	*
436
-	* @return Array the spotter information
437
-	*
438
-	*/
433
+		/**
434
+		 * Gets all the spotter information based on a particular ident
435
+		 *
436
+		 * @return Array the spotter information
437
+		 *
438
+		 */
439 439
 	public function getAllLiveMarineDataByIdent($ident)
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443 443
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
444
-    		try {
444
+			try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
 
456 456
 
457 457
 	/**
458
-	* Deletes all info in the table
459
-	*
460
-	* @return String success or false
461
-	*
462
-	*/
458
+	 * Deletes all info in the table
459
+	 *
460
+	 * @return String success or false
461
+	 *
462
+	 */
463 463
 	public function deleteLiveMarineData()
464 464
 	{
465 465
 		global $globalDBdriver;
466 466
 		if ($globalDBdriver == 'mysql') {
467 467
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
468 468
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
469
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
469
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
470 470
 		} else {
471 471
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
472 472
 		}
473 473
         
474
-    		try {
474
+			try {
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
487
-	*
488
-	* @return String success or false
489
-	*
490
-	*/
486
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
487
+	 *
488
+	 * @return String success or false
489
+	 *
490
+	 */
491 491
 	public function deleteLiveMarineDataNotUpdated()
492 492
 	{
493 493
 		global $globalDBdriver, $globalDebug;
494 494
 		if ($globalDBdriver == 'mysql') {
495 495
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
496
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
-    			try {
496
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
+				try {
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505
-                        $i = 0;
506
-                        $j =0;
505
+						$i = 0;
506
+						$j =0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508 508
 			foreach($all as $row)
509 509
 			{
@@ -511,20 +511,20 @@  discard block
 block discarded – undo
511 511
 				$j++;
512 512
 				if ($j == 30) {
513 513
 					if ($globalDebug) echo ".";
514
-				    	try {
514
+						try {
515 515
 						
516 516
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
517 517
 						$sth->execute();
518 518
 					} catch(PDOException $e) {
519 519
 						return "error";
520 520
 					}
521
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
-                                	$j = 0;
521
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
+									$j = 0;
523 523
 				}
524 524
 				$query_delete .= "'".$row['fammarine_id']."',";
525 525
 			}
526 526
 			if ($i > 0) {
527
-    				try {
527
+					try {
528 528
 					
529 529
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
530 530
 					$sth->execute();
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 			return "success";
536 536
 		} elseif ($globalDBdriver == 'pgsql') {
537 537
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
538
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
-    			try {
538
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
+				try {
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
@@ -581,17 +581,17 @@  discard block
 block discarded – undo
581 581
 	}
582 582
 
583 583
 	/**
584
-	* Deletes all info in the table for an ident
585
-	*
586
-	* @return String success or false
587
-	*
588
-	*/
584
+	 * Deletes all info in the table for an ident
585
+	 *
586
+	 * @return String success or false
587
+	 *
588
+	 */
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592 592
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594
-    		try {
594
+			try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	}
604 604
 
605 605
 	/**
606
-	* Deletes all info in the table for an id
607
-	*
608
-	* @return String success or false
609
-	*
610
-	*/
606
+	 * Deletes all info in the table for an id
607
+	 *
608
+	 * @return String success or false
609
+	 *
610
+	 */
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614 614
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616
-    		try {
616
+			try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
@@ -626,11 +626,11 @@  discard block
 block discarded – undo
626 626
 
627 627
 
628 628
 	/**
629
-	* Gets the aircraft ident within the last hour
630
-	*
631
-	* @return String the ident
632
-	*
633
-	*/
629
+	 * Gets the aircraft ident within the last hour
630
+	 *
631
+	 * @return String the ident
632
+	 *
633
+	 */
634 634
 	public function getIdentFromLastHour($ident)
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
@@ -656,14 +656,14 @@  discard block
 block discarded – undo
656 656
 			$ident_result = $row['ident'];
657 657
 		}
658 658
 		return $ident_result;
659
-        }
659
+		}
660 660
 
661 661
 	/**
662
-	* Check recent aircraft
663
-	*
664
-	* @return String the ident
665
-	*
666
-	*/
662
+	 * Check recent aircraft
663
+	 *
664
+	 * @return String the ident
665
+	 *
666
+	 */
667 667
 	public function checkIdentRecent($ident)
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
691 691
 		return $ident_result;
692
-        }
692
+		}
693 693
 
694 694
 	/**
695
-	* Check recent aircraft by id
696
-	*
697
-	* @return String the ident
698
-	*
699
-	*/
695
+	 * Check recent aircraft by id
696
+	 *
697
+	 * @return String the ident
698
+	 *
699
+	 */
700 700
 	public function checkIdRecent($id)
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
@@ -722,14 +722,14 @@  discard block
 block discarded – undo
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
724 724
 		return $ident_result;
725
-        }
725
+		}
726 726
 
727 727
 	/**
728
-	* Check recent aircraft by mmsi
729
-	*
730
-	* @return String the ident
731
-	*
732
-	*/
728
+	 * Check recent aircraft by mmsi
729
+	 *
730
+	 * @return String the ident
731
+	 *
732
+	 */
733 733
 	public function checkMMSIRecent($mmsi)
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
@@ -755,19 +755,19 @@  discard block
 block discarded – undo
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
757 757
 		return $ident_result;
758
-        }
758
+		}
759 759
 
760 760
 	/**
761
-	* Adds a new spotter data
762
-	*
763
-	* @param String $fammarine_id the ID from flightaware
764
-	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769
-	*
770
-	*/
761
+	 * Adds a new spotter data
762
+	 *
763
+	 * @param String $fammarine_id the ID from flightaware
764
+	 * @param String $ident the flight ident
765
+	 * @param String $aircraft_icao the aircraft type
766
+	 * @param String $departure_airport_icao the departure airport
767
+	 * @param String $arrival_airport_icao the arrival airport
768
+	 * @return String success or false
769
+	 *
770
+	 */
771 771
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
@@ -838,9 +838,9 @@  discard block
 block discarded – undo
838 838
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
839 839
 		
840 840
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
-            	if ($arrival_date == '') $arrival_date = NULL;
841
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
+				if ($arrival_date == '') $arrival_date = NULL;
844 844
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 845
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 846
 
@@ -849,9 +849,9 @@  discard block
 block discarded – undo
849 849
 			
850 850
 			$sth = $this->db->prepare($query);
851 851
 			$sth->execute($query_values);
852
-                } catch(PDOException $e) {
853
-                	return "error : ".$e->getMessage();
854
-                }
852
+				} catch(PDOException $e) {
853
+					return "error : ".$e->getMessage();
854
+				}
855 855
 		/*
856 856
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
857 857
 		    if ($globalDebug) echo '(Add to SBS archive : ';
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@  discard block
 block discarded – undo
16 16
 	* @param Array $filter the filter
17 17
 	* @return Array the SQL part
18 18
 	*/
19
-	public function getFilter($filter = array(),$where = false,$and = false) {
19
+	public function getFilter($filter = array(), $where = false, $and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
22 22
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
23 23
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
24 24
 				$filters = $globalStatsFilters[$globalFilterName];
25 25
 			} else {
26
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
26
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
27 27
 			}
28 28
 		}
29 29
 		if (isset($filter[0]['source'])) {
30
-			$filters = array_merge($filters,$filter);
30
+			$filters = array_merge($filters, $filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
33 33
 		$filter_query_join = '';
34 34
 		$filter_query_where = '';
35
-		foreach($filters as $flt) {
35
+		foreach ($filters as $flt) {
36 36
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
37 37
 				if (isset($flt['source'])) {
38
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
38
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
39 39
 				} else {
40
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
40
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
41 41
 				}
42 42
 			}
43 43
 		}
44 44
 		if (isset($filter['source']) && !empty($filter['source'])) {
45
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
45
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
46 46
 		}
47 47
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
48 48
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
72 72
 				}
73 73
 			}
74
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
74
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
75 75
 		}
76 76
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
77
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
78 78
 		}
79 79
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80 80
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81 81
 		if ($filter_query_where != '') {
82
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
82
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
83 83
 		}
84 84
 		$filter_query = $filter_query_join.$filter_query_where;
85 85
 		return $filter_query;
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 		if ($limit != '')
103 103
 		{
104 104
 			$limit_array = explode(',', $limit);
105
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
106
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
105
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
106
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
107 107
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
108 108
 			{
109 109
 				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		} else {
127 127
 			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
128 128
 		}
129
-		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
129
+		$spotter_array = $Marine->getDataFromDB($query.$limit_query, array(), '', true);
130 130
 
131 131
 		return $spotter_array;
132 132
 	}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		global $globalDBdriver, $globalLiveInterval;
143 143
 		date_default_timezone_set('UTC');
144 144
 
145
-		$filter_query = $this->getFilter($filter,true,true);
145
+		$filter_query = $this->getFilter($filter, true, true);
146 146
 
147 147
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
148 148
 		if ($globalDBdriver == 'mysql') {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		try {
157 157
 			$sth = $this->db->prepare($query);
158 158
 			$sth->execute();
159
-		} catch(PDOException $e) {
159
+		} catch (PDOException $e) {
160 160
 			echo $e->getMessage();
161 161
 			die;
162 162
 		}
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
 		global $globalDBdriver, $globalLiveInterval;
177 177
 		date_default_timezone_set('UTC');
178 178
 
179
-		$filter_query = $this->getFilter($filter,true,true);
179
+		$filter_query = $this->getFilter($filter, true, true);
180 180
 
181 181
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
182 182
 		if ($globalDBdriver == 'mysql') {
183
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
183
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186 186
                 } else {
187
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
187
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     		try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195
-		} catch(PDOException $e) {
195
+		} catch (PDOException $e) {
196 196
 			echo $e->getMessage();
197 197
 			die;
198 198
 		}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
212
-		$filter_query = $this->getFilter($filter,true,true);
212
+		$filter_query = $this->getFilter($filter, true, true);
213 213
 
214 214
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
215 215
 		if ($globalDBdriver == 'mysql') {
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		try {
221 221
 			$sth = $this->db->prepare($query);
222 222
 			$sth->execute();
223
-		} catch(PDOException $e) {
223
+		} catch (PDOException $e) {
224 224
 			echo $e->getMessage();
225 225
 			die;
226 226
 		}
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 		$filter_query = $this->getFilter($filter);
244 244
 
245 245
 		if (is_array($coord)) {
246
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
247
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
248
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
249
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
246
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
247
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
248
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
249
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
250 250
 		} else return array();
251 251
 		if ($globalDBdriver == 'mysql') {
252 252
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 if ($interval == '1m')
299 299
                 {
300 300
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
301
+                } else if ($interval == '15m') {
302 302
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303 303
                 } 
304 304
             }
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
          $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307 307
         }
308 308
 
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
309
+                $query = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius));
317 317
 
318 318
                 return $spotter_array;
319 319
         }
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
336
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident), '', true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
@@ -344,16 +344,16 @@  discard block
 block discarded – undo
344 344
 	* @return Array the spotter information
345 345
 	*
346 346
 	*/
347
-	public function getDateLiveMarineDataByIdent($ident,$date)
347
+	public function getDateLiveMarineDataByIdent($ident, $date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
356
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
355
+                $date = date('c', $date);
356
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
375
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id), '', true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
 	* @return Array the spotter information
384 384
 	*
385 385
 	*/
386
-	public function getDateLiveMarineDataById($id,$date)
386
+	public function getDateLiveMarineDataById($id, $date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
394
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
392
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+                $date = date('c', $date);
394
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date), '', true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	* @return Array the spotter information
404 404
 	*
405 405
 	*/
406
-	public function getAllLiveMarineDataById($id,$liveinterval = false)
406
+	public function getAllLiveMarineDataById($id, $liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
409 409
 		date_default_timezone_set('UTC');
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 		try {
423 423
 			$sth = $this->db->prepare($query);
424 424
 			$sth->execute(array(':id' => $id));
425
-		} catch(PDOException $e) {
425
+		} catch (PDOException $e) {
426 426
 			echo $e->getMessage();
427 427
 			die;
428 428
 		}
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443
-		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
443
+		$query = self::$global_query.' WHERE marine_live.ident = :ident';
444 444
     		try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
448
-		} catch(PDOException $e) {
448
+		} catch (PDOException $e) {
449 449
 			echo $e->getMessage();
450 450
 			die;
451 451
 		}
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
478
-		} catch(PDOException $e) {
478
+		} catch (PDOException $e) {
479 479
 			return "error";
480 480
 		}
481 481
 
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
501
-			} catch(PDOException $e) {
501
+			} catch (PDOException $e) {
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505 505
                         $i = 0;
506
-                        $j =0;
506
+                        $j = 0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508
-			foreach($all as $row)
508
+			foreach ($all as $row)
509 509
 			{
510 510
 				$i++;
511 511
 				$j++;
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
 					if ($globalDebug) echo ".";
514 514
 				    	try {
515 515
 						
516
-						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
516
+						$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
517 517
 						$sth->execute();
518
-					} catch(PDOException $e) {
518
+					} catch (PDOException $e) {
519 519
 						return "error";
520 520
 					}
521 521
                                 	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 			if ($i > 0) {
527 527
     				try {
528 528
 					
529
-					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
529
+					$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
530 530
 					$sth->execute();
531
-				} catch(PDOException $e) {
531
+				} catch (PDOException $e) {
532 532
 					return "error";
533 533
 				}
534 534
 			}
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
544
-			} catch(PDOException $e) {
544
+			} catch (PDOException $e) {
545 545
 				return "error";
546 546
 			}
547 547
 /*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
@@ -589,13 +589,13 @@  discard block
 block discarded – undo
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592
-		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
592
+		$query = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594 594
     		try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
598
-		} catch(PDOException $e) {
598
+		} catch (PDOException $e) {
599 599
 			return "error";
600 600
 		}
601 601
 
@@ -611,13 +611,13 @@  discard block
 block discarded – undo
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614
-		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
614
+		$query = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616 616
     		try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
620
-		} catch(PDOException $e) {
620
+		} catch (PDOException $e) {
621 621
 			return "error";
622 622
 		}
623 623
 
@@ -635,13 +635,13 @@  discard block
 block discarded – undo
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
637 637
 		if ($globalDBdriver == 'mysql') {
638
-			$query  = 'SELECT marine_live.ident FROM marine_live 
638
+			$query = 'SELECT marine_live.ident FROM marine_live 
639 639
 				WHERE marine_live.ident = :ident 
640 640
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
641 641
 				AND marine_live.date < UTC_TIMESTAMP()';
642 642
 			$query_data = array(':ident' => $ident);
643 643
 		} else {
644
-			$query  = "SELECT marine_live.ident FROM marine_live 
644
+			$query = "SELECT marine_live.ident FROM marine_live 
645 645
 				WHERE marine_live.ident = :ident 
646 646
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
647 647
 				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 		
651 651
 		$sth = $this->db->prepare($query);
652 652
 		$sth->execute($query_data);
653
-		$ident_result='';
654
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
653
+		$ident_result = '';
654
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
655 655
 		{
656 656
 			$ident_result = $row['ident'];
657 657
 		}
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
670 670
 		if ($globalDBdriver == 'mysql') {
671
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
671
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
672 672
 				WHERE marine_live.ident = :ident 
673 673
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
674 674
 //				AND marine_live.date < UTC_TIMESTAMP()";
675 675
 			$query_data = array(':ident' => $ident);
676 676
 		} else {
677
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
677
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
678 678
 				WHERE marine_live.ident = :ident 
679 679
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
680 680
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 		
684 684
 		$sth = $this->db->prepare($query);
685 685
 		$sth->execute($query_data);
686
-		$ident_result='';
687
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
686
+		$ident_result = '';
687
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
688 688
 		{
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
@@ -701,13 +701,13 @@  discard block
 block discarded – undo
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
703 703
 		if ($globalDBdriver == 'mysql') {
704
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
704
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
705 705
 				WHERE marine_live.fammarine_id = :id 
706 706
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
707 707
 //				AND marine_live.date < UTC_TIMESTAMP()";
708 708
 			$query_data = array(':id' => $id);
709 709
 		} else {
710
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
710
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
711 711
 				WHERE marine_live.fammarine_id = :id 
712 712
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
713 713
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
 		
717 717
 		$sth = $this->db->prepare($query);
718 718
 		$sth->execute($query_data);
719
-		$ident_result='';
720
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
719
+		$ident_result = '';
720
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
721 721
 		{
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
@@ -734,13 +734,13 @@  discard block
 block discarded – undo
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
736 736
 		if ($globalDBdriver == 'mysql') {
737
-			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
737
+			$query = 'SELECT marine_live.fammarine_id FROM marine_live 
738 738
 				WHERE marine_live.mmsi = :mmsi 
739 739
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
740 740
 //				AND marine_live.date < UTC_TIMESTAMP()";
741 741
 			$query_data = array(':mmsi' => $mmsi);
742 742
 		} else {
743
-			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
743
+			$query = "SELECT marine_live.fammarine_id FROM marine_live 
744 744
 				WHERE marine_live.mmsi = :mmsi 
745 745
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
746 746
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -749,8 +749,8 @@  discard block
 block discarded – undo
749 749
 		
750 750
 		$sth = $this->db->prepare($query);
751 751
 		$sth->execute($query_data);
752
-		$ident_result='';
753
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
752
+		$ident_result = '';
753
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
754 754
 		{
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 	* @return String success or false
769 769
 	*
770 770
 	*/
771
-	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
771
+	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
774 774
 		$Common = new Common();
@@ -820,36 +820,36 @@  discard block
 block discarded – undo
820 820
 		if ($date == '') $date = date("Y-m-d H:i:s", time());
821 821
 
822 822
         
823
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
824
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
825
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
826
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
827
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
828
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
829
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
830
-		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
831
-		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
832
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
833
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
834
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
835
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
836
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
837
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
838
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
823
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
824
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
825
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
826
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
827
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
828
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
829
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
830
+		$source_name = filter_var($source_name, FILTER_SANITIZE_STRING);
831
+		$over_country = filter_var($over_country, FILTER_SANITIZE_STRING);
832
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
833
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
834
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
835
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
836
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
837
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
838
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
839 839
 		
840 840
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
841
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
842
+            	if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
843 843
             	if ($arrival_date == '') $arrival_date = NULL;
844
-		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
844
+		$query = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 845
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 846
 
847
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
847
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
848 848
 		try {
849 849
 			
850 850
 			$sth = $this->db->prepare($query);
851 851
 			$sth->execute($query_values);
852
-                } catch(PDOException $e) {
852
+                } catch (PDOException $e) {
853 853
                 	return "error : ".$e->getMessage();
854 854
                 }
855 855
 		/*
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 
867 867
 	public function getOrderBy()
868 868
 	{
869
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
869
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
870 870
 		return $orderby;
871 871
 	}
872 872
 
Please login to merge, or discard this patch.
require/class.SpotterImport.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -46,6 +46,10 @@
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
+    /**
50
+     * @param string $id
51
+     * @param string $ident
52
+     */
49 53
     public function get_Schedule($id,$ident) {
50 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 55
 	// Get schedule here, so it's done only one time
Please login to merge, or discard this patch.
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class SpotterImport {
13
-    private $all_flights = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
21
-
22
-    public function __construct($dbc = null) {
13
+	private $all_flights = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21
+
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta, $globalServerAPRS, $APRSSpotter;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
34
-	    	$type = $srcst['stats_type'];
33
+		foreach($sourcestat as $srcst) {
34
+			$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36
-		    $source = $srcst['source_name'];
37
-		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
-	        }
40
-	    }
36
+			$source = $srcst['source_name'];
37
+			$data = $srcst['source_data'];
38
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
+			}
40
+		}
41 41
 	}
42 42
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
43 43
 		$APRSSpotter = new APRSSpotter();
44 44
 		$APRSSpotter->connect();
45 45
 	}
46 46
 
47
-    }
47
+	}
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+	public function get_Schedule($id,$ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -66,42 +66,42 @@  discard block
 block discarded – undo
66 66
 	$operator = $Spotter->getOperator($ident);
67 67
 	$scheduleexist = false;
68 68
 	if ($Schedule->checkSchedule($operator) == 0) {
69
-	    $operator = $Translation->checkTranslation($ident);
70
-	    if ($Schedule->checkSchedule($operator) == 0) {
69
+		$operator = $Translation->checkTranslation($ident);
70
+		if ($Schedule->checkSchedule($operator) == 0) {
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
-		    // Should also check if route schedule = route from DB
77
-		    if ($schedule['DepartureAirportIATA'] != '') {
73
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
+			// Should also check if route schedule = route from DB
77
+			if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
79
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
-			    if (trim($airport_icao) != '') {
79
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
+				if (trim($airport_icao) != '') {
81 81
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82 82
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
83
-			    }
83
+				}
84
+			}
84 85
 			}
85
-		    }
86
-		    if ($schedule['ArrivalAirportIATA'] != '') {
86
+			if ($schedule['ArrivalAirportIATA'] != '') {
87 87
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
88
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
-			    if (trim($airport_icao) != '') {
88
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
+				if (trim($airport_icao) != '') {
90 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91 91
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
92
-			    }
92
+				}
93
+			}
93 94
 			}
94
-		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 96
 		}
97
-	    } else $scheduleexist = true;
97
+		} else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
99 99
 	// close connection, at least one way will work ?
100
-       if ($scheduleexist) {
100
+	   if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102
-    		$sch = $Schedule->getSchedule($operator);
102
+			$sch = $Schedule->getSchedule($operator);
103 103
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104
-       }
104
+	   }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
107 107
 	$Translation->db = null;
@@ -116,96 +116,96 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 	  */
118 118
 	}
119
-    }
119
+	}
120 120
 
121
-    public function checkAll() {
121
+	public function checkAll() {
122 122
 	global $globalDebug, $globalNoImport;
123 123
 	if ($globalDebug) echo "Update last seen flights data...\n";
124 124
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125
-	    foreach ($this->all_flights as $key => $flight) {
125
+		foreach ($this->all_flights as $key => $flight) {
126 126
 		if (isset($this->all_flights[$key]['id'])) {
127
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
-    		    $Spotter = new Spotter($this->db);
129
-        	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
-        	}
132
-	    }
127
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
+				$Spotter = new Spotter($this->db);
129
+				$real_arrival = $this->arrival($key);
130
+				$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
+			}
132
+		}
133
+	}
133 134
 	}
134
-    }
135 135
 
136
-    public function arrival($key) {
136
+	public function arrival($key) {
137 137
 	global $globalClosestMinDist, $globalDebug;
138 138
 	if ($globalDebug) echo 'Update arrival...'."\n";
139 139
 	$Spotter = new Spotter($this->db);
140
-        $airport_icao = '';
141
-        $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
140
+		$airport_icao = '';
141
+		$airport_time = '';
142
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
-    	    if (isset($closestAirports[0])) {
146
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
-        	    $airport_icao = $closestAirports[0]['icao'];
148
-        	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
-        	    foreach ($closestAirports as $airport) {
152
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
-        		    $airport_icao = $airport['icao'];
154
-        		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
-        		    break;
157
-        		}
158
-        	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
-        		$airport_icao = $closestAirports[0]['icao'];
161
-        		$airport_time = $this->all_flights[$key]['datetime'];
162
-        	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
-        	}
165
-    	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
-    	    }
168
-
169
-        } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
-        }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
-    }
174
-
175
-
176
-
177
-    public function del() {
144
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
+			if (isset($closestAirports[0])) {
146
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
+				$airport_icao = $closestAirports[0]['icao'];
148
+				$airport_time = $this->all_flights[$key]['datetime'];
149
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
+				foreach ($closestAirports as $airport) {
152
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
+					$airport_icao = $airport['icao'];
154
+					$airport_time = $this->all_flights[$key]['datetime'];
155
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
+					break;
157
+				}
158
+				}
159
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
+				$airport_icao = $closestAirports[0]['icao'];
161
+				$airport_time = $this->all_flights[$key]['datetime'];
162
+			} else {
163
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
+			}
165
+			} else {
166
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
+			}
168
+
169
+		} else {
170
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
+		}
172
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
+	}
174
+
175
+
176
+
177
+	public function del() {
178 178
 	global $globalDebug, $globalNoImport;
179 179
 	// Delete old infos
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182
-    	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
184
-            	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
182
+			if (isset($flight['lastupdate'])) {
183
+			if ($flight['lastupdate'] < (time()-3000)) {
184
+					if (isset($this->all_flights[$key]['id'])) {
185
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
187 187
 			$SpotterLive = new SpotterLive();
188 188
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
189 189
 			$SpotterLive->db = null;
190 190
 			*/
191 191
 			if (!isset($globalNoImport) || $globalNoImport === FALSE) {
192
-            		    $real_arrival = $this->arrival($key);
193
-            		    $Spotter = new Spotter($this->db);
194
-            	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
192
+						$real_arrival = $this->arrival($key);
193
+						$Spotter = new Spotter($this->db);
194
+							if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 195
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197
-			    }
197
+				}
198 198
 			// Put in archive
199 199
 //				$Spotter->db = null;
200 200
 			}
201
-            	    }
202
-            	    unset($this->all_flights[$key]);
203
-    	        }
204
-	    }
205
-        }
206
-    }
201
+					}
202
+					unset($this->all_flights[$key]);
203
+				}
204
+		}
205
+		}
206
+	}
207 207
 
208
-    public function add($line) {
208
+	public function add($line) {
209 209
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 210
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211 211
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 	
231 231
 	// SBS format is CSV format
232 232
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233
-	    //print_r($line);
234
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
233
+		//print_r($line);
234
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
236 236
 		// Increment message number
237 237
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238
-		    $current_date = date('Y-m-d');
239
-		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
238
+			$current_date = date('Y-m-d');
239
+			$source = $line['source_name'];
240
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
242
+				$this->stats[$current_date][$source]['msg']['date'] = time();
243
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
245 245
 		}
246 246
 		
247 247
 		/*
@@ -257,34 +257,34 @@  discard block
 block discarded – undo
257 257
 		//$this->db = $dbc;
258 258
 
259 259
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
260
+			if (!isset($line['id'])) $id = trim($line['hex']);
261
+			else $id = trim($line['id']);
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264
-		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
-		    if (!isset($line['id'])) {
264
+			$this->all_flights[$id] = array();
265
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
+			if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272 272
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
273
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
273
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
+			if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
283
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
286
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 			$Spotter->db = null;
296 296
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297 297
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
298
-		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298
+			}
299
+			if ($globalAllFlights !== FALSE) $dataFound = true;
300
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 303
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323 323
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
324
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
324
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 325
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326
-		    } else {
326
+			} else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
329 329
 				/*
@@ -332,41 +332,41 @@  discard block
 block discarded – undo
332 332
 				print_r($line);
333 333
 				*/
334 334
 				return '';
335
-		    }
335
+			}
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338 338
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
355
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358
-            		$Spotter = new Spotter($this->db);
359
-            		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
358
+					$Spotter = new Spotter($this->db);
359
+					$fromsource = NULL;
360
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368 368
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
-		    }
369
+			}
370 370
 
371 371
 /*
372 372
 		    if (!isset($line['id'])) {
@@ -376,26 +376,26 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381
-		    //$putinarchive = true;
382
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
381
+			//$putinarchive = true;
382
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383 383
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
384
-		    }
385
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
384
+			}
385
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386 386
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
387
-		    }
388
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
387
+			}
388
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
395
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396 396
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397 397
 
398
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
398
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
400 400
 			$Spotter = new Spotter($this->db);
401 401
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -409,43 +409,43 @@  discard block
 block discarded – undo
409 409
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
412
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
-		    	    }
415
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
+					}
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420 420
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
421 421
 			}
422
-		    }
422
+			}
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
-		    //$dataFound = true;
427
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
+			//$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
-		    if ($distance > 1000 && $distance < 10000) {
433
-		    // use datetime
431
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
+			if ($distance > 1000 && $distance < 10000) {
433
+			// use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436 436
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438
-		    }
438
+			}
439 439
 		}
440 440
 
441 441
 
442 442
 
443
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
443
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
+				else unset($timediff);
446
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -459,16 +459,16 @@  discard block
 block discarded – undo
459 459
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460 460
 				$this->tmd = 0;
461 461
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462
-			    }
462
+				}
463 463
 			}
464 464
 
465 465
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
466
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
466
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467 467
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
468 468
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470
-				    $dataFound = true;
471
-				    $this->all_flights[$id]['time_last_coord'] = time();
469
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470
+					$dataFound = true;
471
+					$this->all_flights[$id]['time_last_coord'] = time();
472 472
 				}
473 473
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
474 474
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -479,20 +479,20 @@  discard block
 block discarded – undo
479 479
 				    //$putinarchive = true;
480 480
 				}
481 481
 				*/
482
-			    /*
482
+				/*
483 483
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
484 484
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
485 485
 			    }
486 486
 			    */
487 487
 			}
488 488
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
489
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
490
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
489
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
490
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
491 491
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
492 492
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494
-				    $dataFound = true;
495
-				    $this->all_flights[$id]['time_last_coord'] = time();
493
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494
+					$dataFound = true;
495
+					$this->all_flights[$id]['time_last_coord'] = time();
496 496
 				}
497 497
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
498 498
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -510,54 +510,54 @@  discard block
 block discarded – undo
510 510
 			    */
511 511
 			}
512 512
 
513
-		    } else if ($globalDebug && $timediff > 20) {
513
+			} else if ($globalDebug && $timediff > 20) {
514 514
 			$this->tmd = $this->tmd + 1;
515 515
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
516 516
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
517 517
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
518 518
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
519
-		    }
519
+			}
520 520
 		}
521 521
 		if (isset($line['last_update']) && $line['last_update'] != '') {
522
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
523
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
522
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
523
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524 524
 		}
525 525
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
526
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
-		    //$dataFound = true;
526
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
+			//$dataFound = true;
528 528
 		}
529 529
 		if (isset($line['format_source']) && $line['format_source'] != '') {
530
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
530
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531 531
 		}
532 532
 		if (isset($line['source_name']) && $line['source_name'] != '') {
533
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
533
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534 534
 		}
535 535
 		if (isset($line['emergency']) && $line['emergency'] != '') {
536
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
-		    //$dataFound = true;
536
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
+			//$dataFound = true;
538 538
 		}
539 539
 		if (isset($line['ground']) && $line['ground'] != '') {
540
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
540
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
541 541
 			// Here we force archive of flight because after ground it's a new one (or should be)
542 542
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
543 543
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
544 544
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
545
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546 546
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
547
-		    }
548
-		    if ($line['ground'] != 1) $line['ground'] = 0;
549
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
-		    //$dataFound = true;
547
+			}
548
+			if ($line['ground'] != 1) $line['ground'] = 0;
549
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
+			//$dataFound = true;
551 551
 		}
552 552
 		if (isset($line['squawk']) && $line['squawk'] != '') {
553
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
555
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
-			    $highlight = '';
557
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
560
-			    if ($highlight != '') {
553
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
555
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
+				$highlight = '';
557
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
560
+				if ($highlight != '') {
561 561
 				$timeelapsed = microtime(true);
562 562
 				$Spotter = new Spotter($this->db);
563 563
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -566,38 +566,38 @@  discard block
 block discarded – undo
566 566
 
567 567
 				//$putinarchive = true;
568 568
 				//$highlight = '';
569
-			    }
569
+				}
570 570
 			    
571
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
-		    //$dataFound = true;
571
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
+			//$dataFound = true;
573 573
 		}
574 574
 
575 575
 		if (isset($line['altitude']) && $line['altitude'] != '') {
576
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
576
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577 577
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
578 578
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
579 579
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
580 580
 			//$dataFound = true;
581
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
581
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
582 582
   		}
583 583
 
584 584
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
585
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
585
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586 586
 		}
587 587
 		
588 588
 		if (isset($line['heading']) && $line['heading'] != '') {
589
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592
-		    //$dataFound = true;
589
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592
+			//$dataFound = true;
593 593
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
594
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
594
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
598 598
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
599
-  		    // If not enough messages and ACARS set heading to 0
600
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
599
+  			// If not enough messages and ACARS set heading to 0
600
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601 601
   		}
602 602
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603 603
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -608,121 +608,121 @@  discard block
 block discarded – undo
608 608
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
609 609
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
610 610
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
611
-		    $this->all_flights[$id]['lastupdate'] = time();
612
-		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
613
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
-			    //print_r($this->all_flights);
615
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
611
+			$this->all_flights[$id]['lastupdate'] = time();
612
+			if ($this->all_flights[$id]['addedSpotter'] == 0) {
613
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
+				//print_r($this->all_flights);
615
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
618 618
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
619 619
 				$timeelapsed = microtime(true);
620 620
 				$SpotterLive = new SpotterLive($this->db);
621 621
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
622
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
622
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
624 624
 				} elseif (isset($line['id'])) {
625
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
625
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
627 627
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
628
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
628
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630 630
 				} else $recent_ident = '';
631 631
 				$SpotterLive->db=null;
632 632
 
633 633
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
634 634
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
635
-			    } else {
635
+				} else {
636 636
 				$recent_ident = '';
637 637
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
638
-			    }
639
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
640
-			    if($recent_ident == "")
641
-			    {
638
+				}
639
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
640
+				if($recent_ident == "")
641
+				{
642 642
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
643 643
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
644 644
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
645 645
 				//adds the spotter data for the archive
646 646
 				$ignoreImport = false;
647 647
 				foreach($globalAirportIgnore as $airportIgnore) {
648
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
648
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
649 649
 					$ignoreImport = true;
650
-				    }
650
+					}
651 651
 				}
652 652
 				if (count($globalAirportAccept) > 0) {
653
-				    $ignoreImport = true;
654
-				    foreach($globalAirportIgnore as $airportIgnore) {
653
+					$ignoreImport = true;
654
+					foreach($globalAirportIgnore as $airportIgnore) {
655 655
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
656
-					    $ignoreImport = false;
656
+						$ignoreImport = false;
657
+					}
657 658
 					}
658
-				    }
659 659
 				}
660 660
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
661
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
661
+					foreach($globalAirlineIgnore as $airlineIgnore) {
662 662
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
663
-					    $ignoreImport = true;
663
+						$ignoreImport = true;
664
+					}
664 665
 					}
665
-				    }
666 666
 				}
667 667
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
668
-				    $ignoreImport = true;
669
-				    foreach($globalAirlineAccept as $airlineAccept) {
668
+					$ignoreImport = true;
669
+					foreach($globalAirlineAccept as $airlineAccept) {
670 670
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
671
-					    $ignoreImport = false;
671
+						$ignoreImport = false;
672
+					}
672 673
 					}
673
-				    }
674 674
 				}
675 675
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
676
-				    $ignoreImport = true;
677
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
676
+					$ignoreImport = true;
677
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
678 678
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
679
-					    $ignoreImport = false;
679
+						$ignoreImport = false;
680
+					}
680 681
 					}
681
-				    }
682 682
 				}
683 683
 				
684 684
 				if (!$ignoreImport) {
685
-				    $highlight = '';
686
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
-				    $timeelapsed = microtime(true);
691
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
685
+					$highlight = '';
686
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
+					$timeelapsed = microtime(true);
691
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
692 692
 					$Spotter = new Spotter($this->db);
693 693
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694 694
 					$Spotter->db = null;
695 695
 					if ($globalDebug && isset($result)) echo $result."\n";
696
-				    }
697
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696
+					}
697
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698 698
 				    
699
-				    // Add source stat in DB
700
-				    $Stats = new Stats($this->db);
701
-				    if (!empty($this->stats)) {
699
+					// Add source stat in DB
700
+					$Stats = new Stats($this->db);
701
+					if (!empty($this->stats)) {
702 702
 					if ($globalDebug) echo 'Add source stats : ';
703
-				        foreach($this->stats as $date => $data) {
704
-					    foreach($data as $source => $sourced) {
705
-					        //print_r($sourced);
706
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
708
-				    		if (isset($sourced['msg'])) {
709
-				    		    if (time() - $sourced['msg']['date'] > 10) {
710
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
711
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
-			    			        unset($this->stats[$date][$source]['msg']);
713
-			    			    }
714
-			    			}
715
-			    		    }
716
-			    		    if ($date != date('Y-m-d')) {
717
-			    			unset($this->stats[$date]);
718
-			    		    }
719
-				    	}
720
-				    	if ($globalDebug) echo 'Done'."\n";
721
-
722
-				    }
723
-				    $Stats->db = null;
703
+						foreach($this->stats as $date => $data) {
704
+						foreach($data as $source => $sourced) {
705
+							//print_r($sourced);
706
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
708
+							if (isset($sourced['msg'])) {
709
+								if (time() - $sourced['msg']['date'] > 10) {
710
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
711
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
+									unset($this->stats[$date][$source]['msg']);
713
+								}
714
+							}
715
+							}
716
+							if ($date != date('Y-m-d')) {
717
+							unset($this->stats[$date]);
718
+							}
719
+						}
720
+						if ($globalDebug) echo 'Done'."\n";
721
+
722
+					}
723
+					$Stats->db = null;
724 724
 				    
725
-				    $this->del();
725
+					$this->del();
726 726
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
727 727
 				//$ignoreImport = false;
728 728
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -740,37 +740,37 @@  discard block
 block discarded – undo
740 740
 			*/
741 741
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
742 742
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
743
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
744
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
745
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
743
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
744
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
745
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
746 746
 					$SpotterLive = new SpotterLive($this->db);
747 747
 					$SpotterLive->deleteLiveSpotterData();
748 748
 					$SpotterLive->db=null;
749
-				    }
750
-				    if ($globalDebug) echo " Done\n";
751
-				    $this->last_delete = time();
749
+					}
750
+					if ($globalDebug) echo " Done\n";
751
+					$this->last_delete = time();
752 752
 				}
753
-			    } else {
753
+				} else {
754 754
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
755
-				    $this->all_flights[$id]['id'] = $recent_ident;
756
-				    $this->all_flights[$id]['addedSpotter'] = 1;
755
+					$this->all_flights[$id]['id'] = $recent_ident;
756
+					$this->all_flights[$id]['addedSpotter'] = 1;
757 757
 				}
758 758
 				if (isset($globalDaemon) && !$globalDaemon) {
759
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
759
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
760 760
 					$Spotter = new Spotter($this->db);
761 761
 					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
762 762
 					$Spotter->db = null;
763
-				    }
763
+					}
764 764
 				}
765 765
 				
766
-			    }
766
+				}
767
+			}
767 768
 			}
768
-		    }
769
-		    //adds the spotter LIVE data
770
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
771
-		    //echo "\nAdd in Live !! \n";
772
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773
-		    if ($globalDebug) {
769
+			//adds the spotter LIVE data
770
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
771
+			//echo "\nAdd in Live !! \n";
772
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773
+			if ($globalDebug) {
774 774
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
775 775
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
776 776
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -778,49 +778,49 @@  discard block
 block discarded – undo
778 778
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
779 779
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
780 780
 			}
781
-		    }
782
-		    $ignoreImport = false;
783
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
784
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
781
+			}
782
+			$ignoreImport = false;
783
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
784
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
785 785
 
786
-		    foreach($globalAirportIgnore as $airportIgnore) {
787
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788
-			    $ignoreImport = true;
786
+			foreach($globalAirportIgnore as $airportIgnore) {
787
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788
+				$ignoreImport = true;
789
+			}
789 790
 			}
790
-		    }
791
-		    if (count($globalAirportAccept) > 0) {
792
-		        $ignoreImport = true;
793
-		        foreach($globalAirportIgnore as $airportIgnore) {
794
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
791
+			if (count($globalAirportAccept) > 0) {
792
+				$ignoreImport = true;
793
+				foreach($globalAirportIgnore as $airportIgnore) {
794
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
795 795
 				$ignoreImport = false;
796
-			    }
796
+				}
797
+			}
797 798
 			}
798
-		    }
799
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
799
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
800 800
 			foreach($globalAirlineIgnore as $airlineIgnore) {
801
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
801
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
802 802
 				$ignoreImport = true;
803
-			    }
803
+				}
804
+			}
804 805
 			}
805
-		    }
806
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
806
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
807 807
 			$ignoreImport = true;
808 808
 			foreach($globalAirlineAccept as $airlineAccept) {
809
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
809
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
810 810
 				$ignoreImport = false;
811
-			    }
811
+				}
812
+			}
812 813
 			}
813
-		    }
814
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
814
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
815 815
 			$ignoreImport = true;
816 816
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
817
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
818
-			        $ignoreImport = false;
819
-			    }
817
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
818
+					$ignoreImport = false;
819
+				}
820
+			}
820 821
 			}
821
-		    }
822 822
 
823
-		    if (!$ignoreImport) {
823
+			if (!$ignoreImport) {
824 824
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825 825
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
826 826
 				$timeelapsed = microtime(true);
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 					if ($stats_heading == 16) $stats_heading = 0;
865 865
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
866 866
 						for ($i=0;$i<=15;$i++) {
867
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
867
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
868 868
 						}
869 869
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
870 870
 					} else {
@@ -877,11 +877,11 @@  discard block
 block discarded – undo
877 877
 					//var_dump($this->stats);
878 878
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
879 879
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
880
-						    end($this->stats[$current_date][$source]['hist']);
881
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
880
+							end($this->stats[$current_date][$source]['hist']);
881
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
882 882
 						} else $mini = 0;
883 883
 						for ($i=$mini;$i<=$distance;$i+=10) {
884
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
884
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
885 885
 						}
886 886
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
887 887
 					} else {
@@ -898,22 +898,22 @@  discard block
 block discarded – undo
898 898
 			
899 899
 			
900 900
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
902
-			    $SpotterLive = new SpotterLive($this->db);
903
-			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
904
-			    $SpotterLive->db = null;
905
-			    //SpotterLive->deleteLiveSpotterData();
906
-			    if ($globalDebug) echo " Done\n";
907
-			    $this->last_delete_hourly = time();
901
+				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
902
+				$SpotterLive = new SpotterLive($this->db);
903
+				$SpotterLive->deleteLiveSpotterDataNotUpdated();
904
+				$SpotterLive->db = null;
905
+				//SpotterLive->deleteLiveSpotterData();
906
+				if ($globalDebug) echo " Done\n";
907
+				$this->last_delete_hourly = time();
908 908
 			}
909 909
 			
910
-		    }
911
-		    //$ignoreImport = false;
910
+			}
911
+			//$ignoreImport = false;
912 912
 		}
913 913
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
914 914
 		if ($send) return $this->all_flights[$id];
915
-	    }
915
+		}
916
+	}
916 917
 	}
917
-    }
918 918
 }
919 919
 ?>
Please login to merge, or discard this patch.
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
33
+	    foreach ($sourcestat as $srcst) {
34 34
 	    	$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36 36
 		    $source = $srcst['source_name'];
37 37
 		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
+		    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
39 39
 	        }
40 40
 	    }
41 41
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+    public function get_Schedule($id, $ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73 73
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
74
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
75
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
76 76
 		    // Should also check if route schedule = route from DB
77 77
 		    if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			    }
93 93
 			}
94 94
 		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
96 96
 		}
97 97
 	    } else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
        if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102 102
     		$sch = $Schedule->getSchedule($operator);
103
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
103
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
104 104
        }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128 128
     		    $Spotter = new Spotter($this->db);
129 129
         	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
130
+        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
131 131
         	}
132 132
 	    }
133 133
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $airport_time = '';
142 142
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
144
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
145 145
     	    if (isset($closestAirports[0])) {
146 146
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 147
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         		    break;
157 157
         		}
158 158
         	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
159
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
160 160
         		$airport_icao = $closestAirports[0]['icao'];
161 161
         		$airport_time = $this->all_flights[$key]['datetime'];
162 162
         	} else {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         } else {
170 170
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171 171
         }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
172
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
173 173
     }
174 174
 
175 175
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182 182
     	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
183
+        	if ($flight['lastupdate'] < (time() - 3000)) {
184 184
             	    if (isset($this->all_flights[$key]['id'])) {
185 185
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             		    $real_arrival = $this->arrival($key);
193 193
             		    $Spotter = new Spotter($this->db);
194 194
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
195
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197 197
 			    }
198 198
 			// Put in archive
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	$send = false;
230 230
 	
231 231
 	// SBS format is CSV format
232
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
232
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233 233
 	    //print_r($line);
234 234
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264 264
 		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
265
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
266
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => ''));
267
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
268 268
 		    if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
272
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
273 273
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
274
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
275 275
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
283
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
284 284
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286 286
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -288,41 +288,41 @@  discard block
 block discarded – undo
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
291
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
291
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
292 292
 			} else {
293 293
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 294
 			}
295 295
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
296
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
297
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
298 298
 		    }
299 299
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
300 300
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
303
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
304 304
 		}
305 305
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
306 306
 			// Get aircraft ICAO from aircraft name
307 307
 			$Spotter = new Spotter($this->db);
308 308
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 309
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
310
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
311 311
 		}
312 312
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313 313
 			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314 314
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315 315
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316 316
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
317
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
318 318
 		}
319 319
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
320
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
323
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) {
324 324
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
325
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
326 326
 		    } else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
 		    }
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
338
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
355
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
356 356
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358 358
             		$Spotter = new Spotter($this->db);
@@ -362,10 +362,10 @@  discard block
 block discarded – undo
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
368
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
369 369
 		    }
370 370
 
371 371
 /*
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381 381
 		    //$putinarchive = true;
382 382
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
383
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
384 384
 		    }
385 385
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
386
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
387 387
 		    }
388 388
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
389
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
390 390
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
395
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
396
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
397 397
 
398 398
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
@@ -406,34 +406,34 @@  discard block
 block discarded – undo
406 406
 				$Translation->db = null;
407 407
 			}
408 408
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
409
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 412
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413 413
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
415
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop']));
416 416
 		    	    }
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
420
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
421 421
 			}
422 422
 		    }
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
427
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
428
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
429 429
 		    //$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
431
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
432 432
 		    if ($distance > 1000 && $distance < 10000) {
433 433
 		    // use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
436
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438 438
 		    }
439 439
 		}
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 
442 442
 
443 443
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
444
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
445 445
 	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
446
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -453,10 +453,10 @@  discard block
 block discarded – undo
453 453
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
454 454
 				$timeelapsed = microtime(true);
455 455
 				$Spotter = new Spotter($this->db);
456
-				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
456
+				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
457 457
 				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
458 458
 				$Spotter->db = null;
459
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
459
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
460 460
 				$this->tmd = 0;
461 461
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462 462
 			    }
@@ -465,13 +465,13 @@  discard block
 block discarded – undo
465 465
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
466 466
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467 467
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
468
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
468
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469 469
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470 470
 				    $dataFound = true;
471 471
 				    $this->all_flights[$id]['time_last_coord'] = time();
472 472
 				}
473 473
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
474
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
474
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
475 475
 				/*
476 476
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
477 477
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -489,13 +489,13 @@  discard block
 block discarded – undo
489 489
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
490 490
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
491 491
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
492
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
492
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493 493
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494 494
 				    $dataFound = true;
495 495
 				    $this->all_flights[$id]['time_last_coord'] = time();
496 496
 				}
497 497
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
498
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
498
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
499 499
 				/*
500 500
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
501 501
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -513,46 +513,46 @@  discard block
 block discarded – undo
513 513
 		    } else if ($globalDebug && $timediff > 20) {
514 514
 			$this->tmd = $this->tmd + 1;
515 515
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
516
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
517
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
516
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
517
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
518 518
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
519 519
 		    }
520 520
 		}
521 521
 		if (isset($line['last_update']) && $line['last_update'] != '') {
522 522
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
523
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
523
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
524 524
 		}
525 525
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
526
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
526
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
527 527
 		    //$dataFound = true;
528 528
 		}
529 529
 		if (isset($line['format_source']) && $line['format_source'] != '') {
530
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
530
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
531 531
 		}
532 532
 		if (isset($line['source_name']) && $line['source_name'] != '') {
533
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
533
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
534 534
 		}
535 535
 		if (isset($line['emergency']) && $line['emergency'] != '') {
536
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
536
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
537 537
 		    //$dataFound = true;
538 538
 		}
539 539
 		if (isset($line['ground']) && $line['ground'] != '') {
540 540
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
541 541
 			// Here we force archive of flight because after ground it's a new one (or should be)
542
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
543
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
544
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
542
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
543
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
544
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
546
+			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
547 547
 		    }
548 548
 		    if ($line['ground'] != 1) $line['ground'] = 0;
549
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
549
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
550 550
 		    //$dataFound = true;
551 551
 		}
552 552
 		if (isset($line['squawk']) && $line['squawk'] != '') {
553 553
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554 554
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
555
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
555
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
556 556
 			    $highlight = '';
557 557
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558 558
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -560,47 +560,47 @@  discard block
 block discarded – undo
560 560
 			    if ($highlight != '') {
561 561
 				$timeelapsed = microtime(true);
562 562
 				$Spotter = new Spotter($this->db);
563
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
563
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
564 564
 				$Spotter->db = null;
565
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
565
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
566 566
 
567 567
 				//$putinarchive = true;
568 568
 				//$highlight = '';
569 569
 			    }
570 570
 			    
571
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
571
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
572 572
 		    //$dataFound = true;
573 573
 		}
574 574
 
575 575
 		if (isset($line['altitude']) && $line['altitude'] != '') {
576 576
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
578
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
579
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
577
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
578
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
579
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
580 580
 			//$dataFound = true;
581 581
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
582 582
   		}
583 583
 
584 584
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
585
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
585
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
586 586
 		}
587 587
 		
588 588
 		if (isset($line['heading']) && $line['heading'] != '') {
589
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
589
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
591
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
592 592
 		    //$dataFound = true;
593 593
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
594
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
594
+  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
595
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
596
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597 597
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
598 598
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
599 599
   		    // If not enough messages and ACARS set heading to 0
600
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
600
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
601 601
   		}
602
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
602
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
604 604
 
605 605
 //		print_r($this->all_flights[$id]);
606 606
 		//gets the callsign from the last hour
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
611 611
 		    $this->all_flights[$id]['lastupdate'] = time();
612 612
 		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
613
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
613
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614 614
 			    //print_r($this->all_flights);
615 615
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616 616
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -620,61 +620,61 @@  discard block
 block discarded – undo
620 620
 				$SpotterLive = new SpotterLive($this->db);
621 621
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
622 622
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
623
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
624 624
 				} elseif (isset($line['id'])) {
625 625
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
626
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
627 627
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
628 628
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
629
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
630 630
 				} else $recent_ident = '';
631
-				$SpotterLive->db=null;
631
+				$SpotterLive->db = null;
632 632
 
633 633
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
634 634
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
635 635
 			    } else {
636 636
 				$recent_ident = '';
637
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
637
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
638 638
 			    }
639 639
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
640
-			    if($recent_ident == "")
640
+			    if ($recent_ident == "")
641 641
 			    {
642 642
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
643 643
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
644 644
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
645 645
 				//adds the spotter data for the archive
646 646
 				$ignoreImport = false;
647
-				foreach($globalAirportIgnore as $airportIgnore) {
647
+				foreach ($globalAirportIgnore as $airportIgnore) {
648 648
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
649 649
 					$ignoreImport = true;
650 650
 				    }
651 651
 				}
652 652
 				if (count($globalAirportAccept) > 0) {
653 653
 				    $ignoreImport = true;
654
-				    foreach($globalAirportIgnore as $airportIgnore) {
654
+				    foreach ($globalAirportIgnore as $airportIgnore) {
655 655
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
656 656
 					    $ignoreImport = false;
657 657
 					}
658 658
 				    }
659 659
 				}
660 660
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
661
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
662
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
661
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
662
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
663 663
 					    $ignoreImport = true;
664 664
 					}
665 665
 				    }
666 666
 				}
667 667
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
668 668
 				    $ignoreImport = true;
669
-				    foreach($globalAirlineAccept as $airlineAccept) {
670
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
669
+				    foreach ($globalAirlineAccept as $airlineAccept) {
670
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
671 671
 					    $ignoreImport = false;
672 672
 					}
673 673
 				    }
674 674
 				}
675 675
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
676 676
 				    $ignoreImport = true;
677
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
677
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
678 678
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
679 679
 					    $ignoreImport = false;
680 680
 					}
@@ -686,29 +686,29 @@  discard block
 block discarded – undo
686 686
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687 687
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688 688
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
689
+				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690 690
 				    $timeelapsed = microtime(true);
691 691
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
692 692
 					$Spotter = new Spotter($this->db);
693
-					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
693
+					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']);
694 694
 					$Spotter->db = null;
695 695
 					if ($globalDebug && isset($result)) echo $result."\n";
696 696
 				    }
697
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
698 698
 				    
699 699
 				    // Add source stat in DB
700 700
 				    $Stats = new Stats($this->db);
701 701
 				    if (!empty($this->stats)) {
702 702
 					if ($globalDebug) echo 'Add source stats : ';
703
-				        foreach($this->stats as $date => $data) {
704
-					    foreach($data as $source => $sourced) {
703
+				        foreach ($this->stats as $date => $data) {
704
+					    foreach ($data as $source => $sourced) {
705 705
 					        //print_r($sourced);
706
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
706
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
707
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
708 708
 				    		if (isset($sourced['msg'])) {
709 709
 				    		    if (time() - $sourced['msg']['date'] > 10) {
710 710
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
711
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
711
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
712 712
 			    			        unset($this->stats[$date][$source]['msg']);
713 713
 			    			    }
714 714
 			    			}
@@ -745,20 +745,20 @@  discard block
 block discarded – undo
745 745
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
746 746
 					$SpotterLive = new SpotterLive($this->db);
747 747
 					$SpotterLive->deleteLiveSpotterData();
748
-					$SpotterLive->db=null;
748
+					$SpotterLive->db = null;
749 749
 				    }
750 750
 				    if ($globalDebug) echo " Done\n";
751 751
 				    $this->last_delete = time();
752 752
 				}
753 753
 			    } else {
754
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
754
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
755 755
 				    $this->all_flights[$id]['id'] = $recent_ident;
756 756
 				    $this->all_flights[$id]['addedSpotter'] = 1;
757 757
 				}
758 758
 				if (isset($globalDaemon) && !$globalDaemon) {
759 759
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
760 760
 					$Spotter = new Spotter($this->db);
761
-					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
761
+					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
762 762
 					$Spotter->db = null;
763 763
 				    }
764 764
 				}
@@ -783,37 +783,37 @@  discard block
 block discarded – undo
783 783
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
784 784
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
785 785
 
786
-		    foreach($globalAirportIgnore as $airportIgnore) {
786
+		    foreach ($globalAirportIgnore as $airportIgnore) {
787 787
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788 788
 			    $ignoreImport = true;
789 789
 			}
790 790
 		    }
791 791
 		    if (count($globalAirportAccept) > 0) {
792 792
 		        $ignoreImport = true;
793
-		        foreach($globalAirportIgnore as $airportIgnore) {
793
+		        foreach ($globalAirportIgnore as $airportIgnore) {
794 794
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
795 795
 				$ignoreImport = false;
796 796
 			    }
797 797
 			}
798 798
 		    }
799 799
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
800
-			foreach($globalAirlineIgnore as $airlineIgnore) {
801
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
800
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
801
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
802 802
 				$ignoreImport = true;
803 803
 			    }
804 804
 			}
805 805
 		    }
806 806
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
807 807
 			$ignoreImport = true;
808
-			foreach($globalAirlineAccept as $airlineAccept) {
809
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
808
+			foreach ($globalAirlineAccept as $airlineAccept) {
809
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
810 810
 				$ignoreImport = false;
811 811
 			    }
812 812
 			}
813 813
 		    }
814 814
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
815 815
 			$ignoreImport = true;
816
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
816
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
817 817
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
818 818
 			        $ignoreImport = false;
819 819
 			    }
@@ -821,19 +821,19 @@  discard block
 block discarded – undo
821 821
 		    }
822 822
 
823 823
 		    if (!$ignoreImport) {
824
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
824
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825 825
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
826 826
 				$timeelapsed = microtime(true);
827 827
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
828 828
 					$SpotterLive = new SpotterLive($this->db);
829
-					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
829
+					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
830 830
 					$SpotterLive->db = null;
831 831
 				}
832 832
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
833
-					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
833
+					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
834 834
 				}
835 835
 				$this->all_flights[$id]['putinarchive'] = false;
836
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
836
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
837 837
 
838 838
 				// Put statistics in $this->stats variable
839 839
 				//if ($line['format_source'] != 'aprs') {
@@ -851,19 +851,19 @@  discard block
 block discarded – undo
851 851
 							$latitude = $globalCenterLatitude;
852 852
 							$longitude = $globalCenterLongitude;
853 853
 						}
854
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
854
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
855 855
 					} else {
856 856
 						$latitude = $this->source_location[$source]['latitude'];
857 857
 						$longitude = $this->source_location[$source]['longitude'];
858 858
 					}
859
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
859
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
860 860
 					//$stats_heading = $stats_heading%22.5;
861 861
 					$stats_heading = round($stats_heading/22.5);
862
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
862
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
863 863
 					$current_date = date('Y-m-d');
864 864
 					if ($stats_heading == 16) $stats_heading = 0;
865 865
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
866
-						for ($i=0;$i<=15;$i++) {
866
+						for ($i = 0; $i <= 15; $i++) {
867 867
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
868 868
 						}
869 869
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -878,9 +878,9 @@  discard block
 block discarded – undo
878 878
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
879 879
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
880 880
 						    end($this->stats[$current_date][$source]['hist']);
881
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
881
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
882 882
 						} else $mini = 0;
883
-						for ($i=$mini;$i<=$distance;$i+=10) {
883
+						for ($i = $mini; $i <= $distance; $i += 10) {
884 884
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
885 885
 						}
886 886
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
894 894
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
895 895
 				if ($globalDebug) echo $result."\n";
896
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
896
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
897 897
 			//$this->del();
898 898
 			
899 899
 			
Please login to merge, or discard this patch.
Braces   +331 added lines, -117 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
 	$dbc = $this->db;
60 60
 	$this->all_flights[$id]['schedule_check'] = true;
61 61
 	if ($globalSchedulesFetch) {
62
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Getting schedule info...'."\n";
64
+	}
63 65
 	$Spotter = new Spotter($dbc);
64 66
 	$Schedule = new Schedule($dbc);
65 67
 	$Translation = new Translation($dbc);
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
 	    if ($Schedule->checkSchedule($operator) == 0) {
71 73
 		$schedule = $Schedule->fetchSchedule($operator);
72 74
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
75
+		    if ($globalDebug) {
76
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
77
+		    }
74 78
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75 79
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76 80
 		    // Should also check if route schedule = route from DB
@@ -79,7 +83,9 @@  discard block
 block discarded – undo
79 83
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80 84
 			    if (trim($airport_icao) != '') {
81 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
86
+				if ($globalDebug) {
87
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
88
+				}
83 89
 			    }
84 90
 			}
85 91
 		    }
@@ -88,17 +94,25 @@  discard block
 block discarded – undo
88 94
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89 95
 			    if (trim($airport_icao) != '') {
90 96
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
97
+				if ($globalDebug) {
98
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
99
+				}
92 100
 			    }
93 101
 			}
94 102
 		    }
95 103
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 104
 		}
97
-	    } else $scheduleexist = true;
98
-	} else $scheduleexist = true;
105
+	    } else {
106
+	    	$scheduleexist = true;
107
+	    }
108
+	} else {
109
+		$scheduleexist = true;
110
+	}
99 111
 	// close connection, at least one way will work ?
100 112
        if ($scheduleexist) {
101
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
113
+		if ($globalDebug) {
114
+			echo "-> get arrival/departure airport info for ".$ident."\n";
115
+		}
102 116
     		$sch = $Schedule->getSchedule($operator);
103 117
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104 118
        }
@@ -120,7 +134,9 @@  discard block
 block discarded – undo
120 134
 
121 135
     public function checkAll() {
122 136
 	global $globalDebug, $globalNoImport;
123
-	if ($globalDebug) echo "Update last seen flights data...\n";
137
+	if ($globalDebug) {
138
+		echo "Update last seen flights data...\n";
139
+	}
124 140
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125 141
 	    foreach ($this->all_flights as $key => $flight) {
126 142
 		if (isset($this->all_flights[$key]['id'])) {
@@ -135,24 +151,32 @@  discard block
 block discarded – undo
135 151
 
136 152
     public function arrival($key) {
137 153
 	global $globalClosestMinDist, $globalDebug;
138
-	if ($globalDebug) echo 'Update arrival...'."\n";
154
+	if ($globalDebug) {
155
+		echo 'Update arrival...'."\n";
156
+	}
139 157
 	$Spotter = new Spotter($this->db);
140 158
         $airport_icao = '';
141 159
         $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
161
+        	$globalClosestMinDist = 50;
162
+        }
143 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144 164
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145 165
     	    if (isset($closestAirports[0])) {
146 166
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 167
         	    $airport_icao = $closestAirports[0]['icao'];
148 168
         	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        	    if ($globalDebug) {
170
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        	    }
150 172
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151 173
         	    foreach ($closestAirports as $airport) {
152 174
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153 175
         		    $airport_icao = $airport['icao'];
154 176
         		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        		    if ($globalDebug) {
178
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
179
+        		    }
156 180
         		    break;
157 181
         		}
158 182
         	    }
@@ -160,14 +184,20 @@  discard block
 block discarded – undo
160 184
         		$airport_icao = $closestAirports[0]['icao'];
161 185
         		$airport_time = $this->all_flights[$key]['datetime'];
162 186
         	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
187
+        		if ($globalDebug) {
188
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
189
+        		}
164 190
         	}
165 191
     	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
192
+    		    if ($globalDebug) {
193
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
194
+    		    }
167 195
     	    }
168 196
 
169 197
         } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
198
+        	if ($globalDebug) {
199
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
200
+        	}
171 201
         }
172 202
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173 203
     }
@@ -177,12 +207,16 @@  discard block
 block discarded – undo
177 207
     public function del() {
178 208
 	global $globalDebug, $globalNoImport;
179 209
 	// Delete old infos
180
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
210
+	if ($globalDebug) {
211
+		echo 'Delete old values and update latest data...'."\n";
212
+	}
181 213
 	foreach ($this->all_flights as $key => $flight) {
182 214
     	    if (isset($flight['lastupdate'])) {
183 215
         	if ($flight['lastupdate'] < (time()-3000)) {
184 216
             	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
217
+            		if ($globalDebug) {
218
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
219
+            		}
186 220
 			/*
187 221
 			$SpotterLive = new SpotterLive();
188 222
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -193,7 +227,9 @@  discard block
 block discarded – undo
193 227
             		    $Spotter = new Spotter($this->db);
194 228
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 229
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
230
+				if ($globalDebug && $result != 'success') {
231
+					echo '!!! ERROR : '.$result."\n";
232
+				}
197 233
 			    }
198 234
 			// Put in archive
199 235
 //				$Spotter->db = null;
@@ -208,8 +244,10 @@  discard block
 block discarded – undo
208 244
     public function add($line) {
209 245
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 246
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
212
-/*
247
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
248
+		$globalCoordMinChange = '0.02';
249
+	}
250
+	/*
213 251
 	$Spotter = new Spotter();
214 252
 	$dbc = $Spotter->db;
215 253
 	$SpotterLive = new SpotterLive($dbc);
@@ -237,11 +275,15 @@  discard block
 block discarded – undo
237 275
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238 276
 		    $current_date = date('Y-m-d');
239 277
 		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
278
+		    if ($source == '' || $line['format_source'] == 'aprs') {
279
+		    	$source = $line['format_source'];
280
+		    }
241 281
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242 282
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243 283
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
284
+		    } else {
285
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
286
+		    }
245 287
 		}
246 288
 		
247 289
 		/*
@@ -257,8 +299,11 @@  discard block
 block discarded – undo
257 299
 		//$this->db = $dbc;
258 300
 
259 301
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
302
+	        if (!isset($line['id'])) {
303
+	        	$id = trim($line['hex']);
304
+	        } else {
305
+	        	$id = trim($line['id']);
306
+	        }
262 307
 		
263 308
 		if (!isset($this->all_flights[$id])) {
264 309
 		    $this->all_flights[$id] = array();
@@ -266,13 +311,21 @@  discard block
 block discarded – undo
266 311
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267 312
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268 313
 		    if (!isset($line['id'])) {
269
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
314
+			if (!isset($globalDaemon)) {
315
+				$globalDaemon = TRUE;
316
+			}
317
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 318
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
319
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
320
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
321
+			}
273 322
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
323
+		     } else {
324
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
325
+		     }
326
+		    if ($globalAllFlights !== FALSE) {
327
+		    	$dataFound = true;
328
+		    }
276 329
 		}
277 330
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278 331
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -293,11 +346,19 @@  discard block
 block discarded – undo
293 346
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 347
 			}
295 348
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
349
+			if ($globalDebugTimeElapsed) {
350
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+			}
352
+			if ($aircraft_icao != '') {
353
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
354
+			}
355
+		    }
356
+		    if ($globalAllFlights !== FALSE) {
357
+		    	$dataFound = true;
358
+		    }
359
+		    if ($globalDebug) {
360
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298 361
 		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 362
 		}
302 363
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 364
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -307,14 +368,23 @@  discard block
 block discarded – undo
307 368
 			$Spotter = new Spotter($this->db);
308 369
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 370
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
371
+			if ($aircraft_icao != '') {
372
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
373
+			}
311 374
 		}
312 375
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
376
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
377
+				$aircraft_icao = 'GLID';
378
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
379
+				$aircraft_icao = 'UHEL';
380
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
381
+				$aircraft_icao = 'TOWPLANE';
382
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
383
+				$aircraft_icao = 'POWAIRC';
384
+			}
385
+			if (isset($aircraft_icao)) {
386
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
387
+			}
318 388
 		}
319 389
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320 390
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -324,8 +394,11 @@  discard block
 block discarded – undo
324 394
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326 396
 		    } else {
327
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
397
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
398
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
399
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
400
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
401
+				}
329 402
 				/*
330 403
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
331 404
 				print_r($this->all_flights[$id]);
@@ -357,15 +430,25 @@  discard block
 block discarded – undo
357 430
 			$timeelapsed = microtime(true);
358 431
             		$Spotter = new Spotter($this->db);
359 432
             		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
433
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
434
+            			$fromsource = $globalAirlinesSource;
435
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
436
+            			$fromsource = 'vatsim';
437
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
438
+				$fromsource = 'ivao';
439
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
440
+				$fromsource = 'vatsim';
441
+			} elseif (isset($globalIVAO) && $globalIVAO) {
442
+				$fromsource = 'ivao';
443
+			}
365 444
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
445
+			if ($globalDebug && $result != 'success') {
446
+				echo '!!! ERROR : '.$result."\n";
447
+			}
367 448
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
449
+			if ($globalDebugTimeElapsed) {
450
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+			}
369 452
 		    }
370 453
 
371 454
 /*
@@ -376,7 +459,9 @@  discard block
 block discarded – undo
376 459
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 460
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 461
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
462
+		    if (!isset($this->all_flights[$id]['id'])) {
463
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
464
+		    }
380 465
 
381 466
 		    //$putinarchive = true;
382 467
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -393,7 +478,9 @@  discard block
 block discarded – undo
393 478
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 479
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395 480
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481
+				if ($globalDebugTimeElapsed) {
482
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
483
+				}
397 484
 
398 485
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 486
 			$timeelapsed = microtime(true);
@@ -406,7 +493,9 @@  discard block
 block discarded – undo
406 493
 				$Translation->db = null;
407 494
 			}
408 495
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
496
+			if ($globalDebugTimeElapsed) {
497
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
498
+			}
410 499
 
411 500
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 501
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -415,9 +504,13 @@  discard block
 block discarded – undo
415 504
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416 505
 		    	    }
417 506
 			}
418
-			if (!isset($globalFork)) $globalFork = TRUE;
507
+			if (!isset($globalFork)) {
508
+				$globalFork = TRUE;
509
+			}
419 510
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
511
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
512
+					$this->get_Schedule($id,trim($line['ident']));
513
+				}
421 514
 			}
422 515
 		    }
423 516
 		}
@@ -433,16 +526,23 @@  discard block
 block discarded – undo
433 526
 		    // use datetime
434 527
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 528
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
529
+			if ($speed < 1000) {
530
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
531
+			}
532
+  			if ($globalDebug) {
533
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
534
+  			}
438 535
 		    }
439 536
 		}
440 537
 
441 538
 
442 539
 
443 540
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
541
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
542
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
543
+	    	    } else {
544
+	    	    	unset($timediff);
545
+	    	    }
446 546
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 547
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448 548
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -450,21 +550,31 @@  discard block
 block discarded – undo
450 550
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 551
 				$this->all_flights[$id]['putinarchive'] = true;
452 552
 				
453
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
553
+				if ($globalDebug) {
554
+					echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
555
+				}
454 556
 				$timeelapsed = microtime(true);
455 557
 				$Spotter = new Spotter($this->db);
456 558
 				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
457
-				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
559
+				if (!empty($all_country)) {
560
+					$this->all_flights[$id]['over_country'] = $all_country['iso2'];
561
+				}
458 562
 				$Spotter->db = null;
459
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
563
+				if ($globalDebugTimeElapsed) {
564
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
565
+				}
460 566
 				$this->tmd = 0;
461
-				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
567
+				if ($globalDebug) {
568
+					echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
+				}
462 570
 			    }
463 571
 			}
464 572
 
465 573
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
466 574
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
575
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
576
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
577
+				}
468 578
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469 579
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470 580
 				    $dataFound = true;
@@ -486,9 +596,13 @@  discard block
 block discarded – undo
486 596
 			    */
487 597
 			}
488 598
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
489
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
599
+			    if ($line['longitude'] > 180) {
600
+			    	$line['longitude'] = $line['longitude'] - 360;
601
+			    }
490 602
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
491
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
603
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
604
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
605
+				}
492 606
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493 607
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494 608
 				    $dataFound = true;
@@ -519,7 +633,9 @@  discard block
 block discarded – undo
519 633
 		    }
520 634
 		}
521 635
 		if (isset($line['last_update']) && $line['last_update'] != '') {
522
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
636
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
637
+		    	$dataFound = true;
638
+		    }
523 639
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524 640
 		}
525 641
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -541,40 +657,60 @@  discard block
 block discarded – undo
541 657
 			// Here we force archive of flight because after ground it's a new one (or should be)
542 658
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
543 659
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
544
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
660
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
661
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
662
+			} elseif (isset($line['id'])) {
663
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
664
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
665
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
666
+			}
667
+		    }
668
+		    if ($line['ground'] != 1) {
669
+		    	$line['ground'] = 0;
547 670
 		    }
548
-		    if ($line['ground'] != 1) $line['ground'] = 0;
549 671
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550 672
 		    //$dataFound = true;
551 673
 		}
552 674
 		if (isset($line['squawk']) && $line['squawk'] != '') {
553 675
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
676
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
677
+			    	$this->all_flights[$id]['putinarchive'] = true;
678
+			    }
555 679
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556 680
 			    $highlight = '';
557
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
681
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
682
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
683
+			    }
684
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
685
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
686
+			    }
687
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
688
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
689
+			    }
560 690
 			    if ($highlight != '') {
561 691
 				$timeelapsed = microtime(true);
562 692
 				$Spotter = new Spotter($this->db);
563 693
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
564 694
 				$Spotter->db = null;
565
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
695
+				if ($globalDebugTimeElapsed) {
696
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697
+				}
566 698
 
567 699
 				//$putinarchive = true;
568 700
 				//$highlight = '';
569 701
 			    }
570 702
 			    
571
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
703
+		    } else {
704
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
705
+		    }
572 706
 		    //$dataFound = true;
573 707
 		}
574 708
 
575 709
 		if (isset($line['altitude']) && $line['altitude'] != '') {
576 710
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
711
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
712
+				$this->all_flights[$id]['putinarchive'] = true;
713
+			}
578 714
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
579 715
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
580 716
 			//$dataFound = true;
@@ -586,21 +722,30 @@  discard block
 block discarded – undo
586 722
 		}
587 723
 		
588 724
 		if (isset($line['heading']) && $line['heading'] != '') {
589
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
725
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
726
+		    	$this->all_flights[$id]['putinarchive'] = true;
727
+		    }
590 728
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591 729
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592 730
 		    //$dataFound = true;
593 731
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
594 732
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595 733
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
734
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
735
+		    	$this->all_flights[$id]['putinarchive'] = true;
736
+		    }
737
+  		    if ($globalDebug) {
738
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
739
+  		    }
598 740
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
599 741
   		    // If not enough messages and ACARS set heading to 0
600 742
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601 743
   		}
602
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
744
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
745
+			$dataFound = false;
746
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
747
+			$dataFound = false;
748
+		}
604 749
 
605 750
 //		print_r($this->all_flights[$id]);
606 751
 		//gets the callsign from the last hour
@@ -615,23 +760,36 @@  discard block
 block discarded – undo
615 760
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616 761
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617 762
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
618
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
763
+				if ($globalDebug) {
764
+					echo "Check if aircraft is already in DB...";
765
+				}
619 766
 				$timeelapsed = microtime(true);
620 767
 				$SpotterLive = new SpotterLive($this->db);
621 768
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
622 769
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
770
+				    if ($globalDebugTimeElapsed) {
771
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
772
+				    }
624 773
 				} elseif (isset($line['id'])) {
625 774
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
775
+				    if ($globalDebugTimeElapsed) {
776
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
777
+				    }
627 778
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
628 779
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630
-				} else $recent_ident = '';
780
+				    if ($globalDebugTimeElapsed) {
781
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
782
+				    }
783
+				} else {
784
+					$recent_ident = '';
785
+				}
631 786
 				$SpotterLive->db=null;
632 787
 
633
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
634
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
788
+				if ($globalDebug && $recent_ident == '') {
789
+					echo " Not in DB.\n";
790
+				} elseif ($globalDebug && $recent_ident != '') {
791
+					echo " Already in DB.\n";
792
+				}
635 793
 			    } else {
636 794
 				$recent_ident = '';
637 795
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -639,7 +797,9 @@  discard block
 block discarded – undo
639 797
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
640 798
 			    if($recent_ident == "")
641 799
 			    {
642
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
800
+				if ($globalDebug) {
801
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
802
+				}
643 803
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
644 804
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
645 805
 				//adds the spotter data for the archive
@@ -683,28 +843,46 @@  discard block
 block discarded – undo
683 843
 				
684 844
 				if (!$ignoreImport) {
685 845
 				    $highlight = '';
686
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
846
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
847
+				    	$highlight = 'Squawk 7500 : Hijack';
848
+				    }
849
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
850
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
851
+				    }
852
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
853
+				    	$highlight = 'Squawk 7700 : Emergency';
854
+				    }
855
+				    if (!isset($this->all_flights[$id]['id'])) {
856
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
857
+				    }
690 858
 				    $timeelapsed = microtime(true);
691 859
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
692 860
 					$Spotter = new Spotter($this->db);
693 861
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694 862
 					$Spotter->db = null;
695
-					if ($globalDebug && isset($result)) echo $result."\n";
863
+					if ($globalDebug && isset($result)) {
864
+						echo $result."\n";
865
+					}
866
+				    }
867
+				    if ($globalDebugTimeElapsed) {
868
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696 869
 				    }
697
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698 870
 				    
699 871
 				    // Add source stat in DB
700 872
 				    $Stats = new Stats($this->db);
701 873
 				    if (!empty($this->stats)) {
702
-					if ($globalDebug) echo 'Add source stats : ';
874
+					if ($globalDebug) {
875
+						echo 'Add source stats : ';
876
+					}
703 877
 				        foreach($this->stats as $date => $data) {
704 878
 					    foreach($data as $source => $sourced) {
705 879
 					        //print_r($sourced);
706
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
880
+				    	        if (isset($sourced['polar'])) {
881
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
882
+				    	        }
883
+				    	        if (isset($sourced['hist'])) {
884
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
885
+				    	        }
708 886
 				    		if (isset($sourced['msg'])) {
709 887
 				    		    if (time() - $sourced['msg']['date'] > 10) {
710 888
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -717,13 +895,17 @@  discard block
 block discarded – undo
717 895
 			    			unset($this->stats[$date]);
718 896
 			    		    }
719 897
 				    	}
720
-				    	if ($globalDebug) echo 'Done'."\n";
898
+				    	if ($globalDebug) {
899
+				    		echo 'Done'."\n";
900
+				    	}
721 901
 
722 902
 				    }
723 903
 				    $Stats->db = null;
724 904
 				    
725 905
 				    $this->del();
726
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
906
+				} elseif ($globalDebug) {
907
+					echo 'Ignore data'."\n";
908
+				}
727 909
 				//$ignoreImport = false;
728 910
 				$this->all_flights[$id]['addedSpotter'] = 1;
729 911
 				//print_r($this->all_flights[$id]);
@@ -740,14 +922,18 @@  discard block
 block discarded – undo
740 922
 			*/
741 923
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
742 924
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
743
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
925
+				    if ($globalDebug) {
926
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
927
+				    }
744 928
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
745 929
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
746 930
 					$SpotterLive = new SpotterLive($this->db);
747 931
 					$SpotterLive->deleteLiveSpotterData();
748 932
 					$SpotterLive->db=null;
749 933
 				    }
750
-				    if ($globalDebug) echo " Done\n";
934
+				    if ($globalDebug) {
935
+				    	echo " Done\n";
936
+				    }
751 937
 				    $this->last_delete = time();
752 938
 				}
753 939
 			    } else {
@@ -772,11 +958,17 @@  discard block
 block discarded – undo
772 958
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773 959
 		    if ($globalDebug) {
774 960
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
775
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
776
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
961
+				if (isset($this->all_flights[$id]['source_name'])) {
962
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
963
+				} else {
964
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
965
+				}
777 966
 			} else {
778
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
779
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
967
+				if (isset($this->all_flights[$id]['source_name'])) {
968
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
969
+				} else {
970
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
971
+				}
780 972
 			}
781 973
 		    }
782 974
 		    $ignoreImport = false;
@@ -822,7 +1014,9 @@  discard block
 block discarded – undo
822 1014
 
823 1015
 		    if (!$ignoreImport) {
824 1016
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1017
+				if ($globalDebug) {
1018
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1019
+				}
826 1020
 				$timeelapsed = microtime(true);
827 1021
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
828 1022
 					$SpotterLive = new SpotterLive($this->db);
@@ -833,14 +1027,18 @@  discard block
 block discarded – undo
833 1027
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
834 1028
 				}
835 1029
 				$this->all_flights[$id]['putinarchive'] = false;
836
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1030
+				if ($globalDebugTimeElapsed) {
1031
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1032
+				}
837 1033
 
838 1034
 				// Put statistics in $this->stats variable
839 1035
 				//if ($line['format_source'] != 'aprs') {
840 1036
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
841 1037
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
842 1038
 					$source = $this->all_flights[$id]['source_name'];
843
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1039
+					if ($source == '') {
1040
+						$source = $this->all_flights[$id]['format_source'];
1041
+					}
844 1042
 					if (!isset($this->source_location[$source])) {
845 1043
 						$Location = new Source();
846 1044
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -861,7 +1059,9 @@  discard block
 block discarded – undo
861 1059
 					$stats_heading = round($stats_heading/22.5);
862 1060
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
863 1061
 					$current_date = date('Y-m-d');
864
-					if ($stats_heading == 16) $stats_heading = 0;
1062
+					if ($stats_heading == 16) {
1063
+						$stats_heading = 0;
1064
+					}
865 1065
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
866 1066
 						for ($i=0;$i<=15;$i++) {
867 1067
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -879,7 +1079,9 @@  discard block
 block discarded – undo
879 1079
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
880 1080
 						    end($this->stats[$current_date][$source]['hist']);
881 1081
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
882
-						} else $mini = 0;
1082
+						} else {
1083
+							$mini = 0;
1084
+						}
883 1085
 						for ($i=$mini;$i<=$distance;$i+=10) {
884 1086
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
885 1087
 						}
@@ -890,20 +1092,30 @@  discard block
 block discarded – undo
890 1092
 				}
891 1093
 
892 1094
 				$this->all_flights[$id]['lastupdate'] = time();
893
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1095
+				if ($this->all_flights[$id]['putinarchive']) {
1096
+					$send = true;
1097
+				}
894 1098
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
895
-				if ($globalDebug) echo $result."\n";
896
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1099
+				if ($globalDebug) {
1100
+					echo $result."\n";
1101
+				}
1102
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1103
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1104
+			}
897 1105
 			//$this->del();
898 1106
 			
899 1107
 			
900 1108
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1109
+			    if ($globalDebug) {
1110
+			    	echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1111
+			    }
902 1112
 			    $SpotterLive = new SpotterLive($this->db);
903 1113
 			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
904 1114
 			    $SpotterLive->db = null;
905 1115
 			    //SpotterLive->deleteLiveSpotterData();
906
-			    if ($globalDebug) echo " Done\n";
1116
+			    if ($globalDebug) {
1117
+			    	echo " Done\n";
1118
+			    }
907 1119
 			    $this->last_delete_hourly = time();
908 1120
 			}
909 1121
 			
@@ -911,7 +1123,9 @@  discard block
 block discarded – undo
911 1123
 		    //$ignoreImport = false;
912 1124
 		}
913 1125
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
914
-		if ($send) return $this->all_flights[$id];
1126
+		if ($send) {
1127
+			return $this->all_flights[$id];
1128
+		}
915 1129
 	    }
916 1130
 	}
917 1131
     }
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class MarineImport {
13
-    private $all_tracked = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
13
+	private $all_tracked = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21 21
 
22
-    public function __construct($dbc = null) {
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -41,50 +41,50 @@  discard block
 block discarded – undo
41 41
 	    }
42 42
 	}
43 43
 	*/
44
-    }
44
+	}
45 45
 
46
-    public function checkAll() {
46
+	public function checkAll() {
47 47
 	global $globalDebug;
48 48
 	if ($globalDebug) echo "Update last seen tracked data...\n";
49 49
 	foreach ($this->all_tracked as $key => $flight) {
50
-	    if (isset($this->all_tracked[$key]['id'])) {
50
+		if (isset($this->all_tracked[$key]['id'])) {
51 51
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
52
-    		$Marine = new Marine($this->db);
53
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
54
-            }
52
+			$Marine = new Marine($this->db);
53
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
54
+			}
55
+	}
55 56
 	}
56
-    }
57 57
 
58
-    public function del() {
58
+	public function del() {
59 59
 	global $globalDebug;
60 60
 	// Delete old infos
61 61
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62 62
 	foreach ($this->all_tracked as $key => $flight) {
63
-    	    if (isset($flight['lastupdate'])) {
64
-        	if ($flight['lastupdate'] < (time()-3000)) {
65
-            	    if (isset($this->all_tracked[$key]['id'])) {
66
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
63
+			if (isset($flight['lastupdate'])) {
64
+			if ($flight['lastupdate'] < (time()-3000)) {
65
+					if (isset($this->all_tracked[$key]['id'])) {
66
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
67 67
 			/*
68 68
 			$MarineLive = new MarineLive();
69 69
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
70 70
 			$MarineLive->db = null;
71 71
 			*/
72
-            		//$real_arrival = $this->arrival($key);
73
-            		$Marine = new Marine($this->db);
74
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
72
+					//$real_arrival = $this->arrival($key);
73
+					$Marine = new Marine($this->db);
74
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75 75
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
76 76
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
77 77
 			}
78 78
 			// Put in archive
79 79
 //			$Marine->db = null;
80
-            	    }
81
-            	    unset($this->all_tracked[$key]);
82
-    	        }
83
-	    }
84
-        }
85
-    }
80
+					}
81
+					unset($this->all_tracked[$key]);
82
+				}
83
+		}
84
+		}
85
+	}
86 86
 
87
-    public function add($line) {
87
+	public function add($line) {
88 88
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
89 89
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
90 90
 	date_default_timezone_set('UTC');
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	
94 94
 	// SBS format is CSV format
95 95
 	if(is_array($line) && isset($line['mmsi'])) {
96
-	    //print_r($line);
97
-  	    if (isset($line['mmsi'])) {
96
+		//print_r($line);
97
+  		if (isset($line['mmsi'])) {
98 98
 
99 99
 		/*
100 100
 		// Increment message number
@@ -111,87 +111,87 @@  discard block
 block discarded – undo
111 111
 		
112 112
 		$Common = new Common();
113 113
 		$AIS = new AIS();
114
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
115
-	        else $id = trim($line['id']);
114
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
115
+			else $id = trim($line['id']);
116 116
 		
117 117
 		if (!isset($this->all_tracked[$id])) {
118
-		    $this->all_tracked[$id] = array();
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
-		    if (!isset($line['id'])) {
118
+			$this->all_tracked[$id] = array();
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
+			if (!isset($line['id'])) {
123 123
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
124 124
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
125
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
125
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
+			if ($globalAllTracked !== FALSE) $dataFound = true;
127 127
 		}
128 128
 		
129 129
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
-		    $Marine = new Marine($this->db);
132
-		    $identity = $Marine->getIdentity($line['mmsi']);
133
-		    if (!empty($identity)) {
130
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
+			$Marine = new Marine($this->db);
132
+			$identity = $Marine->getIdentity($line['mmsi']);
133
+			if (!empty($identity)) {
134 134
 			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
135 135
 			$this->all_tracked[$id]['type'] = $identity['type'];
136
-		    }
137
-		    //print_r($identity);
138
-		    unset($Marine);
139
-		    //$dataFound = true;
136
+			}
137
+			//print_r($identity);
138
+			unset($Marine);
139
+			//$dataFound = true;
140 140
 		}
141 141
 		if (isset($line['type_id']) && $line['type_id'] != '') {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
142
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
143 143
 		}
144 144
 		if (isset($line['type']) && $line['type'] != '') {
145
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
145
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
146 146
 		}
147 147
 		if (isset($line['imo']) && $line['imo'] != '') {
148
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
148
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
149 149
 		}
150 150
 		if (isset($line['callsign']) && $line['callsign'] != '') {
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
151
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
152 152
 		}
153 153
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
154
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
155 155
 		}
156 156
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
158 158
 		}
159 159
 
160 160
 
161 161
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
162 162
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
165 165
 			$timeelapsed = microtime(true);
166
-            		$Marine = new Marine($this->db);
167
-            		$fromsource = NULL;
168
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
166
+					$Marine = new Marine($this->db);
167
+					$fromsource = NULL;
168
+					$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
169 169
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170 170
 			$Marine->db = null;
171 171
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
172
-		    }
173
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
172
+			}
173
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
174 174
 		}
175 175
 
176 176
 		if (isset($line['speed']) && $line['speed'] != '') {
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
177
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
179 179
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
180
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
-		    if ($distance > 1000 && $distance < 10000) {
180
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
+			if ($distance > 1000 && $distance < 10000) {
182 182
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 183
 			$speed = $speed*3.6;
184 184
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
185 185
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
186
-		    }
186
+			}
187 187
 		}
188 188
 
189
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
-	    	    else unset($timediff);
192
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
189
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
+				else unset($timediff);
192
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
193 193
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
194
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
194
+				if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
195 195
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
196 196
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 197
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -205,76 +205,76 @@  discard block
 block discarded – undo
205 205
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
206 206
 				$this->tmd = 0;
207 207
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
208
-			    }
208
+				}
209 209
 			}
210 210
 
211 211
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212 212
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
213 213
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
214
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
-				    $dataFound = true;
216
-				    $this->all_tracked[$id]['time_last_coord'] = time();
214
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
+					$dataFound = true;
216
+					$this->all_tracked[$id]['time_last_coord'] = time();
217 217
 				}
218 218
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
219 219
 			}
220 220
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
221
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222 222
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
223 223
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
224
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
-				    $dataFound = true;
226
-				    $this->all_tracked[$id]['time_last_coord'] = time();
224
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
+					$dataFound = true;
226
+					$this->all_tracked[$id]['time_last_coord'] = time();
227 227
 				}
228 228
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
229 229
 			}
230 230
 
231
-		    } else if ($globalDebug && $timediff > 20) {
231
+			} else if ($globalDebug && $timediff > 20) {
232 232
 			$this->tmd = $this->tmd + 1;
233 233
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
234 234
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
235 235
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
236 236
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
237
-		    }
237
+			}
238 238
 		}
239 239
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
240
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
242 242
 		}
243 243
 		if (isset($line['format_source']) && $line['format_source'] != '') {
244
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
244
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
245 245
 		}
246 246
 		if (isset($line['source_name']) && $line['source_name'] != '') {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
247
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
248 248
 		}
249 249
 		if (isset($line['status']) && $line['status'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
250
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
251 251
 		}
252 252
 
253 253
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
255 255
 		}
256 256
 		
257 257
 		if (isset($line['heading']) && $line['heading'] != '') {
258
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
-		    //$dataFound = true;
258
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
+			//$dataFound = true;
262 262
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
263
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
264
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
263
+  			$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
264
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
267 267
   		}
268 268
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 269
 
270 270
 		if (isset($line['datetime'])) {
271
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
271
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272 272
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
273
-		    } else {
273
+			} else {
274 274
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
275 275
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
276 276
 				return '';
277
-		    }
277
+			}
278 278
 		} else {
279 279
 			date_default_timezone_set('UTC');
280 280
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -282,45 +282,45 @@  discard block
 block discarded – undo
282 282
 
283 283
 
284 284
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
285
-		    $this->all_tracked[$id]['lastupdate'] = time();
286
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
288
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
285
+			$this->all_tracked[$id]['lastupdate'] = time();
286
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
288
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289 289
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
290 290
 				$timeelapsed = microtime(true);
291 291
 				$MarineLive = new MarineLive($this->db);
292 292
 				if (isset($line['id'])) {
293
-				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
293
+					$recent_ident = $MarineLive->checkIdRecent($line['id']);
294
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295 295
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296
-				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
296
+					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
298 298
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299
-				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
299
+					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
301 301
 				} else $recent_ident = '';
302 302
 				$MarineLive->db=null;
303 303
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304 304
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
305
-			    } else {
305
+				} else {
306 306
 				$recent_ident = '';
307 307
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
308
-			    }
309
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
-			    {
308
+				}
309
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
+				{
312 312
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
313 313
 				//adds the spotter data for the archive
314
-				    $highlight = '';
315
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
316
-				    $timeelapsed = microtime(true);
317
-				    $Marine = new Marine($this->db);
318
-				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
319
-				    $Marine->db = null;
320
-				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
+					$highlight = '';
315
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
316
+					$timeelapsed = microtime(true);
317
+					$Marine = new Marine($this->db);
318
+					$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
319
+					$Marine->db = null;
320
+					if ($globalDebug && isset($result)) echo $result."\n";
321
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
322 322
 				    
323
-				    /*
323
+					/*
324 324
 				    // Add source stat in DB
325 325
 				    $Stats = new Stats($this->db);
326 326
 				    if (!empty($this->stats)) {
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
 				    }
348 348
 				    $Stats->db = null;
349 349
 				    */
350
-				    $this->del();
350
+					$this->del();
351 351
 				//$ignoreImport = false;
352 352
 				$this->all_tracked[$id]['addedMarine'] = 1;
353 353
 				//print_r($this->all_tracked[$id]);
354 354
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
355
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
357
-				    $MarineLive = new MarineLive($this->db);
358
-				    $MarineLive->deleteLiveMarineData();
359
-				    $MarineLive->db=null;
360
-				    if ($globalDebug) echo " Done\n";
361
-				    $this->last_delete = time();
355
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
+					//MarineLive->deleteLiveMarineDataNotUpdated();
357
+					$MarineLive = new MarineLive($this->db);
358
+					$MarineLive->deleteLiveMarineData();
359
+					$MarineLive->db=null;
360
+					if ($globalDebug) echo " Done\n";
361
+					$this->last_delete = time();
362 362
 				}
363
-			    } elseif ($recent_ident != '') {
363
+				} elseif ($recent_ident != '') {
364 364
 				$this->all_tracked[$id]['id'] = $recent_ident;
365 365
 				$this->all_tracked[$id]['addedMarine'] = 1;
366 366
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -369,16 +369,16 @@  discard block
 block discarded – undo
369 369
 					$Marine->db = null;
370 370
 				}
371 371
 				
372
-			    }
372
+				}
373
+			}
373 374
 			}
374
-		    }
375
-		    //adds the spotter LIVE data
376
-		    if ($globalDebug) {
375
+			//adds the spotter LIVE data
376
+			if ($globalDebug) {
377 377
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
378
-		    }
379
-		    $ignoreImport = false;
378
+			}
379
+			$ignoreImport = false;
380 380
 
381
-		    if (!$ignoreImport) {
381
+			if (!$ignoreImport) {
382 382
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
383 383
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
384 384
 				$timeelapsed = microtime(true);
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 			
451 451
 			
452 452
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
453
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
454
-			    $MarineLive = new MarineLive($this->db);
455
-			    $MarineLive->deleteLiveMarineDataNotUpdated();
456
-			    $MarineLive->db = null;
457
-			    //MarineLive->deleteLiveMarineData();
458
-			    if ($globalDebug) echo " Done\n";
459
-			    $this->last_delete_hourly = time();
453
+				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
454
+				$MarineLive = new MarineLive($this->db);
455
+				$MarineLive->deleteLiveMarineDataNotUpdated();
456
+				$MarineLive->db = null;
457
+				//MarineLive->deleteLiveMarineData();
458
+				if ($globalDebug) echo " Done\n";
459
+				$this->last_delete_hourly = time();
460 460
 			}
461 461
 			
462
-		    }
463
-		    //$ignoreImport = false;
462
+			}
463
+			//$ignoreImport = false;
464 464
 		}
465 465
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
466 466
 		if ($send) return $this->all_tracked[$id];
467
-	    }
467
+		}
468
+	}
468 469
 	}
469
-    }
470 470
 }
471 471
 ?>
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	    if (isset($this->all_tracked[$key]['id'])) {
51 51
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
52 52
     		$Marine = new Marine($this->db);
53
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
+        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
54 54
             }
55 55
 	}
56 56
     }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62 62
 	foreach ($this->all_tracked as $key => $flight) {
63 63
     	    if (isset($flight['lastupdate'])) {
64
-        	if ($flight['lastupdate'] < (time()-3000)) {
64
+        	if ($flight['lastupdate'] < (time() - 3000)) {
65 65
             	    if (isset($this->all_tracked[$key]['id'])) {
66 66
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
67 67
 			/*
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             		//$real_arrival = $this->arrival($key);
73 73
             		$Marine = new Marine($this->db);
74 74
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75
-				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75
+				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed']);
76 76
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
77 77
 			}
78 78
 			// Put in archive
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	$send = false;
93 93
 	
94 94
 	// SBS format is CSV format
95
-	if(is_array($line) && isset($line['mmsi'])) {
95
+	if (is_array($line) && isset($line['mmsi'])) {
96 96
 	    //print_r($line);
97 97
   	    if (isset($line['mmsi'])) {
98 98
 
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 		
117 117
 		if (!isset($this->all_tracked[$id])) {
118 118
 		    $this->all_tracked[$id] = array();
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
120
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => ''));
121
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
122 122
 		    if (!isset($line['id'])) {
123 123
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
124
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
125
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
125
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
126 126
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
127 127
 		}
128 128
 		
129 129
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
130
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
131 131
 		    $Marine = new Marine($this->db);
132 132
 		    $identity = $Marine->getIdentity($line['mmsi']);
133 133
 		    if (!empty($identity)) {
@@ -139,59 +139,59 @@  discard block
 block discarded – undo
139 139
 		    //$dataFound = true;
140 140
 		}
141 141
 		if (isset($line['type_id']) && $line['type_id'] != '') {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
142
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
143 143
 		}
144 144
 		if (isset($line['type']) && $line['type'] != '') {
145
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
145
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
146 146
 		}
147 147
 		if (isset($line['imo']) && $line['imo'] != '') {
148
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
148
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
149 149
 		}
150 150
 		if (isset($line['callsign']) && $line['callsign'] != '') {
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
151
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
152 152
 		}
153 153
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
154
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
155 155
 		}
156 156
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
158 158
 		}
159 159
 
160 160
 
161 161
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
162 162
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
164 164
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
165 165
 			$timeelapsed = microtime(true);
166 166
             		$Marine = new Marine($this->db);
167 167
             		$fromsource = NULL;
168
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
168
+            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
169 169
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170 170
 			$Marine->db = null;
171
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
171
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
172 172
 		    }
173
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
173
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
174 174
 		}
175 175
 
176 176
 		if (isset($line['speed']) && $line['speed'] != '') {
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
177
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
178
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
179 179
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
180
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
180
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
181 181
 		    if ($distance > 1000 && $distance < 10000) {
182 182
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 183
 			$speed = $speed*3.6;
184
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
184
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
185 185
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
186 186
 		    }
187 187
 		}
188 188
 
189 189
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
190
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
191 191
 	    	    else unset($timediff);
192
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
192
+	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')))) {
193 193
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
194
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
194
+			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['livedb_latitude'], $this->all_tracked[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
195 195
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
196 196
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 197
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
200 200
 				$timeelapsed = microtime(true);
201 201
 				$Marine = new Marine($this->db);
202
-				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
202
+				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
203 203
 				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
204 204
 				$Marine->db = null;
205
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
205
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
206 206
 				$this->tmd = 0;
207 207
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
208 208
 			    }
@@ -210,66 +210,66 @@  discard block
 block discarded – undo
210 210
 
211 211
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212 212
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
213
-				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
213
+				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
214 214
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215 215
 				    $dataFound = true;
216 216
 				    $this->all_tracked[$id]['time_last_coord'] = time();
217 217
 				}
218
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
218
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
219 219
 			}
220 220
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221 221
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222 222
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
223
-				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
223
+				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
224 224
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225 225
 				    $dataFound = true;
226 226
 				    $this->all_tracked[$id]['time_last_coord'] = time();
227 227
 				}
228
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
228
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
229 229
 			}
230 230
 
231 231
 		    } else if ($globalDebug && $timediff > 20) {
232 232
 			$this->tmd = $this->tmd + 1;
233 233
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
234
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
235
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
234
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
235
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
236 236
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
237 237
 		    }
238 238
 		}
239 239
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240 240
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
241
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
242 242
 		}
243 243
 		if (isset($line['format_source']) && $line['format_source'] != '') {
244
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
244
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
245 245
 		}
246 246
 		if (isset($line['source_name']) && $line['source_name'] != '') {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
247
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
248 248
 		}
249 249
 		if (isset($line['status']) && $line['status'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
250
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
251 251
 		}
252 252
 
253 253
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
254
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
255 255
 		}
256 256
 		
257 257
 		if (isset($line['heading']) && $line['heading'] != '') {
258
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
258
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
260
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
261 261
 		    //$dataFound = true;
262 262
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
263
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
264
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
263
+  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
264
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
265
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266 266
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
267 267
   		}
268 268
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 269
 
270 270
 		if (isset($line['datetime'])) {
271 271
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
272
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
273 273
 		    } else {
274 274
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
275 275
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -277,48 +277,48 @@  discard block
 block discarded – undo
277 277
 		    }
278 278
 		} else {
279 279
 			date_default_timezone_set('UTC');
280
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
280
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
281 281
 		}
282 282
 
283 283
 
284 284
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
285 285
 		    $this->all_tracked[$id]['lastupdate'] = time();
286 286
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
287
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
288 288
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289 289
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
290 290
 				$timeelapsed = microtime(true);
291 291
 				$MarineLive = new MarineLive($this->db);
292 292
 				if (isset($line['id'])) {
293 293
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
294
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
295 295
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296 296
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
298 298
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299 299
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
300
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
301 301
 				} else $recent_ident = '';
302
-				$MarineLive->db=null;
302
+				$MarineLive->db = null;
303 303
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304 304
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
305 305
 			    } else {
306 306
 				$recent_ident = '';
307
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
307
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
308 308
 			    }
309 309
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
310
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311 311
 			    {
312 312
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
313 313
 				//adds the spotter data for the archive
314 314
 				    $highlight = '';
315
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
315
+				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
316 316
 				    $timeelapsed = microtime(true);
317 317
 				    $Marine = new Marine($this->db);
318
-				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
318
+				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']);
319 319
 				    $Marine->db = null;
320 320
 				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
321
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
322 322
 				    
323 323
 				    /*
324 324
 				    // Add source stat in DB
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
357 357
 				    $MarineLive = new MarineLive($this->db);
358 358
 				    $MarineLive->deleteLiveMarineData();
359
-				    $MarineLive->db=null;
359
+				    $MarineLive->db = null;
360 360
 				    if ($globalDebug) echo " Done\n";
361 361
 				    $this->last_delete = time();
362 362
 				}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 				$this->all_tracked[$id]['addedMarine'] = 1;
366 366
 				if (isset($globalDaemon) && !$globalDaemon) {
367 367
 					$Marine = new Marine($this->db);
368
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
368
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
369 369
 					$Marine->db = null;
370 370
 				}
371 371
 				
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 		    $ignoreImport = false;
380 380
 
381 381
 		    if (!$ignoreImport) {
382
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
382
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
383 383
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
384 384
 				$timeelapsed = microtime(true);
385 385
 				$MarineLive = new MarineLive($this->db);
386
-				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
386
+				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
387 387
 				$MarineLive->db = null;
388 388
 				$this->all_tracked[$id]['putinarchive'] = false;
389
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
389
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
390 390
 
391 391
 				// Put statistics in $this->stats variable
392 392
 				/*
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 				$this->all_tracked[$id]['lastupdate'] = time();
446 446
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
447 447
 				if ($globalDebug) echo $result."\n";
448
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
448
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
449 449
 			//$this->del();
450 450
 			
451 451
 			
Please login to merge, or discard this patch.
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
     public function checkAll() {
47 47
 	global $globalDebug;
48
-	if ($globalDebug) echo "Update last seen tracked data...\n";
48
+	if ($globalDebug) {
49
+		echo "Update last seen tracked data...\n";
50
+	}
49 51
 	foreach ($this->all_tracked as $key => $flight) {
50 52
 	    if (isset($this->all_tracked[$key]['id'])) {
51 53
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -58,12 +60,16 @@  discard block
 block discarded – undo
58 60
     public function del() {
59 61
 	global $globalDebug;
60 62
 	// Delete old infos
61
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
63
+	if ($globalDebug) {
64
+		echo 'Delete old values and update latest data...'."\n";
65
+	}
62 66
 	foreach ($this->all_tracked as $key => $flight) {
63 67
     	    if (isset($flight['lastupdate'])) {
64 68
         	if ($flight['lastupdate'] < (time()-3000)) {
65 69
             	    if (isset($this->all_tracked[$key]['id'])) {
66
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
70
+            		if ($globalDebug) {
71
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
72
+            		}
67 73
 			/*
68 74
 			$MarineLive = new MarineLive();
69 75
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -73,7 +79,9 @@  discard block
 block discarded – undo
73 79
             		$Marine = new Marine($this->db);
74 80
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75 81
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
76
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
82
+				if ($globalDebug && $result != 'success') {
83
+					echo '!!! ERROR : '.$result."\n";
84
+				}
77 85
 			}
78 86
 			// Put in archive
79 87
 //			$Marine->db = null;
@@ -86,7 +94,9 @@  discard block
 block discarded – undo
86 94
 
87 95
     public function add($line) {
88 96
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
89
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
97
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
98
+		$globalCoordMinChange = '0.02';
99
+	}
90 100
 	date_default_timezone_set('UTC');
91 101
 	$dataFound = false;
92 102
 	$send = false;
@@ -111,8 +121,11 @@  discard block
 block discarded – undo
111 121
 		
112 122
 		$Common = new Common();
113 123
 		$AIS = new AIS();
114
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
115
-	        else $id = trim($line['id']);
124
+	        if (!isset($line['id'])) {
125
+	        	$id = trim($line['mmsi']);
126
+	        } else {
127
+	        	$id = trim($line['id']);
128
+	        }
116 129
 		
117 130
 		if (!isset($this->all_tracked[$id])) {
118 131
 		    $this->all_tracked[$id] = array();
@@ -120,10 +133,16 @@  discard block
 block discarded – undo
120 133
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121 134
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122 135
 		    if (!isset($line['id'])) {
123
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
136
+			if (!isset($globalDaemon)) {
137
+				$globalDaemon = TRUE;
138
+			}
124 139
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
125
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
140
+		     } else {
141
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
142
+		     }
143
+		    if ($globalAllTracked !== FALSE) {
144
+		    	$dataFound = true;
145
+		    }
127 146
 		}
128 147
 		
129 148
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -166,11 +185,17 @@  discard block
 block discarded – undo
166 185
             		$Marine = new Marine($this->db);
167 186
             		$fromsource = NULL;
168 187
             		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
169
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
188
+			if ($globalDebug && $result != 'success') {
189
+				echo '!!! ERROR : '.$result."\n";
190
+			}
170 191
 			$Marine->db = null;
171
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
192
+			if ($globalDebugTimeElapsed) {
193
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
194
+			}
195
+		    }
196
+		    if (!isset($this->all_tracked[$id]['id'])) {
197
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
172 198
 		    }
173
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
174 199
 		}
175 200
 
176 201
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -181,14 +206,21 @@  discard block
 block discarded – undo
181 206
 		    if ($distance > 1000 && $distance < 10000) {
182 207
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 208
 			$speed = $speed*3.6;
184
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
185
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
209
+			if ($speed < 1000) {
210
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
211
+			}
212
+  			if ($globalDebug) {
213
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
214
+  			}
186 215
 		    }
187 216
 		}
188 217
 
189 218
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
-	    	    else unset($timediff);
219
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
220
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
221
+	    	    } else {
222
+	    	    	unset($timediff);
223
+	    	    }
192 224
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
193 225
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
194 226
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -196,20 +228,30 @@  discard block
 block discarded – undo
196 228
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 229
 				$this->all_tracked[$id]['putinarchive'] = true;
198 230
 				
199
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
231
+				if ($globalDebug) {
232
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
233
+				}
200 234
 				$timeelapsed = microtime(true);
201 235
 				$Marine = new Marine($this->db);
202 236
 				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
203
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
237
+				if (!empty($all_country)) {
238
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
239
+				}
204 240
 				$Marine->db = null;
205
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
241
+				if ($globalDebugTimeElapsed) {
242
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
243
+				}
206 244
 				$this->tmd = 0;
207
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
245
+				if ($globalDebug) {
246
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
247
+				}
208 248
 			    }
209 249
 			}
210 250
 
211 251
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
252
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
253
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
254
+				}
213 255
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
214 256
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215 257
 				    $dataFound = true;
@@ -218,8 +260,12 @@  discard block
 block discarded – undo
218 260
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
219 261
 			}
220 262
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
263
+			    if ($line['longitude'] > 180) {
264
+			    	$line['longitude'] = $line['longitude'] - 360;
265
+			    }
266
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
267
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
268
+				}
223 269
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
224 270
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225 271
 				    $dataFound = true;
@@ -237,7 +283,9 @@  discard block
 block discarded – undo
237 283
 		    }
238 284
 		}
239 285
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
286
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
287
+		    	$dataFound = true;
288
+		    }
241 289
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
242 290
 		}
243 291
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -255,15 +303,21 @@  discard block
 block discarded – undo
255 303
 		}
256 304
 		
257 305
 		if (isset($line['heading']) && $line['heading'] != '') {
258
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
306
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
307
+		    	$this->all_tracked[$id]['putinarchive'] = true;
308
+		    }
259 309
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260 310
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261 311
 		    //$dataFound = true;
262 312
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
263 313
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
264 314
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
315
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
316
+		    	$this->all_tracked[$id]['putinarchive'] = true;
317
+		    }
318
+  		    if ($globalDebug) {
319
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
320
+  		    }
267 321
   		}
268 322
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 323
 
@@ -271,8 +325,11 @@  discard block
 block discarded – undo
271 325
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272 326
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
273 327
 		    } else {
274
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
275
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
328
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
329
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
330
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
331
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
332
+				}
276 333
 				return '';
277 334
 		    }
278 335
 		} else {
@@ -286,22 +343,35 @@  discard block
 block discarded – undo
286 343
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287 344
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
288 345
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
346
+				if ($globalDebug) {
347
+					echo "Check if aircraft is already in DB...";
348
+				}
290 349
 				$timeelapsed = microtime(true);
291 350
 				$MarineLive = new MarineLive($this->db);
292 351
 				if (isset($line['id'])) {
293 352
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353
+				    if ($globalDebugTimeElapsed) {
354
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
355
+				    }
295 356
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296 357
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
358
+				    if ($globalDebugTimeElapsed) {
359
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
360
+				    }
298 361
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299 362
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
301
-				} else $recent_ident = '';
363
+				    if ($globalDebugTimeElapsed) {
364
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
365
+				    }
366
+				} else {
367
+					$recent_ident = '';
368
+				}
302 369
 				$MarineLive->db=null;
303
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
370
+				if ($globalDebug && $recent_ident == '') {
371
+					echo " Not in DB.\n";
372
+				} elseif ($globalDebug && $recent_ident != '') {
373
+					echo " Already in DB.\n";
374
+				}
305 375
 			    } else {
306 376
 				$recent_ident = '';
307 377
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -309,16 +379,24 @@  discard block
 block discarded – undo
309 379
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310 380
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311 381
 			    {
312
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
382
+				if ($globalDebug) {
383
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
384
+				}
313 385
 				//adds the spotter data for the archive
314 386
 				    $highlight = '';
315
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
387
+				    if (!isset($this->all_tracked[$id]['id'])) {
388
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
389
+				    }
316 390
 				    $timeelapsed = microtime(true);
317 391
 				    $Marine = new Marine($this->db);
318 392
 				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
319 393
 				    $Marine->db = null;
320
-				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
394
+				    if ($globalDebug && isset($result)) {
395
+				    	echo $result."\n";
396
+				    }
397
+				    if ($globalDebugTimeElapsed) {
398
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
399
+				    }
322 400
 				    
323 401
 				    /*
324 402
 				    // Add source stat in DB
@@ -352,12 +430,16 @@  discard block
 block discarded – undo
352 430
 				$this->all_tracked[$id]['addedMarine'] = 1;
353 431
 				//print_r($this->all_tracked[$id]);
354 432
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
355
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
433
+				    if ($globalDebug) {
434
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
435
+				    }
356 436
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
357 437
 				    $MarineLive = new MarineLive($this->db);
358 438
 				    $MarineLive->deleteLiveMarineData();
359 439
 				    $MarineLive->db=null;
360
-				    if ($globalDebug) echo " Done\n";
440
+				    if ($globalDebug) {
441
+				    	echo " Done\n";
442
+				    }
361 443
 				    $this->last_delete = time();
362 444
 				}
363 445
 			    } elseif ($recent_ident != '') {
@@ -380,13 +462,17 @@  discard block
 block discarded – undo
380 462
 
381 463
 		    if (!$ignoreImport) {
382 464
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
383
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
465
+				if ($globalDebug) {
466
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
467
+				}
384 468
 				$timeelapsed = microtime(true);
385 469
 				$MarineLive = new MarineLive($this->db);
386 470
 				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
387 471
 				$MarineLive->db = null;
388 472
 				$this->all_tracked[$id]['putinarchive'] = false;
389
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
473
+				if ($globalDebugTimeElapsed) {
474
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
475
+				}
390 476
 
391 477
 				// Put statistics in $this->stats variable
392 478
 				/*
@@ -443,19 +529,29 @@  discard block
 block discarded – undo
443 529
 				*/
444 530
 
445 531
 				$this->all_tracked[$id]['lastupdate'] = time();
446
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
447
-				if ($globalDebug) echo $result."\n";
448
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
532
+				if ($this->all_tracked[$id]['putinarchive']) {
533
+					$send = true;
534
+				}
535
+				if ($globalDebug) {
536
+					echo $result."\n";
537
+				}
538
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
539
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
540
+			}
449 541
 			//$this->del();
450 542
 			
451 543
 			
452 544
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
453
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
545
+			    if ($globalDebug) {
546
+			    	echo "---- Deleting Live Marine data Not updated since 2 hour...";
547
+			    }
454 548
 			    $MarineLive = new MarineLive($this->db);
455 549
 			    $MarineLive->deleteLiveMarineDataNotUpdated();
456 550
 			    $MarineLive->db = null;
457 551
 			    //MarineLive->deleteLiveMarineData();
458
-			    if ($globalDebug) echo " Done\n";
552
+			    if ($globalDebug) {
553
+			    	echo " Done\n";
554
+			    }
459 555
 			    $this->last_delete_hourly = time();
460 556
 			}
461 557
 			
@@ -463,7 +559,9 @@  discard block
 block discarded – undo
463 559
 		    //$ignoreImport = false;
464 560
 		}
465 561
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
466
-		if ($send) return $this->all_tracked[$id];
562
+		if ($send) {
563
+			return $this->all_tracked[$id];
564
+		}
467 565
 	    }
468 566
 	}
469 567
     }
Please login to merge, or discard this patch.
require/class.AIS.php 1 patch
Braces   +322 added lines, -140 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -175,7 +177,9 @@  discard block
 block discarded – undo
175 177
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176 178
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177 179
 			$ro->heading = bindec(substr($_aisdata,124,9));
178
-			if ($ro->heading == 511) $ro->heading = '';
180
+			if ($ro->heading == 511) {
181
+				$ro->heading = '';
182
+			}
179 183
 			$ro->cls = 2; // class B
180 184
 		} else if ($ro->id == 19) {
181 185
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -185,7 +189,9 @@  discard block
 block discarded – undo
185 189
 			$ro->name = $this->binchar($_aisdata,143,120);
186 190
 			$ro->cls = 2; // class B
187 191
 			$ro->heading = bindec(substr($_aisdata,124,9));
188
-			if ($ro->heading == 511) $ro->heading = '';
192
+			if ($ro->heading == 511) {
193
+				$ro->heading = '';
194
+			}
189 195
 			$ro->typeid = bindec(substr($_aisdata,263,8));
190 196
 			$ro->type = $this->getShipType($ro->typeid);
191 197
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -216,9 +222,13 @@  discard block
 block discarded – undo
216 222
 			$ro->cls = 2; // class B
217 223
 		} else if ($ro->id == 27) {
218 224
 			$ro->cog = bindec(substr($_aisdata,85,9));
219
-			if ($ro->cog == 511) $ro->cog = 0.0;
225
+			if ($ro->cog == 511) {
226
+				$ro->cog = 0.0;
227
+			}
220 228
 			$ro->sog = bindec(substr($_aisdata,79,6));
221
-			if ($ro->sog == 63) $ro->sog = 0.0;
229
+			if ($ro->sog == 63) {
230
+				$ro->sog = 0.0;
231
+			}
222 232
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223 233
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
224 234
 			$ro->cls = 1; // class A
@@ -267,88 +277,171 @@  discard block
 block discarded – undo
267 277
 	}
268 278
 	
269 279
 	public function getShipType($code) {
270
-		if ($code == 0) return 'Not available (default)';
271
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
272
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
273
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
274
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
275
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
276
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
277
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
278
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
279
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
280
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
281
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
282
-		elseif ($code == 30) return 'Fishing';
283
-		elseif ($code == 31) return 'Towing';
284
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
285
-		elseif ($code == 33) return 'Dredging or underwater ops';
286
-		elseif ($code == 34) return 'Diving ops';
287
-		elseif ($code == 35) return 'Military ops';
288
-		elseif ($code == 36) return 'Sailing';
289
-		elseif ($code == 37) return 'Pleasure Craft';
290
-		elseif ($code == 38) return 'Reserved';
291
-		elseif ($code == 39) return 'Reserved';
292
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
293
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
294
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
295
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
296
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
297
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
298
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
299
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
300
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
301
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
302
-		elseif ($code == 50) return 'Pilot Vessel';
303
-		elseif ($code == 51) return 'Search and Rescue vessel';
304
-		elseif ($code == 52) return 'Tug';
305
-		elseif ($code == 53) return 'Port Tender';
306
-		elseif ($code == 54) return 'Anti-pollution equipment';
307
-		elseif ($code == 55) return 'Law Enforcement';
308
-		elseif ($code == 56) return 'Spare - Local Vessel';
309
-		elseif ($code == 57) return 'Spare - Local Vessel';
310
-		elseif ($code == 58) return 'Medical Transport';
311
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
312
-		elseif ($code == 60) return 'Passenger, all ships of this type';
313
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
314
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
315
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
316
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
317
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
318
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
319
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
320
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
321
-		elseif ($code == 69) return 'Passenger, No additional information';
322
-		elseif ($code == 70) return 'Cargo, all ships of this type';
323
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
324
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
325
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
326
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
327
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
328
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
329
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
330
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
331
-		elseif ($code == 79) return 'Cargo, No additional information';
332
-		elseif ($code == 80) return 'Tanker, all ships of this type';
333
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
334
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
335
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
336
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
337
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
338
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
339
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
340
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
341
-		elseif ($code == 89) return 'Tanker, No additional information';
342
-		elseif ($code == 90) return 'Other Type, all ships of this type';
343
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
344
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
345
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
346
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
347
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
348
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
349
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
350
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
351
-		elseif ($code == 99) return 'Other Type, no additional information';
280
+		if ($code == 0) {
281
+			return 'Not available (default)';
282
+		} elseif ($code >= 1 && $code <= 19) {
283
+			return 'Reserved for future use';
284
+		} elseif ($code == 20) {
285
+			return 'Wing in ground (WIG), all ships of this type';
286
+		} elseif ($code == 21) {
287
+			return 'Wing in ground (WIG), Hazardous category A';
288
+		} elseif ($code == 22) {
289
+			return 'Wing in ground (WIG), Hazardous category B';
290
+		} elseif ($code == 23) {
291
+			return 'Wing in ground (WIG), Hazardous category C';
292
+		} elseif ($code == 24) {
293
+			return 'Wing in ground (WIG), Hazardous category D';
294
+		} elseif ($code == 25) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 26) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 27) {
299
+			return 'Wing in ground (WIG), Reserved for future use';
300
+		} elseif ($code == 28) {
301
+			return 'Wing in ground (WIG), Reserved for future use';
302
+		} elseif ($code == 29) {
303
+			return 'Wing in ground (WIG), Reserved for future use';
304
+		} elseif ($code == 30) {
305
+			return 'Fishing';
306
+		} elseif ($code == 31) {
307
+			return 'Towing';
308
+		} elseif ($code == 32) {
309
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
310
+		} elseif ($code == 33) {
311
+			return 'Dredging or underwater ops';
312
+		} elseif ($code == 34) {
313
+			return 'Diving ops';
314
+		} elseif ($code == 35) {
315
+			return 'Military ops';
316
+		} elseif ($code == 36) {
317
+			return 'Sailing';
318
+		} elseif ($code == 37) {
319
+			return 'Pleasure Craft';
320
+		} elseif ($code == 38) {
321
+			return 'Reserved';
322
+		} elseif ($code == 39) {
323
+			return 'Reserved';
324
+		} elseif ($code == 40) {
325
+			return 'High speed craft (HSC), all ships of this type';
326
+		} elseif ($code == 41) {
327
+			return 'High speed craft (HSC), Hazardous category A';
328
+		} elseif ($code == 42) {
329
+			return 'High speed craft (HSC), Hazardous category B';
330
+		} elseif ($code == 43) {
331
+			return 'High speed craft (HSC), Hazardous category C';
332
+		} elseif ($code == 44) {
333
+			return 'High speed craft (HSC), Hazardous category D';
334
+		} elseif ($code == 45) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 46) {
337
+			return 'High speed craft (HSC), Reserved for future use';
338
+		} elseif ($code == 47) {
339
+			return 'High speed craft (HSC), Reserved for future use';
340
+		} elseif ($code == 48) {
341
+			return 'High speed craft (HSC), Reserved for future use';
342
+		} elseif ($code == 49) {
343
+			return 'High speed craft (HSC), No additional information';
344
+		} elseif ($code == 50) {
345
+			return 'Pilot Vessel';
346
+		} elseif ($code == 51) {
347
+			return 'Search and Rescue vessel';
348
+		} elseif ($code == 52) {
349
+			return 'Tug';
350
+		} elseif ($code == 53) {
351
+			return 'Port Tender';
352
+		} elseif ($code == 54) {
353
+			return 'Anti-pollution equipment';
354
+		} elseif ($code == 55) {
355
+			return 'Law Enforcement';
356
+		} elseif ($code == 56) {
357
+			return 'Spare - Local Vessel';
358
+		} elseif ($code == 57) {
359
+			return 'Spare - Local Vessel';
360
+		} elseif ($code == 58) {
361
+			return 'Medical Transport';
362
+		} elseif ($code == 59) {
363
+			return 'Noncombatant ship according to RR Resolution No. 18';
364
+		} elseif ($code == 60) {
365
+			return 'Passenger, all ships of this type';
366
+		} elseif ($code == 61) {
367
+			return 'Passenger, Hazardous category A';
368
+		} elseif ($code == 62) {
369
+			return 'Passenger, Hazardous category B';
370
+		} elseif ($code == 63) {
371
+			return 'Passenger, Hazardous category C';
372
+		} elseif ($code == 64) {
373
+			return 'Passenger, Hazardous category D';
374
+		} elseif ($code == 65) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 66) {
377
+			return 'Passenger, Reserved for future use';
378
+		} elseif ($code == 67) {
379
+			return 'Passenger, Reserved for future use';
380
+		} elseif ($code == 68) {
381
+			return 'Passenger, Reserved for future use';
382
+		} elseif ($code == 69) {
383
+			return 'Passenger, No additional information';
384
+		} elseif ($code == 70) {
385
+			return 'Cargo, all ships of this type';
386
+		} elseif ($code == 71) {
387
+			return 'Cargo, Hazardous category A';
388
+		} elseif ($code == 72) {
389
+			return 'Cargo, Hazardous category B';
390
+		} elseif ($code == 73) {
391
+			return 'Cargo, Hazardous category C';
392
+		} elseif ($code == 74) {
393
+			return 'Cargo, Hazardous category D';
394
+		} elseif ($code == 75) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 76) {
397
+			return 'Cargo, Reserved for future use';
398
+		} elseif ($code == 77) {
399
+			return 'Cargo, Reserved for future use';
400
+		} elseif ($code == 78) {
401
+			return 'Cargo, Reserved for future use';
402
+		} elseif ($code == 79) {
403
+			return 'Cargo, No additional information';
404
+		} elseif ($code == 80) {
405
+			return 'Tanker, all ships of this type';
406
+		} elseif ($code == 81) {
407
+			return 'Tanker, Hazardous category A';
408
+		} elseif ($code == 82) {
409
+			return 'Tanker, Hazardous category B';
410
+		} elseif ($code == 83) {
411
+			return 'Tanker, Hazardous category C';
412
+		} elseif ($code == 84) {
413
+			return 'Tanker, Hazardous category D';
414
+		} elseif ($code == 85) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 86) {
417
+			return 'Tanker, Reserved for future use';
418
+		} elseif ($code == 87) {
419
+			return 'Tanker, Reserved for future use';
420
+		} elseif ($code == 88) {
421
+			return 'Tanker, Reserved for future use';
422
+		} elseif ($code == 89) {
423
+			return 'Tanker, No additional information';
424
+		} elseif ($code == 90) {
425
+			return 'Other Type, all ships of this type';
426
+		} elseif ($code == 91) {
427
+			return 'Other Type, Hazardous category A';
428
+		} elseif ($code == 92) {
429
+			return 'Other Type, Hazardous category B';
430
+		} elseif ($code == 93) {
431
+			return 'Other Type, Hazardous category C';
432
+		} elseif ($code == 94) {
433
+			return 'Other Type, Hazardous category D';
434
+		} elseif ($code == 95) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 96) {
437
+			return 'Other Type, Reserved for future use';
438
+		} elseif ($code == 97) {
439
+			return 'Other Type, Reserved for future use';
440
+		} elseif ($code == 98) {
441
+			return 'Other Type, Reserved for future use';
442
+		} elseif ($code == 99) {
443
+			return 'Other Type, no additional information';
444
+		}
352 445
 	}
353 446
 
354 447
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -386,19 +479,34 @@  discard block
 block discarded – undo
386 479
 		// assume 1st ! is valid
387 480
 		// find * ensure that it is at correct position
388 481
 		$end = strrpos ( $rawdata , '*' );
389
-		if ($end === FALSE) return -1; // check for NULLS!!!
482
+		if ($end === FALSE) {
483
+			return -1;
484
+		}
485
+		// check for NULLS!!!
390 486
 		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
487
+		if ( strlen($cs) != 2 ) {
488
+			return -1;
489
+		}
490
+		// correct cs length
392 491
 		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
492
+		for ( $alias=1; $alias<$end; $alias++) {
493
+			$chksum ^= ord( $rawdata[$alias] );
494
+		}
495
+		// perform XOR for NMEA checksum
394 496
 		if ( $chksum == $dcs ) { // NMEA checksum pass
395 497
 			$pcs = explode(',', $rawdata);
396 498
 			// !AI??? identifier
397 499
 			$num_seq = (int)$pcs[1]; // number of sequences
398 500
 			$seq = (int)$pcs[2]; // get sequence
399 501
 			// get msg sequence id
400
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
502
+			if ($pcs[3] == '') {
503
+				$msg_sid = -1;
504
+			}
505
+			// non-multipart message, set to -1
506
+			else {
507
+				$msg_sid = (int)$pcs[3];
508
+			}
509
+			// multipart message
402 510
 			$ais_ch = $pcs[4]; // get AIS channel
403 511
 			// message sequence checking
404 512
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -459,10 +567,18 @@  discard block
 block discarded – undo
459 567
 				//DEBUG echo "[$start $end $tst]\n";
460 568
 				$result = $this->process_ais_raw( $tst, "" );
461 569
 				$last_pos = $end + 1;
462
-			} else break;
570
+			} else {
571
+				break;
572
+			}
573
+		}
574
+		if ($last_pos > 0) {
575
+			$cbuf = substr($cbuf, $last_pos);
463 576
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
580
+		}
581
+		// prevent overflow simple mode...
466 582
 		return $result;
467 583
 	}
468 584
 
@@ -482,7 +598,9 @@  discard block
 block discarded – undo
482 598
 		if ($lat<0.0) {
483 599
 			$lat = -$lat;
484 600
 			$neg=true;
485
-		} else $neg=false;
601
+		} else {
602
+			$neg=false;
603
+		}
486 604
 		$latd = 0x00000000;
487 605
 		$latd = intval ($lat * 600000.0);
488 606
 		if ($neg==true) {
@@ -498,7 +616,9 @@  discard block
 block discarded – undo
498 616
 		if ($lon<0.0) {
499 617
 			$lon = -$lon;
500 618
 			$neg=true;
501
-		} else $neg=false;
619
+		} else {
620
+			$neg=false;
621
+		}
502 622
 		$lond = 0x00000000;
503 623
 		$lond = intval ($lon * 600000.0);
504 624
 		if ($neg==true) {
@@ -511,9 +631,14 @@  discard block
 block discarded – undo
511 631
 
512 632
 	private function char2bin($name, $max_len) {
513 633
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
-		else $pad = '';
634
+		if ($len > $max_len) {
635
+			$name = substr($name,0,$max_len);
636
+		}
637
+		if ($len < $max_len) {
638
+			$pad = str_repeat('0', ($max_len - $len) * 6);
639
+		} else {
640
+			$pad = '';
641
+		}
517 642
 		$rv = '';
518 643
 		$ais_chars = array(
519 644
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -526,9 +651,12 @@  discard block
 block discarded – undo
526 651
 		);
527 652
 		// "
528 653
 		$_a = str_split($name);
529
-		if ($_a) foreach ($_a as $_1) {
654
+		if ($_a) {
655
+			foreach ($_a as $_1) {
530 656
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531
-			else $dec = 0;
657
+		} else {
658
+				$dec = 0;
659
+			}
532 660
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
533 661
 			$rv .= $bin;
534 662
 			//echo "$_1 $dec ($bin)<br/>";
@@ -540,7 +668,9 @@  discard block
 block discarded – undo
540 668
 		$len_bit = strlen($_enc);
541 669
 		$rem6 = $len_bit % 6;
542 670
 		$pad6_len = 0;
543
-		if ($rem6) $pad6_len = 6 - $rem6;
671
+		if ($rem6) {
672
+			$pad6_len = 6 - $rem6;
673
+		}
544 674
 		//echo  $pad6_len.'<br>';
545 675
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546 676
 		$len_enc = strlen($_enc) / 6;
@@ -549,8 +679,11 @@  discard block
 block discarded – undo
549 679
 		for ($i=0; $i<$len_enc; $i++) {
550 680
 			$offset = $i * 6;
551 681
 			$dec = bindec(substr($_enc,$offset,6));
552
-			if ($dec < 40) $dec += 48;
553
-			else $dec += 56;
682
+			if ($dec < 40) {
683
+				$dec += 48;
684
+			} else {
685
+				$dec += 56;
686
+			}
554 687
 			//echo chr($dec)." $dec<br/>";
555 688
 			$itu .= chr($dec);
556 689
 		}
@@ -563,25 +696,41 @@  discard block
 block discarded – undo
563 696
 		}
564 697
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565 698
 		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
567
-		else $lsbc = '0';
699
+		if ($lsb >=0 && $lsb <= 15 ) {
700
+			$lsbc = $hex_arr[$lsb];
701
+		} else {
702
+			$lsbc = '0';
703
+		}
568 704
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
-		else $msbc = '0';
705
+		if ($msb >=0 && $msb <= 15 ) {
706
+			$msbc = $hex_arr[$msb];
707
+		} else {
708
+			$msbc = '0';
709
+		}
571 710
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 711
 		return $itu;
573 712
 	}
574 713
 
575 714
 	public function parse($buffer) {
576 715
 		$data = $this->process_ais_buf($buffer);
577
-		if (!is_object($data)) return array();
578
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
579
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
716
+		if (!is_object($data)) {
717
+			return array();
718
+		}
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
580 725
 		$result['ident'] = trim($data->name);
581 726
 		$result['timestamp'] = $data->ts;
582 727
 		$result['mmsi'] = $data->mmsi;
583
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
584
-		if ($data->cog != 0) $result['heading'] = $data->cog;
728
+		if ($data->sog != -1.0) {
729
+			$result['speed'] = $data->sog;
730
+		}
731
+		if ($data->cog != 0) {
732
+			$result['heading'] = $data->cog;
733
+		}
585 734
 		/*
586 735
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
587 736
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -591,15 +740,25 @@  discard block
 block discarded – undo
591 740
 
592 741
 	public function mmsitype($mmsi) {
593 742
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
602
-			else return 'Ship';
743
+			if (substr($mmsi,0,3) == '974') {
744
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
745
+			} elseif (substr($mmsi,0,3) == '972') {
746
+				return 'MOB (Man Overboard) device';
747
+			} elseif (substr($mmsi,0,3) == '970') {
748
+				return 'AIS SART (Search and Rescue Transmitter)';
749
+			} elseif (substr($mmsi,0,3) == '111') {
750
+				return 'SAR (Search and Rescue) aircraft';
751
+			} elseif (substr($mmsi,0,2) == '98') {
752
+				return 'Auxiliary craft associated with a parent ship';
753
+			} elseif (substr($mmsi,0,2) == '99') {
754
+				return 'Aids to Navigation';
755
+			} elseif (substr($mmsi,0,2) == '00') {
756
+				return 'Coastal stations';
757
+			} elseif (substr($mmsi,0,1) == '0') {
758
+				return 'Group of ships';
759
+			} else {
760
+				return 'Ship';
761
+			}
603 762
 		}
604 763
 
605 764
 	
@@ -616,25 +775,48 @@  discard block
 block discarded – undo
616 775
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 776
 			return array();
618 777
 		}
619
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
620
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
778
+		if ($data->lon != 0) {
779
+			$result['longitude'] = $data->lon;
780
+		}
781
+		if ($data->lat != 0) {
782
+			$result['latitude'] = $data->lat;
783
+		}
621 784
 		$result['ident'] = trim(str_replace('@','',$data->name));
622 785
 		$result['timestamp'] = $data->ts;
623 786
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') {
788
+			$result['mmsi'] = '3'.$result['mmsi'];
789
+		}
625 790
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627
-		if ($data->heading != '') $result['heading'] = $data->heading;
628
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
629
-		if ($data->status != '') $result['status'] = $data->status;
630
-		if ($data->type != '') $result['type'] = $data->type;
631
-		if ($data->typeid != '') $result['typeid'] = $data->typeid;
632
-		if ($data->imo != '') $result['imo'] = $data->imo;
633
-		if ($data->callsign != '') $result['callsign'] = $data->callsign;
791
+		if ($data->sog != -1.0) {
792
+			$result['speed'] = $data->sog;
793
+		}
794
+		if ($data->heading != '') {
795
+			$result['heading'] = $data->heading;
796
+		} elseif ($data->cog != 0) {
797
+			$result['heading'] = $data->cog;
798
+		}
799
+		if ($data->status != '') {
800
+			$result['status'] = $data->status;
801
+		}
802
+		if ($data->type != '') {
803
+			$result['type'] = $data->type;
804
+		}
805
+		if ($data->typeid != '') {
806
+			$result['typeid'] = $data->typeid;
807
+		}
808
+		if ($data->imo != '') {
809
+			$result['imo'] = $data->imo;
810
+		}
811
+		if ($data->callsign != '') {
812
+			$result['callsign'] = $data->callsign;
813
+		}
634 814
 		if ($data->eta_month != '' && $data->eta_day != '' && $data->eta_hour != '' && $data->eta_minute != '') {
635 815
 			$result['eta_ts'] = strtotime(date('Y').'-'.$data->eta_month.'-'.$data->eta_day.' '.$data->eta_hour.':'.$data->eta_minute.':00');
636 816
 		}
637
-		if ($data->destination != '') $result['destination'] = $data->destination;
817
+		if ($data->destination != '') {
818
+			$result['destination'] = $data->destination;
819
+		}
638 820
 		$result['all'] = (array) $data;
639 821
 		/*
640 822
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Indentation   +839 added lines, -839 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,47 +24,47 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['server'])) $globalServer = TRUE;
63 63
 if (isset($options['idsource'])) $id_source = $options['idsource'];
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
66
+	if ($globalDebug) echo "Using Server Mode\n";
67
+	$SI=new SpotterServer();
68 68
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 } else $SI=new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76
-    $AIS = new AIS();
77
-    $MI = new MarineImport($Connection->db);
76
+	$AIS = new AIS();
77
+	$MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80 80
 $SBS=new SBS();
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
88
-        global $sockets;
89
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
-        die("Bye!\n");
91
-    });
92
-    pcntl_signal_dispatch();
87
+	pcntl_signal(SIGINT,  function() {
88
+		global $sockets;
89
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
+		die("Bye!\n");
91
+	});
92
+	pcntl_signal_dispatch();
93 93
 }
94 94
 
95 95
 // let's try and connect
@@ -99,151 +99,151 @@  discard block
 block discarded – undo
99 99
 $reset = 0;
100 100
 
101 101
 function connect_all($hosts) {
102
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
-    $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
106
-    foreach ($hosts as $id => $value) {
102
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+	$reset++;
105
+	if ($globalDebug) echo 'Connect to all...'."\n";
106
+	foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110 110
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
112
-        	//$formats[$id] = 'deltadbtxt';
113
-        	$globalSources[$id]['format'] = 'deltadbtxt';
114
-        	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
-        	//$formats[$id] = 'vatsimtxt';
118
-        	$globalSources[$id]['format'] = 'vatsimtxt';
119
-        	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
-        	//$formats[$id] = 'aircraftlistjson';
123
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
124
-        	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
127
-        	//$formats[$id] = 'aircraftlistjson';
128
-        	$globalSources[$id]['format'] = 'opensky';
129
-        	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
-        	//$formats[$id] = 'radarvirtueljson';
133
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
134
-        	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
-        	    exit(0);
139
-        	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
-        	//$formats[$id] = 'planeupdatefaa';
142
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
143
-        	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
-        	    exit(0);
148
-        	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
-        	//$formats[$id] = 'phpvmacars';
151
-        	$globalSources[$id]['format'] = 'phpvmacars';
152
-        	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
-        	//$formats[$id] = 'phpvmacars';
156
-        	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
159
-        	//$formats[$id] = 'whazzup';
160
-        	$globalSources[$id]['format'] = 'whazzup';
161
-        	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
164
-        	//$formats[$id] = 'pirepsjson';
165
-        	$globalSources[$id]['format'] = 'pirepsjson';
166
-        	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
-        	//$formats[$id] = 'fr24json';
170
-        	$globalSources[$id]['format'] = 'fr24json';
171
-        	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
-        	    exit(0);
176
-        	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
-        	//$formats[$id] = 'fr24json';
179
-        	$globalSources[$id]['format'] = 'myshiptracking';
180
-        	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
-        	    exit(0);
185
-        	}
186
-            //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
-        	//$formats[$id] = 'tsv';
189
-        	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
-            }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
-    		    if ($idf !== false) {
196
-    			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-    		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
203
-	    if (isset($hostport[1])) {
111
+			if (preg_match('/deltadb.txt$/i',$host)) {
112
+			//$formats[$id] = 'deltadbtxt';
113
+			$globalSources[$id]['format'] = 'deltadbtxt';
114
+			//$last_exec['deltadbtxt'] = 0;
115
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+			//$formats[$id] = 'vatsimtxt';
118
+			$globalSources[$id]['format'] = 'vatsimtxt';
119
+			//$last_exec['vatsimtxt'] = 0;
120
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+			//$formats[$id] = 'aircraftlistjson';
123
+			$globalSources[$id]['format'] = 'aircraftlistjson';
124
+			//$last_exec['aircraftlistjson'] = 0;
125
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
+			} else if (preg_match('/opensky/i',$host)) {
127
+			//$formats[$id] = 'aircraftlistjson';
128
+			$globalSources[$id]['format'] = 'opensky';
129
+			//$last_exec['aircraftlistjson'] = 0;
130
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+			//$formats[$id] = 'radarvirtueljson';
133
+			$globalSources[$id]['format'] = 'radarvirtueljson';
134
+			//$last_exec['radarvirtueljson'] = 0;
135
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
+				exit(0);
139
+			}
140
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+			//$formats[$id] = 'planeupdatefaa';
142
+			$globalSources[$id]['format'] = 'planeupdatefaa';
143
+			//$last_exec['planeupdatefaa'] = 0;
144
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
+				exit(0);
148
+			}
149
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+			//$formats[$id] = 'phpvmacars';
151
+			$globalSources[$id]['format'] = 'phpvmacars';
152
+			//$last_exec['phpvmacars'] = 0;
153
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
155
+			//$formats[$id] = 'phpvmacars';
156
+			$globalSources[$id]['format'] = 'vam';
157
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
+			} else if (preg_match('/whazzup/i',$host)) {
159
+			//$formats[$id] = 'whazzup';
160
+			$globalSources[$id]['format'] = 'whazzup';
161
+			//$last_exec['whazzup'] = 0;
162
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
+			} else if (preg_match('/recentpireps/i',$host)) {
164
+			//$formats[$id] = 'pirepsjson';
165
+			$globalSources[$id]['format'] = 'pirepsjson';
166
+			//$last_exec['pirepsjson'] = 0;
167
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+			//$formats[$id] = 'fr24json';
170
+			$globalSources[$id]['format'] = 'fr24json';
171
+			//$last_exec['fr24json'] = 0;
172
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
+				exit(0);
176
+			}
177
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+			//$formats[$id] = 'fr24json';
179
+			$globalSources[$id]['format'] = 'myshiptracking';
180
+			//$last_exec['fr24json'] = 0;
181
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
+				exit(0);
185
+			}
186
+			//} else if (preg_match('/10001/',$host)) {
187
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+			//$formats[$id] = 'tsv';
189
+			$globalSources[$id]['format'] = 'tsv';
190
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
+			}
192
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+				if ($idf !== false) {
196
+				$httpfeeds[$id] = $idf;
197
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+				}
199
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
+		$hostport = explode(':',$host);
203
+		if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
206
-	    } else {
206
+		} else {
207 207
 		$port = $globalSources[$id]['port'];
208 208
 		$hostn = $globalSources[$id]['host'];
209
-	    }
210
-	    $Common = new Common();
211
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
-    	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
-	    }
216
-	    if ($s) {
217
-    	        $sockets[$id] = $s;
218
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
209
+		}
210
+		$Common = new Common();
211
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+			} else {
214
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+		}
216
+		if ($s) {
217
+				$sockets[$id] = $s;
218
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
223 223
 			//$use_aprs = true;
224
-    		    } elseif ($port == '10001') {
225
-        		//$formats[$id] = 'tsv';
226
-        		$globalSources[$id]['format'] = 'tsv';
227
-		    } elseif ($port == '30002') {
228
-        		//$formats[$id] = 'raw';
229
-        		$globalSources[$id]['format'] = 'raw';
230
-		    } elseif ($port == '5001') {
231
-        		//$formats[$id] = 'raw';
232
-        		$globalSources[$id]['format'] = 'flightgearmp';
233
-		    } elseif ($port == '30005') {
224
+				} elseif ($port == '10001') {
225
+				//$formats[$id] = 'tsv';
226
+				$globalSources[$id]['format'] = 'tsv';
227
+			} elseif ($port == '30002') {
228
+				//$formats[$id] = 'raw';
229
+				$globalSources[$id]['format'] = 'raw';
230
+			} elseif ($port == '5001') {
231
+				//$formats[$id] = 'raw';
232
+				$globalSources[$id]['format'] = 'flightgearmp';
233
+			} elseif ($port == '30005') {
234 234
 			// Not yet supported
235
-        		//$formats[$id] = 'beast';
236
-        		$globalSources[$id]['format'] = 'beast';
237
-		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
239
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
235
+				//$formats[$id] = 'beast';
236
+				$globalSources[$id]['format'] = 'beast';
237
+			//} else $formats[$id] = 'sbs';
238
+			} else $globalSources[$id]['format'] = 'sbs';
239
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 240
 		}
241 241
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
242
-            } else {
242
+			} else {
243 243
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
244
-    	    }
245
-        }
246
-    }
244
+			}
245
+		}
246
+	}
247 247
 }
248 248
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
249 249
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
270 270
 } else {
271
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
271
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
273 273
 
274 274
 // APRS Configuration
@@ -277,18 +277,18 @@  discard block
 block discarded – undo
277 277
 	die;
278 278
 }
279 279
 foreach ($globalSources as $key => $source) {
280
-    if (!isset($source['format'])) {
281
-        $globalSources[$key]['format'] = 'auto';
282
-    }
280
+	if (!isset($source['format'])) {
281
+		$globalSources[$key]['format'] = 'auto';
282
+	}
283 283
 }
284 284
 connect_all($globalSources);
285 285
 foreach ($globalSources as $key => $source) {
286
-    if (isset($source['format']) && $source['format'] == 'aprs') {
286
+	if (isset($source['format']) && $source['format'] == 'aprs') {
287 287
 	$aprs_connect = 0;
288 288
 	$use_aprs = true;
289 289
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
290 290
 	break;
291
-    }
291
+	}
292 292
 }
293 293
 
294 294
 if ($use_aprs) {
@@ -329,152 +329,152 @@  discard block
 block discarded – undo
329 329
 
330 330
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
331 331
 while ($i > 0) {
332
-    if (!$globalDaemon) $i = $endtime-time();
333
-    // Delete old ATC
334
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
332
+	if (!$globalDaemon) $i = $endtime-time();
333
+	// Delete old ATC
334
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
335 335
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
336
-        $ATC->deleteOldATC();
337
-    }
336
+		$ATC->deleteOldATC();
337
+	}
338 338
     
339
-    //if (count($last_exec) > 0) {
340
-    if (count($last_exec) == count($globalSources)) {
339
+	//if (count($last_exec) > 0) {
340
+	if (count($last_exec) == count($globalSources)) {
341 341
 	$max = $globalMinFetch;
342 342
 	foreach ($last_exec as $last) {
343
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
343
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
344 344
 	}
345 345
 	if ($max != $globalMinFetch) {
346
-	    if ($globalDebug) echo 'Sleeping...'."\n";
347
-	    sleep($globalMinFetch-$max+2);
346
+		if ($globalDebug) echo 'Sleeping...'."\n";
347
+		sleep($globalMinFetch-$max+2);
348
+	}
348 349
 	}
349
-    }
350 350
 
351 351
     
352
-    //foreach ($formats as $id => $value) {
353
-    foreach ($globalSources as $id => $value) {
352
+	//foreach ($formats as $id => $value) {
353
+	foreach ($globalSources as $id => $value) {
354 354
 	date_default_timezone_set('UTC');
355 355
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
356 356
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
357
-	    //$buffer = $Common->getData($hosts[$id]);
358
-	    $buffer = $Common->getData($value['host']);
359
-	    if ($buffer != '') $reset = 0;
360
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361
-	    $buffer = explode('\n',$buffer);
362
-	    foreach ($buffer as $line) {
363
-    		if ($line != '' && count($line) > 7) {
364
-    		    $line = explode(',', $line);
365
-	            $data = array();
366
-	            $data['hex'] = $line[1]; // hex
367
-	            $data['ident'] = $line[2]; // ident
368
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
373
-	            $data['verticalrate'] = ''; // vertical rate
374
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375
-	            $data['emergency'] = ''; // emergency
376
-		    $data['datetime'] = date('Y-m-d H:i:s');
377
-		    $data['format_source'] = 'deltadbtxt';
378
-    		    $data['id_source'] = $id_source;
379
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
381
-    		    $SI->add($data);
382
-		    unset($data);
383
-    		}
384
-    	    }
385
-    	    $last_exec[$id]['last'] = time();
357
+		//$buffer = $Common->getData($hosts[$id]);
358
+		$buffer = $Common->getData($value['host']);
359
+		if ($buffer != '') $reset = 0;
360
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361
+		$buffer = explode('\n',$buffer);
362
+		foreach ($buffer as $line) {
363
+			if ($line != '' && count($line) > 7) {
364
+				$line = explode(',', $line);
365
+				$data = array();
366
+				$data['hex'] = $line[1]; // hex
367
+				$data['ident'] = $line[2]; // ident
368
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
373
+				$data['verticalrate'] = ''; // vertical rate
374
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375
+				$data['emergency'] = ''; // emergency
376
+			$data['datetime'] = date('Y-m-d H:i:s');
377
+			$data['format_source'] = 'deltadbtxt';
378
+				$data['id_source'] = $id_source;
379
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
381
+				$SI->add($data);
382
+			unset($data);
383
+			}
384
+			}
385
+			$last_exec[$id]['last'] = time();
386 386
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
387
-	    date_default_timezone_set('CET');
388
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389
-	    date_default_timezone_set('UTC');
390
-	    if ($buffer != '') $reset = 0;
391
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392
-	    $buffer = explode('\n',$buffer);
393
-	    foreach ($buffer as $line) {
387
+		date_default_timezone_set('CET');
388
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389
+		date_default_timezone_set('UTC');
390
+		if ($buffer != '') $reset = 0;
391
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392
+		$buffer = explode('\n',$buffer);
393
+		foreach ($buffer as $line) {
394 394
 		if ($line != '') {
395
-		    echo "'".$line."'\n";
396
-		    $add = false;
397
-		    $ais_data = $AIS->parse_line(trim($line));
398
-		    $data = array();
399
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
409
-		    if (isset($ais_data['timestamp'])) {
395
+			echo "'".$line."'\n";
396
+			$add = false;
397
+			$ais_data = $AIS->parse_line(trim($line));
398
+			$data = array();
399
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
409
+			if (isset($ais_data['timestamp'])) {
410 410
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
411 411
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
412
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
413
-			    $add = true;
412
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
413
+				$add = true;
414 414
 			}
415
-		    } else {
415
+			} else {
416 416
 			$data['datetime'] = date('Y-m-d H:i:s');
417 417
 			$add = true;
418
-		    }
419
-		    $data['format_source'] = 'aisnmeatxt';
420
-    		    $data['id_source'] = $id_source;
421
-		    print_r($data);
422
-		    echo 'Add...'."\n";
423
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
424
-		    unset($data);
418
+			}
419
+			$data['format_source'] = 'aisnmeatxt';
420
+				$data['id_source'] = $id_source;
421
+			print_r($data);
422
+			echo 'Add...'."\n";
423
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
424
+			unset($data);
425 425
 		}
426
-    	    }
427
-    	    $last_exec[$id]['last'] = time();
426
+			}
427
+			$last_exec[$id]['last'] = time();
428 428
 	} elseif ($value['format'] == 'aisnmeahttp') {
429
-	    $arr = $httpfeeds;
430
-	    $w = $e = null;
429
+		$arr = $httpfeeds;
430
+		$w = $e = null;
431 431
 	    
432
-	    if (isset($arr[$id])) {
433
-	    $nn = stream_select($arr,$w,$e,$timeout);
434
-	    if ($nn > 0) {
432
+		if (isset($arr[$id])) {
433
+		$nn = stream_select($arr,$w,$e,$timeout);
434
+		if ($nn > 0) {
435 435
 		foreach ($httpfeeds as $feed) {
436
-		    $buffer = stream_get_line($feed,2000,"\n");
437
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
438
-		    $buffer = explode('\n',$buffer);
439
-		    foreach ($buffer as $line) {
436
+			$buffer = stream_get_line($feed,2000,"\n");
437
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
438
+			$buffer = explode('\n',$buffer);
439
+			foreach ($buffer as $line) {
440 440
 			if ($line != '') {
441
-			    $ais_data = $AIS->parse_line(trim($line));
442
-			    $data = array();
443
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
455
-			    if (isset($ais_data['timestamp'])) {
441
+				$ais_data = $AIS->parse_line(trim($line));
442
+				$data = array();
443
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
455
+				if (isset($ais_data['timestamp'])) {
456 456
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
457
-			    } else {
457
+				} else {
458 458
 				$data['datetime'] = date('Y-m-d H:i:s');
459
-			    }
460
-			    $data['format_source'] = 'aisnmeahttp';
461
-			    $data['id_source'] = $id_source;
462
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
463
-			    unset($data);
459
+				}
460
+				$data['format_source'] = 'aisnmeahttp';
461
+				$data['id_source'] = $id_source;
462
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
463
+				unset($data);
464
+			}
464 465
 			}
465
-		    }
466 466
 		}
467 467
 		}
468
-	    }
468
+		}
469 469
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
470
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
471
-	    if ($buffer != '') {
470
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
471
+		if ($buffer != '') {
472 472
 		//echo $buffer;
473 473
 		$all_data = json_decode($buffer,true);
474 474
 		//print_r($all_data);
475 475
 		if (isset($all_data[0]['DATA'])) {
476 476
 		foreach ($all_data[0]['DATA'] as $line) {
477
-		    if ($line != '') {
477
+			if ($line != '') {
478 478
 			$data = array();
479 479
 			$data['ident'] = $line['NAME'];
480 480
 			$data['mmsi'] = $line['MMSI'];
@@ -490,23 +490,23 @@  discard block
 block discarded – undo
490 490
 			$data['id_source'] = $id_source;
491 491
 			$MI->add($data);
492 492
 			unset($data);
493
-		    }
493
+			}
494 494
 		}
495 495
 		}
496 496
 		
497
-	    }
498
-    	    $last_exec[$id]['last'] = time();
497
+		}
498
+			$last_exec[$id]['last'] = time();
499 499
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
500
-	    echo 'Try ?'."\n";
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
-	    echo $buffer;
503
-	    if ($buffer != '') {
500
+		echo 'Try ?'."\n";
501
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
+		echo $buffer;
503
+		if ($buffer != '') {
504 504
 		//echo $buffer;
505 505
 		$all_data = json_decode($buffer,true);
506 506
 		print_r($all_data);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508 508
 		foreach ($all_data as $line) {
509
-		    if ($line != '') {
509
+			if ($line != '') {
510 510
 			$data = array();
511 511
 			$data['ident'] = $line['shipname'];
512 512
 			$data['callsign'] = $line['callsign'];
@@ -522,59 +522,59 @@  discard block
 block discarded – undo
522 522
 			$data['id_source'] = $id_source;
523 523
 			$MI->add($data);
524 524
 			unset($data);
525
-		    }
525
+			}
526 526
 		}
527 527
 		}
528 528
 		
529
-	    }
530
-    	    $last_exec[$id]['last'] = time();
529
+		}
530
+			$last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532
-	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
-	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
538
-	    foreach ($buffer as $line) {
532
+		echo 'download...';
533
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
+		echo 'done !'."\n";
535
+		if ($buffer != '') $reset = 0;
536
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
+		$buffer = explode('\n',$buffer);
538
+		foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540
-		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
-		    //$data['status'] = substr($line,21,2);
544
-		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
548
-		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
550
-		    //$data['draft'] = substr($line,67,4);
551
-		    //$data['length'] = substr($line,72,3);
552
-		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
-		    //$data['callsign'] = trim(substr($line,100,7);
555
-		    //$data['dest'] = substr($line,108,20);
556
-		    //$data['etaDate'] = substr($line,129,5);
557
-		    //$data['etaTime'] = substr($line,135,5);
558
-		    $data['format_source'] = 'shipplotter';
559
-    		    $data['id_source'] = $id_source;
560
-		    print_r($data);
561
-		    echo 'Add...'."\n";
562
-		    $MI->add($data);
563
-		    unset($data);
540
+			$data = array();
541
+			$data['mmsi'] = (int)substr($line,0,9);
542
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
+			//$data['status'] = substr($line,21,2);
544
+			//$data['type'] = substr($line,24,3);
545
+			$data['latitude'] = substr($line,29,9);
546
+			$data['longitude'] = substr($line,41,9);
547
+			$data['speed'] = round(substr($line,51,5));
548
+			//$data['course'] = substr($line,57,5);
549
+			$data['heading'] = round(substr($line,63,3));
550
+			//$data['draft'] = substr($line,67,4);
551
+			//$data['length'] = substr($line,72,3);
552
+			//$data['beam'] = substr($line,76,2);
553
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
+			//$data['callsign'] = trim(substr($line,100,7);
555
+			//$data['dest'] = substr($line,108,20);
556
+			//$data['etaDate'] = substr($line,129,5);
557
+			//$data['etaTime'] = substr($line,135,5);
558
+			$data['format_source'] = 'shipplotter';
559
+				$data['id_source'] = $id_source;
560
+			print_r($data);
561
+			echo 'Add...'."\n";
562
+			$MI->add($data);
563
+			unset($data);
564 564
 		}
565
-    	    }
566
-    	    $last_exec[$id]['last'] = time();
565
+			}
566
+			$last_exec[$id]['last'] = time();
567 567
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569
-	    //$buffer = $Common->getData($hosts[$id]);
570
-	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
573
-	    $reset = 0;
574
-	    foreach ($buffer as $line) {
575
-    		if ($line != '') {
576
-    		    $line = explode(':', $line);
577
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
569
+		//$buffer = $Common->getData($hosts[$id]);
570
+		$buffer = $Common->getData($value['host']);
571
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
+		$buffer = explode('\n',$buffer);
573
+		$reset = 0;
574
+		foreach ($buffer as $line) {
575
+			if ($line != '') {
576
+				$line = explode(':', $line);
577
+				if (count($line) > 30 && $line[0] != 'callsign') {
578 578
 			$data = array();
579 579
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -587,36 +587,36 @@  discard block
 block discarded – undo
587 587
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588 588
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
589 589
 			$data['latitude'] = $line[5]; // lat
590
-	        	$data['longitude'] = $line[6]; // long
591
-	        	$data['verticalrate'] = ''; // vertical rate
592
-	        	$data['squawk'] = ''; // squawk
593
-	        	$data['emergency'] = ''; // emergency
594
-	        	$data['waypoints'] = $line[30];
590
+				$data['longitude'] = $line[6]; // long
591
+				$data['verticalrate'] = ''; // vertical rate
592
+				$data['squawk'] = ''; // squawk
593
+				$data['emergency'] = ''; // emergency
594
+				$data['waypoints'] = $line[30];
595 595
 			$data['datetime'] = date('Y-m-d H:i:s');
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598
-		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
-		        $data['arrival_airport_icao'] = $line[13];
598
+				$data['departure_airport_icao'] = $line[11];
599
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
+				$data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
603 603
 			$data['range'] = $line[19];
604 604
 			if (isset($line[35])) $data['info'] = $line[35];
605
-    			$data['id_source'] = $id_source;
606
-	    		//$data['arrival_airport_time'] = ;
607
-	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
609
-	    		    if (isset($aircraft_data[1])) {
610
-	    			$data['aircraft_icao'] = $aircraft_data[1];
611
-	    		    }
612
-        		}
613
-	    		/*
605
+				$data['id_source'] = $id_source;
606
+				//$data['arrival_airport_time'] = ;
607
+				if ($line[9] != '') {
608
+					$aircraft_data = explode('/',$line[9]);
609
+					if (isset($aircraft_data[1])) {
610
+					$data['aircraft_icao'] = $aircraft_data[1];
611
+					}
612
+				}
613
+				/*
614 614
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
615 615
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 616
 	    		*/
617
-	    		$data['format_source'] = $value['format'];
617
+				$data['format_source'] = $value['format'];
618 618
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
619
+				if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622 622
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -634,247 +634,247 @@  discard block
 block discarded – undo
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635 635
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
636 636
 			}
637
-    			unset($data);
638
-    		    }
639
-    		}
640
-    	    }
641
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
-    	    $last_exec[$id]['last'] = time();
644
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
647
-	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
649
-	    if (isset($all_data['acList'])) {
637
+				unset($data);
638
+				}
639
+			}
640
+			}
641
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
+			$last_exec[$id]['last'] = time();
644
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
647
+		if ($buffer != '') {
648
+		$all_data = json_decode($buffer,true);
649
+		if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
652
-		    $data = array();
653
-		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
-		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
-		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
-		    /*
652
+			$data = array();
653
+			$data['hex'] = $line['Icao']; // hex
654
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
+			//$data['verticalrate'] = $line['']; // verticale rate
661
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
+			$data['emergency'] = ''; // emergency
663
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
+			/*
665 665
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 666
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 667
 		    */
668
-		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
-	    	    $data['format_source'] = 'aircraftlistjson';
671
-		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['datetime'])) $SI->add($data);
674
-		    unset($data);
668
+			$data['datetime'] = date('Y-m-d H:i:s');
669
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
+				$data['format_source'] = 'aircraftlistjson';
671
+			$data['id_source'] = $id_source;
672
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
+			if (isset($data['datetime'])) $SI->add($data);
674
+			unset($data);
675 675
 		}
676
-	    } else {
676
+		} else {
677 677
 		$reset = 0;
678 678
 		foreach ($all_data as $line) {
679
-		    $data = array();
680
-		    $data['hex'] = $line['hex']; // hex
681
-		    $data['ident'] = $line['flight']; // ident
682
-		    $data['altitude'] = $line['altitude']; // altitude
683
-		    $data['speed'] = $line['speed']; // speed
684
-		    $data['heading'] = $line['track']; // heading
685
-		    $data['latitude'] = $line['lat']; // lat
686
-		    $data['longitude'] = $line['lon']; // long
687
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
688
-		    $data['squawk'] = $line['squawk']; // squawk
689
-		    $data['emergency'] = ''; // emergency
690
-		    $data['datetime'] = date('Y-m-d H:i:s');
691
-	    	    $data['format_source'] = 'aircraftlistjson';
692
-    		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
-		    $SI->add($data);
695
-		    unset($data);
679
+			$data = array();
680
+			$data['hex'] = $line['hex']; // hex
681
+			$data['ident'] = $line['flight']; // ident
682
+			$data['altitude'] = $line['altitude']; // altitude
683
+			$data['speed'] = $line['speed']; // speed
684
+			$data['heading'] = $line['track']; // heading
685
+			$data['latitude'] = $line['lat']; // lat
686
+			$data['longitude'] = $line['lon']; // long
687
+			$data['verticalrate'] = $line['vrt']; // verticale rate
688
+			$data['squawk'] = $line['squawk']; // squawk
689
+			$data['emergency'] = ''; // emergency
690
+			$data['datetime'] = date('Y-m-d H:i:s');
691
+				$data['format_source'] = 'aircraftlistjson';
692
+				$data['id_source'] = $id_source;
693
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
+			$SI->add($data);
695
+			unset($data);
696 696
 		}
697
-	    }
698
-	    }
699
-    	    //$last_exec['aircraftlistjson'] = time();
700
-    	    $last_exec[$id]['last'] = time();
701
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
-	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
705
-	    if (isset($all_data['planes'])) {
697
+		}
698
+		}
699
+			//$last_exec['aircraftlistjson'] = time();
700
+			$last_exec[$id]['last'] = time();
701
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
+		$buffer = $Common->getData($value['host']);
704
+		$all_data = json_decode($buffer,true);
705
+		if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
708
-		    $data = array();
709
-		    $data['hex'] = $key; // hex
710
-		    $data['ident'] = $line[3]; // ident
711
-		    $data['altitude'] = $line[6]; // altitude
712
-		    $data['speed'] = $line[8]; // speed
713
-		    $data['heading'] = $line[7]; // heading
714
-		    $data['latitude'] = $line[4]; // lat
715
-		    $data['longitude'] = $line[5]; // long
716
-		    //$data['verticalrate'] = $line[]; // verticale rate
717
-		    $data['squawk'] = $line[10]; // squawk
718
-		    $data['emergency'] = ''; // emergency
719
-		    $data['registration'] = $line[2];
720
-		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
722
-		    if (count($deparr) == 2) {
708
+			$data = array();
709
+			$data['hex'] = $key; // hex
710
+			$data['ident'] = $line[3]; // ident
711
+			$data['altitude'] = $line[6]; // altitude
712
+			$data['speed'] = $line[8]; // speed
713
+			$data['heading'] = $line[7]; // heading
714
+			$data['latitude'] = $line[4]; // lat
715
+			$data['longitude'] = $line[5]; // long
716
+			//$data['verticalrate'] = $line[]; // verticale rate
717
+			$data['squawk'] = $line[10]; // squawk
718
+			$data['emergency'] = ''; // emergency
719
+			$data['registration'] = $line[2];
720
+			$data['aircraft_icao'] = $line[0];
721
+			$deparr = explode('-',$line[1]);
722
+			if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725
-		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
-	    	    $data['format_source'] = 'planeupdatefaa';
728
-    		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
-		    $SI->add($data);
731
-		    unset($data);
725
+			}
726
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
+				$data['format_source'] = 'planeupdatefaa';
728
+				$data['id_source'] = $id_source;
729
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
+			$SI->add($data);
731
+			unset($data);
732 732
 		}
733
-	    }
734
-    	    //$last_exec['planeupdatefaa'] = time();
735
-    	    $last_exec[$id]['last'] = time();
736
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
-	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
739
-	    if (isset($all_data['states'])) {
733
+		}
734
+			//$last_exec['planeupdatefaa'] = time();
735
+			$last_exec[$id]['last'] = time();
736
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
+		$buffer = $Common->getData($value['host']);
738
+		$all_data = json_decode($buffer,true);
739
+		if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
742
-		    $data = array();
743
-		    $data['hex'] = $line[0]; // hex
744
-		    $data['ident'] = trim($line[1]); // ident
745
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
746
-		    $data['speed'] = round($line[9]*1.94384); // speed
747
-		    $data['heading'] = round($line[10]); // heading
748
-		    $data['latitude'] = $line[5]; // lat
749
-		    $data['longitude'] = $line[6]; // long
750
-		    $data['verticalrate'] = $line[11]; // verticale rate
751
-		    //$data['squawk'] = $line[10]; // squawk
752
-		    //$data['emergency'] = ''; // emergency
753
-		    //$data['registration'] = $line[2];
754
-		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
-	    	    $data['format_source'] = 'opensky';
757
-    		    $data['id_source'] = $id_source;
758
-		    $SI->add($data);
759
-		    unset($data);
742
+			$data = array();
743
+			$data['hex'] = $line[0]; // hex
744
+			$data['ident'] = trim($line[1]); // ident
745
+			$data['altitude'] = round($line[7]*3.28084); // altitude
746
+			$data['speed'] = round($line[9]*1.94384); // speed
747
+			$data['heading'] = round($line[10]); // heading
748
+			$data['latitude'] = $line[5]; // lat
749
+			$data['longitude'] = $line[6]; // long
750
+			$data['verticalrate'] = $line[11]; // verticale rate
751
+			//$data['squawk'] = $line[10]; // squawk
752
+			//$data['emergency'] = ''; // emergency
753
+			//$data['registration'] = $line[2];
754
+			//$data['aircraft_icao'] = $line[0];
755
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
+				$data['format_source'] = 'opensky';
757
+				$data['id_source'] = $id_source;
758
+			$SI->add($data);
759
+			unset($data);
760 760
 		}
761
-	    }
762
-    	    //$last_exec['planeupdatefaa'] = time();
763
-    	    $last_exec[$id]['last'] = time();
764
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
-	    //$buffer = $Common->getData($hosts[$id]);
767
-	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
770
-	    foreach ($all_data as $key => $line) {
761
+		}
762
+			//$last_exec['planeupdatefaa'] = time();
763
+			$last_exec[$id]['last'] = time();
764
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
+		//$buffer = $Common->getData($hosts[$id]);
767
+		$buffer = $Common->getData($value['host']);
768
+		$all_data = json_decode($buffer,true);
769
+		if (!empty($all_data)) $reset = 0;
770
+		foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772
-		    $data = array();
773
-		    $data['hex'] = $line[0];
774
-		    $data['ident'] = $line[16]; //$line[13]
775
-	    	    $data['altitude'] = $line[4]; // altitude
776
-	    	    $data['speed'] = $line[5]; // speed
777
-	    	    $data['heading'] = $line[3]; // heading
778
-	    	    $data['latitude'] = $line[1]; // lat
779
-	    	    $data['longitude'] = $line[2]; // long
780
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
781
-	    	    $data['squawk'] = $line[6]; // squawk
782
-	    	    $data['aircraft_icao'] = $line[8];
783
-	    	    $data['registration'] = $line[9];
784
-		    $data['departure_airport_iata'] = $line[11];
785
-		    $data['arrival_airport_iata'] = $line[12];
786
-	    	    $data['emergency'] = ''; // emergency
787
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
-	    	    $data['format_source'] = 'fr24json';
789
-    		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
-		    $SI->add($data);
792
-		    unset($data);
772
+			$data = array();
773
+			$data['hex'] = $line[0];
774
+			$data['ident'] = $line[16]; //$line[13]
775
+				$data['altitude'] = $line[4]; // altitude
776
+				$data['speed'] = $line[5]; // speed
777
+				$data['heading'] = $line[3]; // heading
778
+				$data['latitude'] = $line[1]; // lat
779
+				$data['longitude'] = $line[2]; // long
780
+				$data['verticalrate'] = $line[15]; // verticale rate
781
+				$data['squawk'] = $line[6]; // squawk
782
+				$data['aircraft_icao'] = $line[8];
783
+				$data['registration'] = $line[9];
784
+			$data['departure_airport_iata'] = $line[11];
785
+			$data['arrival_airport_iata'] = $line[12];
786
+				$data['emergency'] = ''; // emergency
787
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
+				$data['format_source'] = 'fr24json';
789
+				$data['id_source'] = $id_source;
790
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
+			$SI->add($data);
792
+			unset($data);
793 793
 		}
794
-	    }
795
-    	    //$last_exec['fr24json'] = time();
796
-    	    $last_exec[$id]['last'] = time();
797
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
801
-	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
805
-	    if (json_last_error() != JSON_ERROR_NONE) {
794
+		}
795
+			//$last_exec['fr24json'] = time();
796
+			$last_exec[$id]['last'] = time();
797
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
801
+		//echo $buffer;
802
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
803
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
+		$all_data = json_decode($buffer,true);
805
+		if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807
-	    }
808
-	    if (isset($all_data['mrkrs'])) {
807
+		}
808
+		if (isset($all_data['mrkrs'])) {
809 809
 		$reset = 0;
810 810
 		foreach ($all_data['mrkrs'] as $key => $line) {
811
-		    if (isset($line['inf'])) {
811
+			if (isset($line['inf'])) {
812 812
 			$data = array();
813 813
 			$data['hex'] = $line['inf']['ia'];
814 814
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
815
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
-	    		$data['latitude'] = $line['pt'][0]; // lat
819
-	    		$data['longitude'] = $line['pt'][1]; // long
820
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
-	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
815
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
+				$data['latitude'] = $line['pt'][0]; // lat
819
+				$data['longitude'] = $line['pt'][1]; // long
820
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
+				//$data['aircraft_icao'] = $line[8];
823
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826
-	    		//$data['emergency'] = ''; // emergency
826
+				//$data['emergency'] = ''; // emergency
827 827
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828
-	    		$data['format_source'] = 'radarvirtueljson';
829
-    			$data['id_source'] = $id_source;
828
+				$data['format_source'] = 'radarvirtueljson';
829
+				$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
831 831
 			$SI->add($data);
832 832
 			unset($data);
833
-		    }
833
+			}
834
+		}
834 835
 		}
835
-	    }
836
-    	    //$last_exec['radarvirtueljson'] = time();
837
-    	    $last_exec[$id]['last'] = time();
838
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
-	    //$buffer = $Common->getData($hosts[$id]);
841
-	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
836
+			//$last_exec['radarvirtueljson'] = time();
837
+			$last_exec[$id]['last'] = time();
838
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
+		//$buffer = $Common->getData($hosts[$id]);
841
+		$buffer = $Common->getData($value['host'].'?'.time());
842
+		$all_data = json_decode(utf8_encode($buffer),true);
843 843
 	    
844
-	    if (isset($all_data['pireps'])) {
844
+		if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846
-	        foreach ($all_data['pireps'] as $line) {
847
-		    $data = array();
848
-		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
-		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
-		    $data['latitude'] = $line['lat']; // lat
858
-		    $data['longitude'] = $line['lon']; // long
859
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860
-		    //$data['squawk'] = $line['squawk']; // squawk
861
-		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
-		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
870
-		    $data['format_source'] = 'pireps';
871
-    		    $data['id_source'] = $id_source;
872
-		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
-		    if ($line['icon'] == 'plane') {
846
+			foreach ($all_data['pireps'] as $line) {
847
+			$data = array();
848
+			$data['id'] = $line['id'];
849
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
+			$data['ident'] = $line['callsign']; // ident
851
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
+			$data['latitude'] = $line['lat']; // lat
858
+			$data['longitude'] = $line['lon']; // long
859
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
860
+			//$data['squawk'] = $line['squawk']; // squawk
861
+			//$data['emergency'] = ''; // emergency
862
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
+			//$data['arrival_airport_time'] = $line['arrtime'];
866
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
869
+			else $data['info'] = '';
870
+			$data['format_source'] = 'pireps';
871
+				$data['id_source'] = $id_source;
872
+			$data['datetime'] = date('Y-m-d H:i:s');
873
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
+			if ($line['icon'] == 'plane') {
875 875
 			$SI->add($data);
876
-		    //    print_r($data);
877
-    		    } elseif ($line['icon'] == 'ct') {
876
+			//    print_r($data);
877
+				} elseif ($line['icon'] == 'ct') {
878 878
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879 879
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 880
 			$typec = substr($data['ident'],-3);
@@ -889,188 +889,188 @@  discard block
 block discarded – undo
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891 891
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
892
-		    }
893
-		    unset($data);
892
+			}
893
+			unset($data);
894
+		}
894 895
 		}
895
-	    }
896
-    	    //$last_exec['pirepsjson'] = time();
897
-    	    $last_exec[$id]['last'] = time();
898
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
-	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
902
-	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
904
-	    if ($buffer != '' && is_array($all_data)) {
896
+			//$last_exec['pirepsjson'] = time();
897
+			$last_exec[$id]['last'] = time();
898
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
+		//$buffer = $Common->getData($hosts[$id]);
901
+		if ($globalDebug) echo 'Get Data...'."\n";
902
+		$buffer = $Common->getData($value['host']);
903
+		$all_data = json_decode($buffer,true);
904
+		if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907
-	    	    $data = array();
908
-	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
-	    	    $data['ident'] = $line['flightnum']; // ident
914
-	    	    $data['altitude'] = $line['alt']; // altitude
915
-	    	    $data['speed'] = $line['gs']; // speed
916
-	    	    $data['heading'] = $line['heading']; // heading
917
-	    	    $data['latitude'] = $line['lat']; // lat
918
-	    	    $data['longitude'] = $line['lng']; // long
919
-	    	    $data['verticalrate'] = ''; // verticale rate
920
-	    	    $data['squawk'] = ''; // squawk
921
-	    	    $data['emergency'] = ''; // emergency
922
-	    	    //$data['datetime'] = $line['lastupdate'];
923
-	    	    $data['last_update'] = $line['lastupdate'];
924
-		    $data['datetime'] = date('Y-m-d H:i:s');
925
-	    	    $data['departure_airport_icao'] = $line['depicao'];
926
-	    	    $data['departure_airport_time'] = $line['deptime'];
927
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
928
-    		    $data['arrival_airport_time'] = $line['arrtime'];
929
-    		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
-		    if (isset($line['aircraftname'])) {
907
+				$data = array();
908
+				//$data['id'] = $line['id']; // id not usable
909
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
+				$data['ident'] = $line['flightnum']; // ident
914
+				$data['altitude'] = $line['alt']; // altitude
915
+				$data['speed'] = $line['gs']; // speed
916
+				$data['heading'] = $line['heading']; // heading
917
+				$data['latitude'] = $line['lat']; // lat
918
+				$data['longitude'] = $line['lng']; // long
919
+				$data['verticalrate'] = ''; // verticale rate
920
+				$data['squawk'] = ''; // squawk
921
+				$data['emergency'] = ''; // emergency
922
+				//$data['datetime'] = $line['lastupdate'];
923
+				$data['last_update'] = $line['lastupdate'];
924
+			$data['datetime'] = date('Y-m-d H:i:s');
925
+				$data['departure_airport_icao'] = $line['depicao'];
926
+				$data['departure_airport_time'] = $line['deptime'];
927
+				$data['arrival_airport_icao'] = $line['arricao'];
928
+				$data['arrival_airport_time'] = $line['arrtime'];
929
+				$data['registration'] = $line['aircraft'];
930
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
+			if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 933
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941
-	    		}
942
-	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
-    		    $data['id_source'] = $id_source;
945
-	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
-		    $SI->add($data);
948
-		    unset($data);
934
+				$aircraft_data = explode('-',$line['aircraftname']);
935
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
+				else {
938
+					$aircraft_data = explode(' ',$line['aircraftname']);
939
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
+					else $data['aircraft_icao'] = $line['aircraftname'];
941
+				}
942
+				}
943
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
+				$data['id_source'] = $id_source;
945
+				$data['format_source'] = 'phpvmacars';
946
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
+			$SI->add($data);
948
+			unset($data);
949 949
 		}
950 950
 		if ($globalDebug) echo 'No more data...'."\n";
951 951
 		unset($buffer);
952 952
 		unset($all_data);
953
-	    }
954
-    	    //$last_exec['phpvmacars'] = time();
955
-    	    $last_exec[$id]['last'] = time();
956
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
-	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
959
-	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
961
-	    if ($buffer != '' && is_array($all_data)) {
953
+		}
954
+			//$last_exec['phpvmacars'] = time();
955
+			$last_exec[$id]['last'] = time();
956
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
+		//$buffer = $Common->getData($hosts[$id]);
958
+		if ($globalDebug) echo 'Get Data...'."\n";
959
+		$buffer = $Common->getData($value['host']);
960
+		$all_data = json_decode($buffer,true);
961
+		if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964
-	    	    $data = array();
965
-	    	    //$data['id'] = $line['id']; // id not usable
966
-	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
-	    	    $data['pilot_name'] = $line['pilot_name'];
969
-	    	    $data['pilot_id'] = $line['pilot_id'];
970
-	    	    $data['ident'] = trim($line['callsign']); // ident
971
-	    	    $data['altitude'] = $line['altitude']; // altitude
972
-	    	    $data['speed'] = $line['gs']; // speed
973
-	    	    $data['heading'] = $line['heading']; // heading
974
-	    	    $data['latitude'] = $line['latitude']; // lat
975
-	    	    $data['longitude'] = $line['longitude']; // long
976
-	    	    $data['verticalrate'] = ''; // verticale rate
977
-	    	    $data['squawk'] = ''; // squawk
978
-	    	    $data['emergency'] = ''; // emergency
979
-	    	    //$data['datetime'] = $line['lastupdate'];
980
-	    	    $data['last_update'] = $line['last_update'];
981
-		    $data['datetime'] = date('Y-m-d H:i:s');
982
-	    	    $data['departure_airport_icao'] = $line['departure'];
983
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
984
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
985
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
986
-    		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
-	    	    $data['aircraft_icao'] = $line['plane_type'];
989
-    		    $data['id_source'] = $id_source;
990
-	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
-		    $SI->add($data);
993
-		    unset($data);
964
+				$data = array();
965
+				//$data['id'] = $line['id']; // id not usable
966
+				$data['id'] = trim($line['flight_id']);
967
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
+				$data['pilot_name'] = $line['pilot_name'];
969
+				$data['pilot_id'] = $line['pilot_id'];
970
+				$data['ident'] = trim($line['callsign']); // ident
971
+				$data['altitude'] = $line['altitude']; // altitude
972
+				$data['speed'] = $line['gs']; // speed
973
+				$data['heading'] = $line['heading']; // heading
974
+				$data['latitude'] = $line['latitude']; // lat
975
+				$data['longitude'] = $line['longitude']; // long
976
+				$data['verticalrate'] = ''; // verticale rate
977
+				$data['squawk'] = ''; // squawk
978
+				$data['emergency'] = ''; // emergency
979
+				//$data['datetime'] = $line['lastupdate'];
980
+				$data['last_update'] = $line['last_update'];
981
+			$data['datetime'] = date('Y-m-d H:i:s');
982
+				$data['departure_airport_icao'] = $line['departure'];
983
+				//$data['departure_airport_time'] = $line['departure_time'];
984
+				$data['arrival_airport_icao'] = $line['arrival'];
985
+				//$data['arrival_airport_time'] = $line['arrival_time'];
986
+				//$data['registration'] = $line['aircraft'];
987
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
+				$data['aircraft_icao'] = $line['plane_type'];
989
+				$data['id_source'] = $id_source;
990
+				$data['format_source'] = 'vam';
991
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
+			$SI->add($data);
993
+			unset($data);
994 994
 		}
995 995
 		if ($globalDebug) echo 'No more data...'."\n";
996 996
 		unset($buffer);
997 997
 		unset($all_data);
998
-	    }
999
-    	    //$last_exec['phpvmacars'] = time();
1000
-    	    $last_exec[$id]['last'] = time();
998
+		}
999
+			//$last_exec['phpvmacars'] = time();
1000
+			$last_exec[$id]['last'] = time();
1001 1001
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1002
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
-    	    //$last_exec[$id]['last'] = time();
1003
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
+			//$last_exec[$id]['last'] = time();
1005 1005
 
1006
-	    //$read = array( $sockets[$id] );
1007
-	    $read = $sockets;
1008
-	    $write = NULL;
1009
-	    $e = NULL;
1010
-	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1012
-	    if ($n > 0) {
1006
+		//$read = array( $sockets[$id] );
1007
+		$read = $sockets;
1008
+		$write = NULL;
1009
+		$e = NULL;
1010
+		$n = socket_select($read, $write, $e, $timeout);
1011
+		if ($e != NULL) var_dump($e);
1012
+		if ($n > 0) {
1013 1013
 		$reset = 0;
1014 1014
 		foreach ($read as $nb => $r) {
1015
-		    //$value = $formats[$nb];
1016
-		    $format = $globalSources[$nb]['format'];
1017
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
-        	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
-	    	    }
1022
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
-        	    //echo $buffer."\n";
1024
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1025
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
-		    $error = false;
1027
-		    //$SI::del();
1028
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
-		    // SBS format is CSV format
1030
-		    if ($buffer != '') {
1015
+			//$value = $formats[$nb];
1016
+			$format = $globalSources[$nb]['format'];
1017
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1018
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
+				} else {
1020
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
+				}
1022
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
+				//echo $buffer."\n";
1024
+			// lets play nice and handle signals such as ctrl-c/kill properly
1025
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
+			$error = false;
1027
+			//$SI::del();
1028
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
+			// SBS format is CSV format
1030
+			if ($buffer != '') {
1031 1031
 			$tt[$format] = 0;
1032 1032
 			if ($format == 'acarssbs3') {
1033
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1034
-			    $ACARS->add(trim($buffer));
1035
-			    $ACARS->deleteLiveAcarsData();
1033
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1034
+				$ACARS->add(trim($buffer));
1035
+				$ACARS->deleteLiveAcarsData();
1036 1036
 			} elseif ($format == 'raw') {
1037
-			    // AVR format
1038
-			    $data = $SBS->parse($buffer);
1039
-			    if (is_array($data)) {
1037
+				// AVR format
1038
+				$data = $SBS->parse($buffer);
1039
+				if (is_array($data)) {
1040 1040
 				$data['datetime'] = date('Y-m-d H:i:s');
1041 1041
 				$data['format_source'] = 'raw';
1042 1042
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1043
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1045
-                            }
1046
-                        } elseif ($format == 'ais') {
1047
-			    $ais_data = $AIS->parse_line(trim($buffer));
1048
-			    $data = array();
1049
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1043
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1045
+							}
1046
+						} elseif ($format == 'ais') {
1047
+				$ais_data = $AIS->parse_line(trim($buffer));
1048
+				$data = array();
1049
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1061 1061
 
1062
-			    if (isset($ais_data['timestamp'])) {
1062
+				if (isset($ais_data['timestamp'])) {
1063 1063
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1064
-			    } else {
1064
+				} else {
1065 1065
 				$data['datetime'] = date('Y-m-d H:i:s');
1066
-			    }
1067
-			    $data['format_source'] = 'aisnmea';
1068
-    			    $data['id_source'] = $id_source;
1069
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1070
-			    unset($data);
1071
-                        } elseif ($format == 'flightgearsp') {
1072
-                    	    //echo $buffer."\n";
1073
-                    	    if (strlen($buffer) > 5) {
1066
+				}
1067
+				$data['format_source'] = 'aisnmea';
1068
+					$data['id_source'] = $id_source;
1069
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1070
+				unset($data);
1071
+						} elseif ($format == 'flightgearsp') {
1072
+							//echo $buffer."\n";
1073
+							if (strlen($buffer) > 5) {
1074 1074
 				$line = explode(',',$buffer);
1075 1075
 				$data = array();
1076 1076
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1086,121 +1086,121 @@  discard block
 block discarded – undo
1086 1086
 				$data['format_source'] = 'flightgearsp';
1087 1087
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1088 1088
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1089
-			    }
1090
-                        } elseif ($format == 'acars') {
1091
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1092
-			    $ACARS->add(trim($buffer));
1093
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094
-			    $ACARS->deleteLiveAcarsData();
1089
+				}
1090
+						} elseif ($format == 'acars') {
1091
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1092
+				$ACARS->add(trim($buffer));
1093
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094
+				$ACARS->deleteLiveAcarsData();
1095 1095
 			} elseif ($format == 'flightgearmp') {
1096
-			    if (substr($buffer,0,1) != '#') {
1096
+				if (substr($buffer,0,1) != '#') {
1097 1097
 				$data = array();
1098 1098
 				//echo $buffer."\n";
1099 1099
 				$line = explode(' ',$buffer);
1100 1100
 				if (count($line) == 11) {
1101
-				    $userserver = explode('@',$line[0]);
1102
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
-				    $data['ident'] = $userserver[0];
1104
-				    $data['registration'] = $userserver[0];
1105
-				    $data['latitude'] = $line[4];
1106
-				    $data['longitude'] = $line[5];
1107
-				    $data['altitude'] = $line[6];
1108
-				    $data['datetime'] = date('Y-m-d H:i:s');
1109
-				    $aircraft_type = $line[10];
1110
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1111
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1101
+					$userserver = explode('@',$line[0]);
1102
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
+					$data['ident'] = $userserver[0];
1104
+					$data['registration'] = $userserver[0];
1105
+					$data['latitude'] = $line[4];
1106
+					$data['longitude'] = $line[5];
1107
+					$data['altitude'] = $line[6];
1108
+					$data['datetime'] = date('Y-m-d H:i:s');
1109
+					$aircraft_type = $line[10];
1110
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1111
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1113
+				}
1113 1114
 				}
1114
-			    }
1115 1115
 			} elseif ($format == 'beast') {
1116
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1117
-			    die;
1116
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1117
+				die;
1118 1118
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1119
-			    $line = explode("\t", $buffer);
1120
-			    for($k = 0; $k < count($line); $k=$k+2) {
1119
+				$line = explode("\t", $buffer);
1120
+				for($k = 0; $k < count($line); $k=$k+2) {
1121 1121
 				$key = $line[$k];
1122
-			        $lined[$key] = $line[$k+1];
1123
-			    }
1124
-    			    if (count($lined) > 3) {
1125
-    				$data['hex'] = $lined['hexid'];
1126
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1128
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1135
-    				$data['id_source'] = $id_source;
1136
-    				$data['format_source'] = 'tsv';
1137
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1140
-    				unset($lined);
1141
-    				unset($data);
1142
-    			    } else $error = true;
1122
+					$lined[$key] = $line[$k+1];
1123
+				}
1124
+					if (count($lined) > 3) {
1125
+					$data['hex'] = $lined['hexid'];
1126
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127
+					$data['datetime'] = date('Y-m-d H:i:s');;
1128
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1135
+					$data['id_source'] = $id_source;
1136
+					$data['format_source'] = 'tsv';
1137
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1140
+					unset($lined);
1141
+					unset($data);
1142
+					} else $error = true;
1143 1143
 			} elseif ($format == 'aprs' && $use_aprs) {
1144
-			    if ($aprs_connect == 0) {
1144
+				if ($aprs_connect == 0) {
1145 1145
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1146 1146
 				$aprs_connect = 1;
1147
-			    }
1147
+				}
1148 1148
 			    
1149
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1149
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1150 1150
 				$aprs_last_tx = time();
1151 1151
 				$data_aprs = "# Keep alive";
1152 1152
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1153
-			    }
1153
+				}
1154 1154
 			    
1155
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1156
-			    //echo 'APRS data : '.$buffer."\n";
1157
-			    $buffer = str_replace('APRS <- ','',$buffer);
1158
-			    $buffer = str_replace('APRS -> ','',$buffer);
1159
-			    //echo $buffer."\n";
1160
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1155
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1156
+				//echo 'APRS data : '.$buffer."\n";
1157
+				$buffer = str_replace('APRS <- ','',$buffer);
1158
+				$buffer = str_replace('APRS -> ','',$buffer);
1159
+				//echo $buffer."\n";
1160
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1161 1161
 				$line = $APRS->parse($buffer);
1162 1162
 				//print_r($line);
1163 1163
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1164 1164
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && isset($line['ident'])) {
1165
-				    $aprs_last_tx = time();
1166
-				    $data = array();
1167
-				    //print_r($line);
1168
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1169
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1171
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1172
-				    $data['ident'] = $line['ident'];
1173
-				    $data['latitude'] = $line['latitude'];
1174
-				    $data['longitude'] = $line['longitude'];
1175
-				    //$data['verticalrate'] = $line[16];
1176
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
-				    else $data['speed'] = 0;
1178
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1182
-				    //else $data['heading'] = 0;
1183
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1185
-    				    $data['id_source'] = $id_source;
1186
-				    $data['format_source'] = 'aprs';
1187
-				    $data['source_name'] = $line['source'];
1188
-				    $data['source_type'] = 'flarm';
1189
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1190
-				    $currentdate = date('Y-m-d H:i:s');
1191
-				    $aprsdate = strtotime($data['datetime']);
1192
-				    // Accept data if time <= system time + 20s
1193
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1165
+					$aprs_last_tx = time();
1166
+					$data = array();
1167
+					//print_r($line);
1168
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1169
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
+					else $data['datetime'] = date('Y-m-d H:i:s');
1171
+					//$data['datetime'] = date('Y-m-d H:i:s');
1172
+					$data['ident'] = $line['ident'];
1173
+					$data['latitude'] = $line['latitude'];
1174
+					$data['longitude'] = $line['longitude'];
1175
+					//$data['verticalrate'] = $line[16];
1176
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
+					else $data['speed'] = 0;
1178
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1182
+					//else $data['heading'] = 0;
1183
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1185
+						$data['id_source'] = $id_source;
1186
+					$data['format_source'] = 'aprs';
1187
+					$data['source_name'] = $line['source'];
1188
+					$data['source_type'] = 'flarm';
1189
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1190
+					$currentdate = date('Y-m-d H:i:s');
1191
+					$aprsdate = strtotime($data['datetime']);
1192
+					// Accept data if time <= system time + 20s
1193
+					if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1194 1194
 					$send = $SI->add($data);
1195
-				    } elseif (isset($line['stealth'])) {
1195
+					} elseif (isset($line['stealth'])) {
1196 1196
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1197 1197
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1198
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1198
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1200 1200
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1201 1201
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1202
-				    }
1203
-				    unset($data);
1202
+					}
1203
+					unset($data);
1204 1204
 				} 
1205 1205
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1206 1206
 					echo '!! Weather Station not yet supported'."\n";
@@ -1210,12 +1210,12 @@  discard block
 block discarded – undo
1210 1210
 				}
1211 1211
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1212 1212
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1213
-			    }
1213
+				}
1214 1214
 			} else {
1215
-			    $line = explode(',', $buffer);
1216
-    			    if (count($line) > 20) {
1217
-    			    	$data['hex'] = $line[4];
1218
-    				/*
1215
+				$line = explode(',', $buffer);
1216
+					if (count($line) > 20) {
1217
+						$data['hex'] = $line[4];
1218
+					/*
1219 1219
     				$data['datetime'] = $line[6].' '.$line[7];
1220 1220
     					date_default_timezone_set($globalTimezone);
1221 1221
     					$datetime = new DateTime($data['datetime']);
@@ -1223,29 +1223,29 @@  discard block
 block discarded – undo
1223 1223
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1224 1224
     					date_default_timezone_set('UTC');
1225 1225
     				*/
1226
-    				// Force datetime to current UTC datetime
1227
-    				date_default_timezone_set('UTC');
1228
-    				$data['datetime'] = date('Y-m-d H:i:s');
1229
-    				$data['ident'] = trim($line[10]);
1230
-    				$data['latitude'] = $line[14];
1231
-    				$data['longitude'] = $line[15];
1232
-    				$data['verticalrate'] = $line[16];
1233
-    				$data['emergency'] = $line[20];
1234
-    				$data['speed'] = $line[12];
1235
-    				$data['squawk'] = $line[17];
1236
-    				$data['altitude'] = $line[11];
1237
-    				$data['heading'] = $line[13];
1238
-    				$data['ground'] = $line[21];
1239
-    				$data['emergency'] = $line[19];
1240
-    				$data['format_source'] = 'sbs';
1226
+					// Force datetime to current UTC datetime
1227
+					date_default_timezone_set('UTC');
1228
+					$data['datetime'] = date('Y-m-d H:i:s');
1229
+					$data['ident'] = trim($line[10]);
1230
+					$data['latitude'] = $line[14];
1231
+					$data['longitude'] = $line[15];
1232
+					$data['verticalrate'] = $line[16];
1233
+					$data['emergency'] = $line[20];
1234
+					$data['speed'] = $line[12];
1235
+					$data['squawk'] = $line[17];
1236
+					$data['altitude'] = $line[11];
1237
+					$data['heading'] = $line[13];
1238
+					$data['ground'] = $line[21];
1239
+					$data['emergency'] = $line[19];
1240
+					$data['format_source'] = 'sbs';
1241 1241
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1242
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1243
-    				$data['id_source'] = $id_source;
1244
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
-    				else $error = true;
1246
-    				unset($data);
1247
-    			    } else $error = true;
1248
-			    if ($error) {
1242
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1243
+					$data['id_source'] = $id_source;
1244
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
+					else $error = true;
1246
+					unset($data);
1247
+					} else $error = true;
1248
+				if ($error) {
1249 1249
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1250 1250
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1251 1251
 				} else {
@@ -1261,13 +1261,13 @@  discard block
 block discarded – undo
1261 1261
 					connect_all($sourceer);
1262 1262
 					$sourceer = array();
1263 1263
 				}
1264
-			    }
1264
+				}
1265 1265
 			}
1266 1266
 			// Sleep for xxx microseconds
1267 1267
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1268
-		    } else {
1268
+			} else {
1269 1269
 			if ($format == 'flightgearmp') {
1270
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1270
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1271 1271
 				//@socket_close($r);
1272 1272
 				sleep($globalMinFetch);
1273 1273
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1276,9 +1276,9 @@  discard block
 block discarded – undo
1276 1276
 				break;
1277 1277
 				
1278 1278
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1279
-			    if (isset($tt[$format])) $tt[$format]++;
1280
-			    else $tt[$format] = 0;
1281
-			    if ($tt[$format] > 30) {
1279
+				if (isset($tt[$format])) $tt[$format]++;
1280
+				else $tt[$format] = 0;
1281
+				if ($tt[$format] > 30) {
1282 1282
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1283 1283
 				//@socket_close($r);
1284 1284
 				sleep(2);
@@ -1289,23 +1289,23 @@  discard block
 block discarded – undo
1289 1289
 				//connect_all($globalSources);
1290 1290
 				$tt[$format]=0;
1291 1291
 				break;
1292
-			    }
1292
+				}
1293
+			}
1293 1294
 			}
1294
-		    }
1295 1295
 		}
1296
-	    } else {
1296
+		} else {
1297 1297
 		$error = socket_strerror(socket_last_error());
1298 1298
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299 1299
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1300 1300
 			if (isset($globalDebug)) echo "Restarting...\n";
1301 1301
 			// Restart the script if possible
1302 1302
 			if (is_array($sockets)) {
1303
-			    if ($globalDebug) echo "Shutdown all sockets...";
1303
+				if ($globalDebug) echo "Shutdown all sockets...";
1304 1304
 			    
1305
-			    foreach ($sockets as $sock) {
1305
+				foreach ($sockets as $sock) {
1306 1306
 				@socket_shutdown($sock,2);
1307 1307
 				@socket_close($sock);
1308
-			    }
1308
+				}
1309 1309
 			    
1310 1310
 			}
1311 1311
 			if ($globalDebug) echo "Restart all connections...";
@@ -1316,13 +1316,13 @@  discard block
 block discarded – undo
1316 1316
 			if ($reset > 40) exit('Too many attempts...');
1317 1317
 			connect_all($globalSources);
1318 1318
 		}
1319
-	    }
1319
+		}
1320 1320
 	}
1321 1321
 	if ($globalDaemon === false) {
1322
-	    if ($globalDebug) echo 'Check all...'."\n";
1323
-	    $SI->checkAll();
1322
+		if ($globalDebug) echo 'Check all...'."\n";
1323
+		$SI->checkAll();
1324
+	}
1324 1325
 	}
1325
-    }
1326 1326
 }
1327 1327
 
1328 1328
 ?>
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','idsource::'));
52
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
@@ -64,27 +64,27 @@  discard block
 block discarded – undo
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66 66
     if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
67
+    $SI = new SpotterServer();
68 68
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
71 71
     $SI->connect();
72 72
 */
73
-} else $SI=new SpotterImport($Connection->db);
73
+} else $SI = new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76 76
     $AIS = new AIS();
77 77
     $MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80
-$SBS=new SBS();
81
-$ACARS=new ACARS($Connection->db);
82
-$Common=new Common();
80
+$SBS = new SBS();
81
+$ACARS = new ACARS($Connection->db);
82
+$Common = new Common();
83 83
 date_default_timezone_set('UTC');
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
87
+    pcntl_signal(SIGINT, function() {
88 88
         global $sockets;
89 89
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90 90
         die("Bye!\n");
@@ -100,35 +100,35 @@  discard block
 block discarded – undo
100 100
 
101 101
 function connect_all($hosts) {
102 102
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
103
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
104 104
     $reset++;
105 105
     if ($globalDebug) echo 'Connect to all...'."\n";
106 106
     foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
110
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
+            if (preg_match('/deltadb.txt$/i', $host)) {
112 112
         	//$formats[$id] = 'deltadbtxt';
113 113
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 114
         	//$last_exec['deltadbtxt'] = 0;
115 115
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
116
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
117 117
         	//$formats[$id] = 'vatsimtxt';
118 118
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 119
         	//$last_exec['vatsimtxt'] = 0;
120 120
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
121
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
122 122
         	//$formats[$id] = 'aircraftlistjson';
123 123
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 124
         	//$last_exec['aircraftlistjson'] = 0;
125 125
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
126
+    	    } else if (preg_match('/opensky/i', $host)) {
127 127
         	//$formats[$id] = 'aircraftlistjson';
128 128
         	$globalSources[$id]['format'] = 'opensky';
129 129
         	//$last_exec['aircraftlistjson'] = 0;
130 130
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
131
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
132 132
         	//$formats[$id] = 'radarvirtueljson';
133 133
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 134
         	//$last_exec['radarvirtueljson'] = 0;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 138
         	    exit(0);
139 139
         	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
140
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
141 141
         	//$formats[$id] = 'planeupdatefaa';
142 142
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 143
         	//$last_exec['planeupdatefaa'] = 0;
@@ -146,26 +146,26 @@  discard block
 block discarded – undo
146 146
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 147
         	    exit(0);
148 148
         	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
149
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
150 150
         	//$formats[$id] = 'phpvmacars';
151 151
         	$globalSources[$id]['format'] = 'phpvmacars';
152 152
         	//$last_exec['phpvmacars'] = 0;
153 153
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
154
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
155 155
         	//$formats[$id] = 'phpvmacars';
156 156
         	$globalSources[$id]['format'] = 'vam';
157 157
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
158
+            } else if (preg_match('/whazzup/i', $host)) {
159 159
         	//$formats[$id] = 'whazzup';
160 160
         	$globalSources[$id]['format'] = 'whazzup';
161 161
         	//$last_exec['whazzup'] = 0;
162 162
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
163
+            } else if (preg_match('/recentpireps/i', $host)) {
164 164
         	//$formats[$id] = 'pirepsjson';
165 165
         	$globalSources[$id]['format'] = 'pirepsjson';
166 166
         	//$last_exec['pirepsjson'] = 0;
167 167
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
168
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
169 169
         	//$formats[$id] = 'fr24json';
170 170
         	$globalSources[$id]['format'] = 'fr24json';
171 171
         	//$last_exec['fr24json'] = 0;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 175
         	    exit(0);
176 176
         	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
177
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
178 178
         	//$formats[$id] = 'fr24json';
179 179
         	$globalSources[$id]['format'] = 'myshiptracking';
180 180
         	//$last_exec['fr24json'] = 0;
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
         	    exit(0);
185 185
         	}
186 186
             //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
187
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 188
         	//$formats[$id] = 'tsv';
189 189
         	$globalSources[$id]['format'] = 'tsv';
190 190
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191 191
             }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
192
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
193 193
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
194
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
195 195
     		    if ($idf !== false) {
196 196
     			$httpfeeds[$id] = $idf;
197 197
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198 198
     		    }
199 199
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200 200
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
201
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
202
+	    $hostport = explode(':', $host);
203 203
 	    if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
 	    }
210 210
 	    $Common = new Common();
211 211
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
212
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
213 213
     	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
214
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
215 215
 	    }
216 216
 	    if ($s) {
217 217
     	        $sockets[$id] = $s;
218 218
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
219
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259 259
 else $timeout = 20;
260 260
 $errno = '';
261
-$errstr='';
261
+$errstr = '';
262 262
 
263 263
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
264 264
 /* Initiate connections to all the hosts simultaneously */
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
270 270
 } else {
271 271
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
 
294 294
 if ($use_aprs) {
295 295
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
296
-	$APRS=new APRS();
296
+	$APRS = new APRS();
297 297
 	$aprs_connect = 0;
298 298
 	$aprs_keep = 120;
299 299
 	$aprs_last_tx = time();
300 300
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
301
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
302 302
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
303
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
304 304
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
305
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306 306
 	if ($aprs_full) $aprs_filter = '';
307 307
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308 308
 	else $aprs_pass = '-1';
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 sleep(1);
317 317
 if ($globalDebug) echo "SCAN MODE \n\n";
318 318
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
319
-$endtime = time()+$globalCronEnd;
319
+$endtime = time() + $globalCronEnd;
320 320
 $i = 1;
321 321
 $tt = array();
322 322
 // Delete all ATC
323 323
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
324
-	$ATC=new ATC($Connection->db);
324
+	$ATC = new ATC($Connection->db);
325 325
 }
326 326
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
327 327
 	$ATC->deleteAll();
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 
330 330
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
331 331
 while ($i > 0) {
332
-    if (!$globalDaemon) $i = $endtime-time();
332
+    if (!$globalDaemon) $i = $endtime - time();
333 333
     // Delete old ATC
334 334
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
335 335
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	}
345 345
 	if ($max != $globalMinFetch) {
346 346
 	    if ($globalDebug) echo 'Sleeping...'."\n";
347
-	    sleep($globalMinFetch-$max+2);
347
+	    sleep($globalMinFetch - $max + 2);
348 348
 	}
349 349
     }
350 350
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 	    //$buffer = $Common->getData($hosts[$id]);
358 358
 	    $buffer = $Common->getData($value['host']);
359 359
 	    if ($buffer != '') $reset = 0;
360
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361
-	    $buffer = explode('\n',$buffer);
360
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
361
+	    $buffer = explode('\n', $buffer);
362 362
 	    foreach ($buffer as $line) {
363 363
     		if ($line != '' && count($line) > 7) {
364 364
     		    $line = explode(',', $line);
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
     	    $last_exec[$id]['last'] = time();
386 386
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
387 387
 	    date_default_timezone_set('CET');
388
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
388
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
389 389
 	    date_default_timezone_set('UTC');
390 390
 	    if ($buffer != '') $reset = 0;
391
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392
-	    $buffer = explode('\n',$buffer);
391
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
392
+	    $buffer = explode('\n', $buffer);
393 393
 	    foreach ($buffer as $line) {
394 394
 		if ($line != '') {
395 395
 		    echo "'".$line."'\n";
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408 408
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
409 409
 		    if (isset($ais_data['timestamp'])) {
410
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
410
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
411 411
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
412 412
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
413 413
 			    $add = true;
@@ -430,12 +430,12 @@  discard block
 block discarded – undo
430 430
 	    $w = $e = null;
431 431
 	    
432 432
 	    if (isset($arr[$id])) {
433
-	    $nn = stream_select($arr,$w,$e,$timeout);
433
+	    $nn = stream_select($arr, $w, $e, $timeout);
434 434
 	    if ($nn > 0) {
435 435
 		foreach ($httpfeeds as $feed) {
436
-		    $buffer = stream_get_line($feed,2000,"\n");
437
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
438
-		    $buffer = explode('\n',$buffer);
436
+		    $buffer = stream_get_line($feed, 2000, "\n");
437
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
438
+		    $buffer = explode('\n', $buffer);
439 439
 		    foreach ($buffer as $line) {
440 440
 			if ($line != '') {
441 441
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452 452
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453 453
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
454
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
455 455
 			    if (isset($ais_data['timestamp'])) {
456
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
456
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
457 457
 			    } else {
458 458
 				$data['datetime'] = date('Y-m-d H:i:s');
459 459
 			    }
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
 		}
468 468
 	    }
469 469
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
470
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
470
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
471 471
 	    if ($buffer != '') {
472 472
 		//echo $buffer;
473
-		$all_data = json_decode($buffer,true);
473
+		$all_data = json_decode($buffer, true);
474 474
 		//print_r($all_data);
475 475
 		if (isset($all_data[0]['DATA'])) {
476 476
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
486 486
 			$data['imo'] = $line['IMO'];
487 487
 			//$data['arrival_code'] = $ais_data['destination'];
488
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
488
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
489 489
 			$data['format_source'] = 'myshiptracking';
490 490
 			$data['id_source'] = $id_source;
491 491
 			$MI->add($data);
@@ -498,11 +498,11 @@  discard block
 block discarded – undo
498 498
     	    $last_exec[$id]['last'] = time();
499 499
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
500 500
 	    echo 'Try ?'."\n";
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
501
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
502 502
 	    echo $buffer;
503 503
 	    if ($buffer != '') {
504 504
 		//echo $buffer;
505
-		$all_data = json_decode($buffer,true);
505
+		$all_data = json_decode($buffer, true);
506 506
 		print_r($all_data);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508 508
 		foreach ($all_data as $line) {
@@ -530,27 +530,27 @@  discard block
 block discarded – undo
530 530
     	    $last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532 532
 	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
533
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
534 534
 	    echo 'done !'."\n";
535 535
 	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
536
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+	    $buffer = explode('\n', $buffer);
538 538
 	    foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540 540
 		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
541
+		    $data['mmsi'] = (int) substr($line, 0, 9);
542
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
543 543
 		    //$data['status'] = substr($line,21,2);
544 544
 		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
545
+		    $data['latitude'] = substr($line, 29, 9);
546
+		    $data['longitude'] = substr($line, 41, 9);
547
+		    $data['speed'] = round(substr($line, 51, 5));
548 548
 		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
549
+		    $data['heading'] = round(substr($line, 63, 3));
550 550
 		    //$data['draft'] = substr($line,67,4);
551 551
 		    //$data['length'] = substr($line,72,3);
552 552
 		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
553
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
554 554
 		    //$data['callsign'] = trim(substr($line,100,7);
555 555
 		    //$data['dest'] = substr($line,108,20);
556 556
 		    //$data['etaDate'] = substr($line,129,5);
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569 569
 	    //$buffer = $Common->getData($hosts[$id]);
570 570
 	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
571
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
572
+	    $buffer = explode('\n', $buffer);
573 573
 	    $reset = 0;
574 574
 	    foreach ($buffer as $line) {
575 575
     		if ($line != '') {
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
581 581
 			$data['pilot_id'] = $line[1];
582 582
 			$data['pilot_name'] = $line[2];
583
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
583
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
584 584
 			$data['ident'] = $line[0]; // ident
585 585
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
586 586
 			$data['speed'] = $line[8]; // speed
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598 598
 		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
599
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
600 600
 		        $data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
     			$data['id_source'] = $id_source;
606 606
 	    		//$data['arrival_airport_time'] = ;
607 607
 	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
608
+	    		    $aircraft_data = explode('/', $line[9]);
609 609
 	    		    if (isset($aircraft_data[1])) {
610 610
 	    			$data['aircraft_icao'] = $aircraft_data[1];
611 611
 	    		    }
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
     			if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624
-				$typec = substr($data['ident'],-3);
622
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
623
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
624
+				$typec = substr($data['ident'], -3);
625 625
 				if ($typec == 'APP') $data['type'] = 'Approach';
626 626
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627 627
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633 633
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
635
+				if (isset($ATC)) echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
636 636
 			}
637 637
     			unset($data);
638 638
     		    }
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
     	    $last_exec[$id]['last'] = time();
644 644
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645 645
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
646
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
647 647
 	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
648
+	    $all_data = json_decode($buffer, true);
649 649
 	    if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702 702
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703 703
 	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
704
+	    $all_data = json_decode($buffer, true);
705 705
 	    if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
@@ -718,12 +718,12 @@  discard block
 block discarded – undo
718 718
 		    $data['emergency'] = ''; // emergency
719 719
 		    $data['registration'] = $line[2];
720 720
 		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
721
+		    $deparr = explode('-', $line[1]);
722 722
 		    if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725 725
 		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
726
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
727 727
 	    	    $data['format_source'] = 'planeupdatefaa';
728 728
     		    $data['id_source'] = $id_source;
729 729
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
     	    $last_exec[$id]['last'] = time();
736 736
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737 737
 	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
738
+	    $all_data = json_decode($buffer, true);
739 739
 	    if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		    //$data['emergency'] = ''; // emergency
753 753
 		    //$data['registration'] = $line[2];
754 754
 		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
755
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
756 756
 	    	    $data['format_source'] = 'opensky';
757 757
     		    $data['id_source'] = $id_source;
758 758
 		    $SI->add($data);
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766 766
 	    //$buffer = $Common->getData($hosts[$id]);
767 767
 	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
768
+	    $all_data = json_decode($buffer, true);
769 769
 	    if (!empty($all_data)) $reset = 0;
770 770
 	    foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -797,11 +797,11 @@  discard block
 block discarded – undo
797 797
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798 798
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799 799
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
800
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
801 801
 	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
802
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
803
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
804
+	    $all_data = json_decode($buffer, true);
805 805
 	    if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807 807
 	    }
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826 826
 	    		//$data['emergency'] = ''; // emergency
827
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
827
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
828 828
 	    		$data['format_source'] = 'radarvirtueljson';
829 829
     			$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -839,14 +839,14 @@  discard block
 block discarded – undo
839 839
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840 840
 	    //$buffer = $Common->getData($hosts[$id]);
841 841
 	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
842
+	    $all_data = json_decode(utf8_encode($buffer), true);
843 843
 	    
844 844
 	    if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846 846
 	        foreach ($all_data['pireps'] as $line) {
847 847
 		    $data = array();
848 848
 		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
849
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
850 850
 		    $data['ident'] = $line['callsign']; // ident
851 851
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852 852
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -875,9 +875,9 @@  discard block
 block discarded – undo
875 875
 			$SI->add($data);
876 876
 		    //    print_r($data);
877 877
     		    } elseif ($line['icon'] == 'ct') {
878
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880
-			$typec = substr($data['ident'],-3);
878
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
879
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
880
+			$typec = substr($data['ident'], -3);
881 881
 			$data['type'] = '';
882 882
 			if ($typec == 'APP') $data['type'] = 'Approach';
883 883
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
891
+			if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']);
892 892
 		    }
893 893
 		    unset($data);
894 894
 		}
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
 	    //$buffer = $Common->getData($hosts[$id]);
901 901
 	    if ($globalDebug) echo 'Get Data...'."\n";
902 902
 	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
903
+	    $all_data = json_decode($buffer, true);
904 904
 	    if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907 907
 	    	    $data = array();
908 908
 	    	    //$data['id'] = $line['id']; // id not usable
909 909
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
910
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
911 911
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912 912
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913 913
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -930,12 +930,12 @@  discard block
 block discarded – undo
930 930
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931 931
 		    if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
933
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
934
+	    		$aircraft_data = explode('-', $line['aircraftname']);
935 935
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936 936
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937 937
 	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
938
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
939 939
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940 940
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941 941
 	    		}
@@ -957,14 +957,14 @@  discard block
 block discarded – undo
957 957
 	    //$buffer = $Common->getData($hosts[$id]);
958 958
 	    if ($globalDebug) echo 'Get Data...'."\n";
959 959
 	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
960
+	    $all_data = json_decode($buffer, true);
961 961
 	    if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964 964
 	    	    $data = array();
965 965
 	    	    //$data['id'] = $line['id']; // id not usable
966 966
 	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
967
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
968 968
 	    	    $data['pilot_name'] = $line['pilot_name'];
969 969
 	    	    $data['pilot_id'] = $line['pilot_id'];
970 970
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1015,9 +1015,9 @@  discard block
 block discarded – undo
1015 1015
 		    //$value = $formats[$nb];
1016 1016
 		    $format = $globalSources[$nb]['format'];
1017 1017
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1018
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1019 1019
         	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1020
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1021 1021
 	    	    }
1022 1022
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023 1023
         	    //echo $buffer."\n";
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026 1026
 		    $error = false;
1027 1027
 		    //$SI::del();
1028
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1028
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1029 1029
 		    // SBS format is CSV format
1030 1030
 		    if ($buffer != '') {
1031 1031
 			$tt[$format] = 0;
@@ -1057,10 +1057,10 @@  discard block
 block discarded – undo
1057 1057
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058 1058
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059 1059
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1060
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1061 1061
 
1062 1062
 			    if (isset($ais_data['timestamp'])) {
1063
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1063
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1064 1064
 			    } else {
1065 1065
 				$data['datetime'] = date('Y-m-d H:i:s');
1066 1066
 			    }
@@ -1071,10 +1071,10 @@  discard block
 block discarded – undo
1071 1071
                         } elseif ($format == 'flightgearsp') {
1072 1072
                     	    //echo $buffer."\n";
1073 1073
                     	    if (strlen($buffer) > 5) {
1074
-				$line = explode(',',$buffer);
1074
+				$line = explode(',', $buffer);
1075 1075
 				$data = array();
1076 1076
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1077
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1077
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1078 1078
 				$data['ident'] = $line[6];
1079 1079
 				$data['aircraft_name'] = $line[7];
1080 1080
 				$data['longitude'] = $line[1];
@@ -1085,21 +1085,21 @@  discard block
 block discarded – undo
1085 1085
 				$data['datetime'] = date('Y-m-d H:i:s');
1086 1086
 				$data['format_source'] = 'flightgearsp';
1087 1087
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1088
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1088
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1089 1089
 			    }
1090 1090
                         } elseif ($format == 'acars') {
1091 1091
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1092 1092
 			    $ACARS->add(trim($buffer));
1093
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1093
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1094 1094
 			    $ACARS->deleteLiveAcarsData();
1095 1095
 			} elseif ($format == 'flightgearmp') {
1096
-			    if (substr($buffer,0,1) != '#') {
1096
+			    if (substr($buffer, 0, 1) != '#') {
1097 1097
 				$data = array();
1098 1098
 				//echo $buffer."\n";
1099
-				$line = explode(' ',$buffer);
1099
+				$line = explode(' ', $buffer);
1100 1100
 				if (count($line) == 11) {
1101
-				    $userserver = explode('@',$line[0]);
1102
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1101
+				    $userserver = explode('@', $line[0]);
1102
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1103 1103
 				    $data['ident'] = $userserver[0];
1104 1104
 				    $data['registration'] = $userserver[0];
1105 1105
 				    $data['latitude'] = $line[4];
@@ -1107,24 +1107,24 @@  discard block
 block discarded – undo
1107 1107
 				    $data['altitude'] = $line[6];
1108 1108
 				    $data['datetime'] = date('Y-m-d H:i:s');
1109 1109
 				    $aircraft_type = $line[10];
1110
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1111
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1110
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1111
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1112 1112
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1113 1113
 				}
1114 1114
 			    }
1115 1115
 			} elseif ($format == 'beast') {
1116 1116
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1117 1117
 			    die;
1118
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1118
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1119 1119
 			    $line = explode("\t", $buffer);
1120
-			    for($k = 0; $k < count($line); $k=$k+2) {
1120
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1121 1121
 				$key = $line[$k];
1122
-			        $lined[$key] = $line[$k+1];
1122
+			        $lined[$key] = $line[$k + 1];
1123 1123
 			    }
1124 1124
     			    if (count($lined) > 3) {
1125 1125
     				$data['hex'] = $lined['hexid'];
1126 1126
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1127
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1128 1128
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129 1129
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130 1130
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1142,22 +1142,22 @@  discard block
 block discarded – undo
1142 1142
     			    } else $error = true;
1143 1143
 			} elseif ($format == 'aprs' && $use_aprs) {
1144 1144
 			    if ($aprs_connect == 0) {
1145
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1145
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1146 1146
 				$aprs_connect = 1;
1147 1147
 			    }
1148 1148
 			    
1149
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1149
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1150 1150
 				$aprs_last_tx = time();
1151 1151
 				$data_aprs = "# Keep alive";
1152
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1152
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1153 1153
 			    }
1154 1154
 			    
1155 1155
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1156 1156
 			    //echo 'APRS data : '.$buffer."\n";
1157
-			    $buffer = str_replace('APRS <- ','',$buffer);
1158
-			    $buffer = str_replace('APRS -> ','',$buffer);
1157
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1158
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1159 1159
 			    //echo $buffer."\n";
1160
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1160
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1161 1161
 				$line = $APRS->parse($buffer);
1162 1162
 				//print_r($line);
1163 1163
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 				    $data = array();
1167 1167
 				    //print_r($line);
1168 1168
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1169
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1169
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1170 1170
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1171 1171
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1172 1172
 				    $data['ident'] = $line['ident'];
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 				    $currentdate = date('Y-m-d H:i:s');
1191 1191
 				    $aprsdate = strtotime($data['datetime']);
1192 1192
 				    // Accept data if time <= system time + 20s
1193
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1193
+				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1194 1194
 					$send = $SI->add($data);
1195 1195
 				    } elseif (isset($line['stealth'])) {
1196 1196
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 				connect_all($sourceee);
1288 1288
 				$sourceee = array();
1289 1289
 				//connect_all($globalSources);
1290
-				$tt[$format]=0;
1290
+				$tt[$format] = 0;
1291 1291
 				break;
1292 1292
 			    }
1293 1293
 			}
@@ -1296,14 +1296,14 @@  discard block
 block discarded – undo
1296 1296
 	    } else {
1297 1297
 		$error = socket_strerror(socket_last_error());
1298 1298
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1300 1300
 			if (isset($globalDebug)) echo "Restarting...\n";
1301 1301
 			// Restart the script if possible
1302 1302
 			if (is_array($sockets)) {
1303 1303
 			    if ($globalDebug) echo "Shutdown all sockets...";
1304 1304
 			    
1305 1305
 			    foreach ($sockets as $sock) {
1306
-				@socket_shutdown($sock,2);
1306
+				@socket_shutdown($sock, 2);
1307 1307
 				@socket_close($sock);
1308 1308
 			    }
1309 1309
 			    
Please login to merge, or discard this patch.
Braces   +707 added lines, -244 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,19 +63,30 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68 79
 /*
69 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 81
     $SI = new adsb2aprs();
71 82
     $SI->connect();
72 83
 */
73
-} else $SI=new SpotterImport($Connection->db);
74
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
84
+} else {
85
+	$SI=new SpotterImport($Connection->db);
86
+}
87
+if (isset($globalTracker) && $globalTracker) {
88
+	$TI = new TrackerImport($Connection->db);
89
+}
75 90
 if (isset($globalMarine) && $globalMarine) {
76 91
     $AIS = new AIS();
77 92
     $MI = new MarineImport($Connection->db);
@@ -93,7 +108,9 @@  discard block
 block discarded – undo
93 108
 }
94 109
 
95 110
 // let's try and connect
96
-if ($globalDebug) echo "Connecting...\n";
111
+if ($globalDebug) {
112
+	echo "Connecting...\n";
113
+}
97 114
 $use_aprs = false;
98 115
 $aprs_full = false;
99 116
 $reset = 0;
@@ -102,7 +119,9 @@  discard block
 block discarded – undo
102 119
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103 120
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104 121
     $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
122
+    if ($globalDebug) {
123
+    	echo 'Connect to all...'."\n";
124
+    }
106 125
     foreach ($hosts as $id => $value) {
107 126
 	$host = $value['host'];
108 127
 	$globalSources[$id]['last_exec'] = 0;
@@ -112,27 +131,37 @@  discard block
 block discarded – undo
112 131
         	//$formats[$id] = 'deltadbtxt';
113 132
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 133
         	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
134
+        	if ($globalDebug) {
135
+        		echo "Connect to deltadb source (".$host.")...\n";
136
+        	}
116 137
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117 138
         	//$formats[$id] = 'vatsimtxt';
118 139
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 140
         	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
141
+        	if ($globalDebug) {
142
+        		echo "Connect to vatsim source (".$host.")...\n";
143
+        	}
121 144
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122 145
         	//$formats[$id] = 'aircraftlistjson';
123 146
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 147
         	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
148
+        	if ($globalDebug) {
149
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
150
+        	}
126 151
     	    } else if (preg_match('/opensky/i',$host)) {
127 152
         	//$formats[$id] = 'aircraftlistjson';
128 153
         	$globalSources[$id]['format'] = 'opensky';
129 154
         	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
155
+        	if ($globalDebug) {
156
+        		echo "Connect to opensky source (".$host.")...\n";
157
+        	}
131 158
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132 159
         	//$formats[$id] = 'radarvirtueljson';
133 160
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 161
         	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
162
+        	if ($globalDebug) {
163
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
164
+        	}
136 165
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137 166
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 167
         	    exit(0);
@@ -141,7 +170,9 @@  discard block
 block discarded – undo
141 170
         	//$formats[$id] = 'planeupdatefaa';
142 171
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 172
         	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
175
+        	}
145 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 178
         	    exit(0);
@@ -150,26 +181,36 @@  discard block
 block discarded – undo
150 181
         	//$formats[$id] = 'phpvmacars';
151 182
         	$globalSources[$id]['format'] = 'phpvmacars';
152 183
         	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to phpvmacars source (".$host.")...\n";
186
+        	}
154 187
             } else if (preg_match('/VAM-json.php$/i',$host)) {
155 188
         	//$formats[$id] = 'phpvmacars';
156 189
         	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
190
+        	if ($globalDebug) {
191
+        		echo "Connect to Vam source (".$host.")...\n";
192
+        	}
158 193
             } else if (preg_match('/whazzup/i',$host)) {
159 194
         	//$formats[$id] = 'whazzup';
160 195
         	$globalSources[$id]['format'] = 'whazzup';
161 196
         	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
197
+        	if ($globalDebug) {
198
+        		echo "Connect to whazzup source (".$host.")...\n";
199
+        	}
163 200
             } else if (preg_match('/recentpireps/i',$host)) {
164 201
         	//$formats[$id] = 'pirepsjson';
165 202
         	$globalSources[$id]['format'] = 'pirepsjson';
166 203
         	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
204
+        	if ($globalDebug) {
205
+        		echo "Connect to pirepsjson source (".$host.")...\n";
206
+        	}
168 207
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169 208
         	//$formats[$id] = 'fr24json';
170 209
         	$globalSources[$id]['format'] = 'fr24json';
171 210
         	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to fr24 source (".$host.")...\n";
213
+        	}
173 214
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174 215
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 216
         	    exit(0);
@@ -178,7 +219,9 @@  discard block
 block discarded – undo
178 219
         	//$formats[$id] = 'fr24json';
179 220
         	$globalSources[$id]['format'] = 'myshiptracking';
180 221
         	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to myshiptracking source (".$host.")...\n";
224
+        	}
182 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184 227
         	    exit(0);
@@ -187,17 +230,24 @@  discard block
 block discarded – undo
187 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 231
         	//$formats[$id] = 'tsv';
189 232
         	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
191 236
             }
192 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193 238
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194 239
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195 240
     		    if ($idf !== false) {
196 241
     			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
242
+        		if ($globalDebug) {
243
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
244
+        		}
245
+    		    } elseif ($globalDebug) {
246
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
198 247
     		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
248
+    		} elseif ($globalDebug) {
249
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
250
+    		}
201 251
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202 252
 	    $hostport = explode(':',$host);
203 253
 	    if (isset($hostport[1])) {
@@ -235,17 +285,25 @@  discard block
 block discarded – undo
235 285
         		//$formats[$id] = 'beast';
236 286
         		$globalSources[$id]['format'] = 'beast';
237 287
 		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
288
+		    } else {
289
+		    	$globalSources[$id]['format'] = 'sbs';
290
+		    }
239 291
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 292
 		}
241
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
293
+		if ($globalDebug) {
294
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
295
+		}
242 296
             } else {
243
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
297
+		if ($globalDebug) {
298
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
299
+		}
244 300
     	    }
245 301
         }
246 302
     }
247 303
 }
248
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
304
+if (!isset($globalMinFetch)) {
305
+	$globalMinFetch = 15;
306
+}
249 307
 
250 308
 // Initialize all
251 309
 $status = array();
@@ -254,13 +312,19 @@  discard block
 block discarded – undo
254 312
 $formats = array();
255 313
 $last_exec = array();
256 314
 $time = time();
257
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
258
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259
-else $timeout = 20;
315
+if (isset($globalSourcesTimeout)) {
316
+	$timeout = $globalSourcesTimeOut;
317
+} else if (isset($globalSBS1TimeOut)) {
318
+	$timeout = $globalSBS1TimeOut;
319
+} else {
320
+	$timeout = 20;
321
+}
260 322
 $errno = '';
261 323
 $errstr='';
262 324
 
263
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
325
+if (!isset($globalDaemon)) {
326
+	$globalDaemon = TRUE;
327
+}
264 328
 /* Initiate connections to all the hosts simultaneously */
265 329
 //connect_all($hosts);
266 330
 //connect_all($globalSources);
@@ -286,7 +350,9 @@  discard block
 block discarded – undo
286 350
     if (isset($source['format']) && $source['format'] == 'aprs') {
287 351
 	$aprs_connect = 0;
288 352
 	$use_aprs = true;
289
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
353
+	if (isset($source['port']) && $source['port'] == '10152') {
354
+		$aprs_full = true;
355
+	}
290 356
 	break;
291 357
     }
292 358
 }
@@ -297,25 +363,48 @@  discard block
 block discarded – undo
297 363
 	$aprs_connect = 0;
298 364
 	$aprs_keep = 120;
299 365
 	$aprs_last_tx = time();
300
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
302
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
304
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306
-	if ($aprs_full) $aprs_filter = '';
307
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308
-	else $aprs_pass = '-1';
366
+	if (isset($globalAPRSversion)) {
367
+		$aprs_version = $globalAPRSversion;
368
+	} else {
369
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
+	}
371
+	if (isset($globalAPRSssid)) {
372
+		$aprs_ssid = $globalAPRSssid;
373
+	} else {
374
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
375
+	}
376
+	if (isset($globalAPRSfilter)) {
377
+		$aprs_filter = $globalAPRSfilter;
378
+	} else {
379
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
380
+	}
381
+	if ($aprs_full) {
382
+		$aprs_filter = '';
383
+	}
384
+	if (isset($globalAPRSpass)) {
385
+		$aprs_pass = $globalAPRSpass;
386
+	} else {
387
+		$aprs_pass = '-1';
388
+	}
309 389
 
310
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
311
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
312
-}
390
+	if ($aprs_filter != '') {
391
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
+	} else {
393
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
394
+	}
395
+	}
313 396
 
314 397
 // connected - lets do some work
315
-if ($globalDebug) echo "Connected!\n";
398
+if ($globalDebug) {
399
+	echo "Connected!\n";
400
+}
316 401
 sleep(1);
317
-if ($globalDebug) echo "SCAN MODE \n\n";
318
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
402
+if ($globalDebug) {
403
+	echo "SCAN MODE \n\n";
404
+}
405
+if (!isset($globalCronEnd)) {
406
+	$globalCronEnd = 60;
407
+}
319 408
 $endtime = time()+$globalCronEnd;
320 409
 $i = 1;
321 410
 $tt = array();
@@ -329,10 +418,14 @@  discard block
 block discarded – undo
329 418
 
330 419
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
331 420
 while ($i > 0) {
332
-    if (!$globalDaemon) $i = $endtime-time();
421
+    if (!$globalDaemon) {
422
+    	$i = $endtime-time();
423
+    }
333 424
     // Delete old ATC
334 425
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
335
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
426
+	if ($globalDebug) {
427
+		echo 'Delete old ATC...'."\n";
428
+	}
336 429
         $ATC->deleteOldATC();
337 430
     }
338 431
     
@@ -340,10 +433,14 @@  discard block
 block discarded – undo
340 433
     if (count($last_exec) == count($globalSources)) {
341 434
 	$max = $globalMinFetch;
342 435
 	foreach ($last_exec as $last) {
343
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
436
+	    if ((time() - $last['last']) < $max) {
437
+	    	$max = time() - $last['last'];
438
+	    }
344 439
 	}
345 440
 	if ($max != $globalMinFetch) {
346
-	    if ($globalDebug) echo 'Sleeping...'."\n";
441
+	    if ($globalDebug) {
442
+	    	echo 'Sleeping...'."\n";
443
+	    }
347 444
 	    sleep($globalMinFetch-$max+2);
348 445
 	}
349 446
     }
@@ -352,11 +449,15 @@  discard block
 block discarded – undo
352 449
     //foreach ($formats as $id => $value) {
353 450
     foreach ($globalSources as $id => $value) {
354 451
 	date_default_timezone_set('UTC');
355
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452
+	if (!isset($last_exec[$id]['last'])) {
453
+		$last_exec[$id]['last'] = 0;
454
+	}
356 455
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
357 456
 	    //$buffer = $Common->getData($hosts[$id]);
358 457
 	    $buffer = $Common->getData($value['host']);
359
-	    if ($buffer != '') $reset = 0;
458
+	    if ($buffer != '') {
459
+	    	$reset = 0;
460
+	    }
360 461
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361 462
 	    $buffer = explode('\n',$buffer);
362 463
 	    foreach ($buffer as $line) {
@@ -365,19 +466,38 @@  discard block
 block discarded – undo
365 466
 	            $data = array();
366 467
 	            $data['hex'] = $line[1]; // hex
367 468
 	            $data['ident'] = $line[2]; // ident
368
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
469
+	            if (isset($line[3])) {
470
+	            	$data['altitude'] = $line[3];
471
+	            }
472
+	            // altitude
473
+	            if (isset($line[4])) {
474
+	            	$data['speed'] = $line[4];
475
+	            }
476
+	            // speed
477
+	            if (isset($line[5])) {
478
+	            	$data['heading'] = $line[5];
479
+	            }
480
+	            // heading
481
+	            if (isset($line[6])) {
482
+	            	$data['latitude'] = $line[6];
483
+	            }
484
+	            // lat
485
+	            if (isset($line[7])) {
486
+	            	$data['longitude'] = $line[7];
487
+	            }
488
+	            // long
373 489
 	            $data['verticalrate'] = ''; // vertical rate
374 490
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375 491
 	            $data['emergency'] = ''; // emergency
376 492
 		    $data['datetime'] = date('Y-m-d H:i:s');
377 493
 		    $data['format_source'] = 'deltadbtxt';
378 494
     		    $data['id_source'] = $id_source;
379
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
495
+		    if (isset($value['name']) && $value['name'] != '') {
496
+		    	$data['source_name'] = $value['name'];
497
+		    }
498
+		    if (isset($value['sourcestats'])) {
499
+		    	$data['sourcestats'] = $value['sourcestats'];
500
+		    }
381 501
     		    $SI->add($data);
382 502
 		    unset($data);
383 503
     		}
@@ -387,7 +507,9 @@  discard block
 block discarded – undo
387 507
 	    date_default_timezone_set('CET');
388 508
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389 509
 	    date_default_timezone_set('UTC');
390
-	    if ($buffer != '') $reset = 0;
510
+	    if ($buffer != '') {
511
+	    	$reset = 0;
512
+	    }
391 513
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392 514
 	    $buffer = explode('\n',$buffer);
393 515
 	    foreach ($buffer as $line) {
@@ -396,16 +518,36 @@  discard block
 block discarded – undo
396 518
 		    $add = false;
397 519
 		    $ais_data = $AIS->parse_line(trim($line));
398 520
 		    $data = array();
399
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
521
+		    if (isset($ais_data['ident'])) {
522
+		    	$data['ident'] = $ais_data['ident'];
523
+		    }
524
+		    if (isset($ais_data['mmsi'])) {
525
+		    	$data['mmsi'] = $ais_data['mmsi'];
526
+		    }
527
+		    if (isset($ais_data['speed'])) {
528
+		    	$data['speed'] = $ais_data['speed'];
529
+		    }
530
+		    if (isset($ais_data['heading'])) {
531
+		    	$data['heading'] = $ais_data['heading'];
532
+		    }
533
+		    if (isset($ais_data['latitude'])) {
534
+		    	$data['latitude'] = $ais_data['latitude'];
535
+		    }
536
+		    if (isset($ais_data['longitude'])) {
537
+		    	$data['longitude'] = $ais_data['longitude'];
538
+		    }
539
+		    if (isset($ais_data['status'])) {
540
+		    	$data['status'] = $ais_data['status'];
541
+		    }
542
+		    if (isset($ais_data['type'])) {
543
+		    	$data['type'] = $ais_data['type'];
544
+		    }
545
+		    if (isset($ais_data['imo'])) {
546
+		    	$data['imo'] = $ais_data['imo'];
547
+		    }
548
+		    if (isset($ais_data['callsign'])) {
549
+		    	$data['callsign'] = $ais_data['callsign'];
550
+		    }
409 551
 		    if (isset($ais_data['timestamp'])) {
410 552
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
411 553
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -420,7 +562,9 @@  discard block
 block discarded – undo
420 562
     		    $data['id_source'] = $id_source;
421 563
 		    print_r($data);
422 564
 		    echo 'Add...'."\n";
423
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
565
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
566
+		    	$MI->add($data);
567
+		    }
424 568
 		    unset($data);
425 569
 		}
426 570
     	    }
@@ -440,18 +584,42 @@  discard block
 block discarded – undo
440 584
 			if ($line != '') {
441 585
 			    $ais_data = $AIS->parse_line(trim($line));
442 586
 			    $data = array();
443
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
587
+			    if (isset($ais_data['ident'])) {
588
+			    	$data['ident'] = $ais_data['ident'];
589
+			    }
590
+			    if (isset($ais_data['mmsi'])) {
591
+			    	$data['mmsi'] = $ais_data['mmsi'];
592
+			    }
593
+			    if (isset($ais_data['speed'])) {
594
+			    	$data['speed'] = $ais_data['speed'];
595
+			    }
596
+			    if (isset($ais_data['heading'])) {
597
+			    	$data['heading'] = $ais_data['heading'];
598
+			    }
599
+			    if (isset($ais_data['latitude'])) {
600
+			    	$data['latitude'] = $ais_data['latitude'];
601
+			    }
602
+			    if (isset($ais_data['longitude'])) {
603
+			    	$data['longitude'] = $ais_data['longitude'];
604
+			    }
605
+			    if (isset($ais_data['status'])) {
606
+			    	$data['status'] = $ais_data['status'];
607
+			    }
608
+			    if (isset($ais_data['type'])) {
609
+			    	$data['type'] = $ais_data['type'];
610
+			    }
611
+			    if (isset($ais_data['imo'])) {
612
+			    	$data['imo'] = $ais_data['imo'];
613
+			    }
614
+			    if (isset($ais_data['callsign'])) {
615
+			    	$data['callsign'] = $ais_data['callsign'];
616
+			    }
617
+			    if (isset($ais_data['destination'])) {
618
+			    	$data['arrival_code'] = $ais_data['destination'];
619
+			    }
620
+			    if (isset($ais_data['eta_ts'])) {
621
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
622
+			    }
455 623
 			    if (isset($ais_data['timestamp'])) {
456 624
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
457 625
 			    } else {
@@ -459,7 +627,9 @@  discard block
 block discarded – undo
459 627
 			    }
460 628
 			    $data['format_source'] = 'aisnmeahttp';
461 629
 			    $data['id_source'] = $id_source;
462
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
630
+			    if ($ais_data['mmsi_type'] == 'Ship') {
631
+			    	$MI->add($data);
632
+			    }
463 633
 			    unset($data);
464 634
 			}
465 635
 		    }
@@ -512,7 +682,9 @@  discard block
 block discarded – undo
512 682
 			$data['callsign'] = $line['callsign'];
513 683
 			$data['mmsi'] = $line['mmsi'];
514 684
 			$data['speed'] = $line['sog'];
515
-			if ($line['heading'] != '511') $data['heading'] = $line['heading'];
685
+			if ($line['heading'] != '511') {
686
+				$data['heading'] = $line['heading'];
687
+			}
516 688
 			$data['latitude'] = $line['latitude'];
517 689
 			$data['longitude'] = $line['longitude'];
518 690
 			$data['type_id'] = $line['shiptype'];
@@ -532,7 +704,9 @@  discard block
 block discarded – undo
532 704
 	    echo 'download...';
533 705
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534 706
 	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
707
+	    if ($buffer != '') {
708
+	    	$reset = 0;
709
+	    }
536 710
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537 711
 	    $buffer = explode('\n',$buffer);
538 712
 	    foreach ($buffer as $line) {
@@ -576,16 +750,28 @@  discard block
 block discarded – undo
576 750
     		    $line = explode(':', $line);
577 751
     		    if (count($line) > 30 && $line[0] != 'callsign') {
578 752
 			$data = array();
579
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
753
+			if (isset($line[37]) && $line[37] != '') {
754
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
755
+			} else {
756
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
757
+			}
581 758
 			$data['pilot_id'] = $line[1];
582 759
 			$data['pilot_name'] = $line[2];
583 760
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
584 761
 			$data['ident'] = $line[0]; // ident
585
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
762
+			if ($line[7] != '' && $line[7] != 0) {
763
+				$data['altitude'] = $line[7];
764
+			}
765
+			// altitude
586 766
 			$data['speed'] = $line[8]; // speed
587
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
767
+			if (isset($line[45])) {
768
+				$data['heading'] = $line[45];
769
+			}
770
+			// heading
771
+			elseif (isset($line[38])) {
772
+				$data['heading'] = $line[38];
773
+			}
774
+			// heading
589 775
 			$data['latitude'] = $line[5]; // lat
590 776
 	        	$data['longitude'] = $line[6]; // long
591 777
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -601,7 +787,9 @@  discard block
 block discarded – undo
601 787
 			$data['frequency'] = $line[4];
602 788
 			$data['type'] = $line[18];
603 789
 			$data['range'] = $line[19];
604
-			if (isset($line[35])) $data['info'] = $line[35];
790
+			if (isset($line[35])) {
791
+				$data['info'] = $line[35];
792
+			}
605 793
     			$data['id_source'] = $id_source;
606 794
 	    		//$data['arrival_airport_time'] = ;
607 795
 	    		if ($line[9] != '') {
@@ -615,24 +803,41 @@  discard block
 block discarded – undo
615 803
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 804
 	    		*/
617 805
 	    		$data['format_source'] = $value['format'];
618
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
620
-			elseif ($line[3] == 'ATC') {
806
+			if (isset($value['name']) && $value['name'] != '') {
807
+				$data['source_name'] = $value['name'];
808
+			}
809
+    			if ($line[3] == 'PILOT') {
810
+    				$SI->add($data);
811
+    			} elseif ($line[3] == 'ATC') {
621 812
 				//print_r($data);
622 813
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623 814
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624 815
 				$typec = substr($data['ident'],-3);
625
-				if ($typec == 'APP') $data['type'] = 'Approach';
626
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
628
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
629
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
630
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
631
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
632
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
634
-				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
816
+				if ($typec == 'APP') {
817
+					$data['type'] = 'Approach';
818
+				} elseif ($typec == 'TWR') {
819
+					$data['type'] = 'Tower';
820
+				} elseif ($typec == 'OBS') {
821
+					$data['type'] = 'Observer';
822
+				} elseif ($typec == 'GND') {
823
+					$data['type'] = 'Ground';
824
+				} elseif ($typec == 'DEL') {
825
+					$data['type'] = 'Delivery';
826
+				} elseif ($typec == 'DEP') {
827
+					$data['type'] = 'Departure';
828
+				} elseif ($typec == 'FSS') {
829
+					$data['type'] = 'Flight Service Station';
830
+				} elseif ($typec == 'CTR') {
831
+					$data['type'] = 'Control Radar or Centre';
832
+				} elseif ($data['type'] == '') {
833
+					$data['type'] = 'Observer';
834
+				}
835
+				if (!isset($data['source_name'])) {
836
+					$data['source_name'] = '';
837
+				}
838
+				if (isset($ATC)) {
839
+					echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
840
+				}
636 841
 			}
637 842
     			unset($data);
638 843
     		    }
@@ -651,26 +856,55 @@  discard block
 block discarded – undo
651 856
 		foreach ($all_data['acList'] as $line) {
652 857
 		    $data = array();
653 858
 		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
859
+		    if (isset($line['Call'])) {
860
+		    	$data['ident'] = $line['Call'];
861
+		    }
862
+		    // ident
863
+		    if (isset($line['Alt'])) {
864
+		    	$data['altitude'] = $line['Alt'];
865
+		    }
866
+		    // altitude
867
+		    if (isset($line['Spd'])) {
868
+		    	$data['speed'] = $line['Spd'];
869
+		    }
870
+		    // speed
871
+		    if (isset($line['Trak'])) {
872
+		    	$data['heading'] = $line['Trak'];
873
+		    }
874
+		    // heading
875
+		    if (isset($line['Lat'])) {
876
+		    	$data['latitude'] = $line['Lat'];
877
+		    }
878
+		    // lat
879
+		    if (isset($line['Long'])) {
880
+		    	$data['longitude'] = $line['Long'];
881
+		    }
882
+		    // long
660 883
 		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
884
+		    if (isset($line['Sqk'])) {
885
+		    	$data['squawk'] = $line['Sqk'];
886
+		    }
887
+		    // squawk
662 888
 		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
889
+		    if (isset($line['Reg'])) {
890
+		    	$data['registration'] = $line['Reg'];
891
+		    }
664 892
 		    /*
665 893
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 894
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 895
 		    */
668 896
 		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
897
+		    if (isset($line['Type'])) {
898
+		    	$data['aircraft_icao'] = $line['Type'];
899
+		    }
670 900
 	    	    $data['format_source'] = 'aircraftlistjson';
671 901
 		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['datetime'])) $SI->add($data);
902
+		    if (isset($value['name']) && $value['name'] != '') {
903
+		    	$data['source_name'] = $value['name'];
904
+		    }
905
+		    if (isset($data['datetime'])) {
906
+		    	$SI->add($data);
907
+		    }
674 908
 		    unset($data);
675 909
 		}
676 910
 	    } else {
@@ -690,7 +924,9 @@  discard block
 block discarded – undo
690 924
 		    $data['datetime'] = date('Y-m-d H:i:s');
691 925
 	    	    $data['format_source'] = 'aircraftlistjson';
692 926
     		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
927
+		    if (isset($value['name']) && $value['name'] != '') {
928
+		    	$data['source_name'] = $value['name'];
929
+		    }
694 930
 		    $SI->add($data);
695 931
 		    unset($data);
696 932
 		}
@@ -726,7 +962,9 @@  discard block
 block discarded – undo
726 962
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727 963
 	    	    $data['format_source'] = 'planeupdatefaa';
728 964
     		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
965
+		    if (isset($value['name']) && $value['name'] != '') {
966
+		    	$data['source_name'] = $value['name'];
967
+		    }
730 968
 		    $SI->add($data);
731 969
 		    unset($data);
732 970
 		}
@@ -766,7 +1004,9 @@  discard block
 block discarded – undo
766 1004
 	    //$buffer = $Common->getData($hosts[$id]);
767 1005
 	    $buffer = $Common->getData($value['host']);
768 1006
 	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
1007
+	    if (!empty($all_data)) {
1008
+	    	$reset = 0;
1009
+	    }
770 1010
 	    foreach ($all_data as $key => $line) {
771 1011
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772 1012
 		    $data = array();
@@ -787,7 +1027,9 @@  discard block
 block discarded – undo
787 1027
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788 1028
 	    	    $data['format_source'] = 'fr24json';
789 1029
     		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
+		    if (isset($value['name']) && $value['name'] != '') {
1031
+		    	$data['source_name'] = $value['name'];
1032
+		    }
791 1033
 		    $SI->add($data);
792 1034
 		    unset($data);
793 1035
 		}
@@ -811,23 +1053,39 @@  discard block
 block discarded – undo
811 1053
 		    if (isset($line['inf'])) {
812 1054
 			$data = array();
813 1055
 			$data['hex'] = $line['inf']['ia'];
814
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1056
+			if (isset($line['inf']['cs'])) {
1057
+				$data['ident'] = $line['inf']['cs'];
1058
+			}
1059
+			//$line[13]
815 1060
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1061
+	    		if (isset($line['inf']['gs'])) {
1062
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1063
+	    		}
1064
+	    		// speed
1065
+	    		if (isset($line['inf']['tr'])) {
1066
+	    			$data['heading'] = $line['inf']['tr'];
1067
+	    		}
1068
+	    		// heading
818 1069
 	    		$data['latitude'] = $line['pt'][0]; // lat
819 1070
 	    		$data['longitude'] = $line['pt'][1]; // long
820 1071
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1072
+	    		if (isset($line['inf']['sq'])) {
1073
+	    			$data['squawk'] = $line['inf']['sq'];
1074
+	    		}
1075
+	    		// squawk
822 1076
 	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1077
+	    		if (isset($line['inf']['rc'])) {
1078
+	    			$data['registration'] = $line['inf']['rc'];
1079
+	    		}
824 1080
 			//$data['departure_airport_iata'] = $line[11];
825 1081
 			//$data['arrival_airport_iata'] = $line[12];
826 1082
 	    		//$data['emergency'] = ''; // emergency
827 1083
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828 1084
 	    		$data['format_source'] = 'radarvirtueljson';
829 1085
     			$data['id_source'] = $id_source;
830
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1086
+			if (isset($value['name']) && $value['name'] != '') {
1087
+				$data['source_name'] = $value['name'];
1088
+			}
831 1089
 			$SI->add($data);
832 1090
 			unset($data);
833 1091
 		    }
@@ -848,29 +1106,62 @@  discard block
 block discarded – undo
848 1106
 		    $data['id'] = $line['id'];
849 1107
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850 1108
 		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1109
+		    if (isset($line['pilotid'])) {
1110
+		    	$data['pilot_id'] = $line['pilotid'];
1111
+		    }
1112
+		    // pilot id
1113
+		    if (isset($line['name'])) {
1114
+		    	$data['pilot_name'] = $line['name'];
1115
+		    }
1116
+		    // pilot name
1117
+		    if (isset($line['alt'])) {
1118
+		    	$data['altitude'] = $line['alt'];
1119
+		    }
1120
+		    // altitude
1121
+		    if (isset($line['gs'])) {
1122
+		    	$data['speed'] = $line['gs'];
1123
+		    }
1124
+		    // speed
1125
+		    if (isset($line['heading'])) {
1126
+		    	$data['heading'] = $line['heading'];
1127
+		    }
1128
+		    // heading
1129
+		    if (isset($line['route'])) {
1130
+		    	$data['waypoints'] = $line['route'];
1131
+		    }
1132
+		    // route
857 1133
 		    $data['latitude'] = $line['lat']; // lat
858 1134
 		    $data['longitude'] = $line['lon']; // long
859 1135
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860 1136
 		    //$data['squawk'] = $line['squawk']; // squawk
861 1137
 		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1138
+		    if (isset($line['depicao'])) {
1139
+		    	$data['departure_airport_icao'] = $line['depicao'];
1140
+		    }
1141
+		    if (isset($line['deptime'])) {
1142
+		    	$data['departure_airport_time'] = $line['deptime'];
1143
+		    }
1144
+		    if (isset($line['arricao'])) {
1145
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1146
+		    }
865 1147
 		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
1148
+		    if (isset($line['aircraft'])) {
1149
+		    	$data['aircraft_icao'] = $line['aircraft'];
1150
+		    }
1151
+		    if (isset($line['transponder'])) {
1152
+		    	$data['squawk'] = $line['transponder'];
1153
+		    }
1154
+		    if (isset($line['atis'])) {
1155
+		    	$data['info'] = $line['atis'];
1156
+		    } else {
1157
+		    	$data['info'] = '';
1158
+		    }
870 1159
 		    $data['format_source'] = 'pireps';
871 1160
     		    $data['id_source'] = $id_source;
872 1161
 		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1162
+		    if (isset($value['name']) && $value['name'] != '') {
1163
+		    	$data['source_name'] = $value['name'];
1164
+		    }
874 1165
 		    if ($line['icon'] == 'plane') {
875 1166
 			$SI->add($data);
876 1167
 		    //    print_r($data);
@@ -879,16 +1170,28 @@  discard block
 block discarded – undo
879 1170
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 1171
 			$typec = substr($data['ident'],-3);
881 1172
 			$data['type'] = '';
882
-			if ($typec == 'APP') $data['type'] = 'Approach';
883
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
884
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
885
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
886
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
887
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
888
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890
-			else $data['type'] = 'Observer';
891
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1173
+			if ($typec == 'APP') {
1174
+				$data['type'] = 'Approach';
1175
+			} elseif ($typec == 'TWR') {
1176
+				$data['type'] = 'Tower';
1177
+			} elseif ($typec == 'OBS') {
1178
+				$data['type'] = 'Observer';
1179
+			} elseif ($typec == 'GND') {
1180
+				$data['type'] = 'Ground';
1181
+			} elseif ($typec == 'DEL') {
1182
+				$data['type'] = 'Delivery';
1183
+			} elseif ($typec == 'DEP') {
1184
+				$data['type'] = 'Departure';
1185
+			} elseif ($typec == 'FSS') {
1186
+				$data['type'] = 'Flight Service Station';
1187
+			} elseif ($typec == 'CTR') {
1188
+				$data['type'] = 'Control Radar or Centre';
1189
+			} else {
1190
+				$data['type'] = 'Observer';
1191
+			}
1192
+			if (isset($ATC)) {
1193
+				echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1194
+			}
892 1195
 		    }
893 1196
 		    unset($data);
894 1197
 		}
@@ -898,7 +1201,9 @@  discard block
 block discarded – undo
898 1201
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899 1202
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900 1203
 	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
1204
+	    if ($globalDebug) {
1205
+	    	echo 'Get Data...'."\n";
1206
+	    }
902 1207
 	    $buffer = $Common->getData($value['host']);
903 1208
 	    $all_data = json_decode($buffer,true);
904 1209
 	    if ($buffer != '' && is_array($all_data)) {
@@ -906,10 +1211,16 @@  discard block
 block discarded – undo
906 1211
 		foreach ($all_data as $line) {
907 1212
 	    	    $data = array();
908 1213
 	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1214
+	    	    if (isset($line['pilotid'])) {
1215
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1216
+	    	    }
910 1217
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1218
+	    	    if (isset($line['pilotname'])) {
1219
+	    	    	$data['pilot_name'] = $line['pilotname'];
1220
+	    	    }
1221
+	    	    if (isset($line['pilotid'])) {
1222
+	    	    	$data['pilot_id'] = $line['pilotid'];
1223
+	    	    }
913 1224
 	    	    $data['ident'] = $line['flightnum']; // ident
914 1225
 	    	    $data['altitude'] = $line['alt']; // altitude
915 1226
 	    	    $data['speed'] = $line['gs']; // speed
@@ -927,27 +1238,41 @@  discard block
 block discarded – undo
927 1238
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
928 1239
     		    $data['arrival_airport_time'] = $line['arrtime'];
929 1240
     		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1241
+		    if (isset($line['route'])) {
1242
+		    	$data['waypoints'] = $line['route'];
1243
+		    }
1244
+		    // route
931 1245
 		    if (isset($line['aircraftname'])) {
932 1246
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 1247
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934 1248
 	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
1249
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1250
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1251
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1252
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1253
+	    		} else {
938 1254
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1255
+	    		    if (isset($aircraft_data[1])) {
1256
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1257
+	    		    } else {
1258
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1259
+	    		    }
941 1260
 	    		}
942 1261
 	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1262
+    		    if (isset($line['route'])) {
1263
+    		    	$data['waypoints'] = $line['route'];
1264
+    		    }
944 1265
     		    $data['id_source'] = $id_source;
945 1266
 	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1267
+		    if (isset($value['name']) && $value['name'] != '') {
1268
+		    	$data['source_name'] = $value['name'];
1269
+		    }
947 1270
 		    $SI->add($data);
948 1271
 		    unset($data);
949 1272
 		}
950
-		if ($globalDebug) echo 'No more data...'."\n";
1273
+		if ($globalDebug) {
1274
+			echo 'No more data...'."\n";
1275
+		}
951 1276
 		unset($buffer);
952 1277
 		unset($all_data);
953 1278
 	    }
@@ -955,7 +1280,9 @@  discard block
 block discarded – undo
955 1280
     	    $last_exec[$id]['last'] = time();
956 1281
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957 1282
 	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
1283
+	    if ($globalDebug) {
1284
+	    	echo 'Get Data...'."\n";
1285
+	    }
959 1286
 	    $buffer = $Common->getData($value['host']);
960 1287
 	    $all_data = json_decode($buffer,true);
961 1288
 	    if ($buffer != '' && is_array($all_data)) {
@@ -984,15 +1311,22 @@  discard block
 block discarded – undo
984 1311
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
985 1312
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
986 1313
     		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1314
+		    if (isset($line['route'])) {
1315
+		    	$data['waypoints'] = $line['route'];
1316
+		    }
1317
+		    // route
988 1318
 	    	    $data['aircraft_icao'] = $line['plane_type'];
989 1319
     		    $data['id_source'] = $id_source;
990 1320
 	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1321
+		    if (isset($value['name']) && $value['name'] != '') {
1322
+		    	$data['source_name'] = $value['name'];
1323
+		    }
992 1324
 		    $SI->add($data);
993 1325
 		    unset($data);
994 1326
 		}
995
-		if ($globalDebug) echo 'No more data...'."\n";
1327
+		if ($globalDebug) {
1328
+			echo 'No more data...'."\n";
1329
+		}
996 1330
 		unset($buffer);
997 1331
 		unset($all_data);
998 1332
 	    }
@@ -1000,7 +1334,9 @@  discard block
 block discarded – undo
1000 1334
     	    $last_exec[$id]['last'] = time();
1001 1335
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1336
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1337
+	    if (function_exists('pcntl_fork')) {
1338
+	    	pcntl_signal_dispatch();
1339
+	    }
1004 1340
     	    //$last_exec[$id]['last'] = time();
1005 1341
 
1006 1342
 	    //$read = array( $sockets[$id] );
@@ -1008,7 +1344,9 @@  discard block
 block discarded – undo
1008 1344
 	    $write = NULL;
1009 1345
 	    $e = NULL;
1010 1346
 	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1347
+	    if ($e != NULL) {
1348
+	    	var_dump($e);
1349
+	    }
1012 1350
 	    if ($n > 0) {
1013 1351
 		$reset = 0;
1014 1352
 		foreach ($read as $nb => $r) {
@@ -1030,7 +1368,9 @@  discard block
 block discarded – undo
1030 1368
 		    if ($buffer != '') {
1031 1369
 			$tt[$format] = 0;
1032 1370
 			if ($format == 'acarssbs3') {
1033
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1371
+                    	    if ($globalDebug) {
1372
+                    	    	echo 'ACARS : '.$buffer."\n";
1373
+                    	    }
1034 1374
 			    $ACARS->add(trim($buffer));
1035 1375
 			    $ACARS->deleteLiveAcarsData();
1036 1376
 			} elseif ($format == 'raw') {
@@ -1039,25 +1379,55 @@  discard block
 block discarded – undo
1039 1379
 			    if (is_array($data)) {
1040 1380
 				$data['datetime'] = date('Y-m-d H:i:s');
1041 1381
 				$data['format_source'] = 'raw';
1042
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1043
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1382
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1383
+					$data['source_name'] = $globalSources[$nb]['name'];
1384
+				}
1385
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1386
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1387
+    				}
1388
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1389
+                                	$SI->add($data);
1390
+                                }
1045 1391
                             }
1046 1392
                         } elseif ($format == 'ais') {
1047 1393
 			    $ais_data = $AIS->parse_line(trim($buffer));
1048 1394
 			    $data = array();
1049
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1395
+			    if (isset($ais_data['ident'])) {
1396
+			    	$data['ident'] = $ais_data['ident'];
1397
+			    }
1398
+			    if (isset($ais_data['mmsi'])) {
1399
+			    	$data['mmsi'] = $ais_data['mmsi'];
1400
+			    }
1401
+			    if (isset($ais_data['speed'])) {
1402
+			    	$data['speed'] = $ais_data['speed'];
1403
+			    }
1404
+			    if (isset($ais_data['heading'])) {
1405
+			    	$data['heading'] = $ais_data['heading'];
1406
+			    }
1407
+			    if (isset($ais_data['latitude'])) {
1408
+			    	$data['latitude'] = $ais_data['latitude'];
1409
+			    }
1410
+			    if (isset($ais_data['longitude'])) {
1411
+			    	$data['longitude'] = $ais_data['longitude'];
1412
+			    }
1413
+			    if (isset($ais_data['status'])) {
1414
+			    	$data['status'] = $ais_data['status'];
1415
+			    }
1416
+			    if (isset($ais_data['type'])) {
1417
+			    	$data['type'] = $ais_data['type'];
1418
+			    }
1419
+			    if (isset($ais_data['imo'])) {
1420
+			    	$data['imo'] = $ais_data['imo'];
1421
+			    }
1422
+			    if (isset($ais_data['callsign'])) {
1423
+			    	$data['callsign'] = $ais_data['callsign'];
1424
+			    }
1425
+			    if (isset($ais_data['destination'])) {
1426
+			    	$data['arrival_code'] = $ais_data['destination'];
1427
+			    }
1428
+			    if (isset($ais_data['eta_ts'])) {
1429
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1430
+			    }
1061 1431
 
1062 1432
 			    if (isset($ais_data['timestamp'])) {
1063 1433
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1066,7 +1436,9 @@  discard block
 block discarded – undo
1066 1436
 			    }
1067 1437
 			    $data['format_source'] = 'aisnmea';
1068 1438
     			    $data['id_source'] = $id_source;
1069
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1439
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1440
+			    	$MI->add($data);
1441
+			    }
1070 1442
 			    unset($data);
1071 1443
                         } elseif ($format == 'flightgearsp') {
1072 1444
                     	    //echo $buffer."\n";
@@ -1084,11 +1456,15 @@  discard block
 block discarded – undo
1084 1456
 				$data['speed'] = round($line[5]*1.94384);
1085 1457
 				$data['datetime'] = date('Y-m-d H:i:s');
1086 1458
 				$data['format_source'] = 'flightgearsp';
1087
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1459
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1460
+					$SI->add($data);
1461
+				}
1088 1462
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1089 1463
 			    }
1090 1464
                         } elseif ($format == 'acars') {
1091
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1465
+                    	    if ($globalDebug) {
1466
+                    	    	echo 'ACARS : '.$buffer."\n";
1467
+                    	    }
1092 1468
 			    $ACARS->add(trim($buffer));
1093 1469
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094 1470
 			    $ACARS->deleteLiveAcarsData();
@@ -1109,7 +1485,9 @@  discard block
 block discarded – undo
1109 1485
 				    $aircraft_type = $line[10];
1110 1486
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1111 1487
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1488
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1489
+				    	$SI->add($data);
1490
+				    }
1113 1491
 				}
1114 1492
 			    }
1115 1493
 			} elseif ($format == 'beast') {
@@ -1125,21 +1503,43 @@  discard block
 block discarded – undo
1125 1503
     				$data['hex'] = $lined['hexid'];
1126 1504
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127 1505
     				$data['datetime'] = date('Y-m-d H:i:s');;
1128
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1506
+    				if (isset($lined['ident'])) {
1507
+    					$data['ident'] = $lined['ident'];
1508
+    				}
1509
+    				if (isset($lined['lat'])) {
1510
+    					$data['latitude'] = $lined['lat'];
1511
+    				}
1512
+    				if (isset($lined['lon'])) {
1513
+    					$data['longitude'] = $lined['lon'];
1514
+    				}
1515
+    				if (isset($lined['speed'])) {
1516
+    					$data['speed'] = $lined['speed'];
1517
+    				}
1518
+    				if (isset($lined['squawk'])) {
1519
+    					$data['squawk'] = $lined['squawk'];
1520
+    				}
1521
+    				if (isset($lined['alt'])) {
1522
+    					$data['altitude'] = $lined['alt'];
1523
+    				}
1524
+    				if (isset($lined['heading'])) {
1525
+    					$data['heading'] = $lined['heading'];
1526
+    				}
1135 1527
     				$data['id_source'] = $id_source;
1136 1528
     				$data['format_source'] = 'tsv';
1137
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1529
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1530
+    					$data['source_name'] = $globalSources[$nb]['name'];
1531
+    				}
1532
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1533
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1534
+    				}
1535
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1536
+    					$SI->add($data);
1537
+    				}
1140 1538
     				unset($lined);
1141 1539
     				unset($data);
1142
-    			    } else $error = true;
1540
+    			    } else {
1541
+    			    	$error = true;
1542
+    			    }
1143 1543
 			} elseif ($format == 'aprs' && $use_aprs) {
1144 1544
 			    if ($aprs_connect == 0) {
1145 1545
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1165,47 +1565,72 @@  discard block
 block discarded – undo
1165 1565
 				    $aprs_last_tx = time();
1166 1566
 				    $data = array();
1167 1567
 				    //print_r($line);
1168
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1169
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1568
+				    if (isset($line['address'])) {
1569
+				    	$data['hex'] = $line['address'];
1570
+				    }
1571
+				    if (isset($line['timestamp'])) {
1572
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1573
+				    } else {
1574
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1575
+				    }
1171 1576
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1172 1577
 				    $data['ident'] = $line['ident'];
1173 1578
 				    $data['latitude'] = $line['latitude'];
1174 1579
 				    $data['longitude'] = $line['longitude'];
1175 1580
 				    //$data['verticalrate'] = $line[16];
1176
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
-				    else $data['speed'] = 0;
1178
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1581
+				    if (isset($line['speed'])) {
1582
+				    	$data['speed'] = $line['speed'];
1583
+				    } else {
1584
+				    	$data['speed'] = 0;
1585
+				    }
1586
+				    if (isset($line['altitude'])) {
1587
+				    	$data['altitude'] = $line['altitude'];
1588
+				    }
1589
+				    if (isset($line['comment'])) {
1590
+				    	$data['comment'] = $line['comment'];
1591
+				    }
1592
+				    if (isset($line['symbol'])) {
1593
+				    	$data['type'] = $line['symbol'];
1594
+				    }
1595
+				    if (isset($line['heading'])) {
1596
+				    	$data['heading'] = $line['heading'];
1597
+				    }
1182 1598
 				    //else $data['heading'] = 0;
1183
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1599
+				    if (isset($line['stealth'])) {
1600
+				    	$data['aircraft_type'] = $line['stealth'];
1601
+				    }
1602
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1603
+				    	$data['noarchive'] = true;
1604
+				    }
1185 1605
     				    $data['id_source'] = $id_source;
1186 1606
 				    $data['format_source'] = 'aprs';
1187 1607
 				    $data['source_name'] = $line['source'];
1188 1608
 				    $data['source_type'] = 'flarm';
1189
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1609
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1610
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1611
+    				    }
1190 1612
 				    $currentdate = date('Y-m-d H:i:s');
1191 1613
 				    $aprsdate = strtotime($data['datetime']);
1192 1614
 				    // Accept data if time <= system time + 20s
1193 1615
 				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1194 1616
 					$send = $SI->add($data);
1195 1617
 				    } elseif (isset($line['stealth'])) {
1196
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1197
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1618
+					if ($line['stealth'] != 0) {
1619
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1620
+					} else {
1621
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1622
+					}
1198 1623
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199 1624
 				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1200 1625
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1201
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1626
+					if (isset($globalTracker) && $globalTracker) {
1627
+						$send = $TI->add($data);
1628
+					}
1202 1629
 				    }
1203 1630
 				    unset($data);
1204
-				} 
1205
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1631
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1206 1632
 					echo '!! Weather Station not yet supported'."\n";
1207
-				}
1208
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1633
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1209 1634
 					echo '!! Car & Trucks not yet supported'."\n";
1210 1635
 				}
1211 1636
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1238,25 +1663,42 @@  discard block
 block discarded – undo
1238 1663
     				$data['ground'] = $line[21];
1239 1664
     				$data['emergency'] = $line[19];
1240 1665
     				$data['format_source'] = 'sbs';
1241
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1242
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1666
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1667
+					$data['source_name'] = $globalSources[$nb]['name'];
1668
+				}
1669
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1670
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1671
+    				}
1243 1672
     				$data['id_source'] = $id_source;
1244
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
-    				else $error = true;
1673
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1674
+    					$send = $SI->add($data);
1675
+    				} else {
1676
+    					$error = true;
1677
+    				}
1246 1678
     				unset($data);
1247
-    			    } else $error = true;
1679
+    			    } else {
1680
+    			    	$error = true;
1681
+    			    }
1248 1682
 			    if ($error) {
1249 1683
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1250
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1684
+					if ($globalDebug) {
1685
+						echo "Not a message. Ignoring... \n";
1686
+					}
1251 1687
 				} else {
1252
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1688
+					if ($globalDebug) {
1689
+						echo "Wrong line format. Ignoring... \n";
1690
+					}
1253 1691
 					if ($globalDebug) {
1254 1692
 						echo $buffer;
1255 1693
 						print_r($line);
1256 1694
 					}
1257 1695
 					//socket_close($r);
1258
-					if ($globalDebug) echo "Reconnect after an error...\n";
1259
-					if ($format == 'aprs') $aprs_connect = 0;
1696
+					if ($globalDebug) {
1697
+						echo "Reconnect after an error...\n";
1698
+					}
1699
+					if ($format == 'aprs') {
1700
+						$aprs_connect = 0;
1701
+					}
1260 1702
 					$sourceer[$nb] = $globalSources[$nb];
1261 1703
 					connect_all($sourceer);
1262 1704
 					$sourceer = array();
@@ -1264,10 +1706,14 @@  discard block
 block discarded – undo
1264 1706
 			    }
1265 1707
 			}
1266 1708
 			// Sleep for xxx microseconds
1267
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1709
+			if (isset($globalSBSSleep)) {
1710
+				usleep($globalSBSSleep);
1711
+			}
1268 1712
 		    } else {
1269 1713
 			if ($format == 'flightgearmp') {
1270
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1714
+			    	if ($globalDebug) {
1715
+			    		echo "Reconnect FlightGear MP...";
1716
+			    	}
1271 1717
 				//@socket_close($r);
1272 1718
 				sleep($globalMinFetch);
1273 1719
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1276,10 +1722,15 @@  discard block
 block discarded – undo
1276 1722
 				break;
1277 1723
 				
1278 1724
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1279
-			    if (isset($tt[$format])) $tt[$format]++;
1280
-			    else $tt[$format] = 0;
1725
+			    if (isset($tt[$format])) {
1726
+			    	$tt[$format]++;
1727
+			    } else {
1728
+			    	$tt[$format] = 0;
1729
+			    }
1281 1730
 			    if ($tt[$format] > 30) {
1282
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1731
+				if ($globalDebug) {
1732
+					echo "ERROR : Reconnect ".$format."...";
1733
+				}
1283 1734
 				//@socket_close($r);
1284 1735
 				sleep(2);
1285 1736
 				$aprs_connect = 0;
@@ -1296,11 +1747,17 @@  discard block
 block discarded – undo
1296 1747
 	    } else {
1297 1748
 		$error = socket_strerror(socket_last_error());
1298 1749
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1300
-			if (isset($globalDebug)) echo "Restarting...\n";
1750
+			if ($globalDebug) {
1751
+				echo "ERROR : socket_select give this error ".$error . "\n";
1752
+			}
1753
+			if (isset($globalDebug)) {
1754
+				echo "Restarting...\n";
1755
+			}
1301 1756
 			// Restart the script if possible
1302 1757
 			if (is_array($sockets)) {
1303
-			    if ($globalDebug) echo "Shutdown all sockets...";
1758
+			    if ($globalDebug) {
1759
+			    	echo "Shutdown all sockets...";
1760
+			    }
1304 1761
 			    
1305 1762
 			    foreach ($sockets as $sock) {
1306 1763
 				@socket_shutdown($sock,2);
@@ -1308,18 +1765,24 @@  discard block
 block discarded – undo
1308 1765
 			    }
1309 1766
 			    
1310 1767
 			}
1311
-			if ($globalDebug) echo "Restart all connections...";
1768
+			if ($globalDebug) {
1769
+				echo "Restart all connections...";
1770
+			}
1312 1771
 			sleep(2);
1313 1772
 			$time = time();
1314 1773
 			//connect_all($hosts);
1315 1774
 			$aprs_connect = 0;
1316
-			if ($reset > 40) exit('Too many attempts...');
1775
+			if ($reset > 40) {
1776
+				exit('Too many attempts...');
1777
+			}
1317 1778
 			connect_all($globalSources);
1318 1779
 		}
1319 1780
 	    }
1320 1781
 	}
1321 1782
 	if ($globalDaemon === false) {
1322
-	    if ($globalDebug) echo 'Check all...'."\n";
1783
+	    if ($globalDebug) {
1784
+	    	echo 'Check all...'."\n";
1785
+	    }
1323 1786
 	    $SI->checkAll();
1324 1787
 	}
1325 1788
     }
Please login to merge, or discard this patch.