Completed
Push — master ( 946f73...2344d0 )
by Yannick
09:42
created
scripts/daemon-spotter.php 3 patches
Indentation   +869 added lines, -869 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,42 +24,42 @@  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','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver'));
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
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
+	else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60
-    $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
60
+	$globalSources = array();
61
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
+	else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) {
65 65
 	$globalServerAPRS = TRUE;
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 if (isset($options['idsource'])) $id_source = $options['idsource'];
75 75
 else $id_source = 1;
76 76
 if (isset($globalServer) && $globalServer) {
77
-    if ($globalDebug) echo "Using Server Mode\n";
78
-    $SI=new SpotterServer();
77
+	if ($globalDebug) echo "Using Server Mode\n";
78
+	$SI=new SpotterServer();
79 79
 /*
80 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 81
     $SI = new adsb2aprs();
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 } else $SI=new SpotterImport($Connection->db);
85 85
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
86 86
 if (isset($globalMarine) && $globalMarine) {
87
-    $AIS = new AIS();
88
-    $MI = new MarineImport($Connection->db);
87
+	$AIS = new AIS();
88
+	$MI = new MarineImport($Connection->db);
89 89
 }
90 90
 //$APRS=new APRS($Connection->db);
91 91
 $SBS=new SBS();
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 //$servertz = system('date +%Z');
96 96
 // signal handler - playing nice with sockets and dump1090
97 97
 if (function_exists('pcntl_fork')) {
98
-    pcntl_signal(SIGINT,  function() {
99
-        global $sockets;
100
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
101
-        die("Bye!\n");
102
-    });
103
-    pcntl_signal_dispatch();
98
+	pcntl_signal(SIGINT,  function() {
99
+		global $sockets;
100
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
101
+		die("Bye!\n");
102
+	});
103
+	pcntl_signal_dispatch();
104 104
 }
105 105
 
106 106
 // let's try and connect
@@ -110,153 +110,153 @@  discard block
 block discarded – undo
110 110
 $reset = 0;
111 111
 
112 112
 function connect_all($hosts) {
113
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115
-    $reset++;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
117
-    foreach ($hosts as $id => $value) {
113
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115
+	$reset++;
116
+	if ($globalDebug) echo 'Connect to all...'."\n";
117
+	foreach ($hosts as $id => $value) {
118 118
 	$host = $value['host'];
119 119
 	$globalSources[$id]['last_exec'] = 0;
120 120
 	// Here we check type of source(s)
121 121
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
122
-            if (preg_match('/deltadb.txt$/i',$host)) {
123
-        	//$formats[$id] = 'deltadbtxt';
124
-        	$globalSources[$id]['format'] = 'deltadbtxt';
125
-        	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
-        	//$formats[$id] = 'vatsimtxt';
129
-        	$globalSources[$id]['format'] = 'vatsimtxt';
130
-        	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133
-        	//$formats[$id] = 'aircraftlistjson';
134
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
135
-        	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
-    	    } else if (preg_match('/opensky/i',$host)) {
138
-        	//$formats[$id] = 'aircraftlistjson';
139
-        	$globalSources[$id]['format'] = 'opensky';
140
-        	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
-        	//$formats[$id] = 'radarvirtueljson';
144
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
145
-        	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
-        	    exit(0);
150
-        	}
151
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
-        	//$formats[$id] = 'planeupdatefaa';
153
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
154
-        	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
-        	    exit(0);
159
-        	}
160
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
-        	//$formats[$id] = 'phpvmacars';
162
-        	$globalSources[$id]['format'] = 'phpvmacars';
163
-        	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
166
-        	//$formats[$id] = 'phpvmacars';
167
-        	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
-            } else if (preg_match('/whazzup/i',$host)) {
170
-        	//$formats[$id] = 'whazzup';
171
-        	$globalSources[$id]['format'] = 'whazzup';
172
-        	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
-            } else if (preg_match('/recentpireps/i',$host)) {
175
-        	//$formats[$id] = 'pirepsjson';
176
-        	$globalSources[$id]['format'] = 'pirepsjson';
177
-        	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
-        	//$formats[$id] = 'fr24json';
181
-        	$globalSources[$id]['format'] = 'fr24json';
182
-        	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
-        	    exit(0);
187
-        	}
188
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
189
-        	//$formats[$id] = 'fr24json';
190
-        	$globalSources[$id]['format'] = 'myshiptracking';
191
-        	//$last_exec['fr24json'] = 0;
192
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
193
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195
-        	    exit(0);
196
-        	}
197
-            //} else if (preg_match('/10001/',$host)) {
198
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199
-        	//$formats[$id] = 'tsv';
200
-        	$globalSources[$id]['format'] = 'tsv';
201
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
202
-            }
203
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
206
-    		    if ($idf !== false) {
207
-    			$httpfeeds[$id] = $idf;
208
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
209
-    		    }
210
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213
-	    $hostport = explode(':',$host);
214
-	    if (isset($hostport[1])) {
122
+			if (preg_match('/deltadb.txt$/i',$host)) {
123
+			//$formats[$id] = 'deltadbtxt';
124
+			$globalSources[$id]['format'] = 'deltadbtxt';
125
+			//$last_exec['deltadbtxt'] = 0;
126
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
+			//$formats[$id] = 'vatsimtxt';
129
+			$globalSources[$id]['format'] = 'vatsimtxt';
130
+			//$last_exec['vatsimtxt'] = 0;
131
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
133
+			//$formats[$id] = 'aircraftlistjson';
134
+			$globalSources[$id]['format'] = 'aircraftlistjson';
135
+			//$last_exec['aircraftlistjson'] = 0;
136
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
+			} else if (preg_match('/opensky/i',$host)) {
138
+			//$formats[$id] = 'aircraftlistjson';
139
+			$globalSources[$id]['format'] = 'opensky';
140
+			//$last_exec['aircraftlistjson'] = 0;
141
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
+			//$formats[$id] = 'radarvirtueljson';
144
+			$globalSources[$id]['format'] = 'radarvirtueljson';
145
+			//$last_exec['radarvirtueljson'] = 0;
146
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
+				exit(0);
150
+			}
151
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
+			//$formats[$id] = 'planeupdatefaa';
153
+			$globalSources[$id]['format'] = 'planeupdatefaa';
154
+			//$last_exec['planeupdatefaa'] = 0;
155
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
+				exit(0);
159
+			}
160
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
+			//$formats[$id] = 'phpvmacars';
162
+			$globalSources[$id]['format'] = 'phpvmacars';
163
+			//$last_exec['phpvmacars'] = 0;
164
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
166
+			//$formats[$id] = 'phpvmacars';
167
+			$globalSources[$id]['format'] = 'vam';
168
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
+			} else if (preg_match('/whazzup/i',$host)) {
170
+			//$formats[$id] = 'whazzup';
171
+			$globalSources[$id]['format'] = 'whazzup';
172
+			//$last_exec['whazzup'] = 0;
173
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
+			} else if (preg_match('/recentpireps/i',$host)) {
175
+			//$formats[$id] = 'pirepsjson';
176
+			$globalSources[$id]['format'] = 'pirepsjson';
177
+			//$last_exec['pirepsjson'] = 0;
178
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
+			//$formats[$id] = 'fr24json';
181
+			$globalSources[$id]['format'] = 'fr24json';
182
+			//$last_exec['fr24json'] = 0;
183
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
+				exit(0);
187
+			}
188
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
189
+			//$formats[$id] = 'fr24json';
190
+			$globalSources[$id]['format'] = 'myshiptracking';
191
+			//$last_exec['fr24json'] = 0;
192
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
193
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195
+				exit(0);
196
+			}
197
+			//} else if (preg_match('/10001/',$host)) {
198
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199
+			//$formats[$id] = 'tsv';
200
+			$globalSources[$id]['format'] = 'tsv';
201
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
202
+			}
203
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
206
+				if ($idf !== false) {
207
+				$httpfeeds[$id] = $idf;
208
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
209
+				}
210
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213
+		$hostport = explode(':',$host);
214
+		if (isset($hostport[1])) {
215 215
 		$port = $hostport[1];
216 216
 		$hostn = $hostport[0];
217
-	    } else {
217
+		} else {
218 218
 		$port = $globalSources[$id]['port'];
219 219
 		$hostn = $globalSources[$id]['host'];
220
-	    }
221
-	    $Common = new Common();
222
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
223
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
224
-    	    } else {
225
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
226
-	    }
227
-	    if ($s) {
228
-    	        $sockets[$id] = $s;
229
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
230
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220
+		}
221
+		$Common = new Common();
222
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
223
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
224
+			} else {
225
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
226
+		}
227
+		if ($s) {
228
+				$sockets[$id] = $s;
229
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
230
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
231 231
 			//$formats[$id] = 'aprs';
232 232
 			$globalSources[$id]['format'] = 'aprs';
233 233
 			//$aprs_connect = 0;
234 234
 			//$use_aprs = true;
235
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
235
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
236 236
 			$globalSources[$id]['format'] = 'vrstcp';
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) {
@@ -342,116 +342,116 @@  discard block
 block discarded – undo
342 342
 
343 343
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 344
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
346
-    // Delete old ATC
347
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
345
+	if (!$globalDaemon) $i = $endtime-time();
346
+	// Delete old ATC
347
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348 348
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
349
-        $ATC->deleteOldATC();
350
-    }
349
+		$ATC->deleteOldATC();
350
+	}
351 351
     
352
-    //if (count($last_exec) > 0) {
353
-    if (count($last_exec) == count($globalSources)) {
352
+	//if (count($last_exec) > 0) {
353
+	if (count($last_exec) == count($globalSources)) {
354 354
 	$max = $globalMinFetch;
355 355
 	foreach ($last_exec as $last) {
356
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
356
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
357 357
 	}
358 358
 	if ($max != $globalMinFetch) {
359
-	    if ($globalDebug) echo 'Sleeping...'."\n";
360
-	    sleep($globalMinFetch-$max+2);
359
+		if ($globalDebug) echo 'Sleeping...'."\n";
360
+		sleep($globalMinFetch-$max+2);
361
+	}
361 362
 	}
362
-    }
363 363
 
364 364
     
365
-    //foreach ($formats as $id => $value) {
366
-    foreach ($globalSources as $id => $value) {
365
+	//foreach ($formats as $id => $value) {
366
+	foreach ($globalSources as $id => $value) {
367 367
 	date_default_timezone_set('UTC');
368 368
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
369 369
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
370
-	    //$buffer = $Common->getData($hosts[$id]);
371
-	    $buffer = $Common->getData($value['host']);
372
-	    if ($buffer != '') $reset = 0;
373
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
-	    $buffer = explode('\n',$buffer);
375
-	    foreach ($buffer as $line) {
376
-    		if ($line != '' && count($line) > 7) {
377
-    		    $line = explode(',', $line);
378
-	            $data = array();
379
-	            $data['hex'] = $line[1]; // hex
380
-	            $data['ident'] = $line[2]; // ident
381
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
386
-	            $data['verticalrate'] = ''; // vertical rate
387
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388
-	            $data['emergency'] = ''; // emergency
389
-		    $data['datetime'] = date('Y-m-d H:i:s');
390
-		    $data['format_source'] = 'deltadbtxt';
391
-    		    $data['id_source'] = $id_source;
392
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
395
-    		    $SI->add($data);
396
-		    unset($data);
397
-    		}
398
-    	    }
399
-    	    $last_exec[$id]['last'] = time();
370
+		//$buffer = $Common->getData($hosts[$id]);
371
+		$buffer = $Common->getData($value['host']);
372
+		if ($buffer != '') $reset = 0;
373
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
+		$buffer = explode('\n',$buffer);
375
+		foreach ($buffer as $line) {
376
+			if ($line != '' && count($line) > 7) {
377
+				$line = explode(',', $line);
378
+				$data = array();
379
+				$data['hex'] = $line[1]; // hex
380
+				$data['ident'] = $line[2]; // ident
381
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
386
+				$data['verticalrate'] = ''; // vertical rate
387
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388
+				$data['emergency'] = ''; // emergency
389
+			$data['datetime'] = date('Y-m-d H:i:s');
390
+			$data['format_source'] = 'deltadbtxt';
391
+				$data['id_source'] = $id_source;
392
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
395
+				$SI->add($data);
396
+			unset($data);
397
+			}
398
+			}
399
+			$last_exec[$id]['last'] = time();
400 400
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
401
-	    date_default_timezone_set('CET');
402
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403
-	    date_default_timezone_set('UTC');
404
-	    if ($buffer != '') $reset = 0;
405
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406
-	    $buffer = explode('\n',$buffer);
407
-	    foreach ($buffer as $line) {
401
+		date_default_timezone_set('CET');
402
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403
+		date_default_timezone_set('UTC');
404
+		if ($buffer != '') $reset = 0;
405
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406
+		$buffer = explode('\n',$buffer);
407
+		foreach ($buffer as $line) {
408 408
 		if ($line != '') {
409
-		    echo "'".$line."'\n";
410
-		    $add = false;
411
-		    $ais_data = $AIS->parse_line(trim($line));
412
-		    $data = array();
413
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
423
-		    if (isset($ais_data['timestamp'])) {
409
+			echo "'".$line."'\n";
410
+			$add = false;
411
+			$ais_data = $AIS->parse_line(trim($line));
412
+			$data = array();
413
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
423
+			if (isset($ais_data['timestamp'])) {
424 424
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
425 425
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
426
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
427
-			    $add = true;
426
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
427
+				$add = true;
428 428
 			}
429
-		    } else {
429
+			} else {
430 430
 			$data['datetime'] = date('Y-m-d H:i:s');
431 431
 			$add = true;
432
-		    }
433
-		    $data['format_source'] = 'aisnmeatxt';
434
-    		    $data['id_source'] = $id_source;
435
-		    //print_r($data);
436
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
437
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
438
-		    unset($data);
432
+			}
433
+			$data['format_source'] = 'aisnmeatxt';
434
+				$data['id_source'] = $id_source;
435
+			//print_r($data);
436
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
437
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
438
+			unset($data);
439 439
 		}
440
-    	    }
441
-    	    $last_exec[$id]['last'] = time();
440
+			}
441
+			$last_exec[$id]['last'] = time();
442 442
 	} elseif ($value['format'] == 'aisnmeahttp') {
443
-	    $arr = $httpfeeds;
444
-	    $w = $e = null;
443
+		$arr = $httpfeeds;
444
+		$w = $e = null;
445 445
 	    
446
-	    if (isset($arr[$id])) {
446
+		if (isset($arr[$id])) {
447 447
 		$nn = stream_select($arr,$w,$e,$timeout);
448 448
 		if ($nn > 0) {
449
-		    foreach ($httpfeeds as $feed) {
449
+			foreach ($httpfeeds as $feed) {
450 450
 			$buffer = stream_get_line($feed,2000,"\n");
451 451
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
452 452
 			$buffer = explode('\n',$buffer);
453 453
 			foreach ($buffer as $line) {
454
-			    if ($line != '') {
454
+				if ($line != '') {
455 455
 				$ais_data = $AIS->parse_line(trim($line));
456 456
 				$data = array();
457 457
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -469,40 +469,40 @@  discard block
 block discarded – undo
469 469
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
470 470
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
471 471
 				if (isset($ais_data['timestamp'])) {
472
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
472
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
473 473
 				} else {
474
-				    $data['datetime'] = date('Y-m-d H:i:s');
474
+					$data['datetime'] = date('Y-m-d H:i:s');
475 475
 				}
476 476
 				$data['format_source'] = 'aisnmeahttp';
477 477
 				$data['id_source'] = $id_source;
478 478
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
479 479
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
480 480
 				unset($data);
481
-			    }
481
+				}
482
+			}
482 483
 			}
483
-		    }
484 484
 		} else {
485
-		    $format = $value['format'];
486
-		    if (isset($tt[$format])) $tt[$format]++;
487
-		    else $tt[$format] = 0;
488
-		    if ($tt[$format] > 30) {
485
+			$format = $value['format'];
486
+			if (isset($tt[$format])) $tt[$format]++;
487
+			else $tt[$format] = 0;
488
+			if ($tt[$format] > 30) {
489 489
 			if ($globalDebug) echo 'Reconnect...'."\n";
490 490
 			sleep(2);
491 491
 			$sourceeen[] = $value;
492 492
 			connect_all($sourceeen);
493 493
 			$sourceeen = array();
494
-		    }
494
+			}
495
+		}
495 496
 		}
496
-	    }
497 497
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
498
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
499
-	    if ($buffer != '') {
498
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
499
+		if ($buffer != '') {
500 500
 		//echo $buffer;
501 501
 		$all_data = json_decode($buffer,true);
502 502
 		//print_r($all_data);
503 503
 		if (isset($all_data[0]['DATA'])) {
504 504
 		foreach ($all_data[0]['DATA'] as $line) {
505
-		    if ($line != '') {
505
+			if ($line != '') {
506 506
 			$data = array();
507 507
 			$data['ident'] = $line['NAME'];
508 508
 			$data['mmsi'] = $line['MMSI'];
@@ -519,89 +519,89 @@  discard block
 block discarded – undo
519 519
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
520 520
 			$MI->add($data);
521 521
 			unset($data);
522
-		    }
522
+			}
523 523
 		}
524 524
 		}
525 525
 		
526
-	    }
527
-    	    $last_exec[$id]['last'] = time();
526
+		}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
530
-	    if ($buffer != '') {
529
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
530
+		if ($buffer != '') {
531 531
 		$all_data = json_decode($buffer,true);
532 532
 		if (isset($all_data[0]['mmsi'])) {
533
-		    foreach ($all_data as $line) {
533
+			foreach ($all_data as $line) {
534 534
 			if ($line != '') {
535
-			    $data = array();
536
-			    $data['ident'] = $line['shipname'];
537
-			    $data['callsign'] = $line['callsign'];
538
-			    $data['mmsi'] = $line['mmsi'];
539
-			    $data['speed'] = $line['sog'];
540
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
541
-			    $data['latitude'] = $line['latitude'];
542
-			    $data['longitude'] = $line['longitude'];
543
-			    $data['type_id'] = $line['shiptype'];
544
-			    $data['arrival_code'] = $line['destination'];
545
-			    $data['datetime'] = $line['time'];
546
-			    $data['format_source'] = 'boatbeaconapp';
547
-			    $data['id_source'] = $id_source;
548
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
549
-			    $MI->add($data);
550
-			    unset($data);
535
+				$data = array();
536
+				$data['ident'] = $line['shipname'];
537
+				$data['callsign'] = $line['callsign'];
538
+				$data['mmsi'] = $line['mmsi'];
539
+				$data['speed'] = $line['sog'];
540
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
541
+				$data['latitude'] = $line['latitude'];
542
+				$data['longitude'] = $line['longitude'];
543
+				$data['type_id'] = $line['shiptype'];
544
+				$data['arrival_code'] = $line['destination'];
545
+				$data['datetime'] = $line['time'];
546
+				$data['format_source'] = 'boatbeaconapp';
547
+				$data['id_source'] = $id_source;
548
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
549
+				$MI->add($data);
550
+				unset($data);
551
+			}
551 552
 			}
552
-		    }
553 553
 		}
554 554
 		
555
-	    }
556
-    	    $last_exec[$id]['last'] = time();
555
+		}
556
+			$last_exec[$id]['last'] = time();
557 557
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
558
-	    echo 'download...';
559
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560
-	    echo 'done !'."\n";
561
-	    if ($buffer != '') $reset = 0;
562
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563
-	    $buffer = explode('\n',$buffer);
564
-	    foreach ($buffer as $line) {
558
+		echo 'download...';
559
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560
+		echo 'done !'."\n";
561
+		if ($buffer != '') $reset = 0;
562
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563
+		$buffer = explode('\n',$buffer);
564
+		foreach ($buffer as $line) {
565 565
 		if ($line != '') {
566
-		    $data = array();
567
-		    $data['mmsi'] = (int)substr($line,0,9);
568
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
569
-		    //$data['status'] = substr($line,21,2);
570
-		    //$data['type'] = substr($line,24,3);
571
-		    $data['latitude'] = substr($line,29,9);
572
-		    $data['longitude'] = substr($line,41,9);
573
-		    $data['speed'] = round(substr($line,51,5));
574
-		    //$data['course'] = substr($line,57,5);
575
-		    $data['heading'] = round(substr($line,63,3));
576
-		    //$data['draft'] = substr($line,67,4);
577
-		    //$data['length'] = substr($line,72,3);
578
-		    //$data['beam'] = substr($line,76,2);
579
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
580
-		    //$data['callsign'] = trim(substr($line,100,7);
581
-		    //$data['dest'] = substr($line,108,20);
582
-		    //$data['etaDate'] = substr($line,129,5);
583
-		    //$data['etaTime'] = substr($line,135,5);
584
-		    $data['format_source'] = 'shipplotter';
585
-    		    $data['id_source'] = $id_source;
586
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
-		    //print_r($data);
588
-		    echo 'Add...'."\n";
589
-		    $MI->add($data);
590
-		    unset($data);
566
+			$data = array();
567
+			$data['mmsi'] = (int)substr($line,0,9);
568
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
569
+			//$data['status'] = substr($line,21,2);
570
+			//$data['type'] = substr($line,24,3);
571
+			$data['latitude'] = substr($line,29,9);
572
+			$data['longitude'] = substr($line,41,9);
573
+			$data['speed'] = round(substr($line,51,5));
574
+			//$data['course'] = substr($line,57,5);
575
+			$data['heading'] = round(substr($line,63,3));
576
+			//$data['draft'] = substr($line,67,4);
577
+			//$data['length'] = substr($line,72,3);
578
+			//$data['beam'] = substr($line,76,2);
579
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
580
+			//$data['callsign'] = trim(substr($line,100,7);
581
+			//$data['dest'] = substr($line,108,20);
582
+			//$data['etaDate'] = substr($line,129,5);
583
+			//$data['etaTime'] = substr($line,135,5);
584
+			$data['format_source'] = 'shipplotter';
585
+				$data['id_source'] = $id_source;
586
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
587
+			//print_r($data);
588
+			echo 'Add...'."\n";
589
+			$MI->add($data);
590
+			unset($data);
591 591
 		}
592
-    	    }
593
-    	    $last_exec[$id]['last'] = time();
592
+			}
593
+			$last_exec[$id]['last'] = time();
594 594
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
595 595
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
596
-	    //$buffer = $Common->getData($hosts[$id]);
597
-	    $buffer = $Common->getData($value['host']);
598
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
599
-	    $buffer = explode('\n',$buffer);
600
-	    $reset = 0;
601
-	    foreach ($buffer as $line) {
602
-    		if ($line != '') {
603
-    		    $line = explode(':', $line);
604
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
596
+		//$buffer = $Common->getData($hosts[$id]);
597
+		$buffer = $Common->getData($value['host']);
598
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
599
+		$buffer = explode('\n',$buffer);
600
+		$reset = 0;
601
+		foreach ($buffer as $line) {
602
+			if ($line != '') {
603
+				$line = explode(':', $line);
604
+				if (count($line) > 30 && $line[0] != 'callsign') {
605 605
 			$data = array();
606 606
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
607 607
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -614,37 +614,37 @@  discard block
 block discarded – undo
614 614
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
615 615
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
616 616
 			$data['latitude'] = $line[5]; // lat
617
-	        	$data['longitude'] = $line[6]; // long
618
-	        	$data['verticalrate'] = ''; // vertical rate
619
-	        	$data['squawk'] = ''; // squawk
620
-	        	$data['emergency'] = ''; // emergency
621
-	        	$data['waypoints'] = $line[30];
617
+				$data['longitude'] = $line[6]; // long
618
+				$data['verticalrate'] = ''; // vertical rate
619
+				$data['squawk'] = ''; // squawk
620
+				$data['emergency'] = ''; // emergency
621
+				$data['waypoints'] = $line[30];
622 622
 			$data['datetime'] = date('Y-m-d H:i:s');
623 623
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
624 624
 			//if (isset($line[37])) $data['last_update'] = $line[37];
625
-		        $data['departure_airport_icao'] = $line[11];
626
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
627
-		        $data['arrival_airport_icao'] = $line[13];
625
+				$data['departure_airport_icao'] = $line[11];
626
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
627
+				$data['arrival_airport_icao'] = $line[13];
628 628
 			$data['frequency'] = $line[4];
629 629
 			$data['type'] = $line[18];
630 630
 			$data['range'] = $line[19];
631 631
 			if (isset($line[35])) $data['info'] = $line[35];
632
-    			$data['id_source'] = $id_source;
633
-	    		//$data['arrival_airport_time'] = ;
634
-	    		if ($line[9] != '') {
635
-	    		    $aircraft_data = explode('/',$line[9]);
636
-	    		    if (isset($aircraft_data[1])) {
637
-	    			$data['aircraft_icao'] = $aircraft_data[1];
638
-	    		    }
639
-        		}
640
-	    		/*
632
+				$data['id_source'] = $id_source;
633
+				//$data['arrival_airport_time'] = ;
634
+				if ($line[9] != '') {
635
+					$aircraft_data = explode('/',$line[9]);
636
+					if (isset($aircraft_data[1])) {
637
+					$data['aircraft_icao'] = $aircraft_data[1];
638
+					}
639
+				}
640
+				/*
641 641
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
642 642
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
643 643
 	    		*/
644
-	    		$data['format_source'] = $value['format'];
644
+				$data['format_source'] = $value['format'];
645 645
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
646 646
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
647
-    			if ($line[3] == 'PILOT') $SI->add($data);
647
+				if ($line[3] == 'PILOT') $SI->add($data);
648 648
 			elseif ($line[3] == 'ATC') {
649 649
 				//print_r($data);
650 650
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -662,255 +662,255 @@  discard block
 block discarded – undo
662 662
 				if (!isset($data['source_name'])) $data['source_name'] = '';
663 663
 				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']);
664 664
 			}
665
-    			unset($data);
666
-    		    }
667
-    		}
668
-    	    }
669
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
670
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
671
-    	    $last_exec[$id]['last'] = time();
672
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
673
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
674
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
675
-	    if ($buffer != '') {
676
-	    $all_data = json_decode($buffer,true);
677
-	    if (isset($all_data['acList'])) {
665
+				unset($data);
666
+				}
667
+			}
668
+			}
669
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
670
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
671
+			$last_exec[$id]['last'] = time();
672
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
673
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
674
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
675
+		if ($buffer != '') {
676
+		$all_data = json_decode($buffer,true);
677
+		if (isset($all_data['acList'])) {
678 678
 		$reset = 0;
679 679
 		foreach ($all_data['acList'] as $line) {
680
-		    $data = array();
681
-		    $data['hex'] = $line['Icao']; // hex
682
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
688
-		    //$data['verticalrate'] = $line['']; // verticale rate
689
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
690
-		    $data['emergency'] = ''; // emergency
691
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
680
+			$data = array();
681
+			$data['hex'] = $line['Icao']; // hex
682
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
688
+			//$data['verticalrate'] = $line['']; // verticale rate
689
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
690
+			$data['emergency'] = ''; // emergency
691
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
692 692
 		    
693
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
-		    else $data['datetime'] = date('Y-m-d H:i:s');
693
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
+			else $data['datetime'] = date('Y-m-d H:i:s');
695 695
 		    
696
-		    //$data['datetime'] = date('Y-m-d H:i:s');
697
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
698
-	    	    $data['format_source'] = 'aircraftlistjson';
699
-		    $data['id_source'] = $id_source;
700
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-		    if (isset($data['latitude'])) $SI->add($data);
703
-		    unset($data);
696
+			//$data['datetime'] = date('Y-m-d H:i:s');
697
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
698
+				$data['format_source'] = 'aircraftlistjson';
699
+			$data['id_source'] = $id_source;
700
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+			if (isset($data['latitude'])) $SI->add($data);
703
+			unset($data);
704 704
 		}
705
-	    } elseif (is_array($all_data)) {
705
+		} elseif (is_array($all_data)) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data as $line) {
708
-		    $data = array();
709
-		    $data['hex'] = $line['hex']; // hex
710
-		    $data['ident'] = $line['flight']; // ident
711
-		    $data['altitude'] = $line['altitude']; // altitude
712
-		    $data['speed'] = $line['speed']; // speed
713
-		    $data['heading'] = $line['track']; // heading
714
-		    $data['latitude'] = $line['lat']; // lat
715
-		    $data['longitude'] = $line['lon']; // long
716
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
717
-		    $data['squawk'] = $line['squawk']; // squawk
718
-		    $data['emergency'] = ''; // emergency
719
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
-		    else $data['datetime'] = date('Y-m-d H:i:s');
721
-	    	    $data['format_source'] = 'aircraftlistjson';
722
-    		    $data['id_source'] = $id_source;
723
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
725
-		    $SI->add($data);
726
-		    unset($data);
708
+			$data = array();
709
+			$data['hex'] = $line['hex']; // hex
710
+			$data['ident'] = $line['flight']; // ident
711
+			$data['altitude'] = $line['altitude']; // altitude
712
+			$data['speed'] = $line['speed']; // speed
713
+			$data['heading'] = $line['track']; // heading
714
+			$data['latitude'] = $line['lat']; // lat
715
+			$data['longitude'] = $line['lon']; // long
716
+			$data['verticalrate'] = $line['vrt']; // verticale rate
717
+			$data['squawk'] = $line['squawk']; // squawk
718
+			$data['emergency'] = ''; // emergency
719
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
+			else $data['datetime'] = date('Y-m-d H:i:s');
721
+				$data['format_source'] = 'aircraftlistjson';
722
+				$data['id_source'] = $id_source;
723
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
725
+			$SI->add($data);
726
+			unset($data);
727
+		}
728
+		}
727 729
 		}
728
-	    }
729
-	    }
730
-    	    //$last_exec['aircraftlistjson'] = time();
731
-    	    $last_exec[$id]['last'] = time();
732
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
733
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
-	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
736
-	    if (isset($all_data['planes'])) {
730
+			//$last_exec['aircraftlistjson'] = time();
731
+			$last_exec[$id]['last'] = time();
732
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
733
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
+		$buffer = $Common->getData($value['host']);
735
+		$all_data = json_decode($buffer,true);
736
+		if (isset($all_data['planes'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['planes'] as $key => $line) {
739
-		    $data = array();
740
-		    $data['hex'] = $key; // hex
741
-		    $data['ident'] = $line[3]; // ident
742
-		    $data['altitude'] = $line[6]; // altitude
743
-		    $data['speed'] = $line[8]; // speed
744
-		    $data['heading'] = $line[7]; // heading
745
-		    $data['latitude'] = $line[4]; // lat
746
-		    $data['longitude'] = $line[5]; // long
747
-		    //$data['verticalrate'] = $line[]; // verticale rate
748
-		    $data['squawk'] = $line[10]; // squawk
749
-		    $data['emergency'] = ''; // emergency
750
-		    $data['registration'] = $line[2];
751
-		    $data['aircraft_icao'] = $line[0];
752
-		    $deparr = explode('-',$line[1]);
753
-		    if (count($deparr) == 2) {
739
+			$data = array();
740
+			$data['hex'] = $key; // hex
741
+			$data['ident'] = $line[3]; // ident
742
+			$data['altitude'] = $line[6]; // altitude
743
+			$data['speed'] = $line[8]; // speed
744
+			$data['heading'] = $line[7]; // heading
745
+			$data['latitude'] = $line[4]; // lat
746
+			$data['longitude'] = $line[5]; // long
747
+			//$data['verticalrate'] = $line[]; // verticale rate
748
+			$data['squawk'] = $line[10]; // squawk
749
+			$data['emergency'] = ''; // emergency
750
+			$data['registration'] = $line[2];
751
+			$data['aircraft_icao'] = $line[0];
752
+			$deparr = explode('-',$line[1]);
753
+			if (count($deparr) == 2) {
754 754
 			$data['departure_airport_icao'] = $deparr[0];
755 755
 			$data['arrival_airport_icao'] = $deparr[1];
756
-		    }
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758
-	    	    $data['format_source'] = 'planeupdatefaa';
759
-    		    $data['id_source'] = $id_source;
760
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
762
-		    $SI->add($data);
763
-		    unset($data);
756
+			}
757
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758
+				$data['format_source'] = 'planeupdatefaa';
759
+				$data['id_source'] = $id_source;
760
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
762
+			$SI->add($data);
763
+			unset($data);
764 764
 		}
765
-	    }
766
-    	    //$last_exec['planeupdatefaa'] = time();
767
-    	    $last_exec[$id]['last'] = time();
768
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
769
-	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
771
-	    if (isset($all_data['states'])) {
765
+		}
766
+			//$last_exec['planeupdatefaa'] = time();
767
+			$last_exec[$id]['last'] = time();
768
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
769
+		$buffer = $Common->getData($value['host']);
770
+		$all_data = json_decode($buffer,true);
771
+		if (isset($all_data['states'])) {
772 772
 		$reset = 0;
773 773
 		foreach ($all_data['states'] as $key => $line) {
774
-		    $data = array();
775
-		    $data['hex'] = $line[0]; // hex
776
-		    $data['ident'] = trim($line[1]); // ident
777
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
778
-		    $data['speed'] = round($line[9]*1.94384); // speed
779
-		    $data['heading'] = round($line[10]); // heading
780
-		    $data['latitude'] = $line[6]; // lat
781
-		    $data['longitude'] = $line[5]; // long
782
-		    $data['verticalrate'] = $line[11]; // verticale rate
783
-		    //$data['squawk'] = $line[10]; // squawk
784
-		    //$data['emergency'] = ''; // emergency
785
-		    //$data['registration'] = $line[2];
786
-		    //$data['aircraft_icao'] = $line[0];
787
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788
-	    	    $data['format_source'] = 'opensky';
789
-    		    $data['id_source'] = $id_source;
790
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
791
-		    $SI->add($data);
792
-		    unset($data);
774
+			$data = array();
775
+			$data['hex'] = $line[0]; // hex
776
+			$data['ident'] = trim($line[1]); // ident
777
+			$data['altitude'] = round($line[7]*3.28084); // altitude
778
+			$data['speed'] = round($line[9]*1.94384); // speed
779
+			$data['heading'] = round($line[10]); // heading
780
+			$data['latitude'] = $line[6]; // lat
781
+			$data['longitude'] = $line[5]; // long
782
+			$data['verticalrate'] = $line[11]; // verticale rate
783
+			//$data['squawk'] = $line[10]; // squawk
784
+			//$data['emergency'] = ''; // emergency
785
+			//$data['registration'] = $line[2];
786
+			//$data['aircraft_icao'] = $line[0];
787
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788
+				$data['format_source'] = 'opensky';
789
+				$data['id_source'] = $id_source;
790
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
791
+			$SI->add($data);
792
+			unset($data);
793
+		}
793 794
 		}
794
-	    }
795
-    	    //$last_exec['planeupdatefaa'] = time();
796
-    	    $last_exec[$id]['last'] = time();
797
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
798
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
-	    //$buffer = $Common->getData($hosts[$id]);
800
-	    $buffer = $Common->getData($value['host']);
801
-	    $all_data = json_decode($buffer,true);
802
-	    if (!empty($all_data)) $reset = 0;
803
-	    foreach ($all_data as $key => $line) {
795
+			//$last_exec['planeupdatefaa'] = time();
796
+			$last_exec[$id]['last'] = time();
797
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
798
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
+		//$buffer = $Common->getData($hosts[$id]);
800
+		$buffer = $Common->getData($value['host']);
801
+		$all_data = json_decode($buffer,true);
802
+		if (!empty($all_data)) $reset = 0;
803
+		foreach ($all_data as $key => $line) {
804 804
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
805
-		    $data = array();
806
-		    $data['hex'] = $line[0];
807
-		    $data['ident'] = $line[16]; //$line[13]
808
-	    	    $data['altitude'] = $line[4]; // altitude
809
-	    	    $data['speed'] = $line[5]; // speed
810
-	    	    $data['heading'] = $line[3]; // heading
811
-	    	    $data['latitude'] = $line[1]; // lat
812
-	    	    $data['longitude'] = $line[2]; // long
813
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
814
-	    	    $data['squawk'] = $line[6]; // squawk
815
-	    	    $data['aircraft_icao'] = $line[8];
816
-	    	    $data['registration'] = $line[9];
817
-		    $data['departure_airport_iata'] = $line[11];
818
-		    $data['arrival_airport_iata'] = $line[12];
819
-	    	    $data['emergency'] = ''; // emergency
820
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821
-	    	    $data['format_source'] = 'fr24json';
822
-    		    $data['id_source'] = $id_source;
823
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
825
-		    $SI->add($data);
826
-		    unset($data);
805
+			$data = array();
806
+			$data['hex'] = $line[0];
807
+			$data['ident'] = $line[16]; //$line[13]
808
+				$data['altitude'] = $line[4]; // altitude
809
+				$data['speed'] = $line[5]; // speed
810
+				$data['heading'] = $line[3]; // heading
811
+				$data['latitude'] = $line[1]; // lat
812
+				$data['longitude'] = $line[2]; // long
813
+				$data['verticalrate'] = $line[15]; // verticale rate
814
+				$data['squawk'] = $line[6]; // squawk
815
+				$data['aircraft_icao'] = $line[8];
816
+				$data['registration'] = $line[9];
817
+			$data['departure_airport_iata'] = $line[11];
818
+			$data['arrival_airport_iata'] = $line[12];
819
+				$data['emergency'] = ''; // emergency
820
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821
+				$data['format_source'] = 'fr24json';
822
+				$data['id_source'] = $id_source;
823
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
825
+			$SI->add($data);
826
+			unset($data);
827
+		}
827 828
 		}
828
-	    }
829
-    	    //$last_exec['fr24json'] = time();
830
-    	    $last_exec[$id]['last'] = time();
831
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
832
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
833
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
834
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
835
-	    //echo $buffer;
836
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
837
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
838
-	    $all_data = json_decode($buffer,true);
839
-	    if (json_last_error() != JSON_ERROR_NONE) {
829
+			//$last_exec['fr24json'] = time();
830
+			$last_exec[$id]['last'] = time();
831
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
832
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
833
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
834
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
835
+		//echo $buffer;
836
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
837
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
838
+		$all_data = json_decode($buffer,true);
839
+		if (json_last_error() != JSON_ERROR_NONE) {
840 840
 		die(json_last_error_msg());
841
-	    }
842
-	    if (isset($all_data['mrkrs'])) {
841
+		}
842
+		if (isset($all_data['mrkrs'])) {
843 843
 		$reset = 0;
844 844
 		foreach ($all_data['mrkrs'] as $key => $line) {
845
-		    if (isset($line['inf'])) {
845
+			if (isset($line['inf'])) {
846 846
 			$data = array();
847 847
 			$data['hex'] = $line['inf']['ia'];
848 848
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
849
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
852
-	    		$data['latitude'] = $line['pt'][0]; // lat
853
-	    		$data['longitude'] = $line['pt'][1]; // long
854
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
856
-	    		//$data['aircraft_icao'] = $line[8];
857
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
849
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
852
+				$data['latitude'] = $line['pt'][0]; // lat
853
+				$data['longitude'] = $line['pt'][1]; // long
854
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
856
+				//$data['aircraft_icao'] = $line[8];
857
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
858 858
 			//$data['departure_airport_iata'] = $line[11];
859 859
 			//$data['arrival_airport_iata'] = $line[12];
860
-	    		//$data['emergency'] = ''; // emergency
860
+				//$data['emergency'] = ''; // emergency
861 861
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
862
-	    		$data['format_source'] = 'radarvirtueljson';
863
-    			$data['id_source'] = $id_source;
862
+				$data['format_source'] = 'radarvirtueljson';
863
+				$data['id_source'] = $id_source;
864 864
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
865 865
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
866 866
 			$SI->add($data);
867 867
 			unset($data);
868
-		    }
868
+			}
869
+		}
869 870
 		}
870
-	    }
871
-    	    //$last_exec['radarvirtueljson'] = time();
872
-    	    $last_exec[$id]['last'] = time();
873
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
874
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
875
-	    //$buffer = $Common->getData($hosts[$id]);
876
-	    $buffer = $Common->getData($value['host'].'?'.time());
877
-	    $all_data = json_decode(utf8_encode($buffer),true);
871
+			//$last_exec['radarvirtueljson'] = time();
872
+			$last_exec[$id]['last'] = time();
873
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
874
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
875
+		//$buffer = $Common->getData($hosts[$id]);
876
+		$buffer = $Common->getData($value['host'].'?'.time());
877
+		$all_data = json_decode(utf8_encode($buffer),true);
878 878
 	    
879
-	    if (isset($all_data['pireps'])) {
879
+		if (isset($all_data['pireps'])) {
880 880
 		$reset = 0;
881
-	        foreach ($all_data['pireps'] as $line) {
882
-		    $data = array();
883
-		    $data['id'] = $line['id'];
884
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885
-		    $data['ident'] = $line['callsign']; // ident
886
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
892
-		    $data['latitude'] = $line['lat']; // lat
893
-		    $data['longitude'] = $line['lon']; // long
894
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
895
-		    //$data['squawk'] = $line['squawk']; // squawk
896
-		    //$data['emergency'] = ''; // emergency
897
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
900
-		    //$data['arrival_airport_time'] = $line['arrtime'];
901
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
904
-		    else $data['info'] = '';
905
-		    $data['format_source'] = 'pireps';
906
-    		    $data['id_source'] = $id_source;
907
-		    $data['datetime'] = date('Y-m-d H:i:s');
908
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
910
-		    if ($line['icon'] == 'plane') {
881
+			foreach ($all_data['pireps'] as $line) {
882
+			$data = array();
883
+			$data['id'] = $line['id'];
884
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885
+			$data['ident'] = $line['callsign']; // ident
886
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
892
+			$data['latitude'] = $line['lat']; // lat
893
+			$data['longitude'] = $line['lon']; // long
894
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
895
+			//$data['squawk'] = $line['squawk']; // squawk
896
+			//$data['emergency'] = ''; // emergency
897
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
900
+			//$data['arrival_airport_time'] = $line['arrtime'];
901
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
904
+			else $data['info'] = '';
905
+			$data['format_source'] = 'pireps';
906
+				$data['id_source'] = $id_source;
907
+			$data['datetime'] = date('Y-m-d H:i:s');
908
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
910
+			if ($line['icon'] == 'plane') {
911 911
 			$SI->add($data);
912
-		    //    print_r($data);
913
-    		    } elseif ($line['icon'] == 'ct') {
912
+			//    print_r($data);
913
+				} elseif ($line['icon'] == 'ct') {
914 914
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
915 915
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
916 916
 			$typec = substr($data['ident'],-3);
@@ -925,199 +925,199 @@  discard block
 block discarded – undo
925 925
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
926 926
 			else $data['type'] = 'Observer';
927 927
 			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']);
928
-		    }
929
-		    unset($data);
928
+			}
929
+			unset($data);
930
+		}
930 931
 		}
931
-	    }
932
-    	    //$last_exec['pirepsjson'] = time();
933
-    	    $last_exec[$id]['last'] = time();
934
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936
-	    //$buffer = $Common->getData($hosts[$id]);
937
-	    if ($globalDebug) echo 'Get Data...'."\n";
938
-	    $buffer = $Common->getData($value['host']);
939
-	    $all_data = json_decode($buffer,true);
940
-	    if ($buffer != '' && is_array($all_data)) {
932
+			//$last_exec['pirepsjson'] = time();
933
+			$last_exec[$id]['last'] = time();
934
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936
+		//$buffer = $Common->getData($hosts[$id]);
937
+		if ($globalDebug) echo 'Get Data...'."\n";
938
+		$buffer = $Common->getData($value['host']);
939
+		$all_data = json_decode($buffer,true);
940
+		if ($buffer != '' && is_array($all_data)) {
941 941
 		$reset = 0;
942 942
 		foreach ($all_data as $line) {
943
-	    	    $data = array();
944
-	    	    //$data['id'] = $line['id']; // id not usable
945
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
946
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
949
-	    	    $data['ident'] = $line['flightnum']; // ident
950
-	    	    $data['altitude'] = $line['alt']; // altitude
951
-	    	    $data['speed'] = $line['gs']; // speed
952
-	    	    $data['heading'] = $line['heading']; // heading
953
-	    	    $data['latitude'] = $line['lat']; // lat
954
-	    	    $data['longitude'] = $line['lng']; // long
955
-	    	    $data['verticalrate'] = ''; // verticale rate
956
-	    	    $data['squawk'] = ''; // squawk
957
-	    	    $data['emergency'] = ''; // emergency
958
-	    	    //$data['datetime'] = $line['lastupdate'];
959
-	    	    $data['last_update'] = $line['lastupdate'];
960
-		    $data['datetime'] = date('Y-m-d H:i:s');
961
-	    	    $data['departure_airport_icao'] = $line['depicao'];
962
-	    	    $data['departure_airport_time'] = $line['deptime'];
963
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
964
-    		    $data['arrival_airport_time'] = $line['arrtime'];
965
-    		    $data['registration'] = $line['aircraft'];
966
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
968
-		    if (isset($line['aircraftname'])) {
943
+				$data = array();
944
+				//$data['id'] = $line['id']; // id not usable
945
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
946
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
949
+				$data['ident'] = $line['flightnum']; // ident
950
+				$data['altitude'] = $line['alt']; // altitude
951
+				$data['speed'] = $line['gs']; // speed
952
+				$data['heading'] = $line['heading']; // heading
953
+				$data['latitude'] = $line['lat']; // lat
954
+				$data['longitude'] = $line['lng']; // long
955
+				$data['verticalrate'] = ''; // verticale rate
956
+				$data['squawk'] = ''; // squawk
957
+				$data['emergency'] = ''; // emergency
958
+				//$data['datetime'] = $line['lastupdate'];
959
+				$data['last_update'] = $line['lastupdate'];
960
+			$data['datetime'] = date('Y-m-d H:i:s');
961
+				$data['departure_airport_icao'] = $line['depicao'];
962
+				$data['departure_airport_time'] = $line['deptime'];
963
+				$data['arrival_airport_icao'] = $line['arricao'];
964
+				$data['arrival_airport_time'] = $line['arrtime'];
965
+				$data['registration'] = $line['aircraft'];
966
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
968
+			if (isset($line['aircraftname'])) {
969 969
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
970 970
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
971
-	    		$aircraft_data = explode('-',$line['aircraftname']);
972
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
-	    		else {
975
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
976
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
978
-	    		}
979
-	    	    }
980
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
981
-    		    $data['id_source'] = $id_source;
982
-	    	    $data['format_source'] = 'phpvmacars';
983
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
984
-		    $SI->add($data);
985
-		    unset($data);
971
+				$aircraft_data = explode('-',$line['aircraftname']);
972
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
+				else {
975
+					$aircraft_data = explode(' ',$line['aircraftname']);
976
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
978
+				}
979
+				}
980
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
981
+				$data['id_source'] = $id_source;
982
+				$data['format_source'] = 'phpvmacars';
983
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
984
+			$SI->add($data);
985
+			unset($data);
986 986
 		}
987 987
 		if ($globalDebug) echo 'No more data...'."\n";
988 988
 		unset($buffer);
989 989
 		unset($all_data);
990
-	    }
991
-    	    //$last_exec['phpvmacars'] = time();
992
-    	    $last_exec[$id]['last'] = time();
993
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994
-	    //$buffer = $Common->getData($hosts[$id]);
995
-	    if ($globalDebug) echo 'Get Data...'."\n";
996
-	    $buffer = $Common->getData($value['host']);
997
-	    $all_data = json_decode($buffer,true);
998
-	    if ($buffer != '' && is_array($all_data)) {
990
+		}
991
+			//$last_exec['phpvmacars'] = time();
992
+			$last_exec[$id]['last'] = time();
993
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994
+		//$buffer = $Common->getData($hosts[$id]);
995
+		if ($globalDebug) echo 'Get Data...'."\n";
996
+		$buffer = $Common->getData($value['host']);
997
+		$all_data = json_decode($buffer,true);
998
+		if ($buffer != '' && is_array($all_data)) {
999 999
 		$reset = 0;
1000 1000
 		foreach ($all_data as $line) {
1001
-	    	    $data = array();
1002
-	    	    //$data['id'] = $line['id']; // id not usable
1003
-	    	    $data['id'] = trim($line['flight_id']);
1004
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1005
-	    	    $data['pilot_name'] = $line['pilot_name'];
1006
-	    	    $data['pilot_id'] = $line['pilot_id'];
1007
-	    	    $data['ident'] = trim($line['callsign']); // ident
1008
-	    	    $data['altitude'] = $line['altitude']; // altitude
1009
-	    	    $data['speed'] = $line['gs']; // speed
1010
-	    	    $data['heading'] = $line['heading']; // heading
1011
-	    	    $data['latitude'] = $line['latitude']; // lat
1012
-	    	    $data['longitude'] = $line['longitude']; // long
1013
-	    	    $data['verticalrate'] = ''; // verticale rate
1014
-	    	    $data['squawk'] = ''; // squawk
1015
-	    	    $data['emergency'] = ''; // emergency
1016
-	    	    //$data['datetime'] = $line['lastupdate'];
1017
-	    	    $data['last_update'] = $line['last_update'];
1018
-		    $data['datetime'] = date('Y-m-d H:i:s');
1019
-	    	    $data['departure_airport_icao'] = $line['departure'];
1020
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1021
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1022
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1023
-    		    //$data['registration'] = $line['aircraft'];
1024
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1025
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1026
-    		    $data['id_source'] = $id_source;
1027
-	    	    $data['format_source'] = 'vam';
1028
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
-		    $SI->add($data);
1031
-		    unset($data);
1001
+				$data = array();
1002
+				//$data['id'] = $line['id']; // id not usable
1003
+				$data['id'] = trim($line['flight_id']);
1004
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1005
+				$data['pilot_name'] = $line['pilot_name'];
1006
+				$data['pilot_id'] = $line['pilot_id'];
1007
+				$data['ident'] = trim($line['callsign']); // ident
1008
+				$data['altitude'] = $line['altitude']; // altitude
1009
+				$data['speed'] = $line['gs']; // speed
1010
+				$data['heading'] = $line['heading']; // heading
1011
+				$data['latitude'] = $line['latitude']; // lat
1012
+				$data['longitude'] = $line['longitude']; // long
1013
+				$data['verticalrate'] = ''; // verticale rate
1014
+				$data['squawk'] = ''; // squawk
1015
+				$data['emergency'] = ''; // emergency
1016
+				//$data['datetime'] = $line['lastupdate'];
1017
+				$data['last_update'] = $line['last_update'];
1018
+			$data['datetime'] = date('Y-m-d H:i:s');
1019
+				$data['departure_airport_icao'] = $line['departure'];
1020
+				//$data['departure_airport_time'] = $line['departure_time'];
1021
+				$data['arrival_airport_icao'] = $line['arrival'];
1022
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1023
+				//$data['registration'] = $line['aircraft'];
1024
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1025
+				$data['aircraft_icao'] = $line['plane_type'];
1026
+				$data['id_source'] = $id_source;
1027
+				$data['format_source'] = 'vam';
1028
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
+			$SI->add($data);
1031
+			unset($data);
1032 1032
 		}
1033 1033
 		if ($globalDebug) echo 'No more data...'."\n";
1034 1034
 		unset($buffer);
1035 1035
 		unset($all_data);
1036
-	    }
1037
-    	    //$last_exec['phpvmacars'] = time();
1038
-    	    $last_exec[$id]['last'] = time();
1036
+		}
1037
+			//$last_exec['phpvmacars'] = time();
1038
+			$last_exec[$id]['last'] = time();
1039 1039
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1040 1040
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1041
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1042
-    	    //$last_exec[$id]['last'] = time();
1041
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1042
+			//$last_exec[$id]['last'] = time();
1043 1043
 
1044
-	    //$read = array( $sockets[$id] );
1045
-	    $read = $sockets;
1046
-	    $write = NULL;
1047
-	    $e = NULL;
1048
-	    $n = socket_select($read, $write, $e, $timeout);
1049
-	    if ($e != NULL) var_dump($e);
1050
-	    if ($n > 0) {
1044
+		//$read = array( $sockets[$id] );
1045
+		$read = $sockets;
1046
+		$write = NULL;
1047
+		$e = NULL;
1048
+		$n = socket_select($read, $write, $e, $timeout);
1049
+		if ($e != NULL) var_dump($e);
1050
+		if ($n > 0) {
1051 1051
 		$reset = 0;
1052 1052
 		foreach ($read as $nb => $r) {
1053
-		    //$value = $formats[$nb];
1054
-		    $format = $globalSources[$nb]['format'];
1055
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1053
+			//$value = $formats[$nb];
1054
+			$format = $globalSources[$nb]['format'];
1055
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1056 1056
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1057
-		    } elseif ($format == 'vrstcp') {
1057
+			} elseif ($format == 'vrstcp') {
1058 1058
 			$buffer = @socket_read($r, 6000);
1059
-		    } else {
1059
+			} else {
1060 1060
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1061
-		    }
1062
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1063
-		    //echo $buffer."\n";
1064
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1065
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1066
-		    $error = false;
1067
-		    //$SI::del();
1068
-		    if ($format == 'vrstcp') {
1061
+			}
1062
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1063
+			//echo $buffer."\n";
1064
+			// lets play nice and handle signals such as ctrl-c/kill properly
1065
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1066
+			$error = false;
1067
+			//$SI::del();
1068
+			if ($format == 'vrstcp') {
1069 1069
 			$buffer = explode('},{',$buffer);
1070
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1071
-		    // SBS format is CSV format
1072
-		    if ($buffer !== FALSE && $buffer != '') {
1070
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1071
+			// SBS format is CSV format
1072
+			if ($buffer !== FALSE && $buffer != '') {
1073 1073
 			$tt[$format] = 0;
1074 1074
 			if ($format == 'acarssbs3') {
1075
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1076
-			    $ACARS->add(trim($buffer));
1077
-			    $ACARS->deleteLiveAcarsData();
1075
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1076
+				$ACARS->add(trim($buffer));
1077
+				$ACARS->deleteLiveAcarsData();
1078 1078
 			} elseif ($format == 'raw') {
1079
-			    // AVR format
1080
-			    $data = $SBS->parse($buffer);
1081
-			    if (is_array($data)) {
1079
+				// AVR format
1080
+				$data = $SBS->parse($buffer);
1081
+				if (is_array($data)) {
1082 1082
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1083
 				$data['format_source'] = 'raw';
1084 1084
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1085 1085
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1086 1086
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1087 1087
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1088
-			    }
1088
+				}
1089 1089
 			} elseif ($format == 'ais') {
1090
-			    $ais_data = $AIS->parse_line(trim($buffer));
1091
-			    $data = array();
1092
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1106
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1107
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1090
+				$ais_data = $AIS->parse_line(trim($buffer));
1091
+				$data = array();
1092
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1106
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1107
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1108 1108
 
1109
-			    if (isset($ais_data['timestamp'])) {
1109
+				if (isset($ais_data['timestamp'])) {
1110 1110
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1111
-			    } else {
1111
+				} else {
1112 1112
 				$data['datetime'] = date('Y-m-d H:i:s');
1113
-			    }
1114
-			    $data['format_source'] = 'aisnmea';
1115
-    			    $data['id_source'] = $id_source;
1116
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1117
-			    unset($data);
1118
-                        } elseif ($format == 'flightgearsp') {
1119
-                    	    //echo $buffer."\n";
1120
-                    	    if (strlen($buffer) > 5) {
1113
+				}
1114
+				$data['format_source'] = 'aisnmea';
1115
+					$data['id_source'] = $id_source;
1116
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1117
+				unset($data);
1118
+						} elseif ($format == 'flightgearsp') {
1119
+							//echo $buffer."\n";
1120
+							if (strlen($buffer) > 5) {
1121 1121
 				$line = explode(',',$buffer);
1122 1122
 				$data = array();
1123 1123
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1134,38 +1134,38 @@  discard block
 block discarded – undo
1134 1134
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1135 1135
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1136 1136
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1137
-			    }
1138
-                        } elseif ($format == 'acars') {
1139
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1140
-			    $ACARS->add(trim($buffer));
1141
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1142
-			    $ACARS->deleteLiveAcarsData();
1137
+				}
1138
+						} elseif ($format == 'acars') {
1139
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1140
+				$ACARS->add(trim($buffer));
1141
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1142
+				$ACARS->deleteLiveAcarsData();
1143 1143
 			} elseif ($format == 'flightgearmp') {
1144
-			    if (substr($buffer,0,1) != '#') {
1144
+				if (substr($buffer,0,1) != '#') {
1145 1145
 				$data = array();
1146 1146
 				//echo $buffer."\n";
1147 1147
 				$line = explode(' ',$buffer);
1148 1148
 				if (count($line) == 11) {
1149
-				    $userserver = explode('@',$line[0]);
1150
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1151
-				    $data['ident'] = $userserver[0];
1152
-				    $data['registration'] = $userserver[0];
1153
-				    $data['latitude'] = $line[4];
1154
-				    $data['longitude'] = $line[5];
1155
-				    $data['altitude'] = $line[6];
1156
-				    $data['datetime'] = date('Y-m-d H:i:s');
1157
-				    $aircraft_type = $line[10];
1158
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1159
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1160
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1161
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1149
+					$userserver = explode('@',$line[0]);
1150
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1151
+					$data['ident'] = $userserver[0];
1152
+					$data['registration'] = $userserver[0];
1153
+					$data['latitude'] = $line[4];
1154
+					$data['longitude'] = $line[5];
1155
+					$data['altitude'] = $line[6];
1156
+					$data['datetime'] = date('Y-m-d H:i:s');
1157
+					$aircraft_type = $line[10];
1158
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1159
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1160
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1161
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1162
+				}
1162 1163
 				}
1163
-			    }
1164 1164
 			} elseif ($format == 'beast') {
1165
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1166
-			    die;
1165
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1166
+				die;
1167 1167
 			} elseif ($format == 'vrstcp') {
1168
-			    foreach($buffer as $all_data) {
1168
+				foreach($buffer as $all_data) {
1169 1169
 				$line = json_decode('{'.$all_data.'}',true);
1170 1170
 				$data = array();
1171 1171
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1185,113 +1185,113 @@  discard block
 block discarded – undo
1185 1185
 				*/
1186 1186
 				$data['datetime'] = date('Y-m-d H:i:s');
1187 1187
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1188
-		    		$data['format_source'] = 'vrstcp';
1188
+					$data['format_source'] = 'vrstcp';
1189 1189
 				$data['id_source'] = $id_source;
1190 1190
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1191 1191
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1192 1192
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1193 1193
 				unset($data);
1194
-			    }
1194
+				}
1195 1195
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1196
-			    $line = explode("\t", $buffer);
1197
-			    for($k = 0; $k < count($line); $k=$k+2) {
1196
+				$line = explode("\t", $buffer);
1197
+				for($k = 0; $k < count($line); $k=$k+2) {
1198 1198
 				$key = $line[$k];
1199
-			        $lined[$key] = $line[$k+1];
1200
-			    }
1201
-    			    if (count($lined) > 3) {
1202
-    				$data['hex'] = $lined['hexid'];
1203
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1204
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1205
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1206
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1207
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1208
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1209
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1210
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1211
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1212
-    				$data['id_source'] = $id_source;
1213
-    				$data['format_source'] = 'tsv';
1214
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1215
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1199
+					$lined[$key] = $line[$k+1];
1200
+				}
1201
+					if (count($lined) > 3) {
1202
+					$data['hex'] = $lined['hexid'];
1203
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1204
+					$data['datetime'] = date('Y-m-d H:i:s');;
1205
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1206
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1207
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1208
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1209
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1210
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1211
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1212
+					$data['id_source'] = $id_source;
1213
+					$data['format_source'] = 'tsv';
1214
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1215
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1216 1216
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1217
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1218
-    				unset($lined);
1219
-    				unset($data);
1220
-    			    } else $error = true;
1217
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1218
+					unset($lined);
1219
+					unset($data);
1220
+					} else $error = true;
1221 1221
 			} elseif ($format == 'aprs' && $use_aprs) {
1222
-			    if ($aprs_connect == 0) {
1222
+				if ($aprs_connect == 0) {
1223 1223
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1224 1224
 				$aprs_connect = 1;
1225
-			    }
1225
+				}
1226 1226
 			    
1227
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1227
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1228 1228
 				$aprs_last_tx = time();
1229 1229
 				$data_aprs = "# Keep alive";
1230 1230
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1231
-			    }
1231
+				}
1232 1232
 			    
1233
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1234
-			    //echo 'APRS data : '.$buffer."\n";
1235
-			    $buffer = str_replace('APRS <- ','',$buffer);
1236
-			    $buffer = str_replace('APRS -> ','',$buffer);
1237
-			    //echo $buffer."\n";
1238
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1233
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1234
+				//echo 'APRS data : '.$buffer."\n";
1235
+				$buffer = str_replace('APRS <- ','',$buffer);
1236
+				$buffer = str_replace('APRS -> ','',$buffer);
1237
+				//echo $buffer."\n";
1238
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1239 1239
 				$line = $APRS->parse($buffer);
1240 1240
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1241 1241
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1242
-				    $aprs_last_tx = time();
1243
-				    $data = array();
1244
-				    //print_r($line);
1245
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1246
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1247
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1248
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1249
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1250
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1251
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1252
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1253
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1254
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1255
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1256
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1257
-				    $data['latitude'] = $line['latitude'];
1258
-				    $data['longitude'] = $line['longitude'];
1259
-				    //$data['verticalrate'] = $line[16];
1260
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1261
-				    else $data['speed'] = 0;
1262
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1263
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1264
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1265
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1266
-				    //else $data['heading'] = 0;
1267
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1268
-				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1269
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1270
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1271
-    				    $data['id_source'] = $id_source;
1272
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1273
-				    else $data['format_source'] = 'aprs';
1274
-				    $data['source_name'] = $line['source'];
1275
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1276
-				    else $data['source_type'] = 'flarm';
1277
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1278
-				    $currentdate = date('Y-m-d H:i:s');
1279
-				    $aprsdate = strtotime($data['datetime']);
1280
-				    // Accept data if time <= system time + 20s
1281
-				    //if (($data['source_type'] == 'modes') || 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'])))) {
1282
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1242
+					$aprs_last_tx = time();
1243
+					$data = array();
1244
+					//print_r($line);
1245
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1246
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1247
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1248
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1249
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1250
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1251
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1252
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1253
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1254
+					else $data['datetime'] = date('Y-m-d H:i:s');
1255
+					//$data['datetime'] = date('Y-m-d H:i:s');
1256
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1257
+					$data['latitude'] = $line['latitude'];
1258
+					$data['longitude'] = $line['longitude'];
1259
+					//$data['verticalrate'] = $line[16];
1260
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1261
+					else $data['speed'] = 0;
1262
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1263
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1264
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1265
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1266
+					//else $data['heading'] = 0;
1267
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1268
+					if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1269
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1270
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1271
+						$data['id_source'] = $id_source;
1272
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1273
+					else $data['format_source'] = 'aprs';
1274
+					$data['source_name'] = $line['source'];
1275
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1276
+					else $data['source_type'] = 'flarm';
1277
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1278
+					$currentdate = date('Y-m-d H:i:s');
1279
+					$aprsdate = strtotime($data['datetime']);
1280
+					// Accept data if time <= system time + 20s
1281
+					//if (($data['source_type'] == 'modes') || 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'])))) {
1282
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1283 1283
 					$send = $SI->add($data);
1284
-				    } elseif ($data['source_type'] == 'ais') {
1284
+					} elseif ($data['source_type'] == 'ais') {
1285 1285
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1286
-				    } elseif (isset($line['stealth'])) {
1286
+					} elseif (isset($line['stealth'])) {
1287 1287
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1288 1288
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1289
-				    //} 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')) {
1290
-				    } 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') {
1289
+					//} 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')) {
1290
+					} 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') {
1291 1291
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1292 1292
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1293
-				    }
1294
-				    unset($data);
1293
+					}
1294
+					unset($data);
1295 1295
 				} 
1296 1296
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1297 1297
 					echo '!! Weather Station not yet supported'."\n";
@@ -1301,12 +1301,12 @@  discard block
 block discarded – undo
1301 1301
 				}
1302 1302
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1303 1303
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1304
-			    }
1304
+				}
1305 1305
 			} else {
1306
-			    $line = explode(',', $buffer);
1307
-    			    if (count($line) > 20) {
1308
-    			    	$data['hex'] = $line[4];
1309
-    				/*
1306
+				$line = explode(',', $buffer);
1307
+					if (count($line) > 20) {
1308
+						$data['hex'] = $line[4];
1309
+					/*
1310 1310
     				$data['datetime'] = $line[6].' '.$line[7];
1311 1311
     					date_default_timezone_set($globalTimezone);
1312 1312
     					$datetime = new DateTime($data['datetime']);
@@ -1314,30 +1314,30 @@  discard block
 block discarded – undo
1314 1314
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1315 1315
     					date_default_timezone_set('UTC');
1316 1316
     				*/
1317
-    				// Force datetime to current UTC datetime
1318
-    				date_default_timezone_set('UTC');
1319
-    				$data['datetime'] = date('Y-m-d H:i:s');
1320
-    				$data['ident'] = trim($line[10]);
1321
-    				$data['latitude'] = $line[14];
1322
-    				$data['longitude'] = $line[15];
1323
-    				$data['verticalrate'] = $line[16];
1324
-    				$data['emergency'] = $line[20];
1325
-    				$data['speed'] = $line[12];
1326
-    				$data['squawk'] = $line[17];
1327
-    				$data['altitude'] = $line[11];
1328
-    				$data['heading'] = $line[13];
1329
-    				$data['ground'] = $line[21];
1330
-    				$data['emergency'] = $line[19];
1331
-    				$data['format_source'] = 'sbs';
1317
+					// Force datetime to current UTC datetime
1318
+					date_default_timezone_set('UTC');
1319
+					$data['datetime'] = date('Y-m-d H:i:s');
1320
+					$data['ident'] = trim($line[10]);
1321
+					$data['latitude'] = $line[14];
1322
+					$data['longitude'] = $line[15];
1323
+					$data['verticalrate'] = $line[16];
1324
+					$data['emergency'] = $line[20];
1325
+					$data['speed'] = $line[12];
1326
+					$data['squawk'] = $line[17];
1327
+					$data['altitude'] = $line[11];
1328
+					$data['heading'] = $line[13];
1329
+					$data['ground'] = $line[21];
1330
+					$data['emergency'] = $line[19];
1331
+					$data['format_source'] = 'sbs';
1332 1332
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1333
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1333
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1334 1334
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1335
-    				$data['id_source'] = $id_source;
1336
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1337
-    				else $error = true;
1338
-    				unset($data);
1339
-    			    } else $error = true;
1340
-			    if ($error) {
1335
+					$data['id_source'] = $id_source;
1336
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1337
+					else $error = true;
1338
+					unset($data);
1339
+					} else $error = true;
1340
+				if ($error) {
1341 1341
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1342 1342
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1343 1343
 				} else {
@@ -1353,13 +1353,13 @@  discard block
 block discarded – undo
1353 1353
 					connect_all($sourceer);
1354 1354
 					$sourceer = array();
1355 1355
 				}
1356
-			    }
1356
+				}
1357 1357
 			}
1358 1358
 			// Sleep for xxx microseconds
1359 1359
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1360
-		    } else {
1360
+			} else {
1361 1361
 			if ($format == 'flightgearmp') {
1362
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1362
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1363 1363
 				//@socket_close($r);
1364 1364
 				sleep($globalMinFetch);
1365 1365
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1368,9 +1368,9 @@  discard block
 block discarded – undo
1368 1368
 				break;
1369 1369
 				
1370 1370
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1371
-			    if (isset($tt[$format])) $tt[$format]++;
1372
-			    else $tt[$format] = 0;
1373
-			    if ($tt[$format] > 30) {
1371
+				if (isset($tt[$format])) $tt[$format]++;
1372
+				else $tt[$format] = 0;
1373
+				if ($tt[$format] > 30) {
1374 1374
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1375 1375
 				//@socket_close($r);
1376 1376
 				sleep(2);
@@ -1381,23 +1381,23 @@  discard block
 block discarded – undo
1381 1381
 				//connect_all($globalSources);
1382 1382
 				$tt[$format]=0;
1383 1383
 				break;
1384
-			    }
1384
+				}
1385
+			}
1385 1386
 			}
1386
-		    }
1387 1387
 		}
1388
-	    } else {
1388
+		} else {
1389 1389
 		$error = socket_strerror(socket_last_error());
1390 1390
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1391 1391
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1392 1392
 			if (isset($globalDebug)) echo "Restarting...\n";
1393 1393
 			// Restart the script if possible
1394 1394
 			if (is_array($sockets)) {
1395
-			    if ($globalDebug) echo "Shutdown all sockets...";
1395
+				if ($globalDebug) echo "Shutdown all sockets...";
1396 1396
 			    
1397
-			    foreach ($sockets as $sock) {
1397
+				foreach ($sockets as $sock) {
1398 1398
 				@socket_shutdown($sock,2);
1399 1399
 				@socket_close($sock);
1400
-			    }
1400
+				}
1401 1401
 			    
1402 1402
 			}
1403 1403
 			if ($globalDebug) echo "Waiting...";
@@ -1412,13 +1412,13 @@  discard block
 block discarded – undo
1412 1412
 			if ($globalDebug) echo "Restart all connections...";
1413 1413
 			connect_all($globalSources);
1414 1414
 		}
1415
-	    }
1415
+		}
1416 1416
 	}
1417 1417
 	if ($globalDaemon === false) {
1418
-	    if ($globalDebug) echo 'Check all...'."\n";
1419
-	    $SI->checkAll();
1418
+		if ($globalDebug) echo 'Check all...'."\n";
1419
+		$SI->checkAll();
1420
+	}
1420 1421
 	}
1421
-    }
1422 1422
 }
1423 1423
 
1424 1424
 ?>
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -45,20 +45,20 @@  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','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver'));
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 56
     $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
57
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
58 58
     else $globalSources[] = array('host' => $options['s']);
59 59
 } elseif (isset($options['source'])) {
60 60
     $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
61
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
62 62
     else $globalSources[] = array('host' => $options['source']);
63 63
 }
64 64
 if (isset($options['aprsserverhost'])) {
@@ -75,27 +75,27 @@  discard block
 block discarded – undo
75 75
 else $id_source = 1;
76 76
 if (isset($globalServer) && $globalServer) {
77 77
     if ($globalDebug) echo "Using Server Mode\n";
78
-    $SI=new SpotterServer();
78
+    $SI = new SpotterServer();
79 79
 /*
80 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 81
     $SI = new adsb2aprs();
82 82
     $SI->connect();
83 83
 */
84
-} else $SI=new SpotterImport($Connection->db);
84
+} else $SI = new SpotterImport($Connection->db);
85 85
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
86 86
 if (isset($globalMarine) && $globalMarine) {
87 87
     $AIS = new AIS();
88 88
     $MI = new MarineImport($Connection->db);
89 89
 }
90 90
 //$APRS=new APRS($Connection->db);
91
-$SBS=new SBS();
92
-$ACARS=new ACARS($Connection->db);
93
-$Common=new Common();
91
+$SBS = new SBS();
92
+$ACARS = new ACARS($Connection->db);
93
+$Common = new Common();
94 94
 date_default_timezone_set('UTC');
95 95
 //$servertz = system('date +%Z');
96 96
 // signal handler - playing nice with sockets and dump1090
97 97
 if (function_exists('pcntl_fork')) {
98
-    pcntl_signal(SIGINT,  function() {
98
+    pcntl_signal(SIGINT, function() {
99 99
         global $sockets;
100 100
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
101 101
         die("Bye!\n");
@@ -111,35 +111,35 @@  discard block
 block discarded – undo
111 111
 
112 112
 function connect_all($hosts) {
113 113
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
114
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
115 115
     $reset++;
116 116
     if ($globalDebug) echo 'Connect to all...'."\n";
117 117
     foreach ($hosts as $id => $value) {
118 118
 	$host = $value['host'];
119 119
 	$globalSources[$id]['last_exec'] = 0;
120 120
 	// Here we check type of source(s)
121
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
122
-            if (preg_match('/deltadb.txt$/i',$host)) {
121
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
122
+            if (preg_match('/deltadb.txt$/i', $host)) {
123 123
         	//$formats[$id] = 'deltadbtxt';
124 124
         	$globalSources[$id]['format'] = 'deltadbtxt';
125 125
         	//$last_exec['deltadbtxt'] = 0;
126 126
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
127
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
128 128
         	//$formats[$id] = 'vatsimtxt';
129 129
         	$globalSources[$id]['format'] = 'vatsimtxt';
130 130
         	//$last_exec['vatsimtxt'] = 0;
131 131
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
132
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
133 133
         	//$formats[$id] = 'aircraftlistjson';
134 134
         	$globalSources[$id]['format'] = 'aircraftlistjson';
135 135
         	//$last_exec['aircraftlistjson'] = 0;
136 136
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
-    	    } else if (preg_match('/opensky/i',$host)) {
137
+    	    } else if (preg_match('/opensky/i', $host)) {
138 138
         	//$formats[$id] = 'aircraftlistjson';
139 139
         	$globalSources[$id]['format'] = 'opensky';
140 140
         	//$last_exec['aircraftlistjson'] = 0;
141 141
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
142
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
143 143
         	//$formats[$id] = 'radarvirtueljson';
144 144
         	$globalSources[$id]['format'] = 'radarvirtueljson';
145 145
         	//$last_exec['radarvirtueljson'] = 0;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149 149
         	    exit(0);
150 150
         	}
151
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
151
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
152 152
         	//$formats[$id] = 'planeupdatefaa';
153 153
         	$globalSources[$id]['format'] = 'planeupdatefaa';
154 154
         	//$last_exec['planeupdatefaa'] = 0;
@@ -157,26 +157,26 @@  discard block
 block discarded – undo
157 157
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158 158
         	    exit(0);
159 159
         	}
160
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
160
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
161 161
         	//$formats[$id] = 'phpvmacars';
162 162
         	$globalSources[$id]['format'] = 'phpvmacars';
163 163
         	//$last_exec['phpvmacars'] = 0;
164 164
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
165
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
166 166
         	//$formats[$id] = 'phpvmacars';
167 167
         	$globalSources[$id]['format'] = 'vam';
168 168
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
-            } else if (preg_match('/whazzup/i',$host)) {
169
+            } else if (preg_match('/whazzup/i', $host)) {
170 170
         	//$formats[$id] = 'whazzup';
171 171
         	$globalSources[$id]['format'] = 'whazzup';
172 172
         	//$last_exec['whazzup'] = 0;
173 173
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
-            } else if (preg_match('/recentpireps/i',$host)) {
174
+            } else if (preg_match('/recentpireps/i', $host)) {
175 175
         	//$formats[$id] = 'pirepsjson';
176 176
         	$globalSources[$id]['format'] = 'pirepsjson';
177 177
         	//$last_exec['pirepsjson'] = 0;
178 178
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
179
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
180 180
         	//$formats[$id] = 'fr24json';
181 181
         	$globalSources[$id]['format'] = 'fr24json';
182 182
         	//$last_exec['fr24json'] = 0;
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186 186
         	    exit(0);
187 187
         	}
188
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
188
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
189 189
         	//$formats[$id] = 'fr24json';
190 190
         	$globalSources[$id]['format'] = 'myshiptracking';
191 191
         	//$last_exec['fr24json'] = 0;
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
         	    exit(0);
196 196
         	}
197 197
             //} else if (preg_match('/10001/',$host)) {
198
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
198
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199 199
         	//$formats[$id] = 'tsv';
200 200
         	$globalSources[$id]['format'] = 'tsv';
201 201
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
202 202
             }
203
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
203
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
204 204
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
205
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
206 206
     		    if ($idf !== false) {
207 207
     			$httpfeeds[$id] = $idf;
208 208
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
209 209
     		    }
210 210
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211 211
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213
-	    $hostport = explode(':',$host);
212
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
213
+	    $hostport = explode(':', $host);
214 214
 	    if (isset($hostport[1])) {
215 215
 		$port = $hostport[1];
216 216
 		$hostn = $hostport[0];
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 	    }
221 221
 	    $Common = new Common();
222 222
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
223
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
223
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
224 224
     	    } else {
225
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
225
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
226 226
 	    }
227 227
 	    if ($s) {
228 228
     	        $sockets[$id] = $s;
229 229
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
230
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
230
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
231 231
 			//$formats[$id] = 'aprs';
232 232
 			$globalSources[$id]['format'] = 'aprs';
233 233
 			//$aprs_connect = 0;
234 234
 			//$use_aprs = true;
235
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
235
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
236 236
 			$globalSources[$id]['format'] = 'vrstcp';
237 237
     		    } elseif ($port == '10001') {
238 238
         		//$formats[$id] = 'tsv';
@@ -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
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
321 321
 	else $aprs_pass = '-1';
@@ -329,12 +329,12 @@  discard block
 block discarded – undo
329 329
 sleep(1);
330 330
 if ($globalDebug) echo "SCAN MODE \n\n";
331 331
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
332
-$endtime = time()+$globalCronEnd;
332
+$endtime = time() + $globalCronEnd;
333 333
 $i = 1;
334 334
 $tt = array();
335 335
 // Delete all ATC
336 336
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
337
-	$ATC=new ATC($Connection->db);
337
+	$ATC = new ATC($Connection->db);
338 338
 }
339 339
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
340 340
 	$ATC->deleteAll();
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 344
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
345
+    if (!$globalDaemon) $i = $endtime - time();
346 346
     // Delete old ATC
347 347
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348 348
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	}
358 358
 	if ($max != $globalMinFetch) {
359 359
 	    if ($globalDebug) echo 'Sleeping...'."\n";
360
-	    sleep($globalMinFetch-$max+2);
360
+	    sleep($globalMinFetch - $max + 2);
361 361
 	}
362 362
     }
363 363
 
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
 	    //$buffer = $Common->getData($hosts[$id]);
371 371
 	    $buffer = $Common->getData($value['host']);
372 372
 	    if ($buffer != '') $reset = 0;
373
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
-	    $buffer = explode('\n',$buffer);
373
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
374
+	    $buffer = explode('\n', $buffer);
375 375
 	    foreach ($buffer as $line) {
376 376
     		if ($line != '' && count($line) > 7) {
377 377
     		    $line = explode(',', $line);
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
     	    $last_exec[$id]['last'] = time();
400 400
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
401 401
 	    date_default_timezone_set('CET');
402
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
402
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
403 403
 	    date_default_timezone_set('UTC');
404 404
 	    if ($buffer != '') $reset = 0;
405
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406
-	    $buffer = explode('\n',$buffer);
405
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
406
+	    $buffer = explode('\n', $buffer);
407 407
 	    foreach ($buffer as $line) {
408 408
 		if ($line != '') {
409 409
 		    echo "'".$line."'\n";
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422 422
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
423 423
 		    if (isset($ais_data['timestamp'])) {
424
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
424
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
425 425
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
426 426
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
427 427
 			    $add = true;
@@ -444,12 +444,12 @@  discard block
 block discarded – undo
444 444
 	    $w = $e = null;
445 445
 	    
446 446
 	    if (isset($arr[$id])) {
447
-		$nn = stream_select($arr,$w,$e,$timeout);
447
+		$nn = stream_select($arr, $w, $e, $timeout);
448 448
 		if ($nn > 0) {
449 449
 		    foreach ($httpfeeds as $feed) {
450
-			$buffer = stream_get_line($feed,2000,"\n");
451
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
452
-			$buffer = explode('\n',$buffer);
450
+			$buffer = stream_get_line($feed, 2000, "\n");
451
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
452
+			$buffer = explode('\n', $buffer);
453 453
 			foreach ($buffer as $line) {
454 454
 			    if ($line != '') {
455 455
 				$ais_data = $AIS->parse_line(trim($line));
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
468 468
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
469 469
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
470
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
470
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
471 471
 				if (isset($ais_data['timestamp'])) {
472
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
472
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
473 473
 				} else {
474 474
 				    $data['datetime'] = date('Y-m-d H:i:s');
475 475
 				}
@@ -495,10 +495,10 @@  discard block
 block discarded – undo
495 495
 		}
496 496
 	    }
497 497
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
498
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
498
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
499 499
 	    if ($buffer != '') {
500 500
 		//echo $buffer;
501
-		$all_data = json_decode($buffer,true);
501
+		$all_data = json_decode($buffer, true);
502 502
 		//print_r($all_data);
503 503
 		if (isset($all_data[0]['DATA'])) {
504 504
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
514 514
 			$data['imo'] = $line['IMO'];
515 515
 			//$data['arrival_code'] = $ais_data['destination'];
516
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
516
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
517 517
 			$data['format_source'] = 'myshiptracking';
518 518
 			$data['id_source'] = $id_source;
519 519
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 	    }
527 527
     	    $last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
529
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
530 530
 	    if ($buffer != '') {
531
-		$all_data = json_decode($buffer,true);
531
+		$all_data = json_decode($buffer, true);
532 532
 		if (isset($all_data[0]['mmsi'])) {
533 533
 		    foreach ($all_data as $line) {
534 534
 			if ($line != '') {
@@ -556,27 +556,27 @@  discard block
 block discarded – undo
556 556
     	    $last_exec[$id]['last'] = time();
557 557
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
558 558
 	    echo 'download...';
559
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
559
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
560 560
 	    echo 'done !'."\n";
561 561
 	    if ($buffer != '') $reset = 0;
562
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563
-	    $buffer = explode('\n',$buffer);
562
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
563
+	    $buffer = explode('\n', $buffer);
564 564
 	    foreach ($buffer as $line) {
565 565
 		if ($line != '') {
566 566
 		    $data = array();
567
-		    $data['mmsi'] = (int)substr($line,0,9);
568
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
567
+		    $data['mmsi'] = (int) substr($line, 0, 9);
568
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
569 569
 		    //$data['status'] = substr($line,21,2);
570 570
 		    //$data['type'] = substr($line,24,3);
571
-		    $data['latitude'] = substr($line,29,9);
572
-		    $data['longitude'] = substr($line,41,9);
573
-		    $data['speed'] = round(substr($line,51,5));
571
+		    $data['latitude'] = substr($line, 29, 9);
572
+		    $data['longitude'] = substr($line, 41, 9);
573
+		    $data['speed'] = round(substr($line, 51, 5));
574 574
 		    //$data['course'] = substr($line,57,5);
575
-		    $data['heading'] = round(substr($line,63,3));
575
+		    $data['heading'] = round(substr($line, 63, 3));
576 576
 		    //$data['draft'] = substr($line,67,4);
577 577
 		    //$data['length'] = substr($line,72,3);
578 578
 		    //$data['beam'] = substr($line,76,2);
579
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
579
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
580 580
 		    //$data['callsign'] = trim(substr($line,100,7);
581 581
 		    //$data['dest'] = substr($line,108,20);
582 582
 		    //$data['etaDate'] = substr($line,129,5);
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
596 596
 	    //$buffer = $Common->getData($hosts[$id]);
597 597
 	    $buffer = $Common->getData($value['host']);
598
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
599
-	    $buffer = explode('\n',$buffer);
598
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
599
+	    $buffer = explode('\n', $buffer);
600 600
 	    $reset = 0;
601 601
 	    foreach ($buffer as $line) {
602 602
     		if ($line != '') {
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
608 608
 			$data['pilot_id'] = $line[1];
609 609
 			$data['pilot_name'] = $line[2];
610
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
610
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
611 611
 			$data['ident'] = $line[0]; // ident
612 612
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
613 613
 			$data['speed'] = $line[8]; // speed
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
624 624
 			//if (isset($line[37])) $data['last_update'] = $line[37];
625 625
 		        $data['departure_airport_icao'] = $line[11];
626
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
626
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
627 627
 		        $data['arrival_airport_icao'] = $line[13];
628 628
 			$data['frequency'] = $line[4];
629 629
 			$data['type'] = $line[18];
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     			$data['id_source'] = $id_source;
633 633
 	    		//$data['arrival_airport_time'] = ;
634 634
 	    		if ($line[9] != '') {
635
-	    		    $aircraft_data = explode('/',$line[9]);
635
+	    		    $aircraft_data = explode('/', $line[9]);
636 636
 	    		    if (isset($aircraft_data[1])) {
637 637
 	    			$data['aircraft_icao'] = $aircraft_data[1];
638 638
 	    		    }
@@ -647,9 +647,9 @@  discard block
 block discarded – undo
647 647
     			if ($line[3] == 'PILOT') $SI->add($data);
648 648
 			elseif ($line[3] == 'ATC') {
649 649
 				//print_r($data);
650
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
651
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
652
-				$typec = substr($data['ident'],-3);
650
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
651
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
652
+				$typec = substr($data['ident'], -3);
653 653
 				if ($typec == 'APP') $data['type'] = 'Approach';
654 654
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
655 655
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
661 661
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
662 662
 				if (!isset($data['source_name'])) $data['source_name'] = '';
663
-				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']);
663
+				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']);
664 664
 			}
665 665
     			unset($data);
666 666
     		    }
@@ -671,9 +671,9 @@  discard block
 block discarded – undo
671 671
     	    $last_exec[$id]['last'] = time();
672 672
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
673 673
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
674
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
674
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
675 675
 	    if ($buffer != '') {
676
-	    $all_data = json_decode($buffer,true);
676
+	    $all_data = json_decode($buffer, true);
677 677
 	    if (isset($all_data['acList'])) {
678 678
 		$reset = 0;
679 679
 		foreach ($all_data['acList'] as $line) {
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 		    $data['emergency'] = ''; // emergency
691 691
 		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
692 692
 		    
693
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
693
+		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
694 694
 		    else $data['datetime'] = date('Y-m-d H:i:s');
695 695
 		    
696 696
 		    //$data['datetime'] = date('Y-m-d H:i:s');
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
717 717
 		    $data['squawk'] = $line['squawk']; // squawk
718 718
 		    $data['emergency'] = ''; // emergency
719
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
719
+		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
720 720
 		    else $data['datetime'] = date('Y-m-d H:i:s');
721 721
 	    	    $data['format_source'] = 'aircraftlistjson';
722 722
     		    $data['id_source'] = $id_source;
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
733 733
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734 734
 	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
735
+	    $all_data = json_decode($buffer, true);
736 736
 	    if (isset($all_data['planes'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['planes'] as $key => $line) {
@@ -749,12 +749,12 @@  discard block
 block discarded – undo
749 749
 		    $data['emergency'] = ''; // emergency
750 750
 		    $data['registration'] = $line[2];
751 751
 		    $data['aircraft_icao'] = $line[0];
752
-		    $deparr = explode('-',$line[1]);
752
+		    $deparr = explode('-', $line[1]);
753 753
 		    if (count($deparr) == 2) {
754 754
 			$data['departure_airport_icao'] = $deparr[0];
755 755
 			$data['arrival_airport_icao'] = $deparr[1];
756 756
 		    }
757
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
757
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
758 758
 	    	    $data['format_source'] = 'planeupdatefaa';
759 759
     		    $data['id_source'] = $id_source;
760 760
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
     	    $last_exec[$id]['last'] = time();
768 768
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
769 769
 	    $buffer = $Common->getData($value['host']);
770
-	    $all_data = json_decode($buffer,true);
770
+	    $all_data = json_decode($buffer, true);
771 771
 	    if (isset($all_data['states'])) {
772 772
 		$reset = 0;
773 773
 		foreach ($all_data['states'] as $key => $line) {
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 		    //$data['emergency'] = ''; // emergency
785 785
 		    //$data['registration'] = $line[2];
786 786
 		    //$data['aircraft_icao'] = $line[0];
787
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
787
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
788 788
 	    	    $data['format_source'] = 'opensky';
789 789
     		    $data['id_source'] = $id_source;
790 790
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799 799
 	    //$buffer = $Common->getData($hosts[$id]);
800 800
 	    $buffer = $Common->getData($value['host']);
801
-	    $all_data = json_decode($buffer,true);
801
+	    $all_data = json_decode($buffer, true);
802 802
 	    if (!empty($all_data)) $reset = 0;
803 803
 	    foreach ($all_data as $key => $line) {
804 804
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -831,11 +831,11 @@  discard block
 block discarded – undo
831 831
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
832 832
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
833 833
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
834
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
834
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
835 835
 	    //echo $buffer;
836
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
837
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
838
-	    $all_data = json_decode($buffer,true);
836
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
837
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
838
+	    $all_data = json_decode($buffer, true);
839 839
 	    if (json_last_error() != JSON_ERROR_NONE) {
840 840
 		die(json_last_error_msg());
841 841
 	    }
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 			//$data['departure_airport_iata'] = $line[11];
859 859
 			//$data['arrival_airport_iata'] = $line[12];
860 860
 	    		//$data['emergency'] = ''; // emergency
861
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
861
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
862 862
 	    		$data['format_source'] = 'radarvirtueljson';
863 863
     			$data['id_source'] = $id_source;
864 864
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -874,14 +874,14 @@  discard block
 block discarded – undo
874 874
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
875 875
 	    //$buffer = $Common->getData($hosts[$id]);
876 876
 	    $buffer = $Common->getData($value['host'].'?'.time());
877
-	    $all_data = json_decode(utf8_encode($buffer),true);
877
+	    $all_data = json_decode(utf8_encode($buffer), true);
878 878
 	    
879 879
 	    if (isset($all_data['pireps'])) {
880 880
 		$reset = 0;
881 881
 	        foreach ($all_data['pireps'] as $line) {
882 882
 		    $data = array();
883 883
 		    $data['id'] = $line['id'];
884
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
884
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
885 885
 		    $data['ident'] = $line['callsign']; // ident
886 886
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887 887
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -911,9 +911,9 @@  discard block
 block discarded – undo
911 911
 			$SI->add($data);
912 912
 		    //    print_r($data);
913 913
     		    } elseif ($line['icon'] == 'ct') {
914
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
915
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
916
-			$typec = substr($data['ident'],-3);
914
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
915
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
916
+			$typec = substr($data['ident'], -3);
917 917
 			$data['type'] = '';
918 918
 			if ($typec == 'APP') $data['type'] = 'Approach';
919 919
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
925 925
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
926 926
 			else $data['type'] = 'Observer';
927
-			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']);
927
+			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']);
928 928
 		    }
929 929
 		    unset($data);
930 930
 		}
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
 	    //$buffer = $Common->getData($hosts[$id]);
937 937
 	    if ($globalDebug) echo 'Get Data...'."\n";
938 938
 	    $buffer = $Common->getData($value['host']);
939
-	    $all_data = json_decode($buffer,true);
939
+	    $all_data = json_decode($buffer, true);
940 940
 	    if ($buffer != '' && is_array($all_data)) {
941 941
 		$reset = 0;
942 942
 		foreach ($all_data as $line) {
943 943
 	    	    $data = array();
944 944
 	    	    //$data['id'] = $line['id']; // id not usable
945 945
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
946
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
946
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
947 947
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948 948
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
949 949
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -967,14 +967,14 @@  discard block
 block discarded – undo
967 967
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
968 968
 		    if (isset($line['aircraftname'])) {
969 969
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
970
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
971
-	    		$aircraft_data = explode('-',$line['aircraftname']);
970
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
971
+	    		$aircraft_data = explode('-', $line['aircraftname']);
972 972
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973 973
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974 974
 	    		else {
975
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
976
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
975
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
976
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
977
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
978 978
 	    		}
979 979
 	    	    }
980 980
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -994,14 +994,14 @@  discard block
 block discarded – undo
994 994
 	    //$buffer = $Common->getData($hosts[$id]);
995 995
 	    if ($globalDebug) echo 'Get Data...'."\n";
996 996
 	    $buffer = $Common->getData($value['host']);
997
-	    $all_data = json_decode($buffer,true);
997
+	    $all_data = json_decode($buffer, true);
998 998
 	    if ($buffer != '' && is_array($all_data)) {
999 999
 		$reset = 0;
1000 1000
 		foreach ($all_data as $line) {
1001 1001
 	    	    $data = array();
1002 1002
 	    	    //$data['id'] = $line['id']; // id not usable
1003 1003
 	    	    $data['id'] = trim($line['flight_id']);
1004
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1004
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1005 1005
 	    	    $data['pilot_name'] = $line['pilot_name'];
1006 1006
 	    	    $data['pilot_id'] = $line['pilot_id'];
1007 1007
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
 		    //$value = $formats[$nb];
1054 1054
 		    $format = $globalSources[$nb]['format'];
1055 1055
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1056
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1056
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1057 1057
 		    } elseif ($format == 'vrstcp') {
1058 1058
 			$buffer = @socket_read($r, 6000);
1059 1059
 		    } else {
1060
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1060
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1061 1061
 		    }
1062 1062
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1063 1063
 		    //echo $buffer."\n";
@@ -1066,8 +1066,8 @@  discard block
 block discarded – undo
1066 1066
 		    $error = false;
1067 1067
 		    //$SI::del();
1068 1068
 		    if ($format == 'vrstcp') {
1069
-			$buffer = explode('},{',$buffer);
1070
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1069
+			$buffer = explode('},{', $buffer);
1070
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1071 1071
 		    // SBS format is CSV format
1072 1072
 		    if ($buffer !== FALSE && $buffer != '') {
1073 1073
 			$tt[$format] = 0;
@@ -1101,13 +1101,13 @@  discard block
 block discarded – undo
1101 1101
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102 1102
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103 1103
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1104
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1105 1105
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1106 1106
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1107 1107
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1108 1108
 
1109 1109
 			    if (isset($ais_data['timestamp'])) {
1110
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1110
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1111 1111
 			    } else {
1112 1112
 				$data['datetime'] = date('Y-m-d H:i:s');
1113 1113
 			    }
@@ -1118,10 +1118,10 @@  discard block
 block discarded – undo
1118 1118
                         } elseif ($format == 'flightgearsp') {
1119 1119
                     	    //echo $buffer."\n";
1120 1120
                     	    if (strlen($buffer) > 5) {
1121
-				$line = explode(',',$buffer);
1121
+				$line = explode(',', $buffer);
1122 1122
 				$data = array();
1123 1123
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1124
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1124
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1125 1125
 				$data['ident'] = $line[6];
1126 1126
 				$data['aircraft_name'] = $line[7];
1127 1127
 				$data['longitude'] = $line[1];
@@ -1133,21 +1133,21 @@  discard block
 block discarded – undo
1133 1133
 				$data['format_source'] = 'flightgearsp';
1134 1134
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1135 1135
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1136
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1136
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1137 1137
 			    }
1138 1138
                         } elseif ($format == 'acars') {
1139 1139
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1140 1140
 			    $ACARS->add(trim($buffer));
1141
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1141
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1142 1142
 			    $ACARS->deleteLiveAcarsData();
1143 1143
 			} elseif ($format == 'flightgearmp') {
1144
-			    if (substr($buffer,0,1) != '#') {
1144
+			    if (substr($buffer, 0, 1) != '#') {
1145 1145
 				$data = array();
1146 1146
 				//echo $buffer."\n";
1147
-				$line = explode(' ',$buffer);
1147
+				$line = explode(' ', $buffer);
1148 1148
 				if (count($line) == 11) {
1149
-				    $userserver = explode('@',$line[0]);
1150
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1149
+				    $userserver = explode('@', $line[0]);
1150
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1151 1151
 				    $data['ident'] = $userserver[0];
1152 1152
 				    $data['registration'] = $userserver[0];
1153 1153
 				    $data['latitude'] = $line[4];
@@ -1155,8 +1155,8 @@  discard block
 block discarded – undo
1155 1155
 				    $data['altitude'] = $line[6];
1156 1156
 				    $data['datetime'] = date('Y-m-d H:i:s');
1157 1157
 				    $aircraft_type = $line[10];
1158
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1159
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1158
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1159
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1160 1160
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1161 1161
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1162 1162
 				}
@@ -1165,8 +1165,8 @@  discard block
 block discarded – undo
1165 1165
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1166 1166
 			    die;
1167 1167
 			} elseif ($format == 'vrstcp') {
1168
-			    foreach($buffer as $all_data) {
1169
-				$line = json_decode('{'.$all_data.'}',true);
1168
+			    foreach ($buffer as $all_data) {
1169
+				$line = json_decode('{'.$all_data.'}', true);
1170 1170
 				$data = array();
1171 1171
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1172 1172
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1192,16 +1192,16 @@  discard block
 block discarded – undo
1192 1192
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1193 1193
 				unset($data);
1194 1194
 			    }
1195
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1195
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1196 1196
 			    $line = explode("\t", $buffer);
1197
-			    for($k = 0; $k < count($line); $k=$k+2) {
1197
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1198 1198
 				$key = $line[$k];
1199
-			        $lined[$key] = $line[$k+1];
1199
+			        $lined[$key] = $line[$k + 1];
1200 1200
 			    }
1201 1201
     			    if (count($lined) > 3) {
1202 1202
     				$data['hex'] = $lined['hexid'];
1203 1203
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1204
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1204
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1205 1205
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1206 1206
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1207 1207
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1220,22 +1220,22 @@  discard block
 block discarded – undo
1220 1220
     			    } else $error = true;
1221 1221
 			} elseif ($format == 'aprs' && $use_aprs) {
1222 1222
 			    if ($aprs_connect == 0) {
1223
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1223
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1224 1224
 				$aprs_connect = 1;
1225 1225
 			    }
1226 1226
 			    
1227
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1227
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1228 1228
 				$aprs_last_tx = time();
1229 1229
 				$data_aprs = "# Keep alive";
1230
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1230
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1231 1231
 			    }
1232 1232
 			    
1233 1233
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1234 1234
 			    //echo 'APRS data : '.$buffer."\n";
1235
-			    $buffer = str_replace('APRS <- ','',$buffer);
1236
-			    $buffer = str_replace('APRS -> ','',$buffer);
1235
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1236
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1237 1237
 			    //echo $buffer."\n";
1238
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1238
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1239 1239
 				$line = $APRS->parse($buffer);
1240 1240
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1241 1241
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1251 1251
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1252 1252
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1253
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1253
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1254 1254
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1255 1255
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1256 1256
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
 				connect_all($sourceee);
1380 1380
 				$sourceee = array();
1381 1381
 				//connect_all($globalSources);
1382
-				$tt[$format]=0;
1382
+				$tt[$format] = 0;
1383 1383
 				break;
1384 1384
 			    }
1385 1385
 			}
@@ -1388,14 +1388,14 @@  discard block
 block discarded – undo
1388 1388
 	    } else {
1389 1389
 		$error = socket_strerror(socket_last_error());
1390 1390
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1391
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1391
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1392 1392
 			if (isset($globalDebug)) echo "Restarting...\n";
1393 1393
 			// Restart the script if possible
1394 1394
 			if (is_array($sockets)) {
1395 1395
 			    if ($globalDebug) echo "Shutdown all sockets...";
1396 1396
 			    
1397 1397
 			    foreach ($sockets as $sock) {
1398
-				@socket_shutdown($sock,2);
1398
+				@socket_shutdown($sock, 2);
1399 1399
 				@socket_close($sock);
1400 1400
 			    }
1401 1401
 			    
Please login to merge, or discard this patch.
Braces   +937 added lines, -322 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();
@@ -54,35 +58,62 @@  discard block
 block discarded – undo
54 58
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 59
 if (isset($options['s'])) {
56 60
     $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
59
-} elseif (isset($options['source'])) {
61
+    if (isset($options['format'])) {
62
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+    } else {
64
+    	$globalSources[] = array('host' => $options['s']);
65
+    }
66
+    } elseif (isset($options['source'])) {
60 67
     $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
63
-}
68
+    if (isset($options['format'])) {
69
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
70
+    } else {
71
+    	$globalSources[] = array('host' => $options['source']);
72
+    }
73
+    }
64 74
 if (isset($options['aprsserverhost'])) {
65 75
 	$globalServerAPRS = TRUE;
66 76
 	$globalServerAPRShost = $options['aprsserverhost'];
67 77
 }
68
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
69
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
70
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
71
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
72
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
73
-if (isset($options['server'])) $globalServer = TRUE;
74
-if (isset($options['idsource'])) $id_source = $options['idsource'];
75
-else $id_source = 1;
78
+if (isset($options['aprsserverport'])) {
79
+	$globalServerAPRSport = $options['aprsserverport'];
80
+}
81
+if (isset($options['aprsserverssid'])) {
82
+	$globalServerAPRSssid = $options['aprsserverssid'];
83
+}
84
+if (isset($options['aprsserverpass'])) {
85
+	$globalServerAPRSpass = $options['aprsserverpass'];
86
+}
87
+if (isset($options['noaprsserver'])) {
88
+	$globalServerAPRS = FALSE;
89
+}
90
+if (isset($options['nodaemon'])) {
91
+	$globalDaemon = FALSE;
92
+}
93
+if (isset($options['server'])) {
94
+	$globalServer = TRUE;
95
+}
96
+if (isset($options['idsource'])) {
97
+	$id_source = $options['idsource'];
98
+} else {
99
+	$id_source = 1;
100
+}
76 101
 if (isset($globalServer) && $globalServer) {
77
-    if ($globalDebug) echo "Using Server Mode\n";
102
+    if ($globalDebug) {
103
+    	echo "Using Server Mode\n";
104
+    }
78 105
     $SI=new SpotterServer();
79 106
 /*
80 107
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 108
     $SI = new adsb2aprs();
82 109
     $SI->connect();
83 110
 */
84
-} else $SI=new SpotterImport($Connection->db);
85
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
111
+} else {
112
+	$SI=new SpotterImport($Connection->db);
113
+}
114
+if (isset($globalTracker) && $globalTracker) {
115
+	$TI = new TrackerImport($Connection->db);
116
+}
86 117
 if (isset($globalMarine) && $globalMarine) {
87 118
     $AIS = new AIS();
88 119
     $MI = new MarineImport($Connection->db);
@@ -104,7 +135,9 @@  discard block
 block discarded – undo
104 135
 }
105 136
 
106 137
 // let's try and connect
107
-if ($globalDebug) echo "Connecting...\n";
138
+if ($globalDebug) {
139
+	echo "Connecting...\n";
140
+}
108 141
 $use_aprs = false;
109 142
 $aprs_full = false;
110 143
 $reset = 0;
@@ -113,7 +146,9 @@  discard block
 block discarded – undo
113 146
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114 147
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115 148
     $reset++;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
149
+    if ($globalDebug) {
150
+    	echo 'Connect to all...'."\n";
151
+    }
117 152
     foreach ($hosts as $id => $value) {
118 153
 	$host = $value['host'];
119 154
 	$globalSources[$id]['last_exec'] = 0;
@@ -123,27 +158,37 @@  discard block
 block discarded – undo
123 158
         	//$formats[$id] = 'deltadbtxt';
124 159
         	$globalSources[$id]['format'] = 'deltadbtxt';
125 160
         	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
161
+        	if ($globalDebug) {
162
+        		echo "Connect to deltadb source (".$host.")...\n";
163
+        	}
127 164
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128 165
         	//$formats[$id] = 'vatsimtxt';
129 166
         	$globalSources[$id]['format'] = 'vatsimtxt';
130 167
         	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
168
+        	if ($globalDebug) {
169
+        		echo "Connect to vatsim source (".$host.")...\n";
170
+        	}
132 171
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133 172
         	//$formats[$id] = 'aircraftlistjson';
134 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
135 174
         	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	if ($globalDebug) {
176
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
177
+        	}
137 178
     	    } else if (preg_match('/opensky/i',$host)) {
138 179
         	//$formats[$id] = 'aircraftlistjson';
139 180
         	$globalSources[$id]['format'] = 'opensky';
140 181
         	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to opensky source (".$host.")...\n";
184
+        	}
142 185
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143 186
         	//$formats[$id] = 'radarvirtueljson';
144 187
         	$globalSources[$id]['format'] = 'radarvirtueljson';
145 188
         	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	if ($globalDebug) {
190
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
191
+        	}
147 192
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148 193
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149 194
         	    exit(0);
@@ -152,7 +197,9 @@  discard block
 block discarded – undo
152 197
         	//$formats[$id] = 'planeupdatefaa';
153 198
         	$globalSources[$id]['format'] = 'planeupdatefaa';
154 199
         	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	if ($globalDebug) {
201
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
202
+        	}
156 203
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157 204
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158 205
         	    exit(0);
@@ -161,26 +208,36 @@  discard block
 block discarded – undo
161 208
         	//$formats[$id] = 'phpvmacars';
162 209
         	$globalSources[$id]['format'] = 'phpvmacars';
163 210
         	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to phpvmacars source (".$host.")...\n";
213
+        	}
165 214
             } else if (preg_match('/VAM-json.php$/i',$host)) {
166 215
         	//$formats[$id] = 'phpvmacars';
167 216
         	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
217
+        	if ($globalDebug) {
218
+        		echo "Connect to Vam source (".$host.")...\n";
219
+        	}
169 220
             } else if (preg_match('/whazzup/i',$host)) {
170 221
         	//$formats[$id] = 'whazzup';
171 222
         	$globalSources[$id]['format'] = 'whazzup';
172 223
         	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
224
+        	if ($globalDebug) {
225
+        		echo "Connect to whazzup source (".$host.")...\n";
226
+        	}
174 227
             } else if (preg_match('/recentpireps/i',$host)) {
175 228
         	//$formats[$id] = 'pirepsjson';
176 229
         	$globalSources[$id]['format'] = 'pirepsjson';
177 230
         	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	if ($globalDebug) {
232
+        		echo "Connect to pirepsjson source (".$host.")...\n";
233
+        	}
179 234
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180 235
         	//$formats[$id] = 'fr24json';
181 236
         	$globalSources[$id]['format'] = 'fr24json';
182 237
         	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to fr24 source (".$host.")...\n";
240
+        	}
184 241
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185 242
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186 243
         	    exit(0);
@@ -189,7 +246,9 @@  discard block
 block discarded – undo
189 246
         	//$formats[$id] = 'fr24json';
190 247
         	$globalSources[$id]['format'] = 'myshiptracking';
191 248
         	//$last_exec['fr24json'] = 0;
192
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to myshiptracking source (".$host.")...\n";
251
+        	}
193 252
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194 253
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195 254
         	    exit(0);
@@ -198,17 +257,24 @@  discard block
 block discarded – undo
198 257
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199 258
         	//$formats[$id] = 'tsv';
200 259
         	$globalSources[$id]['format'] = 'tsv';
201
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
260
+        	if ($globalDebug) {
261
+        		echo "Connect to tsv source (".$host.")...\n";
262
+        	}
202 263
             }
203 264
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204 265
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205 266
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
206 267
     		    if ($idf !== false) {
207 268
     			$httpfeeds[$id] = $idf;
208
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
269
+        		if ($globalDebug) {
270
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
271
+        		}
272
+    		    } elseif ($globalDebug) {
273
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
209 274
     		    }
210
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
+    		} elseif ($globalDebug) {
276
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
277
+    		}
212 278
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213 279
 	    $hostport = explode(':',$host);
214 280
 	    if (isset($hostport[1])) {
@@ -248,17 +314,25 @@  discard block
 block discarded – undo
248 314
         		//$formats[$id] = 'beast';
249 315
         		$globalSources[$id]['format'] = 'beast';
250 316
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
317
+		    } else {
318
+		    	$globalSources[$id]['format'] = 'sbs';
319
+		    }
252 320
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 321
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
322
+		if ($globalDebug) {
323
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
324
+		}
255 325
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
326
+		if ($globalDebug) {
327
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
328
+		}
257 329
     	    }
258 330
         }
259 331
     }
260 332
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
333
+if (!isset($globalMinFetch)) {
334
+	$globalMinFetch = 15;
335
+}
262 336
 
263 337
 // Initialize all
264 338
 $status = array();
@@ -267,13 +341,19 @@  discard block
 block discarded – undo
267 341
 $formats = array();
268 342
 $last_exec = array();
269 343
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
344
+if (isset($globalSourcesTimeout)) {
345
+	$timeout = $globalSourcesTimeOut;
346
+} else if (isset($globalSBS1TimeOut)) {
347
+	$timeout = $globalSBS1TimeOut;
348
+} else {
349
+	$timeout = 20;
350
+}
273 351
 $errno = '';
274 352
 $errstr='';
275 353
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
354
+if (!isset($globalDaemon)) {
355
+	$globalDaemon = TRUE;
356
+}
277 357
 /* Initiate connections to all the hosts simultaneously */
278 358
 //connect_all($hosts);
279 359
 //connect_all($globalSources);
@@ -299,7 +379,9 @@  discard block
 block discarded – undo
299 379
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 380
 	$aprs_connect = 0;
301 381
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
382
+	if (isset($source['port']) && $source['port'] == '10152') {
383
+		$aprs_full = true;
384
+	}
303 385
 	break;
304 386
     }
305 387
 }
@@ -310,25 +392,48 @@  discard block
 block discarded – undo
310 392
 	$aprs_connect = 0;
311 393
 	$aprs_keep = 120;
312 394
 	$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 = '';
320
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
321
-	else $aprs_pass = '-1';
395
+	if (isset($globalAPRSversion)) {
396
+		$aprs_version = $globalAPRSversion;
397
+	} else {
398
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
399
+	}
400
+	if (isset($globalAPRSssid)) {
401
+		$aprs_ssid = $globalAPRSssid;
402
+	} else {
403
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
404
+	}
405
+	if (isset($globalAPRSfilter)) {
406
+		$aprs_filter = $globalAPRSfilter;
407
+	} else {
408
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
409
+	}
410
+	if ($aprs_full) {
411
+		$aprs_filter = '';
412
+	}
413
+	if (isset($globalAPRSpass)) {
414
+		$aprs_pass = $globalAPRSpass;
415
+	} else {
416
+		$aprs_pass = '-1';
417
+	}
322 418
 
323
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
324
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
325
-}
419
+	if ($aprs_filter != '') {
420
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
421
+	} else {
422
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
423
+	}
424
+	}
326 425
 
327 426
 // connected - lets do some work
328
-if ($globalDebug) echo "Connected!\n";
427
+if ($globalDebug) {
428
+	echo "Connected!\n";
429
+}
329 430
 sleep(1);
330
-if ($globalDebug) echo "SCAN MODE \n\n";
331
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
431
+if ($globalDebug) {
432
+	echo "SCAN MODE \n\n";
433
+}
434
+if (!isset($globalCronEnd)) {
435
+	$globalCronEnd = 60;
436
+}
332 437
 $endtime = time()+$globalCronEnd;
333 438
 $i = 1;
334 439
 $tt = array();
@@ -342,10 +447,14 @@  discard block
 block discarded – undo
342 447
 
343 448
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 449
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
450
+    if (!$globalDaemon) {
451
+    	$i = $endtime-time();
452
+    }
346 453
     // Delete old ATC
347 454
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
455
+	if ($globalDebug) {
456
+		echo 'Delete old ATC...'."\n";
457
+	}
349 458
         $ATC->deleteOldATC();
350 459
     }
351 460
     
@@ -353,10 +462,14 @@  discard block
 block discarded – undo
353 462
     if (count($last_exec) == count($globalSources)) {
354 463
 	$max = $globalMinFetch;
355 464
 	foreach ($last_exec as $last) {
356
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
465
+	    if ((time() - $last['last']) < $max) {
466
+	    	$max = time() - $last['last'];
467
+	    }
357 468
 	}
358 469
 	if ($max != $globalMinFetch) {
359
-	    if ($globalDebug) echo 'Sleeping...'."\n";
470
+	    if ($globalDebug) {
471
+	    	echo 'Sleeping...'."\n";
472
+	    }
360 473
 	    sleep($globalMinFetch-$max+2);
361 474
 	}
362 475
     }
@@ -365,11 +478,15 @@  discard block
 block discarded – undo
365 478
     //foreach ($formats as $id => $value) {
366 479
     foreach ($globalSources as $id => $value) {
367 480
 	date_default_timezone_set('UTC');
368
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
481
+	if (!isset($last_exec[$id]['last'])) {
482
+		$last_exec[$id]['last'] = 0;
483
+	}
369 484
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
370 485
 	    //$buffer = $Common->getData($hosts[$id]);
371 486
 	    $buffer = $Common->getData($value['host']);
372
-	    if ($buffer != '') $reset = 0;
487
+	    if ($buffer != '') {
488
+	    	$reset = 0;
489
+	    }
373 490
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374 491
 	    $buffer = explode('\n',$buffer);
375 492
 	    foreach ($buffer as $line) {
@@ -378,20 +495,41 @@  discard block
 block discarded – undo
378 495
 	            $data = array();
379 496
 	            $data['hex'] = $line[1]; // hex
380 497
 	            $data['ident'] = $line[2]; // ident
381
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
498
+	            if (isset($line[3])) {
499
+	            	$data['altitude'] = $line[3];
500
+	            }
501
+	            // altitude
502
+	            if (isset($line[4])) {
503
+	            	$data['speed'] = $line[4];
504
+	            }
505
+	            // speed
506
+	            if (isset($line[5])) {
507
+	            	$data['heading'] = $line[5];
508
+	            }
509
+	            // heading
510
+	            if (isset($line[6])) {
511
+	            	$data['latitude'] = $line[6];
512
+	            }
513
+	            // lat
514
+	            if (isset($line[7])) {
515
+	            	$data['longitude'] = $line[7];
516
+	            }
517
+	            // long
386 518
 	            $data['verticalrate'] = ''; // vertical rate
387 519
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388 520
 	            $data['emergency'] = ''; // emergency
389 521
 		    $data['datetime'] = date('Y-m-d H:i:s');
390 522
 		    $data['format_source'] = 'deltadbtxt';
391 523
     		    $data['id_source'] = $id_source;
392
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
524
+		    if (isset($value['name']) && $value['name'] != '') {
525
+		    	$data['source_name'] = $value['name'];
526
+		    }
527
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
528
+		    	$data['noarchive'] = true;
529
+		    }
530
+		    if (isset($value['sourcestats'])) {
531
+		    	$data['sourcestats'] = $value['sourcestats'];
532
+		    }
395 533
     		    $SI->add($data);
396 534
 		    unset($data);
397 535
     		}
@@ -401,7 +539,9 @@  discard block
 block discarded – undo
401 539
 	    date_default_timezone_set('CET');
402 540
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403 541
 	    date_default_timezone_set('UTC');
404
-	    if ($buffer != '') $reset = 0;
542
+	    if ($buffer != '') {
543
+	    	$reset = 0;
544
+	    }
405 545
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406 546
 	    $buffer = explode('\n',$buffer);
407 547
 	    foreach ($buffer as $line) {
@@ -410,16 +550,36 @@  discard block
 block discarded – undo
410 550
 		    $add = false;
411 551
 		    $ais_data = $AIS->parse_line(trim($line));
412 552
 		    $data = array();
413
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553
+		    if (isset($ais_data['ident'])) {
554
+		    	$data['ident'] = $ais_data['ident'];
555
+		    }
556
+		    if (isset($ais_data['mmsi'])) {
557
+		    	$data['mmsi'] = $ais_data['mmsi'];
558
+		    }
559
+		    if (isset($ais_data['speed'])) {
560
+		    	$data['speed'] = $ais_data['speed'];
561
+		    }
562
+		    if (isset($ais_data['heading'])) {
563
+		    	$data['heading'] = $ais_data['heading'];
564
+		    }
565
+		    if (isset($ais_data['latitude'])) {
566
+		    	$data['latitude'] = $ais_data['latitude'];
567
+		    }
568
+		    if (isset($ais_data['longitude'])) {
569
+		    	$data['longitude'] = $ais_data['longitude'];
570
+		    }
571
+		    if (isset($ais_data['status'])) {
572
+		    	$data['status'] = $ais_data['status'];
573
+		    }
574
+		    if (isset($ais_data['type'])) {
575
+		    	$data['type'] = $ais_data['type'];
576
+		    }
577
+		    if (isset($ais_data['imo'])) {
578
+		    	$data['imo'] = $ais_data['imo'];
579
+		    }
580
+		    if (isset($ais_data['callsign'])) {
581
+		    	$data['callsign'] = $ais_data['callsign'];
582
+		    }
423 583
 		    if (isset($ais_data['timestamp'])) {
424 584
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
425 585
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -433,8 +593,12 @@  discard block
 block discarded – undo
433 593
 		    $data['format_source'] = 'aisnmeatxt';
434 594
     		    $data['id_source'] = $id_source;
435 595
 		    //print_r($data);
436
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
437
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
596
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
597
+		    	$data['noarchive'] = true;
598
+		    }
599
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
600
+		    	$MI->add($data);
601
+		    }
438 602
 		    unset($data);
439 603
 		}
440 604
     	    }
@@ -454,20 +618,48 @@  discard block
 block discarded – undo
454 618
 			    if ($line != '') {
455 619
 				$ais_data = $AIS->parse_line(trim($line));
456 620
 				$data = array();
457
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
458
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
459
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
460
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
461
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
462
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
463
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
464
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
465
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
466
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
467
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
468
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
469
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
470
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
621
+				if (isset($ais_data['ident'])) {
622
+					$data['ident'] = $ais_data['ident'];
623
+				}
624
+				if (isset($ais_data['mmsi'])) {
625
+					$data['mmsi'] = $ais_data['mmsi'];
626
+				}
627
+				if (isset($ais_data['speed'])) {
628
+					$data['speed'] = $ais_data['speed'];
629
+				}
630
+				if (isset($ais_data['heading'])) {
631
+					$data['heading'] = $ais_data['heading'];
632
+				}
633
+				if (isset($ais_data['latitude'])) {
634
+					$data['latitude'] = $ais_data['latitude'];
635
+				}
636
+				if (isset($ais_data['longitude'])) {
637
+					$data['longitude'] = $ais_data['longitude'];
638
+				}
639
+				if (isset($ais_data['status'])) {
640
+					$data['status'] = $ais_data['status'];
641
+				}
642
+				if (isset($ais_data['statusid'])) {
643
+					$data['status_id'] = $ais_data['statusid'];
644
+				}
645
+				if (isset($ais_data['type'])) {
646
+					$data['type'] = $ais_data['type'];
647
+				}
648
+				if (isset($ais_data['typeid'])) {
649
+					$data['type_id'] = $ais_data['typeid'];
650
+				}
651
+				if (isset($ais_data['imo'])) {
652
+					$data['imo'] = $ais_data['imo'];
653
+				}
654
+				if (isset($ais_data['callsign'])) {
655
+					$data['callsign'] = $ais_data['callsign'];
656
+				}
657
+				if (isset($ais_data['destination'])) {
658
+					$data['arrival_code'] = $ais_data['destination'];
659
+				}
660
+				if (isset($ais_data['eta_ts'])) {
661
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
662
+				}
471 663
 				if (isset($ais_data['timestamp'])) {
472 664
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
473 665
 				} else {
@@ -475,18 +667,27 @@  discard block
 block discarded – undo
475 667
 				}
476 668
 				$data['format_source'] = 'aisnmeahttp';
477 669
 				$data['id_source'] = $id_source;
478
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
479
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
670
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
671
+					$data['noarchive'] = true;
672
+				}
673
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
674
+					$MI->add($data);
675
+				}
480 676
 				unset($data);
481 677
 			    }
482 678
 			}
483 679
 		    }
484 680
 		} else {
485 681
 		    $format = $value['format'];
486
-		    if (isset($tt[$format])) $tt[$format]++;
487
-		    else $tt[$format] = 0;
682
+		    if (isset($tt[$format])) {
683
+		    	$tt[$format]++;
684
+		    } else {
685
+		    	$tt[$format] = 0;
686
+		    }
488 687
 		    if ($tt[$format] > 30) {
489
-			if ($globalDebug) echo 'Reconnect...'."\n";
688
+			if ($globalDebug) {
689
+				echo 'Reconnect...'."\n";
690
+			}
490 691
 			sleep(2);
491 692
 			$sourceeen[] = $value;
492 693
 			connect_all($sourceeen);
@@ -516,7 +717,9 @@  discard block
 block discarded – undo
516 717
 			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
517 718
 			$data['format_source'] = 'myshiptracking';
518 719
 			$data['id_source'] = $id_source;
519
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
720
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
721
+				$data['noarchive'] = true;
722
+			}
520 723
 			$MI->add($data);
521 724
 			unset($data);
522 725
 		    }
@@ -537,7 +740,9 @@  discard block
 block discarded – undo
537 740
 			    $data['callsign'] = $line['callsign'];
538 741
 			    $data['mmsi'] = $line['mmsi'];
539 742
 			    $data['speed'] = $line['sog'];
540
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
743
+			    if ($line['heading'] != '511') {
744
+			    	$data['heading'] = $line['heading'];
745
+			    }
541 746
 			    $data['latitude'] = $line['latitude'];
542 747
 			    $data['longitude'] = $line['longitude'];
543 748
 			    $data['type_id'] = $line['shiptype'];
@@ -545,7 +750,9 @@  discard block
 block discarded – undo
545 750
 			    $data['datetime'] = $line['time'];
546 751
 			    $data['format_source'] = 'boatbeaconapp';
547 752
 			    $data['id_source'] = $id_source;
548
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
753
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
754
+			    	$data['noarchive'] = true;
755
+			    }
549 756
 			    $MI->add($data);
550 757
 			    unset($data);
551 758
 			}
@@ -558,7 +765,9 @@  discard block
 block discarded – undo
558 765
 	    echo 'download...';
559 766
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
560 767
 	    echo 'done !'."\n";
561
-	    if ($buffer != '') $reset = 0;
768
+	    if ($buffer != '') {
769
+	    	$reset = 0;
770
+	    }
562 771
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
563 772
 	    $buffer = explode('\n',$buffer);
564 773
 	    foreach ($buffer as $line) {
@@ -583,7 +792,9 @@  discard block
 block discarded – undo
583 792
 		    //$data['etaTime'] = substr($line,135,5);
584 793
 		    $data['format_source'] = 'shipplotter';
585 794
     		    $data['id_source'] = $id_source;
586
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
795
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
796
+		    	$data['noarchive'] = true;
797
+		    }
587 798
 		    //print_r($data);
588 799
 		    echo 'Add...'."\n";
589 800
 		    $MI->add($data);
@@ -603,16 +814,28 @@  discard block
 block discarded – undo
603 814
     		    $line = explode(':', $line);
604 815
     		    if (count($line) > 30 && $line[0] != 'callsign') {
605 816
 			$data = array();
606
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
607
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
817
+			if (isset($line[37]) && $line[37] != '') {
818
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
819
+			} else {
820
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
821
+			}
608 822
 			$data['pilot_id'] = $line[1];
609 823
 			$data['pilot_name'] = $line[2];
610 824
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
611 825
 			$data['ident'] = $line[0]; // ident
612
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
826
+			if ($line[7] != '' && $line[7] != 0) {
827
+				$data['altitude'] = $line[7];
828
+			}
829
+			// altitude
613 830
 			$data['speed'] = $line[8]; // speed
614
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
615
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
831
+			if (isset($line[45])) {
832
+				$data['heading'] = $line[45];
833
+			}
834
+			// heading
835
+			elseif (isset($line[38])) {
836
+				$data['heading'] = $line[38];
837
+			}
838
+			// heading
616 839
 			$data['latitude'] = $line[5]; // lat
617 840
 	        	$data['longitude'] = $line[6]; // long
618 841
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -628,7 +851,9 @@  discard block
 block discarded – undo
628 851
 			$data['frequency'] = $line[4];
629 852
 			$data['type'] = $line[18];
630 853
 			$data['range'] = $line[19];
631
-			if (isset($line[35])) $data['info'] = $line[35];
854
+			if (isset($line[35])) {
855
+				$data['info'] = $line[35];
856
+			}
632 857
     			$data['id_source'] = $id_source;
633 858
 	    		//$data['arrival_airport_time'] = ;
634 859
 	    		if ($line[9] != '') {
@@ -642,25 +867,44 @@  discard block
 block discarded – undo
642 867
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
643 868
 	    		*/
644 869
 	    		$data['format_source'] = $value['format'];
645
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
646
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
647
-    			if ($line[3] == 'PILOT') $SI->add($data);
648
-			elseif ($line[3] == 'ATC') {
870
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
871
+				$data['noarchive'] = true;
872
+			}
873
+			if (isset($value['name']) && $value['name'] != '') {
874
+				$data['source_name'] = $value['name'];
875
+			}
876
+    			if ($line[3] == 'PILOT') {
877
+    				$SI->add($data);
878
+    			} elseif ($line[3] == 'ATC') {
649 879
 				//print_r($data);
650 880
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
651 881
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
652 882
 				$typec = substr($data['ident'],-3);
653
-				if ($typec == 'APP') $data['type'] = 'Approach';
654
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
655
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
656
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
657
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
658
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
659
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
660
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
661
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
662
-				if (!isset($data['source_name'])) $data['source_name'] = '';
663
-				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']);
883
+				if ($typec == 'APP') {
884
+					$data['type'] = 'Approach';
885
+				} elseif ($typec == 'TWR') {
886
+					$data['type'] = 'Tower';
887
+				} elseif ($typec == 'OBS') {
888
+					$data['type'] = 'Observer';
889
+				} elseif ($typec == 'GND') {
890
+					$data['type'] = 'Ground';
891
+				} elseif ($typec == 'DEL') {
892
+					$data['type'] = 'Delivery';
893
+				} elseif ($typec == 'DEP') {
894
+					$data['type'] = 'Departure';
895
+				} elseif ($typec == 'FSS') {
896
+					$data['type'] = 'Flight Service Station';
897
+				} elseif ($typec == 'CTR') {
898
+					$data['type'] = 'Control Radar or Centre';
899
+				} elseif ($data['type'] == '') {
900
+					$data['type'] = 'Observer';
901
+				}
902
+				if (!isset($data['source_name'])) {
903
+					$data['source_name'] = '';
904
+				}
905
+				if (isset($ATC)) {
906
+					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']);
907
+				}
664 908
 			}
665 909
     			unset($data);
666 910
     		    }
@@ -679,27 +923,61 @@  discard block
 block discarded – undo
679 923
 		foreach ($all_data['acList'] as $line) {
680 924
 		    $data = array();
681 925
 		    $data['hex'] = $line['Icao']; // hex
682
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
683
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
684
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
685
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
686
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
687
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
926
+		    if (isset($line['Call'])) {
927
+		    	$data['ident'] = $line['Call'];
928
+		    }
929
+		    // ident
930
+		    if (isset($line['Alt'])) {
931
+		    	$data['altitude'] = $line['Alt'];
932
+		    }
933
+		    // altitude
934
+		    if (isset($line['Spd'])) {
935
+		    	$data['speed'] = $line['Spd'];
936
+		    }
937
+		    // speed
938
+		    if (isset($line['Trak'])) {
939
+		    	$data['heading'] = $line['Trak'];
940
+		    }
941
+		    // heading
942
+		    if (isset($line['Lat'])) {
943
+		    	$data['latitude'] = $line['Lat'];
944
+		    }
945
+		    // lat
946
+		    if (isset($line['Long'])) {
947
+		    	$data['longitude'] = $line['Long'];
948
+		    }
949
+		    // long
688 950
 		    //$data['verticalrate'] = $line['']; // verticale rate
689
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
951
+		    if (isset($line['Sqk'])) {
952
+		    	$data['squawk'] = $line['Sqk'];
953
+		    }
954
+		    // squawk
690 955
 		    $data['emergency'] = ''; // emergency
691
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
956
+		    if (isset($line['Reg'])) {
957
+		    	$data['registration'] = $line['Reg'];
958
+		    }
692 959
 		    
693
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
694
-		    else $data['datetime'] = date('Y-m-d H:i:s');
960
+		    if (isset($line['PosTime'])) {
961
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
962
+		    } else {
963
+		    	$data['datetime'] = date('Y-m-d H:i:s');
964
+		    }
695 965
 		    
696 966
 		    //$data['datetime'] = date('Y-m-d H:i:s');
697
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
967
+		    if (isset($line['Type'])) {
968
+		    	$data['aircraft_icao'] = $line['Type'];
969
+		    }
698 970
 	    	    $data['format_source'] = 'aircraftlistjson';
699 971
 		    $data['id_source'] = $id_source;
700
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
701
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-		    if (isset($data['latitude'])) $SI->add($data);
972
+		    if (isset($value['name']) && $value['name'] != '') {
973
+		    	$data['source_name'] = $value['name'];
974
+		    }
975
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
976
+		    	$data['noarchive'] = true;
977
+		    }
978
+		    if (isset($data['latitude'])) {
979
+		    	$SI->add($data);
980
+		    }
703 981
 		    unset($data);
704 982
 		}
705 983
 	    } elseif (is_array($all_data)) {
@@ -716,12 +994,19 @@  discard block
 block discarded – undo
716 994
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
717 995
 		    $data['squawk'] = $line['squawk']; // squawk
718 996
 		    $data['emergency'] = ''; // emergency
719
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
720
-		    else $data['datetime'] = date('Y-m-d H:i:s');
997
+		    if (isset($line['PosTime'])) {
998
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
999
+		    } else {
1000
+		    	$data['datetime'] = date('Y-m-d H:i:s');
1001
+		    }
721 1002
 	    	    $data['format_source'] = 'aircraftlistjson';
722 1003
     		    $data['id_source'] = $id_source;
723
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
724
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1004
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1005
+		    	$data['noarchive'] = true;
1006
+		    }
1007
+		    if (isset($value['name']) && $value['name'] != '') {
1008
+		    	$data['source_name'] = $value['name'];
1009
+		    }
725 1010
 		    $SI->add($data);
726 1011
 		    unset($data);
727 1012
 		}
@@ -757,8 +1042,12 @@  discard block
 block discarded – undo
757 1042
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
758 1043
 	    	    $data['format_source'] = 'planeupdatefaa';
759 1044
     		    $data['id_source'] = $id_source;
760
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
761
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1045
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1046
+		    	$data['noarchive'] = true;
1047
+		    }
1048
+		    if (isset($value['name']) && $value['name'] != '') {
1049
+		    	$data['source_name'] = $value['name'];
1050
+		    }
762 1051
 		    $SI->add($data);
763 1052
 		    unset($data);
764 1053
 		}
@@ -787,7 +1076,9 @@  discard block
 block discarded – undo
787 1076
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
788 1077
 	    	    $data['format_source'] = 'opensky';
789 1078
     		    $data['id_source'] = $id_source;
790
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1079
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1080
+		    	$data['noarchive'] = true;
1081
+		    }
791 1082
 		    $SI->add($data);
792 1083
 		    unset($data);
793 1084
 		}
@@ -799,7 +1090,9 @@  discard block
 block discarded – undo
799 1090
 	    //$buffer = $Common->getData($hosts[$id]);
800 1091
 	    $buffer = $Common->getData($value['host']);
801 1092
 	    $all_data = json_decode($buffer,true);
802
-	    if (!empty($all_data)) $reset = 0;
1093
+	    if (!empty($all_data)) {
1094
+	    	$reset = 0;
1095
+	    }
803 1096
 	    foreach ($all_data as $key => $line) {
804 1097
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
805 1098
 		    $data = array();
@@ -820,8 +1113,12 @@  discard block
 block discarded – undo
820 1113
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
821 1114
 	    	    $data['format_source'] = 'fr24json';
822 1115
     		    $data['id_source'] = $id_source;
823
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
824
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1116
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1117
+		    	$data['noarchive'] = true;
1118
+		    }
1119
+		    if (isset($value['name']) && $value['name'] != '') {
1120
+		    	$data['source_name'] = $value['name'];
1121
+		    }
825 1122
 		    $SI->add($data);
826 1123
 		    unset($data);
827 1124
 		}
@@ -845,24 +1142,42 @@  discard block
 block discarded – undo
845 1142
 		    if (isset($line['inf'])) {
846 1143
 			$data = array();
847 1144
 			$data['hex'] = $line['inf']['ia'];
848
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1145
+			if (isset($line['inf']['cs'])) {
1146
+				$data['ident'] = $line['inf']['cs'];
1147
+			}
1148
+			//$line[13]
849 1149
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
850
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
851
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1150
+	    		if (isset($line['inf']['gs'])) {
1151
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1152
+	    		}
1153
+	    		// speed
1154
+	    		if (isset($line['inf']['tr'])) {
1155
+	    			$data['heading'] = $line['inf']['tr'];
1156
+	    		}
1157
+	    		// heading
852 1158
 	    		$data['latitude'] = $line['pt'][0]; // lat
853 1159
 	    		$data['longitude'] = $line['pt'][1]; // long
854 1160
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
855
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1161
+	    		if (isset($line['inf']['sq'])) {
1162
+	    			$data['squawk'] = $line['inf']['sq'];
1163
+	    		}
1164
+	    		// squawk
856 1165
 	    		//$data['aircraft_icao'] = $line[8];
857
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1166
+	    		if (isset($line['inf']['rc'])) {
1167
+	    			$data['registration'] = $line['inf']['rc'];
1168
+	    		}
858 1169
 			//$data['departure_airport_iata'] = $line[11];
859 1170
 			//$data['arrival_airport_iata'] = $line[12];
860 1171
 	    		//$data['emergency'] = ''; // emergency
861 1172
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
862 1173
 	    		$data['format_source'] = 'radarvirtueljson';
863 1174
     			$data['id_source'] = $id_source;
864
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
865
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1175
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1176
+				$data['noarchive'] = true;
1177
+			}
1178
+			if (isset($value['name']) && $value['name'] != '') {
1179
+				$data['source_name'] = $value['name'];
1180
+			}
866 1181
 			$SI->add($data);
867 1182
 			unset($data);
868 1183
 		    }
@@ -883,30 +1198,65 @@  discard block
 block discarded – undo
883 1198
 		    $data['id'] = $line['id'];
884 1199
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
885 1200
 		    $data['ident'] = $line['callsign']; // ident
886
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
887
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
888
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
889
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
890
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
891
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1201
+		    if (isset($line['pilotid'])) {
1202
+		    	$data['pilot_id'] = $line['pilotid'];
1203
+		    }
1204
+		    // pilot id
1205
+		    if (isset($line['name'])) {
1206
+		    	$data['pilot_name'] = $line['name'];
1207
+		    }
1208
+		    // pilot name
1209
+		    if (isset($line['alt'])) {
1210
+		    	$data['altitude'] = $line['alt'];
1211
+		    }
1212
+		    // altitude
1213
+		    if (isset($line['gs'])) {
1214
+		    	$data['speed'] = $line['gs'];
1215
+		    }
1216
+		    // speed
1217
+		    if (isset($line['heading'])) {
1218
+		    	$data['heading'] = $line['heading'];
1219
+		    }
1220
+		    // heading
1221
+		    if (isset($line['route'])) {
1222
+		    	$data['waypoints'] = $line['route'];
1223
+		    }
1224
+		    // route
892 1225
 		    $data['latitude'] = $line['lat']; // lat
893 1226
 		    $data['longitude'] = $line['lon']; // long
894 1227
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
895 1228
 		    //$data['squawk'] = $line['squawk']; // squawk
896 1229
 		    //$data['emergency'] = ''; // emergency
897
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
898
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
899
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1230
+		    if (isset($line['depicao'])) {
1231
+		    	$data['departure_airport_icao'] = $line['depicao'];
1232
+		    }
1233
+		    if (isset($line['deptime'])) {
1234
+		    	$data['departure_airport_time'] = $line['deptime'];
1235
+		    }
1236
+		    if (isset($line['arricao'])) {
1237
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1238
+		    }
900 1239
 		    //$data['arrival_airport_time'] = $line['arrtime'];
901
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
902
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
903
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
904
-		    else $data['info'] = '';
1240
+		    if (isset($line['aircraft'])) {
1241
+		    	$data['aircraft_icao'] = $line['aircraft'];
1242
+		    }
1243
+		    if (isset($line['transponder'])) {
1244
+		    	$data['squawk'] = $line['transponder'];
1245
+		    }
1246
+		    if (isset($line['atis'])) {
1247
+		    	$data['info'] = $line['atis'];
1248
+		    } else {
1249
+		    	$data['info'] = '';
1250
+		    }
905 1251
 		    $data['format_source'] = 'pireps';
906 1252
     		    $data['id_source'] = $id_source;
907 1253
 		    $data['datetime'] = date('Y-m-d H:i:s');
908
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
909
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1254
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1255
+		    	$data['noarchive'] = true;
1256
+		    }
1257
+		    if (isset($value['name']) && $value['name'] != '') {
1258
+		    	$data['source_name'] = $value['name'];
1259
+		    }
910 1260
 		    if ($line['icon'] == 'plane') {
911 1261
 			$SI->add($data);
912 1262
 		    //    print_r($data);
@@ -915,16 +1265,28 @@  discard block
 block discarded – undo
915 1265
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
916 1266
 			$typec = substr($data['ident'],-3);
917 1267
 			$data['type'] = '';
918
-			if ($typec == 'APP') $data['type'] = 'Approach';
919
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
920
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
921
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
922
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
923
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
924
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
925
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
926
-			else $data['type'] = 'Observer';
927
-			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']);
1268
+			if ($typec == 'APP') {
1269
+				$data['type'] = 'Approach';
1270
+			} elseif ($typec == 'TWR') {
1271
+				$data['type'] = 'Tower';
1272
+			} elseif ($typec == 'OBS') {
1273
+				$data['type'] = 'Observer';
1274
+			} elseif ($typec == 'GND') {
1275
+				$data['type'] = 'Ground';
1276
+			} elseif ($typec == 'DEL') {
1277
+				$data['type'] = 'Delivery';
1278
+			} elseif ($typec == 'DEP') {
1279
+				$data['type'] = 'Departure';
1280
+			} elseif ($typec == 'FSS') {
1281
+				$data['type'] = 'Flight Service Station';
1282
+			} elseif ($typec == 'CTR') {
1283
+				$data['type'] = 'Control Radar or Centre';
1284
+			} else {
1285
+				$data['type'] = 'Observer';
1286
+			}
1287
+			if (isset($ATC)) {
1288
+				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']);
1289
+			}
928 1290
 		    }
929 1291
 		    unset($data);
930 1292
 		}
@@ -934,7 +1296,9 @@  discard block
 block discarded – undo
934 1296
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
935 1297
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
936 1298
 	    //$buffer = $Common->getData($hosts[$id]);
937
-	    if ($globalDebug) echo 'Get Data...'."\n";
1299
+	    if ($globalDebug) {
1300
+	    	echo 'Get Data...'."\n";
1301
+	    }
938 1302
 	    $buffer = $Common->getData($value['host']);
939 1303
 	    $all_data = json_decode($buffer,true);
940 1304
 	    if ($buffer != '' && is_array($all_data)) {
@@ -942,10 +1306,16 @@  discard block
 block discarded – undo
942 1306
 		foreach ($all_data as $line) {
943 1307
 	    	    $data = array();
944 1308
 	    	    //$data['id'] = $line['id']; // id not usable
945
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1309
+	    	    if (isset($line['pilotid'])) {
1310
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1311
+	    	    }
946 1312
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
947
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
948
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1313
+	    	    if (isset($line['pilotname'])) {
1314
+	    	    	$data['pilot_name'] = $line['pilotname'];
1315
+	    	    }
1316
+	    	    if (isset($line['pilotid'])) {
1317
+	    	    	$data['pilot_id'] = $line['pilotid'];
1318
+	    	    }
949 1319
 	    	    $data['ident'] = $line['flightnum']; // ident
950 1320
 	    	    $data['altitude'] = $line['alt']; // altitude
951 1321
 	    	    $data['speed'] = $line['gs']; // speed
@@ -963,28 +1333,44 @@  discard block
 block discarded – undo
963 1333
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
964 1334
     		    $data['arrival_airport_time'] = $line['arrtime'];
965 1335
     		    $data['registration'] = $line['aircraft'];
966
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
967
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1336
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1337
+		    	$data['noarchive'] = true;
1338
+		    }
1339
+		    if (isset($line['route'])) {
1340
+		    	$data['waypoints'] = $line['route'];
1341
+		    }
1342
+		    // route
968 1343
 		    if (isset($line['aircraftname'])) {
969 1344
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
970 1345
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
971 1346
 	    		$aircraft_data = explode('-',$line['aircraftname']);
972
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
973
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
974
-	    		else {
1347
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1348
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1349
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1350
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1351
+	    		} else {
975 1352
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
976
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
977
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1353
+	    		    if (isset($aircraft_data[1])) {
1354
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1355
+	    		    } else {
1356
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1357
+	    		    }
978 1358
 	    		}
979 1359
 	    	    }
980
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1360
+    		    if (isset($line['route'])) {
1361
+    		    	$data['waypoints'] = $line['route'];
1362
+    		    }
981 1363
     		    $data['id_source'] = $id_source;
982 1364
 	    	    $data['format_source'] = 'phpvmacars';
983
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1365
+		    if (isset($value['name']) && $value['name'] != '') {
1366
+		    	$data['source_name'] = $value['name'];
1367
+		    }
984 1368
 		    $SI->add($data);
985 1369
 		    unset($data);
986 1370
 		}
987
-		if ($globalDebug) echo 'No more data...'."\n";
1371
+		if ($globalDebug) {
1372
+			echo 'No more data...'."\n";
1373
+		}
988 1374
 		unset($buffer);
989 1375
 		unset($all_data);
990 1376
 	    }
@@ -992,7 +1378,9 @@  discard block
 block discarded – undo
992 1378
     	    $last_exec[$id]['last'] = time();
993 1379
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
994 1380
 	    //$buffer = $Common->getData($hosts[$id]);
995
-	    if ($globalDebug) echo 'Get Data...'."\n";
1381
+	    if ($globalDebug) {
1382
+	    	echo 'Get Data...'."\n";
1383
+	    }
996 1384
 	    $buffer = $Common->getData($value['host']);
997 1385
 	    $all_data = json_decode($buffer,true);
998 1386
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1021,16 +1409,25 @@  discard block
 block discarded – undo
1021 1409
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1022 1410
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1023 1411
     		    //$data['registration'] = $line['aircraft'];
1024
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1412
+		    if (isset($line['route'])) {
1413
+		    	$data['waypoints'] = $line['route'];
1414
+		    }
1415
+		    // route
1025 1416
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1026 1417
     		    $data['id_source'] = $id_source;
1027 1418
 	    	    $data['format_source'] = 'vam';
1028
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1419
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1420
+		    	$data['noarchive'] = true;
1421
+		    }
1422
+		    if (isset($value['name']) && $value['name'] != '') {
1423
+		    	$data['source_name'] = $value['name'];
1424
+		    }
1030 1425
 		    $SI->add($data);
1031 1426
 		    unset($data);
1032 1427
 		}
1033
-		if ($globalDebug) echo 'No more data...'."\n";
1428
+		if ($globalDebug) {
1429
+			echo 'No more data...'."\n";
1430
+		}
1034 1431
 		unset($buffer);
1035 1432
 		unset($all_data);
1036 1433
 	    }
@@ -1038,7 +1435,9 @@  discard block
 block discarded – undo
1038 1435
     	    $last_exec[$id]['last'] = time();
1039 1436
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1040 1437
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1041
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1438
+	    if (function_exists('pcntl_fork')) {
1439
+	    	pcntl_signal_dispatch();
1440
+	    }
1042 1441
     	    //$last_exec[$id]['last'] = time();
1043 1442
 
1044 1443
 	    //$read = array( $sockets[$id] );
@@ -1046,7 +1445,9 @@  discard block
 block discarded – undo
1046 1445
 	    $write = NULL;
1047 1446
 	    $e = NULL;
1048 1447
 	    $n = socket_select($read, $write, $e, $timeout);
1049
-	    if ($e != NULL) var_dump($e);
1448
+	    if ($e != NULL) {
1449
+	    	var_dump($e);
1450
+	    }
1050 1451
 	    if ($n > 0) {
1051 1452
 		$reset = 0;
1052 1453
 		foreach ($read as $nb => $r) {
@@ -1067,12 +1468,16 @@  discard block
 block discarded – undo
1067 1468
 		    //$SI::del();
1068 1469
 		    if ($format == 'vrstcp') {
1069 1470
 			$buffer = explode('},{',$buffer);
1070
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1471
+		    } else {
1472
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1473
+		    }
1071 1474
 		    // SBS format is CSV format
1072 1475
 		    if ($buffer !== FALSE && $buffer != '') {
1073 1476
 			$tt[$format] = 0;
1074 1477
 			if ($format == 'acarssbs3') {
1075
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1478
+			    if ($globalDebug) {
1479
+			    	echo 'ACARS : '.$buffer."\n";
1480
+			    }
1076 1481
 			    $ACARS->add(trim($buffer));
1077 1482
 			    $ACARS->deleteLiveAcarsData();
1078 1483
 			} elseif ($format == 'raw') {
@@ -1081,30 +1486,70 @@  discard block
 block discarded – undo
1081 1486
 			    if (is_array($data)) {
1082 1487
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1488
 				$data['format_source'] = 'raw';
1084
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1085
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1086
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1087
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1489
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1490
+					$data['source_name'] = $globalSources[$nb]['name'];
1491
+				}
1492
+				if (isset($globalSources[$nb]['sourcestats'])) {
1493
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1494
+				}
1495
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1496
+					$data['noarchive'] = true;
1497
+				}
1498
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1499
+					$SI->add($data);
1500
+				}
1088 1501
 			    }
1089 1502
 			} elseif ($format == 'ais') {
1090 1503
 			    $ais_data = $AIS->parse_line(trim($buffer));
1091 1504
 			    $data = array();
1092
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1093
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1094
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1095
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1096
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1097
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1098
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1099
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1100
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1101
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1102
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1103
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1104
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1105
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1106
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1107
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1505
+			    if (isset($ais_data['ident'])) {
1506
+			    	$data['ident'] = $ais_data['ident'];
1507
+			    }
1508
+			    if (isset($ais_data['mmsi'])) {
1509
+			    	$data['mmsi'] = $ais_data['mmsi'];
1510
+			    }
1511
+			    if (isset($ais_data['speed'])) {
1512
+			    	$data['speed'] = $ais_data['speed'];
1513
+			    }
1514
+			    if (isset($ais_data['heading'])) {
1515
+			    	$data['heading'] = $ais_data['heading'];
1516
+			    }
1517
+			    if (isset($ais_data['latitude'])) {
1518
+			    	$data['latitude'] = $ais_data['latitude'];
1519
+			    }
1520
+			    if (isset($ais_data['longitude'])) {
1521
+			    	$data['longitude'] = $ais_data['longitude'];
1522
+			    }
1523
+			    if (isset($ais_data['status'])) {
1524
+			    	$data['status'] = $ais_data['status'];
1525
+			    }
1526
+			    if (isset($ais_data['statusid'])) {
1527
+			    	$data['status_id'] = $ais_data['statusid'];
1528
+			    }
1529
+			    if (isset($ais_data['type'])) {
1530
+			    	$data['type'] = $ais_data['type'];
1531
+			    }
1532
+			    if (isset($ais_data['imo'])) {
1533
+			    	$data['imo'] = $ais_data['imo'];
1534
+			    }
1535
+			    if (isset($ais_data['callsign'])) {
1536
+			    	$data['callsign'] = $ais_data['callsign'];
1537
+			    }
1538
+			    if (isset($ais_data['destination'])) {
1539
+			    	$data['arrival_code'] = $ais_data['destination'];
1540
+			    }
1541
+			    if (isset($ais_data['eta_ts'])) {
1542
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1543
+			    }
1544
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1545
+			    	$data['noarchive'] = true;
1546
+			    }
1547
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1548
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1549
+			    }
1550
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1551
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1552
+			    }
1108 1553
 
1109 1554
 			    if (isset($ais_data['timestamp'])) {
1110 1555
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1113,7 +1558,9 @@  discard block
 block discarded – undo
1113 1558
 			    }
1114 1559
 			    $data['format_source'] = 'aisnmea';
1115 1560
     			    $data['id_source'] = $id_source;
1116
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1561
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1562
+			    	$MI->add($data);
1563
+			    }
1117 1564
 			    unset($data);
1118 1565
                         } elseif ($format == 'flightgearsp') {
1119 1566
                     	    //echo $buffer."\n";
@@ -1131,12 +1578,18 @@  discard block
 block discarded – undo
1131 1578
 				$data['speed'] = round($line[5]*1.94384);
1132 1579
 				$data['datetime'] = date('Y-m-d H:i:s');
1133 1580
 				$data['format_source'] = 'flightgearsp';
1134
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1135
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1581
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1582
+					$data['noarchive'] = true;
1583
+				}
1584
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1585
+					$SI->add($data);
1586
+				}
1136 1587
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1137 1588
 			    }
1138 1589
                         } elseif ($format == 'acars') {
1139
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1590
+                    	    if ($globalDebug) {
1591
+                    	    	echo 'ACARS : '.$buffer."\n";
1592
+                    	    }
1140 1593
 			    $ACARS->add(trim($buffer));
1141 1594
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1142 1595
 			    $ACARS->deleteLiveAcarsData();
@@ -1157,8 +1610,12 @@  discard block
 block discarded – undo
1157 1610
 				    $aircraft_type = $line[10];
1158 1611
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1159 1612
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1160
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1161
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1613
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1614
+				    	$data['noarchive'] = true;
1615
+				    }
1616
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1617
+				    	$SI->add($data);
1618
+				    }
1162 1619
 				}
1163 1620
 			    }
1164 1621
 			} elseif ($format == 'beast') {
@@ -1168,28 +1625,62 @@  discard block
 block discarded – undo
1168 1625
 			    foreach($buffer as $all_data) {
1169 1626
 				$line = json_decode('{'.$all_data.'}',true);
1170 1627
 				$data = array();
1171
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1172
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1173
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1174
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1175
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1176
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1177
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1628
+				if (isset($line['Icao'])) {
1629
+					$data['hex'] = $line['Icao'];
1630
+				}
1631
+				// hex
1632
+				if (isset($line['Call'])) {
1633
+					$data['ident'] = $line['Call'];
1634
+				}
1635
+				// ident
1636
+				if (isset($line['Alt'])) {
1637
+					$data['altitude'] = $line['Alt'];
1638
+				}
1639
+				// altitude
1640
+				if (isset($line['Spd'])) {
1641
+					$data['speed'] = $line['Spd'];
1642
+				}
1643
+				// speed
1644
+				if (isset($line['Trak'])) {
1645
+					$data['heading'] = $line['Trak'];
1646
+				}
1647
+				// heading
1648
+				if (isset($line['Lat'])) {
1649
+					$data['latitude'] = $line['Lat'];
1650
+				}
1651
+				// lat
1652
+				if (isset($line['Long'])) {
1653
+					$data['longitude'] = $line['Long'];
1654
+				}
1655
+				// long
1178 1656
 				//$data['verticalrate'] = $line['']; // verticale rate
1179
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1657
+				if (isset($line['Sqk'])) {
1658
+					$data['squawk'] = $line['Sqk'];
1659
+				}
1660
+				// squawk
1180 1661
 				$data['emergency'] = ''; // emergency
1181
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1662
+				if (isset($line['Reg'])) {
1663
+					$data['registration'] = $line['Reg'];
1664
+				}
1182 1665
 				/*
1183 1666
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1184 1667
 				else $data['datetime'] = date('Y-m-d H:i:s');
1185 1668
 				*/
1186 1669
 				$data['datetime'] = date('Y-m-d H:i:s');
1187
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1670
+				if (isset($line['Type'])) {
1671
+					$data['aircraft_icao'] = $line['Type'];
1672
+				}
1188 1673
 		    		$data['format_source'] = 'vrstcp';
1189 1674
 				$data['id_source'] = $id_source;
1190
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1191
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1192
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1675
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1676
+					$data['noarchive'] = true;
1677
+				}
1678
+				if (isset($value['name']) && $value['name'] != '') {
1679
+					$data['source_name'] = $value['name'];
1680
+				}
1681
+				if (isset($data['latitude']) && isset($data['hex'])) {
1682
+					$SI->add($data);
1683
+				}
1193 1684
 				unset($data);
1194 1685
 			    }
1195 1686
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1202,22 +1693,46 @@  discard block
 block discarded – undo
1202 1693
     				$data['hex'] = $lined['hexid'];
1203 1694
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1204 1695
     				$data['datetime'] = date('Y-m-d H:i:s');;
1205
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1206
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1207
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1208
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1209
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1210
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1211
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1696
+    				if (isset($lined['ident'])) {
1697
+    					$data['ident'] = $lined['ident'];
1698
+    				}
1699
+    				if (isset($lined['lat'])) {
1700
+    					$data['latitude'] = $lined['lat'];
1701
+    				}
1702
+    				if (isset($lined['lon'])) {
1703
+    					$data['longitude'] = $lined['lon'];
1704
+    				}
1705
+    				if (isset($lined['speed'])) {
1706
+    					$data['speed'] = $lined['speed'];
1707
+    				}
1708
+    				if (isset($lined['squawk'])) {
1709
+    					$data['squawk'] = $lined['squawk'];
1710
+    				}
1711
+    				if (isset($lined['alt'])) {
1712
+    					$data['altitude'] = $lined['alt'];
1713
+    				}
1714
+    				if (isset($lined['heading'])) {
1715
+    					$data['heading'] = $lined['heading'];
1716
+    				}
1212 1717
     				$data['id_source'] = $id_source;
1213 1718
     				$data['format_source'] = 'tsv';
1214
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1215
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1216
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1217
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1719
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1720
+    					$data['source_name'] = $globalSources[$nb]['name'];
1721
+    				}
1722
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1723
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1724
+    				}
1725
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1726
+					$data['noarchive'] = true;
1727
+				}
1728
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1729
+    					$SI->add($data);
1730
+    				}
1218 1731
     				unset($lined);
1219 1732
     				unset($data);
1220
-    			    } else $error = true;
1733
+    			    } else {
1734
+    			    	$error = true;
1735
+    			    }
1221 1736
 			} elseif ($format == 'aprs' && $use_aprs) {
1222 1737
 			    if ($aprs_connect == 0) {
1223 1738
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1242,39 +1757,86 @@  discard block
 block discarded – undo
1242 1757
 				    $aprs_last_tx = time();
1243 1758
 				    $data = array();
1244 1759
 				    //print_r($line);
1245
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1246
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1247
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1248
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1249
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1250
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1251
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1252
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1253
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1254
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1760
+				    if (isset($line['address'])) {
1761
+				    	$data['hex'] = $line['address'];
1762
+				    }
1763
+				    if (isset($line['mmsi'])) {
1764
+				    	$data['mmsi'] = $line['mmsi'];
1765
+				    }
1766
+				    if (isset($line['imo'])) {
1767
+				    	$data['imo'] = $line['imo'];
1768
+				    }
1769
+				    if (isset($line['squawk'])) {
1770
+				    	$data['squawk'] = $line['squawk'];
1771
+				    }
1772
+				    if (isset($line['arrival_code'])) {
1773
+				    	$data['arrical_code'] = $line['arrival_code'];
1774
+				    }
1775
+				    if (isset($line['arrival_date'])) {
1776
+				    	$data['arrical_date'] = $line['arrival_date'];
1777
+				    }
1778
+				    if (isset($line['type_id'])) {
1779
+				    	$data['type_id'] = $line['typeid'];
1780
+				    }
1781
+				    if (isset($line['status_id'])) {
1782
+				    	$data['status_id'] = $line['statusid'];
1783
+				    }
1784
+				    if (isset($line['timestamp'])) {
1785
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1786
+				    } else {
1787
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1788
+				    }
1255 1789
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1256
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1790
+				    if (isset($line['ident'])) {
1791
+				    	$data['ident'] = $line['ident'];
1792
+				    }
1257 1793
 				    $data['latitude'] = $line['latitude'];
1258 1794
 				    $data['longitude'] = $line['longitude'];
1259 1795
 				    //$data['verticalrate'] = $line[16];
1260
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1261
-				    else $data['speed'] = 0;
1262
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1263
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1264
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1265
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1796
+				    if (isset($line['speed'])) {
1797
+				    	$data['speed'] = $line['speed'];
1798
+				    } else {
1799
+				    	$data['speed'] = 0;
1800
+				    }
1801
+				    if (isset($line['altitude'])) {
1802
+				    	$data['altitude'] = $line['altitude'];
1803
+				    }
1804
+				    if (isset($line['comment'])) {
1805
+				    	$data['comment'] = $line['comment'];
1806
+				    }
1807
+				    if (isset($line['symbol'])) {
1808
+				    	$data['type'] = $line['symbol'];
1809
+				    }
1810
+				    if (isset($line['heading'])) {
1811
+				    	$data['heading'] = $line['heading'];
1812
+				    }
1266 1813
 				    //else $data['heading'] = 0;
1267
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1268
-				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1269
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1270
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1814
+				    if (isset($line['stealth'])) {
1815
+				    	$data['aircraft_type'] = $line['stealth'];
1816
+				    }
1817
+				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) {
1818
+				    	$data['noarchive'] = true;
1819
+				    }
1820
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1821
+				    	$data['noarchive'] = true;
1822
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
1823
+				    	$data['noarchive'] = false;
1824
+				    }
1271 1825
     				    $data['id_source'] = $id_source;
1272
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1273
-				    else $data['format_source'] = 'aprs';
1826
+    				    if (isset($line['format_source'])) {
1827
+    				    	$data['format_source'] = $line['format_source'];
1828
+    				    } else {
1829
+				    	$data['format_source'] = 'aprs';
1830
+				    }
1274 1831
 				    $data['source_name'] = $line['source'];
1275
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1276
-				    else $data['source_type'] = 'flarm';
1277
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1832
+				    if (isset($line['source_type'])) {
1833
+				    	$data['source_type'] = $line['source_type'];
1834
+				    } else {
1835
+				    	$data['source_type'] = 'flarm';
1836
+				    }
1837
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1838
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1839
+    				    }
1278 1840
 				    $currentdate = date('Y-m-d H:i:s');
1279 1841
 				    $aprsdate = strtotime($data['datetime']);
1280 1842
 				    // Accept data if time <= system time + 20s
@@ -1282,21 +1844,26 @@  discard block
 block discarded – undo
1282 1844
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1283 1845
 					$send = $SI->add($data);
1284 1846
 				    } elseif ($data['source_type'] == 'ais') {
1285
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1847
+					if (isset($globalMarine) && $globalMarine) {
1848
+						$send = $MI->add($data);
1849
+					}
1286 1850
 				    } elseif (isset($line['stealth'])) {
1287
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1288
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1851
+					if ($line['stealth'] != 0) {
1852
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1853
+					} else {
1854
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1855
+					}
1289 1856
 				    //} 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')) {
1290 1857
 				    } 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') {
1291 1858
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1292
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1859
+					if (isset($globalTracker) && $globalTracker) {
1860
+						$send = $TI->add($data);
1861
+					}
1293 1862
 				    }
1294 1863
 				    unset($data);
1295
-				} 
1296
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1864
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1297 1865
 					echo '!! Weather Station not yet supported'."\n";
1298
-				}
1299
-				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')) {
1866
+				} 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')) {
1300 1867
 					echo '!! Car & Trucks not yet supported'."\n";
1301 1868
 				}
1302 1869
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1329,26 +1896,45 @@  discard block
 block discarded – undo
1329 1896
     				$data['ground'] = $line[21];
1330 1897
     				$data['emergency'] = $line[19];
1331 1898
     				$data['format_source'] = 'sbs';
1332
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1333
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1334
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1899
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1900
+					$data['source_name'] = $globalSources[$nb]['name'];
1901
+				}
1902
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1903
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1904
+    				}
1905
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1906
+					$data['noarchive'] = true;
1907
+				}
1335 1908
     				$data['id_source'] = $id_source;
1336
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1337
-    				else $error = true;
1909
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1910
+    					$send = $SI->add($data);
1911
+    				} else {
1912
+    					$error = true;
1913
+    				}
1338 1914
     				unset($data);
1339
-    			    } else $error = true;
1915
+    			    } else {
1916
+    			    	$error = true;
1917
+    			    }
1340 1918
 			    if ($error) {
1341 1919
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1342
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1920
+					if ($globalDebug) {
1921
+						echo "Not a message. Ignoring... \n";
1922
+					}
1343 1923
 				} else {
1344
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1924
+					if ($globalDebug) {
1925
+						echo "Wrong line format. Ignoring... \n";
1926
+					}
1345 1927
 					if ($globalDebug) {
1346 1928
 						echo $buffer;
1347 1929
 						//print_r($line);
1348 1930
 					}
1349 1931
 					//socket_close($r);
1350
-					if ($globalDebug) echo "Reconnect after an error...\n";
1351
-					if ($format == 'aprs') $aprs_connect = 0;
1932
+					if ($globalDebug) {
1933
+						echo "Reconnect after an error...\n";
1934
+					}
1935
+					if ($format == 'aprs') {
1936
+						$aprs_connect = 0;
1937
+					}
1352 1938
 					$sourceer[$nb] = $globalSources[$nb];
1353 1939
 					connect_all($sourceer);
1354 1940
 					$sourceer = array();
@@ -1356,10 +1942,14 @@  discard block
 block discarded – undo
1356 1942
 			    }
1357 1943
 			}
1358 1944
 			// Sleep for xxx microseconds
1359
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1945
+			if (isset($globalSBSSleep)) {
1946
+				usleep($globalSBSSleep);
1947
+			}
1360 1948
 		    } else {
1361 1949
 			if ($format == 'flightgearmp') {
1362
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1950
+			    	if ($globalDebug) {
1951
+			    		echo "Reconnect FlightGear MP...";
1952
+			    	}
1363 1953
 				//@socket_close($r);
1364 1954
 				sleep($globalMinFetch);
1365 1955
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1368,10 +1958,15 @@  discard block
 block discarded – undo
1368 1958
 				break;
1369 1959
 				
1370 1960
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1371
-			    if (isset($tt[$format])) $tt[$format]++;
1372
-			    else $tt[$format] = 0;
1961
+			    if (isset($tt[$format])) {
1962
+			    	$tt[$format]++;
1963
+			    } else {
1964
+			    	$tt[$format] = 0;
1965
+			    }
1373 1966
 			    if ($tt[$format] > 30) {
1374
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1967
+				if ($globalDebug) {
1968
+					echo "ERROR : Reconnect ".$format."...";
1969
+				}
1375 1970
 				//@socket_close($r);
1376 1971
 				sleep(2);
1377 1972
 				$aprs_connect = 0;
@@ -1388,11 +1983,17 @@  discard block
 block discarded – undo
1388 1983
 	    } else {
1389 1984
 		$error = socket_strerror(socket_last_error());
1390 1985
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1391
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1392
-			if (isset($globalDebug)) echo "Restarting...\n";
1986
+			if ($globalDebug) {
1987
+				echo "ERROR : socket_select give this error ".$error . "\n";
1988
+			}
1989
+			if (isset($globalDebug)) {
1990
+				echo "Restarting...\n";
1991
+			}
1393 1992
 			// Restart the script if possible
1394 1993
 			if (is_array($sockets)) {
1395
-			    if ($globalDebug) echo "Shutdown all sockets...";
1994
+			    if ($globalDebug) {
1995
+			    	echo "Shutdown all sockets...";
1996
+			    }
1396 1997
 			    
1397 1998
 			    foreach ($sockets as $sock) {
1398 1999
 				@socket_shutdown($sock,2);
@@ -1400,22 +2001,36 @@  discard block
 block discarded – undo
1400 2001
 			    }
1401 2002
 			    
1402 2003
 			}
1403
-			if ($globalDebug) echo "Waiting...";
2004
+			if ($globalDebug) {
2005
+				echo "Waiting...";
2006
+			}
1404 2007
 			sleep(2);
1405 2008
 			$time = time();
1406 2009
 			//connect_all($hosts);
1407 2010
 			$aprs_connect = 0;
1408
-			if ($reset%5 == 0) sleep(20);
1409
-			if ($reset%10 == 0) sleep(100);
1410
-			if ($reset%20 == 0) sleep(200);
1411
-			if ($reset > 100) exit('Too many attempts...');
1412
-			if ($globalDebug) echo "Restart all connections...";
2011
+			if ($reset%5 == 0) {
2012
+				sleep(20);
2013
+			}
2014
+			if ($reset%10 == 0) {
2015
+				sleep(100);
2016
+			}
2017
+			if ($reset%20 == 0) {
2018
+				sleep(200);
2019
+			}
2020
+			if ($reset > 100) {
2021
+				exit('Too many attempts...');
2022
+			}
2023
+			if ($globalDebug) {
2024
+				echo "Restart all connections...";
2025
+			}
1413 2026
 			connect_all($globalSources);
1414 2027
 		}
1415 2028
 	    }
1416 2029
 	}
1417 2030
 	if ($globalDaemon === false) {
1418
-	    if ($globalDebug) echo 'Check all...'."\n";
2031
+	    if ($globalDebug) {
2032
+	    	echo 'Check all...'."\n";
2033
+	    }
1419 2034
 	    $SI->checkAll();
1420 2035
 	}
1421 2036
     }
Please login to merge, or discard this patch.