Completed
Push — master ( 3b2be2...aa3dba )
by Yannick
06:52
created
scripts/daemon-spotter.php 3 patches
Indentation   +694 added lines, -694 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 // Check if schema is at latest version
20 20
 $Connection = new Connection();
21 21
 if ($Connection->latest() === false) {
22
-    echo "You MUST update to latest schema. Run install/index.php";
23
-    exit();
22
+	echo "You MUST update to latest schema. Run install/index.php";
23
+	exit();
24 24
 }
25 25
 if (PHP_SAPI != 'cli') {
26
-    echo "This script MUST be called from console, not a web browser.";
26
+	echo "This script MUST be called from console, not a web browser.";
27 27
 //    exit();
28 28
 }
29 29
 
30 30
 // This is to be compatible with old version of settings.php
31 31
 if (!isset($globalSources)) {
32
-    if (isset($globalSBS1Hosts)) {
33
-        //$hosts = $globalSBS1Hosts;
34
-        foreach ($globalSBS1Hosts as $host) {
35
-	    $globalSources[] = array('host' => $host);
36
-    	}
37
-    } else {
38
-        if (!isset($globalSBS1Host)) {
39
-	    echo '$globalSources MUST be defined !';
40
-	    die;
32
+	if (isset($globalSBS1Hosts)) {
33
+		//$hosts = $globalSBS1Hosts;
34
+		foreach ($globalSBS1Hosts as $host) {
35
+		$globalSources[] = array('host' => $host);
36
+		}
37
+	} else {
38
+		if (!isset($globalSBS1Host)) {
39
+		echo '$globalSources MUST be defined !';
40
+		die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43 43
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
44
-    }
44
+	}
45 45
 }
46 46
 
47 47
 $options = getopt('s::',array('source::','server','idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
51
-    $globalSources = array();
52
-    $globalSources[] = array('host' => $options['s']);
51
+	$globalSources = array();
52
+	$globalSources[] = array('host' => $options['s']);
53 53
 } elseif (isset($options['source'])) {
54
-    $globalSources = array();
55
-    $globalSources[] = array('host' => $options['source']);
54
+	$globalSources = array();
55
+	$globalSources[] = array('host' => $options['source']);
56 56
 }
57 57
 if (isset($options['server'])) $globalServer = TRUE;
58 58
 if (isset($options['idsource'])) $id_source = $options['idsource'];
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
61
+	if ($globalDebug) echo "Using Server Mode\n";
62
+	$SI=new SpotterServer();
63 63
 } else $SI=new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65 65
 $SBS=new SBS();
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
73
-        global $sockets;
74
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
-        die("Bye!\n");
76
-    });
77
-    pcntl_signal_dispatch();
72
+	pcntl_signal(SIGINT,  function() {
73
+		global $sockets;
74
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
+		die("Bye!\n");
76
+	});
77
+	pcntl_signal_dispatch();
78 78
 }
79 79
 
80 80
 // let's try and connect
@@ -84,162 +84,162 @@  discard block
 block discarded – undo
84 84
 $reset = 0;
85 85
 
86 86
 function create_socket($host, $port, &$errno, &$errstr) {
87
-    $ip = gethostbyname($host);
88
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
89
-    $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
-        return $s;
93
-    }
94
-    $errno = socket_last_error($s);
95
-    $errstr = socket_strerror($errno);
96
-    socket_close($s);
97
-    return false;
87
+	$ip = gethostbyname($host);
88
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
89
+	$r = @socket_connect($s, $ip, $port);
90
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
+		return $s;
93
+	}
94
+	$errno = socket_last_error($s);
95
+	$errstr = socket_strerror($errno);
96
+	socket_close($s);
97
+	return false;
98 98
 }
99 99
 
100 100
 function create_socket_udp($host, $port, &$errno, &$errstr) {
101
-    echo "Create an UDP socket...\n";
102
-    $ip = gethostbyname($host);
103
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
-    $r = @socket_bind($s, $ip, $port);
105
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
-        return $s;
107
-    }
108
-    $errno = socket_last_error($s);
109
-    $errstr = socket_strerror($errno);
110
-    socket_close($s);
111
-    return false;
101
+	echo "Create an UDP socket...\n";
102
+	$ip = gethostbyname($host);
103
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
+	$r = @socket_bind($s, $ip, $port);
105
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
+		return $s;
107
+	}
108
+	$errno = socket_last_error($s);
109
+	$errstr = socket_strerror($errno);
110
+	socket_close($s);
111
+	return false;
112 112
 }
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
-        	//$formats[$id] = 'radarvirtueljson';
146
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
147
-        	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
-        	    exit(0);
152
-        	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
-        	//$formats[$id] = 'planeupdatefaa';
155
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
156
-        	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
-        	    exit(0);
161
-        	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
-        	//$formats[$id] = 'phpvmacars';
164
-        	$globalSources[$id]['format'] = 'phpvmacars';
165
-        	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
168
-        	//$formats[$id] = 'phpvmacars';
169
-        	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
172
-        	//$formats[$id] = 'whazzup';
173
-        	$globalSources[$id]['format'] = 'whazzup';
174
-        	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
177
-        	//$formats[$id] = 'pirepsjson';
178
-        	$globalSources[$id]['format'] = 'pirepsjson';
179
-        	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
-        	//$formats[$id] = 'fr24json';
183
-        	$globalSources[$id]['format'] = 'fr24json';
184
-        	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
-        	    exit(0);
189
-        	}
190
-            //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
-        	//$formats[$id] = 'tsv';
193
-        	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
-            }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
200
-	    if (isset($hostport[1])) {
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
+			//$formats[$id] = 'radarvirtueljson';
146
+			$globalSources[$id]['format'] = 'radarvirtueljson';
147
+			//$last_exec['radarvirtueljson'] = 0;
148
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
+				exit(0);
152
+			}
153
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
+			//$formats[$id] = 'planeupdatefaa';
155
+			$globalSources[$id]['format'] = 'planeupdatefaa';
156
+			//$last_exec['planeupdatefaa'] = 0;
157
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
+				exit(0);
161
+			}
162
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
+			//$formats[$id] = 'phpvmacars';
164
+			$globalSources[$id]['format'] = 'phpvmacars';
165
+			//$last_exec['phpvmacars'] = 0;
166
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
168
+			//$formats[$id] = 'phpvmacars';
169
+			$globalSources[$id]['format'] = 'vam';
170
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
+			} else if (preg_match('/whazzup/i',$host)) {
172
+			//$formats[$id] = 'whazzup';
173
+			$globalSources[$id]['format'] = 'whazzup';
174
+			//$last_exec['whazzup'] = 0;
175
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
+			} else if (preg_match('/recentpireps/i',$host)) {
177
+			//$formats[$id] = 'pirepsjson';
178
+			$globalSources[$id]['format'] = 'pirepsjson';
179
+			//$last_exec['pirepsjson'] = 0;
180
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
+			//$formats[$id] = 'fr24json';
183
+			$globalSources[$id]['format'] = 'fr24json';
184
+			//$last_exec['fr24json'] = 0;
185
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
+				exit(0);
189
+			}
190
+			//} else if (preg_match('/10001/',$host)) {
191
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
+			//$formats[$id] = 'tsv';
193
+			$globalSources[$id]['format'] = 'tsv';
194
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
+			}
196
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
+		$hostport = explode(':',$host);
200
+		if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
203
-	    } else {
203
+		} else {
204 204
 		$port = $globalSources[$id]['port'];
205 205
 		$hostn = $globalSources[$id]['host'];
206
-	    }
207
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
209
-    	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
-	    }
212
-	    if ($s) {
213
-    	        $sockets[$id] = $s;
214
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
206
+		}
207
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
+			$s = create_socket($hostn,$port, $errno, $errstr);
209
+			} else {
210
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
+		}
212
+		if ($s) {
213
+				$sockets[$id] = $s;
214
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
+			if (preg_match('/aprs/',$hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
219 219
 			//$use_aprs = true;
220
-    		    } elseif ($port == '10001') {
221
-        		//$formats[$id] = 'tsv';
222
-        		$globalSources[$id]['format'] = 'tsv';
223
-		    } elseif ($port == '30002') {
224
-        		//$formats[$id] = 'raw';
225
-        		$globalSources[$id]['format'] = 'raw';
226
-		    } elseif ($port == '5001') {
227
-        		//$formats[$id] = 'raw';
228
-        		$globalSources[$id]['format'] = 'flightgearmp';
229
-		    } elseif ($port == '30005') {
220
+				} elseif ($port == '10001') {
221
+				//$formats[$id] = 'tsv';
222
+				$globalSources[$id]['format'] = 'tsv';
223
+			} elseif ($port == '30002') {
224
+				//$formats[$id] = 'raw';
225
+				$globalSources[$id]['format'] = 'raw';
226
+			} elseif ($port == '5001') {
227
+				//$formats[$id] = 'raw';
228
+				$globalSources[$id]['format'] = 'flightgearmp';
229
+			} elseif ($port == '30005') {
230 230
 			// Not yet supported
231
-        		//$formats[$id] = 'beast';
232
-        		$globalSources[$id]['format'] = 'beast';
233
-		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
235
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
231
+				//$formats[$id] = 'beast';
232
+				$globalSources[$id]['format'] = 'beast';
233
+			//} else $formats[$id] = 'sbs';
234
+			} else $globalSources[$id]['format'] = 'sbs';
235
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 236
 		}
237 237
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
238
-            } else {
238
+			} else {
239 239
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
240
-    	    }
241
-        }
242
-    }
240
+			}
241
+		}
242
+	}
243 243
 }
244 244
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
245 245
 
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	die;
267 267
 }
268 268
 foreach ($globalSources as $key => $source) {
269
-    if (!isset($source['format'])) {
270
-        $globalSources[$key]['format'] = 'auto';
271
-    }
269
+	if (!isset($source['format'])) {
270
+		$globalSources[$key]['format'] = 'auto';
271
+	}
272 272
 }
273 273
 connect_all($globalSources);
274 274
 foreach ($globalSources as $key => $source) {
275
-    if (isset($source['format']) && $source['format'] == 'aprs') {
275
+	if (isset($source['format']) && $source['format'] == 'aprs') {
276 276
 	$aprs_connect = 0;
277 277
 	$use_aprs = true;
278 278
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
279 279
 	break;
280
-    }
280
+	}
281 281
 }
282 282
 
283 283
 if ($use_aprs) {
@@ -317,70 +317,70 @@  discard block
 block discarded – undo
317 317
 
318 318
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 319
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
321
-    // Delete old ATC
322
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
320
+	if (!$globalDaemon) $i = $endtime-time();
321
+	// Delete old ATC
322
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323 323
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
324
-        $ATC->deleteOldATC();
325
-    }
324
+		$ATC->deleteOldATC();
325
+	}
326 326
     
327
-    if (count($last_exec) > 0) {
327
+	if (count($last_exec) > 0) {
328 328
 	$max = $globalMinFetch;
329 329
 	foreach ($last_exec as $last) {
330
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
330
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
331 331
 	}
332 332
 	if ($max != $globalMinFetch) {
333
-	    if ($globalDebug) echo 'Sleeping...'."\n";
334
-	    sleep($globalMinFetch-$max+2);
333
+		if ($globalDebug) echo 'Sleeping...'."\n";
334
+		sleep($globalMinFetch-$max+2);
335
+	}
335 336
 	}
336
-    }
337 337
 
338 338
     
339
-    //foreach ($formats as $id => $value) {
340
-    foreach ($globalSources as $id => $value) {
339
+	//foreach ($formats as $id => $value) {
340
+	foreach ($globalSources as $id => $value) {
341 341
 	date_default_timezone_set('UTC');
342 342
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
343 343
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
344
-	    //$buffer = $Common->getData($hosts[$id]);
345
-	    $buffer = $Common->getData($value['host']);
346
-	    if ($buffer != '') $reset = 0;
347
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
348
-	    $buffer = explode('\n',$buffer);
349
-	    foreach ($buffer as $line) {
350
-    		if ($line != '' && count($line) > 7) {
351
-    		    $line = explode(',', $line);
352
-	            $data = array();
353
-	            $data['hex'] = $line[1]; // hex
354
-	            $data['ident'] = $line[2]; // ident
355
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
356
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
357
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
358
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
359
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
360
-	            $data['verticalrate'] = ''; // vertical rate
361
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
362
-	            $data['emergency'] = ''; // emergency
363
-		    $data['datetime'] = date('Y-m-d H:i:s');
364
-		    $data['format_source'] = 'deltadbtxt';
365
-    		    $data['id_source'] = $id_source;
366
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
367
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
368
-    		    $SI->add($data);
369
-		    unset($data);
370
-    		}
371
-    	    }
372
-    	    $last_exec[$id]['last'] = time();
344
+		//$buffer = $Common->getData($hosts[$id]);
345
+		$buffer = $Common->getData($value['host']);
346
+		if ($buffer != '') $reset = 0;
347
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
348
+		$buffer = explode('\n',$buffer);
349
+		foreach ($buffer as $line) {
350
+			if ($line != '' && count($line) > 7) {
351
+				$line = explode(',', $line);
352
+				$data = array();
353
+				$data['hex'] = $line[1]; // hex
354
+				$data['ident'] = $line[2]; // ident
355
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
356
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
357
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
358
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
359
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
360
+				$data['verticalrate'] = ''; // vertical rate
361
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
362
+				$data['emergency'] = ''; // emergency
363
+			$data['datetime'] = date('Y-m-d H:i:s');
364
+			$data['format_source'] = 'deltadbtxt';
365
+				$data['id_source'] = $id_source;
366
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
367
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
368
+				$SI->add($data);
369
+			unset($data);
370
+			}
371
+			}
372
+			$last_exec[$id]['last'] = time();
373 373
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
374 374
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
375
-	    //$buffer = $Common->getData($hosts[$id]);
376
-	    $buffer = $Common->getData($value['host']);
377
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
378
-	    $buffer = explode('\n',$buffer);
379
-	    $reset = 0;
380
-	    foreach ($buffer as $line) {
381
-    		if ($line != '') {
382
-    		    $line = explode(':', $line);
383
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
375
+		//$buffer = $Common->getData($hosts[$id]);
376
+		$buffer = $Common->getData($value['host']);
377
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
378
+		$buffer = explode('\n',$buffer);
379
+		$reset = 0;
380
+		foreach ($buffer as $line) {
381
+			if ($line != '') {
382
+				$line = explode(':', $line);
383
+				if (count($line) > 30 && $line[0] != 'callsign') {
384 384
 			$data = array();
385 385
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
386 386
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -393,36 +393,36 @@  discard block
 block discarded – undo
393 393
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
394 394
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
395 395
 			$data['latitude'] = $line[5]; // lat
396
-	        	$data['longitude'] = $line[6]; // long
397
-	        	$data['verticalrate'] = ''; // vertical rate
398
-	        	$data['squawk'] = ''; // squawk
399
-	        	$data['emergency'] = ''; // emergency
400
-	        	$data['waypoints'] = $line[30];
396
+				$data['longitude'] = $line[6]; // long
397
+				$data['verticalrate'] = ''; // vertical rate
398
+				$data['squawk'] = ''; // squawk
399
+				$data['emergency'] = ''; // emergency
400
+				$data['waypoints'] = $line[30];
401 401
 			$data['datetime'] = date('Y-m-d H:i:s');
402 402
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
403 403
 			//if (isset($line[37])) $data['last_update'] = $line[37];
404
-		        $data['departure_airport_icao'] = $line[11];
405
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
406
-		        $data['arrival_airport_icao'] = $line[13];
404
+				$data['departure_airport_icao'] = $line[11];
405
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
406
+				$data['arrival_airport_icao'] = $line[13];
407 407
 			$data['frequency'] = $line[4];
408 408
 			$data['type'] = $line[18];
409 409
 			$data['range'] = $line[19];
410 410
 			if (isset($line[35])) $data['info'] = $line[35];
411
-    			$data['id_source'] = $id_source;
412
-	    		//$data['arrival_airport_time'] = ;
413
-	    		if ($line[9] != '') {
414
-	    		    $aircraft_data = explode('/',$line[9]);
415
-	    		    if (isset($aircraft_data[1])) {
416
-	    			$data['aircraft_icao'] = $aircraft_data[1];
417
-	    		    }
418
-        		}
419
-	    		/*
411
+				$data['id_source'] = $id_source;
412
+				//$data['arrival_airport_time'] = ;
413
+				if ($line[9] != '') {
414
+					$aircraft_data = explode('/',$line[9]);
415
+					if (isset($aircraft_data[1])) {
416
+					$data['aircraft_icao'] = $aircraft_data[1];
417
+					}
418
+				}
419
+				/*
420 420
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
421 421
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
422 422
 	    		*/
423
-	    		$data['format_source'] = $value['format'];
423
+				$data['format_source'] = $value['format'];
424 424
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
425
-    			if ($line[3] == 'PILOT') $SI->add($data);
425
+				if ($line[3] == 'PILOT') $SI->add($data);
426 426
 			elseif ($line[3] == 'ATC') {
427 427
 				//print_r($data);
428 428
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -440,247 +440,247 @@  discard block
 block discarded – undo
440 440
 				if (!isset($data['source_name'])) $data['source_name'] = '';
441 441
 				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']);
442 442
 			}
443
-    			unset($data);
444
-    		    }
445
-    		}
446
-    	    }
447
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
448
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
449
-    	    $last_exec[$id]['last'] = time();
450
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
451
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
452
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
453
-	    if ($buffer != '') {
454
-	    $all_data = json_decode($buffer,true);
455
-	    if (isset($all_data['acList'])) {
443
+				unset($data);
444
+				}
445
+			}
446
+			}
447
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
448
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
449
+			$last_exec[$id]['last'] = time();
450
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
451
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
452
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
453
+		if ($buffer != '') {
454
+		$all_data = json_decode($buffer,true);
455
+		if (isset($all_data['acList'])) {
456 456
 		$reset = 0;
457 457
 		foreach ($all_data['acList'] as $line) {
458
-		    $data = array();
459
-		    $data['hex'] = $line['Icao']; // hex
460
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
461
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
462
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
463
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
464
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
465
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
466
-		    //$data['verticalrate'] = $line['']; // verticale rate
467
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
468
-		    $data['emergency'] = ''; // emergency
469
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
470
-		    /*
458
+			$data = array();
459
+			$data['hex'] = $line['Icao']; // hex
460
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
461
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
462
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
463
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
464
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
465
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
466
+			//$data['verticalrate'] = $line['']; // verticale rate
467
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
468
+			$data['emergency'] = ''; // emergency
469
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
470
+			/*
471 471
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
472 472
 		    else $data['datetime'] = date('Y-m-d H:i:s');
473 473
 		    */
474
-		    $data['datetime'] = date('Y-m-d H:i:s');
475
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
476
-	    	    $data['format_source'] = 'aircraftlistjson';
477
-		    $data['id_source'] = $id_source;
478
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
479
-		    if (isset($data['datetime'])) $SI->add($data);
480
-		    unset($data);
474
+			$data['datetime'] = date('Y-m-d H:i:s');
475
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
476
+				$data['format_source'] = 'aircraftlistjson';
477
+			$data['id_source'] = $id_source;
478
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
479
+			if (isset($data['datetime'])) $SI->add($data);
480
+			unset($data);
481 481
 		}
482
-	    } else {
482
+		} else {
483 483
 		$reset = 0;
484 484
 		foreach ($all_data as $line) {
485
-		    $data = array();
486
-		    $data['hex'] = $line['hex']; // hex
487
-		    $data['ident'] = $line['flight']; // ident
488
-		    $data['altitude'] = $line['altitude']; // altitude
489
-		    $data['speed'] = $line['speed']; // speed
490
-		    $data['heading'] = $line['track']; // heading
491
-		    $data['latitude'] = $line['lat']; // lat
492
-		    $data['longitude'] = $line['lon']; // long
493
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
494
-		    $data['squawk'] = $line['squawk']; // squawk
495
-		    $data['emergency'] = ''; // emergency
496
-		    $data['datetime'] = date('Y-m-d H:i:s');
497
-	    	    $data['format_source'] = 'aircraftlistjson';
498
-    		    $data['id_source'] = $id_source;
499
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
500
-		    $SI->add($data);
501
-		    unset($data);
485
+			$data = array();
486
+			$data['hex'] = $line['hex']; // hex
487
+			$data['ident'] = $line['flight']; // ident
488
+			$data['altitude'] = $line['altitude']; // altitude
489
+			$data['speed'] = $line['speed']; // speed
490
+			$data['heading'] = $line['track']; // heading
491
+			$data['latitude'] = $line['lat']; // lat
492
+			$data['longitude'] = $line['lon']; // long
493
+			$data['verticalrate'] = $line['vrt']; // verticale rate
494
+			$data['squawk'] = $line['squawk']; // squawk
495
+			$data['emergency'] = ''; // emergency
496
+			$data['datetime'] = date('Y-m-d H:i:s');
497
+				$data['format_source'] = 'aircraftlistjson';
498
+				$data['id_source'] = $id_source;
499
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
500
+			$SI->add($data);
501
+			unset($data);
502
+		}
502 503
 		}
503
-	    }
504
-	    }
505
-    	    //$last_exec['aircraftlistjson'] = time();
506
-    	    $last_exec[$id]['last'] = time();
507
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
508
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
509
-	    $buffer = $Common->getData($value['host']);
510
-	    $all_data = json_decode($buffer,true);
511
-	    if (isset($all_data['planes'])) {
504
+		}
505
+			//$last_exec['aircraftlistjson'] = time();
506
+			$last_exec[$id]['last'] = time();
507
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
508
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
509
+		$buffer = $Common->getData($value['host']);
510
+		$all_data = json_decode($buffer,true);
511
+		if (isset($all_data['planes'])) {
512 512
 		$reset = 0;
513 513
 		foreach ($all_data['planes'] as $key => $line) {
514
-		    $data = array();
515
-		    $data['hex'] = $key; // hex
516
-		    $data['ident'] = $line[3]; // ident
517
-		    $data['altitude'] = $line[6]; // altitude
518
-		    $data['speed'] = $line[8]; // speed
519
-		    $data['heading'] = $line[7]; // heading
520
-		    $data['latitude'] = $line[4]; // lat
521
-		    $data['longitude'] = $line[5]; // long
522
-		    //$data['verticalrate'] = $line[]; // verticale rate
523
-		    $data['squawk'] = $line[10]; // squawk
524
-		    $data['emergency'] = ''; // emergency
525
-		    $data['registration'] = $line[2];
526
-		    $data['aircraft_icao'] = $line[0];
527
-		    $deparr = explode('-',$line[1]);
528
-		    if (count($deparr) == 2) {
514
+			$data = array();
515
+			$data['hex'] = $key; // hex
516
+			$data['ident'] = $line[3]; // ident
517
+			$data['altitude'] = $line[6]; // altitude
518
+			$data['speed'] = $line[8]; // speed
519
+			$data['heading'] = $line[7]; // heading
520
+			$data['latitude'] = $line[4]; // lat
521
+			$data['longitude'] = $line[5]; // long
522
+			//$data['verticalrate'] = $line[]; // verticale rate
523
+			$data['squawk'] = $line[10]; // squawk
524
+			$data['emergency'] = ''; // emergency
525
+			$data['registration'] = $line[2];
526
+			$data['aircraft_icao'] = $line[0];
527
+			$deparr = explode('-',$line[1]);
528
+			if (count($deparr) == 2) {
529 529
 			$data['departure_airport_icao'] = $deparr[0];
530 530
 			$data['arrival_airport_icao'] = $deparr[1];
531
-		    }
532
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
533
-	    	    $data['format_source'] = 'planeupdatefaa';
534
-    		    $data['id_source'] = $id_source;
535
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
536
-		    $SI->add($data);
537
-		    unset($data);
531
+			}
532
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
533
+				$data['format_source'] = 'planeupdatefaa';
534
+				$data['id_source'] = $id_source;
535
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
536
+			$SI->add($data);
537
+			unset($data);
538
+		}
538 539
 		}
539
-	    }
540
-    	    //$last_exec['planeupdatefaa'] = time();
541
-    	    $last_exec[$id]['last'] = time();
542
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
543
-	    $buffer = $Common->getData($value['host']);
544
-	    $all_data = json_decode($buffer,true);
545
-	    if (isset($all_data['states'])) {
540
+			//$last_exec['planeupdatefaa'] = time();
541
+			$last_exec[$id]['last'] = time();
542
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
543
+		$buffer = $Common->getData($value['host']);
544
+		$all_data = json_decode($buffer,true);
545
+		if (isset($all_data['states'])) {
546 546
 		$reset = 0;
547 547
 		foreach ($all_data['states'] as $key => $line) {
548
-		    $data = array();
549
-		    $data['hex'] = $line[0]; // hex
550
-		    $data['ident'] = trim($line[1]); // ident
551
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
552
-		    $data['speed'] = round($line[9]*1.94384); // speed
553
-		    $data['heading'] = round($line[10]); // heading
554
-		    $data['latitude'] = $line[5]; // lat
555
-		    $data['longitude'] = $line[6]; // long
556
-		    $data['verticalrate'] = $line[11]; // verticale rate
557
-		    //$data['squawk'] = $line[10]; // squawk
558
-		    //$data['emergency'] = ''; // emergency
559
-		    //$data['registration'] = $line[2];
560
-		    //$data['aircraft_icao'] = $line[0];
561
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
562
-	    	    $data['format_source'] = 'opensky';
563
-    		    $data['id_source'] = $id_source;
564
-		    $SI->add($data);
565
-		    unset($data);
548
+			$data = array();
549
+			$data['hex'] = $line[0]; // hex
550
+			$data['ident'] = trim($line[1]); // ident
551
+			$data['altitude'] = round($line[7]*3.28084); // altitude
552
+			$data['speed'] = round($line[9]*1.94384); // speed
553
+			$data['heading'] = round($line[10]); // heading
554
+			$data['latitude'] = $line[5]; // lat
555
+			$data['longitude'] = $line[6]; // long
556
+			$data['verticalrate'] = $line[11]; // verticale rate
557
+			//$data['squawk'] = $line[10]; // squawk
558
+			//$data['emergency'] = ''; // emergency
559
+			//$data['registration'] = $line[2];
560
+			//$data['aircraft_icao'] = $line[0];
561
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
562
+				$data['format_source'] = 'opensky';
563
+				$data['id_source'] = $id_source;
564
+			$SI->add($data);
565
+			unset($data);
566
+		}
566 567
 		}
567
-	    }
568
-    	    //$last_exec['planeupdatefaa'] = time();
569
-    	    $last_exec[$id]['last'] = time();
570
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
571
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
572
-	    //$buffer = $Common->getData($hosts[$id]);
573
-	    $buffer = $Common->getData($value['host']);
574
-	    $all_data = json_decode($buffer,true);
575
-	    if (!empty($all_data)) $reset = 0;
576
-	    foreach ($all_data as $key => $line) {
568
+			//$last_exec['planeupdatefaa'] = time();
569
+			$last_exec[$id]['last'] = time();
570
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
571
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
572
+		//$buffer = $Common->getData($hosts[$id]);
573
+		$buffer = $Common->getData($value['host']);
574
+		$all_data = json_decode($buffer,true);
575
+		if (!empty($all_data)) $reset = 0;
576
+		foreach ($all_data as $key => $line) {
577 577
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
578
-		    $data = array();
579
-		    $data['hex'] = $line[0];
580
-		    $data['ident'] = $line[16]; //$line[13]
581
-	    	    $data['altitude'] = $line[4]; // altitude
582
-	    	    $data['speed'] = $line[5]; // speed
583
-	    	    $data['heading'] = $line[3]; // heading
584
-	    	    $data['latitude'] = $line[1]; // lat
585
-	    	    $data['longitude'] = $line[2]; // long
586
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
587
-	    	    $data['squawk'] = $line[6]; // squawk
588
-	    	    $data['aircraft_icao'] = $line[8];
589
-	    	    $data['registration'] = $line[9];
590
-		    $data['departure_airport_iata'] = $line[11];
591
-		    $data['arrival_airport_iata'] = $line[12];
592
-	    	    $data['emergency'] = ''; // emergency
593
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
594
-	    	    $data['format_source'] = 'fr24json';
595
-    		    $data['id_source'] = $id_source;
596
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
597
-		    $SI->add($data);
598
-		    unset($data);
578
+			$data = array();
579
+			$data['hex'] = $line[0];
580
+			$data['ident'] = $line[16]; //$line[13]
581
+				$data['altitude'] = $line[4]; // altitude
582
+				$data['speed'] = $line[5]; // speed
583
+				$data['heading'] = $line[3]; // heading
584
+				$data['latitude'] = $line[1]; // lat
585
+				$data['longitude'] = $line[2]; // long
586
+				$data['verticalrate'] = $line[15]; // verticale rate
587
+				$data['squawk'] = $line[6]; // squawk
588
+				$data['aircraft_icao'] = $line[8];
589
+				$data['registration'] = $line[9];
590
+			$data['departure_airport_iata'] = $line[11];
591
+			$data['arrival_airport_iata'] = $line[12];
592
+				$data['emergency'] = ''; // emergency
593
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
594
+				$data['format_source'] = 'fr24json';
595
+				$data['id_source'] = $id_source;
596
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
597
+			$SI->add($data);
598
+			unset($data);
599
+		}
599 600
 		}
600
-	    }
601
-    	    //$last_exec['fr24json'] = time();
602
-    	    $last_exec[$id]['last'] = time();
603
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
604
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
605
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
606
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
607
-	    //echo $buffer;
608
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
609
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
610
-	    $all_data = json_decode($buffer,true);
611
-	    if (json_last_error() != JSON_ERROR_NONE) {
601
+			//$last_exec['fr24json'] = time();
602
+			$last_exec[$id]['last'] = time();
603
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
604
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
605
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
606
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
607
+		//echo $buffer;
608
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
609
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
610
+		$all_data = json_decode($buffer,true);
611
+		if (json_last_error() != JSON_ERROR_NONE) {
612 612
 		die(json_last_error_msg());
613
-	    }
614
-	    if (isset($all_data['mrkrs'])) {
613
+		}
614
+		if (isset($all_data['mrkrs'])) {
615 615
 		$reset = 0;
616 616
 		foreach ($all_data['mrkrs'] as $key => $line) {
617
-		    if (isset($line['inf'])) {
617
+			if (isset($line['inf'])) {
618 618
 			$data = array();
619 619
 			$data['hex'] = $line['inf']['ia'];
620 620
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
621
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
622
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
623
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
624
-	    		$data['latitude'] = $line['pt'][0]; // lat
625
-	    		$data['longitude'] = $line['pt'][1]; // long
626
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
627
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
628
-	    		//$data['aircraft_icao'] = $line[8];
629
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
621
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
622
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
623
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
624
+				$data['latitude'] = $line['pt'][0]; // lat
625
+				$data['longitude'] = $line['pt'][1]; // long
626
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
627
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
628
+				//$data['aircraft_icao'] = $line[8];
629
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
630 630
 			//$data['departure_airport_iata'] = $line[11];
631 631
 			//$data['arrival_airport_iata'] = $line[12];
632
-	    		//$data['emergency'] = ''; // emergency
632
+				//$data['emergency'] = ''; // emergency
633 633
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
634
-	    		$data['format_source'] = 'radarvirtueljson';
635
-    			$data['id_source'] = $id_source;
634
+				$data['format_source'] = 'radarvirtueljson';
635
+				$data['id_source'] = $id_source;
636 636
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
637 637
 			$SI->add($data);
638 638
 			unset($data);
639
-		    }
639
+			}
640
+		}
640 641
 		}
641
-	    }
642
-    	    //$last_exec['radarvirtueljson'] = time();
643
-    	    $last_exec[$id]['last'] = time();
644
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
645
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    //$buffer = $Common->getData($hosts[$id]);
647
-	    $buffer = $Common->getData($value['host'].'?'.time());
648
-	    $all_data = json_decode(utf8_encode($buffer),true);
642
+			//$last_exec['radarvirtueljson'] = time();
643
+			$last_exec[$id]['last'] = time();
644
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
645
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
+		//$buffer = $Common->getData($hosts[$id]);
647
+		$buffer = $Common->getData($value['host'].'?'.time());
648
+		$all_data = json_decode(utf8_encode($buffer),true);
649 649
 	    
650
-	    if (isset($all_data['pireps'])) {
650
+		if (isset($all_data['pireps'])) {
651 651
 		$reset = 0;
652
-	        foreach ($all_data['pireps'] as $line) {
653
-		    $data = array();
654
-		    $data['id'] = $line['id'];
655
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
656
-		    $data['ident'] = $line['callsign']; // ident
657
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
658
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
659
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
660
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
661
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
662
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
663
-		    $data['latitude'] = $line['lat']; // lat
664
-		    $data['longitude'] = $line['lon']; // long
665
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
666
-		    //$data['squawk'] = $line['squawk']; // squawk
667
-		    //$data['emergency'] = ''; // emergency
668
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
669
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
670
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
671
-		    //$data['arrival_airport_time'] = $line['arrtime'];
672
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
673
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
674
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
675
-		    else $data['info'] = '';
676
-		    $data['format_source'] = 'pireps';
677
-    		    $data['id_source'] = $id_source;
678
-		    $data['datetime'] = date('Y-m-d H:i:s');
679
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
680
-		    if ($line['icon'] == 'plane') {
652
+			foreach ($all_data['pireps'] as $line) {
653
+			$data = array();
654
+			$data['id'] = $line['id'];
655
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
656
+			$data['ident'] = $line['callsign']; // ident
657
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
658
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
659
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
660
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
661
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
662
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
663
+			$data['latitude'] = $line['lat']; // lat
664
+			$data['longitude'] = $line['lon']; // long
665
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
666
+			//$data['squawk'] = $line['squawk']; // squawk
667
+			//$data['emergency'] = ''; // emergency
668
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
669
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
670
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
671
+			//$data['arrival_airport_time'] = $line['arrtime'];
672
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
673
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
674
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
675
+			else $data['info'] = '';
676
+			$data['format_source'] = 'pireps';
677
+				$data['id_source'] = $id_source;
678
+			$data['datetime'] = date('Y-m-d H:i:s');
679
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
680
+			if ($line['icon'] == 'plane') {
681 681
 			$SI->add($data);
682
-		    //    print_r($data);
683
-    		    } elseif ($line['icon'] == 'ct') {
682
+			//    print_r($data);
683
+				} elseif ($line['icon'] == 'ct') {
684 684
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
685 685
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
686 686
 			$typec = substr($data['ident'],-3);
@@ -695,163 +695,163 @@  discard block
 block discarded – undo
695 695
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
696 696
 			else $data['type'] = 'Observer';
697 697
 			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']);
698
-		    }
699
-		    unset($data);
698
+			}
699
+			unset($data);
700
+		}
700 701
 		}
701
-	    }
702
-    	    //$last_exec['pirepsjson'] = time();
703
-    	    $last_exec[$id]['last'] = time();
704
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
705
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
706
-	    //$buffer = $Common->getData($hosts[$id]);
707
-	    if ($globalDebug) echo 'Get Data...'."\n";
708
-	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
710
-	    if ($buffer != '' && is_array($all_data)) {
702
+			//$last_exec['pirepsjson'] = time();
703
+			$last_exec[$id]['last'] = time();
704
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
705
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
706
+		//$buffer = $Common->getData($hosts[$id]);
707
+		if ($globalDebug) echo 'Get Data...'."\n";
708
+		$buffer = $Common->getData($value['host']);
709
+		$all_data = json_decode($buffer,true);
710
+		if ($buffer != '' && is_array($all_data)) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data as $line) {
713
-	    	    $data = array();
714
-	    	    //$data['id'] = $line['id']; // id not usable
715
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
716
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
717
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
718
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
719
-	    	    $data['ident'] = $line['flightnum']; // ident
720
-	    	    $data['altitude'] = $line['alt']; // altitude
721
-	    	    $data['speed'] = $line['gs']; // speed
722
-	    	    $data['heading'] = $line['heading']; // heading
723
-	    	    $data['latitude'] = $line['lat']; // lat
724
-	    	    $data['longitude'] = $line['lng']; // long
725
-	    	    $data['verticalrate'] = ''; // verticale rate
726
-	    	    $data['squawk'] = ''; // squawk
727
-	    	    $data['emergency'] = ''; // emergency
728
-	    	    //$data['datetime'] = $line['lastupdate'];
729
-	    	    $data['last_update'] = $line['lastupdate'];
730
-		    $data['datetime'] = date('Y-m-d H:i:s');
731
-	    	    $data['departure_airport_icao'] = $line['depicao'];
732
-	    	    $data['departure_airport_time'] = $line['deptime'];
733
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
734
-    		    $data['arrival_airport_time'] = $line['arrtime'];
735
-    		    $data['registration'] = $line['aircraft'];
736
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
737
-		    if (isset($line['aircraftname'])) {
713
+				$data = array();
714
+				//$data['id'] = $line['id']; // id not usable
715
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
716
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
717
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
718
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
719
+				$data['ident'] = $line['flightnum']; // ident
720
+				$data['altitude'] = $line['alt']; // altitude
721
+				$data['speed'] = $line['gs']; // speed
722
+				$data['heading'] = $line['heading']; // heading
723
+				$data['latitude'] = $line['lat']; // lat
724
+				$data['longitude'] = $line['lng']; // long
725
+				$data['verticalrate'] = ''; // verticale rate
726
+				$data['squawk'] = ''; // squawk
727
+				$data['emergency'] = ''; // emergency
728
+				//$data['datetime'] = $line['lastupdate'];
729
+				$data['last_update'] = $line['lastupdate'];
730
+			$data['datetime'] = date('Y-m-d H:i:s');
731
+				$data['departure_airport_icao'] = $line['depicao'];
732
+				$data['departure_airport_time'] = $line['deptime'];
733
+				$data['arrival_airport_icao'] = $line['arricao'];
734
+				$data['arrival_airport_time'] = $line['arrtime'];
735
+				$data['registration'] = $line['aircraft'];
736
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
737
+			if (isset($line['aircraftname'])) {
738 738
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
739 739
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
740
-	    		$aircraft_data = explode('-',$line['aircraftname']);
741
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
742
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
743
-	    		else {
744
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
745
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
746
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
747
-	    		}
748
-	    	    }
749
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
750
-    		    $data['id_source'] = $id_source;
751
-	    	    $data['format_source'] = 'phpvmacars';
752
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
753
-		    $SI->add($data);
754
-		    unset($data);
740
+				$aircraft_data = explode('-',$line['aircraftname']);
741
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
742
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
743
+				else {
744
+					$aircraft_data = explode(' ',$line['aircraftname']);
745
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
746
+					else $data['aircraft_icao'] = $line['aircraftname'];
747
+				}
748
+				}
749
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
750
+				$data['id_source'] = $id_source;
751
+				$data['format_source'] = 'phpvmacars';
752
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
753
+			$SI->add($data);
754
+			unset($data);
755 755
 		}
756 756
 		if ($globalDebug) echo 'No more data...'."\n";
757 757
 		unset($buffer);
758 758
 		unset($all_data);
759
-	    }
760
-    	    //$last_exec['phpvmacars'] = time();
761
-    	    $last_exec[$id]['last'] = time();
762
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
-	    //$buffer = $Common->getData($hosts[$id]);
764
-	    if ($globalDebug) echo 'Get Data...'."\n";
765
-	    $buffer = $Common->getData($value['host']);
766
-	    $all_data = json_decode($buffer,true);
767
-	    if ($buffer != '' && is_array($all_data)) {
759
+		}
760
+			//$last_exec['phpvmacars'] = time();
761
+			$last_exec[$id]['last'] = time();
762
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
+		//$buffer = $Common->getData($hosts[$id]);
764
+		if ($globalDebug) echo 'Get Data...'."\n";
765
+		$buffer = $Common->getData($value['host']);
766
+		$all_data = json_decode($buffer,true);
767
+		if ($buffer != '' && is_array($all_data)) {
768 768
 		$reset = 0;
769 769
 		foreach ($all_data as $line) {
770
-	    	    $data = array();
771
-	    	    //$data['id'] = $line['id']; // id not usable
772
-	    	    $data['id'] = trim($line['flight_id']);
773
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
774
-	    	    $data['pilot_name'] = $line['pilot_name'];
775
-	    	    $data['pilot_id'] = $line['pilot_id'];
776
-	    	    $data['ident'] = trim($line['callsign']); // ident
777
-	    	    $data['altitude'] = $line['altitude']; // altitude
778
-	    	    $data['speed'] = $line['gs']; // speed
779
-	    	    $data['heading'] = $line['heading']; // heading
780
-	    	    $data['latitude'] = $line['latitude']; // lat
781
-	    	    $data['longitude'] = $line['longitude']; // long
782
-	    	    $data['verticalrate'] = ''; // verticale rate
783
-	    	    $data['squawk'] = ''; // squawk
784
-	    	    $data['emergency'] = ''; // emergency
785
-	    	    //$data['datetime'] = $line['lastupdate'];
786
-	    	    $data['last_update'] = $line['last_update'];
787
-		    $data['datetime'] = date('Y-m-d H:i:s');
788
-	    	    $data['departure_airport_icao'] = $line['departure'];
789
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
790
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
791
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
792
-    		    //$data['registration'] = $line['aircraft'];
793
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
794
-	    	    $data['aircraft_icao'] = $line['plane_type'];
795
-    		    $data['id_source'] = $id_source;
796
-	    	    $data['format_source'] = 'vam';
797
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
798
-		    $SI->add($data);
799
-		    unset($data);
770
+				$data = array();
771
+				//$data['id'] = $line['id']; // id not usable
772
+				$data['id'] = trim($line['flight_id']);
773
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
774
+				$data['pilot_name'] = $line['pilot_name'];
775
+				$data['pilot_id'] = $line['pilot_id'];
776
+				$data['ident'] = trim($line['callsign']); // ident
777
+				$data['altitude'] = $line['altitude']; // altitude
778
+				$data['speed'] = $line['gs']; // speed
779
+				$data['heading'] = $line['heading']; // heading
780
+				$data['latitude'] = $line['latitude']; // lat
781
+				$data['longitude'] = $line['longitude']; // long
782
+				$data['verticalrate'] = ''; // verticale rate
783
+				$data['squawk'] = ''; // squawk
784
+				$data['emergency'] = ''; // emergency
785
+				//$data['datetime'] = $line['lastupdate'];
786
+				$data['last_update'] = $line['last_update'];
787
+			$data['datetime'] = date('Y-m-d H:i:s');
788
+				$data['departure_airport_icao'] = $line['departure'];
789
+				//$data['departure_airport_time'] = $line['departure_time'];
790
+				$data['arrival_airport_icao'] = $line['arrival'];
791
+				//$data['arrival_airport_time'] = $line['arrival_time'];
792
+				//$data['registration'] = $line['aircraft'];
793
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
794
+				$data['aircraft_icao'] = $line['plane_type'];
795
+				$data['id_source'] = $id_source;
796
+				$data['format_source'] = 'vam';
797
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
798
+			$SI->add($data);
799
+			unset($data);
800 800
 		}
801 801
 		if ($globalDebug) echo 'No more data...'."\n";
802 802
 		unset($buffer);
803 803
 		unset($all_data);
804
-	    }
805
-    	    //$last_exec['phpvmacars'] = time();
806
-    	    $last_exec[$id]['last'] = time();
804
+		}
805
+			//$last_exec['phpvmacars'] = time();
806
+			$last_exec[$id]['last'] = time();
807 807
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
808 808
 	} 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') {
809
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
810
-    	    //$last_exec[$id]['last'] = time();
809
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
810
+			//$last_exec[$id]['last'] = time();
811 811
 
812
-	    //$read = array( $sockets[$id] );
813
-	    $read = $sockets;
814
-	    $write = NULL;
815
-	    $e = NULL;
816
-	    $n = socket_select($read, $write, $e, $timeout);
817
-	    if ($e != NULL) var_dump($e);
818
-	    if ($n > 0) {
812
+		//$read = array( $sockets[$id] );
813
+		$read = $sockets;
814
+		$write = NULL;
815
+		$e = NULL;
816
+		$n = socket_select($read, $write, $e, $timeout);
817
+		if ($e != NULL) var_dump($e);
818
+		if ($n > 0) {
819 819
 		$reset = 0;
820 820
 		foreach ($read as $nb => $r) {
821
-		    //$value = $formats[$nb];
822
-		    $format = $globalSources[$nb]['format'];
823
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
824
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
825
-        	    } else {
826
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
827
-	    	    }
828
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
829
-        	    //echo $buffer."\n";
830
-		    // lets play nice and handle signals such as ctrl-c/kill properly
831
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
832
-		    $error = false;
833
-		    //$SI::del();
834
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
835
-		    // SBS format is CSV format
836
-		    if ($buffer != '') {
821
+			//$value = $formats[$nb];
822
+			$format = $globalSources[$nb]['format'];
823
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
824
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
825
+				} else {
826
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
827
+				}
828
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
829
+				//echo $buffer."\n";
830
+			// lets play nice and handle signals such as ctrl-c/kill properly
831
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
832
+			$error = false;
833
+			//$SI::del();
834
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
835
+			// SBS format is CSV format
836
+			if ($buffer != '') {
837 837
 			$tt[$format] = 0;
838 838
 			if ($format == 'acarssbs3') {
839
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
840
-			    $ACARS->add(trim($buffer));
841
-			    $ACARS->deleteLiveAcarsData();
839
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
840
+				$ACARS->add(trim($buffer));
841
+				$ACARS->deleteLiveAcarsData();
842 842
 			} elseif ($format == 'raw') {
843
-			    // AVR format
844
-			    $data = $SBS->parse($buffer);
845
-			    if (is_array($data)) {
843
+				// AVR format
844
+				$data = $SBS->parse($buffer);
845
+				if (is_array($data)) {
846 846
 				$data['datetime'] = date('Y-m-d H:i:s');
847 847
 				$data['format_source'] = 'raw';
848 848
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
849
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
850
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
851
-                            }
852
-                        } elseif ($format == 'flightgearsp') {
853
-                    	    //echo $buffer."\n";
854
-                    	    if (strlen($buffer) > 5) {
849
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
850
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
851
+							}
852
+						} elseif ($format == 'flightgearsp') {
853
+							//echo $buffer."\n";
854
+							if (strlen($buffer) > 5) {
855 855
 				$line = explode(',',$buffer);
856 856
 				$data = array();
857 857
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -867,117 +867,117 @@  discard block
 block discarded – undo
867 867
 				$data['format_source'] = 'flightgearsp';
868 868
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
869 869
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
870
-			    }
871
-                        } elseif ($format == 'acars') {
872
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
873
-			    $ACARS->add(trim($buffer));
874
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
875
-			    $ACARS->deleteLiveAcarsData();
870
+				}
871
+						} elseif ($format == 'acars') {
872
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
873
+				$ACARS->add(trim($buffer));
874
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
875
+				$ACARS->deleteLiveAcarsData();
876 876
 			} elseif ($format == 'flightgearmp') {
877
-			    if (substr($buffer,0,1) != '#') {
877
+				if (substr($buffer,0,1) != '#') {
878 878
 				$data = array();
879 879
 				//echo $buffer."\n";
880 880
 				$line = explode(' ',$buffer);
881 881
 				if (count($line) == 11) {
882
-				    $userserver = explode('@',$line[0]);
883
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
884
-				    $data['ident'] = $userserver[0];
885
-				    $data['registration'] = $userserver[0];
886
-				    $data['latitude'] = $line[4];
887
-				    $data['longitude'] = $line[5];
888
-				    $data['altitude'] = $line[6];
889
-				    $data['datetime'] = date('Y-m-d H:i:s');
890
-				    $aircraft_type = $line[10];
891
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
892
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
893
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
882
+					$userserver = explode('@',$line[0]);
883
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
884
+					$data['ident'] = $userserver[0];
885
+					$data['registration'] = $userserver[0];
886
+					$data['latitude'] = $line[4];
887
+					$data['longitude'] = $line[5];
888
+					$data['altitude'] = $line[6];
889
+					$data['datetime'] = date('Y-m-d H:i:s');
890
+					$aircraft_type = $line[10];
891
+					$aircraft_type = preg_split(':/:',$aircraft_type);
892
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
893
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
894
+				}
894 895
 				}
895
-			    }
896 896
 			} elseif ($format == 'beast') {
897
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
898
-			    die;
897
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
898
+				die;
899 899
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
900
-			    $line = explode("\t", $buffer);
901
-			    for($k = 0; $k < count($line); $k=$k+2) {
900
+				$line = explode("\t", $buffer);
901
+				for($k = 0; $k < count($line); $k=$k+2) {
902 902
 				$key = $line[$k];
903
-			        $lined[$key] = $line[$k+1];
904
-			    }
905
-    			    if (count($lined) > 3) {
906
-    				$data['hex'] = $lined['hexid'];
907
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
908
-    				$data['datetime'] = date('Y-m-d H:i:s');;
909
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
910
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
911
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
912
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
913
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
914
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
915
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
916
-    				$data['id_source'] = $id_source;
917
-    				$data['format_source'] = 'tsv';
918
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
919
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
920
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
921
-    				unset($lined);
922
-    				unset($data);
923
-    			    } else $error = true;
903
+					$lined[$key] = $line[$k+1];
904
+				}
905
+					if (count($lined) > 3) {
906
+					$data['hex'] = $lined['hexid'];
907
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
908
+					$data['datetime'] = date('Y-m-d H:i:s');;
909
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
910
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
911
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
912
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
913
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
914
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
915
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
916
+					$data['id_source'] = $id_source;
917
+					$data['format_source'] = 'tsv';
918
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
919
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
920
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
921
+					unset($lined);
922
+					unset($data);
923
+					} else $error = true;
924 924
 			} elseif ($format == 'aprs' && $use_aprs) {
925
-			    if ($aprs_connect == 0) {
925
+				if ($aprs_connect == 0) {
926 926
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
927 927
 				$aprs_connect = 1;
928
-			    }
928
+				}
929 929
 			    
930
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
930
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
931 931
 				$aprs_last_tx = time();
932 932
 				$data_aprs = "# Keep alive";
933 933
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
934
-			    }
934
+				}
935 935
 			    
936
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
937
-			    $buffer = str_replace('APRS <- ','',$buffer);
938
-			    $buffer = str_replace('APRS -> ','',$buffer);
939
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
936
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
937
+				$buffer = str_replace('APRS <- ','',$buffer);
938
+				$buffer = str_replace('APRS -> ','',$buffer);
939
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
940 940
 				$line = $APRS->parse($buffer);
941 941
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
942
-				    $aprs_last_tx = time();
943
-				    $data = array();
944
-				    //print_r($line);
945
-				    $data['hex'] = $line['address'];
946
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
947
-				    //$data['datetime'] = date('Y-m-d H:i:s');
948
-				    $data['ident'] = $line['ident'];
949
-				    $data['latitude'] = $line['latitude'];
950
-				    $data['longitude'] = $line['longitude'];
951
-				    //$data['verticalrate'] = $line[16];
952
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
953
-				    else $data['speed'] = 0;
954
-				    $data['altitude'] = $line['altitude'];
955
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
956
-				    //else $data['heading'] = 0;
957
-				    $data['aircraft_type'] = $line['stealth'];
958
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
959
-    				    $data['id_source'] = $id_source;
960
-				    $data['format_source'] = 'aprs';
961
-				    $data['source_name'] = $line['source'];
962
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
963
-				    $currentdate = date('Y-m-d H:i:s');
964
-				    $aprsdate = strtotime($data['datetime']);
965
-				    // Accept data if time <= system time + 20s
966
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
967
-				    else {
942
+					$aprs_last_tx = time();
943
+					$data = array();
944
+					//print_r($line);
945
+					$data['hex'] = $line['address'];
946
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
947
+					//$data['datetime'] = date('Y-m-d H:i:s');
948
+					$data['ident'] = $line['ident'];
949
+					$data['latitude'] = $line['latitude'];
950
+					$data['longitude'] = $line['longitude'];
951
+					//$data['verticalrate'] = $line[16];
952
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
953
+					else $data['speed'] = 0;
954
+					$data['altitude'] = $line['altitude'];
955
+					if (isset($line['course'])) $data['heading'] = $line['course'];
956
+					//else $data['heading'] = 0;
957
+					$data['aircraft_type'] = $line['stealth'];
958
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
959
+						$data['id_source'] = $id_source;
960
+					$data['format_source'] = 'aprs';
961
+					$data['source_name'] = $line['source'];
962
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
963
+					$currentdate = date('Y-m-d H:i:s');
964
+					$aprsdate = strtotime($data['datetime']);
965
+					// Accept data if time <= system time + 20s
966
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
967
+					else {
968 968
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
969 969
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
970
-				    }
971
-				    unset($data);
970
+					}
971
+					unset($data);
972 972
 				} 
973 973
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
974 974
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
975
-			    }
975
+				}
976 976
 			} else {
977
-			    $line = explode(',', $buffer);
978
-    			    if (count($line) > 20) {
979
-    			    	$data['hex'] = $line[4];
980
-    				/*
977
+				$line = explode(',', $buffer);
978
+					if (count($line) > 20) {
979
+						$data['hex'] = $line[4];
980
+					/*
981 981
     				$data['datetime'] = $line[6].' '.$line[7];
982 982
     					date_default_timezone_set($globalTimezone);
983 983
     					$datetime = new DateTime($data['datetime']);
@@ -985,29 +985,29 @@  discard block
 block discarded – undo
985 985
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
986 986
     					date_default_timezone_set('UTC');
987 987
     				*/
988
-    				// Force datetime to current UTC datetime
989
-    				date_default_timezone_set('UTC');
990
-    				$data['datetime'] = date('Y-m-d H:i:s');
991
-    				$data['ident'] = trim($line[10]);
992
-    				$data['latitude'] = $line[14];
993
-    				$data['longitude'] = $line[15];
994
-    				$data['verticalrate'] = $line[16];
995
-    				$data['emergency'] = $line[20];
996
-    				$data['speed'] = $line[12];
997
-    				$data['squawk'] = $line[17];
998
-    				$data['altitude'] = $line[11];
999
-    				$data['heading'] = $line[13];
1000
-    				$data['ground'] = $line[21];
1001
-    				$data['emergency'] = $line[19];
1002
-    				$data['format_source'] = 'sbs';
988
+					// Force datetime to current UTC datetime
989
+					date_default_timezone_set('UTC');
990
+					$data['datetime'] = date('Y-m-d H:i:s');
991
+					$data['ident'] = trim($line[10]);
992
+					$data['latitude'] = $line[14];
993
+					$data['longitude'] = $line[15];
994
+					$data['verticalrate'] = $line[16];
995
+					$data['emergency'] = $line[20];
996
+					$data['speed'] = $line[12];
997
+					$data['squawk'] = $line[17];
998
+					$data['altitude'] = $line[11];
999
+					$data['heading'] = $line[13];
1000
+					$data['ground'] = $line[21];
1001
+					$data['emergency'] = $line[19];
1002
+					$data['format_source'] = 'sbs';
1003 1003
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1004
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1005
-    				$data['id_source'] = $id_source;
1006
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1007
-    				else $error = true;
1008
-    				unset($data);
1009
-    			    } else $error = true;
1010
-			    if ($error) {
1004
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1005
+					$data['id_source'] = $id_source;
1006
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1007
+					else $error = true;
1008
+					unset($data);
1009
+					} else $error = true;
1010
+				if ($error) {
1011 1011
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1012 1012
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1013 1013
 				} else {
@@ -1023,13 +1023,13 @@  discard block
 block discarded – undo
1023 1023
 					connect_all($sourceer);
1024 1024
 					$sourceer = array();
1025 1025
 				}
1026
-			    }
1026
+				}
1027 1027
 			}
1028 1028
 			// Sleep for xxx microseconds
1029 1029
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1030
-		    } else {
1030
+			} else {
1031 1031
 			if ($format == 'flightgearmp') {
1032
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1032
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1033 1033
 				//@socket_close($r);
1034 1034
 				sleep($globalMinFetch);
1035 1035
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1038,9 +1038,9 @@  discard block
 block discarded – undo
1038 1038
 				break;
1039 1039
 				
1040 1040
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1041
-			    if (isset($tt[$format])) $tt[$format]++;
1042
-			    else $tt[$format] = 0;
1043
-			    if ($tt[$format] > 30) {
1041
+				if (isset($tt[$format])) $tt[$format]++;
1042
+				else $tt[$format] = 0;
1043
+				if ($tt[$format] > 30) {
1044 1044
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1045 1045
 				//@socket_close($r);
1046 1046
 				sleep(2);
@@ -1051,23 +1051,23 @@  discard block
 block discarded – undo
1051 1051
 				//connect_all($globalSources);
1052 1052
 				$tt[$format]=0;
1053 1053
 				break;
1054
-			    }
1054
+				}
1055
+			}
1055 1056
 			}
1056
-		    }
1057 1057
 		}
1058
-	    } else {
1058
+		} else {
1059 1059
 		$error = socket_strerror(socket_last_error());
1060 1060
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1061 1061
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1062 1062
 			if (isset($globalDebug)) echo "Restarting...\n";
1063 1063
 			// Restart the script if possible
1064 1064
 			if (is_array($sockets)) {
1065
-			    if ($globalDebug) echo "Shutdown all sockets...";
1065
+				if ($globalDebug) echo "Shutdown all sockets...";
1066 1066
 			    
1067
-			    foreach ($sockets as $sock) {
1067
+				foreach ($sockets as $sock) {
1068 1068
 				@socket_shutdown($sock,2);
1069 1069
 				@socket_close($sock);
1070
-			    }
1070
+				}
1071 1071
 			    
1072 1072
 			}
1073 1073
 			if ($globalDebug) echo "Restart all connections...";
@@ -1078,13 +1078,13 @@  discard block
 block discarded – undo
1078 1078
 			if ($reset > 40) exit('Too many attempts...');
1079 1079
 			connect_all($globalSources);
1080 1080
 		}
1081
-	    }
1081
+		}
1082 1082
 	}
1083 1083
 	if ($globalDaemon === false) {
1084
-	    if ($globalDebug) echo 'Check all...'."\n";
1085
-	    $SI->checkAll();
1084
+		if ($globalDebug) echo 'Check all...'."\n";
1085
+		$SI->checkAll();
1086
+	}
1086 1087
 	}
1087
-    }
1088 1088
 }
1089 1089
 
1090 1090
 ?>
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 	    die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
43
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
44 44
     }
45 45
 }
46 46
 
47
-$options = getopt('s::',array('source::','server','idsource::'));
47
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
@@ -59,17 +59,17 @@  discard block
 block discarded – undo
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61 61
     if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
62
+    $SI = new SpotterServer();
63
+} else $SI = new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65
-$SBS=new SBS();
66
-$ACARS=new ACARS($Connection->db);
67
-$Common=new Common();
65
+$SBS = new SBS();
66
+$ACARS = new ACARS($Connection->db);
67
+$Common = new Common();
68 68
 date_default_timezone_set('UTC');
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
72
+    pcntl_signal(SIGINT, function() {
73 73
         global $sockets;
74 74
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75 75
         die("Bye!\n");
@@ -113,35 +113,35 @@  discard block
 block discarded – undo
113 113
 
114 114
 function connect_all($hosts) {
115 115
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
116
+    global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset;
117 117
     $reset++;
118 118
     if ($globalDebug) echo 'Connect to all...'."\n";
119 119
     foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
123
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
+            if (preg_match('/deltadb.txt$/i', $host)) {
125 125
         	//$formats[$id] = 'deltadbtxt';
126 126
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 127
         	//$last_exec['deltadbtxt'] = 0;
128 128
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
129
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
130 130
         	//$formats[$id] = 'vatsimtxt';
131 131
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 132
         	//$last_exec['vatsimtxt'] = 0;
133 133
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
134
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
135 135
         	//$formats[$id] = 'aircraftlistjson';
136 136
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 137
         	//$last_exec['aircraftlistjson'] = 0;
138 138
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
139
+    	    } else if (preg_match('/opensky/i', $host)) {
140 140
         	//$formats[$id] = 'aircraftlistjson';
141 141
         	$globalSources[$id]['format'] = 'opensky';
142 142
         	//$last_exec['aircraftlistjson'] = 0;
143 143
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
144
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
145 145
         	//$formats[$id] = 'radarvirtueljson';
146 146
         	$globalSources[$id]['format'] = 'radarvirtueljson';
147 147
         	//$last_exec['radarvirtueljson'] = 0;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 151
         	    exit(0);
152 152
         	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
153
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
154 154
         	//$formats[$id] = 'planeupdatefaa';
155 155
         	$globalSources[$id]['format'] = 'planeupdatefaa';
156 156
         	//$last_exec['planeupdatefaa'] = 0;
@@ -159,26 +159,26 @@  discard block
 block discarded – undo
159 159
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160 160
         	    exit(0);
161 161
         	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
162
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
163 163
         	//$formats[$id] = 'phpvmacars';
164 164
         	$globalSources[$id]['format'] = 'phpvmacars';
165 165
         	//$last_exec['phpvmacars'] = 0;
166 166
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
167
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
168 168
         	//$formats[$id] = 'phpvmacars';
169 169
         	$globalSources[$id]['format'] = 'vam';
170 170
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
171
+            } else if (preg_match('/whazzup/i', $host)) {
172 172
         	//$formats[$id] = 'whazzup';
173 173
         	$globalSources[$id]['format'] = 'whazzup';
174 174
         	//$last_exec['whazzup'] = 0;
175 175
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
176
+            } else if (preg_match('/recentpireps/i', $host)) {
177 177
         	//$formats[$id] = 'pirepsjson';
178 178
         	$globalSources[$id]['format'] = 'pirepsjson';
179 179
         	//$last_exec['pirepsjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
181
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
182 182
         	//$formats[$id] = 'fr24json';
183 183
         	$globalSources[$id]['format'] = 'fr24json';
184 184
         	//$last_exec['fr24json'] = 0;
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
         	    exit(0);
189 189
         	}
190 190
             //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
191
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192 192
         	//$formats[$id] = 'tsv';
193 193
         	$globalSources[$id]['format'] = 'tsv';
194 194
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195 195
             }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
196
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
197 197
         	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
198
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
199
+	    $hostport = explode(':', $host);
200 200
 	    if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 		$hostn = $globalSources[$id]['host'];
206 206
 	    }
207 207
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
208
+        	$s = create_socket($hostn, $port, $errno, $errstr);
209 209
     	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
210
+        	$s = create_socket_udp($hostn, $port, $errno, $errstr);
211 211
 	    }
212 212
 	    if ($s) {
213 213
     	        $sockets[$id] = $s;
214 214
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
215
+		    if (preg_match('/aprs/', $hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
254 254
 else $timeout = 20;
255 255
 $errno = '';
256
-$errstr='';
256
+$errstr = '';
257 257
 
258 258
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
259 259
 /* Initiate connections to all the hosts simultaneously */
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
 
283 283
 if ($use_aprs) {
284 284
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
285
-	$APRS=new APRS();
285
+	$APRS = new APRS();
286 286
 	$aprs_connect = 0;
287 287
 	$aprs_keep = 120;
288 288
 	$aprs_last_tx = time();
289 289
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
290
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
290
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
291 291
 	//else $aprs_version = 'Perl Example App';
292 292
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
293
-	else $aprs_ssid = 'FAM-'.str_replace(' ','_',$globalName);
293
+	else $aprs_ssid = 'FAM-'.str_replace(' ', '_', $globalName);
294 294
 	//else $aprs_ssid = 'PerlEx';
295 295
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
296
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
296
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
297 297
 	if ($aprs_full) $aprs_filter = '';
298 298
 	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} vers {$aprs_version} filter {$aprs_filter}\n";
299 299
 	else $aprs_login = "user {$aprs_ssid} vers {$aprs_version}\n";
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
 sleep(1);
305 305
 if ($globalDebug) echo "SCAN MODE \n\n";
306 306
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
307
-$endtime = time()+$globalCronEnd;
307
+$endtime = time() + $globalCronEnd;
308 308
 $i = 1;
309 309
 $tt = array();
310 310
 // Delete all ATC
311 311
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
312
-	$ATC=new ATC($Connection->db);
312
+	$ATC = new ATC($Connection->db);
313 313
 }
314 314
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
315 315
 	$ATC->deleteAll();
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 
318 318
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 319
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
320
+    if (!$globalDaemon) $i = $endtime - time();
321 321
     // Delete old ATC
322 322
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323 323
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 	if ($max != $globalMinFetch) {
333 333
 	    if ($globalDebug) echo 'Sleeping...'."\n";
334
-	    sleep($globalMinFetch-$max+2);
334
+	    sleep($globalMinFetch - $max + 2);
335 335
 	}
336 336
     }
337 337
 
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 	    //$buffer = $Common->getData($hosts[$id]);
345 345
 	    $buffer = $Common->getData($value['host']);
346 346
 	    if ($buffer != '') $reset = 0;
347
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
348
-	    $buffer = explode('\n',$buffer);
347
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
348
+	    $buffer = explode('\n', $buffer);
349 349
 	    foreach ($buffer as $line) {
350 350
     		if ($line != '' && count($line) > 7) {
351 351
     		    $line = explode(',', $line);
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
375 375
 	    //$buffer = $Common->getData($hosts[$id]);
376 376
 	    $buffer = $Common->getData($value['host']);
377
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
378
-	    $buffer = explode('\n',$buffer);
377
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
378
+	    $buffer = explode('\n', $buffer);
379 379
 	    $reset = 0;
380 380
 	    foreach ($buffer as $line) {
381 381
     		if ($line != '') {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
387 387
 			$data['pilot_id'] = $line[1];
388 388
 			$data['pilot_name'] = $line[2];
389
-			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
389
+			$data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT);
390 390
 			$data['ident'] = $line[0]; // ident
391 391
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
392 392
 			$data['speed'] = $line[8]; // speed
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
403 403
 			//if (isset($line[37])) $data['last_update'] = $line[37];
404 404
 		        $data['departure_airport_icao'] = $line[11];
405
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
406 406
 		        $data['arrival_airport_icao'] = $line[13];
407 407
 			$data['frequency'] = $line[4];
408 408
 			$data['type'] = $line[18];
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     			$data['id_source'] = $id_source;
412 412
 	    		//$data['arrival_airport_time'] = ;
413 413
 	    		if ($line[9] != '') {
414
-	    		    $aircraft_data = explode('/',$line[9]);
414
+	    		    $aircraft_data = explode('/', $line[9]);
415 415
 	    		    if (isset($aircraft_data[1])) {
416 416
 	    			$data['aircraft_icao'] = $aircraft_data[1];
417 417
 	    		    }
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
     			if ($line[3] == 'PILOT') $SI->add($data);
426 426
 			elseif ($line[3] == 'ATC') {
427 427
 				//print_r($data);
428
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
429
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
430
-				$typec = substr($data['ident'],-3);
428
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
429
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
430
+				$typec = substr($data['ident'], -3);
431 431
 				if ($typec == 'APP') $data['type'] = 'Approach';
432 432
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
433 433
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
439 439
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
440 440
 				if (!isset($data['source_name'])) $data['source_name'] = '';
441
-				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']);
441
+				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']);
442 442
 			}
443 443
     			unset($data);
444 444
     		    }
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
449 449
     	    $last_exec[$id]['last'] = time();
450 450
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
451 451
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
452
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
452
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
453 453
 	    if ($buffer != '') {
454
-	    $all_data = json_decode($buffer,true);
454
+	    $all_data = json_decode($buffer, true);
455 455
 	    if (isset($all_data['acList'])) {
456 456
 		$reset = 0;
457 457
 		foreach ($all_data['acList'] as $line) {
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
508 508
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
509 509
 	    $buffer = $Common->getData($value['host']);
510
-	    $all_data = json_decode($buffer,true);
510
+	    $all_data = json_decode($buffer, true);
511 511
 	    if (isset($all_data['planes'])) {
512 512
 		$reset = 0;
513 513
 		foreach ($all_data['planes'] as $key => $line) {
@@ -524,12 +524,12 @@  discard block
 block discarded – undo
524 524
 		    $data['emergency'] = ''; // emergency
525 525
 		    $data['registration'] = $line[2];
526 526
 		    $data['aircraft_icao'] = $line[0];
527
-		    $deparr = explode('-',$line[1]);
527
+		    $deparr = explode('-', $line[1]);
528 528
 		    if (count($deparr) == 2) {
529 529
 			$data['departure_airport_icao'] = $deparr[0];
530 530
 			$data['arrival_airport_icao'] = $deparr[1];
531 531
 		    }
532
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
533 533
 	    	    $data['format_source'] = 'planeupdatefaa';
534 534
     		    $data['id_source'] = $id_source;
535 535
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
     	    $last_exec[$id]['last'] = time();
542 542
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
543 543
 	    $buffer = $Common->getData($value['host']);
544
-	    $all_data = json_decode($buffer,true);
544
+	    $all_data = json_decode($buffer, true);
545 545
 	    if (isset($all_data['states'])) {
546 546
 		$reset = 0;
547 547
 		foreach ($all_data['states'] as $key => $line) {
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		    //$data['emergency'] = ''; // emergency
559 559
 		    //$data['registration'] = $line[2];
560 560
 		    //$data['aircraft_icao'] = $line[0];
561
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
562 562
 	    	    $data['format_source'] = 'opensky';
563 563
     		    $data['id_source'] = $id_source;
564 564
 		    $SI->add($data);
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
572 572
 	    //$buffer = $Common->getData($hosts[$id]);
573 573
 	    $buffer = $Common->getData($value['host']);
574
-	    $all_data = json_decode($buffer,true);
574
+	    $all_data = json_decode($buffer, true);
575 575
 	    if (!empty($all_data)) $reset = 0;
576 576
 	    foreach ($all_data as $key => $line) {
577 577
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -603,11 +603,11 @@  discard block
 block discarded – undo
603 603
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
604 604
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
605 605
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
606
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
606
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
607 607
 	    //echo $buffer;
608
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
609
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
610
-	    $all_data = json_decode($buffer,true);
608
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
609
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
610
+	    $all_data = json_decode($buffer, true);
611 611
 	    if (json_last_error() != JSON_ERROR_NONE) {
612 612
 		die(json_last_error_msg());
613 613
 	    }
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 			//$data['departure_airport_iata'] = $line[11];
631 631
 			//$data['arrival_airport_iata'] = $line[12];
632 632
 	    		//$data['emergency'] = ''; // emergency
633
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
633
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
634 634
 	    		$data['format_source'] = 'radarvirtueljson';
635 635
     			$data['id_source'] = $id_source;
636 636
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646 646
 	    //$buffer = $Common->getData($hosts[$id]);
647 647
 	    $buffer = $Common->getData($value['host'].'?'.time());
648
-	    $all_data = json_decode(utf8_encode($buffer),true);
648
+	    $all_data = json_decode(utf8_encode($buffer), true);
649 649
 	    
650 650
 	    if (isset($all_data['pireps'])) {
651 651
 		$reset = 0;
652 652
 	        foreach ($all_data['pireps'] as $line) {
653 653
 		    $data = array();
654 654
 		    $data['id'] = $line['id'];
655
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
656 656
 		    $data['ident'] = $line['callsign']; // ident
657 657
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
658 658
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -681,9 +681,9 @@  discard block
 block discarded – undo
681 681
 			$SI->add($data);
682 682
 		    //    print_r($data);
683 683
     		    } elseif ($line['icon'] == 'ct') {
684
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
685
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
686
-			$typec = substr($data['ident'],-3);
684
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
685
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
686
+			$typec = substr($data['ident'], -3);
687 687
 			$data['type'] = '';
688 688
 			if ($typec == 'APP') $data['type'] = 'Approach';
689 689
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
695 695
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
696 696
 			else $data['type'] = 'Observer';
697
-			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']);
697
+			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']);
698 698
 		    }
699 699
 		    unset($data);
700 700
 		}
@@ -706,14 +706,14 @@  discard block
 block discarded – undo
706 706
 	    //$buffer = $Common->getData($hosts[$id]);
707 707
 	    if ($globalDebug) echo 'Get Data...'."\n";
708 708
 	    $buffer = $Common->getData($value['host']);
709
-	    $all_data = json_decode($buffer,true);
709
+	    $all_data = json_decode($buffer, true);
710 710
 	    if ($buffer != '' && is_array($all_data)) {
711 711
 		$reset = 0;
712 712
 		foreach ($all_data as $line) {
713 713
 	    	    $data = array();
714 714
 	    	    //$data['id'] = $line['id']; // id not usable
715 715
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
716
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
717 717
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
718 718
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
719 719
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -736,12 +736,12 @@  discard block
 block discarded – undo
736 736
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
737 737
 		    if (isset($line['aircraftname'])) {
738 738
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
739
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
740
-	    		$aircraft_data = explode('-',$line['aircraftname']);
739
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
740
+	    		$aircraft_data = explode('-', $line['aircraftname']);
741 741
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
742 742
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
743 743
 	    		else {
744
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
744
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
745 745
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
746 746
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
747 747
 	    		}
@@ -763,14 +763,14 @@  discard block
 block discarded – undo
763 763
 	    //$buffer = $Common->getData($hosts[$id]);
764 764
 	    if ($globalDebug) echo 'Get Data...'."\n";
765 765
 	    $buffer = $Common->getData($value['host']);
766
-	    $all_data = json_decode($buffer,true);
766
+	    $all_data = json_decode($buffer, true);
767 767
 	    if ($buffer != '' && is_array($all_data)) {
768 768
 		$reset = 0;
769 769
 		foreach ($all_data as $line) {
770 770
 	    	    $data = array();
771 771
 	    	    //$data['id'] = $line['id']; // id not usable
772 772
 	    	    $data['id'] = trim($line['flight_id']);
773
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
774 774
 	    	    $data['pilot_name'] = $line['pilot_name'];
775 775
 	    	    $data['pilot_id'] = $line['pilot_id'];
776 776
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -821,9 +821,9 @@  discard block
 block discarded – undo
821 821
 		    //$value = $formats[$nb];
822 822
 		    $format = $globalSources[$nb]['format'];
823 823
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
824
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
825 825
         	    } else {
826
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
827 827
 	    	    }
828 828
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
829 829
         	    //echo $buffer."\n";
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
832 832
 		    $error = false;
833 833
 		    //$SI::del();
834
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
835 835
 		    // SBS format is CSV format
836 836
 		    if ($buffer != '') {
837 837
 			$tt[$format] = 0;
@@ -852,10 +852,10 @@  discard block
 block discarded – undo
852 852
                         } elseif ($format == 'flightgearsp') {
853 853
                     	    //echo $buffer."\n";
854 854
                     	    if (strlen($buffer) > 5) {
855
-				$line = explode(',',$buffer);
855
+				$line = explode(',', $buffer);
856 856
 				$data = array();
857 857
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
858
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
858
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
859 859
 				$data['ident'] = $line[6];
860 860
 				$data['aircraft_name'] = $line[7];
861 861
 				$data['longitude'] = $line[1];
@@ -866,21 +866,21 @@  discard block
 block discarded – undo
866 866
 				$data['datetime'] = date('Y-m-d H:i:s');
867 867
 				$data['format_source'] = 'flightgearsp';
868 868
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
869
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
869
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
870 870
 			    }
871 871
                         } elseif ($format == 'acars') {
872 872
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
873 873
 			    $ACARS->add(trim($buffer));
874
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
875 875
 			    $ACARS->deleteLiveAcarsData();
876 876
 			} elseif ($format == 'flightgearmp') {
877
-			    if (substr($buffer,0,1) != '#') {
877
+			    if (substr($buffer, 0, 1) != '#') {
878 878
 				$data = array();
879 879
 				//echo $buffer."\n";
880
-				$line = explode(' ',$buffer);
880
+				$line = explode(' ', $buffer);
881 881
 				if (count($line) == 11) {
882
-				    $userserver = explode('@',$line[0]);
883
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
882
+				    $userserver = explode('@', $line[0]);
883
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
884 884
 				    $data['ident'] = $userserver[0];
885 885
 				    $data['registration'] = $userserver[0];
886 886
 				    $data['latitude'] = $line[4];
@@ -888,24 +888,24 @@  discard block
 block discarded – undo
888 888
 				    $data['altitude'] = $line[6];
889 889
 				    $data['datetime'] = date('Y-m-d H:i:s');
890 890
 				    $aircraft_type = $line[10];
891
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
892
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
891
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
892
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
893 893
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
894 894
 				}
895 895
 			    }
896 896
 			} elseif ($format == 'beast') {
897 897
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
898 898
 			    die;
899
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
899
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
900 900
 			    $line = explode("\t", $buffer);
901
-			    for($k = 0; $k < count($line); $k=$k+2) {
901
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
902 902
 				$key = $line[$k];
903
-			        $lined[$key] = $line[$k+1];
903
+			        $lined[$key] = $line[$k + 1];
904 904
 			    }
905 905
     			    if (count($lined) > 3) {
906 906
     				$data['hex'] = $lined['hexid'];
907 907
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
908
-    				$data['datetime'] = date('Y-m-d H:i:s');;
908
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
909 909
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
910 910
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
911 911
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -923,27 +923,27 @@  discard block
 block discarded – undo
923 923
     			    } else $error = true;
924 924
 			} elseif ($format == 'aprs' && $use_aprs) {
925 925
 			    if ($aprs_connect == 0) {
926
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
926
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
927 927
 				$aprs_connect = 1;
928 928
 			    }
929 929
 			    
930
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
930
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
931 931
 				$aprs_last_tx = time();
932 932
 				$data_aprs = "# Keep alive";
933
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
933
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
934 934
 			    }
935 935
 			    
936 936
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
937
-			    $buffer = str_replace('APRS <- ','',$buffer);
938
-			    $buffer = str_replace('APRS -> ','',$buffer);
939
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
937
+			    $buffer = str_replace('APRS <- ', '', $buffer);
938
+			    $buffer = str_replace('APRS -> ', '', $buffer);
939
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
940 940
 				$line = $APRS->parse($buffer);
941 941
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
942 942
 				    $aprs_last_tx = time();
943 943
 				    $data = array();
944 944
 				    //print_r($line);
945 945
 				    $data['hex'] = $line['address'];
946
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
946
+				    $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
947 947
 				    //$data['datetime'] = date('Y-m-d H:i:s');
948 948
 				    $data['ident'] = $line['ident'];
949 949
 				    $data['latitude'] = $line['latitude'];
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 				    $currentdate = date('Y-m-d H:i:s');
964 964
 				    $aprsdate = strtotime($data['datetime']);
965 965
 				    // Accept data if time <= system time + 20s
966
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
966
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
967 967
 				    else {
968 968
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
969 969
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 				connect_all($sourceee);
1050 1050
 				$sourceee = array();
1051 1051
 				//connect_all($globalSources);
1052
-				$tt[$format]=0;
1052
+				$tt[$format] = 0;
1053 1053
 				break;
1054 1054
 			    }
1055 1055
 			}
@@ -1057,7 +1057,7 @@  discard block
 block discarded – undo
1057 1057
 		}
1058 1058
 	    } else {
1059 1059
 		$error = socket_strerror(socket_last_error());
1060
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1060
+		if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1061 1061
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1062 1062
 			if (isset($globalDebug)) echo "Restarting...\n";
1063 1063
 			// Restart the script if possible
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 			    if ($globalDebug) echo "Shutdown all sockets...";
1066 1066
 			    
1067 1067
 			    foreach ($sockets as $sock) {
1068
-				@socket_shutdown($sock,2);
1068
+				@socket_shutdown($sock, 2);
1069 1069
 				@socket_close($sock);
1070 1070
 			    }
1071 1071
 			    
Please login to merge, or discard this patch.
Braces   +546 added lines, -187 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 
17
-if (!isset($globalDebug)) $globalDebug = FALSE;
17
+if (!isset($globalDebug)) {
18
+	$globalDebug = FALSE;
19
+}
18 20
 
19 21
 // Check if schema is at latest version
20 22
 $Connection = new Connection();
@@ -54,13 +56,22 @@  discard block
 block discarded – undo
54 56
     $globalSources = array();
55 57
     $globalSources[] = array('host' => $options['source']);
56 58
 }
57
-if (isset($options['server'])) $globalServer = TRUE;
58
-if (isset($options['idsource'])) $id_source = $options['idsource'];
59
-else $id_source = 1;
59
+if (isset($options['server'])) {
60
+	$globalServer = TRUE;
61
+}
62
+if (isset($options['idsource'])) {
63
+	$id_source = $options['idsource'];
64
+} else {
65
+	$id_source = 1;
66
+}
60 67
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
68
+    if ($globalDebug) {
69
+    	echo "Using Server Mode\n";
70
+    }
62 71
     $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
72
+} else {
73
+	$SI=new SpotterImport($Connection->db);
74
+}
64 75
 //$APRS=new APRS($Connection->db);
65 76
 $SBS=new SBS();
66 77
 $ACARS=new ACARS($Connection->db);
@@ -78,7 +89,9 @@  discard block
 block discarded – undo
78 89
 }
79 90
 
80 91
 // let's try and connect
81
-if ($globalDebug) echo "Connecting...\n";
92
+if ($globalDebug) {
93
+	echo "Connecting...\n";
94
+}
82 95
 $use_aprs = false;
83 96
 $aprs_full = false;
84 97
 $reset = 0;
@@ -87,7 +100,9 @@  discard block
 block discarded – undo
87 100
     $ip = gethostbyname($host);
88 101
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
89 102
     $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
103
+    if (!socket_set_nonblock($s)) {
104
+    	echo "Unable to set nonblock on socket\n";
105
+    }
91 106
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92 107
         return $s;
93 108
     }
@@ -115,7 +130,9 @@  discard block
 block discarded – undo
115 130
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116 131
     global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117 132
     $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
133
+    if ($globalDebug) {
134
+    	echo 'Connect to all...'."\n";
135
+    }
119 136
     foreach ($hosts as $id => $value) {
120 137
 	$host = $value['host'];
121 138
 	$globalSources[$id]['last_exec'] = 0;
@@ -125,27 +142,37 @@  discard block
 block discarded – undo
125 142
         	//$formats[$id] = 'deltadbtxt';
126 143
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 144
         	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
145
+        	if ($globalDebug) {
146
+        		echo "Connect to deltadb source (".$host.")...\n";
147
+        	}
129 148
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130 149
         	//$formats[$id] = 'vatsimtxt';
131 150
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 151
         	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
152
+        	if ($globalDebug) {
153
+        		echo "Connect to vatsim source (".$host.")...\n";
154
+        	}
134 155
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135 156
         	//$formats[$id] = 'aircraftlistjson';
136 157
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 158
         	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
161
+        	}
139 162
     	    } else if (preg_match('/opensky/i',$host)) {
140 163
         	//$formats[$id] = 'aircraftlistjson';
141 164
         	$globalSources[$id]['format'] = 'opensky';
142 165
         	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to opensky source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145 170
         	//$formats[$id] = 'radarvirtueljson';
146 171
         	$globalSources[$id]['format'] = 'radarvirtueljson';
147 172
         	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
175
+        	}
149 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 178
         	    exit(0);
@@ -154,7 +181,9 @@  discard block
 block discarded – undo
154 181
         	//$formats[$id] = 'planeupdatefaa';
155 182
         	$globalSources[$id]['format'] = 'planeupdatefaa';
156 183
         	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
186
+        	}
158 187
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159 188
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160 189
         	    exit(0);
@@ -163,26 +192,36 @@  discard block
 block discarded – undo
163 192
         	//$formats[$id] = 'phpvmacars';
164 193
         	$globalSources[$id]['format'] = 'phpvmacars';
165 194
         	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
195
+        	if ($globalDebug) {
196
+        		echo "Connect to phpvmacars source (".$host.")...\n";
197
+        	}
167 198
             } else if (preg_match('/VAM-json.php$/i',$host)) {
168 199
         	//$formats[$id] = 'phpvmacars';
169 200
         	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
201
+        	if ($globalDebug) {
202
+        		echo "Connect to Vam source (".$host.")...\n";
203
+        	}
171 204
             } else if (preg_match('/whazzup/i',$host)) {
172 205
         	//$formats[$id] = 'whazzup';
173 206
         	$globalSources[$id]['format'] = 'whazzup';
174 207
         	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
208
+        	if ($globalDebug) {
209
+        		echo "Connect to whazzup source (".$host.")...\n";
210
+        	}
176 211
             } else if (preg_match('/recentpireps/i',$host)) {
177 212
         	//$formats[$id] = 'pirepsjson';
178 213
         	$globalSources[$id]['format'] = 'pirepsjson';
179 214
         	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to pirepsjson source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182 219
         	//$formats[$id] = 'fr24json';
183 220
         	$globalSources[$id]['format'] = 'fr24json';
184 221
         	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to fr24 source (".$host.")...\n";
224
+        	}
186 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188 227
         	    exit(0);
@@ -191,10 +230,14 @@  discard block
 block discarded – undo
191 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192 231
         	//$formats[$id] = 'tsv';
193 232
         	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
195 236
             }
196 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
240
+        	}
198 241
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199 242
 	    $hostport = explode(':',$host);
200 243
 	    if (isset($hostport[1])) {
@@ -231,17 +274,25 @@  discard block
 block discarded – undo
231 274
         		//$formats[$id] = 'beast';
232 275
         		$globalSources[$id]['format'] = 'beast';
233 276
 		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
277
+		    } else {
278
+		    	$globalSources[$id]['format'] = 'sbs';
279
+		    }
235 280
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 281
 		}
237
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
282
+		if ($globalDebug) {
283
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
284
+		}
238 285
             } else {
239
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
286
+		if ($globalDebug) {
287
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
288
+		}
240 289
     	    }
241 290
         }
242 291
     }
243 292
 }
244
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
293
+if (!isset($globalMinFetch)) {
294
+	$globalMinFetch = 15;
295
+}
245 296
 
246 297
 // Initialize all
247 298
 $status = array();
@@ -249,13 +300,19 @@  discard block
 block discarded – undo
249 300
 $formats = array();
250 301
 $last_exec = array();
251 302
 $time = time();
252
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
253
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
254
-else $timeout = 20;
303
+if (isset($globalSourcesTimeout)) {
304
+	$timeout = $globalSourcesTimeOut;
305
+} else if (isset($globalSBS1TimeOut)) {
306
+	$timeout = $globalSBS1TimeOut;
307
+} else {
308
+	$timeout = 20;
309
+}
255 310
 $errno = '';
256 311
 $errstr='';
257 312
 
258
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
313
+if (!isset($globalDaemon)) {
314
+	$globalDaemon = TRUE;
315
+}
259 316
 /* Initiate connections to all the hosts simultaneously */
260 317
 //connect_all($hosts);
261 318
 //connect_all($globalSources);
@@ -275,7 +332,9 @@  discard block
 block discarded – undo
275 332
     if (isset($source['format']) && $source['format'] == 'aprs') {
276 333
 	$aprs_connect = 0;
277 334
 	$use_aprs = true;
278
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
335
+	if (isset($source['port']) && $source['port'] == '10152') {
336
+		$aprs_full = true;
337
+	}
279 338
 	break;
280 339
     }
281 340
 }
@@ -286,24 +345,44 @@  discard block
 block discarded – undo
286 345
 	$aprs_connect = 0;
287 346
 	$aprs_keep = 120;
288 347
 	$aprs_last_tx = time();
289
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
290
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
348
+	if (isset($globalAPRSversion)) {
349
+		$aprs_version = $globalAPRSversion;
350
+	} else {
351
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
352
+	}
291 353
 	//else $aprs_version = 'Perl Example App';
292
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
293
-	else $aprs_ssid = 'FAM-'.str_replace(' ','_',$globalName);
354
+	if (isset($globalAPRSssid)) {
355
+		$aprs_ssid = $globalAPRSssid;
356
+	} else {
357
+		$aprs_ssid = 'FAM-'.str_replace(' ','_',$globalName);
358
+	}
294 359
 	//else $aprs_ssid = 'PerlEx';
295
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
296
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
297
-	if ($aprs_full) $aprs_filter = '';
298
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} vers {$aprs_version} filter {$aprs_filter}\n";
299
-	else $aprs_login = "user {$aprs_ssid} vers {$aprs_version}\n";
300
-}
360
+	if (isset($globalAPRSfilter)) {
361
+		$aprs_filter = $globalAPRSfilter;
362
+	} else {
363
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
364
+	}
365
+	if ($aprs_full) {
366
+		$aprs_filter = '';
367
+	}
368
+	if ($aprs_filter != '') {
369
+		$aprs_login = "user {$aprs_ssid} vers {$aprs_version} filter {$aprs_filter}\n";
370
+	} else {
371
+		$aprs_login = "user {$aprs_ssid} vers {$aprs_version}\n";
372
+	}
373
+	}
301 374
 
302 375
 // connected - lets do some work
303
-if ($globalDebug) echo "Connected!\n";
376
+if ($globalDebug) {
377
+	echo "Connected!\n";
378
+}
304 379
 sleep(1);
305
-if ($globalDebug) echo "SCAN MODE \n\n";
306
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
380
+if ($globalDebug) {
381
+	echo "SCAN MODE \n\n";
382
+}
383
+if (!isset($globalCronEnd)) {
384
+	$globalCronEnd = 60;
385
+}
307 386
 $endtime = time()+$globalCronEnd;
308 387
 $i = 1;
309 388
 $tt = array();
@@ -317,20 +396,28 @@  discard block
 block discarded – undo
317 396
 
318 397
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
319 398
 while ($i > 0) {
320
-    if (!$globalDaemon) $i = $endtime-time();
399
+    if (!$globalDaemon) {
400
+    	$i = $endtime-time();
401
+    }
321 402
     // Delete old ATC
322 403
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
323
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
404
+	if ($globalDebug) {
405
+		echo 'Delete old ATC...'."\n";
406
+	}
324 407
         $ATC->deleteOldATC();
325 408
     }
326 409
     
327 410
     if (count($last_exec) > 0) {
328 411
 	$max = $globalMinFetch;
329 412
 	foreach ($last_exec as $last) {
330
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
413
+	    if ((time() - $last['last']) < $max) {
414
+	    	$max = time() - $last['last'];
415
+	    }
331 416
 	}
332 417
 	if ($max != $globalMinFetch) {
333
-	    if ($globalDebug) echo 'Sleeping...'."\n";
418
+	    if ($globalDebug) {
419
+	    	echo 'Sleeping...'."\n";
420
+	    }
334 421
 	    sleep($globalMinFetch-$max+2);
335 422
 	}
336 423
     }
@@ -339,11 +426,15 @@  discard block
 block discarded – undo
339 426
     //foreach ($formats as $id => $value) {
340 427
     foreach ($globalSources as $id => $value) {
341 428
 	date_default_timezone_set('UTC');
342
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
429
+	if (!isset($last_exec[$id]['last'])) {
430
+		$last_exec[$id]['last'] = 0;
431
+	}
343 432
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
344 433
 	    //$buffer = $Common->getData($hosts[$id]);
345 434
 	    $buffer = $Common->getData($value['host']);
346
-	    if ($buffer != '') $reset = 0;
435
+	    if ($buffer != '') {
436
+	    	$reset = 0;
437
+	    }
347 438
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
348 439
 	    $buffer = explode('\n',$buffer);
349 440
 	    foreach ($buffer as $line) {
@@ -352,19 +443,38 @@  discard block
 block discarded – undo
352 443
 	            $data = array();
353 444
 	            $data['hex'] = $line[1]; // hex
354 445
 	            $data['ident'] = $line[2]; // ident
355
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
356
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
357
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
358
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
359
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
446
+	            if (isset($line[3])) {
447
+	            	$data['altitude'] = $line[3];
448
+	            }
449
+	            // altitude
450
+	            if (isset($line[4])) {
451
+	            	$data['speed'] = $line[4];
452
+	            }
453
+	            // speed
454
+	            if (isset($line[5])) {
455
+	            	$data['heading'] = $line[5];
456
+	            }
457
+	            // heading
458
+	            if (isset($line[6])) {
459
+	            	$data['latitude'] = $line[6];
460
+	            }
461
+	            // lat
462
+	            if (isset($line[7])) {
463
+	            	$data['longitude'] = $line[7];
464
+	            }
465
+	            // long
360 466
 	            $data['verticalrate'] = ''; // vertical rate
361 467
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
362 468
 	            $data['emergency'] = ''; // emergency
363 469
 		    $data['datetime'] = date('Y-m-d H:i:s');
364 470
 		    $data['format_source'] = 'deltadbtxt';
365 471
     		    $data['id_source'] = $id_source;
366
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
367
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
472
+		    if (isset($value['name']) && $value['name'] != '') {
473
+		    	$data['source_name'] = $value['name'];
474
+		    }
475
+		    if (isset($value['sourcestats'])) {
476
+		    	$data['sourcestats'] = $value['sourcestats'];
477
+		    }
368 478
     		    $SI->add($data);
369 479
 		    unset($data);
370 480
     		}
@@ -382,16 +492,28 @@  discard block
 block discarded – undo
382 492
     		    $line = explode(':', $line);
383 493
     		    if (count($line) > 30 && $line[0] != 'callsign') {
384 494
 			$data = array();
385
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
386
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
495
+			if (isset($line[37]) && $line[37] != '') {
496
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
497
+			} else {
498
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
499
+			}
387 500
 			$data['pilot_id'] = $line[1];
388 501
 			$data['pilot_name'] = $line[2];
389 502
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
390 503
 			$data['ident'] = $line[0]; // ident
391
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
504
+			if ($line[7] != '' && $line[7] != 0) {
505
+				$data['altitude'] = $line[7];
506
+			}
507
+			// altitude
392 508
 			$data['speed'] = $line[8]; // speed
393
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
394
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
509
+			if (isset($line[45])) {
510
+				$data['heading'] = $line[45];
511
+			}
512
+			// heading
513
+			elseif (isset($line[38])) {
514
+				$data['heading'] = $line[38];
515
+			}
516
+			// heading
395 517
 			$data['latitude'] = $line[5]; // lat
396 518
 	        	$data['longitude'] = $line[6]; // long
397 519
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -407,7 +529,9 @@  discard block
 block discarded – undo
407 529
 			$data['frequency'] = $line[4];
408 530
 			$data['type'] = $line[18];
409 531
 			$data['range'] = $line[19];
410
-			if (isset($line[35])) $data['info'] = $line[35];
532
+			if (isset($line[35])) {
533
+				$data['info'] = $line[35];
534
+			}
411 535
     			$data['id_source'] = $id_source;
412 536
 	    		//$data['arrival_airport_time'] = ;
413 537
 	    		if ($line[9] != '') {
@@ -421,23 +545,38 @@  discard block
 block discarded – undo
421 545
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
422 546
 	    		*/
423 547
 	    		$data['format_source'] = $value['format'];
424
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
425
-    			if ($line[3] == 'PILOT') $SI->add($data);
426
-			elseif ($line[3] == 'ATC') {
548
+			if (isset($value['name']) && $value['name'] != '') {
549
+				$data['source_name'] = $value['name'];
550
+			}
551
+    			if ($line[3] == 'PILOT') {
552
+    				$SI->add($data);
553
+    			} elseif ($line[3] == 'ATC') {
427 554
 				//print_r($data);
428 555
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
429 556
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
430 557
 				$typec = substr($data['ident'],-3);
431
-				if ($typec == 'APP') $data['type'] = 'Approach';
432
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
433
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
434
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
435
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
436
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
437
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
438
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
439
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
440
-				if (!isset($data['source_name'])) $data['source_name'] = '';
558
+				if ($typec == 'APP') {
559
+					$data['type'] = 'Approach';
560
+				} elseif ($typec == 'TWR') {
561
+					$data['type'] = 'Tower';
562
+				} elseif ($typec == 'OBS') {
563
+					$data['type'] = 'Observer';
564
+				} elseif ($typec == 'GND') {
565
+					$data['type'] = 'Ground';
566
+				} elseif ($typec == 'DEL') {
567
+					$data['type'] = 'Delivery';
568
+				} elseif ($typec == 'DEP') {
569
+					$data['type'] = 'Departure';
570
+				} elseif ($typec == 'FSS') {
571
+					$data['type'] = 'Flight Service Station';
572
+				} elseif ($typec == 'CTR') {
573
+					$data['type'] = 'Control Radar or Centre';
574
+				} elseif ($data['type'] == '') {
575
+					$data['type'] = 'Observer';
576
+				}
577
+				if (!isset($data['source_name'])) {
578
+					$data['source_name'] = '';
579
+				}
441 580
 				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']);
442 581
 			}
443 582
     			unset($data);
@@ -457,26 +596,55 @@  discard block
 block discarded – undo
457 596
 		foreach ($all_data['acList'] as $line) {
458 597
 		    $data = array();
459 598
 		    $data['hex'] = $line['Icao']; // hex
460
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
461
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
462
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
463
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
464
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
465
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
599
+		    if (isset($line['Call'])) {
600
+		    	$data['ident'] = $line['Call'];
601
+		    }
602
+		    // ident
603
+		    if (isset($line['Alt'])) {
604
+		    	$data['altitude'] = $line['Alt'];
605
+		    }
606
+		    // altitude
607
+		    if (isset($line['Spd'])) {
608
+		    	$data['speed'] = $line['Spd'];
609
+		    }
610
+		    // speed
611
+		    if (isset($line['Trak'])) {
612
+		    	$data['heading'] = $line['Trak'];
613
+		    }
614
+		    // heading
615
+		    if (isset($line['Lat'])) {
616
+		    	$data['latitude'] = $line['Lat'];
617
+		    }
618
+		    // lat
619
+		    if (isset($line['Long'])) {
620
+		    	$data['longitude'] = $line['Long'];
621
+		    }
622
+		    // long
466 623
 		    //$data['verticalrate'] = $line['']; // verticale rate
467
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
624
+		    if (isset($line['Sqk'])) {
625
+		    	$data['squawk'] = $line['Sqk'];
626
+		    }
627
+		    // squawk
468 628
 		    $data['emergency'] = ''; // emergency
469
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
629
+		    if (isset($line['Reg'])) {
630
+		    	$data['registration'] = $line['Reg'];
631
+		    }
470 632
 		    /*
471 633
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
472 634
 		    else $data['datetime'] = date('Y-m-d H:i:s');
473 635
 		    */
474 636
 		    $data['datetime'] = date('Y-m-d H:i:s');
475
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
637
+		    if (isset($line['Type'])) {
638
+		    	$data['aircraft_icao'] = $line['Type'];
639
+		    }
476 640
 	    	    $data['format_source'] = 'aircraftlistjson';
477 641
 		    $data['id_source'] = $id_source;
478
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
479
-		    if (isset($data['datetime'])) $SI->add($data);
642
+		    if (isset($value['name']) && $value['name'] != '') {
643
+		    	$data['source_name'] = $value['name'];
644
+		    }
645
+		    if (isset($data['datetime'])) {
646
+		    	$SI->add($data);
647
+		    }
480 648
 		    unset($data);
481 649
 		}
482 650
 	    } else {
@@ -496,7 +664,9 @@  discard block
 block discarded – undo
496 664
 		    $data['datetime'] = date('Y-m-d H:i:s');
497 665
 	    	    $data['format_source'] = 'aircraftlistjson';
498 666
     		    $data['id_source'] = $id_source;
499
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
667
+		    if (isset($value['name']) && $value['name'] != '') {
668
+		    	$data['source_name'] = $value['name'];
669
+		    }
500 670
 		    $SI->add($data);
501 671
 		    unset($data);
502 672
 		}
@@ -532,7 +702,9 @@  discard block
 block discarded – undo
532 702
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
533 703
 	    	    $data['format_source'] = 'planeupdatefaa';
534 704
     		    $data['id_source'] = $id_source;
535
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
705
+		    if (isset($value['name']) && $value['name'] != '') {
706
+		    	$data['source_name'] = $value['name'];
707
+		    }
536 708
 		    $SI->add($data);
537 709
 		    unset($data);
538 710
 		}
@@ -572,7 +744,9 @@  discard block
 block discarded – undo
572 744
 	    //$buffer = $Common->getData($hosts[$id]);
573 745
 	    $buffer = $Common->getData($value['host']);
574 746
 	    $all_data = json_decode($buffer,true);
575
-	    if (!empty($all_data)) $reset = 0;
747
+	    if (!empty($all_data)) {
748
+	    	$reset = 0;
749
+	    }
576 750
 	    foreach ($all_data as $key => $line) {
577 751
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
578 752
 		    $data = array();
@@ -593,7 +767,9 @@  discard block
 block discarded – undo
593 767
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
594 768
 	    	    $data['format_source'] = 'fr24json';
595 769
     		    $data['id_source'] = $id_source;
596
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
770
+		    if (isset($value['name']) && $value['name'] != '') {
771
+		    	$data['source_name'] = $value['name'];
772
+		    }
597 773
 		    $SI->add($data);
598 774
 		    unset($data);
599 775
 		}
@@ -617,23 +793,39 @@  discard block
 block discarded – undo
617 793
 		    if (isset($line['inf'])) {
618 794
 			$data = array();
619 795
 			$data['hex'] = $line['inf']['ia'];
620
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
796
+			if (isset($line['inf']['cs'])) {
797
+				$data['ident'] = $line['inf']['cs'];
798
+			}
799
+			//$line[13]
621 800
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
622
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
623
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
801
+	    		if (isset($line['inf']['gs'])) {
802
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
803
+	    		}
804
+	    		// speed
805
+	    		if (isset($line['inf']['tr'])) {
806
+	    			$data['heading'] = $line['inf']['tr'];
807
+	    		}
808
+	    		// heading
624 809
 	    		$data['latitude'] = $line['pt'][0]; // lat
625 810
 	    		$data['longitude'] = $line['pt'][1]; // long
626 811
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
627
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
812
+	    		if (isset($line['inf']['sq'])) {
813
+	    			$data['squawk'] = $line['inf']['sq'];
814
+	    		}
815
+	    		// squawk
628 816
 	    		//$data['aircraft_icao'] = $line[8];
629
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
817
+	    		if (isset($line['inf']['rc'])) {
818
+	    			$data['registration'] = $line['inf']['rc'];
819
+	    		}
630 820
 			//$data['departure_airport_iata'] = $line[11];
631 821
 			//$data['arrival_airport_iata'] = $line[12];
632 822
 	    		//$data['emergency'] = ''; // emergency
633 823
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
634 824
 	    		$data['format_source'] = 'radarvirtueljson';
635 825
     			$data['id_source'] = $id_source;
636
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
826
+			if (isset($value['name']) && $value['name'] != '') {
827
+				$data['source_name'] = $value['name'];
828
+			}
637 829
 			$SI->add($data);
638 830
 			unset($data);
639 831
 		    }
@@ -654,29 +846,62 @@  discard block
 block discarded – undo
654 846
 		    $data['id'] = $line['id'];
655 847
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
656 848
 		    $data['ident'] = $line['callsign']; // ident
657
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
658
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
659
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
660
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
661
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
662
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
849
+		    if (isset($line['pilotid'])) {
850
+		    	$data['pilot_id'] = $line['pilotid'];
851
+		    }
852
+		    // pilot id
853
+		    if (isset($line['name'])) {
854
+		    	$data['pilot_name'] = $line['name'];
855
+		    }
856
+		    // pilot name
857
+		    if (isset($line['alt'])) {
858
+		    	$data['altitude'] = $line['alt'];
859
+		    }
860
+		    // altitude
861
+		    if (isset($line['gs'])) {
862
+		    	$data['speed'] = $line['gs'];
863
+		    }
864
+		    // speed
865
+		    if (isset($line['heading'])) {
866
+		    	$data['heading'] = $line['heading'];
867
+		    }
868
+		    // heading
869
+		    if (isset($line['route'])) {
870
+		    	$data['waypoints'] = $line['route'];
871
+		    }
872
+		    // route
663 873
 		    $data['latitude'] = $line['lat']; // lat
664 874
 		    $data['longitude'] = $line['lon']; // long
665 875
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
666 876
 		    //$data['squawk'] = $line['squawk']; // squawk
667 877
 		    //$data['emergency'] = ''; // emergency
668
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
669
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
670
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
878
+		    if (isset($line['depicao'])) {
879
+		    	$data['departure_airport_icao'] = $line['depicao'];
880
+		    }
881
+		    if (isset($line['deptime'])) {
882
+		    	$data['departure_airport_time'] = $line['deptime'];
883
+		    }
884
+		    if (isset($line['arricao'])) {
885
+		    	$data['arrival_airport_icao'] = $line['arricao'];
886
+		    }
671 887
 		    //$data['arrival_airport_time'] = $line['arrtime'];
672
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
673
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
674
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
675
-		    else $data['info'] = '';
888
+		    if (isset($line['aircraft'])) {
889
+		    	$data['aircraft_icao'] = $line['aircraft'];
890
+		    }
891
+		    if (isset($line['transponder'])) {
892
+		    	$data['squawk'] = $line['transponder'];
893
+		    }
894
+		    if (isset($line['atis'])) {
895
+		    	$data['info'] = $line['atis'];
896
+		    } else {
897
+		    	$data['info'] = '';
898
+		    }
676 899
 		    $data['format_source'] = 'pireps';
677 900
     		    $data['id_source'] = $id_source;
678 901
 		    $data['datetime'] = date('Y-m-d H:i:s');
679
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
902
+		    if (isset($value['name']) && $value['name'] != '') {
903
+		    	$data['source_name'] = $value['name'];
904
+		    }
680 905
 		    if ($line['icon'] == 'plane') {
681 906
 			$SI->add($data);
682 907
 		    //    print_r($data);
@@ -685,15 +910,25 @@  discard block
 block discarded – undo
685 910
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
686 911
 			$typec = substr($data['ident'],-3);
687 912
 			$data['type'] = '';
688
-			if ($typec == 'APP') $data['type'] = 'Approach';
689
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
690
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
691
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
692
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
693
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
694
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
695
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
696
-			else $data['type'] = 'Observer';
913
+			if ($typec == 'APP') {
914
+				$data['type'] = 'Approach';
915
+			} elseif ($typec == 'TWR') {
916
+				$data['type'] = 'Tower';
917
+			} elseif ($typec == 'OBS') {
918
+				$data['type'] = 'Observer';
919
+			} elseif ($typec == 'GND') {
920
+				$data['type'] = 'Ground';
921
+			} elseif ($typec == 'DEL') {
922
+				$data['type'] = 'Delivery';
923
+			} elseif ($typec == 'DEP') {
924
+				$data['type'] = 'Departure';
925
+			} elseif ($typec == 'FSS') {
926
+				$data['type'] = 'Flight Service Station';
927
+			} elseif ($typec == 'CTR') {
928
+				$data['type'] = 'Control Radar or Centre';
929
+			} else {
930
+				$data['type'] = 'Observer';
931
+			}
697 932
 			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']);
698 933
 		    }
699 934
 		    unset($data);
@@ -704,7 +939,9 @@  discard block
 block discarded – undo
704 939
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
705 940
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
706 941
 	    //$buffer = $Common->getData($hosts[$id]);
707
-	    if ($globalDebug) echo 'Get Data...'."\n";
942
+	    if ($globalDebug) {
943
+	    	echo 'Get Data...'."\n";
944
+	    }
708 945
 	    $buffer = $Common->getData($value['host']);
709 946
 	    $all_data = json_decode($buffer,true);
710 947
 	    if ($buffer != '' && is_array($all_data)) {
@@ -712,10 +949,16 @@  discard block
 block discarded – undo
712 949
 		foreach ($all_data as $line) {
713 950
 	    	    $data = array();
714 951
 	    	    //$data['id'] = $line['id']; // id not usable
715
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
952
+	    	    if (isset($line['pilotid'])) {
953
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
954
+	    	    }
716 955
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
717
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
718
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
956
+	    	    if (isset($line['pilotname'])) {
957
+	    	    	$data['pilot_name'] = $line['pilotname'];
958
+	    	    }
959
+	    	    if (isset($line['pilotid'])) {
960
+	    	    	$data['pilot_id'] = $line['pilotid'];
961
+	    	    }
719 962
 	    	    $data['ident'] = $line['flightnum']; // ident
720 963
 	    	    $data['altitude'] = $line['alt']; // altitude
721 964
 	    	    $data['speed'] = $line['gs']; // speed
@@ -733,27 +976,41 @@  discard block
 block discarded – undo
733 976
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
734 977
     		    $data['arrival_airport_time'] = $line['arrtime'];
735 978
     		    $data['registration'] = $line['aircraft'];
736
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
979
+		    if (isset($line['route'])) {
980
+		    	$data['waypoints'] = $line['route'];
981
+		    }
982
+		    // route
737 983
 		    if (isset($line['aircraftname'])) {
738 984
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
739 985
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
740 986
 	    		$aircraft_data = explode('-',$line['aircraftname']);
741
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
742
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
743
-	    		else {
987
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
988
+	    			$data['aircraft_icao'] = $aircraft_data[0];
989
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
990
+	    			$data['aircraft_icao'] = $aircraft_data[1];
991
+	    		} else {
744 992
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
745
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
746
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
993
+	    		    if (isset($aircraft_data[1])) {
994
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
995
+	    		    } else {
996
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
997
+	    		    }
747 998
 	    		}
748 999
 	    	    }
749
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1000
+    		    if (isset($line['route'])) {
1001
+    		    	$data['waypoints'] = $line['route'];
1002
+    		    }
750 1003
     		    $data['id_source'] = $id_source;
751 1004
 	    	    $data['format_source'] = 'phpvmacars';
752
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1005
+		    if (isset($value['name']) && $value['name'] != '') {
1006
+		    	$data['source_name'] = $value['name'];
1007
+		    }
753 1008
 		    $SI->add($data);
754 1009
 		    unset($data);
755 1010
 		}
756
-		if ($globalDebug) echo 'No more data...'."\n";
1011
+		if ($globalDebug) {
1012
+			echo 'No more data...'."\n";
1013
+		}
757 1014
 		unset($buffer);
758 1015
 		unset($all_data);
759 1016
 	    }
@@ -761,7 +1018,9 @@  discard block
 block discarded – undo
761 1018
     	    $last_exec[$id]['last'] = time();
762 1019
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763 1020
 	    //$buffer = $Common->getData($hosts[$id]);
764
-	    if ($globalDebug) echo 'Get Data...'."\n";
1021
+	    if ($globalDebug) {
1022
+	    	echo 'Get Data...'."\n";
1023
+	    }
765 1024
 	    $buffer = $Common->getData($value['host']);
766 1025
 	    $all_data = json_decode($buffer,true);
767 1026
 	    if ($buffer != '' && is_array($all_data)) {
@@ -790,15 +1049,22 @@  discard block
 block discarded – undo
790 1049
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
791 1050
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
792 1051
     		    //$data['registration'] = $line['aircraft'];
793
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1052
+		    if (isset($line['route'])) {
1053
+		    	$data['waypoints'] = $line['route'];
1054
+		    }
1055
+		    // route
794 1056
 	    	    $data['aircraft_icao'] = $line['plane_type'];
795 1057
     		    $data['id_source'] = $id_source;
796 1058
 	    	    $data['format_source'] = 'vam';
797
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1059
+		    if (isset($value['name']) && $value['name'] != '') {
1060
+		    	$data['source_name'] = $value['name'];
1061
+		    }
798 1062
 		    $SI->add($data);
799 1063
 		    unset($data);
800 1064
 		}
801
-		if ($globalDebug) echo 'No more data...'."\n";
1065
+		if ($globalDebug) {
1066
+			echo 'No more data...'."\n";
1067
+		}
802 1068
 		unset($buffer);
803 1069
 		unset($all_data);
804 1070
 	    }
@@ -806,7 +1072,9 @@  discard block
 block discarded – undo
806 1072
     	    $last_exec[$id]['last'] = time();
807 1073
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
808 1074
 	} 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') {
809
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1075
+	    if (function_exists('pcntl_fork')) {
1076
+	    	pcntl_signal_dispatch();
1077
+	    }
810 1078
     	    //$last_exec[$id]['last'] = time();
811 1079
 
812 1080
 	    //$read = array( $sockets[$id] );
@@ -814,7 +1082,9 @@  discard block
 block discarded – undo
814 1082
 	    $write = NULL;
815 1083
 	    $e = NULL;
816 1084
 	    $n = socket_select($read, $write, $e, $timeout);
817
-	    if ($e != NULL) var_dump($e);
1085
+	    if ($e != NULL) {
1086
+	    	var_dump($e);
1087
+	    }
818 1088
 	    if ($n > 0) {
819 1089
 		$reset = 0;
820 1090
 		foreach ($read as $nb => $r) {
@@ -836,7 +1106,9 @@  discard block
 block discarded – undo
836 1106
 		    if ($buffer != '') {
837 1107
 			$tt[$format] = 0;
838 1108
 			if ($format == 'acarssbs3') {
839
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1109
+                    	    if ($globalDebug) {
1110
+                    	    	echo 'ACARS : '.$buffer."\n";
1111
+                    	    }
840 1112
 			    $ACARS->add(trim($buffer));
841 1113
 			    $ACARS->deleteLiveAcarsData();
842 1114
 			} elseif ($format == 'raw') {
@@ -845,9 +1117,15 @@  discard block
 block discarded – undo
845 1117
 			    if (is_array($data)) {
846 1118
 				$data['datetime'] = date('Y-m-d H:i:s');
847 1119
 				$data['format_source'] = 'raw';
848
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
849
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
850
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1120
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1121
+					$data['source_name'] = $globalSources[$nb]['name'];
1122
+				}
1123
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1124
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1125
+    				}
1126
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1127
+                                	$SI->add($data);
1128
+                                }
851 1129
                             }
852 1130
                         } elseif ($format == 'flightgearsp') {
853 1131
                     	    //echo $buffer."\n";
@@ -865,11 +1143,15 @@  discard block
 block discarded – undo
865 1143
 				$data['speed'] = round($line[5]*1.94384);
866 1144
 				$data['datetime'] = date('Y-m-d H:i:s');
867 1145
 				$data['format_source'] = 'flightgearsp';
868
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1146
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1147
+					$SI->add($data);
1148
+				}
869 1149
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
870 1150
 			    }
871 1151
                         } elseif ($format == 'acars') {
872
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1152
+                    	    if ($globalDebug) {
1153
+                    	    	echo 'ACARS : '.$buffer."\n";
1154
+                    	    }
873 1155
 			    $ACARS->add(trim($buffer));
874 1156
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
875 1157
 			    $ACARS->deleteLiveAcarsData();
@@ -890,7 +1172,9 @@  discard block
 block discarded – undo
890 1172
 				    $aircraft_type = $line[10];
891 1173
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
892 1174
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
893
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1175
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1176
+				    	$SI->add($data);
1177
+				    }
894 1178
 				}
895 1179
 			    }
896 1180
 			} elseif ($format == 'beast') {
@@ -906,21 +1190,43 @@  discard block
 block discarded – undo
906 1190
     				$data['hex'] = $lined['hexid'];
907 1191
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
908 1192
     				$data['datetime'] = date('Y-m-d H:i:s');;
909
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
910
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
911
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
912
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
913
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
914
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
915
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1193
+    				if (isset($lined['ident'])) {
1194
+    					$data['ident'] = $lined['ident'];
1195
+    				}
1196
+    				if (isset($lined['lat'])) {
1197
+    					$data['latitude'] = $lined['lat'];
1198
+    				}
1199
+    				if (isset($lined['lon'])) {
1200
+    					$data['longitude'] = $lined['lon'];
1201
+    				}
1202
+    				if (isset($lined['speed'])) {
1203
+    					$data['speed'] = $lined['speed'];
1204
+    				}
1205
+    				if (isset($lined['squawk'])) {
1206
+    					$data['squawk'] = $lined['squawk'];
1207
+    				}
1208
+    				if (isset($lined['alt'])) {
1209
+    					$data['altitude'] = $lined['alt'];
1210
+    				}
1211
+    				if (isset($lined['heading'])) {
1212
+    					$data['heading'] = $lined['heading'];
1213
+    				}
916 1214
     				$data['id_source'] = $id_source;
917 1215
     				$data['format_source'] = 'tsv';
918
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
919
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
920
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1216
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1217
+    					$data['source_name'] = $globalSources[$nb]['name'];
1218
+    				}
1219
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1220
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1221
+    				}
1222
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1223
+    					$SI->add($data);
1224
+    				}
921 1225
     				unset($lined);
922 1226
     				unset($data);
923
-    			    } else $error = true;
1227
+    			    } else {
1228
+    			    	$error = true;
1229
+    			    }
924 1230
 			} elseif ($format == 'aprs' && $use_aprs) {
925 1231
 			    if ($aprs_connect == 0) {
926 1232
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -949,29 +1255,44 @@  discard block
 block discarded – undo
949 1255
 				    $data['latitude'] = $line['latitude'];
950 1256
 				    $data['longitude'] = $line['longitude'];
951 1257
 				    //$data['verticalrate'] = $line[16];
952
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
953
-				    else $data['speed'] = 0;
1258
+				    if (isset($line['speed'])) {
1259
+				    	$data['speed'] = $line['speed'];
1260
+				    } else {
1261
+				    	$data['speed'] = 0;
1262
+				    }
954 1263
 				    $data['altitude'] = $line['altitude'];
955
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
1264
+				    if (isset($line['course'])) {
1265
+				    	$data['heading'] = $line['course'];
1266
+				    }
956 1267
 				    //else $data['heading'] = 0;
957 1268
 				    $data['aircraft_type'] = $line['stealth'];
958
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1269
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1270
+				    	$data['noarchive'] = true;
1271
+				    }
959 1272
     				    $data['id_source'] = $id_source;
960 1273
 				    $data['format_source'] = 'aprs';
961 1274
 				    $data['source_name'] = $line['source'];
962
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1275
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1276
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1277
+    				    }
963 1278
 				    $currentdate = date('Y-m-d H:i:s');
964 1279
 				    $aprsdate = strtotime($data['datetime']);
965 1280
 				    // Accept data if time <= system time + 20s
966
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
967
-				    else {
968
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
969
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1281
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1282
+				    	$send = $SI->add($data);
1283
+				    } else {
1284
+					if ($line['stealth'] != 0) {
1285
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1286
+					} else {
1287
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1288
+					}
970 1289
 				    }
971 1290
 				    unset($data);
972 1291
 				} 
973 1292
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
974
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1293
+				elseif ($line == true && $globalDebug) {
1294
+					echo '!! Failed : '.$buffer."!!\n";
1295
+				}
975 1296
 			    }
976 1297
 			} else {
977 1298
 			    $line = explode(',', $buffer);
@@ -1000,25 +1321,42 @@  discard block
 block discarded – undo
1000 1321
     				$data['ground'] = $line[21];
1001 1322
     				$data['emergency'] = $line[19];
1002 1323
     				$data['format_source'] = 'sbs';
1003
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1004
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1324
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1325
+					$data['source_name'] = $globalSources[$nb]['name'];
1326
+				}
1327
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1328
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1329
+    				}
1005 1330
     				$data['id_source'] = $id_source;
1006
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1007
-    				else $error = true;
1331
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1332
+    					$send = $SI->add($data);
1333
+    				} else {
1334
+    					$error = true;
1335
+    				}
1008 1336
     				unset($data);
1009
-    			    } else $error = true;
1337
+    			    } else {
1338
+    			    	$error = true;
1339
+    			    }
1010 1340
 			    if ($error) {
1011 1341
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1012
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1342
+					if ($globalDebug) {
1343
+						echo "Not a message. Ignoring... \n";
1344
+					}
1013 1345
 				} else {
1014
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1346
+					if ($globalDebug) {
1347
+						echo "Wrong line format. Ignoring... \n";
1348
+					}
1015 1349
 					if ($globalDebug) {
1016 1350
 						echo $buffer;
1017 1351
 						print_r($line);
1018 1352
 					}
1019 1353
 					//socket_close($r);
1020
-					if ($globalDebug) echo "Reconnect after an error...\n";
1021
-					if ($format == 'aprs') $aprs_connect = 0;
1354
+					if ($globalDebug) {
1355
+						echo "Reconnect after an error...\n";
1356
+					}
1357
+					if ($format == 'aprs') {
1358
+						$aprs_connect = 0;
1359
+					}
1022 1360
 					$sourceer[$nb] = $globalSources[$nb];
1023 1361
 					connect_all($sourceer);
1024 1362
 					$sourceer = array();
@@ -1026,10 +1364,14 @@  discard block
 block discarded – undo
1026 1364
 			    }
1027 1365
 			}
1028 1366
 			// Sleep for xxx microseconds
1029
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1367
+			if (isset($globalSBSSleep)) {
1368
+				usleep($globalSBSSleep);
1369
+			}
1030 1370
 		    } else {
1031 1371
 			if ($format == 'flightgearmp') {
1032
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1372
+			    	if ($globalDebug) {
1373
+			    		echo "Reconnect FlightGear MP...";
1374
+			    	}
1033 1375
 				//@socket_close($r);
1034 1376
 				sleep($globalMinFetch);
1035 1377
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1038,10 +1380,15 @@  discard block
 block discarded – undo
1038 1380
 				break;
1039 1381
 				
1040 1382
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1041
-			    if (isset($tt[$format])) $tt[$format]++;
1042
-			    else $tt[$format] = 0;
1383
+			    if (isset($tt[$format])) {
1384
+			    	$tt[$format]++;
1385
+			    } else {
1386
+			    	$tt[$format] = 0;
1387
+			    }
1043 1388
 			    if ($tt[$format] > 30) {
1044
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1389
+				if ($globalDebug) {
1390
+					echo "ERROR : Reconnect ".$format."...";
1391
+				}
1045 1392
 				//@socket_close($r);
1046 1393
 				sleep(2);
1047 1394
 				$aprs_connect = 0;
@@ -1057,12 +1404,18 @@  discard block
 block discarded – undo
1057 1404
 		}
1058 1405
 	    } else {
1059 1406
 		$error = socket_strerror(socket_last_error());
1060
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1407
+		if ($globalDebug) {
1408
+			echo "ERROR : socket_select give this error ".$error . "\n";
1409
+		}
1061 1410
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1062
-			if (isset($globalDebug)) echo "Restarting...\n";
1411
+			if (isset($globalDebug)) {
1412
+				echo "Restarting...\n";
1413
+			}
1063 1414
 			// Restart the script if possible
1064 1415
 			if (is_array($sockets)) {
1065
-			    if ($globalDebug) echo "Shutdown all sockets...";
1416
+			    if ($globalDebug) {
1417
+			    	echo "Shutdown all sockets...";
1418
+			    }
1066 1419
 			    
1067 1420
 			    foreach ($sockets as $sock) {
1068 1421
 				@socket_shutdown($sock,2);
@@ -1070,18 +1423,24 @@  discard block
 block discarded – undo
1070 1423
 			    }
1071 1424
 			    
1072 1425
 			}
1073
-			if ($globalDebug) echo "Restart all connections...";
1426
+			if ($globalDebug) {
1427
+				echo "Restart all connections...";
1428
+			}
1074 1429
 			sleep(2);
1075 1430
 			$time = time();
1076 1431
 			//connect_all($hosts);
1077 1432
 			$aprs_connect = 0;
1078
-			if ($reset > 40) exit('Too many attempts...');
1433
+			if ($reset > 40) {
1434
+				exit('Too many attempts...');
1435
+			}
1079 1436
 			connect_all($globalSources);
1080 1437
 		}
1081 1438
 	    }
1082 1439
 	}
1083 1440
 	if ($globalDaemon === false) {
1084
-	    if ($globalDebug) echo 'Check all...'."\n";
1441
+	    if ($globalDebug) {
1442
+	    	echo 'Check all...'."\n";
1443
+	    }
1085 1444
 	    $SI->checkAll();
1086 1445
 	}
1087 1446
     }
Please login to merge, or discard this patch.