Completed
Push — master ( cb0b23...3240cd )
by Yannick
74:14 queued 46:04
created
scripts/daemon-spotter.php 3 patches
Indentation   +958 added lines, -958 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,46 +25,46 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->connectionExists() === false) {
28
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
-    exit();
28
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
+	exit();
30 30
 }
31 31
 if ($Connection->latest() === false) {
32
-    echo "You MUST update to latest schema. Run install/index.php";
33
-    exit();
32
+	echo "You MUST update to latest schema. Run install/index.php";
33
+	exit();
34 34
 }
35 35
 if (PHP_SAPI != 'cli') {
36
-    echo "This script MUST be called from console, not a web browser.";
36
+	echo "This script MUST be called from console, not a web browser.";
37 37
 //    exit();
38 38
 }
39 39
 
40 40
 // This is to be compatible with old version of settings.php
41 41
 if (!isset($globalSources)) {
42
-    if (isset($globalSBS1Hosts)) {
43
-        //$hosts = $globalSBS1Hosts;
44
-        foreach ($globalSBS1Hosts as $host) {
45
-	    $globalSources[] = array('host' => $host);
46
-    	}
47
-    } else {
48
-        if (!isset($globalSBS1Host)) {
49
-	    echo '$globalSources MUST be defined !';
50
-	    die;
42
+	if (isset($globalSBS1Hosts)) {
43
+		//$hosts = $globalSBS1Hosts;
44
+		foreach ($globalSBS1Hosts as $host) {
45
+		$globalSources[] = array('host' => $host);
46
+		}
47
+	} else {
48
+		if (!isset($globalSBS1Host)) {
49
+		echo '$globalSources MUST be defined !';
50
+		die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53 53
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
54
-    }
54
+	}
55 55
 }
56 56
 
57 57
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65
-    $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
65
+	$globalSources = array();
66
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
+	else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
70 70
 	$globalServerAPRS = TRUE;
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 if (isset($options['idsource'])) $id_source = $options['idsource'];
89 89
 else $id_source = 1;
90 90
 if (isset($globalServer) && $globalServer) {
91
-    if ($globalDebug) echo "Using Server Mode\n";
92
-    $SI=new SpotterServer();
91
+	if ($globalDebug) echo "Using Server Mode\n";
92
+	$SI=new SpotterServer();
93 93
 /*
94 94
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
95 95
     $SI = new adsb2aprs();
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
 
100 100
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
101 101
 if (isset($globalMarine) && $globalMarine) {
102
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
103
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
102
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
103
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
104 104
 }
105 105
 
106 106
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
107 107
 if (isset($globalMarine) && $globalMarine) {
108
-    $AIS = new AIS();
109
-    $MI = new MarineImport($Connection->db);
108
+	$AIS = new AIS();
109
+	$MI = new MarineImport($Connection->db);
110 110
 }
111 111
 //$APRS=new APRS($Connection->db);
112 112
 $SBS=new SBS();
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
 //$servertz = system('date +%Z');
118 118
 // signal handler - playing nice with sockets and dump1090
119 119
 if (function_exists('pcntl_fork')) {
120
-    pcntl_signal(SIGINT,  function() {
121
-        global $sockets;
122
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
123
-        die("Bye!\n");
124
-    });
125
-    pcntl_signal_dispatch();
120
+	pcntl_signal(SIGINT,  function() {
121
+		global $sockets;
122
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
123
+		die("Bye!\n");
124
+	});
125
+	pcntl_signal_dispatch();
126 126
 }
127 127
 
128 128
 // let's try and connect
@@ -132,36 +132,36 @@  discard block
 block discarded – undo
132 132
 $reset = 0;
133 133
 
134 134
 function connect_all($hosts) {
135
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
136
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
137
-    $reset++;
138
-    if ($globalDebug) echo 'Connect to all...'."\n";
139
-    foreach ($hosts as $id => $value) {
135
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
136
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
137
+	$reset++;
138
+	if ($globalDebug) echo 'Connect to all...'."\n";
139
+	foreach ($hosts as $id => $value) {
140 140
 	$host = $value['host'];
141 141
 	$globalSources[$id]['last_exec'] = 0;
142 142
 	// Here we check type of source(s)
143 143
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
144
-            if (preg_match('/deltadb.txt$/i',$host)) {
145
-        	//$formats[$id] = 'deltadbtxt';
146
-        	$globalSources[$id]['format'] = 'deltadbtxt';
147
-        	//$last_exec['deltadbtxt'] = 0;
148
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
149
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
150
-        	//$formats[$id] = 'vatsimtxt';
151
-        	$globalSources[$id]['format'] = 'vatsimtxt';
152
-        	//$last_exec['vatsimtxt'] = 0;
153
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
154
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
155
-        	//$formats[$id] = 'aircraftlistjson';
156
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
157
-        	//$last_exec['aircraftlistjson'] = 0;
158
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
-    	    } else if (preg_match('/opensky/i',$host)) {
160
-        	//$formats[$id] = 'aircraftlistjson';
161
-        	$globalSources[$id]['format'] = 'opensky';
162
-        	//$last_exec['aircraftlistjson'] = 0;
163
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
164
-    	    /*
144
+			if (preg_match('/deltadb.txt$/i',$host)) {
145
+			//$formats[$id] = 'deltadbtxt';
146
+			$globalSources[$id]['format'] = 'deltadbtxt';
147
+			//$last_exec['deltadbtxt'] = 0;
148
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
149
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
150
+			//$formats[$id] = 'vatsimtxt';
151
+			$globalSources[$id]['format'] = 'vatsimtxt';
152
+			//$last_exec['vatsimtxt'] = 0;
153
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
154
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
155
+			//$formats[$id] = 'aircraftlistjson';
156
+			$globalSources[$id]['format'] = 'aircraftlistjson';
157
+			//$last_exec['aircraftlistjson'] = 0;
158
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+			} else if (preg_match('/opensky/i',$host)) {
160
+			//$formats[$id] = 'aircraftlistjson';
161
+			$globalSources[$id]['format'] = 'opensky';
162
+			//$last_exec['aircraftlistjson'] = 0;
163
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
164
+			/*
165 165
     	    // Disabled for now, site change source format
166 166
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
167 167
         	//$formats[$id] = 'radarvirtueljson';
@@ -173,121 +173,121 @@  discard block
 block discarded – undo
173 173
         	    exit(0);
174 174
         	}
175 175
     	    */
176
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
177
-        	//$formats[$id] = 'planeupdatefaa';
178
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
179
-        	//$last_exec['planeupdatefaa'] = 0;
180
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
181
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
182
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
183
-        	    exit(0);
184
-        	}
185
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
186
-        	//$formats[$id] = 'phpvmacars';
187
-        	$globalSources[$id]['format'] = 'phpvmacars';
188
-        	//$last_exec['phpvmacars'] = 0;
189
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
190
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
191
-        	//$formats[$id] = 'phpvmacars';
192
-        	$globalSources[$id]['format'] = 'vam';
193
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
194
-            } else if (preg_match('/whazzup/i',$host)) {
195
-        	//$formats[$id] = 'whazzup';
196
-        	$globalSources[$id]['format'] = 'whazzup';
197
-        	//$last_exec['whazzup'] = 0;
198
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
199
-            } else if (preg_match('/blitzortung/i',$host)) {
200
-        	$globalSources[$id]['format'] = 'blitzortung';
201
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
202
-            } else if (preg_match('/airwhere/i',$host)) {
203
-        	$globalSources[$id]['format'] = 'airwhere';
204
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
205
-            } else if (preg_match('/recentpireps/i',$host)) {
206
-        	//$formats[$id] = 'pirepsjson';
207
-        	$globalSources[$id]['format'] = 'pirepsjson';
208
-        	//$last_exec['pirepsjson'] = 0;
209
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
210
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
211
-        	//$formats[$id] = 'fr24json';
212
-        	$globalSources[$id]['format'] = 'fr24json';
213
-        	//$last_exec['fr24json'] = 0;
214
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
215
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
216
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
217
-        	    exit(0);
218
-        	}
219
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
220
-        	//$formats[$id] = 'fr24json';
221
-        	$globalSources[$id]['format'] = 'myshiptracking';
222
-        	//$last_exec['fr24json'] = 0;
223
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
224
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
225
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
226
-        	    exit(0);
227
-        	}
228
-            //} else if (preg_match('/10001/',$host)) {
229
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
230
-        	//$formats[$id] = 'tsv';
231
-        	$globalSources[$id]['format'] = 'tsv';
232
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
-            }
234
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
235
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
236
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
237
-    		    if ($idf !== false) {
238
-    			$httpfeeds[$id] = $idf;
239
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
240
-    		    }
241
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
242
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
243
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
244
-	    $hostport = explode(':',$host);
245
-	    if (isset($hostport[1])) {
176
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
177
+			//$formats[$id] = 'planeupdatefaa';
178
+			$globalSources[$id]['format'] = 'planeupdatefaa';
179
+			//$last_exec['planeupdatefaa'] = 0;
180
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
181
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
182
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
183
+				exit(0);
184
+			}
185
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
186
+			//$formats[$id] = 'phpvmacars';
187
+			$globalSources[$id]['format'] = 'phpvmacars';
188
+			//$last_exec['phpvmacars'] = 0;
189
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
190
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
191
+			//$formats[$id] = 'phpvmacars';
192
+			$globalSources[$id]['format'] = 'vam';
193
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
194
+			} else if (preg_match('/whazzup/i',$host)) {
195
+			//$formats[$id] = 'whazzup';
196
+			$globalSources[$id]['format'] = 'whazzup';
197
+			//$last_exec['whazzup'] = 0;
198
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
199
+			} else if (preg_match('/blitzortung/i',$host)) {
200
+			$globalSources[$id]['format'] = 'blitzortung';
201
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
202
+			} else if (preg_match('/airwhere/i',$host)) {
203
+			$globalSources[$id]['format'] = 'airwhere';
204
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
205
+			} else if (preg_match('/recentpireps/i',$host)) {
206
+			//$formats[$id] = 'pirepsjson';
207
+			$globalSources[$id]['format'] = 'pirepsjson';
208
+			//$last_exec['pirepsjson'] = 0;
209
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
210
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
211
+			//$formats[$id] = 'fr24json';
212
+			$globalSources[$id]['format'] = 'fr24json';
213
+			//$last_exec['fr24json'] = 0;
214
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
215
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
216
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
217
+				exit(0);
218
+			}
219
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
220
+			//$formats[$id] = 'fr24json';
221
+			$globalSources[$id]['format'] = 'myshiptracking';
222
+			//$last_exec['fr24json'] = 0;
223
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
224
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
225
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
226
+				exit(0);
227
+			}
228
+			//} else if (preg_match('/10001/',$host)) {
229
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
230
+			//$formats[$id] = 'tsv';
231
+			$globalSources[$id]['format'] = 'tsv';
232
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+			}
234
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
235
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
236
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
237
+				if ($idf !== false) {
238
+				$httpfeeds[$id] = $idf;
239
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
240
+				}
241
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
242
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
243
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
244
+		$hostport = explode(':',$host);
245
+		if (isset($hostport[1])) {
246 246
 		$port = $hostport[1];
247 247
 		$hostn = $hostport[0];
248
-	    } else {
248
+		} else {
249 249
 		$port = $globalSources[$id]['port'];
250 250
 		$hostn = $globalSources[$id]['host'];
251
-	    }
252
-	    $Common = new Common();
253
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
254
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
255
-    	    } else {
256
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
257
-	    }
258
-	    if ($s) {
259
-    	        $sockets[$id] = $s;
260
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
261
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
251
+		}
252
+		$Common = new Common();
253
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
254
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
255
+			} else {
256
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
257
+		}
258
+		if ($s) {
259
+				$sockets[$id] = $s;
260
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
261
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
262 262
 			//$formats[$id] = 'aprs';
263 263
 			$globalSources[$id]['format'] = 'aprs';
264 264
 			//$aprs_connect = 0;
265 265
 			//$use_aprs = true;
266
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
266
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
267 267
 			$globalSources[$id]['format'] = 'vrstcp';
268
-    		    } elseif ($port == '10001') {
269
-        		//$formats[$id] = 'tsv';
270
-        		$globalSources[$id]['format'] = 'tsv';
271
-		    } elseif ($port == '30002') {
272
-        		//$formats[$id] = 'raw';
273
-        		$globalSources[$id]['format'] = 'raw';
274
-		    } elseif ($port == '5001') {
275
-        		//$formats[$id] = 'raw';
276
-        		$globalSources[$id]['format'] = 'flightgearmp';
277
-		    } elseif ($port == '30005') {
268
+				} elseif ($port == '10001') {
269
+				//$formats[$id] = 'tsv';
270
+				$globalSources[$id]['format'] = 'tsv';
271
+			} elseif ($port == '30002') {
272
+				//$formats[$id] = 'raw';
273
+				$globalSources[$id]['format'] = 'raw';
274
+			} elseif ($port == '5001') {
275
+				//$formats[$id] = 'raw';
276
+				$globalSources[$id]['format'] = 'flightgearmp';
277
+			} elseif ($port == '30005') {
278 278
 			// Not yet supported
279
-        		//$formats[$id] = 'beast';
280
-        		$globalSources[$id]['format'] = 'beast';
281
-		    //} else $formats[$id] = 'sbs';
282
-		    } else $globalSources[$id]['format'] = 'sbs';
283
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
279
+				//$formats[$id] = 'beast';
280
+				$globalSources[$id]['format'] = 'beast';
281
+			//} else $formats[$id] = 'sbs';
282
+			} else $globalSources[$id]['format'] = 'sbs';
283
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
284 284
 		}
285 285
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
286
-            } else {
286
+			} else {
287 287
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
288
-    	    }
289
-        }
290
-    }
288
+			}
289
+		}
290
+	}
291 291
 }
292 292
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
293 293
 
@@ -310,9 +310,9 @@  discard block
 block discarded – undo
310 310
 //connect_all($globalSources);
311 311
 
312 312
 if (isset($globalProxy) && $globalProxy) {
313
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
313
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
314 314
 } else {
315
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
315
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
316 316
 }
317 317
 
318 318
 // APRS Configuration
@@ -321,21 +321,21 @@  discard block
 block discarded – undo
321 321
 	die;
322 322
 }
323 323
 foreach ($globalSources as $key => $source) {
324
-    if (!isset($source['format'])) {
325
-        $globalSources[$key]['format'] = 'auto';
326
-    }
327
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
328
-        unset($globalSources[$key]);
329
-    }
324
+	if (!isset($source['format'])) {
325
+		$globalSources[$key]['format'] = 'auto';
326
+	}
327
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
328
+		unset($globalSources[$key]);
329
+	}
330 330
 }
331 331
 connect_all($globalSources);
332 332
 foreach ($globalSources as $key => $source) {
333
-    if (isset($source['format']) && $source['format'] == 'aprs') {
333
+	if (isset($source['format']) && $source['format'] == 'aprs') {
334 334
 	$aprs_connect = 0;
335 335
 	$use_aprs = true;
336 336
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
337 337
 	break;
338
-    }
338
+	}
339 339
 }
340 340
 
341 341
 if ($use_aprs) {
@@ -376,126 +376,126 @@  discard block
 block discarded – undo
376 376
 
377 377
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
378 378
 while ($i > 0) {
379
-    if (!$globalDaemon) $i = $endtime-time();
380
-    // Delete old ATC
381
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
379
+	if (!$globalDaemon) $i = $endtime-time();
380
+	// Delete old ATC
381
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
382 382
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
383
-        $ATC->deleteOldATC();
384
-    }
383
+		$ATC->deleteOldATC();
384
+	}
385 385
     
386
-    if (count($last_exec) == count($globalSources)) {
386
+	if (count($last_exec) == count($globalSources)) {
387 387
 	$max = $globalMinFetch;
388 388
 	foreach ($last_exec as $last) {
389
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
389
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
390 390
 	}
391 391
 	if ($max != $globalMinFetch) {
392
-	    if ($globalDebug) echo 'Sleeping...'."\n";
393
-	    sleep($globalMinFetch-$max+2);
392
+		if ($globalDebug) echo 'Sleeping...'."\n";
393
+		sleep($globalMinFetch-$max+2);
394
+	}
394 395
 	}
395
-    }
396 396
 
397 397
     
398
-    //foreach ($formats as $id => $value) {
399
-    foreach ($globalSources as $id => $value) {
398
+	//foreach ($formats as $id => $value) {
399
+	foreach ($globalSources as $id => $value) {
400 400
 	date_default_timezone_set('UTC');
401 401
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
402 402
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
403 403
 	if ($value['format'] == 'deltadbtxt' && 
404
-	    (
404
+		(
405 405
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
406 406
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
407
-	    )
407
+		)
408 408
 	) {
409
-	    //$buffer = $Common->getData($hosts[$id]);
410
-	    $buffer = $Common->getData($value['host']);
411
-	    if ($buffer != '') $reset = 0;
412
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
-	    $buffer = explode('\n',$buffer);
414
-	    foreach ($buffer as $line) {
415
-    		if ($line != '' && count($line) > 7) {
416
-    		    $line = explode(',', $line);
417
-	            $data = array();
418
-	            $data['hex'] = $line[1]; // hex
419
-	            $data['ident'] = $line[2]; // ident
420
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
421
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
422
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
423
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
424
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
425
-	            $data['verticalrate'] = ''; // vertical rate
426
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
427
-	            $data['emergency'] = ''; // emergency
428
-		    $data['datetime'] = date('Y-m-d H:i:s');
429
-		    $data['format_source'] = 'deltadbtxt';
430
-    		    $data['id_source'] = $id_source;
431
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
432
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
433
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
434
-    		    $SI->add($data);
435
-		    unset($data);
436
-    		}
437
-    	    }
438
-    	    $last_exec[$id]['last'] = time();
409
+		//$buffer = $Common->getData($hosts[$id]);
410
+		$buffer = $Common->getData($value['host']);
411
+		if ($buffer != '') $reset = 0;
412
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
+		$buffer = explode('\n',$buffer);
414
+		foreach ($buffer as $line) {
415
+			if ($line != '' && count($line) > 7) {
416
+				$line = explode(',', $line);
417
+				$data = array();
418
+				$data['hex'] = $line[1]; // hex
419
+				$data['ident'] = $line[2]; // ident
420
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
421
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
422
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
423
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
424
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
425
+				$data['verticalrate'] = ''; // vertical rate
426
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
427
+				$data['emergency'] = ''; // emergency
428
+			$data['datetime'] = date('Y-m-d H:i:s');
429
+			$data['format_source'] = 'deltadbtxt';
430
+				$data['id_source'] = $id_source;
431
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
432
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
433
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
434
+				$SI->add($data);
435
+			unset($data);
436
+			}
437
+			}
438
+			$last_exec[$id]['last'] = time();
439 439
 	} elseif ($value['format'] == 'aisnmeatxt' && 
440
-	    (
440
+		(
441 441
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
442 442
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
443
-	    )
443
+		)
444 444
 	) {
445
-	    date_default_timezone_set('CET');
446
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
447
-	    date_default_timezone_set('UTC');
448
-	    if ($buffer != '') $reset = 0;
449
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
450
-	    $buffer = explode('\n',$buffer);
451
-	    foreach ($buffer as $line) {
445
+		date_default_timezone_set('CET');
446
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
447
+		date_default_timezone_set('UTC');
448
+		if ($buffer != '') $reset = 0;
449
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
450
+		$buffer = explode('\n',$buffer);
451
+		foreach ($buffer as $line) {
452 452
 		if ($line != '') {
453
-		    //echo "'".$line."'\n";
454
-		    $add = false;
455
-		    $ais_data = $AIS->parse_line(trim($line));
456
-		    $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['type'])) $data['type'] = $ais_data['type'];
465
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
466
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
467
-		    if (isset($ais_data['timestamp'])) {
453
+			//echo "'".$line."'\n";
454
+			$add = false;
455
+			$ais_data = $AIS->parse_line(trim($line));
456
+			$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['type'])) $data['type'] = $ais_data['type'];
465
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
466
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
467
+			if (isset($ais_data['timestamp'])) {
468 468
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
469 469
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
470
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
471
-			    $add = true;
470
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
471
+				$add = true;
472 472
 			}
473
-		    } else {
473
+			} else {
474 474
 			$data['datetime'] = date('Y-m-d H:i:s');
475 475
 			$add = true;
476
-		    }
477
-		    $data['format_source'] = 'aisnmeatxt';
478
-    		    $data['id_source'] = $id_source;
479
-		    //print_r($data);
480
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
481
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
482
-		    unset($data);
476
+			}
477
+			$data['format_source'] = 'aisnmeatxt';
478
+				$data['id_source'] = $id_source;
479
+			//print_r($data);
480
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
481
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
482
+			unset($data);
483 483
 		}
484
-    	    }
485
-    	    $last_exec[$id]['last'] = time();
484
+			}
485
+			$last_exec[$id]['last'] = time();
486 486
 	} elseif ($value['format'] == 'aisnmeahttp') {
487
-	    $arr = $httpfeeds;
488
-	    $w = $e = null;
487
+		$arr = $httpfeeds;
488
+		$w = $e = null;
489 489
 	    
490
-	    if (isset($arr[$id])) {
490
+		if (isset($arr[$id])) {
491 491
 		$nn = stream_select($arr,$w,$e,$timeout);
492 492
 		if ($nn > 0) {
493
-		    foreach ($httpfeeds as $feed) {
493
+			foreach ($httpfeeds as $feed) {
494 494
 			$buffer = stream_get_line($feed,2000,"\n");
495 495
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
496 496
 			$buffer = explode('\n',$buffer);
497 497
 			foreach ($buffer as $line) {
498
-			    if ($line != '') {
498
+				if ($line != '') {
499 499
 				$ais_data = $AIS->parse_line(trim($line));
500 500
 				$data = array();
501 501
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -513,111 +513,111 @@  discard block
 block discarded – undo
513 513
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
514 514
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
515 515
 				if (isset($ais_data['timestamp'])) {
516
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
516
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
517 517
 				} else {
518
-				    $data['datetime'] = date('Y-m-d H:i:s');
518
+					$data['datetime'] = date('Y-m-d H:i:s');
519 519
 				}
520 520
 				$data['format_source'] = 'aisnmeahttp';
521 521
 				$data['id_source'] = $id_source;
522 522
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
523 523
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
524 524
 				unset($data);
525
-			    }
525
+				}
526
+			}
526 527
 			}
527
-		    }
528 528
 		} else {
529
-		    $format = $value['format'];
530
-		    if (isset($tt[$format])) $tt[$format]++;
531
-		    else $tt[$format] = 0;
532
-		    if ($tt[$format] > 30) {
529
+			$format = $value['format'];
530
+			if (isset($tt[$format])) $tt[$format]++;
531
+			else $tt[$format] = 0;
532
+			if ($tt[$format] > 30) {
533 533
 			if ($globalDebug) echo 'Reconnect...'."\n";
534 534
 			sleep(2);
535 535
 			$sourceeen[] = $value;
536 536
 			connect_all($sourceeen);
537 537
 			$sourceeen = array();
538
-		    }
538
+			}
539
+		}
539 540
 		}
540
-	    }
541 541
 	} elseif ($value['format'] == 'myshiptracking' && 
542
-	    (
542
+		(
543 543
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
544 544
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
545
-	    )
545
+		)
546 546
 	) {
547
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
548
-	    if ($buffer != '') {
547
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
548
+		if ($buffer != '') {
549 549
 		//echo $buffer;
550 550
 		$all_data = json_decode($buffer,true);
551 551
 		//print_r($all_data);
552 552
 		if (isset($all_data[0]['DATA'])) {
553
-		    foreach ($all_data[0]['DATA'] as $line) {
553
+			foreach ($all_data[0]['DATA'] as $line) {
554 554
 			if ($line != '') {
555
-			    $data = array();
556
-			    $data['ident'] = $line['NAME'];
557
-			    $data['mmsi'] = $line['MMSI'];
558
-			    $data['speed'] = $line['SOG'];
559
-			    $data['heading'] = $line['COG'];
560
-			    $data['latitude'] = $line['LAT'];
561
-			    $data['longitude'] = $line['LNG'];
562
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
563
-			    $data['imo'] = $line['IMO'];
564
-			    //$data['arrival_code'] = $ais_data['destination'];
565
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
566
-			    $data['format_source'] = 'myshiptracking';
567
-			    $data['id_source'] = $id_source;
568
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
569
-			    $MI->add($data);
570
-			    unset($data);
555
+				$data = array();
556
+				$data['ident'] = $line['NAME'];
557
+				$data['mmsi'] = $line['MMSI'];
558
+				$data['speed'] = $line['SOG'];
559
+				$data['heading'] = $line['COG'];
560
+				$data['latitude'] = $line['LAT'];
561
+				$data['longitude'] = $line['LNG'];
562
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
563
+				$data['imo'] = $line['IMO'];
564
+				//$data['arrival_code'] = $ais_data['destination'];
565
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
566
+				$data['format_source'] = 'myshiptracking';
567
+				$data['id_source'] = $id_source;
568
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
569
+				$MI->add($data);
570
+				unset($data);
571
+			}
571 572
 			}
572
-		    }
573 573
 		}
574
-	    }
575
-	    $last_exec[$id]['last'] = time();
574
+		}
575
+		$last_exec[$id]['last'] = time();
576 576
 	} elseif ($value['format'] == 'boatbeaconapp' && 
577
-	    (
577
+		(
578 578
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
579 579
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
580
-	    )
580
+		)
581 581
 	) {
582
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
583
-	    if ($buffer != '') {
582
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
583
+		if ($buffer != '') {
584 584
 		$all_data = json_decode($buffer,true);
585 585
 		if (isset($all_data[0]['mmsi'])) {
586
-		    foreach ($all_data as $line) {
586
+			foreach ($all_data as $line) {
587 587
 			if ($line != '') {
588
-			    $data = array();
589
-			    $data['ident'] = $line['shipname'];
590
-			    $data['callsign'] = $line['callsign'];
591
-			    $data['mmsi'] = $line['mmsi'];
592
-			    $data['speed'] = $line['sog'];
593
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
594
-			    $data['latitude'] = $line['latitude'];
595
-			    $data['longitude'] = $line['longitude'];
596
-			    $data['type_id'] = $line['shiptype'];
597
-			    $data['arrival_code'] = $line['destination'];
598
-			    $data['datetime'] = $line['time'];
599
-			    $data['format_source'] = 'boatbeaconapp';
600
-			    $data['id_source'] = $id_source;
601
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
602
-			    $MI->add($data);
603
-			    unset($data);
588
+				$data = array();
589
+				$data['ident'] = $line['shipname'];
590
+				$data['callsign'] = $line['callsign'];
591
+				$data['mmsi'] = $line['mmsi'];
592
+				$data['speed'] = $line['sog'];
593
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
594
+				$data['latitude'] = $line['latitude'];
595
+				$data['longitude'] = $line['longitude'];
596
+				$data['type_id'] = $line['shiptype'];
597
+				$data['arrival_code'] = $line['destination'];
598
+				$data['datetime'] = $line['time'];
599
+				$data['format_source'] = 'boatbeaconapp';
600
+				$data['id_source'] = $id_source;
601
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
602
+				$MI->add($data);
603
+				unset($data);
604
+			}
604 605
 			}
605
-		    }
606 606
 		}
607 607
 		
608
-	    }
609
-    	    $last_exec[$id]['last'] = time();
608
+		}
609
+			$last_exec[$id]['last'] = time();
610 610
 	} elseif ($value['format'] == 'boatnerd' && 
611
-	    (
611
+		(
612 612
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
613 613
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
614
-	    )
614
+		)
615 615
 	) {
616
-	    $buffer = $Common->getData($value['host']);
617
-	    if ($buffer != '') {
616
+		$buffer = $Common->getData($value['host']);
617
+		if ($buffer != '') {
618 618
 		$all_data = json_decode($buffer,true);
619 619
 		if (isset($all_data['features'][0]['id'])) {
620
-		    foreach ($all_data['features'] as $line) {
620
+			foreach ($all_data['features'] as $line) {
621 621
 			$data = array();
622 622
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
623 623
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
@@ -636,78 +636,78 @@  discard block
 block discarded – undo
636 636
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
637 637
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
638 638
 			unset($data);
639
-		    }
639
+			}
640 640
 		}
641 641
 		
642
-	    }
643
-    	    $last_exec[$id]['last'] = time();
642
+		}
643
+			$last_exec[$id]['last'] = time();
644 644
 	} elseif ($value['format'] == 'shipplotter' && 
645
-	    (
645
+		(
646 646
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
647 647
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
648
-	    )
648
+		)
649 649
 	) {
650
-	    echo 'download...';
651
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
652
-	    echo 'done !'."\n";
653
-	    if ($buffer != '') $reset = 0;
654
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
655
-	    $buffer = explode('\n',$buffer);
656
-	    foreach ($buffer as $line) {
650
+		echo 'download...';
651
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
652
+		echo 'done !'."\n";
653
+		if ($buffer != '') $reset = 0;
654
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
655
+		$buffer = explode('\n',$buffer);
656
+		foreach ($buffer as $line) {
657 657
 		if ($line != '') {
658
-		    $data = array();
659
-		    $data['mmsi'] = (int)substr($line,0,9);
660
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
661
-		    //$data['status'] = substr($line,21,2);
662
-		    //$data['type'] = substr($line,24,3);
663
-		    $data['latitude'] = substr($line,29,9);
664
-		    $data['longitude'] = substr($line,41,9);
665
-		    $data['speed'] = round(substr($line,51,5));
666
-		    //$data['course'] = substr($line,57,5);
667
-		    $data['heading'] = round(substr($line,63,3));
668
-		    //$data['draft'] = substr($line,67,4);
669
-		    //$data['length'] = substr($line,72,3);
670
-		    //$data['beam'] = substr($line,76,2);
671
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
672
-		    //$data['callsign'] = trim(substr($line,100,7);
673
-		    //$data['dest'] = substr($line,108,20);
674
-		    //$data['etaDate'] = substr($line,129,5);
675
-		    //$data['etaTime'] = substr($line,135,5);
676
-		    $data['format_source'] = 'shipplotter';
677
-    		    $data['id_source'] = $id_source;
678
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
679
-		    //print_r($data);
680
-		    echo 'Add...'."\n";
681
-		    $MI->add($data);
682
-		    unset($data);
658
+			$data = array();
659
+			$data['mmsi'] = (int)substr($line,0,9);
660
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
661
+			//$data['status'] = substr($line,21,2);
662
+			//$data['type'] = substr($line,24,3);
663
+			$data['latitude'] = substr($line,29,9);
664
+			$data['longitude'] = substr($line,41,9);
665
+			$data['speed'] = round(substr($line,51,5));
666
+			//$data['course'] = substr($line,57,5);
667
+			$data['heading'] = round(substr($line,63,3));
668
+			//$data['draft'] = substr($line,67,4);
669
+			//$data['length'] = substr($line,72,3);
670
+			//$data['beam'] = substr($line,76,2);
671
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
672
+			//$data['callsign'] = trim(substr($line,100,7);
673
+			//$data['dest'] = substr($line,108,20);
674
+			//$data['etaDate'] = substr($line,129,5);
675
+			//$data['etaTime'] = substr($line,135,5);
676
+			$data['format_source'] = 'shipplotter';
677
+				$data['id_source'] = $id_source;
678
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
679
+			//print_r($data);
680
+			echo 'Add...'."\n";
681
+			$MI->add($data);
682
+			unset($data);
683 683
 		}
684
-    	    }
685
-    	    $last_exec[$id]['last'] = time();
684
+			}
685
+			$last_exec[$id]['last'] = time();
686 686
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
687 687
 	} elseif (
688
-	    (
688
+		(
689 689
 		$value['format'] == 'whazzup' && 
690 690
 		(
691
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
692
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
691
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
692
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
693 693
 		)
694
-	    ) || (
694
+		) || (
695 695
 		$value['format'] == 'vatsimtxt' && 
696 696
 		(
697
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
698
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
697
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
698
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
699
+		)
699 700
 		)
700
-	    )
701 701
 	) {
702
-	    //$buffer = $Common->getData($hosts[$id]);
703
-	    $buffer = $Common->getData($value['host']);
704
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
705
-	    $buffer = explode('\n',$buffer);
706
-	    $reset = 0;
707
-	    foreach ($buffer as $line) {
708
-    		if ($line != '') {
709
-    		    $line = explode(':', $line);
710
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
702
+		//$buffer = $Common->getData($hosts[$id]);
703
+		$buffer = $Common->getData($value['host']);
704
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
705
+		$buffer = explode('\n',$buffer);
706
+		$reset = 0;
707
+		foreach ($buffer as $line) {
708
+			if ($line != '') {
709
+				$line = explode(':', $line);
710
+				if (count($line) > 30 && $line[0] != 'callsign') {
711 711
 			$data = array();
712 712
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
713 713
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -720,37 +720,37 @@  discard block
 block discarded – undo
720 720
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
721 721
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
722 722
 			$data['latitude'] = $line[5]; // lat
723
-	        	$data['longitude'] = $line[6]; // long
724
-	        	$data['verticalrate'] = ''; // vertical rate
725
-	        	$data['squawk'] = ''; // squawk
726
-	        	$data['emergency'] = ''; // emergency
727
-	        	$data['waypoints'] = $line[30];
723
+				$data['longitude'] = $line[6]; // long
724
+				$data['verticalrate'] = ''; // vertical rate
725
+				$data['squawk'] = ''; // squawk
726
+				$data['emergency'] = ''; // emergency
727
+				$data['waypoints'] = $line[30];
728 728
 			$data['datetime'] = date('Y-m-d H:i:s');
729 729
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
730 730
 			//if (isset($line[37])) $data['last_update'] = $line[37];
731
-		        $data['departure_airport_icao'] = $line[11];
732
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
733
-		        $data['arrival_airport_icao'] = $line[13];
731
+				$data['departure_airport_icao'] = $line[11];
732
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
733
+				$data['arrival_airport_icao'] = $line[13];
734 734
 			$data['frequency'] = $line[4];
735 735
 			$data['type'] = $line[18];
736 736
 			$data['range'] = $line[19];
737 737
 			if (isset($line[35])) $data['info'] = $line[35];
738
-    			$data['id_source'] = $id_source;
739
-	    		//$data['arrival_airport_time'] = ;
740
-	    		if ($line[9] != '') {
741
-	    		    $aircraft_data = explode('/',$line[9]);
742
-	    		    if (isset($aircraft_data[1])) {
743
-	    			$data['aircraft_icao'] = $aircraft_data[1];
744
-	    		    }
745
-        		}
746
-	    		/*
738
+				$data['id_source'] = $id_source;
739
+				//$data['arrival_airport_time'] = ;
740
+				if ($line[9] != '') {
741
+					$aircraft_data = explode('/',$line[9]);
742
+					if (isset($aircraft_data[1])) {
743
+					$data['aircraft_icao'] = $aircraft_data[1];
744
+					}
745
+				}
746
+				/*
747 747
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
748 748
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
749 749
 	    		*/
750
-	    		$data['format_source'] = $value['format'];
750
+				$data['format_source'] = $value['format'];
751 751
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
752 752
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
753
-    			if ($line[3] == 'PILOT') $SI->add($data);
753
+				if ($line[3] == 'PILOT') $SI->add($data);
754 754
 			elseif ($line[3] == 'ATC') {
755 755
 				//print_r($data);
756 756
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -771,21 +771,21 @@  discard block
 block discarded – undo
771 771
 					else 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']);
772 772
 				}
773 773
 			}
774
-    			unset($data);
775
-    		    }
776
-    		}
777
-    	    }
778
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
779
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
780
-    	    $last_exec[$id]['last'] = time();
781
-    	} elseif ($value['format'] == 'airwhere' && 
782
-    	    (
783
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
784
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
785
-    	    )
786
-    	) {
787
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
788
-	    if ($buffer != '') {
774
+				unset($data);
775
+				}
776
+			}
777
+			}
778
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
779
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
780
+			$last_exec[$id]['last'] = time();
781
+		} elseif ($value['format'] == 'airwhere' && 
782
+			(
783
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
784
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
785
+			)
786
+		) {
787
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
788
+		if ($buffer != '') {
789 789
 		$all_data = simplexml_load_string($buffer);
790 790
 		foreach($all_data->children() as $childdata) {
791 791
 			$data = array();
@@ -807,10 +807,10 @@  discard block
 block discarded – undo
807 807
 			$SI->add($data);
808 808
 			unset($data);
809 809
 		}
810
-	    }
811
-	    $Source->deleteOldLocationByType('gs');
812
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
813
-	    if ($buffer != '') {
810
+		}
811
+		$Source->deleteOldLocationByType('gs');
812
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
813
+		if ($buffer != '') {
814 814
 		$all_data = simplexml_load_string($buffer);
815 815
 		foreach($all_data->children() as $childdata) {
816 816
 			$data = array();
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
 			}
829 829
 			unset($data);
830 830
 		}
831
-	    }
832
-	    $last_exec[$id]['last'] = time();
831
+		}
832
+		$last_exec[$id]['last'] = time();
833 833
 	/*
834 834
 	} if ($value['format'] == 'aircraftlistjson') {
835 835
 	    print_r($globalSources);
@@ -837,17 +837,17 @@  discard block
 block discarded – undo
837 837
 	    echo $globalMinFetch;
838 838
 	*/
839 839
 	} elseif ($value['format'] == 'aircraftlistjson' && 
840
-	    (
840
+		(
841 841
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
842 842
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
843
-	    )
843
+		)
844 844
 	) {
845
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
846
-	    if ($buffer != '') {
847
-	        $all_data = json_decode($buffer,true);
845
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
846
+		if ($buffer != '') {
847
+			$all_data = json_decode($buffer,true);
848 848
 		if (isset($all_data['acList'])) {
849
-		    $reset = 0;
850
-		    foreach ($all_data['acList'] as $line) {
849
+			$reset = 0;
850
+			foreach ($all_data['acList'] as $line) {
851 851
 			$data = array();
852 852
 			$data['hex'] = $line['Icao']; // hex
853 853
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -870,10 +870,10 @@  discard block
 block discarded – undo
870 870
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
871 871
 			if (isset($data['latitude'])) $SI->add($data);
872 872
 			unset($data);
873
-		    }
873
+			}
874 874
 		} elseif (is_array($all_data)) {
875
-		    $reset = 0;
876
-		    foreach ($all_data as $line) {
875
+			$reset = 0;
876
+			foreach ($all_data as $line) {
877 877
 			$data = array();
878 878
 			$data['hex'] = $line['hex']; // hex
879 879
 			$data['ident'] = $line['flight']; // ident
@@ -893,218 +893,218 @@  discard block
 block discarded – undo
893 893
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
894 894
 			$SI->add($data);
895 895
 			unset($data);
896
-		    }
896
+			}
897 897
 		}
898
-	    } elseif ($globalDebug) echo 'No data'."\n";
899
-    	    //$last_exec['aircraftlistjson'] = time();
900
-    	    $last_exec[$id]['last'] = time();
901
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
902
-    	} elseif ($value['format'] == 'planeupdatefaa' && 
903
-    	    (
904
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
905
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
906
-    	    )
907
-    	) {
908
-	    $buffer = $Common->getData($value['host']);
909
-	    $all_data = json_decode($buffer,true);
910
-	    if (isset($all_data['planes'])) {
898
+		} elseif ($globalDebug) echo 'No data'."\n";
899
+			//$last_exec['aircraftlistjson'] = time();
900
+			$last_exec[$id]['last'] = time();
901
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
902
+		} elseif ($value['format'] == 'planeupdatefaa' && 
903
+			(
904
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
905
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
906
+			)
907
+		) {
908
+		$buffer = $Common->getData($value['host']);
909
+		$all_data = json_decode($buffer,true);
910
+		if (isset($all_data['planes'])) {
911 911
 		$reset = 0;
912 912
 		foreach ($all_data['planes'] as $key => $line) {
913
-		    $data = array();
914
-		    $data['hex'] = $key; // hex
915
-		    $data['ident'] = $line[3]; // ident
916
-		    $data['altitude'] = $line[6]; // altitude
917
-		    $data['speed'] = $line[8]; // speed
918
-		    $data['heading'] = $line[7]; // heading
919
-		    $data['latitude'] = $line[4]; // lat
920
-		    $data['longitude'] = $line[5]; // long
921
-		    //$data['verticalrate'] = $line[]; // verticale rate
922
-		    $data['squawk'] = $line[10]; // squawk
923
-		    $data['emergency'] = ''; // emergency
924
-		    $data['registration'] = $line[2];
925
-		    $data['aircraft_icao'] = $line[0];
926
-		    $deparr = explode('-',$line[1]);
927
-		    if (count($deparr) == 2) {
913
+			$data = array();
914
+			$data['hex'] = $key; // hex
915
+			$data['ident'] = $line[3]; // ident
916
+			$data['altitude'] = $line[6]; // altitude
917
+			$data['speed'] = $line[8]; // speed
918
+			$data['heading'] = $line[7]; // heading
919
+			$data['latitude'] = $line[4]; // lat
920
+			$data['longitude'] = $line[5]; // long
921
+			//$data['verticalrate'] = $line[]; // verticale rate
922
+			$data['squawk'] = $line[10]; // squawk
923
+			$data['emergency'] = ''; // emergency
924
+			$data['registration'] = $line[2];
925
+			$data['aircraft_icao'] = $line[0];
926
+			$deparr = explode('-',$line[1]);
927
+			if (count($deparr) == 2) {
928 928
 			$data['departure_airport_icao'] = $deparr[0];
929 929
 			$data['arrival_airport_icao'] = $deparr[1];
930
-		    }
931
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
932
-	    	    $data['format_source'] = 'planeupdatefaa';
933
-    		    $data['id_source'] = $id_source;
934
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
935
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
936
-		    $SI->add($data);
937
-		    unset($data);
930
+			}
931
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
932
+				$data['format_source'] = 'planeupdatefaa';
933
+				$data['id_source'] = $id_source;
934
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
935
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
936
+			$SI->add($data);
937
+			unset($data);
938
+		}
938 939
 		}
939
-	    }
940
-	    //$last_exec['planeupdatefaa'] = time();
941
-	    $last_exec[$id]['last'] = time();
940
+		//$last_exec['planeupdatefaa'] = time();
941
+		$last_exec[$id]['last'] = time();
942 942
 	} elseif ($value['format'] == 'opensky' && 
943
-	    (
943
+		(
944 944
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
945 945
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
946
-	    )
946
+		)
947 947
 	) {
948
-	    $buffer = $Common->getData($value['host']);
949
-	    $all_data = json_decode($buffer,true);
950
-	    if (isset($all_data['states'])) {
948
+		$buffer = $Common->getData($value['host']);
949
+		$all_data = json_decode($buffer,true);
950
+		if (isset($all_data['states'])) {
951 951
 		$reset = 0;
952 952
 		foreach ($all_data['states'] as $key => $line) {
953
-		    $data = array();
954
-		    $data['hex'] = $line[0]; // hex
955
-		    $data['ident'] = trim($line[1]); // ident
956
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
957
-		    $data['speed'] = round($line[9]*1.94384); // speed
958
-		    $data['heading'] = round($line[10]); // heading
959
-		    $data['latitude'] = $line[6]; // lat
960
-		    $data['longitude'] = $line[5]; // long
961
-		    $data['verticalrate'] = $line[11]; // verticale rate
962
-		    //$data['squawk'] = $line[10]; // squawk
963
-		    //$data['emergency'] = ''; // emergency
964
-		    //$data['registration'] = $line[2];
965
-		    //$data['aircraft_icao'] = $line[0];
966
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
967
-		    $data['format_source'] = 'opensky';
968
-		    $data['id_source'] = $id_source;
969
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
970
-		    $SI->add($data);
971
-		    unset($data);
953
+			$data = array();
954
+			$data['hex'] = $line[0]; // hex
955
+			$data['ident'] = trim($line[1]); // ident
956
+			$data['altitude'] = round($line[7]*3.28084); // altitude
957
+			$data['speed'] = round($line[9]*1.94384); // speed
958
+			$data['heading'] = round($line[10]); // heading
959
+			$data['latitude'] = $line[6]; // lat
960
+			$data['longitude'] = $line[5]; // long
961
+			$data['verticalrate'] = $line[11]; // verticale rate
962
+			//$data['squawk'] = $line[10]; // squawk
963
+			//$data['emergency'] = ''; // emergency
964
+			//$data['registration'] = $line[2];
965
+			//$data['aircraft_icao'] = $line[0];
966
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
967
+			$data['format_source'] = 'opensky';
968
+			$data['id_source'] = $id_source;
969
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
970
+			$SI->add($data);
971
+			unset($data);
972 972
 		}
973
-	    }
974
-	    //$last_exec['planeupdatefaa'] = time();
975
-	    $last_exec[$id]['last'] = time();
973
+		}
974
+		//$last_exec['planeupdatefaa'] = time();
975
+		$last_exec[$id]['last'] = time();
976 976
 	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
977 977
 	} elseif ($value['format'] == 'fr24json' && 
978
-	    (
978
+		(
979 979
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
980 980
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
981
-	    )
981
+		)
982 982
 	) {
983
-	    //$buffer = $Common->getData($hosts[$id]);
984
-	    $buffer = $Common->getData($value['host']);
985
-	    $all_data = json_decode($buffer,true);
986
-	    if (!empty($all_data)) $reset = 0;
987
-	    foreach ($all_data as $key => $line) {
983
+		//$buffer = $Common->getData($hosts[$id]);
984
+		$buffer = $Common->getData($value['host']);
985
+		$all_data = json_decode($buffer,true);
986
+		if (!empty($all_data)) $reset = 0;
987
+		foreach ($all_data as $key => $line) {
988 988
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
989
-		    $data = array();
990
-		    $data['hex'] = $line[0];
991
-		    $data['ident'] = $line[16]; //$line[13]
992
-	    	    $data['altitude'] = $line[4]; // altitude
993
-	    	    $data['speed'] = $line[5]; // speed
994
-	    	    $data['heading'] = $line[3]; // heading
995
-	    	    $data['latitude'] = $line[1]; // lat
996
-	    	    $data['longitude'] = $line[2]; // long
997
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
998
-	    	    $data['squawk'] = $line[6]; // squawk
999
-	    	    $data['aircraft_icao'] = $line[8];
1000
-	    	    $data['registration'] = $line[9];
1001
-		    $data['departure_airport_iata'] = $line[11];
1002
-		    $data['arrival_airport_iata'] = $line[12];
1003
-	    	    $data['emergency'] = ''; // emergency
1004
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1005
-	    	    $data['format_source'] = 'fr24json';
1006
-    		    $data['id_source'] = $id_source;
1007
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1008
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1009
-		    $SI->add($data);
1010
-		    unset($data);
989
+			$data = array();
990
+			$data['hex'] = $line[0];
991
+			$data['ident'] = $line[16]; //$line[13]
992
+				$data['altitude'] = $line[4]; // altitude
993
+				$data['speed'] = $line[5]; // speed
994
+				$data['heading'] = $line[3]; // heading
995
+				$data['latitude'] = $line[1]; // lat
996
+				$data['longitude'] = $line[2]; // long
997
+				$data['verticalrate'] = $line[15]; // verticale rate
998
+				$data['squawk'] = $line[6]; // squawk
999
+				$data['aircraft_icao'] = $line[8];
1000
+				$data['registration'] = $line[9];
1001
+			$data['departure_airport_iata'] = $line[11];
1002
+			$data['arrival_airport_iata'] = $line[12];
1003
+				$data['emergency'] = ''; // emergency
1004
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1005
+				$data['format_source'] = 'fr24json';
1006
+				$data['id_source'] = $id_source;
1007
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1008
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1009
+			$SI->add($data);
1010
+			unset($data);
1011 1011
 		}
1012
-	    }
1013
-	    //$last_exec['fr24json'] = time();
1014
-	    $last_exec[$id]['last'] = time();
1012
+		}
1013
+		//$last_exec['fr24json'] = time();
1014
+		$last_exec[$id]['last'] = time();
1015 1015
 	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1016 1016
 	} elseif ($value['format'] == 'radarvirtueljson' && 
1017
-	    (
1017
+		(
1018 1018
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1019 1019
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1020
-	    )
1020
+		)
1021 1021
 	) {
1022
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1023
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1024
-	    //echo $buffer;
1025
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1026
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1027
-	    $all_data = json_decode($buffer,true);
1028
-	    if (json_last_error() != JSON_ERROR_NONE) {
1022
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1023
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1024
+		//echo $buffer;
1025
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1026
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1027
+		$all_data = json_decode($buffer,true);
1028
+		if (json_last_error() != JSON_ERROR_NONE) {
1029 1029
 		die(json_last_error_msg());
1030
-	    }
1031
-	    if (isset($all_data['mrkrs'])) {
1030
+		}
1031
+		if (isset($all_data['mrkrs'])) {
1032 1032
 		$reset = 0;
1033 1033
 		foreach ($all_data['mrkrs'] as $key => $line) {
1034
-		    if (isset($line['inf'])) {
1034
+			if (isset($line['inf'])) {
1035 1035
 			$data = array();
1036 1036
 			$data['hex'] = $line['inf']['ia'];
1037 1037
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1038
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1039
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1040
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1041
-	    		$data['latitude'] = $line['pt'][0]; // lat
1042
-	    		$data['longitude'] = $line['pt'][1]; // long
1043
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1044
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1045
-	    		//$data['aircraft_icao'] = $line[8];
1046
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1038
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1039
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1040
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1041
+				$data['latitude'] = $line['pt'][0]; // lat
1042
+				$data['longitude'] = $line['pt'][1]; // long
1043
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1044
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1045
+				//$data['aircraft_icao'] = $line[8];
1046
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1047 1047
 			//$data['departure_airport_iata'] = $line[11];
1048 1048
 			//$data['arrival_airport_iata'] = $line[12];
1049
-	    		//$data['emergency'] = ''; // emergency
1049
+				//$data['emergency'] = ''; // emergency
1050 1050
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1051
-	    		$data['format_source'] = 'radarvirtueljson';
1052
-    			$data['id_source'] = $id_source;
1051
+				$data['format_source'] = 'radarvirtueljson';
1052
+				$data['id_source'] = $id_source;
1053 1053
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1054 1054
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1055 1055
 			$SI->add($data);
1056 1056
 			unset($data);
1057
-		    }
1057
+			}
1058
+		}
1058 1059
 		}
1059
-	    }
1060
-	    //$last_exec['radarvirtueljson'] = time();
1061
-	    $last_exec[$id]['last'] = time();
1060
+		//$last_exec['radarvirtueljson'] = time();
1061
+		$last_exec[$id]['last'] = time();
1062 1062
 	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1063 1063
 	} elseif ($value['format'] == 'pirepsjson' && 
1064
-	    (
1064
+		(
1065 1065
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1066 1066
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1067
-	    )
1067
+		)
1068 1068
 	) {
1069
-	    //$buffer = $Common->getData($hosts[$id]);
1070
-	    $buffer = $Common->getData($value['host'].'?'.time());
1071
-	    $all_data = json_decode(utf8_encode($buffer),true);
1069
+		//$buffer = $Common->getData($hosts[$id]);
1070
+		$buffer = $Common->getData($value['host'].'?'.time());
1071
+		$all_data = json_decode(utf8_encode($buffer),true);
1072 1072
 	    
1073
-	    if (isset($all_data['pireps'])) {
1073
+		if (isset($all_data['pireps'])) {
1074 1074
 		$reset = 0;
1075
-	        foreach ($all_data['pireps'] as $line) {
1076
-		    $data = array();
1077
-		    $data['id'] = $line['id'];
1078
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1079
-		    $data['ident'] = $line['callsign']; // ident
1080
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1081
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1082
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1083
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1084
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1085
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1086
-		    $data['latitude'] = $line['lat']; // lat
1087
-		    $data['longitude'] = $line['lon']; // long
1088
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1089
-		    //$data['squawk'] = $line['squawk']; // squawk
1090
-		    //$data['emergency'] = ''; // emergency
1091
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1092
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1093
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1094
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1095
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1096
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1097
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1098
-		    else $data['info'] = '';
1099
-		    $data['format_source'] = 'pireps';
1100
-    		    $data['id_source'] = $id_source;
1101
-		    $data['datetime'] = date('Y-m-d H:i:s');
1102
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1103
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1104
-		    if ($line['icon'] == 'plane') {
1075
+			foreach ($all_data['pireps'] as $line) {
1076
+			$data = array();
1077
+			$data['id'] = $line['id'];
1078
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1079
+			$data['ident'] = $line['callsign']; // ident
1080
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1081
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1082
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1083
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1084
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1085
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1086
+			$data['latitude'] = $line['lat']; // lat
1087
+			$data['longitude'] = $line['lon']; // long
1088
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1089
+			//$data['squawk'] = $line['squawk']; // squawk
1090
+			//$data['emergency'] = ''; // emergency
1091
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1092
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1093
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1094
+			//$data['arrival_airport_time'] = $line['arrtime'];
1095
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1096
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1097
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1098
+			else $data['info'] = '';
1099
+			$data['format_source'] = 'pireps';
1100
+				$data['id_source'] = $id_source;
1101
+			$data['datetime'] = date('Y-m-d H:i:s');
1102
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1103
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1104
+			if ($line['icon'] == 'plane') {
1105 1105
 			$SI->add($data);
1106
-		    //    print_r($data);
1107
-    		    } elseif ($line['icon'] == 'ct') {
1106
+			//    print_r($data);
1107
+				} elseif ($line['icon'] == 'ct') {
1108 1108
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1109 1109
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1110 1110
 			$typec = substr($data['ident'],-3);
@@ -1119,148 +1119,148 @@  discard block
 block discarded – undo
1119 1119
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1120 1120
 			else $data['type'] = 'Observer';
1121 1121
 			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']);
1122
-		    }
1123
-		    unset($data);
1122
+			}
1123
+			unset($data);
1124
+		}
1124 1125
 		}
1125
-	    }
1126
-	    //$last_exec['pirepsjson'] = time();
1127
-	    $last_exec[$id]['last'] = time();
1126
+		//$last_exec['pirepsjson'] = time();
1127
+		$last_exec[$id]['last'] = time();
1128 1128
 	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1129 1129
 	} elseif ($value['format'] == 'phpvmacars' && 
1130
-	    (
1130
+		(
1131 1131
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1132 1132
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1133
-	    )
1133
+		)
1134 1134
 	) {
1135
-	    //$buffer = $Common->getData($hosts[$id]);
1136
-	    if ($globalDebug) echo 'Get Data...'."\n";
1137
-	    $buffer = $Common->getData($value['host']);
1138
-	    $all_data = json_decode($buffer,true);
1139
-	    if ($buffer != '' && is_array($all_data)) {
1135
+		//$buffer = $Common->getData($hosts[$id]);
1136
+		if ($globalDebug) echo 'Get Data...'."\n";
1137
+		$buffer = $Common->getData($value['host']);
1138
+		$all_data = json_decode($buffer,true);
1139
+		if ($buffer != '' && is_array($all_data)) {
1140 1140
 		$reset = 0;
1141 1141
 		foreach ($all_data as $line) {
1142
-	    	    $data = array();
1143
-	    	    //$data['id'] = $line['id']; // id not usable
1144
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1145
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1146
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1147
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1148
-	    	    $data['ident'] = $line['flightnum']; // ident
1149
-	    	    $data['altitude'] = $line['alt']; // altitude
1150
-	    	    $data['speed'] = $line['gs']; // speed
1151
-	    	    $data['heading'] = $line['heading']; // heading
1152
-	    	    $data['latitude'] = $line['lat']; // lat
1153
-	    	    $data['longitude'] = $line['lng']; // long
1154
-	    	    $data['verticalrate'] = ''; // verticale rate
1155
-	    	    $data['squawk'] = ''; // squawk
1156
-	    	    $data['emergency'] = ''; // emergency
1157
-	    	    //$data['datetime'] = $line['lastupdate'];
1158
-	    	    //$data['last_update'] = $line['lastupdate'];
1159
-	    	    if (isset($value['timezone'])) {
1160
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1161
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1162
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1163
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1164
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1165
-	    	    $data['departure_airport_time'] = $line['deptime'];
1166
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1167
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1168
-    		    $data['registration'] = $line['aircraft'];
1169
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1170
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1171
-		    if (isset($line['aircraftname'])) {
1142
+				$data = array();
1143
+				//$data['id'] = $line['id']; // id not usable
1144
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1145
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1146
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1147
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1148
+				$data['ident'] = $line['flightnum']; // ident
1149
+				$data['altitude'] = $line['alt']; // altitude
1150
+				$data['speed'] = $line['gs']; // speed
1151
+				$data['heading'] = $line['heading']; // heading
1152
+				$data['latitude'] = $line['lat']; // lat
1153
+				$data['longitude'] = $line['lng']; // long
1154
+				$data['verticalrate'] = ''; // verticale rate
1155
+				$data['squawk'] = ''; // squawk
1156
+				$data['emergency'] = ''; // emergency
1157
+				//$data['datetime'] = $line['lastupdate'];
1158
+				//$data['last_update'] = $line['lastupdate'];
1159
+				if (isset($value['timezone'])) {
1160
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1161
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1162
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1163
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1164
+				$data['departure_airport_icao'] = $line['depicao'];
1165
+				$data['departure_airport_time'] = $line['deptime'];
1166
+				$data['arrival_airport_icao'] = $line['arricao'];
1167
+				$data['arrival_airport_time'] = $line['arrtime'];
1168
+				$data['registration'] = $line['aircraft'];
1169
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1170
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1171
+			if (isset($line['aircraftname'])) {
1172 1172
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1173 1173
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1174
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1175
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1176
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1177
-	    		else {
1178
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1179
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1180
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1181
-	    		}
1182
-	    	    }
1183
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1184
-    		    $data['id_source'] = $id_source;
1185
-	    	    $data['format_source'] = 'phpvmacars';
1186
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1187
-		    $SI->add($data);
1188
-		    unset($data);
1174
+				$aircraft_data = explode('-',$line['aircraftname']);
1175
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1176
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1177
+				else {
1178
+					$aircraft_data = explode(' ',$line['aircraftname']);
1179
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1180
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1181
+				}
1182
+				}
1183
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1184
+				$data['id_source'] = $id_source;
1185
+				$data['format_source'] = 'phpvmacars';
1186
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1187
+			$SI->add($data);
1188
+			unset($data);
1189 1189
 		}
1190 1190
 		if ($globalDebug) echo 'No more data...'."\n";
1191 1191
 		unset($buffer);
1192 1192
 		unset($all_data);
1193
-	    }
1194
-	    //$last_exec['phpvmacars'] = time();
1195
-	    $last_exec[$id]['last'] = time();
1193
+		}
1194
+		//$last_exec['phpvmacars'] = time();
1195
+		$last_exec[$id]['last'] = time();
1196 1196
 	} elseif ($value['format'] == 'vam' && 
1197
-	    (
1197
+		(
1198 1198
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1199 1199
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1200
-	    )
1200
+		)
1201 1201
 	) {
1202
-	    //$buffer = $Common->getData($hosts[$id]);
1203
-	    if ($globalDebug) echo 'Get Data...'."\n";
1204
-	    $buffer = $Common->getData($value['host']);
1205
-	    $all_data = json_decode($buffer,true);
1206
-	    if ($buffer != '' && is_array($all_data)) {
1202
+		//$buffer = $Common->getData($hosts[$id]);
1203
+		if ($globalDebug) echo 'Get Data...'."\n";
1204
+		$buffer = $Common->getData($value['host']);
1205
+		$all_data = json_decode($buffer,true);
1206
+		if ($buffer != '' && is_array($all_data)) {
1207 1207
 		$reset = 0;
1208 1208
 		foreach ($all_data as $line) {
1209
-	    	    $data = array();
1210
-	    	    //$data['id'] = $line['id']; // id not usable
1211
-	    	    $data['id'] = trim($line['flight_id']);
1212
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1213
-	    	    $data['pilot_name'] = $line['pilot_name'];
1214
-	    	    $data['pilot_id'] = $line['pilot_id'];
1215
-	    	    $data['ident'] = trim($line['callsign']); // ident
1216
-	    	    $data['altitude'] = $line['altitude']; // altitude
1217
-	    	    $data['speed'] = $line['gs']; // speed
1218
-	    	    $data['heading'] = $line['heading']; // heading
1219
-	    	    $data['latitude'] = $line['latitude']; // lat
1220
-	    	    $data['longitude'] = $line['longitude']; // long
1221
-	    	    $data['verticalrate'] = ''; // verticale rate
1222
-	    	    $data['squawk'] = ''; // squawk
1223
-	    	    $data['emergency'] = ''; // emergency
1224
-	    	    //$data['datetime'] = $line['lastupdate'];
1225
-	    	    $data['last_update'] = $line['last_update'];
1226
-		    $data['datetime'] = date('Y-m-d H:i:s');
1227
-	    	    $data['departure_airport_icao'] = $line['departure'];
1228
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1229
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1230
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1231
-    		    //$data['registration'] = $line['aircraft'];
1232
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1233
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1234
-    		    $data['id_source'] = $id_source;
1235
-	    	    $data['format_source'] = 'vam';
1236
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1237
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1238
-		    $SI->add($data);
1239
-		    unset($data);
1209
+				$data = array();
1210
+				//$data['id'] = $line['id']; // id not usable
1211
+				$data['id'] = trim($line['flight_id']);
1212
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1213
+				$data['pilot_name'] = $line['pilot_name'];
1214
+				$data['pilot_id'] = $line['pilot_id'];
1215
+				$data['ident'] = trim($line['callsign']); // ident
1216
+				$data['altitude'] = $line['altitude']; // altitude
1217
+				$data['speed'] = $line['gs']; // speed
1218
+				$data['heading'] = $line['heading']; // heading
1219
+				$data['latitude'] = $line['latitude']; // lat
1220
+				$data['longitude'] = $line['longitude']; // long
1221
+				$data['verticalrate'] = ''; // verticale rate
1222
+				$data['squawk'] = ''; // squawk
1223
+				$data['emergency'] = ''; // emergency
1224
+				//$data['datetime'] = $line['lastupdate'];
1225
+				$data['last_update'] = $line['last_update'];
1226
+			$data['datetime'] = date('Y-m-d H:i:s');
1227
+				$data['departure_airport_icao'] = $line['departure'];
1228
+				//$data['departure_airport_time'] = $line['departure_time'];
1229
+				$data['arrival_airport_icao'] = $line['arrival'];
1230
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1231
+				//$data['registration'] = $line['aircraft'];
1232
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1233
+				$data['aircraft_icao'] = $line['plane_type'];
1234
+				$data['id_source'] = $id_source;
1235
+				$data['format_source'] = 'vam';
1236
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1237
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1238
+			$SI->add($data);
1239
+			unset($data);
1240 1240
 		}
1241 1241
 		if ($globalDebug) echo 'No more data...'."\n";
1242 1242
 		unset($buffer);
1243 1243
 		unset($all_data);
1244
-	    }
1245
-	    //$last_exec['phpvmacars'] = time();
1246
-	    $last_exec[$id]['last'] = time();
1244
+		}
1245
+		//$last_exec['phpvmacars'] = time();
1246
+		$last_exec[$id]['last'] = time();
1247 1247
 	} elseif ($value['format'] == 'blitzortung' && 
1248
-	    (
1248
+		(
1249 1249
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1250 1250
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1251
-	    )
1251
+		)
1252 1252
 	) {
1253
-	    //$buffer = $Common->getData($hosts[$id]);
1254
-	    if ($globalDebug) echo 'Get Data...'."\n";
1255
-	    $buffer = $Common->getData($value['host']);
1256
-	    $all_data = json_decode($buffer,true);
1257
-	    if ($buffer != '') {
1253
+		//$buffer = $Common->getData($hosts[$id]);
1254
+		if ($globalDebug) echo 'Get Data...'."\n";
1255
+		$buffer = $Common->getData($value['host']);
1256
+		$all_data = json_decode($buffer,true);
1257
+		if ($buffer != '') {
1258 1258
 		$Source->deleteLocationBySource('blitzortung');
1259 1259
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1260 1260
 		$buffer = explode('\n',$buffer);
1261 1261
 		foreach ($buffer as $buffer_line) {
1262
-		    $line = json_decode($buffer_line,true);
1263
-		    if (isset($line['time'])) {
1262
+			$line = json_decode($buffer_line,true);
1263
+			if (isset($line['time'])) {
1264 1264
 			$data = array();
1265 1265
 			$data['altitude'] = $line['alt']; // altitude
1266 1266
 			$data['latitude'] = $line['lat']; // lat
@@ -1272,94 +1272,94 @@  discard block
 block discarded – undo
1272 1272
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1273 1273
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1274 1274
 			unset($data);
1275
-		    }
1275
+			}
1276 1276
 		}
1277 1277
 		if ($globalDebug) echo 'No more data...'."\n";
1278 1278
 		unset($buffer);
1279
-	    }
1280
-	    $last_exec[$id]['last'] = time();
1279
+		}
1280
+		$last_exec[$id]['last'] = time();
1281 1281
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1282 1282
 	} 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') {
1283
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1284
-    	    //$last_exec[$id]['last'] = time();
1283
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1284
+			//$last_exec[$id]['last'] = time();
1285 1285
 
1286
-	    //$read = array( $sockets[$id] );
1287
-	    $read = $sockets;
1288
-	    $write = NULL;
1289
-	    $e = NULL;
1290
-	    $n = socket_select($read, $write, $e, $timeout);
1291
-	    if ($e != NULL) var_dump($e);
1292
-	    if ($n > 0) {
1286
+		//$read = array( $sockets[$id] );
1287
+		$read = $sockets;
1288
+		$write = NULL;
1289
+		$e = NULL;
1290
+		$n = socket_select($read, $write, $e, $timeout);
1291
+		if ($e != NULL) var_dump($e);
1292
+		if ($n > 0) {
1293 1293
 		$reset = 0;
1294 1294
 		foreach ($read as $nb => $r) {
1295
-		    //$value = $formats[$nb];
1296
-		    $format = $globalSources[$nb]['format'];
1297
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1295
+			//$value = $formats[$nb];
1296
+			$format = $globalSources[$nb]['format'];
1297
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1298 1298
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1299
-		    } elseif ($format == 'vrstcp') {
1299
+			} elseif ($format == 'vrstcp') {
1300 1300
 			$buffer = @socket_read($r, 6000);
1301
-		    } else {
1301
+			} else {
1302 1302
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1303
-		    }
1304
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1305
-		    //echo $buffer."\n";
1306
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1307
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1308
-		    $error = false;
1309
-		    //$SI::del();
1310
-		    if ($format == 'vrstcp') {
1303
+			}
1304
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1305
+			//echo $buffer."\n";
1306
+			// lets play nice and handle signals such as ctrl-c/kill properly
1307
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1308
+			$error = false;
1309
+			//$SI::del();
1310
+			if ($format == 'vrstcp') {
1311 1311
 			$buffer = explode('},{',$buffer);
1312
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1313
-		    // SBS format is CSV format
1314
-		    if ($buffer !== FALSE && $buffer != '') {
1312
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1313
+			// SBS format is CSV format
1314
+			if ($buffer !== FALSE && $buffer != '') {
1315 1315
 			$tt[$format] = 0;
1316 1316
 			if ($format == 'acarssbs3') {
1317
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1318
-			    $ACARS->add(trim($buffer));
1319
-			    $ACARS->deleteLiveAcarsData();
1317
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1318
+				$ACARS->add(trim($buffer));
1319
+				$ACARS->deleteLiveAcarsData();
1320 1320
 			} elseif ($format == 'raw') {
1321
-			    // AVR format
1322
-			    $data = $SBS->parse($buffer);
1323
-			    if (is_array($data)) {
1321
+				// AVR format
1322
+				$data = $SBS->parse($buffer);
1323
+				if (is_array($data)) {
1324 1324
 				$data['datetime'] = date('Y-m-d H:i:s');
1325 1325
 				$data['format_source'] = 'raw';
1326 1326
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1327 1327
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1328 1328
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1329 1329
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1330
-			    }
1330
+				}
1331 1331
 			} elseif ($format == 'ais') {
1332
-			    $ais_data = $AIS->parse_line(trim($buffer));
1333
-			    $data = array();
1334
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1335
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1336
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1337
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1338
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1339
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1340
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1341
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1342
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1343
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1344
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1345
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1346
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1347
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1348
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1349
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1332
+				$ais_data = $AIS->parse_line(trim($buffer));
1333
+				$data = array();
1334
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1335
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1336
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1337
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1338
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1339
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1340
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1341
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1342
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1343
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1344
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1345
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1346
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1347
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1348
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1349
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1350 1350
 
1351
-			    if (isset($ais_data['timestamp'])) {
1351
+				if (isset($ais_data['timestamp'])) {
1352 1352
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1353
-			    } else {
1353
+				} else {
1354 1354
 				$data['datetime'] = date('Y-m-d H:i:s');
1355
-			    }
1356
-			    $data['format_source'] = 'aisnmea';
1357
-    			    $data['id_source'] = $id_source;
1358
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1359
-			    unset($data);
1360
-                        } elseif ($format == 'flightgearsp') {
1361
-                    	    //echo $buffer."\n";
1362
-                    	    if (strlen($buffer) > 5) {
1355
+				}
1356
+				$data['format_source'] = 'aisnmea';
1357
+					$data['id_source'] = $id_source;
1358
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1359
+				unset($data);
1360
+						} elseif ($format == 'flightgearsp') {
1361
+							//echo $buffer."\n";
1362
+							if (strlen($buffer) > 5) {
1363 1363
 				$line = explode(',',$buffer);
1364 1364
 				$data = array();
1365 1365
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1376,38 +1376,38 @@  discard block
 block discarded – undo
1376 1376
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1377 1377
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1378 1378
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1379
-			    }
1380
-                        } elseif ($format == 'acars') {
1381
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1382
-			    $ACARS->add(trim($buffer));
1383
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1384
-			    $ACARS->deleteLiveAcarsData();
1379
+				}
1380
+						} elseif ($format == 'acars') {
1381
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1382
+				$ACARS->add(trim($buffer));
1383
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1384
+				$ACARS->deleteLiveAcarsData();
1385 1385
 			} elseif ($format == 'flightgearmp') {
1386
-			    if (substr($buffer,0,1) != '#') {
1386
+				if (substr($buffer,0,1) != '#') {
1387 1387
 				$data = array();
1388 1388
 				//echo $buffer."\n";
1389 1389
 				$line = explode(' ',$buffer);
1390 1390
 				if (count($line) == 11) {
1391
-				    $userserver = explode('@',$line[0]);
1392
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1393
-				    $data['ident'] = $userserver[0];
1394
-				    $data['registration'] = $userserver[0];
1395
-				    $data['latitude'] = $line[4];
1396
-				    $data['longitude'] = $line[5];
1397
-				    $data['altitude'] = $line[6];
1398
-				    $data['datetime'] = date('Y-m-d H:i:s');
1399
-				    $aircraft_type = $line[10];
1400
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1401
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1402
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1391
+					$userserver = explode('@',$line[0]);
1392
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1393
+					$data['ident'] = $userserver[0];
1394
+					$data['registration'] = $userserver[0];
1395
+					$data['latitude'] = $line[4];
1396
+					$data['longitude'] = $line[5];
1397
+					$data['altitude'] = $line[6];
1398
+					$data['datetime'] = date('Y-m-d H:i:s');
1399
+					$aircraft_type = $line[10];
1400
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1401
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1402
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1404
+				}
1404 1405
 				}
1405
-			    }
1406 1406
 			} elseif ($format == 'beast') {
1407
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1408
-			    die;
1407
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1408
+				die;
1409 1409
 			} elseif ($format == 'vrstcp') {
1410
-			    foreach($buffer as $all_data) {
1410
+				foreach($buffer as $all_data) {
1411 1411
 				$line = json_decode('{'.$all_data.'}',true);
1412 1412
 				$data = array();
1413 1413
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1427,151 +1427,151 @@  discard block
 block discarded – undo
1427 1427
 				*/
1428 1428
 				$data['datetime'] = date('Y-m-d H:i:s');
1429 1429
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1430
-		    		$data['format_source'] = 'vrstcp';
1430
+					$data['format_source'] = 'vrstcp';
1431 1431
 				$data['id_source'] = $id_source;
1432 1432
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1433 1433
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1434 1434
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1435 1435
 				unset($data);
1436
-			    }
1436
+				}
1437 1437
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1438
-			    $line = explode("\t", $buffer);
1439
-			    for($k = 0; $k < count($line); $k=$k+2) {
1438
+				$line = explode("\t", $buffer);
1439
+				for($k = 0; $k < count($line); $k=$k+2) {
1440 1440
 				$key = $line[$k];
1441
-			        $lined[$key] = $line[$k+1];
1442
-			    }
1443
-    			    if (count($lined) > 3) {
1444
-    				$data['hex'] = $lined['hexid'];
1445
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1446
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1447
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1448
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1449
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1450
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1451
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1452
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1453
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1454
-    				$data['id_source'] = $id_source;
1455
-    				$data['format_source'] = 'tsv';
1456
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1457
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1441
+					$lined[$key] = $line[$k+1];
1442
+				}
1443
+					if (count($lined) > 3) {
1444
+					$data['hex'] = $lined['hexid'];
1445
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1446
+					$data['datetime'] = date('Y-m-d H:i:s');;
1447
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1448
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1449
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1450
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1451
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1452
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1453
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1454
+					$data['id_source'] = $id_source;
1455
+					$data['format_source'] = 'tsv';
1456
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1457
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1458 1458
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1459
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1460
-    				unset($lined);
1461
-    				unset($data);
1462
-    			    } else $error = true;
1459
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1460
+					unset($lined);
1461
+					unset($data);
1462
+					} else $error = true;
1463 1463
 			} elseif ($format == 'aprs' && $use_aprs) {
1464
-			    if ($aprs_connect == 0) {
1464
+				if ($aprs_connect == 0) {
1465 1465
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1466 1466
 				$aprs_connect = 1;
1467
-			    }
1467
+				}
1468 1468
 			    
1469
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1469
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1470 1470
 				$aprs_last_tx = time();
1471 1471
 				$data_aprs = "# Keep alive";
1472 1472
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1473
-			    }
1473
+				}
1474 1474
 			    
1475
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1476
-			    //echo 'APRS data : '.$buffer."\n";
1477
-			    $buffer = str_replace('APRS <- ','',$buffer);
1478
-			    $buffer = str_replace('APRS -> ','',$buffer);
1479
-			    //echo $buffer."\n";
1480
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1475
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1476
+				//echo 'APRS data : '.$buffer."\n";
1477
+				$buffer = str_replace('APRS <- ','',$buffer);
1478
+				$buffer = str_replace('APRS -> ','',$buffer);
1479
+				//echo $buffer."\n";
1480
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1481 1481
 				$line = $APRS->parse($buffer);
1482 1482
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1483 1483
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1484
-				    $aprs_last_tx = time();
1485
-				    $data = array();
1486
-				    //print_r($line);
1487
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1488
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1489
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1490
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1491
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1492
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1493
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1494
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1495
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1496
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1497
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1498
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1499
-				    $data['latitude'] = $line['latitude'];
1500
-				    $data['longitude'] = $line['longitude'];
1501
-				    //$data['verticalrate'] = $line[16];
1502
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1503
-				    //else $data['speed'] = 0;
1504
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1505
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1506
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1507
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1484
+					$aprs_last_tx = time();
1485
+					$data = array();
1486
+					//print_r($line);
1487
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1488
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1489
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1490
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1491
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1492
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1493
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1494
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1495
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1496
+					else $data['datetime'] = date('Y-m-d H:i:s');
1497
+					//$data['datetime'] = date('Y-m-d H:i:s');
1498
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1499
+					$data['latitude'] = $line['latitude'];
1500
+					$data['longitude'] = $line['longitude'];
1501
+					//$data['verticalrate'] = $line[16];
1502
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1503
+					//else $data['speed'] = 0;
1504
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1505
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1506
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1507
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1508 1508
 				    
1509
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1510
-				    //else echo 'No heading...'."\n";
1511
-				    //else $data['heading'] = 0;
1512
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1513
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1514
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1515
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1516
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1517
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1518
-    				    $data['id_source'] = $id_source;
1519
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1520
-				    else $data['format_source'] = 'aprs';
1521
-				    $data['source_name'] = $line['source'];
1522
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1523
-				    else $data['source_type'] = 'flarm';
1524
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1525
-				    $currentdate = date('Y-m-d H:i:s');
1526
-				    $aprsdate = strtotime($data['datetime']);
1527
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1528
-				    // Accept data if time <= system time + 20s
1529
-				    //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'])))) {
1530
-				    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'])))) {
1509
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1510
+					//else echo 'No heading...'."\n";
1511
+					//else $data['heading'] = 0;
1512
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1513
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1514
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1515
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1516
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1517
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1518
+						$data['id_source'] = $id_source;
1519
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1520
+					else $data['format_source'] = 'aprs';
1521
+					$data['source_name'] = $line['source'];
1522
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1523
+					else $data['source_type'] = 'flarm';
1524
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1525
+					$currentdate = date('Y-m-d H:i:s');
1526
+					$aprsdate = strtotime($data['datetime']);
1527
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1528
+					// Accept data if time <= system time + 20s
1529
+					//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'])))) {
1530
+					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'])))) {
1531 1531
 					$send = $SI->add($data);
1532
-				    } elseif ($data['source_type'] == 'ais') {
1532
+					} elseif ($data['source_type'] == 'ais') {
1533 1533
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1534
-				    } elseif (isset($line['stealth'])) {
1534
+					} elseif (isset($line['stealth'])) {
1535 1535
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1536 1536
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1537
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1538
-					    //$line['symbol'] == 'Balloon' ||
1539
-					    $line['symbol'] == 'Glider' || 
1540
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1541
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1542
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1543
-					    $send = $SI->add($data);
1544
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1545
-					    $line['symbol'] == 'Yacht (Sail)' || 
1546
-					    $line['symbol'] == 'Ship (Power Boat)')) {
1547
-					    $send = $MI->add($data);
1548
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1549
-					    $line['symbol'] == 'Car' || 
1550
-					    $line['symbol'] == 'Ambulance' || 
1551
-					    $line['symbol'] == 'Van' || 
1552
-					    $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1553
-					    $line['symbol'] == 'Motorcycle' || 
1554
-					    $line['symbol'] == 'Tractor' || 
1555
-					    $line['symbol'] == 'Police' || 
1556
-					    $line['symbol'] == 'Bike' || 
1557
-					    $line['symbol'] == 'Jogger' || 
1558
-					    $line['symbol'] == 'Horse' || 
1559
-					    $line['symbol'] == 'Bus' || 
1560
-					    $line['symbol'] == 'Jeep' || 
1561
-					    $line['symbol'] == 'Recreational Vehicle' || 
1562
-					    $line['symbol'] == 'Yacht (Sail)' || 
1563
-					    $line['symbol'] == 'Ship (Power Boat)' || 
1564
-					    $line['symbol'] == 'Firetruck' || 
1565
-					    $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1566
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1567
-					    $line['symbol'] == 'SUV' ||
1568
-					    $line['symbol'] == 'Snowmobile' ||
1569
-					    $line['symbol'] == 'Mobile Satellite Station')) {
1570
-				    //} 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') {
1537
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1538
+						//$line['symbol'] == 'Balloon' ||
1539
+						$line['symbol'] == 'Glider' || 
1540
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1541
+						if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1542
+						if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1543
+						$send = $SI->add($data);
1544
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1545
+						$line['symbol'] == 'Yacht (Sail)' || 
1546
+						$line['symbol'] == 'Ship (Power Boat)')) {
1547
+						$send = $MI->add($data);
1548
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1549
+						$line['symbol'] == 'Car' || 
1550
+						$line['symbol'] == 'Ambulance' || 
1551
+						$line['symbol'] == 'Van' || 
1552
+						$line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1553
+						$line['symbol'] == 'Motorcycle' || 
1554
+						$line['symbol'] == 'Tractor' || 
1555
+						$line['symbol'] == 'Police' || 
1556
+						$line['symbol'] == 'Bike' || 
1557
+						$line['symbol'] == 'Jogger' || 
1558
+						$line['symbol'] == 'Horse' || 
1559
+						$line['symbol'] == 'Bus' || 
1560
+						$line['symbol'] == 'Jeep' || 
1561
+						$line['symbol'] == 'Recreational Vehicle' || 
1562
+						$line['symbol'] == 'Yacht (Sail)' || 
1563
+						$line['symbol'] == 'Ship (Power Boat)' || 
1564
+						$line['symbol'] == 'Firetruck' || 
1565
+						$line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1566
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1567
+						$line['symbol'] == 'SUV' ||
1568
+						$line['symbol'] == 'Snowmobile' ||
1569
+						$line['symbol'] == 'Mobile Satellite Station')) {
1570
+					//} 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') {
1571 1571
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $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') {
1572 1572
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1573 1573
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1574
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1574
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1575 1575
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1576 1576
 					$Source->deleteOldLocationByType('gs');
1577 1577
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
 					} else {
1580 1580
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1581 1581
 					}
1582
-				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1582
+					} elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1583 1583
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1584 1584
 					if ($globalDebug) echo '# Weather Station added'."\n";
1585 1585
 					$Source->deleteOldLocationByType('wx');
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
 					} else {
1590 1590
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1591 1591
 					}
1592
-				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1592
+					} elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1593 1593
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1594 1594
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1595 1595
 					$Source->deleteOldLocationByType('lightning');
@@ -1598,11 +1598,11 @@  discard block
 block discarded – undo
1598 1598
 					} else {
1599 1599
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1600 1600
 					}
1601
-				    } elseif ($globalDebug) {
1602
-				    	echo '/!\ Not added: '.$buffer."\n";
1603
-				    	print_r($line);
1604
-				    }
1605
-				    unset($data);
1601
+					} elseif ($globalDebug) {
1602
+						echo '/!\ Not added: '.$buffer."\n";
1603
+						print_r($line);
1604
+					}
1605
+					unset($data);
1606 1606
 				}
1607 1607
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1608 1608
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1621,12 +1621,12 @@  discard block
 block discarded – undo
1621 1621
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1622 1622
 					$globalSources[$nb]['last_weather_clean'] = time();
1623 1623
 				}
1624
-			    }
1624
+				}
1625 1625
 			} else {
1626
-			    $line = explode(',', $buffer);
1627
-    			    if (count($line) > 20) {
1628
-    			    	$data['hex'] = $line[4];
1629
-    				/*
1626
+				$line = explode(',', $buffer);
1627
+					if (count($line) > 20) {
1628
+						$data['hex'] = $line[4];
1629
+					/*
1630 1630
     				$data['datetime'] = $line[6].' '.$line[7];
1631 1631
     					date_default_timezone_set($globalTimezone);
1632 1632
     					$datetime = new DateTime($data['datetime']);
@@ -1634,30 +1634,30 @@  discard block
 block discarded – undo
1634 1634
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1635 1635
     					date_default_timezone_set('UTC');
1636 1636
     				*/
1637
-    				// Force datetime to current UTC datetime
1638
-    				date_default_timezone_set('UTC');
1639
-    				$data['datetime'] = date('Y-m-d H:i:s');
1640
-    				$data['ident'] = trim($line[10]);
1641
-    				$data['latitude'] = $line[14];
1642
-    				$data['longitude'] = $line[15];
1643
-    				$data['verticalrate'] = $line[16];
1644
-    				$data['emergency'] = $line[20];
1645
-    				$data['speed'] = $line[12];
1646
-    				$data['squawk'] = $line[17];
1647
-    				$data['altitude'] = $line[11];
1648
-    				$data['heading'] = $line[13];
1649
-    				$data['ground'] = $line[21];
1650
-    				$data['emergency'] = $line[19];
1651
-    				$data['format_source'] = 'sbs';
1637
+					// Force datetime to current UTC datetime
1638
+					date_default_timezone_set('UTC');
1639
+					$data['datetime'] = date('Y-m-d H:i:s');
1640
+					$data['ident'] = trim($line[10]);
1641
+					$data['latitude'] = $line[14];
1642
+					$data['longitude'] = $line[15];
1643
+					$data['verticalrate'] = $line[16];
1644
+					$data['emergency'] = $line[20];
1645
+					$data['speed'] = $line[12];
1646
+					$data['squawk'] = $line[17];
1647
+					$data['altitude'] = $line[11];
1648
+					$data['heading'] = $line[13];
1649
+					$data['ground'] = $line[21];
1650
+					$data['emergency'] = $line[19];
1651
+					$data['format_source'] = 'sbs';
1652 1652
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1653
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1653
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1654 1654
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1655
-    				$data['id_source'] = $id_source;
1656
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1657
-    				else $error = true;
1658
-    				unset($data);
1659
-    			    } else $error = true;
1660
-			    if ($error) {
1655
+					$data['id_source'] = $id_source;
1656
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1657
+					else $error = true;
1658
+					unset($data);
1659
+					} else $error = true;
1660
+				if ($error) {
1661 1661
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1662 1662
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1663 1663
 				} else {
@@ -1673,13 +1673,13 @@  discard block
 block discarded – undo
1673 1673
 					connect_all($sourceer);
1674 1674
 					$sourceer = array();
1675 1675
 				}
1676
-			    }
1676
+				}
1677 1677
 			}
1678 1678
 			// Sleep for xxx microseconds
1679 1679
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1680
-		    } else {
1680
+			} else {
1681 1681
 			if ($format == 'flightgearmp') {
1682
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1682
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1683 1683
 				//@socket_close($r);
1684 1684
 				sleep($globalMinFetch);
1685 1685
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1688,9 +1688,9 @@  discard block
 block discarded – undo
1688 1688
 				break;
1689 1689
 				
1690 1690
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1691
-			    if (isset($tt[$format])) $tt[$format]++;
1692
-			    else $tt[$format] = 0;
1693
-			    if ($tt[$format] > 30) {
1691
+				if (isset($tt[$format])) $tt[$format]++;
1692
+				else $tt[$format] = 0;
1693
+				if ($tt[$format] > 30) {
1694 1694
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1695 1695
 				//@socket_close($r);
1696 1696
 				sleep(2);
@@ -1701,23 +1701,23 @@  discard block
 block discarded – undo
1701 1701
 				//connect_all($globalSources);
1702 1702
 				$tt[$format]=0;
1703 1703
 				break;
1704
-			    }
1704
+				}
1705
+			}
1705 1706
 			}
1706
-		    }
1707 1707
 		}
1708
-	    } else {
1708
+		} else {
1709 1709
 		$error = socket_strerror(socket_last_error());
1710 1710
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1711 1711
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1712 1712
 			if (isset($globalDebug)) echo "Restarting...\n";
1713 1713
 			// Restart the script if possible
1714 1714
 			if (is_array($sockets)) {
1715
-			    if ($globalDebug) echo "Shutdown all sockets...";
1715
+				if ($globalDebug) echo "Shutdown all sockets...";
1716 1716
 			    
1717
-			    foreach ($sockets as $sock) {
1717
+				foreach ($sockets as $sock) {
1718 1718
 				@socket_shutdown($sock,2);
1719 1719
 				@socket_close($sock);
1720
-			    }
1720
+				}
1721 1721
 			    
1722 1722
 			}
1723 1723
 			if ($globalDebug) echo "Waiting...";
@@ -1732,15 +1732,15 @@  discard block
 block discarded – undo
1732 1732
 			if ($globalDebug) echo "Restart all connections...";
1733 1733
 			connect_all($globalSources);
1734 1734
 		}
1735
-	    }
1735
+		}
1736 1736
 	}
1737 1737
 	if ($globalDaemon === false) {
1738
-	    if ($globalDebug) echo 'Check all...'."\n";
1739
-	    if (isset($SI)) $SI->checkAll();
1740
-	    if (isset($TI)) $TI->checkAll();
1741
-	    if (isset($MI)) $MI->checkAll();
1738
+		if ($globalDebug) echo 'Check all...'."\n";
1739
+		if (isset($SI)) $SI->checkAll();
1740
+		if (isset($TI)) $TI->checkAll();
1741
+		if (isset($MI)) $MI->checkAll();
1742
+	}
1742 1743
 	}
1743
-    }
1744 1744
 }
1745 1745
 
1746 1746
 ?>
Please login to merge, or discard this patch.
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 else $id_source = 1;
90 90
 if (isset($globalServer) && $globalServer) {
91 91
     if ($globalDebug) echo "Using Server Mode\n";
92
-    $SI=new SpotterServer();
92
+    $SI = new SpotterServer();
93 93
 /*
94 94
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
95 95
     $SI = new adsb2aprs();
96 96
     $SI->connect();
97 97
 */
98
-} else $SI=new SpotterImport($Connection->db);
98
+} else $SI = new SpotterImport($Connection->db);
99 99
 
100 100
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
101 101
 if (isset($globalMarine) && $globalMarine) {
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
     $MI = new MarineImport($Connection->db);
110 110
 }
111 111
 //$APRS=new APRS($Connection->db);
112
-$SBS=new SBS();
113
-$ACARS=new ACARS($Connection->db,true);
114
-$Source=new Source($Connection->db);
115
-$Common=new Common();
112
+$SBS = new SBS();
113
+$ACARS = new ACARS($Connection->db, true);
114
+$Source = new Source($Connection->db);
115
+$Common = new Common();
116 116
 date_default_timezone_set('UTC');
117 117
 //$servertz = system('date +%Z');
118 118
 // signal handler - playing nice with sockets and dump1090
119 119
 if (function_exists('pcntl_fork')) {
120
-    pcntl_signal(SIGINT,  function() {
120
+    pcntl_signal(SIGINT, function() {
121 121
         global $sockets;
122 122
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
123 123
         die("Bye!\n");
@@ -133,30 +133,30 @@  discard block
 block discarded – undo
133 133
 
134 134
 function connect_all($hosts) {
135 135
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
136
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
136
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
137 137
     $reset++;
138 138
     if ($globalDebug) echo 'Connect to all...'."\n";
139 139
     foreach ($hosts as $id => $value) {
140 140
 	$host = $value['host'];
141 141
 	$globalSources[$id]['last_exec'] = 0;
142 142
 	// Here we check type of source(s)
143
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
144
-            if (preg_match('/deltadb.txt$/i',$host)) {
143
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
144
+            if (preg_match('/deltadb.txt$/i', $host)) {
145 145
         	//$formats[$id] = 'deltadbtxt';
146 146
         	$globalSources[$id]['format'] = 'deltadbtxt';
147 147
         	//$last_exec['deltadbtxt'] = 0;
148 148
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
149
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
149
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
150 150
         	//$formats[$id] = 'vatsimtxt';
151 151
         	$globalSources[$id]['format'] = 'vatsimtxt';
152 152
         	//$last_exec['vatsimtxt'] = 0;
153 153
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
154
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
154
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
155 155
         	//$formats[$id] = 'aircraftlistjson';
156 156
         	$globalSources[$id]['format'] = 'aircraftlistjson';
157 157
         	//$last_exec['aircraftlistjson'] = 0;
158 158
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
-    	    } else if (preg_match('/opensky/i',$host)) {
159
+    	    } else if (preg_match('/opensky/i', $host)) {
160 160
         	//$formats[$id] = 'aircraftlistjson';
161 161
         	$globalSources[$id]['format'] = 'opensky';
162 162
         	//$last_exec['aircraftlistjson'] = 0;
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         	    exit(0);
174 174
         	}
175 175
     	    */
176
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
176
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
177 177
         	//$formats[$id] = 'planeupdatefaa';
178 178
         	$globalSources[$id]['format'] = 'planeupdatefaa';
179 179
         	//$last_exec['planeupdatefaa'] = 0;
@@ -182,32 +182,32 @@  discard block
 block discarded – undo
182 182
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
183 183
         	    exit(0);
184 184
         	}
185
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
185
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
186 186
         	//$formats[$id] = 'phpvmacars';
187 187
         	$globalSources[$id]['format'] = 'phpvmacars';
188 188
         	//$last_exec['phpvmacars'] = 0;
189 189
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
190
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
190
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
191 191
         	//$formats[$id] = 'phpvmacars';
192 192
         	$globalSources[$id]['format'] = 'vam';
193 193
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
194
-            } else if (preg_match('/whazzup/i',$host)) {
194
+            } else if (preg_match('/whazzup/i', $host)) {
195 195
         	//$formats[$id] = 'whazzup';
196 196
         	$globalSources[$id]['format'] = 'whazzup';
197 197
         	//$last_exec['whazzup'] = 0;
198 198
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
199
-            } else if (preg_match('/blitzortung/i',$host)) {
199
+            } else if (preg_match('/blitzortung/i', $host)) {
200 200
         	$globalSources[$id]['format'] = 'blitzortung';
201 201
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
202
-            } else if (preg_match('/airwhere/i',$host)) {
202
+            } else if (preg_match('/airwhere/i', $host)) {
203 203
         	$globalSources[$id]['format'] = 'airwhere';
204 204
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
205
-            } else if (preg_match('/recentpireps/i',$host)) {
205
+            } else if (preg_match('/recentpireps/i', $host)) {
206 206
         	//$formats[$id] = 'pirepsjson';
207 207
         	$globalSources[$id]['format'] = 'pirepsjson';
208 208
         	//$last_exec['pirepsjson'] = 0;
209 209
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
210
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
210
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
211 211
         	//$formats[$id] = 'fr24json';
212 212
         	$globalSources[$id]['format'] = 'fr24json';
213 213
         	//$last_exec['fr24json'] = 0;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
217 217
         	    exit(0);
218 218
         	}
219
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
219
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
220 220
         	//$formats[$id] = 'fr24json';
221 221
         	$globalSources[$id]['format'] = 'myshiptracking';
222 222
         	//$last_exec['fr24json'] = 0;
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
         	    exit(0);
227 227
         	}
228 228
             //} else if (preg_match('/10001/',$host)) {
229
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
229
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
230 230
         	//$formats[$id] = 'tsv';
231 231
         	$globalSources[$id]['format'] = 'tsv';
232 232
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233 233
             }
234
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
234
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
235 235
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
236
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
236
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
237 237
     		    if ($idf !== false) {
238 238
     			$httpfeeds[$id] = $idf;
239 239
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
240 240
     		    }
241 241
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
242 242
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
243
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
244
-	    $hostport = explode(':',$host);
243
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
244
+	    $hostport = explode(':', $host);
245 245
 	    if (isset($hostport[1])) {
246 246
 		$port = $hostport[1];
247 247
 		$hostn = $hostport[0];
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
 	    }
252 252
 	    $Common = new Common();
253 253
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
254
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
254
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
255 255
     	    } else {
256
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
256
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
257 257
 	    }
258 258
 	    if ($s) {
259 259
     	        $sockets[$id] = $s;
260 260
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
261
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
261
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
262 262
 			//$formats[$id] = 'aprs';
263 263
 			$globalSources[$id]['format'] = 'aprs';
264 264
 			//$aprs_connect = 0;
265 265
 			//$use_aprs = true;
266
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
266
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
267 267
 			$globalSources[$id]['format'] = 'vrstcp';
268 268
     		    } elseif ($port == '10001') {
269 269
         		//$formats[$id] = 'tsv';
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
303 303
 else $timeout = 20;
304 304
 $errno = '';
305
-$errstr='';
305
+$errstr = '';
306 306
 
307 307
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
308 308
 /* Initiate connections to all the hosts simultaneously */
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 //connect_all($globalSources);
311 311
 
312 312
 if (isset($globalProxy) && $globalProxy) {
313
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
313
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
314 314
 } else {
315 315
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
316 316
 }
@@ -340,16 +340,16 @@  discard block
 block discarded – undo
340 340
 
341 341
 if ($use_aprs) {
342 342
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
343
-	$APRS=new APRS();
343
+	$APRS = new APRS();
344 344
 	$aprs_connect = 0;
345 345
 	$aprs_keep = 120;
346 346
 	$aprs_last_tx = time();
347 347
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
348
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
348
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
349 349
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
350
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
350
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
351 351
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
352
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
352
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
353 353
 	if ($aprs_full) $aprs_filter = '';
354 354
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
355 355
 	else $aprs_pass = '-1';
@@ -363,12 +363,12 @@  discard block
 block discarded – undo
363 363
 sleep(1);
364 364
 if ($globalDebug) echo "SCAN MODE \n\n";
365 365
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
366
-$endtime = time()+$globalCronEnd;
366
+$endtime = time() + $globalCronEnd;
367 367
 $i = 1;
368 368
 $tt = array();
369 369
 // Delete all ATC
370 370
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
371
-	$ATC=new ATC($Connection->db);
371
+	$ATC = new ATC($Connection->db);
372 372
 }
373 373
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
374 374
 	$ATC->deleteAll();
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 
377 377
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
378 378
 while ($i > 0) {
379
-    if (!$globalDaemon) $i = $endtime-time();
379
+    if (!$globalDaemon) $i = $endtime - time();
380 380
     // Delete old ATC
381 381
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
382 382
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	}
391 391
 	if ($max != $globalMinFetch) {
392 392
 	    if ($globalDebug) echo 'Sleeping...'."\n";
393
-	    sleep($globalMinFetch-$max+2);
393
+	    sleep($globalMinFetch - $max + 2);
394 394
 	}
395 395
     }
396 396
 
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	    //$buffer = $Common->getData($hosts[$id]);
410 410
 	    $buffer = $Common->getData($value['host']);
411 411
 	    if ($buffer != '') $reset = 0;
412
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
-	    $buffer = explode('\n',$buffer);
412
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
413
+	    $buffer = explode('\n', $buffer);
414 414
 	    foreach ($buffer as $line) {
415 415
     		if ($line != '' && count($line) > 7) {
416 416
     		    $line = explode(',', $line);
@@ -443,11 +443,11 @@  discard block
 block discarded – undo
443 443
 	    )
444 444
 	) {
445 445
 	    date_default_timezone_set('CET');
446
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
446
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
447 447
 	    date_default_timezone_set('UTC');
448 448
 	    if ($buffer != '') $reset = 0;
449
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
450
-	    $buffer = explode('\n',$buffer);
449
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
450
+	    $buffer = explode('\n', $buffer);
451 451
 	    foreach ($buffer as $line) {
452 452
 		if ($line != '') {
453 453
 		    //echo "'".$line."'\n";
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
466 466
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
467 467
 		    if (isset($ais_data['timestamp'])) {
468
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
468
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
469 469
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
470 470
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
471 471
 			    $add = true;
@@ -488,12 +488,12 @@  discard block
 block discarded – undo
488 488
 	    $w = $e = null;
489 489
 	    
490 490
 	    if (isset($arr[$id])) {
491
-		$nn = stream_select($arr,$w,$e,$timeout);
491
+		$nn = stream_select($arr, $w, $e, $timeout);
492 492
 		if ($nn > 0) {
493 493
 		    foreach ($httpfeeds as $feed) {
494
-			$buffer = stream_get_line($feed,2000,"\n");
495
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
496
-			$buffer = explode('\n',$buffer);
494
+			$buffer = stream_get_line($feed, 2000, "\n");
495
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
496
+			$buffer = explode('\n', $buffer);
497 497
 			foreach ($buffer as $line) {
498 498
 			    if ($line != '') {
499 499
 				$ais_data = $AIS->parse_line(trim($line));
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
512 512
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
513 513
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
514
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
514
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
515 515
 				if (isset($ais_data['timestamp'])) {
516
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
516
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
517 517
 				} else {
518 518
 				    $data['datetime'] = date('Y-m-d H:i:s');
519 519
 				}
@@ -544,10 +544,10 @@  discard block
 block discarded – undo
544 544
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
545 545
 	    )
546 546
 	) {
547
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
547
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
548 548
 	    if ($buffer != '') {
549 549
 		//echo $buffer;
550
-		$all_data = json_decode($buffer,true);
550
+		$all_data = json_decode($buffer, true);
551 551
 		//print_r($all_data);
552 552
 		if (isset($all_data[0]['DATA'])) {
553 553
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
563 563
 			    $data['imo'] = $line['IMO'];
564 564
 			    //$data['arrival_code'] = $ais_data['destination'];
565
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
565
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
566 566
 			    $data['format_source'] = 'myshiptracking';
567 567
 			    $data['id_source'] = $id_source;
568 568
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -579,9 +579,9 @@  discard block
 block discarded – undo
579 579
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
580 580
 	    )
581 581
 	) {
582
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
582
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
583 583
 	    if ($buffer != '') {
584
-		$all_data = json_decode($buffer,true);
584
+		$all_data = json_decode($buffer, true);
585 585
 		if (isset($all_data[0]['mmsi'])) {
586 586
 		    foreach ($all_data as $line) {
587 587
 			if ($line != '') {
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 	) {
616 616
 	    $buffer = $Common->getData($value['host']);
617 617
 	    if ($buffer != '') {
618
-		$all_data = json_decode($buffer,true);
618
+		$all_data = json_decode($buffer, true);
619 619
 		if (isset($all_data['features'][0]['id'])) {
620 620
 		    foreach ($all_data['features'] as $line) {
621 621
 			$data = array();
@@ -648,27 +648,27 @@  discard block
 block discarded – undo
648 648
 	    )
649 649
 	) {
650 650
 	    echo 'download...';
651
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
651
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
652 652
 	    echo 'done !'."\n";
653 653
 	    if ($buffer != '') $reset = 0;
654
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
655
-	    $buffer = explode('\n',$buffer);
654
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
655
+	    $buffer = explode('\n', $buffer);
656 656
 	    foreach ($buffer as $line) {
657 657
 		if ($line != '') {
658 658
 		    $data = array();
659
-		    $data['mmsi'] = (int)substr($line,0,9);
660
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
659
+		    $data['mmsi'] = (int) substr($line, 0, 9);
660
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
661 661
 		    //$data['status'] = substr($line,21,2);
662 662
 		    //$data['type'] = substr($line,24,3);
663
-		    $data['latitude'] = substr($line,29,9);
664
-		    $data['longitude'] = substr($line,41,9);
665
-		    $data['speed'] = round(substr($line,51,5));
663
+		    $data['latitude'] = substr($line, 29, 9);
664
+		    $data['longitude'] = substr($line, 41, 9);
665
+		    $data['speed'] = round(substr($line, 51, 5));
666 666
 		    //$data['course'] = substr($line,57,5);
667
-		    $data['heading'] = round(substr($line,63,3));
667
+		    $data['heading'] = round(substr($line, 63, 3));
668 668
 		    //$data['draft'] = substr($line,67,4);
669 669
 		    //$data['length'] = substr($line,72,3);
670 670
 		    //$data['beam'] = substr($line,76,2);
671
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
671
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
672 672
 		    //$data['callsign'] = trim(substr($line,100,7);
673 673
 		    //$data['dest'] = substr($line,108,20);
674 674
 		    //$data['etaDate'] = substr($line,129,5);
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	) {
702 702
 	    //$buffer = $Common->getData($hosts[$id]);
703 703
 	    $buffer = $Common->getData($value['host']);
704
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
705
-	    $buffer = explode('\n',$buffer);
704
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
705
+	    $buffer = explode('\n', $buffer);
706 706
 	    $reset = 0;
707 707
 	    foreach ($buffer as $line) {
708 708
     		if ($line != '') {
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
714 714
 			$data['pilot_id'] = $line[1];
715 715
 			$data['pilot_name'] = $line[2];
716
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
716
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
717 717
 			$data['ident'] = $line[0]; // ident
718 718
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
719 719
 			$data['speed'] = $line[8]; // speed
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
730 730
 			//if (isset($line[37])) $data['last_update'] = $line[37];
731 731
 		        $data['departure_airport_icao'] = $line[11];
732
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
732
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
733 733
 		        $data['arrival_airport_icao'] = $line[13];
734 734
 			$data['frequency'] = $line[4];
735 735
 			$data['type'] = $line[18];
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
     			$data['id_source'] = $id_source;
739 739
 	    		//$data['arrival_airport_time'] = ;
740 740
 	    		if ($line[9] != '') {
741
-	    		    $aircraft_data = explode('/',$line[9]);
741
+	    		    $aircraft_data = explode('/', $line[9]);
742 742
 	    		    if (isset($aircraft_data[1])) {
743 743
 	    			$data['aircraft_icao'] = $aircraft_data[1];
744 744
 	    		    }
@@ -753,9 +753,9 @@  discard block
 block discarded – undo
753 753
     			if ($line[3] == 'PILOT') $SI->add($data);
754 754
 			elseif ($line[3] == 'ATC') {
755 755
 				//print_r($data);
756
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
757
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
758
-				$typec = substr($data['ident'],-3);
756
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
757
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
758
+				$typec = substr($data['ident'], -3);
759 759
 				if ($typec == 'APP') $data['type'] = 'Approach';
760 760
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
761 761
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -767,8 +767,8 @@  discard block
 block discarded – undo
767 767
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
768 768
 				if (!isset($data['source_name'])) $data['source_name'] = '';
769 769
 				if (isset($ATC)) {
770
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
771
-					else 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']);
770
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($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']);
771
+					else 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']);
772 772
 				}
773 773
 			}
774 774
     			unset($data);
@@ -784,24 +784,24 @@  discard block
 block discarded – undo
784 784
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
785 785
     	    )
786 786
     	) {
787
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
787
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
788 788
 	    if ($buffer != '') {
789 789
 		$all_data = simplexml_load_string($buffer);
790
-		foreach($all_data->children() as $childdata) {
790
+		foreach ($all_data->children() as $childdata) {
791 791
 			$data = array();
792 792
 			$line = $childdata;
793 793
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
794
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
795
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
796
-			$data['latitude'] = (float)$line['pktLatitude'];
797
-			$data['longitude'] = (float)$line['pktLongitude'];
798
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
799
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
800
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
794
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
795
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
796
+			$data['latitude'] = (float) $line['pktLatitude'];
797
+			$data['longitude'] = (float) $line['pktLongitude'];
798
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
799
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
800
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
801 801
 			$data['altitude_relative'] = 'AMSL';
802
-			$data['pilot_id'] = (int)$line['pktPilotID'];
802
+			$data['pilot_id'] = (int) $line['pktPilotID'];
803 803
 			$data['aircraft_icao'] = 'PARAGLIDER';
804
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
804
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
805 805
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
806 806
 			$data['format_source'] = $value['format'];
807 807
 			$SI->add($data);
@@ -809,22 +809,22 @@  discard block
 block discarded – undo
809 809
 		}
810 810
 	    }
811 811
 	    $Source->deleteOldLocationByType('gs');
812
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
812
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
813 813
 	    if ($buffer != '') {
814 814
 		$all_data = simplexml_load_string($buffer);
815
-		foreach($all_data->children() as $childdata) {
815
+		foreach ($all_data->children() as $childdata) {
816 816
 			$data = array();
817 817
 			$line = $childdata;
818
-			$data['id'] = (int)$line['gsID'];
819
-			$data['latitude'] = (float)$line['gsLatitude'];
820
-			$data['longitude'] = (float)$line['gsLongitude'];
821
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
818
+			$data['id'] = (int) $line['gsID'];
819
+			$data['latitude'] = (float) $line['gsLatitude'];
820
+			$data['longitude'] = (float) $line['gsLongitude'];
821
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
822 822
 			$data['altitude_relative'] = 'AMSL';
823
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
823
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
824 824
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
825
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
825
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
826 826
 			} else {
827
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
827
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
828 828
 			}
829 829
 			unset($data);
830 830
 		}
@@ -842,9 +842,9 @@  discard block
 block discarded – undo
842 842
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
843 843
 	    )
844 844
 	) {
845
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
845
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
846 846
 	    if ($buffer != '') {
847
-	        $all_data = json_decode($buffer,true);
847
+	        $all_data = json_decode($buffer, true);
848 848
 		if (isset($all_data['acList'])) {
849 849
 		    $reset = 0;
850 850
 		    foreach ($all_data['acList'] as $line) {
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
861 861
 			$data['emergency'] = ''; // emergency
862 862
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
863
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
863
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
864 864
 			else $data['datetime'] = date('Y-m-d H:i:s');
865 865
 			//$data['datetime'] = date('Y-m-d H:i:s');
866 866
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 			$data['verticalrate'] = $line['vrt']; // verticale rate
886 886
 			$data['squawk'] = $line['squawk']; // squawk
887 887
 			$data['emergency'] = ''; // emergency
888
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
888
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
889 889
 			else $data['datetime'] = date('Y-m-d H:i:s');
890 890
 			$data['format_source'] = 'aircraftlistjson';
891 891
 			$data['id_source'] = $id_source;
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
     	    )
907 907
     	) {
908 908
 	    $buffer = $Common->getData($value['host']);
909
-	    $all_data = json_decode($buffer,true);
909
+	    $all_data = json_decode($buffer, true);
910 910
 	    if (isset($all_data['planes'])) {
911 911
 		$reset = 0;
912 912
 		foreach ($all_data['planes'] as $key => $line) {
@@ -923,12 +923,12 @@  discard block
 block discarded – undo
923 923
 		    $data['emergency'] = ''; // emergency
924 924
 		    $data['registration'] = $line[2];
925 925
 		    $data['aircraft_icao'] = $line[0];
926
-		    $deparr = explode('-',$line[1]);
926
+		    $deparr = explode('-', $line[1]);
927 927
 		    if (count($deparr) == 2) {
928 928
 			$data['departure_airport_icao'] = $deparr[0];
929 929
 			$data['arrival_airport_icao'] = $deparr[1];
930 930
 		    }
931
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
931
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
932 932
 	    	    $data['format_source'] = 'planeupdatefaa';
933 933
     		    $data['id_source'] = $id_source;
934 934
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 	    )
947 947
 	) {
948 948
 	    $buffer = $Common->getData($value['host']);
949
-	    $all_data = json_decode($buffer,true);
949
+	    $all_data = json_decode($buffer, true);
950 950
 	    if (isset($all_data['states'])) {
951 951
 		$reset = 0;
952 952
 		foreach ($all_data['states'] as $key => $line) {
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 		    //$data['emergency'] = ''; // emergency
964 964
 		    //$data['registration'] = $line[2];
965 965
 		    //$data['aircraft_icao'] = $line[0];
966
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
966
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
967 967
 		    $data['format_source'] = 'opensky';
968 968
 		    $data['id_source'] = $id_source;
969 969
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 	) {
983 983
 	    //$buffer = $Common->getData($hosts[$id]);
984 984
 	    $buffer = $Common->getData($value['host']);
985
-	    $all_data = json_decode($buffer,true);
985
+	    $all_data = json_decode($buffer, true);
986 986
 	    if (!empty($all_data)) $reset = 0;
987 987
 	    foreach ($all_data as $key => $line) {
988 988
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1020,11 +1020,11 @@  discard block
 block discarded – undo
1020 1020
 	    )
1021 1021
 	) {
1022 1022
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1023
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1023
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1024 1024
 	    //echo $buffer;
1025
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1026
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1027
-	    $all_data = json_decode($buffer,true);
1025
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1026
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1027
+	    $all_data = json_decode($buffer, true);
1028 1028
 	    if (json_last_error() != JSON_ERROR_NONE) {
1029 1029
 		die(json_last_error_msg());
1030 1030
 	    }
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 			//$data['departure_airport_iata'] = $line[11];
1048 1048
 			//$data['arrival_airport_iata'] = $line[12];
1049 1049
 	    		//$data['emergency'] = ''; // emergency
1050
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1050
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1051 1051
 	    		$data['format_source'] = 'radarvirtueljson';
1052 1052
     			$data['id_source'] = $id_source;
1053 1053
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1068,14 +1068,14 @@  discard block
 block discarded – undo
1068 1068
 	) {
1069 1069
 	    //$buffer = $Common->getData($hosts[$id]);
1070 1070
 	    $buffer = $Common->getData($value['host'].'?'.time());
1071
-	    $all_data = json_decode(utf8_encode($buffer),true);
1071
+	    $all_data = json_decode(utf8_encode($buffer), true);
1072 1072
 	    
1073 1073
 	    if (isset($all_data['pireps'])) {
1074 1074
 		$reset = 0;
1075 1075
 	        foreach ($all_data['pireps'] as $line) {
1076 1076
 		    $data = array();
1077 1077
 		    $data['id'] = $line['id'];
1078
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1078
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1079 1079
 		    $data['ident'] = $line['callsign']; // ident
1080 1080
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1081 1081
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1105,9 +1105,9 @@  discard block
 block discarded – undo
1105 1105
 			$SI->add($data);
1106 1106
 		    //    print_r($data);
1107 1107
     		    } elseif ($line['icon'] == 'ct') {
1108
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1109
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1110
-			$typec = substr($data['ident'],-3);
1108
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1109
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1110
+			$typec = substr($data['ident'], -3);
1111 1111
 			$data['type'] = '';
1112 1112
 			if ($typec == 'APP') $data['type'] = 'Approach';
1113 1113
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1119 1119
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1120 1120
 			else $data['type'] = 'Observer';
1121
-			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']);
1121
+			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']);
1122 1122
 		    }
1123 1123
 		    unset($data);
1124 1124
 		}
@@ -1135,14 +1135,14 @@  discard block
 block discarded – undo
1135 1135
 	    //$buffer = $Common->getData($hosts[$id]);
1136 1136
 	    if ($globalDebug) echo 'Get Data...'."\n";
1137 1137
 	    $buffer = $Common->getData($value['host']);
1138
-	    $all_data = json_decode($buffer,true);
1138
+	    $all_data = json_decode($buffer, true);
1139 1139
 	    if ($buffer != '' && is_array($all_data)) {
1140 1140
 		$reset = 0;
1141 1141
 		foreach ($all_data as $line) {
1142 1142
 	    	    $data = array();
1143 1143
 	    	    //$data['id'] = $line['id']; // id not usable
1144 1144
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1145
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1145
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1146 1146
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1147 1147
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1148 1148
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 	    	    //$data['datetime'] = $line['lastupdate'];
1158 1158
 	    	    //$data['last_update'] = $line['lastupdate'];
1159 1159
 	    	    if (isset($value['timezone'])) {
1160
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1160
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1161 1161
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1162 1162
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1163 1163
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1170,14 +1170,14 @@  discard block
 block discarded – undo
1170 1170
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1171 1171
 		    if (isset($line['aircraftname'])) {
1172 1172
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1173
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1174
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1173
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1174
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1175 1175
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1176 1176
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1177 1177
 	    		else {
1178
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1179
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1180
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1178
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1179
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1180
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1181 1181
 	    		}
1182 1182
 	    	    }
1183 1183
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1202,14 +1202,14 @@  discard block
 block discarded – undo
1202 1202
 	    //$buffer = $Common->getData($hosts[$id]);
1203 1203
 	    if ($globalDebug) echo 'Get Data...'."\n";
1204 1204
 	    $buffer = $Common->getData($value['host']);
1205
-	    $all_data = json_decode($buffer,true);
1205
+	    $all_data = json_decode($buffer, true);
1206 1206
 	    if ($buffer != '' && is_array($all_data)) {
1207 1207
 		$reset = 0;
1208 1208
 		foreach ($all_data as $line) {
1209 1209
 	    	    $data = array();
1210 1210
 	    	    //$data['id'] = $line['id']; // id not usable
1211 1211
 	    	    $data['id'] = trim($line['flight_id']);
1212
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1212
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1213 1213
 	    	    $data['pilot_name'] = $line['pilot_name'];
1214 1214
 	    	    $data['pilot_id'] = $line['pilot_id'];
1215 1215
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1253,24 +1253,24 @@  discard block
 block discarded – undo
1253 1253
 	    //$buffer = $Common->getData($hosts[$id]);
1254 1254
 	    if ($globalDebug) echo 'Get Data...'."\n";
1255 1255
 	    $buffer = $Common->getData($value['host']);
1256
-	    $all_data = json_decode($buffer,true);
1256
+	    $all_data = json_decode($buffer, true);
1257 1257
 	    if ($buffer != '') {
1258 1258
 		$Source->deleteLocationBySource('blitzortung');
1259
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1260
-		$buffer = explode('\n',$buffer);
1259
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1260
+		$buffer = explode('\n', $buffer);
1261 1261
 		foreach ($buffer as $buffer_line) {
1262
-		    $line = json_decode($buffer_line,true);
1262
+		    $line = json_decode($buffer_line, true);
1263 1263
 		    if (isset($line['time'])) {
1264 1264
 			$data = array();
1265 1265
 			$data['altitude'] = $line['alt']; // altitude
1266 1266
 			$data['latitude'] = $line['lat']; // lat
1267 1267
 			$data['longitude'] = $line['lon']; // long
1268
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1268
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1269 1269
 			$data['id_source'] = $id_source;
1270 1270
 			$data['format_source'] = 'blitzortung';
1271 1271
 			$SI->add($data);
1272 1272
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1273
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1273
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1274 1274
 			unset($data);
1275 1275
 		    }
1276 1276
 		}
@@ -1295,11 +1295,11 @@  discard block
 block discarded – undo
1295 1295
 		    //$value = $formats[$nb];
1296 1296
 		    $format = $globalSources[$nb]['format'];
1297 1297
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1298
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1298
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1299 1299
 		    } elseif ($format == 'vrstcp') {
1300 1300
 			$buffer = @socket_read($r, 6000);
1301 1301
 		    } else {
1302
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1302
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1303 1303
 		    }
1304 1304
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1305 1305
 		    //echo $buffer."\n";
@@ -1308,8 +1308,8 @@  discard block
 block discarded – undo
1308 1308
 		    $error = false;
1309 1309
 		    //$SI::del();
1310 1310
 		    if ($format == 'vrstcp') {
1311
-			$buffer = explode('},{',$buffer);
1312
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1311
+			$buffer = explode('},{', $buffer);
1312
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1313 1313
 		    // SBS format is CSV format
1314 1314
 		    if ($buffer !== FALSE && $buffer != '') {
1315 1315
 			$tt[$format] = 0;
@@ -1343,13 +1343,13 @@  discard block
 block discarded – undo
1343 1343
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1344 1344
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1345 1345
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1346
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1346
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1347 1347
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1348 1348
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1349 1349
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1350 1350
 
1351 1351
 			    if (isset($ais_data['timestamp'])) {
1352
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1352
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1353 1353
 			    } else {
1354 1354
 				$data['datetime'] = date('Y-m-d H:i:s');
1355 1355
 			    }
@@ -1360,10 +1360,10 @@  discard block
 block discarded – undo
1360 1360
                         } elseif ($format == 'flightgearsp') {
1361 1361
                     	    //echo $buffer."\n";
1362 1362
                     	    if (strlen($buffer) > 5) {
1363
-				$line = explode(',',$buffer);
1363
+				$line = explode(',', $buffer);
1364 1364
 				$data = array();
1365 1365
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1366
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1366
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1367 1367
 				$data['ident'] = $line[6];
1368 1368
 				$data['aircraft_name'] = $line[7];
1369 1369
 				$data['longitude'] = $line[1];
@@ -1380,16 +1380,16 @@  discard block
 block discarded – undo
1380 1380
                         } elseif ($format == 'acars') {
1381 1381
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1382 1382
 			    $ACARS->add(trim($buffer));
1383
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1383
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1384 1384
 			    $ACARS->deleteLiveAcarsData();
1385 1385
 			} elseif ($format == 'flightgearmp') {
1386
-			    if (substr($buffer,0,1) != '#') {
1386
+			    if (substr($buffer, 0, 1) != '#') {
1387 1387
 				$data = array();
1388 1388
 				//echo $buffer."\n";
1389
-				$line = explode(' ',$buffer);
1389
+				$line = explode(' ', $buffer);
1390 1390
 				if (count($line) == 11) {
1391
-				    $userserver = explode('@',$line[0]);
1392
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1391
+				    $userserver = explode('@', $line[0]);
1392
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1393 1393
 				    $data['ident'] = $userserver[0];
1394 1394
 				    $data['registration'] = $userserver[0];
1395 1395
 				    $data['latitude'] = $line[4];
@@ -1397,8 +1397,8 @@  discard block
 block discarded – undo
1397 1397
 				    $data['altitude'] = $line[6];
1398 1398
 				    $data['datetime'] = date('Y-m-d H:i:s');
1399 1399
 				    $aircraft_type = $line[10];
1400
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1401
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1400
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1401
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1402 1402
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403 1403
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1404 1404
 				}
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1408 1408
 			    die;
1409 1409
 			} elseif ($format == 'vrstcp') {
1410
-			    foreach($buffer as $all_data) {
1411
-				$line = json_decode('{'.$all_data.'}',true);
1410
+			    foreach ($buffer as $all_data) {
1411
+				$line = json_decode('{'.$all_data.'}', true);
1412 1412
 				$data = array();
1413 1413
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1414 1414
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1434,16 +1434,16 @@  discard block
 block discarded – undo
1434 1434
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1435 1435
 				unset($data);
1436 1436
 			    }
1437
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1437
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1438 1438
 			    $line = explode("\t", $buffer);
1439
-			    for($k = 0; $k < count($line); $k=$k+2) {
1439
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1440 1440
 				$key = $line[$k];
1441
-			        $lined[$key] = $line[$k+1];
1441
+			        $lined[$key] = $line[$k + 1];
1442 1442
 			    }
1443 1443
     			    if (count($lined) > 3) {
1444 1444
     				$data['hex'] = $lined['hexid'];
1445 1445
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1446
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1446
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1447 1447
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1448 1448
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1449 1449
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1462,22 +1462,22 @@  discard block
 block discarded – undo
1462 1462
     			    } else $error = true;
1463 1463
 			} elseif ($format == 'aprs' && $use_aprs) {
1464 1464
 			    if ($aprs_connect == 0) {
1465
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1465
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1466 1466
 				$aprs_connect = 1;
1467 1467
 			    }
1468 1468
 			    
1469
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1469
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1470 1470
 				$aprs_last_tx = time();
1471 1471
 				$data_aprs = "# Keep alive";
1472
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1472
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1473 1473
 			    }
1474 1474
 			    
1475 1475
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1476 1476
 			    //echo 'APRS data : '.$buffer."\n";
1477
-			    $buffer = str_replace('APRS <- ','',$buffer);
1478
-			    $buffer = str_replace('APRS -> ','',$buffer);
1477
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1478
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1479 1479
 			    //echo $buffer."\n";
1480
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1480
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1481 1481
 				$line = $APRS->parse($buffer);
1482 1482
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1483 1483
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
 				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1493 1493
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1494 1494
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1495
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1495
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1496 1496
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1497 1497
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1498 1498
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1574,29 +1574,29 @@  discard block
 block discarded – undo
1574 1574
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1575 1575
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1576 1576
 					$Source->deleteOldLocationByType('gs');
1577
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1578
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1577
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1578
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1579 1579
 					} else {
1580
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1580
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1581 1581
 					}
1582 1582
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1583 1583
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1584 1584
 					if ($globalDebug) echo '# Weather Station added'."\n";
1585 1585
 					$Source->deleteOldLocationByType('wx');
1586 1586
 					$weather_data = json_encode($line);
1587
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1588
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1587
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1588
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1589 1589
 					} else {
1590
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1590
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1591 1591
 					}
1592 1592
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1593 1593
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1594 1594
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1595 1595
 					$Source->deleteOldLocationByType('lightning');
1596
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1597
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1596
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1597
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1598 1598
 					} else {
1599
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1599
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1600 1600
 					}
1601 1601
 				    } elseif ($globalDebug) {
1602 1602
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1605,7 +1605,7 @@  discard block
 block discarded – undo
1605 1605
 				    unset($data);
1606 1606
 				}
1607 1607
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1608
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1608
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1609 1609
 				}
1610 1610
 				/*
1611 1611
 				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')) {
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
 				*/
1615 1615
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1616 1616
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1617
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1617
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1618 1618
 					$Source->deleteOldLocationByType('lightning');
1619 1619
 					$Source->deleteOldLocationByType('wx');
1620 1620
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1699,7 +1699,7 @@  discard block
 block discarded – undo
1699 1699
 				connect_all($sourceee);
1700 1700
 				$sourceee = array();
1701 1701
 				//connect_all($globalSources);
1702
-				$tt[$format]=0;
1702
+				$tt[$format] = 0;
1703 1703
 				break;
1704 1704
 			    }
1705 1705
 			}
@@ -1708,14 +1708,14 @@  discard block
 block discarded – undo
1708 1708
 	    } else {
1709 1709
 		$error = socket_strerror(socket_last_error());
1710 1710
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1711
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1711
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1712 1712
 			if (isset($globalDebug)) echo "Restarting...\n";
1713 1713
 			// Restart the script if possible
1714 1714
 			if (is_array($sockets)) {
1715 1715
 			    if ($globalDebug) echo "Shutdown all sockets...";
1716 1716
 			    
1717 1717
 			    foreach ($sockets as $sock) {
1718
-				@socket_shutdown($sock,2);
1718
+				@socket_shutdown($sock, 2);
1719 1719
 				@socket_close($sock);
1720 1720
 			    }
1721 1721
 			    
Please login to merge, or discard this patch.
Braces   +1049 added lines, -358 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,51 +63,92 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
77
-if (isset($options['enable-aircraft'])) $globalAircraft = TRUE; 
78
-if (isset($options['disable-aircraft'])) $globalAircraft = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
95
+if (isset($options['enable-aircraft'])) {
96
+	$globalAircraft = TRUE;
97
+}
98
+if (isset($options['disable-aircraft'])) {
99
+	$globalAircraft = FALSE;
100
+}
79 101
 if (isset($options['enable-tracker'])) {
80
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Enable Tracker mode'."\n";
104
+	}
81 105
 	$globalTracker = TRUE; 
82 106
 }
83
-if (isset($options['disable-tracker'])) $globalTracker = FALSE; 
84
-if (isset($options['enable-marine'])) $globalMarine = TRUE; 
85
-if (isset($options['disable-marine'])) $globalMarine = FALSE; 
86
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
87
-if (isset($options['server'])) $globalServer = TRUE;
88
-if (isset($options['idsource'])) $id_source = $options['idsource'];
89
-else $id_source = 1;
107
+if (isset($options['disable-tracker'])) {
108
+	$globalTracker = FALSE;
109
+}
110
+if (isset($options['enable-marine'])) {
111
+	$globalMarine = TRUE;
112
+}
113
+if (isset($options['disable-marine'])) {
114
+	$globalMarine = FALSE;
115
+}
116
+if (isset($options['nodaemon'])) {
117
+	$globalDaemon = FALSE;
118
+}
119
+if (isset($options['server'])) {
120
+	$globalServer = TRUE;
121
+}
122
+if (isset($options['idsource'])) {
123
+	$id_source = $options['idsource'];
124
+} else {
125
+	$id_source = 1;
126
+}
90 127
 if (isset($globalServer) && $globalServer) {
91
-    if ($globalDebug) echo "Using Server Mode\n";
128
+    if ($globalDebug) {
129
+    	echo "Using Server Mode\n";
130
+    }
92 131
     $SI=new SpotterServer();
93 132
 /*
94 133
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
95 134
     $SI = new adsb2aprs();
96 135
     $SI->connect();
97 136
 */
98
-} else $SI=new SpotterImport($Connection->db);
137
+} else {
138
+	$SI=new SpotterImport($Connection->db);
139
+}
99 140
 
100
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
141
+if (isset($globalTracker) && $globalTracker) {
142
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
143
+}
101 144
 if (isset($globalMarine) && $globalMarine) {
102 145
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
103 146
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
104 147
 }
105 148
 
106
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
149
+if (isset($globalTracker) && $globalTracker) {
150
+	$TI = new TrackerImport($Connection->db);
151
+}
107 152
 if (isset($globalMarine) && $globalMarine) {
108 153
     $AIS = new AIS();
109 154
     $MI = new MarineImport($Connection->db);
@@ -126,7 +171,9 @@  discard block
 block discarded – undo
126 171
 }
127 172
 
128 173
 // let's try and connect
129
-if ($globalDebug) echo "Connecting...\n";
174
+if ($globalDebug) {
175
+	echo "Connecting...\n";
176
+}
130 177
 $use_aprs = false;
131 178
 $aprs_full = false;
132 179
 $reset = 0;
@@ -135,7 +182,9 @@  discard block
 block discarded – undo
135 182
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
136 183
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
137 184
     $reset++;
138
-    if ($globalDebug) echo 'Connect to all...'."\n";
185
+    if ($globalDebug) {
186
+    	echo 'Connect to all...'."\n";
187
+    }
139 188
     foreach ($hosts as $id => $value) {
140 189
 	$host = $value['host'];
141 190
 	$globalSources[$id]['last_exec'] = 0;
@@ -145,22 +194,30 @@  discard block
 block discarded – undo
145 194
         	//$formats[$id] = 'deltadbtxt';
146 195
         	$globalSources[$id]['format'] = 'deltadbtxt';
147 196
         	//$last_exec['deltadbtxt'] = 0;
148
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
197
+        	if ($globalDebug) {
198
+        		echo "Connect to deltadb source (".$host.")...\n";
199
+        	}
149 200
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
150 201
         	//$formats[$id] = 'vatsimtxt';
151 202
         	$globalSources[$id]['format'] = 'vatsimtxt';
152 203
         	//$last_exec['vatsimtxt'] = 0;
153
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
204
+        	if ($globalDebug) {
205
+        		echo "Connect to vatsim source (".$host.")...\n";
206
+        	}
154 207
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
155 208
         	//$formats[$id] = 'aircraftlistjson';
156 209
         	$globalSources[$id]['format'] = 'aircraftlistjson';
157 210
         	//$last_exec['aircraftlistjson'] = 0;
158
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
213
+        	}
159 214
     	    } else if (preg_match('/opensky/i',$host)) {
160 215
         	//$formats[$id] = 'aircraftlistjson';
161 216
         	$globalSources[$id]['format'] = 'opensky';
162 217
         	//$last_exec['aircraftlistjson'] = 0;
163
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
218
+        	if ($globalDebug) {
219
+        		echo "Connect to opensky source (".$host.")...\n";
220
+        	}
164 221
     	    /*
165 222
     	    // Disabled for now, site change source format
166 223
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -177,7 +234,9 @@  discard block
 block discarded – undo
177 234
         	//$formats[$id] = 'planeupdatefaa';
178 235
         	$globalSources[$id]['format'] = 'planeupdatefaa';
179 236
         	//$last_exec['planeupdatefaa'] = 0;
180
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
237
+        	if ($globalDebug) {
238
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
239
+        	}
181 240
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
182 241
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
183 242
         	    exit(0);
@@ -186,32 +245,46 @@  discard block
 block discarded – undo
186 245
         	//$formats[$id] = 'phpvmacars';
187 246
         	$globalSources[$id]['format'] = 'phpvmacars';
188 247
         	//$last_exec['phpvmacars'] = 0;
189
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
248
+        	if ($globalDebug) {
249
+        		echo "Connect to phpvmacars source (".$host.")...\n";
250
+        	}
190 251
             } else if (preg_match('/VAM-json.php$/i',$host)) {
191 252
         	//$formats[$id] = 'phpvmacars';
192 253
         	$globalSources[$id]['format'] = 'vam';
193
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
254
+        	if ($globalDebug) {
255
+        		echo "Connect to Vam source (".$host.")...\n";
256
+        	}
194 257
             } else if (preg_match('/whazzup/i',$host)) {
195 258
         	//$formats[$id] = 'whazzup';
196 259
         	$globalSources[$id]['format'] = 'whazzup';
197 260
         	//$last_exec['whazzup'] = 0;
198
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
261
+        	if ($globalDebug) {
262
+        		echo "Connect to whazzup source (".$host.")...\n";
263
+        	}
199 264
             } else if (preg_match('/blitzortung/i',$host)) {
200 265
         	$globalSources[$id]['format'] = 'blitzortung';
201
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
266
+        	if ($globalDebug) {
267
+        		echo "Connect to blitzortung source (".$host.")...\n";
268
+        	}
202 269
             } else if (preg_match('/airwhere/i',$host)) {
203 270
         	$globalSources[$id]['format'] = 'airwhere';
204
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
271
+        	if ($globalDebug) {
272
+        		echo "Connect to airwhere source (".$host.")...\n";
273
+        	}
205 274
             } else if (preg_match('/recentpireps/i',$host)) {
206 275
         	//$formats[$id] = 'pirepsjson';
207 276
         	$globalSources[$id]['format'] = 'pirepsjson';
208 277
         	//$last_exec['pirepsjson'] = 0;
209
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
278
+        	if ($globalDebug) {
279
+        		echo "Connect to pirepsjson source (".$host.")...\n";
280
+        	}
210 281
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
211 282
         	//$formats[$id] = 'fr24json';
212 283
         	$globalSources[$id]['format'] = 'fr24json';
213 284
         	//$last_exec['fr24json'] = 0;
214
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
285
+        	if ($globalDebug) {
286
+        		echo "Connect to fr24 source (".$host.")...\n";
287
+        	}
215 288
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
216 289
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
217 290
         	    exit(0);
@@ -220,7 +293,9 @@  discard block
 block discarded – undo
220 293
         	//$formats[$id] = 'fr24json';
221 294
         	$globalSources[$id]['format'] = 'myshiptracking';
222 295
         	//$last_exec['fr24json'] = 0;
223
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
296
+        	if ($globalDebug) {
297
+        		echo "Connect to myshiptracking source (".$host.")...\n";
298
+        	}
224 299
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
225 300
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
226 301
         	    exit(0);
@@ -229,17 +304,24 @@  discard block
 block discarded – undo
229 304
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
230 305
         	//$formats[$id] = 'tsv';
231 306
         	$globalSources[$id]['format'] = 'tsv';
232
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
307
+        	if ($globalDebug) {
308
+        		echo "Connect to tsv source (".$host.")...\n";
309
+        	}
233 310
             }
234 311
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
235 312
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
236 313
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
237 314
     		    if ($idf !== false) {
238 315
     			$httpfeeds[$id] = $idf;
239
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
316
+        		if ($globalDebug) {
317
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
318
+        		}
319
+    		    } elseif ($globalDebug) {
320
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
240 321
     		    }
241
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
242
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
322
+    		} elseif ($globalDebug) {
323
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
324
+    		}
243 325
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
244 326
 	    $hostport = explode(':',$host);
245 327
 	    if (isset($hostport[1])) {
@@ -279,17 +361,25 @@  discard block
 block discarded – undo
279 361
         		//$formats[$id] = 'beast';
280 362
         		$globalSources[$id]['format'] = 'beast';
281 363
 		    //} else $formats[$id] = 'sbs';
282
-		    } else $globalSources[$id]['format'] = 'sbs';
364
+		    } else {
365
+		    	$globalSources[$id]['format'] = 'sbs';
366
+		    }
283 367
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
284 368
 		}
285
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
369
+		if ($globalDebug) {
370
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
371
+		}
286 372
             } else {
287
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
373
+		if ($globalDebug) {
374
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
375
+		}
288 376
     	    }
289 377
         }
290 378
     }
291 379
 }
292
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
380
+if (!isset($globalMinFetch)) {
381
+	$globalMinFetch = 15;
382
+}
293 383
 
294 384
 // Initialize all
295 385
 $status = array();
@@ -298,13 +388,19 @@  discard block
 block discarded – undo
298 388
 $formats = array();
299 389
 $last_exec = array();
300 390
 $time = time();
301
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
302
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
303
-else $timeout = 20;
391
+if (isset($globalSourcesTimeout)) {
392
+	$timeout = $globalSourcesTimeOut;
393
+} else if (isset($globalSBS1TimeOut)) {
394
+	$timeout = $globalSBS1TimeOut;
395
+} else {
396
+	$timeout = 20;
397
+}
304 398
 $errno = '';
305 399
 $errstr='';
306 400
 
307
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
401
+if (!isset($globalDaemon)) {
402
+	$globalDaemon = TRUE;
403
+}
308 404
 /* Initiate connections to all the hosts simultaneously */
309 405
 //connect_all($hosts);
310 406
 //connect_all($globalSources);
@@ -333,7 +429,9 @@  discard block
 block discarded – undo
333 429
     if (isset($source['format']) && $source['format'] == 'aprs') {
334 430
 	$aprs_connect = 0;
335 431
 	$use_aprs = true;
336
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
432
+	if (isset($source['port']) && $source['port'] == '10152') {
433
+		$aprs_full = true;
434
+	}
337 435
 	break;
338 436
     }
339 437
 }
@@ -344,25 +442,48 @@  discard block
 block discarded – undo
344 442
 	$aprs_connect = 0;
345 443
 	$aprs_keep = 120;
346 444
 	$aprs_last_tx = time();
347
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
348
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
349
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
350
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
351
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
352
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
353
-	if ($aprs_full) $aprs_filter = '';
354
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
355
-	else $aprs_pass = '-1';
445
+	if (isset($globalAPRSversion)) {
446
+		$aprs_version = $globalAPRSversion;
447
+	} else {
448
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
449
+	}
450
+	if (isset($globalAPRSssid)) {
451
+		$aprs_ssid = $globalAPRSssid;
452
+	} else {
453
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
454
+	}
455
+	if (isset($globalAPRSfilter)) {
456
+		$aprs_filter = $globalAPRSfilter;
457
+	} else {
458
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
459
+	}
460
+	if ($aprs_full) {
461
+		$aprs_filter = '';
462
+	}
463
+	if (isset($globalAPRSpass)) {
464
+		$aprs_pass = $globalAPRSpass;
465
+	} else {
466
+		$aprs_pass = '-1';
467
+	}
356 468
 
357
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
358
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
359
-}
469
+	if ($aprs_filter != '') {
470
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
471
+	} else {
472
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
473
+	}
474
+	}
360 475
 
361 476
 // connected - lets do some work
362
-if ($globalDebug) echo "Connected!\n";
477
+if ($globalDebug) {
478
+	echo "Connected!\n";
479
+}
363 480
 sleep(1);
364
-if ($globalDebug) echo "SCAN MODE \n\n";
365
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
481
+if ($globalDebug) {
482
+	echo "SCAN MODE \n\n";
483
+}
484
+if (!isset($globalCronEnd)) {
485
+	$globalCronEnd = 60;
486
+}
366 487
 $endtime = time()+$globalCronEnd;
367 488
 $i = 1;
368 489
 $tt = array();
@@ -376,20 +497,28 @@  discard block
 block discarded – undo
376 497
 
377 498
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
378 499
 while ($i > 0) {
379
-    if (!$globalDaemon) $i = $endtime-time();
500
+    if (!$globalDaemon) {
501
+    	$i = $endtime-time();
502
+    }
380 503
     // Delete old ATC
381 504
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
382
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
505
+	if ($globalDebug) {
506
+		echo 'Delete old ATC...'."\n";
507
+	}
383 508
         $ATC->deleteOldATC();
384 509
     }
385 510
     
386 511
     if (count($last_exec) == count($globalSources)) {
387 512
 	$max = $globalMinFetch;
388 513
 	foreach ($last_exec as $last) {
389
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
514
+	    if ((time() - $last['last']) < $max) {
515
+	    	$max = time() - $last['last'];
516
+	    }
390 517
 	}
391 518
 	if ($max != $globalMinFetch) {
392
-	    if ($globalDebug) echo 'Sleeping...'."\n";
519
+	    if ($globalDebug) {
520
+	    	echo 'Sleeping...'."\n";
521
+	    }
393 522
 	    sleep($globalMinFetch-$max+2);
394 523
 	}
395 524
     }
@@ -399,7 +528,9 @@  discard block
 block discarded – undo
399 528
     foreach ($globalSources as $id => $value) {
400 529
 	date_default_timezone_set('UTC');
401 530
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
402
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
531
+	if (!isset($last_exec[$id]['last'])) {
532
+		$last_exec[$id]['last'] = 0;
533
+	}
403 534
 	if ($value['format'] == 'deltadbtxt' && 
404 535
 	    (
405 536
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -408,7 +539,9 @@  discard block
 block discarded – undo
408 539
 	) {
409 540
 	    //$buffer = $Common->getData($hosts[$id]);
410 541
 	    $buffer = $Common->getData($value['host']);
411
-	    if ($buffer != '') $reset = 0;
542
+	    if ($buffer != '') {
543
+	    	$reset = 0;
544
+	    }
412 545
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413 546
 	    $buffer = explode('\n',$buffer);
414 547
 	    foreach ($buffer as $line) {
@@ -417,20 +550,41 @@  discard block
 block discarded – undo
417 550
 	            $data = array();
418 551
 	            $data['hex'] = $line[1]; // hex
419 552
 	            $data['ident'] = $line[2]; // ident
420
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
421
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
422
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
423
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
424
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
553
+	            if (isset($line[3])) {
554
+	            	$data['altitude'] = $line[3];
555
+	            }
556
+	            // altitude
557
+	            if (isset($line[4])) {
558
+	            	$data['speed'] = $line[4];
559
+	            }
560
+	            // speed
561
+	            if (isset($line[5])) {
562
+	            	$data['heading'] = $line[5];
563
+	            }
564
+	            // heading
565
+	            if (isset($line[6])) {
566
+	            	$data['latitude'] = $line[6];
567
+	            }
568
+	            // lat
569
+	            if (isset($line[7])) {
570
+	            	$data['longitude'] = $line[7];
571
+	            }
572
+	            // long
425 573
 	            $data['verticalrate'] = ''; // vertical rate
426 574
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
427 575
 	            $data['emergency'] = ''; // emergency
428 576
 		    $data['datetime'] = date('Y-m-d H:i:s');
429 577
 		    $data['format_source'] = 'deltadbtxt';
430 578
     		    $data['id_source'] = $id_source;
431
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
432
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
433
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
579
+		    if (isset($value['name']) && $value['name'] != '') {
580
+		    	$data['source_name'] = $value['name'];
581
+		    }
582
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
583
+		    	$data['noarchive'] = true;
584
+		    }
585
+		    if (isset($value['sourcestats'])) {
586
+		    	$data['sourcestats'] = $value['sourcestats'];
587
+		    }
434 588
     		    $SI->add($data);
435 589
 		    unset($data);
436 590
     		}
@@ -445,7 +599,9 @@  discard block
 block discarded – undo
445 599
 	    date_default_timezone_set('CET');
446 600
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
447 601
 	    date_default_timezone_set('UTC');
448
-	    if ($buffer != '') $reset = 0;
602
+	    if ($buffer != '') {
603
+	    	$reset = 0;
604
+	    }
449 605
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
450 606
 	    $buffer = explode('\n',$buffer);
451 607
 	    foreach ($buffer as $line) {
@@ -454,16 +610,36 @@  discard block
 block discarded – undo
454 610
 		    $add = false;
455 611
 		    $ais_data = $AIS->parse_line(trim($line));
456 612
 		    $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['type'])) $data['type'] = $ais_data['type'];
465
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
466
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
613
+		    if (isset($ais_data['ident'])) {
614
+		    	$data['ident'] = $ais_data['ident'];
615
+		    }
616
+		    if (isset($ais_data['mmsi'])) {
617
+		    	$data['mmsi'] = $ais_data['mmsi'];
618
+		    }
619
+		    if (isset($ais_data['speed'])) {
620
+		    	$data['speed'] = $ais_data['speed'];
621
+		    }
622
+		    if (isset($ais_data['heading'])) {
623
+		    	$data['heading'] = $ais_data['heading'];
624
+		    }
625
+		    if (isset($ais_data['latitude'])) {
626
+		    	$data['latitude'] = $ais_data['latitude'];
627
+		    }
628
+		    if (isset($ais_data['longitude'])) {
629
+		    	$data['longitude'] = $ais_data['longitude'];
630
+		    }
631
+		    if (isset($ais_data['status'])) {
632
+		    	$data['status'] = $ais_data['status'];
633
+		    }
634
+		    if (isset($ais_data['type'])) {
635
+		    	$data['type'] = $ais_data['type'];
636
+		    }
637
+		    if (isset($ais_data['imo'])) {
638
+		    	$data['imo'] = $ais_data['imo'];
639
+		    }
640
+		    if (isset($ais_data['callsign'])) {
641
+		    	$data['callsign'] = $ais_data['callsign'];
642
+		    }
467 643
 		    if (isset($ais_data['timestamp'])) {
468 644
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
469 645
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -477,8 +653,12 @@  discard block
 block discarded – undo
477 653
 		    $data['format_source'] = 'aisnmeatxt';
478 654
     		    $data['id_source'] = $id_source;
479 655
 		    //print_r($data);
480
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
481
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
656
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
657
+		    	$data['noarchive'] = true;
658
+		    }
659
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
660
+		    	$MI->add($data);
661
+		    }
482 662
 		    unset($data);
483 663
 		}
484 664
     	    }
@@ -498,20 +678,48 @@  discard block
 block discarded – undo
498 678
 			    if ($line != '') {
499 679
 				$ais_data = $AIS->parse_line(trim($line));
500 680
 				$data = array();
501
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
502
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
503
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
504
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
505
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
506
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
507
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
508
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
509
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
510
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
511
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
512
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
513
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
514
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
681
+				if (isset($ais_data['ident'])) {
682
+					$data['ident'] = $ais_data['ident'];
683
+				}
684
+				if (isset($ais_data['mmsi'])) {
685
+					$data['mmsi'] = $ais_data['mmsi'];
686
+				}
687
+				if (isset($ais_data['speed'])) {
688
+					$data['speed'] = $ais_data['speed'];
689
+				}
690
+				if (isset($ais_data['heading'])) {
691
+					$data['heading'] = $ais_data['heading'];
692
+				}
693
+				if (isset($ais_data['latitude'])) {
694
+					$data['latitude'] = $ais_data['latitude'];
695
+				}
696
+				if (isset($ais_data['longitude'])) {
697
+					$data['longitude'] = $ais_data['longitude'];
698
+				}
699
+				if (isset($ais_data['status'])) {
700
+					$data['status'] = $ais_data['status'];
701
+				}
702
+				if (isset($ais_data['statusid'])) {
703
+					$data['status_id'] = $ais_data['statusid'];
704
+				}
705
+				if (isset($ais_data['type'])) {
706
+					$data['type'] = $ais_data['type'];
707
+				}
708
+				if (isset($ais_data['typeid'])) {
709
+					$data['type_id'] = $ais_data['typeid'];
710
+				}
711
+				if (isset($ais_data['imo'])) {
712
+					$data['imo'] = $ais_data['imo'];
713
+				}
714
+				if (isset($ais_data['callsign'])) {
715
+					$data['callsign'] = $ais_data['callsign'];
716
+				}
717
+				if (isset($ais_data['destination'])) {
718
+					$data['arrival_code'] = $ais_data['destination'];
719
+				}
720
+				if (isset($ais_data['eta_ts'])) {
721
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
722
+				}
515 723
 				if (isset($ais_data['timestamp'])) {
516 724
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
517 725
 				} else {
@@ -519,18 +727,27 @@  discard block
 block discarded – undo
519 727
 				}
520 728
 				$data['format_source'] = 'aisnmeahttp';
521 729
 				$data['id_source'] = $id_source;
522
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
523
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
730
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
731
+					$data['noarchive'] = true;
732
+				}
733
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
734
+					$MI->add($data);
735
+				}
524 736
 				unset($data);
525 737
 			    }
526 738
 			}
527 739
 		    }
528 740
 		} else {
529 741
 		    $format = $value['format'];
530
-		    if (isset($tt[$format])) $tt[$format]++;
531
-		    else $tt[$format] = 0;
742
+		    if (isset($tt[$format])) {
743
+		    	$tt[$format]++;
744
+		    } else {
745
+		    	$tt[$format] = 0;
746
+		    }
532 747
 		    if ($tt[$format] > 30) {
533
-			if ($globalDebug) echo 'Reconnect...'."\n";
748
+			if ($globalDebug) {
749
+				echo 'Reconnect...'."\n";
750
+			}
534 751
 			sleep(2);
535 752
 			$sourceeen[] = $value;
536 753
 			connect_all($sourceeen);
@@ -565,7 +782,9 @@  discard block
 block discarded – undo
565 782
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
566 783
 			    $data['format_source'] = 'myshiptracking';
567 784
 			    $data['id_source'] = $id_source;
568
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
785
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
786
+			    	$data['noarchive'] = true;
787
+			    }
569 788
 			    $MI->add($data);
570 789
 			    unset($data);
571 790
 			}
@@ -590,7 +809,9 @@  discard block
 block discarded – undo
590 809
 			    $data['callsign'] = $line['callsign'];
591 810
 			    $data['mmsi'] = $line['mmsi'];
592 811
 			    $data['speed'] = $line['sog'];
593
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
812
+			    if ($line['heading'] != '511') {
813
+			    	$data['heading'] = $line['heading'];
814
+			    }
594 815
 			    $data['latitude'] = $line['latitude'];
595 816
 			    $data['longitude'] = $line['longitude'];
596 817
 			    $data['type_id'] = $line['shiptype'];
@@ -598,7 +819,9 @@  discard block
 block discarded – undo
598 819
 			    $data['datetime'] = $line['time'];
599 820
 			    $data['format_source'] = 'boatbeaconapp';
600 821
 			    $data['id_source'] = $id_source;
601
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
822
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
823
+			    	$data['noarchive'] = true;
824
+			    }
602 825
 			    $MI->add($data);
603 826
 			    unset($data);
604 827
 			}
@@ -619,22 +842,44 @@  discard block
 block discarded – undo
619 842
 		if (isset($all_data['features'][0]['id'])) {
620 843
 		    foreach ($all_data['features'] as $line) {
621 844
 			$data = array();
622
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
623
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
624
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
625
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
626
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
627
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
845
+			if (isset($line['properties']['name'])) {
846
+				$data['ident'] = $line['properties']['name'];
847
+			}
848
+			if (isset($line['properties']['callsign'])) {
849
+				$data['callsign'] = $line['properties']['callsign'];
850
+			}
851
+			if (isset($line['properties']['mmsi'])) {
852
+				$data['mmsi'] = $line['properties']['mmsi'];
853
+			}
854
+			if (isset($line['properties']['imo'])) {
855
+				$data['mmsi'] = $line['properties']['imo'];
856
+			}
857
+			if (isset($line['properties']['speed'])) {
858
+				$data['speed'] = $line['properties']['speed'];
859
+			}
860
+			if (isset($line['properties']['heading'])) {
861
+				$data['heading'] = $line['properties']['heading'];
862
+			}
628 863
 			$data['latitude'] = $line['geometry']['coordinates'][1];
629 864
 			$data['longitude'] = $line['geometry']['coordinates'][0];
630
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
631
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
632
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
865
+			if (isset($line['properties']['vesselType'])) {
866
+				$data['type'] = $line['properties']['vesselType'];
867
+			}
868
+			if (isset($line['properties']['destination'])) {
869
+				$data['arrival_code'] = $line['properties']['destination'];
870
+			}
871
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
872
+				$data['arrival_date'] = $line['properties']['eta'];
873
+			}
633 874
 			$data['format_source'] = 'boatnerd';
634 875
 			$data['id_source'] = $id_source;
635 876
 			$data['datetime'] = date('Y-m-d H:i:s');
636
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
637
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
877
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
878
+				$data['noarchive'] = true;
879
+			}
880
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
881
+				$MI->add($data);
882
+			}
638 883
 			unset($data);
639 884
 		    }
640 885
 		}
@@ -650,7 +895,9 @@  discard block
 block discarded – undo
650 895
 	    echo 'download...';
651 896
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
652 897
 	    echo 'done !'."\n";
653
-	    if ($buffer != '') $reset = 0;
898
+	    if ($buffer != '') {
899
+	    	$reset = 0;
900
+	    }
654 901
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
655 902
 	    $buffer = explode('\n',$buffer);
656 903
 	    foreach ($buffer as $line) {
@@ -675,7 +922,9 @@  discard block
 block discarded – undo
675 922
 		    //$data['etaTime'] = substr($line,135,5);
676 923
 		    $data['format_source'] = 'shipplotter';
677 924
     		    $data['id_source'] = $id_source;
678
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
925
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
926
+		    	$data['noarchive'] = true;
927
+		    }
679 928
 		    //print_r($data);
680 929
 		    echo 'Add...'."\n";
681 930
 		    $MI->add($data);
@@ -709,16 +958,28 @@  discard block
 block discarded – undo
709 958
     		    $line = explode(':', $line);
710 959
     		    if (count($line) > 30 && $line[0] != 'callsign') {
711 960
 			$data = array();
712
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
713
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
961
+			if (isset($line[37]) && $line[37] != '') {
962
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
963
+			} else {
964
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
965
+			}
714 966
 			$data['pilot_id'] = $line[1];
715 967
 			$data['pilot_name'] = $line[2];
716 968
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
717 969
 			$data['ident'] = $line[0]; // ident
718
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
970
+			if ($line[7] != '' && $line[7] != 0) {
971
+				$data['altitude'] = $line[7];
972
+			}
973
+			// altitude
719 974
 			$data['speed'] = $line[8]; // speed
720
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
721
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
975
+			if (isset($line[45])) {
976
+				$data['heading'] = $line[45];
977
+			}
978
+			// heading
979
+			elseif (isset($line[38])) {
980
+				$data['heading'] = $line[38];
981
+			}
982
+			// heading
722 983
 			$data['latitude'] = $line[5]; // lat
723 984
 	        	$data['longitude'] = $line[6]; // long
724 985
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -734,7 +995,9 @@  discard block
 block discarded – undo
734 995
 			$data['frequency'] = $line[4];
735 996
 			$data['type'] = $line[18];
736 997
 			$data['range'] = $line[19];
737
-			if (isset($line[35])) $data['info'] = $line[35];
998
+			if (isset($line[35])) {
999
+				$data['info'] = $line[35];
1000
+			}
738 1001
     			$data['id_source'] = $id_source;
739 1002
 	    		//$data['arrival_airport_time'] = ;
740 1003
 	    		if ($line[9] != '') {
@@ -748,27 +1011,47 @@  discard block
 block discarded – undo
748 1011
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
749 1012
 	    		*/
750 1013
 	    		$data['format_source'] = $value['format'];
751
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
752
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
753
-    			if ($line[3] == 'PILOT') $SI->add($data);
754
-			elseif ($line[3] == 'ATC') {
1014
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1015
+				$data['noarchive'] = true;
1016
+			}
1017
+			if (isset($value['name']) && $value['name'] != '') {
1018
+				$data['source_name'] = $value['name'];
1019
+			}
1020
+    			if ($line[3] == 'PILOT') {
1021
+    				$SI->add($data);
1022
+    			} elseif ($line[3] == 'ATC') {
755 1023
 				//print_r($data);
756 1024
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
757 1025
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
758 1026
 				$typec = substr($data['ident'],-3);
759
-				if ($typec == 'APP') $data['type'] = 'Approach';
760
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
761
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
762
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
763
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
764
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
765
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
766
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
767
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
768
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1027
+				if ($typec == 'APP') {
1028
+					$data['type'] = 'Approach';
1029
+				} elseif ($typec == 'TWR') {
1030
+					$data['type'] = 'Tower';
1031
+				} elseif ($typec == 'OBS') {
1032
+					$data['type'] = 'Observer';
1033
+				} elseif ($typec == 'GND') {
1034
+					$data['type'] = 'Ground';
1035
+				} elseif ($typec == 'DEL') {
1036
+					$data['type'] = 'Delivery';
1037
+				} elseif ($typec == 'DEP') {
1038
+					$data['type'] = 'Departure';
1039
+				} elseif ($typec == 'FSS') {
1040
+					$data['type'] = 'Flight Service Station';
1041
+				} elseif ($typec == 'CTR') {
1042
+					$data['type'] = 'Control Radar or Centre';
1043
+				} elseif ($data['type'] == '') {
1044
+					$data['type'] = 'Observer';
1045
+				}
1046
+				if (!isset($data['source_name'])) {
1047
+					$data['source_name'] = '';
1048
+				}
769 1049
 				if (isset($ATC)) {
770
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
771
-					else 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']);
1050
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1051
+						echo $ATC->update($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']);
1052
+					} else {
1053
+						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']);
1054
+					}
772 1055
 				}
773 1056
 			}
774 1057
     			unset($data);
@@ -795,14 +1078,20 @@  discard block
 block discarded – undo
795 1078
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
796 1079
 			$data['latitude'] = (float)$line['pktLatitude'];
797 1080
 			$data['longitude'] = (float)$line['pktLongitude'];
798
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
799
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1081
+			if ((float)$line['pktTrack'] != 0) {
1082
+				$data['heading'] = (float)$line['pktTrack'];
1083
+			}
1084
+			if ((int)$line['pktSpeed'] != 0) {
1085
+				$data['speed'] = (int)$line['pktSpeed'];
1086
+			}
800 1087
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
801 1088
 			$data['altitude_relative'] = 'AMSL';
802 1089
 			$data['pilot_id'] = (int)$line['pktPilotID'];
803 1090
 			$data['aircraft_icao'] = 'PARAGLIDER';
804 1091
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
805
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1092
+			if (isset($pilot_data[4])) {
1093
+				$data['pilot_name'] = $pilot_data[4];
1094
+			}
806 1095
 			$data['format_source'] = $value['format'];
807 1096
 			$SI->add($data);
808 1097
 			unset($data);
@@ -850,25 +1139,59 @@  discard block
 block discarded – undo
850 1139
 		    foreach ($all_data['acList'] as $line) {
851 1140
 			$data = array();
852 1141
 			$data['hex'] = $line['Icao']; // hex
853
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
854
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
855
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
856
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
857
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
858
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1142
+			if (isset($line['Call'])) {
1143
+				$data['ident'] = $line['Call'];
1144
+			}
1145
+			// ident
1146
+			if (isset($line['Alt'])) {
1147
+				$data['altitude'] = $line['Alt'];
1148
+			}
1149
+			// altitude
1150
+			if (isset($line['Spd'])) {
1151
+				$data['speed'] = $line['Spd'];
1152
+			}
1153
+			// speed
1154
+			if (isset($line['Trak'])) {
1155
+				$data['heading'] = $line['Trak'];
1156
+			}
1157
+			// heading
1158
+			if (isset($line['Lat'])) {
1159
+				$data['latitude'] = $line['Lat'];
1160
+			}
1161
+			// lat
1162
+			if (isset($line['Long'])) {
1163
+				$data['longitude'] = $line['Long'];
1164
+			}
1165
+			// long
859 1166
 			//$data['verticalrate'] = $line['']; // verticale rate
860
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1167
+			if (isset($line['Sqk'])) {
1168
+				$data['squawk'] = $line['Sqk'];
1169
+			}
1170
+			// squawk
861 1171
 			$data['emergency'] = ''; // emergency
862
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
863
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
864
-			else $data['datetime'] = date('Y-m-d H:i:s');
1172
+			if (isset($line['Reg'])) {
1173
+				$data['registration'] = $line['Reg'];
1174
+			}
1175
+			if (isset($line['PosTime'])) {
1176
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1177
+			} else {
1178
+				$data['datetime'] = date('Y-m-d H:i:s');
1179
+			}
865 1180
 			//$data['datetime'] = date('Y-m-d H:i:s');
866
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1181
+			if (isset($line['Type'])) {
1182
+				$data['aircraft_icao'] = $line['Type'];
1183
+			}
867 1184
 			$data['format_source'] = 'aircraftlistjson';
868 1185
 			$data['id_source'] = $id_source;
869
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
870
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
871
-			if (isset($data['latitude'])) $SI->add($data);
1186
+			if (isset($value['name']) && $value['name'] != '') {
1187
+				$data['source_name'] = $value['name'];
1188
+			}
1189
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1190
+				$data['noarchive'] = true;
1191
+			}
1192
+			if (isset($data['latitude'])) {
1193
+				$SI->add($data);
1194
+			}
872 1195
 			unset($data);
873 1196
 		    }
874 1197
 		} elseif (is_array($all_data)) {
@@ -885,17 +1208,26 @@  discard block
 block discarded – undo
885 1208
 			$data['verticalrate'] = $line['vrt']; // verticale rate
886 1209
 			$data['squawk'] = $line['squawk']; // squawk
887 1210
 			$data['emergency'] = ''; // emergency
888
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
889
-			else $data['datetime'] = date('Y-m-d H:i:s');
1211
+			if (isset($line['PosTime'])) {
1212
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1213
+			} else {
1214
+				$data['datetime'] = date('Y-m-d H:i:s');
1215
+			}
890 1216
 			$data['format_source'] = 'aircraftlistjson';
891 1217
 			$data['id_source'] = $id_source;
892
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
893
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1218
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1219
+				$data['noarchive'] = true;
1220
+			}
1221
+			if (isset($value['name']) && $value['name'] != '') {
1222
+				$data['source_name'] = $value['name'];
1223
+			}
894 1224
 			$SI->add($data);
895 1225
 			unset($data);
896 1226
 		    }
897 1227
 		}
898
-	    } elseif ($globalDebug) echo 'No data'."\n";
1228
+	    } elseif ($globalDebug) {
1229
+	    	echo 'No data'."\n";
1230
+	    }
899 1231
     	    //$last_exec['aircraftlistjson'] = time();
900 1232
     	    $last_exec[$id]['last'] = time();
901 1233
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -931,8 +1263,12 @@  discard block
 block discarded – undo
931 1263
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
932 1264
 	    	    $data['format_source'] = 'planeupdatefaa';
933 1265
     		    $data['id_source'] = $id_source;
934
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
935
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1266
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1267
+		    	$data['noarchive'] = true;
1268
+		    }
1269
+		    if (isset($value['name']) && $value['name'] != '') {
1270
+		    	$data['source_name'] = $value['name'];
1271
+		    }
936 1272
 		    $SI->add($data);
937 1273
 		    unset($data);
938 1274
 		}
@@ -966,7 +1302,9 @@  discard block
 block discarded – undo
966 1302
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
967 1303
 		    $data['format_source'] = 'opensky';
968 1304
 		    $data['id_source'] = $id_source;
969
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1305
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1306
+		    	$data['noarchive'] = true;
1307
+		    }
970 1308
 		    $SI->add($data);
971 1309
 		    unset($data);
972 1310
 		}
@@ -983,7 +1321,9 @@  discard block
 block discarded – undo
983 1321
 	    //$buffer = $Common->getData($hosts[$id]);
984 1322
 	    $buffer = $Common->getData($value['host']);
985 1323
 	    $all_data = json_decode($buffer,true);
986
-	    if (!empty($all_data)) $reset = 0;
1324
+	    if (!empty($all_data)) {
1325
+	    	$reset = 0;
1326
+	    }
987 1327
 	    foreach ($all_data as $key => $line) {
988 1328
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
989 1329
 		    $data = array();
@@ -1004,8 +1344,12 @@  discard block
 block discarded – undo
1004 1344
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1005 1345
 	    	    $data['format_source'] = 'fr24json';
1006 1346
     		    $data['id_source'] = $id_source;
1007
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1008
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1347
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1348
+		    	$data['noarchive'] = true;
1349
+		    }
1350
+		    if (isset($value['name']) && $value['name'] != '') {
1351
+		    	$data['source_name'] = $value['name'];
1352
+		    }
1009 1353
 		    $SI->add($data);
1010 1354
 		    unset($data);
1011 1355
 		}
@@ -1034,24 +1378,42 @@  discard block
 block discarded – undo
1034 1378
 		    if (isset($line['inf'])) {
1035 1379
 			$data = array();
1036 1380
 			$data['hex'] = $line['inf']['ia'];
1037
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1381
+			if (isset($line['inf']['cs'])) {
1382
+				$data['ident'] = $line['inf']['cs'];
1383
+			}
1384
+			//$line[13]
1038 1385
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1039
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1040
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1386
+	    		if (isset($line['inf']['gs'])) {
1387
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1388
+	    		}
1389
+	    		// speed
1390
+	    		if (isset($line['inf']['tr'])) {
1391
+	    			$data['heading'] = $line['inf']['tr'];
1392
+	    		}
1393
+	    		// heading
1041 1394
 	    		$data['latitude'] = $line['pt'][0]; // lat
1042 1395
 	    		$data['longitude'] = $line['pt'][1]; // long
1043 1396
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1044
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1397
+	    		if (isset($line['inf']['sq'])) {
1398
+	    			$data['squawk'] = $line['inf']['sq'];
1399
+	    		}
1400
+	    		// squawk
1045 1401
 	    		//$data['aircraft_icao'] = $line[8];
1046
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1402
+	    		if (isset($line['inf']['rc'])) {
1403
+	    			$data['registration'] = $line['inf']['rc'];
1404
+	    		}
1047 1405
 			//$data['departure_airport_iata'] = $line[11];
1048 1406
 			//$data['arrival_airport_iata'] = $line[12];
1049 1407
 	    		//$data['emergency'] = ''; // emergency
1050 1408
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1051 1409
 	    		$data['format_source'] = 'radarvirtueljson';
1052 1410
     			$data['id_source'] = $id_source;
1053
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1054
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1411
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1412
+				$data['noarchive'] = true;
1413
+			}
1414
+			if (isset($value['name']) && $value['name'] != '') {
1415
+				$data['source_name'] = $value['name'];
1416
+			}
1055 1417
 			$SI->add($data);
1056 1418
 			unset($data);
1057 1419
 		    }
@@ -1077,30 +1439,65 @@  discard block
 block discarded – undo
1077 1439
 		    $data['id'] = $line['id'];
1078 1440
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1079 1441
 		    $data['ident'] = $line['callsign']; // ident
1080
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1081
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1082
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1083
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1084
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1085
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1442
+		    if (isset($line['pilotid'])) {
1443
+		    	$data['pilot_id'] = $line['pilotid'];
1444
+		    }
1445
+		    // pilot id
1446
+		    if (isset($line['name'])) {
1447
+		    	$data['pilot_name'] = $line['name'];
1448
+		    }
1449
+		    // pilot name
1450
+		    if (isset($line['alt'])) {
1451
+		    	$data['altitude'] = $line['alt'];
1452
+		    }
1453
+		    // altitude
1454
+		    if (isset($line['gs'])) {
1455
+		    	$data['speed'] = $line['gs'];
1456
+		    }
1457
+		    // speed
1458
+		    if (isset($line['heading'])) {
1459
+		    	$data['heading'] = $line['heading'];
1460
+		    }
1461
+		    // heading
1462
+		    if (isset($line['route'])) {
1463
+		    	$data['waypoints'] = $line['route'];
1464
+		    }
1465
+		    // route
1086 1466
 		    $data['latitude'] = $line['lat']; // lat
1087 1467
 		    $data['longitude'] = $line['lon']; // long
1088 1468
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1089 1469
 		    //$data['squawk'] = $line['squawk']; // squawk
1090 1470
 		    //$data['emergency'] = ''; // emergency
1091
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1092
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1093
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1471
+		    if (isset($line['depicao'])) {
1472
+		    	$data['departure_airport_icao'] = $line['depicao'];
1473
+		    }
1474
+		    if (isset($line['deptime'])) {
1475
+		    	$data['departure_airport_time'] = $line['deptime'];
1476
+		    }
1477
+		    if (isset($line['arricao'])) {
1478
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1479
+		    }
1094 1480
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1095
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1096
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1097
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1098
-		    else $data['info'] = '';
1481
+		    if (isset($line['aircraft'])) {
1482
+		    	$data['aircraft_icao'] = $line['aircraft'];
1483
+		    }
1484
+		    if (isset($line['transponder'])) {
1485
+		    	$data['squawk'] = $line['transponder'];
1486
+		    }
1487
+		    if (isset($line['atis'])) {
1488
+		    	$data['info'] = $line['atis'];
1489
+		    } else {
1490
+		    	$data['info'] = '';
1491
+		    }
1099 1492
 		    $data['format_source'] = 'pireps';
1100 1493
     		    $data['id_source'] = $id_source;
1101 1494
 		    $data['datetime'] = date('Y-m-d H:i:s');
1102
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1103
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1495
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1496
+		    	$data['noarchive'] = true;
1497
+		    }
1498
+		    if (isset($value['name']) && $value['name'] != '') {
1499
+		    	$data['source_name'] = $value['name'];
1500
+		    }
1104 1501
 		    if ($line['icon'] == 'plane') {
1105 1502
 			$SI->add($data);
1106 1503
 		    //    print_r($data);
@@ -1109,16 +1506,28 @@  discard block
 block discarded – undo
1109 1506
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1110 1507
 			$typec = substr($data['ident'],-3);
1111 1508
 			$data['type'] = '';
1112
-			if ($typec == 'APP') $data['type'] = 'Approach';
1113
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1114
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1115
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1116
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1117
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1118
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1119
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1120
-			else $data['type'] = 'Observer';
1121
-			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']);
1509
+			if ($typec == 'APP') {
1510
+				$data['type'] = 'Approach';
1511
+			} elseif ($typec == 'TWR') {
1512
+				$data['type'] = 'Tower';
1513
+			} elseif ($typec == 'OBS') {
1514
+				$data['type'] = 'Observer';
1515
+			} elseif ($typec == 'GND') {
1516
+				$data['type'] = 'Ground';
1517
+			} elseif ($typec == 'DEL') {
1518
+				$data['type'] = 'Delivery';
1519
+			} elseif ($typec == 'DEP') {
1520
+				$data['type'] = 'Departure';
1521
+			} elseif ($typec == 'FSS') {
1522
+				$data['type'] = 'Flight Service Station';
1523
+			} elseif ($typec == 'CTR') {
1524
+				$data['type'] = 'Control Radar or Centre';
1525
+			} else {
1526
+				$data['type'] = 'Observer';
1527
+			}
1528
+			if (isset($ATC)) {
1529
+				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']);
1530
+			}
1122 1531
 		    }
1123 1532
 		    unset($data);
1124 1533
 		}
@@ -1133,7 +1542,9 @@  discard block
 block discarded – undo
1133 1542
 	    )
1134 1543
 	) {
1135 1544
 	    //$buffer = $Common->getData($hosts[$id]);
1136
-	    if ($globalDebug) echo 'Get Data...'."\n";
1545
+	    if ($globalDebug) {
1546
+	    	echo 'Get Data...'."\n";
1547
+	    }
1137 1548
 	    $buffer = $Common->getData($value['host']);
1138 1549
 	    $all_data = json_decode($buffer,true);
1139 1550
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1141,10 +1552,16 @@  discard block
 block discarded – undo
1141 1552
 		foreach ($all_data as $line) {
1142 1553
 	    	    $data = array();
1143 1554
 	    	    //$data['id'] = $line['id']; // id not usable
1144
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1555
+	    	    if (isset($line['pilotid'])) {
1556
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1557
+	    	    }
1145 1558
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1146
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1147
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1559
+	    	    if (isset($line['pilotname'])) {
1560
+	    	    	$data['pilot_name'] = $line['pilotname'];
1561
+	    	    }
1562
+	    	    if (isset($line['pilotid'])) {
1563
+	    	    	$data['pilot_id'] = $line['pilotid'];
1564
+	    	    }
1148 1565
 	    	    $data['ident'] = $line['flightnum']; // ident
1149 1566
 	    	    $data['altitude'] = $line['alt']; // altitude
1150 1567
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1160,34 +1577,52 @@  discard block
 block discarded – undo
1160 1577
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1161 1578
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1162 1579
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1163
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1580
+	    	    } else {
1581
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1582
+	    	    }
1164 1583
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1165 1584
 	    	    $data['departure_airport_time'] = $line['deptime'];
1166 1585
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1167 1586
     		    $data['arrival_airport_time'] = $line['arrtime'];
1168 1587
     		    $data['registration'] = $line['aircraft'];
1169
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1170
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1588
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1589
+		    	$data['noarchive'] = true;
1590
+		    }
1591
+		    if (isset($line['route'])) {
1592
+		    	$data['waypoints'] = $line['route'];
1593
+		    }
1594
+		    // route
1171 1595
 		    if (isset($line['aircraftname'])) {
1172 1596
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1173 1597
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1174 1598
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1175
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1176
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1177
-	    		else {
1599
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1600
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1601
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1602
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1603
+	    		} else {
1178 1604
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1179
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1180
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1605
+	    		    if (isset($aircraft_data[1])) {
1606
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1607
+	    		    } else {
1608
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1609
+	    		    }
1181 1610
 	    		}
1182 1611
 	    	    }
1183
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1612
+    		    if (isset($line['route'])) {
1613
+    		    	$data['waypoints'] = $line['route'];
1614
+    		    }
1184 1615
     		    $data['id_source'] = $id_source;
1185 1616
 	    	    $data['format_source'] = 'phpvmacars';
1186
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1617
+		    if (isset($value['name']) && $value['name'] != '') {
1618
+		    	$data['source_name'] = $value['name'];
1619
+		    }
1187 1620
 		    $SI->add($data);
1188 1621
 		    unset($data);
1189 1622
 		}
1190
-		if ($globalDebug) echo 'No more data...'."\n";
1623
+		if ($globalDebug) {
1624
+			echo 'No more data...'."\n";
1625
+		}
1191 1626
 		unset($buffer);
1192 1627
 		unset($all_data);
1193 1628
 	    }
@@ -1200,7 +1635,9 @@  discard block
 block discarded – undo
1200 1635
 	    )
1201 1636
 	) {
1202 1637
 	    //$buffer = $Common->getData($hosts[$id]);
1203
-	    if ($globalDebug) echo 'Get Data...'."\n";
1638
+	    if ($globalDebug) {
1639
+	    	echo 'Get Data...'."\n";
1640
+	    }
1204 1641
 	    $buffer = $Common->getData($value['host']);
1205 1642
 	    $all_data = json_decode($buffer,true);
1206 1643
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1229,16 +1666,25 @@  discard block
 block discarded – undo
1229 1666
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1230 1667
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1231 1668
     		    //$data['registration'] = $line['aircraft'];
1232
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1669
+		    if (isset($line['route'])) {
1670
+		    	$data['waypoints'] = $line['route'];
1671
+		    }
1672
+		    // route
1233 1673
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1234 1674
     		    $data['id_source'] = $id_source;
1235 1675
 	    	    $data['format_source'] = 'vam';
1236
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1237
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1676
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1677
+		    	$data['noarchive'] = true;
1678
+		    }
1679
+		    if (isset($value['name']) && $value['name'] != '') {
1680
+		    	$data['source_name'] = $value['name'];
1681
+		    }
1238 1682
 		    $SI->add($data);
1239 1683
 		    unset($data);
1240 1684
 		}
1241
-		if ($globalDebug) echo 'No more data...'."\n";
1685
+		if ($globalDebug) {
1686
+			echo 'No more data...'."\n";
1687
+		}
1242 1688
 		unset($buffer);
1243 1689
 		unset($all_data);
1244 1690
 	    }
@@ -1251,7 +1697,9 @@  discard block
 block discarded – undo
1251 1697
 	    )
1252 1698
 	) {
1253 1699
 	    //$buffer = $Common->getData($hosts[$id]);
1254
-	    if ($globalDebug) echo 'Get Data...'."\n";
1700
+	    if ($globalDebug) {
1701
+	    	echo 'Get Data...'."\n";
1702
+	    }
1255 1703
 	    $buffer = $Common->getData($value['host']);
1256 1704
 	    $all_data = json_decode($buffer,true);
1257 1705
 	    if ($buffer != '') {
@@ -1269,18 +1717,24 @@  discard block
 block discarded – undo
1269 1717
 			$data['id_source'] = $id_source;
1270 1718
 			$data['format_source'] = 'blitzortung';
1271 1719
 			$SI->add($data);
1272
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1720
+			if ($globalDebug) {
1721
+				echo '☈ Lightning added'."\n";
1722
+			}
1273 1723
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1274 1724
 			unset($data);
1275 1725
 		    }
1276 1726
 		}
1277
-		if ($globalDebug) echo 'No more data...'."\n";
1727
+		if ($globalDebug) {
1728
+			echo 'No more data...'."\n";
1729
+		}
1278 1730
 		unset($buffer);
1279 1731
 	    }
1280 1732
 	    $last_exec[$id]['last'] = time();
1281 1733
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1282 1734
 	} 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') {
1283
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1735
+	    if (function_exists('pcntl_fork')) {
1736
+	    	pcntl_signal_dispatch();
1737
+	    }
1284 1738
     	    //$last_exec[$id]['last'] = time();
1285 1739
 
1286 1740
 	    //$read = array( $sockets[$id] );
@@ -1288,7 +1742,9 @@  discard block
 block discarded – undo
1288 1742
 	    $write = NULL;
1289 1743
 	    $e = NULL;
1290 1744
 	    $n = socket_select($read, $write, $e, $timeout);
1291
-	    if ($e != NULL) var_dump($e);
1745
+	    if ($e != NULL) {
1746
+	    	var_dump($e);
1747
+	    }
1292 1748
 	    if ($n > 0) {
1293 1749
 		$reset = 0;
1294 1750
 		foreach ($read as $nb => $r) {
@@ -1309,12 +1765,16 @@  discard block
 block discarded – undo
1309 1765
 		    //$SI::del();
1310 1766
 		    if ($format == 'vrstcp') {
1311 1767
 			$buffer = explode('},{',$buffer);
1312
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1768
+		    } else {
1769
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1770
+		    }
1313 1771
 		    // SBS format is CSV format
1314 1772
 		    if ($buffer !== FALSE && $buffer != '') {
1315 1773
 			$tt[$format] = 0;
1316 1774
 			if ($format == 'acarssbs3') {
1317
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1775
+			    if ($globalDebug) {
1776
+			    	echo 'ACARS : '.$buffer."\n";
1777
+			    }
1318 1778
 			    $ACARS->add(trim($buffer));
1319 1779
 			    $ACARS->deleteLiveAcarsData();
1320 1780
 			} elseif ($format == 'raw') {
@@ -1323,30 +1783,70 @@  discard block
 block discarded – undo
1323 1783
 			    if (is_array($data)) {
1324 1784
 				$data['datetime'] = date('Y-m-d H:i:s');
1325 1785
 				$data['format_source'] = 'raw';
1326
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1327
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1328
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1329
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1786
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1787
+					$data['source_name'] = $globalSources[$nb]['name'];
1788
+				}
1789
+				if (isset($globalSources[$nb]['sourcestats'])) {
1790
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1791
+				}
1792
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1793
+					$data['noarchive'] = true;
1794
+				}
1795
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1796
+					$SI->add($data);
1797
+				}
1330 1798
 			    }
1331 1799
 			} elseif ($format == 'ais') {
1332 1800
 			    $ais_data = $AIS->parse_line(trim($buffer));
1333 1801
 			    $data = array();
1334
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1335
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1336
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1337
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1338
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1339
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1340
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1341
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1342
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1343
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1344
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1345
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1346
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1347
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1348
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1349
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1802
+			    if (isset($ais_data['ident'])) {
1803
+			    	$data['ident'] = $ais_data['ident'];
1804
+			    }
1805
+			    if (isset($ais_data['mmsi'])) {
1806
+			    	$data['mmsi'] = $ais_data['mmsi'];
1807
+			    }
1808
+			    if (isset($ais_data['speed'])) {
1809
+			    	$data['speed'] = $ais_data['speed'];
1810
+			    }
1811
+			    if (isset($ais_data['heading'])) {
1812
+			    	$data['heading'] = $ais_data['heading'];
1813
+			    }
1814
+			    if (isset($ais_data['latitude'])) {
1815
+			    	$data['latitude'] = $ais_data['latitude'];
1816
+			    }
1817
+			    if (isset($ais_data['longitude'])) {
1818
+			    	$data['longitude'] = $ais_data['longitude'];
1819
+			    }
1820
+			    if (isset($ais_data['status'])) {
1821
+			    	$data['status'] = $ais_data['status'];
1822
+			    }
1823
+			    if (isset($ais_data['statusid'])) {
1824
+			    	$data['status_id'] = $ais_data['statusid'];
1825
+			    }
1826
+			    if (isset($ais_data['type'])) {
1827
+			    	$data['type'] = $ais_data['type'];
1828
+			    }
1829
+			    if (isset($ais_data['imo'])) {
1830
+			    	$data['imo'] = $ais_data['imo'];
1831
+			    }
1832
+			    if (isset($ais_data['callsign'])) {
1833
+			    	$data['callsign'] = $ais_data['callsign'];
1834
+			    }
1835
+			    if (isset($ais_data['destination'])) {
1836
+			    	$data['arrival_code'] = $ais_data['destination'];
1837
+			    }
1838
+			    if (isset($ais_data['eta_ts'])) {
1839
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1840
+			    }
1841
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1842
+			    	$data['noarchive'] = true;
1843
+			    }
1844
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1845
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1846
+			    }
1847
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1848
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1849
+			    }
1350 1850
 
1351 1851
 			    if (isset($ais_data['timestamp'])) {
1352 1852
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1355,7 +1855,9 @@  discard block
 block discarded – undo
1355 1855
 			    }
1356 1856
 			    $data['format_source'] = 'aisnmea';
1357 1857
     			    $data['id_source'] = $id_source;
1358
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1858
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1859
+			    	$MI->add($data);
1860
+			    }
1359 1861
 			    unset($data);
1360 1862
                         } elseif ($format == 'flightgearsp') {
1361 1863
                     	    //echo $buffer."\n";
@@ -1373,12 +1875,18 @@  discard block
 block discarded – undo
1373 1875
 				$data['speed'] = round($line[5]*1.94384);
1374 1876
 				$data['datetime'] = date('Y-m-d H:i:s');
1375 1877
 				$data['format_source'] = 'flightgearsp';
1376
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1377
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1878
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1879
+					$data['noarchive'] = true;
1880
+				}
1881
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1882
+					$SI->add($data);
1883
+				}
1378 1884
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1379 1885
 			    }
1380 1886
                         } elseif ($format == 'acars') {
1381
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1887
+                    	    if ($globalDebug) {
1888
+                    	    	echo 'ACARS : '.$buffer."\n";
1889
+                    	    }
1382 1890
 			    $ACARS->add(trim($buffer));
1383 1891
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1384 1892
 			    $ACARS->deleteLiveAcarsData();
@@ -1399,8 +1907,12 @@  discard block
 block discarded – undo
1399 1907
 				    $aircraft_type = $line[10];
1400 1908
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1401 1909
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1402
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1910
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1911
+				    	$data['noarchive'] = true;
1912
+				    }
1913
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1914
+				    	$SI->add($data);
1915
+				    }
1404 1916
 				}
1405 1917
 			    }
1406 1918
 			} elseif ($format == 'beast') {
@@ -1410,28 +1922,62 @@  discard block
 block discarded – undo
1410 1922
 			    foreach($buffer as $all_data) {
1411 1923
 				$line = json_decode('{'.$all_data.'}',true);
1412 1924
 				$data = array();
1413
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1414
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1415
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1416
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1417
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1418
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1419
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1925
+				if (isset($line['Icao'])) {
1926
+					$data['hex'] = $line['Icao'];
1927
+				}
1928
+				// hex
1929
+				if (isset($line['Call'])) {
1930
+					$data['ident'] = $line['Call'];
1931
+				}
1932
+				// ident
1933
+				if (isset($line['Alt'])) {
1934
+					$data['altitude'] = $line['Alt'];
1935
+				}
1936
+				// altitude
1937
+				if (isset($line['Spd'])) {
1938
+					$data['speed'] = $line['Spd'];
1939
+				}
1940
+				// speed
1941
+				if (isset($line['Trak'])) {
1942
+					$data['heading'] = $line['Trak'];
1943
+				}
1944
+				// heading
1945
+				if (isset($line['Lat'])) {
1946
+					$data['latitude'] = $line['Lat'];
1947
+				}
1948
+				// lat
1949
+				if (isset($line['Long'])) {
1950
+					$data['longitude'] = $line['Long'];
1951
+				}
1952
+				// long
1420 1953
 				//$data['verticalrate'] = $line['']; // verticale rate
1421
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1954
+				if (isset($line['Sqk'])) {
1955
+					$data['squawk'] = $line['Sqk'];
1956
+				}
1957
+				// squawk
1422 1958
 				$data['emergency'] = ''; // emergency
1423
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1959
+				if (isset($line['Reg'])) {
1960
+					$data['registration'] = $line['Reg'];
1961
+				}
1424 1962
 				/*
1425 1963
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1426 1964
 				else $data['datetime'] = date('Y-m-d H:i:s');
1427 1965
 				*/
1428 1966
 				$data['datetime'] = date('Y-m-d H:i:s');
1429
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1967
+				if (isset($line['Type'])) {
1968
+					$data['aircraft_icao'] = $line['Type'];
1969
+				}
1430 1970
 		    		$data['format_source'] = 'vrstcp';
1431 1971
 				$data['id_source'] = $id_source;
1432
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1433
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1434
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1972
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1973
+					$data['noarchive'] = true;
1974
+				}
1975
+				if (isset($value['name']) && $value['name'] != '') {
1976
+					$data['source_name'] = $value['name'];
1977
+				}
1978
+				if (isset($data['latitude']) && isset($data['hex'])) {
1979
+					$SI->add($data);
1980
+				}
1435 1981
 				unset($data);
1436 1982
 			    }
1437 1983
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1444,22 +1990,46 @@  discard block
 block discarded – undo
1444 1990
     				$data['hex'] = $lined['hexid'];
1445 1991
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1446 1992
     				$data['datetime'] = date('Y-m-d H:i:s');;
1447
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1448
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1449
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1450
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1451
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1452
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1453
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1993
+    				if (isset($lined['ident'])) {
1994
+    					$data['ident'] = $lined['ident'];
1995
+    				}
1996
+    				if (isset($lined['lat'])) {
1997
+    					$data['latitude'] = $lined['lat'];
1998
+    				}
1999
+    				if (isset($lined['lon'])) {
2000
+    					$data['longitude'] = $lined['lon'];
2001
+    				}
2002
+    				if (isset($lined['speed'])) {
2003
+    					$data['speed'] = $lined['speed'];
2004
+    				}
2005
+    				if (isset($lined['squawk'])) {
2006
+    					$data['squawk'] = $lined['squawk'];
2007
+    				}
2008
+    				if (isset($lined['alt'])) {
2009
+    					$data['altitude'] = $lined['alt'];
2010
+    				}
2011
+    				if (isset($lined['heading'])) {
2012
+    					$data['heading'] = $lined['heading'];
2013
+    				}
1454 2014
     				$data['id_source'] = $id_source;
1455 2015
     				$data['format_source'] = 'tsv';
1456
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1457
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1458
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1459
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2016
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2017
+    					$data['source_name'] = $globalSources[$nb]['name'];
2018
+    				}
2019
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2020
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2021
+    				}
2022
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2023
+					$data['noarchive'] = true;
2024
+				}
2025
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2026
+    					$SI->add($data);
2027
+    				}
1460 2028
     				unset($lined);
1461 2029
     				unset($data);
1462
-    			    } else $error = true;
2030
+    			    } else {
2031
+    			    	$error = true;
2032
+    			    }
1463 2033
 			} elseif ($format == 'aprs' && $use_aprs) {
1464 2034
 			    if ($aprs_connect == 0) {
1465 2035
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1484,62 +2054,120 @@  discard block
 block discarded – undo
1484 2054
 				    $aprs_last_tx = time();
1485 2055
 				    $data = array();
1486 2056
 				    //print_r($line);
1487
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1488
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1489
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1490
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1491
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1492
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1493
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1494
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1495
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1496
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2057
+				    if (isset($line['address'])) {
2058
+				    	$data['hex'] = $line['address'];
2059
+				    }
2060
+				    if (isset($line['mmsi'])) {
2061
+				    	$data['mmsi'] = $line['mmsi'];
2062
+				    }
2063
+				    if (isset($line['imo'])) {
2064
+				    	$data['imo'] = $line['imo'];
2065
+				    }
2066
+				    if (isset($line['squawk'])) {
2067
+				    	$data['squawk'] = $line['squawk'];
2068
+				    }
2069
+				    if (isset($line['arrival_code'])) {
2070
+				    	$data['arrical_code'] = $line['arrival_code'];
2071
+				    }
2072
+				    if (isset($line['arrival_date'])) {
2073
+				    	$data['arrical_date'] = $line['arrival_date'];
2074
+				    }
2075
+				    if (isset($line['type_id'])) {
2076
+				    	$data['type_id'] = $line['typeid'];
2077
+				    }
2078
+				    if (isset($line['status_id'])) {
2079
+				    	$data['status_id'] = $line['statusid'];
2080
+				    }
2081
+				    if (isset($line['timestamp'])) {
2082
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2083
+				    } else {
2084
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2085
+				    }
1497 2086
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1498
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2087
+				    if (isset($line['ident'])) {
2088
+				    	$data['ident'] = $line['ident'];
2089
+				    }
1499 2090
 				    $data['latitude'] = $line['latitude'];
1500 2091
 				    $data['longitude'] = $line['longitude'];
1501 2092
 				    //$data['verticalrate'] = $line[16];
1502
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2093
+				    if (isset($line['speed'])) {
2094
+				    	$data['speed'] = $line['speed'];
2095
+				    }
1503 2096
 				    //else $data['speed'] = 0;
1504
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1505
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1506
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2097
+				    if (isset($line['altitude'])) {
2098
+				    	$data['altitude'] = $line['altitude'];
2099
+				    }
2100
+				    if (isset($line['comment'])) {
2101
+				    	$data['comment'] = $line['comment'];
2102
+				    }
2103
+				    if (isset($line['symbol'])) {
2104
+				    	$data['type'] = $line['symbol'];
2105
+				    }
1507 2106
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1508 2107
 				    
1509
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2108
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2109
+				    	$data['heading'] = $line['heading'];
2110
+				    }
1510 2111
 				    //else echo 'No heading...'."\n";
1511 2112
 				    //else $data['heading'] = 0;
1512
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2113
+				    if (isset($line['stealth'])) {
2114
+				    	$data['aircraft_type'] = $line['stealth'];
2115
+				    }
1513 2116
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1514
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1515
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1516
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1517
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2117
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2118
+				    	$data['noarchive'] = true;
2119
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2120
+				    	$data['noarchive'] = false;
2121
+				    }
2122
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2123
+				    	$data['noarchive'] = true;
2124
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2125
+				    	$data['noarchive'] = false;
2126
+				    }
1518 2127
     				    $data['id_source'] = $id_source;
1519
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1520
-				    else $data['format_source'] = 'aprs';
2128
+    				    if (isset($line['format_source'])) {
2129
+    				    	$data['format_source'] = $line['format_source'];
2130
+    				    } else {
2131
+				    	$data['format_source'] = 'aprs';
2132
+				    }
1521 2133
 				    $data['source_name'] = $line['source'];
1522
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1523
-				    else $data['source_type'] = 'flarm';
1524
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2134
+				    if (isset($line['source_type'])) {
2135
+				    	$data['source_type'] = $line['source_type'];
2136
+				    } else {
2137
+				    	$data['source_type'] = 'flarm';
2138
+				    }
2139
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2140
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2141
+    				    }
1525 2142
 				    $currentdate = date('Y-m-d H:i:s');
1526 2143
 				    $aprsdate = strtotime($data['datetime']);
1527
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2144
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2145
+				    	$data['altitude_relative'] = 'AMSL';
2146
+				    }
1528 2147
 				    // Accept data if time <= system time + 20s
1529 2148
 				    //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'])))) {
1530 2149
 				    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'])))) {
1531 2150
 					$send = $SI->add($data);
1532 2151
 				    } elseif ($data['source_type'] == 'ais') {
1533
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2152
+					if (isset($globalMarine) && $globalMarine) {
2153
+						$send = $MI->add($data);
2154
+					}
1534 2155
 				    } elseif (isset($line['stealth'])) {
1535
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1536
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2156
+					if ($line['stealth'] != 0) {
2157
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2158
+					} else {
2159
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2160
+					}
1537 2161
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1538 2162
 					    //$line['symbol'] == 'Balloon' ||
1539 2163
 					    $line['symbol'] == 'Glider' || 
1540 2164
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1541
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1542
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2165
+					    if ($line['symbol'] == 'Ballon') {
2166
+					    	$data['aircraft_icao'] = 'BALL';
2167
+					    }
2168
+					    if ($line['symbol'] == 'Glider') {
2169
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2170
+					    }
1543 2171
 					    $send = $SI->add($data);
1544 2172
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1545 2173
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1570,9 +2198,13 @@  discard block
 block discarded – undo
1570 2198
 				    //} 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') {
1571 2199
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $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') {
1572 2200
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1573
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2201
+					if (isset($globalTracker) && $globalTracker) {
2202
+						$send = $TI->add($data);
2203
+					}
1574 2204
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1575
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2205
+					if (!isset($data['altitude'])) {
2206
+						$data['altitude'] = 0;
2207
+					}
1576 2208
 					$Source->deleteOldLocationByType('gs');
1577 2209
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1578 2210
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1581,7 +2213,9 @@  discard block
 block discarded – undo
1581 2213
 					}
1582 2214
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1583 2215
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1584
-					if ($globalDebug) echo '# Weather Station added'."\n";
2216
+					if ($globalDebug) {
2217
+						echo '# Weather Station added'."\n";
2218
+					}
1585 2219
 					$Source->deleteOldLocationByType('wx');
1586 2220
 					$weather_data = json_encode($line);
1587 2221
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1591,7 +2225,9 @@  discard block
 block discarded – undo
1591 2225
 					}
1592 2226
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1593 2227
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1594
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2228
+					if ($globalDebug) {
2229
+						echo '☈ Lightning added'."\n";
2230
+					}
1595 2231
 					$Source->deleteOldLocationByType('lightning');
1596 2232
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1597 2233
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1603,8 +2239,7 @@  discard block
 block discarded – undo
1603 2239
 				    	print_r($line);
1604 2240
 				    }
1605 2241
 				    unset($data);
1606
-				}
1607
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2242
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1608 2243
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1609 2244
 				}
1610 2245
 				/*
@@ -1613,7 +2248,9 @@  discard block
 block discarded – undo
1613 2248
 				}
1614 2249
 				*/
1615 2250
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1616
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2251
+				elseif ($line == true && $globalDebug) {
2252
+					echo '!! Failed : '.$buffer."!!\n";
2253
+				}
1617 2254
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1618 2255
 					$Source->deleteOldLocationByType('lightning');
1619 2256
 					$Source->deleteOldLocationByType('wx');
@@ -1649,26 +2286,45 @@  discard block
 block discarded – undo
1649 2286
     				$data['ground'] = $line[21];
1650 2287
     				$data['emergency'] = $line[19];
1651 2288
     				$data['format_source'] = 'sbs';
1652
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1653
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1654
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2289
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2290
+					$data['source_name'] = $globalSources[$nb]['name'];
2291
+				}
2292
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2293
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2294
+    				}
2295
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2296
+					$data['noarchive'] = true;
2297
+				}
1655 2298
     				$data['id_source'] = $id_source;
1656
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1657
-    				else $error = true;
2299
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2300
+    					$send = $SI->add($data);
2301
+    				} else {
2302
+    					$error = true;
2303
+    				}
1658 2304
     				unset($data);
1659
-    			    } else $error = true;
2305
+    			    } else {
2306
+    			    	$error = true;
2307
+    			    }
1660 2308
 			    if ($error) {
1661 2309
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1662
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2310
+					if ($globalDebug) {
2311
+						echo "Not a message. Ignoring... \n";
2312
+					}
1663 2313
 				} else {
1664
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2314
+					if ($globalDebug) {
2315
+						echo "Wrong line format. Ignoring... \n";
2316
+					}
1665 2317
 					if ($globalDebug) {
1666 2318
 						echo $buffer;
1667 2319
 						//print_r($line);
1668 2320
 					}
1669 2321
 					//socket_close($r);
1670
-					if ($globalDebug) echo "Reconnect after an error...\n";
1671
-					if ($format == 'aprs') $aprs_connect = 0;
2322
+					if ($globalDebug) {
2323
+						echo "Reconnect after an error...\n";
2324
+					}
2325
+					if ($format == 'aprs') {
2326
+						$aprs_connect = 0;
2327
+					}
1672 2328
 					$sourceer[$nb] = $globalSources[$nb];
1673 2329
 					connect_all($sourceer);
1674 2330
 					$sourceer = array();
@@ -1676,10 +2332,14 @@  discard block
 block discarded – undo
1676 2332
 			    }
1677 2333
 			}
1678 2334
 			// Sleep for xxx microseconds
1679
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2335
+			if (isset($globalSBSSleep)) {
2336
+				usleep($globalSBSSleep);
2337
+			}
1680 2338
 		    } else {
1681 2339
 			if ($format == 'flightgearmp') {
1682
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2340
+			    	if ($globalDebug) {
2341
+			    		echo "Reconnect FlightGear MP...";
2342
+			    	}
1683 2343
 				//@socket_close($r);
1684 2344
 				sleep($globalMinFetch);
1685 2345
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1688,10 +2348,15 @@  discard block
 block discarded – undo
1688 2348
 				break;
1689 2349
 				
1690 2350
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1691
-			    if (isset($tt[$format])) $tt[$format]++;
1692
-			    else $tt[$format] = 0;
2351
+			    if (isset($tt[$format])) {
2352
+			    	$tt[$format]++;
2353
+			    } else {
2354
+			    	$tt[$format] = 0;
2355
+			    }
1693 2356
 			    if ($tt[$format] > 30) {
1694
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2357
+				if ($globalDebug) {
2358
+					echo "ERROR : Reconnect ".$format."...";
2359
+				}
1695 2360
 				//@socket_close($r);
1696 2361
 				sleep(2);
1697 2362
 				$aprs_connect = 0;
@@ -1708,11 +2373,17 @@  discard block
 block discarded – undo
1708 2373
 	    } else {
1709 2374
 		$error = socket_strerror(socket_last_error());
1710 2375
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1711
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1712
-			if (isset($globalDebug)) echo "Restarting...\n";
2376
+			if ($globalDebug) {
2377
+				echo "ERROR : socket_select give this error ".$error . "\n";
2378
+			}
2379
+			if (isset($globalDebug)) {
2380
+				echo "Restarting...\n";
2381
+			}
1713 2382
 			// Restart the script if possible
1714 2383
 			if (is_array($sockets)) {
1715
-			    if ($globalDebug) echo "Shutdown all sockets...";
2384
+			    if ($globalDebug) {
2385
+			    	echo "Shutdown all sockets...";
2386
+			    }
1716 2387
 			    
1717 2388
 			    foreach ($sockets as $sock) {
1718 2389
 				@socket_shutdown($sock,2);
@@ -1720,25 +2391,45 @@  discard block
 block discarded – undo
1720 2391
 			    }
1721 2392
 			    
1722 2393
 			}
1723
-			if ($globalDebug) echo "Waiting...";
2394
+			if ($globalDebug) {
2395
+				echo "Waiting...";
2396
+			}
1724 2397
 			sleep(2);
1725 2398
 			$time = time();
1726 2399
 			//connect_all($hosts);
1727 2400
 			$aprs_connect = 0;
1728
-			if ($reset%5 == 0) sleep(20);
1729
-			if ($reset%10 == 0) sleep(100);
1730
-			if ($reset%20 == 0) sleep(200);
1731
-			if ($reset > 100) exit('Too many attempts...');
1732
-			if ($globalDebug) echo "Restart all connections...";
2401
+			if ($reset%5 == 0) {
2402
+				sleep(20);
2403
+			}
2404
+			if ($reset%10 == 0) {
2405
+				sleep(100);
2406
+			}
2407
+			if ($reset%20 == 0) {
2408
+				sleep(200);
2409
+			}
2410
+			if ($reset > 100) {
2411
+				exit('Too many attempts...');
2412
+			}
2413
+			if ($globalDebug) {
2414
+				echo "Restart all connections...";
2415
+			}
1733 2416
 			connect_all($globalSources);
1734 2417
 		}
1735 2418
 	    }
1736 2419
 	}
1737 2420
 	if ($globalDaemon === false) {
1738
-	    if ($globalDebug) echo 'Check all...'."\n";
1739
-	    if (isset($SI)) $SI->checkAll();
1740
-	    if (isset($TI)) $TI->checkAll();
1741
-	    if (isset($MI)) $MI->checkAll();
2421
+	    if ($globalDebug) {
2422
+	    	echo 'Check all...'."\n";
2423
+	    }
2424
+	    if (isset($SI)) {
2425
+	    	$SI->checkAll();
2426
+	    }
2427
+	    if (isset($TI)) {
2428
+	    	$TI->checkAll();
2429
+	    }
2430
+	    if (isset($MI)) {
2431
+	    	$MI->checkAll();
2432
+	    }
1742 2433
 	}
1743 2434
     }
1744 2435
 }
Please login to merge, or discard this patch.