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