Completed
Push — master ( ee3831...b6b651 )
by Yannick
33:24
created
scripts/daemon-spotter.php 1 patch
Indentation   +1091 added lines, -1091 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;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 if (isset($options['idsource'])) $id_source = $options['idsource'];
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
106
+	if ($globalDebug) echo "Using Server Mode\n";
107
+	$SI=new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
117
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
117
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 119
 }
120 120
 
121 121
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
122 122
 if (isset($globalMarine) && $globalMarine) {
123
-    $AIS = new AIS();
124
-    $MI = new MarineImport($Connection->db);
123
+	$AIS = new AIS();
124
+	$MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127 127
 $SBS=new SBS();
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
138
-        global $sockets;
139
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
-        die("Bye!\n");
141
-    });
142
-    pcntl_signal_dispatch();
137
+	pcntl_signal(SIGINT,  function() {
138
+		global $sockets;
139
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
+		die("Bye!\n");
141
+	});
142
+	pcntl_signal_dispatch();
143 143
 }
144 144
 
145 145
 // let's try and connect
@@ -149,46 +149,46 @@  discard block
 block discarded – undo
149 149
 $reset = 0;
150 150
 
151 151
 function connect_all($hosts) {
152
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
-    $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
156
-    foreach ($hosts as $id => $value) {
152
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
+	$reset++;
155
+	if ($globalDebug) echo 'Connect to all...'."\n";
156
+	foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160 160
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
162
-        	//$formats[$id] = 'deltadbtxt';
163
-        	$globalSources[$id]['format'] = 'deltadbtxt';
164
-        	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
-        	//$formats[$id] = 'vatsimtxt';
168
-        	$globalSources[$id]['format'] = 'vatsimtxt';
169
-        	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172
-        	//$formats[$id] = 'aircraftlistjson';
173
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
174
-        	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
177
-        	//$formats[$id] = 'aircraftjson';
178
-        	$globalSources[$id]['format'] = 'aircraftjson';
179
-        	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
182
-        	//$formats[$id] = 'planefinderclient';
183
-        	$globalSources[$id]['format'] = 'planefinderclient';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
187
-        	//$formats[$id] = 'aircraftlistjson';
188
-        	$globalSources[$id]['format'] = 'opensky';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
191
-    	    /*
161
+			if (preg_match('/deltadb.txt$/i',$host)) {
162
+			//$formats[$id] = 'deltadbtxt';
163
+			$globalSources[$id]['format'] = 'deltadbtxt';
164
+			//$last_exec['deltadbtxt'] = 0;
165
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
+			//$formats[$id] = 'vatsimtxt';
168
+			$globalSources[$id]['format'] = 'vatsimtxt';
169
+			//$last_exec['vatsimtxt'] = 0;
170
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
172
+			//$formats[$id] = 'aircraftlistjson';
173
+			$globalSources[$id]['format'] = 'aircraftlistjson';
174
+			//$last_exec['aircraftlistjson'] = 0;
175
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
+			} else if (preg_match('/aircraft.json$/i',$host)) {
177
+			//$formats[$id] = 'aircraftjson';
178
+			$globalSources[$id]['format'] = 'aircraftjson';
179
+			//$last_exec['aircraftlistjson'] = 0;
180
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
+			} else if (preg_match('/aircraft$/i',$host)) {
182
+			//$formats[$id] = 'planefinderclient';
183
+			$globalSources[$id]['format'] = 'planefinderclient';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
+			} else if (preg_match('/opensky/i',$host)) {
187
+			//$formats[$id] = 'aircraftlistjson';
188
+			$globalSources[$id]['format'] = 'opensky';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
191
+			/*
192 192
     	    // Disabled for now, site change source format
193 193
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
194 194
         	//$formats[$id] = 'radarvirtueljson';
@@ -200,127 +200,127 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
204
-        	//$formats[$id] = 'planeupdatefaa';
205
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
206
-        	//$last_exec['planeupdatefaa'] = 0;
207
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
208
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210
-        	    exit(0);
211
-        	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
213
-        	//$formats[$id] = 'phpvmacars';
214
-        	$globalSources[$id]['format'] = 'phpvmacars';
215
-        	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218
-        	//$formats[$id] = 'phpvmacars';
219
-        	$globalSources[$id]['format'] = 'vaos';
220
-        	//$last_exec['phpvmacars'] = 0;
221
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'vam';
225
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
227
-        	//$formats[$id] = 'whazzup';
228
-        	$globalSources[$id]['format'] = 'whazzup';
229
-        	//$last_exec['whazzup'] = 0;
230
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
232
-        	$globalSources[$id]['format'] = 'blitzortung';
233
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
235
-        	$globalSources[$id]['format'] = 'airwhere';
236
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
238
-        	//$formats[$id] = 'pirepsjson';
239
-        	$globalSources[$id]['format'] = 'pirepsjson';
240
-        	//$last_exec['pirepsjson'] = 0;
241
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243
-        	//$formats[$id] = 'fr24json';
244
-        	$globalSources[$id]['format'] = 'fr24json';
245
-        	//$last_exec['fr24json'] = 0;
246
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
247
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249
-        	    exit(0);
250
-        	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
252
-        	//$formats[$id] = 'fr24json';
253
-        	$globalSources[$id]['format'] = 'myshiptracking';
254
-        	//$last_exec['fr24json'] = 0;
255
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
256
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258
-        	    exit(0);
259
-        	}
260
-            //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262
-        	//$formats[$id] = 'tsv';
263
-        	$globalSources[$id]['format'] = 'tsv';
264
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265
-            }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
267
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
269
-    		    if ($idf !== false) {
270
-    			$httpfeeds[$id] = $idf;
271
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
274
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
275
-	    $hostport = explode(':',$host);
276
-	    if (isset($hostport[1])) {
203
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
204
+			//$formats[$id] = 'planeupdatefaa';
205
+			$globalSources[$id]['format'] = 'planeupdatefaa';
206
+			//$last_exec['planeupdatefaa'] = 0;
207
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
208
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210
+				exit(0);
211
+			}
212
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
213
+			//$formats[$id] = 'phpvmacars';
214
+			$globalSources[$id]['format'] = 'phpvmacars';
215
+			//$last_exec['phpvmacars'] = 0;
216
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218
+			//$formats[$id] = 'phpvmacars';
219
+			$globalSources[$id]['format'] = 'vaos';
220
+			//$last_exec['phpvmacars'] = 0;
221
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'vam';
225
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
+			} else if (preg_match('/whazzup/i',$host)) {
227
+			//$formats[$id] = 'whazzup';
228
+			$globalSources[$id]['format'] = 'whazzup';
229
+			//$last_exec['whazzup'] = 0;
230
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
+			} else if (preg_match('/blitzortung/i',$host)) {
232
+			$globalSources[$id]['format'] = 'blitzortung';
233
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
+			} else if (preg_match('/airwhere/i',$host)) {
235
+			$globalSources[$id]['format'] = 'airwhere';
236
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
+			} else if (preg_match('/recentpireps/i',$host)) {
238
+			//$formats[$id] = 'pirepsjson';
239
+			$globalSources[$id]['format'] = 'pirepsjson';
240
+			//$last_exec['pirepsjson'] = 0;
241
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243
+			//$formats[$id] = 'fr24json';
244
+			$globalSources[$id]['format'] = 'fr24json';
245
+			//$last_exec['fr24json'] = 0;
246
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
247
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249
+				exit(0);
250
+			}
251
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
252
+			//$formats[$id] = 'fr24json';
253
+			$globalSources[$id]['format'] = 'myshiptracking';
254
+			//$last_exec['fr24json'] = 0;
255
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
256
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258
+				exit(0);
259
+			}
260
+			//} else if (preg_match('/10001/',$host)) {
261
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262
+			//$formats[$id] = 'tsv';
263
+			$globalSources[$id]['format'] = 'tsv';
264
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265
+			}
266
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
267
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
269
+				if ($idf !== false) {
270
+				$httpfeeds[$id] = $idf;
271
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
274
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
275
+		$hostport = explode(':',$host);
276
+		if (isset($hostport[1])) {
277 277
 		$port = $hostport[1];
278 278
 		$hostn = $hostport[0];
279
-	    } else {
279
+		} else {
280 280
 		$port = $globalSources[$id]['port'];
281 281
 		$hostn = $globalSources[$id]['host'];
282
-	    }
283
-	    $Common = new Common();
284
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
285
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
286
-    	    } else {
287
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
288
-	    }
289
-	    if ($s) {
290
-    	        $sockets[$id] = $s;
291
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
292
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
282
+		}
283
+		$Common = new Common();
284
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
285
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
286
+			} else {
287
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
288
+		}
289
+		if ($s) {
290
+				$sockets[$id] = $s;
291
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
292
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
293 293
 			//$formats[$id] = 'aprs';
294 294
 			$globalSources[$id]['format'] = 'aprs';
295 295
 			//$aprs_connect = 0;
296 296
 			//$use_aprs = true;
297
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
297
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
298 298
 			$globalSources[$id]['format'] = 'vrstcp';
299
-    		    } elseif ($port == '10001') {
300
-        		//$formats[$id] = 'tsv';
301
-        		$globalSources[$id]['format'] = 'tsv';
302
-		    } elseif ($port == '30002') {
303
-        		//$formats[$id] = 'raw';
304
-        		$globalSources[$id]['format'] = 'raw';
305
-		    } elseif ($port == '5001') {
306
-        		//$formats[$id] = 'raw';
307
-        		$globalSources[$id]['format'] = 'flightgearmp';
308
-		    } elseif ($port == '30005') {
299
+				} elseif ($port == '10001') {
300
+				//$formats[$id] = 'tsv';
301
+				$globalSources[$id]['format'] = 'tsv';
302
+			} elseif ($port == '30002') {
303
+				//$formats[$id] = 'raw';
304
+				$globalSources[$id]['format'] = 'raw';
305
+			} elseif ($port == '5001') {
306
+				//$formats[$id] = 'raw';
307
+				$globalSources[$id]['format'] = 'flightgearmp';
308
+			} elseif ($port == '30005') {
309 309
 			// Not yet supported
310
-        		//$formats[$id] = 'beast';
311
-        		$globalSources[$id]['format'] = 'beast';
312
-		    //} else $formats[$id] = 'sbs';
313
-		    } else $globalSources[$id]['format'] = 'sbs';
314
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
310
+				//$formats[$id] = 'beast';
311
+				$globalSources[$id]['format'] = 'beast';
312
+			//} else $formats[$id] = 'sbs';
313
+			} else $globalSources[$id]['format'] = 'sbs';
314
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
315 315
 		}
316 316
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
317
-            } else {
317
+			} else {
318 318
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
319 319
 		sleep(10);
320 320
 		connect_all($hosts);
321
-    	    }
322
-        }
323
-    }
321
+			}
322
+		}
323
+	}
324 324
 }
325 325
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
326 326
 
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 //connect_all($globalSources);
344 344
 
345 345
 if (isset($globalProxy) && $globalProxy) {
346
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
346
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
347 347
 } else {
348
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
348
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
349 349
 }
350 350
 
351 351
 // APRS Configuration
@@ -354,21 +354,21 @@  discard block
 block discarded – undo
354 354
 	die;
355 355
 }
356 356
 foreach ($globalSources as $key => $source) {
357
-    if (!isset($source['format'])) {
358
-        $globalSources[$key]['format'] = 'auto';
359
-    }
360
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
361
-        unset($globalSources[$key]);
362
-    }
357
+	if (!isset($source['format'])) {
358
+		$globalSources[$key]['format'] = 'auto';
359
+	}
360
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
361
+		unset($globalSources[$key]);
362
+	}
363 363
 }
364 364
 connect_all($globalSources);
365 365
 foreach ($globalSources as $key => $source) {
366
-    if (isset($source['format']) && $source['format'] == 'aprs') {
366
+	if (isset($source['format']) && $source['format'] == 'aprs') {
367 367
 	$aprs_connect = 0;
368 368
 	$use_aprs = true;
369 369
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
370 370
 	break;
371
-    }
371
+	}
372 372
 }
373 373
 
374 374
 if ($use_aprs) {
@@ -409,133 +409,133 @@  discard block
 block discarded – undo
409 409
 
410 410
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
411 411
 while ($i > 0) {
412
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
412
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
413 413
 
414
-    if (!$globalDaemon) $i = $endtime-time();
415
-    // Delete old ATC
416
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
414
+	if (!$globalDaemon) $i = $endtime-time();
415
+	// Delete old ATC
416
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
417 417
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
418
-        $ATC->deleteOldATC();
419
-    }
418
+		$ATC->deleteOldATC();
419
+	}
420 420
     
421
-    if (count($last_exec) == count($globalSources)) {
421
+	if (count($last_exec) == count($globalSources)) {
422 422
 	$max = $globalMinFetch;
423 423
 	foreach ($last_exec as $last) {
424
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
424
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
425 425
 	}
426 426
 	if ($max < $globalMinFetch) {
427
-	    if ($globalDebug) echo 'Sleeping...'."\n";
428
-	    sleep($globalMinFetch-$max+2);
427
+		if ($globalDebug) echo 'Sleeping...'."\n";
428
+		sleep($globalMinFetch-$max+2);
429
+	}
429 430
 	}
430
-    }
431 431
 
432 432
     
433
-    //foreach ($formats as $id => $value) {
434
-    foreach ($globalSources as $id => $value) {
433
+	//foreach ($formats as $id => $value) {
434
+	foreach ($globalSources as $id => $value) {
435 435
 	date_default_timezone_set('UTC');
436 436
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
437 437
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
438 438
 	if ($value['format'] === 'deltadbtxt' && 
439
-	    (
439
+		(
440 440
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
441 441
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
442
-	    )
442
+		)
443 443
 	) {
444
-	    //$buffer = $Common->getData($hosts[$id]);
445
-	    $buffer = $Common->getData($value['host']);
446
-	    if ($buffer != '') $reset = 0;
447
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
448
-	    $buffer = explode('\n',$buffer);
449
-	    foreach ($buffer as $line) {
450
-    		if ($line != '' && count($line) > 7) {
451
-    		    $line = explode(',', $line);
452
-	            $data = array();
453
-	            $data['hex'] = $line[1]; // hex
454
-	            $data['ident'] = $line[2]; // ident
455
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
456
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
457
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
458
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
459
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
460
-	            $data['verticalrate'] = ''; // vertical rate
461
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
462
-	            $data['emergency'] = ''; // emergency
463
-		    $data['datetime'] = date('Y-m-d H:i:s');
464
-		    $data['format_source'] = 'deltadbtxt';
465
-    		    $data['id_source'] = $id_source;
466
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
467
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
468
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
469
-    		    $SI->add($data);
470
-		    unset($data);
471
-    		}
472
-    	    }
473
-    	    $last_exec[$id]['last'] = time();
444
+		//$buffer = $Common->getData($hosts[$id]);
445
+		$buffer = $Common->getData($value['host']);
446
+		if ($buffer != '') $reset = 0;
447
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
448
+		$buffer = explode('\n',$buffer);
449
+		foreach ($buffer as $line) {
450
+			if ($line != '' && count($line) > 7) {
451
+				$line = explode(',', $line);
452
+				$data = array();
453
+				$data['hex'] = $line[1]; // hex
454
+				$data['ident'] = $line[2]; // ident
455
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
456
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
457
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
458
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
459
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
460
+				$data['verticalrate'] = ''; // vertical rate
461
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
462
+				$data['emergency'] = ''; // emergency
463
+			$data['datetime'] = date('Y-m-d H:i:s');
464
+			$data['format_source'] = 'deltadbtxt';
465
+				$data['id_source'] = $id_source;
466
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
467
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
468
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
469
+				$SI->add($data);
470
+			unset($data);
471
+			}
472
+			}
473
+			$last_exec[$id]['last'] = time();
474 474
 	} elseif ($value['format'] === 'aisnmeatxt' && 
475
-	    (
475
+		(
476 476
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
477 477
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
478
-	    )
478
+		)
479 479
 	) {
480
-	    date_default_timezone_set('CET');
481
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482
-	    date_default_timezone_set('UTC');
483
-	    if ($buffer != '') $reset = 0;
484
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
485
-	    $buffer = explode('\n',$buffer);
486
-	    foreach ($buffer as $line) {
480
+		date_default_timezone_set('CET');
481
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482
+		date_default_timezone_set('UTC');
483
+		if ($buffer != '') $reset = 0;
484
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
485
+		$buffer = explode('\n',$buffer);
486
+		foreach ($buffer as $line) {
487 487
 		if ($line != '') {
488
-		    //echo "'".$line."'\n";
489
-		    $add = false;
490
-		    $ais_data = $AIS->parse_line(trim($line));
491
-		    $data = array();
492
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
493
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
494
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
495
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
496
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
497
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
498
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
499
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
500
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
501
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
502
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
503
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
504
-		    if (isset($ais_data['timestamp'])) {
488
+			//echo "'".$line."'\n";
489
+			$add = false;
490
+			$ais_data = $AIS->parse_line(trim($line));
491
+			$data = array();
492
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
493
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
494
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
495
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
496
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
497
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
498
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
499
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
500
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
501
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
502
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
503
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
504
+			if (isset($ais_data['timestamp'])) {
505 505
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
506 506
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
507
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
508
-			    $add = true;
507
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
508
+				$add = true;
509 509
 			}
510
-		    } else {
510
+			} else {
511 511
 			$data['datetime'] = date('Y-m-d H:i:s');
512 512
 			$add = true;
513
-		    }
514
-		    $data['format_source'] = 'aisnmeatxt';
515
-    		    $data['id_source'] = $id_source;
516
-		    //print_r($data);
517
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
518
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
519
-		    unset($data);
513
+			}
514
+			$data['format_source'] = 'aisnmeatxt';
515
+				$data['id_source'] = $id_source;
516
+			//print_r($data);
517
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
518
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
519
+			unset($data);
520 520
 		}
521
-    	    }
522
-    	    $last_exec[$id]['last'] = time();
521
+			}
522
+			$last_exec[$id]['last'] = time();
523 523
 	} elseif ($value['format'] === 'aisnmeahttp') {
524
-	    $arr = $httpfeeds;
525
-	    $w = $e = null;
524
+		$arr = $httpfeeds;
525
+		$w = $e = null;
526 526
 	    
527
-	    if (isset($arr[$id])) {
527
+		if (isset($arr[$id])) {
528 528
 		$nn = stream_select($arr,$w,$e,$timeout);
529 529
 		if ($nn > 0) {
530
-		    foreach ($httpfeeds as $feed) {
530
+			foreach ($httpfeeds as $feed) {
531 531
 			$buffer = stream_get_line($feed,2000,"\n");
532 532
 			if ($buffer === FALSE) {
533
-			    connect_all($globalSources);
533
+				connect_all($globalSources);
534 534
 			}
535 535
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
536 536
 			$buffer = explode('\n',$buffer);
537 537
 			foreach ($buffer as $line) {
538
-			    if ($line != '') {
538
+				if ($line != '') {
539 539
 				$ais_data = $AIS->parse_line(trim($line));
540 540
 				$data = array();
541 541
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -553,117 +553,117 @@  discard block
 block discarded – undo
553 553
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
554 554
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
555 555
 				if (isset($ais_data['timestamp'])) {
556
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
556
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
557 557
 				} else {
558
-				    $data['datetime'] = date('Y-m-d H:i:s');
558
+					$data['datetime'] = date('Y-m-d H:i:s');
559 559
 				}
560 560
 				$data['format_source'] = 'aisnmeahttp';
561 561
 				$data['id_source'] = $id_source;
562 562
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
563 563
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
564 564
 				unset($data);
565
-			    }
565
+				}
566
+			}
566 567
 			}
567
-		    }
568 568
 		} else {
569
-		    $format = $value['format'];
570
-		    if (isset($tt[$format])) $tt[$format]++;
571
-		    else $tt[$format] = 0;
572
-		    if ($tt[$format] > 30) {
569
+			$format = $value['format'];
570
+			if (isset($tt[$format])) $tt[$format]++;
571
+			else $tt[$format] = 0;
572
+			if ($tt[$format] > 30) {
573 573
 			if ($globalDebug) echo 'Reconnect...'."\n";
574 574
 			sleep(2);
575 575
 			//$sourceeen[] = $value;
576 576
 			//connect_all($sourceeen);
577 577
 			//$sourceeen = array();
578 578
 			connect_all($globalSources);
579
-		    }
579
+			}
580
+		}
580 581
 		}
581
-	    }
582 582
 	} elseif ($value['format'] === 'myshiptracking' && 
583
-	    (
583
+		(
584 584
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
585 585
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
586
-	    )
586
+		)
587 587
 	) {
588
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
589
-	    if ($buffer != '') {
588
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
589
+		if ($buffer != '') {
590 590
 		//echo $buffer;
591 591
 		$all_data = json_decode($buffer,true);
592 592
 		//print_r($all_data);
593 593
 		if (isset($all_data[0]['DATA'])) {
594
-		    foreach ($all_data[0]['DATA'] as $line) {
594
+			foreach ($all_data[0]['DATA'] as $line) {
595 595
 			if ($line != '') {
596
-			    $data = array();
597
-			    $data['ident'] = $line['NAME'];
598
-			    $data['mmsi'] = $line['MMSI'];
599
-			    if (strlen($data['mmsi']) > 9) {
596
+				$data = array();
597
+				$data['ident'] = $line['NAME'];
598
+				$data['mmsi'] = $line['MMSI'];
599
+				if (strlen($data['mmsi']) > 9) {
600 600
 				$data['mmsi'] = substr($data['mmsi'],-9);
601
-			    }
602
-			    $data['speed'] = $line['SOG'];
603
-			    $data['heading'] = $line['COG'];
604
-			    $data['latitude'] = $line['LAT'];
605
-			    $data['longitude'] = $line['LNG'];
606
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
607
-			    //$data['type_id'] = $line['TYPE'];
608
-			    $data['imo'] = $line['IMO'];
609
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
610
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
611
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
612
-			    $data['format_source'] = 'myshiptracking';
613
-			    $data['id_source'] = $id_source;
614
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
615
-			    $MI->add($data);
616
-			    unset($data);
601
+				}
602
+				$data['speed'] = $line['SOG'];
603
+				$data['heading'] = $line['COG'];
604
+				$data['latitude'] = $line['LAT'];
605
+				$data['longitude'] = $line['LNG'];
606
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
607
+				//$data['type_id'] = $line['TYPE'];
608
+				$data['imo'] = $line['IMO'];
609
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
610
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
611
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
612
+				$data['format_source'] = 'myshiptracking';
613
+				$data['id_source'] = $id_source;
614
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
615
+				$MI->add($data);
616
+				unset($data);
617 617
 			}
618
-		    }
618
+			}
619
+		}
619 620
 		}
620
-	    }
621
-	    $last_exec[$id]['last'] = time();
621
+		$last_exec[$id]['last'] = time();
622 622
 	} elseif ($value['format'] === 'boatbeaconapp' && 
623
-	    (
623
+		(
624 624
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
625 625
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
626
-	    )
626
+		)
627 627
 	) {
628
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
629
-	    if ($buffer != '') {
628
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
629
+		if ($buffer != '') {
630 630
 		$all_data = json_decode($buffer,true);
631 631
 		if (isset($all_data[0]['mmsi'])) {
632
-		    foreach ($all_data as $line) {
632
+			foreach ($all_data as $line) {
633 633
 			if ($line != '') {
634
-			    $data = array();
635
-			    $data['ident'] = $line['shipname'];
636
-			    $data['callsign'] = $line['callsign'];
637
-			    $data['mmsi'] = substr($line['mmsi'],-9);
638
-			    $data['speed'] = $line['sog'];
639
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
640
-			    $data['latitude'] = $line['latitude'];
641
-			    $data['longitude'] = $line['longitude'];
642
-			    $data['type_id'] = $line['shiptype'];
643
-			    $data['arrival_code'] = $line['destination'];
644
-			    $data['datetime'] = $line['time'];
645
-			    $data['format_source'] = 'boatbeaconapp';
646
-			    $data['id_source'] = $id_source;
647
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
648
-			    $MI->add($data);
649
-			    unset($data);
634
+				$data = array();
635
+				$data['ident'] = $line['shipname'];
636
+				$data['callsign'] = $line['callsign'];
637
+				$data['mmsi'] = substr($line['mmsi'],-9);
638
+				$data['speed'] = $line['sog'];
639
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
640
+				$data['latitude'] = $line['latitude'];
641
+				$data['longitude'] = $line['longitude'];
642
+				$data['type_id'] = $line['shiptype'];
643
+				$data['arrival_code'] = $line['destination'];
644
+				$data['datetime'] = $line['time'];
645
+				$data['format_source'] = 'boatbeaconapp';
646
+				$data['id_source'] = $id_source;
647
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
648
+				$MI->add($data);
649
+				unset($data);
650
+			}
650 651
 			}
651
-		    }
652 652
 		}
653 653
 		
654
-	    }
655
-    	    $last_exec[$id]['last'] = time();
654
+		}
655
+			$last_exec[$id]['last'] = time();
656 656
 	} elseif ($value['format'] === 'boatnerd' && 
657
-	    (
657
+		(
658 658
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
659 659
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
660
-	    )
660
+		)
661 661
 	) {
662
-	    $buffer = $Common->getData($value['host']);
663
-	    if ($buffer != '') {
662
+		$buffer = $Common->getData($value['host']);
663
+		if ($buffer != '') {
664 664
 		$all_data = json_decode($buffer,true);
665 665
 		if (isset($all_data['features'][0]['id'])) {
666
-		    foreach ($all_data['features'] as $line) {
666
+			foreach ($all_data['features'] as $line) {
667 667
 			print_r($line);
668 668
 			$data = array();
669 669
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -683,80 +683,80 @@  discard block
 block discarded – undo
683 683
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
684 684
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
685 685
 			unset($data);
686
-		    }
686
+			}
687 687
 		}
688 688
 		
689
-	    }
690
-    	    $last_exec[$id]['last'] = time();
689
+		}
690
+			$last_exec[$id]['last'] = time();
691 691
 	} elseif ($value['format'] === 'shipplotter' && 
692
-	    (
692
+		(
693 693
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
694 694
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
695
-	    )
695
+		)
696 696
 	) {
697
-	    echo 'download...';
698
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699
-	    echo 'done !'."\n";
700
-	    // FIXME: Need more work
701
-	    if ($buffer != '') $reset = 0;
702
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
703
-	    $buffer = explode('\n',$buffer);
704
-	    foreach ($buffer as $line) {
697
+		echo 'download...';
698
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699
+		echo 'done !'."\n";
700
+		// FIXME: Need more work
701
+		if ($buffer != '') $reset = 0;
702
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
703
+		$buffer = explode('\n',$buffer);
704
+		foreach ($buffer as $line) {
705 705
 		if ($line != '') {
706
-		    $data = array();
707
-		    echo $line."\n";
708
-		    $data['mmsi'] = (int)substr($line,0,9);
709
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
710
-		    $data['status_id'] = substr($line,21,2);
711
-		    $data['type_id'] = substr($line,24,3);
712
-		    $data['latitude'] = substr($line,29,9);
713
-		    $data['longitude'] = substr($line,41,9);
714
-		    $data['speed'] = round(substr($line,51,5));
715
-		    //$data['course'] = substr($line,57,5);
716
-		    $data['heading'] = round(substr($line,63,3));
717
-		    //$data['draft'] = substr($line,67,4);
718
-		    //$data['length'] = substr($line,72,3);
719
-		    //$data['beam'] = substr($line,76,2);
720
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
721
-		    //$data['callsign'] = trim(substr($line,100,7);
722
-		    $data['arrival_code'] = substr($line,108,20);
723
-		    //$data['etaDate'] = substr($line,129,5);
724
-		    //$data['etaTime'] = substr($line,135,5);
725
-		    $data['format_source'] = 'shipplotter';
726
-    		    $data['id_source'] = $id_source;
727
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
728
-		    //print_r($data);
729
-		    echo 'Add...'."\n";
730
-		    $MI->add($data);
731
-		    unset($data);
706
+			$data = array();
707
+			echo $line."\n";
708
+			$data['mmsi'] = (int)substr($line,0,9);
709
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
710
+			$data['status_id'] = substr($line,21,2);
711
+			$data['type_id'] = substr($line,24,3);
712
+			$data['latitude'] = substr($line,29,9);
713
+			$data['longitude'] = substr($line,41,9);
714
+			$data['speed'] = round(substr($line,51,5));
715
+			//$data['course'] = substr($line,57,5);
716
+			$data['heading'] = round(substr($line,63,3));
717
+			//$data['draft'] = substr($line,67,4);
718
+			//$data['length'] = substr($line,72,3);
719
+			//$data['beam'] = substr($line,76,2);
720
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
721
+			//$data['callsign'] = trim(substr($line,100,7);
722
+			$data['arrival_code'] = substr($line,108,20);
723
+			//$data['etaDate'] = substr($line,129,5);
724
+			//$data['etaTime'] = substr($line,135,5);
725
+			$data['format_source'] = 'shipplotter';
726
+				$data['id_source'] = $id_source;
727
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
728
+			//print_r($data);
729
+			echo 'Add...'."\n";
730
+			$MI->add($data);
731
+			unset($data);
732 732
 		}
733
-    	    }
734
-    	    $last_exec[$id]['last'] = time();
733
+			}
734
+			$last_exec[$id]['last'] = time();
735 735
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
736 736
 	} elseif (
737
-	    (
737
+		(
738 738
 		$value['format'] === 'whazzup' && 
739 739
 		(
740
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
741
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
740
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
741
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
742 742
 		)
743
-	    ) || (
743
+		) || (
744 744
 		$value['format'] === 'vatsimtxt' && 
745 745
 		(
746
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
747
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
746
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
747
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
748
+		)
748 749
 		)
749
-	    )
750 750
 	) {
751
-	    //$buffer = $Common->getData($hosts[$id]);
752
-	    $buffer = $Common->getData($value['host']);
753
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
754
-	    $buffer = explode('\n',$buffer);
755
-	    $reset = 0;
756
-	    foreach ($buffer as $line) {
757
-    		if ($line != '') {
758
-    		    $line = explode(':', $line);
759
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
751
+		//$buffer = $Common->getData($hosts[$id]);
752
+		$buffer = $Common->getData($value['host']);
753
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
754
+		$buffer = explode('\n',$buffer);
755
+		$reset = 0;
756
+		foreach ($buffer as $line) {
757
+			if ($line != '') {
758
+				$line = explode(':', $line);
759
+				if (count($line) > 30 && $line[0] != 'callsign') {
760 760
 			$data = array();
761 761
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
762 762
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -769,37 +769,37 @@  discard block
 block discarded – undo
769 769
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
770 770
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
771 771
 			$data['latitude'] = $line[5]; // lat
772
-	        	$data['longitude'] = $line[6]; // long
773
-	        	$data['verticalrate'] = ''; // vertical rate
774
-	        	$data['squawk'] = ''; // squawk
775
-	        	$data['emergency'] = ''; // emergency
776
-	        	$data['waypoints'] = $line[30];
772
+				$data['longitude'] = $line[6]; // long
773
+				$data['verticalrate'] = ''; // vertical rate
774
+				$data['squawk'] = ''; // squawk
775
+				$data['emergency'] = ''; // emergency
776
+				$data['waypoints'] = $line[30];
777 777
 			$data['datetime'] = date('Y-m-d H:i:s');
778 778
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
779 779
 			//if (isset($line[37])) $data['last_update'] = $line[37];
780
-		        $data['departure_airport_icao'] = $line[11];
781
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
782
-		        $data['arrival_airport_icao'] = $line[13];
780
+				$data['departure_airport_icao'] = $line[11];
781
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
782
+				$data['arrival_airport_icao'] = $line[13];
783 783
 			$data['frequency'] = $line[4];
784 784
 			$data['type'] = $line[18];
785 785
 			$data['range'] = $line[19];
786 786
 			if (isset($line[35])) $data['info'] = $line[35];
787
-    			$data['id_source'] = $id_source;
788
-	    		//$data['arrival_airport_time'] = ;
789
-	    		if ($line[9] != '') {
790
-	    		    $aircraft_data = explode('/',$line[9]);
791
-	    		    if (isset($aircraft_data[1])) {
792
-	    			$data['aircraft_icao'] = $aircraft_data[1];
793
-	    		    }
794
-        		}
795
-	    		/*
787
+				$data['id_source'] = $id_source;
788
+				//$data['arrival_airport_time'] = ;
789
+				if ($line[9] != '') {
790
+					$aircraft_data = explode('/',$line[9]);
791
+					if (isset($aircraft_data[1])) {
792
+					$data['aircraft_icao'] = $aircraft_data[1];
793
+					}
794
+				}
795
+				/*
796 796
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
797 797
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
798 798
 	    		*/
799
-	    		$data['format_source'] = $value['format'];
799
+				$data['format_source'] = $value['format'];
800 800
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
801 801
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
802
-    			if ($line[3] === 'PILOT') $SI->add($data);
802
+				if ($line[3] === 'PILOT') $SI->add($data);
803 803
 			elseif ($line[3] === 'ATC') {
804 804
 				//print_r($data);
805 805
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -820,21 +820,21 @@  discard block
 block discarded – undo
820 820
 					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']);
821 821
 				}
822 822
 			}
823
-    			unset($data);
824
-    		    }
825
-    		}
826
-    	    }
827
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
828
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
829
-    	    $last_exec[$id]['last'] = time();
830
-    	} elseif ($value['format'] === 'airwhere' && 
831
-    	    (
832
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
833
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
834
-    	    )
835
-    	) {
836
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
837
-	    if ($buffer != '') {
823
+				unset($data);
824
+				}
825
+			}
826
+			}
827
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
828
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
829
+			$last_exec[$id]['last'] = time();
830
+		} elseif ($value['format'] === 'airwhere' && 
831
+			(
832
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
833
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
834
+			)
835
+		) {
836
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
837
+		if ($buffer != '') {
838 838
 		$all_data = simplexml_load_string($buffer);
839 839
 		foreach($all_data->children() as $childdata) {
840 840
 			$data = array();
@@ -856,10 +856,10 @@  discard block
 block discarded – undo
856 856
 			$SI->add($data);
857 857
 			unset($data);
858 858
 		}
859
-	    }
860
-	    $Source->deleteOldLocationByType('gs');
861
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
862
-	    if ($buffer != '') {
859
+		}
860
+		$Source->deleteOldLocationByType('gs');
861
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
862
+		if ($buffer != '') {
863 863
 		$all_data = simplexml_load_string($buffer);
864 864
 		foreach($all_data->children() as $childdata) {
865 865
 			$data = array();
@@ -877,8 +877,8 @@  discard block
 block discarded – undo
877 877
 			}
878 878
 			unset($data);
879 879
 		}
880
-	    }
881
-	    $last_exec[$id]['last'] = time();
880
+		}
881
+		$last_exec[$id]['last'] = time();
882 882
 	/*
883 883
 	} if ($value['format'] === 'aircraftlistjson') {
884 884
 	    print_r($globalSources);
@@ -886,17 +886,17 @@  discard block
 block discarded – undo
886 886
 	    echo $globalMinFetch;
887 887
 	*/
888 888
 	} elseif ($value['format'] === 'aircraftlistjson' && 
889
-	    (
889
+		(
890 890
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
891 891
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
892
-	    )
892
+		)
893 893
 	) {
894
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
895
-	    if ($buffer != '') {
896
-	        $all_data = json_decode($buffer,true);
894
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
895
+		if ($buffer != '') {
896
+			$all_data = json_decode($buffer,true);
897 897
 		if (isset($all_data['acList'])) {
898
-		    $reset = 0;
899
-		    foreach ($all_data['acList'] as $line) {
898
+			$reset = 0;
899
+			foreach ($all_data['acList'] as $line) {
900 900
 			$data = array();
901 901
 			$data['hex'] = $line['Icao']; // hex
902 902
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -919,10 +919,10 @@  discard block
 block discarded – undo
919 919
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
920 920
 			if (isset($data['latitude'])) $SI->add($data);
921 921
 			unset($data);
922
-		    }
922
+			}
923 923
 		} elseif (is_array($all_data)) {
924
-		    $reset = 0;
925
-		    foreach ($all_data as $line) {
924
+			$reset = 0;
925
+			foreach ($all_data as $line) {
926 926
 			$data = array();
927 927
 			$data['hex'] = $line['hex']; // hex
928 928
 			$data['ident'] = $line['flight']; // ident
@@ -942,291 +942,291 @@  discard block
 block discarded – undo
942 942
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
943 943
 			$SI->add($data);
944 944
 			unset($data);
945
-		    }
945
+			}
946 946
 		}
947
-	    } elseif ($globalDebug) echo 'No data'."\n";
948
-    	    //$last_exec['aircraftlistjson'] = time();
949
-    	    $last_exec[$id]['last'] = time();
950
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
951
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
952
-    	    (
953
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
954
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
955
-    	    )
956
-    	) {
957
-	    $buffer = $Common->getData($value['host']);
958
-	    $all_data = json_decode($buffer,true);
959
-	    if (isset($all_data['planes'])) {
947
+		} elseif ($globalDebug) echo 'No data'."\n";
948
+			//$last_exec['aircraftlistjson'] = time();
949
+			$last_exec[$id]['last'] = time();
950
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
951
+		} elseif ($value['format'] === 'planeupdatefaa' && 
952
+			(
953
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
954
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
955
+			)
956
+		) {
957
+		$buffer = $Common->getData($value['host']);
958
+		$all_data = json_decode($buffer,true);
959
+		if (isset($all_data['planes'])) {
960 960
 		$reset = 0;
961 961
 		foreach ($all_data['planes'] as $key => $line) {
962
-		    $data = array();
963
-		    $data['hex'] = $key; // hex
964
-		    $data['ident'] = $line[3]; // ident
965
-		    $data['altitude'] = $line[6]; // altitude
966
-		    $data['speed'] = $line[8]; // speed
967
-		    $data['heading'] = $line[7]; // heading
968
-		    $data['latitude'] = $line[4]; // lat
969
-		    $data['longitude'] = $line[5]; // long
970
-		    //$data['verticalrate'] = $line[]; // verticale rate
971
-		    $data['squawk'] = $line[10]; // squawk
972
-		    $data['emergency'] = ''; // emergency
973
-		    $data['registration'] = $line[2];
974
-		    $data['aircraft_icao'] = $line[0];
975
-		    $deparr = explode('-',$line[1]);
976
-		    if (count($deparr) === 2) {
962
+			$data = array();
963
+			$data['hex'] = $key; // hex
964
+			$data['ident'] = $line[3]; // ident
965
+			$data['altitude'] = $line[6]; // altitude
966
+			$data['speed'] = $line[8]; // speed
967
+			$data['heading'] = $line[7]; // heading
968
+			$data['latitude'] = $line[4]; // lat
969
+			$data['longitude'] = $line[5]; // long
970
+			//$data['verticalrate'] = $line[]; // verticale rate
971
+			$data['squawk'] = $line[10]; // squawk
972
+			$data['emergency'] = ''; // emergency
973
+			$data['registration'] = $line[2];
974
+			$data['aircraft_icao'] = $line[0];
975
+			$deparr = explode('-',$line[1]);
976
+			if (count($deparr) === 2) {
977 977
 			$data['departure_airport_icao'] = $deparr[0];
978 978
 			$data['arrival_airport_icao'] = $deparr[1];
979
-		    }
980
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
981
-	    	    $data['format_source'] = 'planeupdatefaa';
982
-    		    $data['id_source'] = $id_source;
983
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
984
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
985
-		    $SI->add($data);
986
-		    unset($data);
979
+			}
980
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
981
+				$data['format_source'] = 'planeupdatefaa';
982
+				$data['id_source'] = $id_source;
983
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
984
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
985
+			$SI->add($data);
986
+			unset($data);
987 987
 		}
988
-	    }
989
-	    //$last_exec['planeupdatefaa'] = time();
990
-	    $last_exec[$id]['last'] = time();
988
+		}
989
+		//$last_exec['planeupdatefaa'] = time();
990
+		$last_exec[$id]['last'] = time();
991 991
 	} elseif ($value['format'] === 'opensky' && 
992
-	    (
992
+		(
993 993
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
994 994
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
995
-	    )
995
+		)
996 996
 	) {
997
-	    $buffer = $Common->getData($value['host']);
998
-	    $all_data = json_decode($buffer,true);
999
-	    if (isset($all_data['states'])) {
997
+		$buffer = $Common->getData($value['host']);
998
+		$all_data = json_decode($buffer,true);
999
+		if (isset($all_data['states'])) {
1000 1000
 		$reset = 0;
1001 1001
 		foreach ($all_data['states'] as $key => $line) {
1002
-		    $data = array();
1003
-		    $data['hex'] = $line[0]; // hex
1004
-		    $data['ident'] = trim($line[1]); // ident
1005
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1006
-		    $data['speed'] = round($line[9]*1.94384); // speed
1007
-		    $data['heading'] = round($line[10]); // heading
1008
-		    $data['latitude'] = $line[6]; // lat
1009
-		    $data['longitude'] = $line[5]; // long
1010
-		    $data['verticalrate'] = $line[11]; // verticale rate
1011
-		    //$data['squawk'] = $line[10]; // squawk
1012
-		    //$data['emergency'] = ''; // emergency
1013
-		    //$data['registration'] = $line[2];
1014
-		    //$data['aircraft_icao'] = $line[0];
1015
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1016
-		    $data['format_source'] = 'opensky';
1017
-		    $data['id_source'] = $id_source;
1018
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1019
-		    $SI->add($data);
1020
-		    unset($data);
1002
+			$data = array();
1003
+			$data['hex'] = $line[0]; // hex
1004
+			$data['ident'] = trim($line[1]); // ident
1005
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1006
+			$data['speed'] = round($line[9]*1.94384); // speed
1007
+			$data['heading'] = round($line[10]); // heading
1008
+			$data['latitude'] = $line[6]; // lat
1009
+			$data['longitude'] = $line[5]; // long
1010
+			$data['verticalrate'] = $line[11]; // verticale rate
1011
+			//$data['squawk'] = $line[10]; // squawk
1012
+			//$data['emergency'] = ''; // emergency
1013
+			//$data['registration'] = $line[2];
1014
+			//$data['aircraft_icao'] = $line[0];
1015
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1016
+			$data['format_source'] = 'opensky';
1017
+			$data['id_source'] = $id_source;
1018
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1019
+			$SI->add($data);
1020
+			unset($data);
1021
+		}
1021 1022
 		}
1022
-	    }
1023
-	    //$last_exec['planeupdatefaa'] = time();
1024
-	    $last_exec[$id]['last'] = time();
1023
+		//$last_exec['planeupdatefaa'] = time();
1024
+		$last_exec[$id]['last'] = time();
1025 1025
 	} elseif ($value['format'] === 'aircraftjson' && 
1026
-	    (
1026
+		(
1027 1027
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1028 1028
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1029
-	    )
1029
+		)
1030 1030
 	) {
1031
-	    $buffer = $Common->getData($value['host']);
1032
-	    $all_data = json_decode($buffer,true);
1033
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1031
+		$buffer = $Common->getData($value['host']);
1032
+		$all_data = json_decode($buffer,true);
1033
+		if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1034 1034
 		$reset = 0;
1035 1035
 		foreach ($all_data['aircraft'] as $key => $line) {
1036
-		    $data = array();
1037
-		    // add support for ground vehicule with ~ in front of hex
1038
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1039
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1040
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1041
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1042
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1043
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1044
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1045
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1046
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1047
-		    //$data['emergency'] = ''; // emergency
1048
-		    //$data['registration'] = $line[2];
1049
-		    //$data['aircraft_icao'] = $line[0];
1050
-		    $data['datetime'] = date('Y-m-d H:i:s');
1051
-		    $data['format_source'] = 'aircraftjson';
1052
-		    $data['id_source'] = $id_source;
1053
-		    if (isset($value['name']) && $value['name'] != '') {
1054
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1055
-			    else $data['source_name'] = $value['name'];
1056
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1057
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1058
-		    $SI->add($data);
1059
-		    unset($data);
1036
+			$data = array();
1037
+			// add support for ground vehicule with ~ in front of hex
1038
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1039
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1040
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1041
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1042
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1043
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1044
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1045
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1046
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1047
+			//$data['emergency'] = ''; // emergency
1048
+			//$data['registration'] = $line[2];
1049
+			//$data['aircraft_icao'] = $line[0];
1050
+			$data['datetime'] = date('Y-m-d H:i:s');
1051
+			$data['format_source'] = 'aircraftjson';
1052
+			$data['id_source'] = $id_source;
1053
+			if (isset($value['name']) && $value['name'] != '') {
1054
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1055
+				else $data['source_name'] = $value['name'];
1056
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1057
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1058
+			$SI->add($data);
1059
+			unset($data);
1060 1060
 		}
1061
-	    }
1062
-	    //$last_exec['planeupdatefaa'] = time();
1063
-	    $last_exec[$id]['last'] = time();
1061
+		}
1062
+		//$last_exec['planeupdatefaa'] = time();
1063
+		$last_exec[$id]['last'] = time();
1064 1064
 	} elseif ($value['format'] === 'planefinderclient' && 
1065
-	    (
1065
+		(
1066 1066
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1067 1067
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1068
-	    )
1068
+		)
1069 1069
 	) {
1070
-	    $buffer = $Common->getData($value['host']);
1071
-	    $all_data = json_decode($buffer,true);
1072
-	    if (isset($all_data['aircraft'])) {
1070
+		$buffer = $Common->getData($value['host']);
1071
+		$all_data = json_decode($buffer,true);
1072
+		if (isset($all_data['aircraft'])) {
1073 1073
 		$reset = 0;
1074 1074
 		foreach ($all_data['aircraft'] as $key => $line) {
1075
-		    $data = array();
1076
-		    $data['hex'] = $key; // hex
1077
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1078
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1079
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1080
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1081
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1082
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1083
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1084
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1085
-		    //$data['emergency'] = ''; // emergency
1086
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1087
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1088
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1089
-		    $data['format_source'] = 'planefinderclient';
1090
-		    $data['id_source'] = $id_source;
1091
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1092
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1093
-		    $SI->add($data);
1094
-		    unset($data);
1075
+			$data = array();
1076
+			$data['hex'] = $key; // hex
1077
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1078
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1079
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1080
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1081
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1082
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1083
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1084
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1085
+			//$data['emergency'] = ''; // emergency
1086
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1087
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1088
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1089
+			$data['format_source'] = 'planefinderclient';
1090
+			$data['id_source'] = $id_source;
1091
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1092
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1093
+			$SI->add($data);
1094
+			unset($data);
1095 1095
 		}
1096
-	    }
1097
-	    $last_exec[$id]['last'] = time();
1096
+		}
1097
+		$last_exec[$id]['last'] = time();
1098 1098
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1099 1099
 	} elseif ($value['format'] === 'fr24json' && 
1100
-	    (
1100
+		(
1101 1101
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1102 1102
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1103
-	    )
1103
+		)
1104 1104
 	) {
1105
-	    //$buffer = $Common->getData($hosts[$id]);
1106
-	    $buffer = $Common->getData($value['host']);
1107
-	    $all_data = json_decode($buffer,true);
1108
-	    if (!empty($all_data)) $reset = 0;
1109
-	    foreach ($all_data as $key => $line) {
1105
+		//$buffer = $Common->getData($hosts[$id]);
1106
+		$buffer = $Common->getData($value['host']);
1107
+		$all_data = json_decode($buffer,true);
1108
+		if (!empty($all_data)) $reset = 0;
1109
+		foreach ($all_data as $key => $line) {
1110 1110
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1111
-		    $data = array();
1112
-		    $data['hex'] = $line[0];
1113
-		    $data['ident'] = $line[16]; //$line[13]
1114
-	    	    $data['altitude'] = $line[4]; // altitude
1115
-	    	    $data['speed'] = $line[5]; // speed
1116
-	    	    $data['heading'] = $line[3]; // heading
1117
-	    	    $data['latitude'] = $line[1]; // lat
1118
-	    	    $data['longitude'] = $line[2]; // long
1119
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1120
-	    	    $data['squawk'] = $line[6]; // squawk
1121
-	    	    $data['aircraft_icao'] = $line[8];
1122
-	    	    $data['registration'] = $line[9];
1123
-		    $data['departure_airport_iata'] = $line[11];
1124
-		    $data['arrival_airport_iata'] = $line[12];
1125
-	    	    $data['emergency'] = ''; // emergency
1126
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1127
-	    	    $data['format_source'] = 'fr24json';
1128
-    		    $data['id_source'] = $id_source;
1129
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1130
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1131
-		    $SI->add($data);
1132
-		    unset($data);
1111
+			$data = array();
1112
+			$data['hex'] = $line[0];
1113
+			$data['ident'] = $line[16]; //$line[13]
1114
+				$data['altitude'] = $line[4]; // altitude
1115
+				$data['speed'] = $line[5]; // speed
1116
+				$data['heading'] = $line[3]; // heading
1117
+				$data['latitude'] = $line[1]; // lat
1118
+				$data['longitude'] = $line[2]; // long
1119
+				$data['verticalrate'] = $line[15]; // verticale rate
1120
+				$data['squawk'] = $line[6]; // squawk
1121
+				$data['aircraft_icao'] = $line[8];
1122
+				$data['registration'] = $line[9];
1123
+			$data['departure_airport_iata'] = $line[11];
1124
+			$data['arrival_airport_iata'] = $line[12];
1125
+				$data['emergency'] = ''; // emergency
1126
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1127
+				$data['format_source'] = 'fr24json';
1128
+				$data['id_source'] = $id_source;
1129
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1130
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1131
+			$SI->add($data);
1132
+			unset($data);
1133
+		}
1133 1134
 		}
1134
-	    }
1135
-	    //$last_exec['fr24json'] = time();
1136
-	    $last_exec[$id]['last'] = time();
1135
+		//$last_exec['fr24json'] = time();
1136
+		$last_exec[$id]['last'] = time();
1137 1137
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1138 1138
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1139
-	    (
1139
+		(
1140 1140
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1141 1141
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1142
-	    )
1142
+		)
1143 1143
 	) {
1144
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1145
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1146
-	    //echo $buffer;
1147
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1148
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1149
-	    $all_data = json_decode($buffer,true);
1150
-	    if (json_last_error() != JSON_ERROR_NONE) {
1144
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1145
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1146
+		//echo $buffer;
1147
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1148
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1149
+		$all_data = json_decode($buffer,true);
1150
+		if (json_last_error() != JSON_ERROR_NONE) {
1151 1151
 		die(json_last_error_msg());
1152
-	    }
1153
-	    if (isset($all_data['mrkrs'])) {
1152
+		}
1153
+		if (isset($all_data['mrkrs'])) {
1154 1154
 		$reset = 0;
1155 1155
 		foreach ($all_data['mrkrs'] as $key => $line) {
1156
-		    if (isset($line['inf'])) {
1156
+			if (isset($line['inf'])) {
1157 1157
 			$data = array();
1158 1158
 			$data['hex'] = $line['inf']['ia'];
1159 1159
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1160
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1161
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1162
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1163
-	    		$data['latitude'] = $line['pt'][0]; // lat
1164
-	    		$data['longitude'] = $line['pt'][1]; // long
1165
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1166
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1167
-	    		//$data['aircraft_icao'] = $line[8];
1168
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1160
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1161
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1162
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1163
+				$data['latitude'] = $line['pt'][0]; // lat
1164
+				$data['longitude'] = $line['pt'][1]; // long
1165
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1166
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1167
+				//$data['aircraft_icao'] = $line[8];
1168
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1169 1169
 			//$data['departure_airport_iata'] = $line[11];
1170 1170
 			//$data['arrival_airport_iata'] = $line[12];
1171
-	    		//$data['emergency'] = ''; // emergency
1171
+				//$data['emergency'] = ''; // emergency
1172 1172
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1173
-	    		$data['format_source'] = 'radarvirtueljson';
1174
-    			$data['id_source'] = $id_source;
1173
+				$data['format_source'] = 'radarvirtueljson';
1174
+				$data['id_source'] = $id_source;
1175 1175
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1176 1176
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1177 1177
 			$SI->add($data);
1178 1178
 			unset($data);
1179
-		    }
1179
+			}
1180 1180
 		}
1181
-	    }
1182
-	    //$last_exec['radarvirtueljson'] = time();
1183
-	    $last_exec[$id]['last'] = time();
1181
+		}
1182
+		//$last_exec['radarvirtueljson'] = time();
1183
+		$last_exec[$id]['last'] = time();
1184 1184
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1185 1185
 	} elseif ($value['format'] === 'pirepsjson' && 
1186
-	    (
1186
+		(
1187 1187
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1188 1188
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1189
-	    )
1189
+		)
1190 1190
 	) {
1191
-	    //$buffer = $Common->getData($hosts[$id]);
1192
-	    $buffer = $Common->getData($value['host'].'?'.time());
1193
-	    $all_data = json_decode(utf8_encode($buffer),true);
1191
+		//$buffer = $Common->getData($hosts[$id]);
1192
+		$buffer = $Common->getData($value['host'].'?'.time());
1193
+		$all_data = json_decode(utf8_encode($buffer),true);
1194 1194
 	    
1195
-	    if (isset($all_data['pireps'])) {
1195
+		if (isset($all_data['pireps'])) {
1196 1196
 		$reset = 0;
1197
-	        foreach ($all_data['pireps'] as $line) {
1198
-		    $data = array();
1199
-		    $data['id'] = $line['id'];
1200
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1201
-		    $data['ident'] = $line['callsign']; // ident
1202
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1203
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1204
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1205
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1206
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1207
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1208
-		    $data['latitude'] = $line['lat']; // lat
1209
-		    $data['longitude'] = $line['lon']; // long
1210
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1211
-		    //$data['squawk'] = $line['squawk']; // squawk
1212
-		    //$data['emergency'] = ''; // emergency
1213
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1214
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1215
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1216
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1217
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1218
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1219
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1220
-		    else $data['info'] = '';
1221
-		    $data['format_source'] = 'pireps';
1222
-    		    $data['id_source'] = $id_source;
1223
-		    $data['datetime'] = date('Y-m-d H:i:s');
1224
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1225
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1226
-		    if ($line['icon'] === 'plane') {
1197
+			foreach ($all_data['pireps'] as $line) {
1198
+			$data = array();
1199
+			$data['id'] = $line['id'];
1200
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1201
+			$data['ident'] = $line['callsign']; // ident
1202
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1203
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1204
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1205
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1206
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1207
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1208
+			$data['latitude'] = $line['lat']; // lat
1209
+			$data['longitude'] = $line['lon']; // long
1210
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1211
+			//$data['squawk'] = $line['squawk']; // squawk
1212
+			//$data['emergency'] = ''; // emergency
1213
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1214
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1215
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1216
+			//$data['arrival_airport_time'] = $line['arrtime'];
1217
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1218
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1219
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1220
+			else $data['info'] = '';
1221
+			$data['format_source'] = 'pireps';
1222
+				$data['id_source'] = $id_source;
1223
+			$data['datetime'] = date('Y-m-d H:i:s');
1224
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1225
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1226
+			if ($line['icon'] === 'plane') {
1227 1227
 			$SI->add($data);
1228
-		    //    print_r($data);
1229
-    		    } elseif ($line['icon'] === 'ct') {
1228
+			//    print_r($data);
1229
+				} elseif ($line['icon'] === 'ct') {
1230 1230
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1231 1231
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1232 1232
 			$typec = substr($data['ident'],-3);
@@ -1241,209 +1241,209 @@  discard block
 block discarded – undo
1241 1241
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1242 1242
 			else $data['type'] = 'Observer';
1243 1243
 			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']);
1244
-		    }
1245
-		    unset($data);
1244
+			}
1245
+			unset($data);
1246 1246
 		}
1247
-	    }
1248
-	    //$last_exec['pirepsjson'] = time();
1249
-	    $last_exec[$id]['last'] = time();
1247
+		}
1248
+		//$last_exec['pirepsjson'] = time();
1249
+		$last_exec[$id]['last'] = time();
1250 1250
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1251 1251
 	} elseif ($value['format'] === 'phpvmacars' && 
1252
-	    (
1252
+		(
1253 1253
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1254 1254
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1255
-	    )
1255
+		)
1256 1256
 	) {
1257
-	    //$buffer = $Common->getData($hosts[$id]);
1258
-	    if ($globalDebug) echo 'Get Data...'."\n";
1259
-	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1261
-	    if ($buffer != '' && is_array($all_data)) {
1257
+		//$buffer = $Common->getData($hosts[$id]);
1258
+		if ($globalDebug) echo 'Get Data...'."\n";
1259
+		$buffer = $Common->getData($value['host']);
1260
+		$all_data = json_decode($buffer,true);
1261
+		if ($buffer != '' && is_array($all_data)) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data as $line) {
1264
-	    	    $data = array();
1265
-	    	    //$data['id'] = $line['id']; // id not usable
1266
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1267
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1268
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1269
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1270
-	    	    $data['ident'] = $line['flightnum']; // ident
1271
-	    	    $data['altitude'] = $line['alt']; // altitude
1272
-	    	    $data['speed'] = $line['gs']; // speed
1273
-	    	    $data['heading'] = $line['heading']; // heading
1274
-	    	    $data['latitude'] = $line['lat']; // lat
1275
-	    	    $data['longitude'] = $line['lng']; // long
1276
-	    	    $data['verticalrate'] = ''; // verticale rate
1277
-	    	    $data['squawk'] = ''; // squawk
1278
-	    	    $data['emergency'] = ''; // emergency
1279
-	    	    //$data['datetime'] = $line['lastupdate'];
1280
-	    	    //$data['last_update'] = $line['lastupdate'];
1281
-	    	    if (isset($value['timezone'])) {
1282
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1283
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1284
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1285
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1286
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1287
-	    	    $data['departure_airport_time'] = $line['deptime'];
1288
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1289
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1290
-    		    if (isset($line['registration'])) {
1291
-    			$data['registration'] = $line['registration'];
1292
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1293
-    		    } else $data['registration'] = $line['aircraft'];
1294
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1295
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1296
-		    if (isset($line['aircraftname'])) {
1264
+				$data = array();
1265
+				//$data['id'] = $line['id']; // id not usable
1266
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1267
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1268
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1269
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1270
+				$data['ident'] = $line['flightnum']; // ident
1271
+				$data['altitude'] = $line['alt']; // altitude
1272
+				$data['speed'] = $line['gs']; // speed
1273
+				$data['heading'] = $line['heading']; // heading
1274
+				$data['latitude'] = $line['lat']; // lat
1275
+				$data['longitude'] = $line['lng']; // long
1276
+				$data['verticalrate'] = ''; // verticale rate
1277
+				$data['squawk'] = ''; // squawk
1278
+				$data['emergency'] = ''; // emergency
1279
+				//$data['datetime'] = $line['lastupdate'];
1280
+				//$data['last_update'] = $line['lastupdate'];
1281
+				if (isset($value['timezone'])) {
1282
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1283
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1284
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1285
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1286
+				$data['departure_airport_icao'] = $line['depicao'];
1287
+				$data['departure_airport_time'] = $line['deptime'];
1288
+				$data['arrival_airport_icao'] = $line['arricao'];
1289
+				$data['arrival_airport_time'] = $line['arrtime'];
1290
+				if (isset($line['registration'])) {
1291
+				$data['registration'] = $line['registration'];
1292
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1293
+				} else $data['registration'] = $line['aircraft'];
1294
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1295
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1296
+			if (isset($line['aircraftname'])) {
1297 1297
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1298 1298
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1299
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1300
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1301
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1302
-	    		else {
1303
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1304
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1305
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1306
-	    		}
1307
-	    	    }
1308
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1309
-    		    $data['id_source'] = $id_source;
1310
-	    	    $data['format_source'] = 'phpvmacars';
1311
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1312
-		    $SI->add($data);
1313
-		    unset($data);
1299
+				$aircraft_data = explode('-',$line['aircraftname']);
1300
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1301
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1302
+				else {
1303
+					$aircraft_data = explode(' ',$line['aircraftname']);
1304
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1305
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1306
+				}
1307
+				}
1308
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1309
+				$data['id_source'] = $id_source;
1310
+				$data['format_source'] = 'phpvmacars';
1311
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1312
+			$SI->add($data);
1313
+			unset($data);
1314 1314
 		}
1315 1315
 		if ($globalDebug) echo 'No more data...'."\n";
1316 1316
 		unset($buffer);
1317 1317
 		unset($all_data);
1318
-	    }
1319
-	    //$last_exec['phpvmacars'] = time();
1320
-	    $last_exec[$id]['last'] = time();
1318
+		}
1319
+		//$last_exec['phpvmacars'] = time();
1320
+		$last_exec[$id]['last'] = time();
1321 1321
 	} elseif ($value['format'] === 'vaos' && 
1322
-	    (
1322
+		(
1323 1323
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1324 1324
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1325
-	    )
1325
+		)
1326 1326
 	) {
1327
-	    //$buffer = $Common->getData($hosts[$id]);
1328
-	    if ($globalDebug) echo 'Get Data...'."\n";
1329
-	    $buffer = $Common->getData($value['host']);
1330
-	    $all_data = json_decode($buffer,true);
1331
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1327
+		//$buffer = $Common->getData($hosts[$id]);
1328
+		if ($globalDebug) echo 'Get Data...'."\n";
1329
+		$buffer = $Common->getData($value['host']);
1330
+		$all_data = json_decode($buffer,true);
1331
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1332 1332
 		$reset = 0;
1333 1333
 		foreach ($all_data['ACARSData'] as $line) {
1334
-		    //print_r($line);
1335
-	    	    $data = array();
1336
-	    	    //$data['id'] = $line['id']; // id not usable
1337
-	    	    $data['id'] = $line['id'];
1338
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1339
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1340
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1341
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1342
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1343
-	    	    $data['altitude'] = $line['altitude']; // altitude
1344
-	    	    $data['speed'] = $line['groundspeed']; // speed
1345
-	    	    $data['heading'] = $line['heading']; // heading
1346
-	    	    $data['latitude'] = $line['lat']; // lat
1347
-	    	    $data['longitude'] = $line['lon']; // long
1348
-	    	    //$data['verticalrate'] = ''; // verticale rate
1349
-	    	    //$data['squawk'] = ''; // squawk
1350
-	    	    //$data['emergency'] = ''; // emergency
1351
-	    	    if (isset($value['timezone'])) {
1352
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1353
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1354
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1355
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1334
+			//print_r($line);
1335
+				$data = array();
1336
+				//$data['id'] = $line['id']; // id not usable
1337
+				$data['id'] = $line['id'];
1338
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1339
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1340
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1341
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1342
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1343
+				$data['altitude'] = $line['altitude']; // altitude
1344
+				$data['speed'] = $line['groundspeed']; // speed
1345
+				$data['heading'] = $line['heading']; // heading
1346
+				$data['latitude'] = $line['lat']; // lat
1347
+				$data['longitude'] = $line['lon']; // long
1348
+				//$data['verticalrate'] = ''; // verticale rate
1349
+				//$data['squawk'] = ''; // squawk
1350
+				//$data['emergency'] = ''; // emergency
1351
+				if (isset($value['timezone'])) {
1352
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1353
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1354
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1355
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1356 1356
 	    	    
1357
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1358
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1359
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1360
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1361
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1357
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1358
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1359
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1360
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1361
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1362 1362
 
1363
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1364
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1365
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1363
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1364
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1365
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1366 1366
 
1367
-    		    $data['id_source'] = $id_source;
1368
-	    	    $data['format_source'] = 'vaos';
1369
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1370
-		    $SI->add($data);
1371
-		    unset($data);
1367
+				$data['id_source'] = $id_source;
1368
+				$data['format_source'] = 'vaos';
1369
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1370
+			$SI->add($data);
1371
+			unset($data);
1372 1372
 		}
1373 1373
 		if ($globalDebug) echo 'No more data...'."\n";
1374 1374
 		unset($buffer);
1375 1375
 		unset($all_data);
1376
-	    }
1377
-	    //$last_exec['phpvmacars'] = time();
1378
-	    $last_exec[$id]['last'] = time();
1376
+		}
1377
+		//$last_exec['phpvmacars'] = time();
1378
+		$last_exec[$id]['last'] = time();
1379 1379
 	} elseif ($value['format'] === 'vam' && 
1380
-	    (
1380
+		(
1381 1381
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1382 1382
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1383
-	    )
1383
+		)
1384 1384
 	) {
1385
-	    //$buffer = $Common->getData($hosts[$id]);
1386
-	    if ($globalDebug) echo 'Get Data...'."\n";
1387
-	    $buffer = $Common->getData($value['host']);
1388
-	    $all_data = json_decode($buffer,true);
1389
-	    if ($buffer != '' && is_array($all_data)) {
1385
+		//$buffer = $Common->getData($hosts[$id]);
1386
+		if ($globalDebug) echo 'Get Data...'."\n";
1387
+		$buffer = $Common->getData($value['host']);
1388
+		$all_data = json_decode($buffer,true);
1389
+		if ($buffer != '' && is_array($all_data)) {
1390 1390
 		$reset = 0;
1391 1391
 		foreach ($all_data as $line) {
1392
-	    	    $data = array();
1393
-	    	    //$data['id'] = $line['id']; // id not usable
1394
-	    	    $data['id'] = trim($line['flight_id']);
1395
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1396
-	    	    $data['pilot_name'] = $line['pilot_name'];
1397
-	    	    $data['pilot_id'] = $line['pilot_id'];
1398
-	    	    $data['ident'] = trim($line['callsign']); // ident
1399
-	    	    $data['altitude'] = $line['altitude']; // altitude
1400
-	    	    $data['speed'] = $line['gs']; // speed
1401
-	    	    $data['heading'] = $line['heading']; // heading
1402
-	    	    $data['latitude'] = $line['latitude']; // lat
1403
-	    	    $data['longitude'] = $line['longitude']; // long
1404
-	    	    $data['verticalrate'] = ''; // verticale rate
1405
-	    	    $data['squawk'] = ''; // squawk
1406
-	    	    $data['emergency'] = ''; // emergency
1407
-	    	    //$data['datetime'] = $line['lastupdate'];
1408
-	    	    $data['last_update'] = $line['last_update'];
1409
-		    $data['datetime'] = date('Y-m-d H:i:s');
1410
-	    	    $data['departure_airport_icao'] = $line['departure'];
1411
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1412
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1413
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1414
-    		    //$data['registration'] = $line['aircraft'];
1415
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1416
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1417
-    		    $data['id_source'] = $id_source;
1418
-	    	    $data['format_source'] = 'vam';
1419
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1420
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1421
-		    $SI->add($data);
1422
-		    unset($data);
1392
+				$data = array();
1393
+				//$data['id'] = $line['id']; // id not usable
1394
+				$data['id'] = trim($line['flight_id']);
1395
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1396
+				$data['pilot_name'] = $line['pilot_name'];
1397
+				$data['pilot_id'] = $line['pilot_id'];
1398
+				$data['ident'] = trim($line['callsign']); // ident
1399
+				$data['altitude'] = $line['altitude']; // altitude
1400
+				$data['speed'] = $line['gs']; // speed
1401
+				$data['heading'] = $line['heading']; // heading
1402
+				$data['latitude'] = $line['latitude']; // lat
1403
+				$data['longitude'] = $line['longitude']; // long
1404
+				$data['verticalrate'] = ''; // verticale rate
1405
+				$data['squawk'] = ''; // squawk
1406
+				$data['emergency'] = ''; // emergency
1407
+				//$data['datetime'] = $line['lastupdate'];
1408
+				$data['last_update'] = $line['last_update'];
1409
+			$data['datetime'] = date('Y-m-d H:i:s');
1410
+				$data['departure_airport_icao'] = $line['departure'];
1411
+				//$data['departure_airport_time'] = $line['departure_time'];
1412
+				$data['arrival_airport_icao'] = $line['arrival'];
1413
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1414
+				//$data['registration'] = $line['aircraft'];
1415
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1416
+				$data['aircraft_icao'] = $line['plane_type'];
1417
+				$data['id_source'] = $id_source;
1418
+				$data['format_source'] = 'vam';
1419
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1420
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1421
+			$SI->add($data);
1422
+			unset($data);
1423 1423
 		}
1424 1424
 		if ($globalDebug) echo 'No more data...'."\n";
1425 1425
 		unset($buffer);
1426 1426
 		unset($all_data);
1427
-	    }
1428
-	    //$last_exec['phpvmacars'] = time();
1429
-	    $last_exec[$id]['last'] = time();
1427
+		}
1428
+		//$last_exec['phpvmacars'] = time();
1429
+		$last_exec[$id]['last'] = time();
1430 1430
 	} elseif ($value['format'] === 'blitzortung' && 
1431
-	    (
1431
+		(
1432 1432
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1433 1433
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1434
-	    )
1434
+		)
1435 1435
 	) {
1436
-	    //$buffer = $Common->getData($hosts[$id]);
1437
-	    if ($globalDebug) echo 'Get Data...'."\n";
1438
-	    $buffer = $Common->getData($value['host']);
1439
-	    $all_data = json_decode($buffer,true);
1440
-	    if ($buffer != '') {
1436
+		//$buffer = $Common->getData($hosts[$id]);
1437
+		if ($globalDebug) echo 'Get Data...'."\n";
1438
+		$buffer = $Common->getData($value['host']);
1439
+		$all_data = json_decode($buffer,true);
1440
+		if ($buffer != '') {
1441 1441
 		$Source->deleteLocationBySource('blitzortung');
1442 1442
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1443 1443
 		$buffer = explode('\n',$buffer);
1444 1444
 		foreach ($buffer as $buffer_line) {
1445
-		    $line = json_decode($buffer_line,true);
1446
-		    if (isset($line['time'])) {
1445
+			$line = json_decode($buffer_line,true);
1446
+			if (isset($line['time'])) {
1447 1447
 			$data = array();
1448 1448
 			$data['altitude'] = $line['alt']; // altitude
1449 1449
 			$data['latitude'] = $line['lat']; // lat
@@ -1455,94 +1455,94 @@  discard block
 block discarded – undo
1455 1455
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1456 1456
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1457 1457
 			unset($data);
1458
-		    }
1458
+			}
1459 1459
 		}
1460 1460
 		if ($globalDebug) echo 'No more data...'."\n";
1461 1461
 		unset($buffer);
1462
-	    }
1463
-	    $last_exec[$id]['last'] = time();
1462
+		}
1463
+		$last_exec[$id]['last'] = time();
1464 1464
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1465 1465
 	} 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') {
1466
-	    //$last_exec[$id]['last'] = time();
1467
-	    //$read = array( $sockets[$id] );
1468
-	    $read = $sockets;
1469
-	    $write = NULL;
1470
-	    $e = NULL;
1471
-	    $n = socket_select($read, $write, $e, $timeout);
1472
-	    if ($e != NULL) var_dump($e);
1473
-	    if ($n > 0) {
1466
+		//$last_exec[$id]['last'] = time();
1467
+		//$read = array( $sockets[$id] );
1468
+		$read = $sockets;
1469
+		$write = NULL;
1470
+		$e = NULL;
1471
+		$n = socket_select($read, $write, $e, $timeout);
1472
+		if ($e != NULL) var_dump($e);
1473
+		if ($n > 0) {
1474 1474
 		$reset = 0;
1475 1475
 		foreach ($read as $nb => $r) {
1476
-		    //$value = $formats[$nb];
1477
-		    $format = $globalSources[$nb]['format'];
1478
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1476
+			//$value = $formats[$nb];
1477
+			$format = $globalSources[$nb]['format'];
1478
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1479 1479
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1480
-		    } elseif ($format === 'vrstcp') {
1480
+			} elseif ($format === 'vrstcp') {
1481 1481
 			$buffer = @socket_read($r, 6000);
1482
-		    } else {
1482
+			} else {
1483 1483
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1484
-		    }
1485
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1486
-		    //echo $buffer."\n";
1487
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1488
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1489
-		    $error = false;
1490
-		    //$SI::del();
1491
-		    if ($buffer !== FALSE) {
1484
+			}
1485
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1486
+			//echo $buffer."\n";
1487
+			// lets play nice and handle signals such as ctrl-c/kill properly
1488
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1489
+			$error = false;
1490
+			//$SI::del();
1491
+			if ($buffer !== FALSE) {
1492 1492
 			if ($format === 'vrstcp') {
1493
-			    $buffer = explode('},{',$buffer);
1493
+				$buffer = explode('},{',$buffer);
1494 1494
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1495
-		    }
1496
-		    // SBS format is CSV format
1497
-		    if ($buffer !== FALSE && $buffer !== '') {
1495
+			}
1496
+			// SBS format is CSV format
1497
+			if ($buffer !== FALSE && $buffer !== '') {
1498 1498
 			$tt[$format] = 0;
1499 1499
 			if ($format === 'acarssbs3') {
1500
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1501
-			    $ACARS->add(trim($buffer));
1502
-			    $ACARS->deleteLiveAcarsData();
1500
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1501
+				$ACARS->add(trim($buffer));
1502
+				$ACARS->deleteLiveAcarsData();
1503 1503
 			} elseif ($format === 'raw') {
1504
-			    // AVR format
1505
-			    $data = $SBS->parse($buffer);
1506
-			    if (is_array($data)) {
1504
+				// AVR format
1505
+				$data = $SBS->parse($buffer);
1506
+				if (is_array($data)) {
1507 1507
 				$data['datetime'] = date('Y-m-d H:i:s');
1508 1508
 				$data['format_source'] = 'raw';
1509 1509
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1510 1510
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1511 1511
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1512 1512
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1513
-			    }
1513
+				}
1514 1514
 			} elseif ($format === 'ais') {
1515
-			    $ais_data = $AIS->parse_line(trim($buffer));
1516
-			    $data = array();
1517
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1518
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1519
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1520
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1521
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1522
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1523
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1524
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1525
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1526
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1527
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1528
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1529
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1530
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1531
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1532
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1515
+				$ais_data = $AIS->parse_line(trim($buffer));
1516
+				$data = array();
1517
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1518
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1519
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1520
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1521
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1522
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1523
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1524
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1525
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1526
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1527
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1528
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1529
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1530
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1531
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1532
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1533 1533
 
1534
-			    if (isset($ais_data['timestamp'])) {
1534
+				if (isset($ais_data['timestamp'])) {
1535 1535
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1536
-			    } else {
1536
+				} else {
1537 1537
 				$data['datetime'] = date('Y-m-d H:i:s');
1538
-			    }
1539
-			    $data['format_source'] = 'aisnmea';
1540
-    			    $data['id_source'] = $id_source;
1541
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1542
-			    unset($data);
1543
-                        } elseif ($format === 'flightgearsp') {
1544
-                    	    //echo $buffer."\n";
1545
-                    	    if (strlen($buffer) > 5) {
1538
+				}
1539
+				$data['format_source'] = 'aisnmea';
1540
+					$data['id_source'] = $id_source;
1541
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1542
+				unset($data);
1543
+						} elseif ($format === 'flightgearsp') {
1544
+							//echo $buffer."\n";
1545
+							if (strlen($buffer) > 5) {
1546 1546
 				$line = explode(',',$buffer);
1547 1547
 				$data = array();
1548 1548
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1559,38 +1559,38 @@  discard block
 block discarded – undo
1559 1559
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1560 1560
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1561 1561
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1562
-			    }
1563
-                        } elseif ($format === 'acars') {
1564
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1565
-			    $ACARS->add(trim($buffer));
1566
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1567
-			    $ACARS->deleteLiveAcarsData();
1562
+				}
1563
+						} elseif ($format === 'acars') {
1564
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1565
+				$ACARS->add(trim($buffer));
1566
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1567
+				$ACARS->deleteLiveAcarsData();
1568 1568
 			} elseif ($format === 'flightgearmp') {
1569
-			    if (substr($buffer,0,1) != '#') {
1569
+				if (substr($buffer,0,1) != '#') {
1570 1570
 				$data = array();
1571 1571
 				//echo $buffer."\n";
1572 1572
 				$line = explode(' ',$buffer);
1573 1573
 				if (count($line) === 11) {
1574
-				    $userserver = explode('@',$line[0]);
1575
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1576
-				    $data['ident'] = $userserver[0];
1577
-				    $data['registration'] = $userserver[0];
1578
-				    $data['latitude'] = $line[4];
1579
-				    $data['longitude'] = $line[5];
1580
-				    $data['altitude'] = $line[6];
1581
-				    $data['datetime'] = date('Y-m-d H:i:s');
1582
-				    $aircraft_type = $line[10];
1583
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1584
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1585
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1586
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1574
+					$userserver = explode('@',$line[0]);
1575
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1576
+					$data['ident'] = $userserver[0];
1577
+					$data['registration'] = $userserver[0];
1578
+					$data['latitude'] = $line[4];
1579
+					$data['longitude'] = $line[5];
1580
+					$data['altitude'] = $line[6];
1581
+					$data['datetime'] = date('Y-m-d H:i:s');
1582
+					$aircraft_type = $line[10];
1583
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1584
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1585
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1586
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1587
+				}
1587 1588
 				}
1588
-			    }
1589 1589
 			} elseif ($format === 'beast') {
1590
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1591
-			    die;
1590
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1591
+				die;
1592 1592
 			} elseif ($format === 'vrstcp') {
1593
-			    foreach($buffer as $all_data) {
1593
+				foreach($buffer as $all_data) {
1594 1594
 				$line = json_decode('{'.$all_data.'}',true);
1595 1595
 				$data = array();
1596 1596
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1610,153 +1610,153 @@  discard block
 block discarded – undo
1610 1610
 				*/
1611 1611
 				$data['datetime'] = date('Y-m-d H:i:s');
1612 1612
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1613
-		    		$data['format_source'] = 'vrstcp';
1613
+					$data['format_source'] = 'vrstcp';
1614 1614
 				$data['id_source'] = $id_source;
1615 1615
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1616 1616
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1617 1617
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1618 1618
 				unset($data);
1619
-			    }
1619
+				}
1620 1620
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1621
-			    $line = explode("\t", $buffer);
1622
-			    for($k = 0; $k < count($line); $k=$k+2) {
1621
+				$line = explode("\t", $buffer);
1622
+				for($k = 0; $k < count($line); $k=$k+2) {
1623 1623
 				$key = $line[$k];
1624
-			        $lined[$key] = $line[$k+1];
1625
-			    }
1626
-    			    if (count($lined) > 3) {
1627
-    				$data['hex'] = $lined['hexid'];
1628
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1629
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1630
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1631
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1632
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1633
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1634
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1635
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1636
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1637
-    				$data['id_source'] = $id_source;
1638
-    				$data['format_source'] = 'tsv';
1639
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1640
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1624
+					$lined[$key] = $line[$k+1];
1625
+				}
1626
+					if (count($lined) > 3) {
1627
+					$data['hex'] = $lined['hexid'];
1628
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1629
+					$data['datetime'] = date('Y-m-d H:i:s');;
1630
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1631
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1632
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1633
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1634
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1635
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1636
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1637
+					$data['id_source'] = $id_source;
1638
+					$data['format_source'] = 'tsv';
1639
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1640
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1641 1641
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1642
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1643
-    				unset($lined);
1644
-    				unset($data);
1645
-    			    } else $error = true;
1642
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1643
+					unset($lined);
1644
+					unset($data);
1645
+					} else $error = true;
1646 1646
 			} elseif ($format === 'aprs' && $use_aprs) {
1647
-			    if ($aprs_connect === 0) {
1647
+				if ($aprs_connect === 0) {
1648 1648
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1649 1649
 				$aprs_connect = 1;
1650
-			    }
1650
+				}
1651 1651
 			    
1652
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1652
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1653 1653
 				$aprs_last_tx = time();
1654 1654
 				$data_aprs = "# Keep alive";
1655 1655
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1656
-			    }
1656
+				}
1657 1657
 			    
1658
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1659
-			    //echo 'APRS data : '.$buffer."\n";
1660
-			    $buffer = str_replace('APRS <- ','',$buffer);
1661
-			    $buffer = str_replace('APRS -> ','',$buffer);
1662
-			    //echo $buffer."\n";
1663
-			    date_default_timezone_set('UTC');
1664
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1658
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1659
+				//echo 'APRS data : '.$buffer."\n";
1660
+				$buffer = str_replace('APRS <- ','',$buffer);
1661
+				$buffer = str_replace('APRS -> ','',$buffer);
1662
+				//echo $buffer."\n";
1663
+				date_default_timezone_set('UTC');
1664
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1665 1665
 				$line = $APRS->parse($buffer);
1666 1666
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1667 1667
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1668
-				    $aprs_last_tx = time();
1669
-				    $data = array();
1670
-				    //print_r($line);
1671
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1672
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1673
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1674
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1675
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1676
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1677
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1678
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1679
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1680
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1681
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1682
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1683
-				    $data['latitude'] = $line['latitude'];
1684
-				    $data['longitude'] = $line['longitude'];
1685
-				    //$data['verticalrate'] = $line[16];
1686
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1687
-				    //else $data['speed'] = 0;
1688
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1689
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1690
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1691
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1668
+					$aprs_last_tx = time();
1669
+					$data = array();
1670
+					//print_r($line);
1671
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1672
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1673
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1674
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1675
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1676
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1677
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1678
+					if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1679
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1680
+					else $data['datetime'] = date('Y-m-d H:i:s');
1681
+					//$data['datetime'] = date('Y-m-d H:i:s');
1682
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1683
+					$data['latitude'] = $line['latitude'];
1684
+					$data['longitude'] = $line['longitude'];
1685
+					//$data['verticalrate'] = $line[16];
1686
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1687
+					//else $data['speed'] = 0;
1688
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1689
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1690
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1691
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1692 1692
 				    
1693
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1694
-				    //else echo 'No heading...'."\n";
1695
-				    //else $data['heading'] = 0;
1696
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1697
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1698
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1699
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1700
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1701
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1702
-    				    $data['id_source'] = $id_source;
1703
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1704
-				    else $data['format_source'] = 'aprs';
1705
-				    $data['source_name'] = $line['source'];
1706
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1707
-				    else $data['source_type'] = 'flarm';
1708
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1709
-				    $currentdate = date('Y-m-d H:i:s');
1710
-				    $aprsdate = strtotime($data['datetime']);
1711
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1712
-				    // Accept data if time <= system time + 20s
1713
-				    //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'])))) {
1714
-				    if (($data['source_type'] === 'modes') || isset($line['stealth']) && (!isset($data['hex']) || $data['hex'] != 'FFFFFF') && ($line['stealth'] === 0 || $line['stealth'] === '') && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1693
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1694
+					//else echo 'No heading...'."\n";
1695
+					//else $data['heading'] = 0;
1696
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1697
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1698
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1699
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1700
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1701
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1702
+						$data['id_source'] = $id_source;
1703
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1704
+					else $data['format_source'] = 'aprs';
1705
+					$data['source_name'] = $line['source'];
1706
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1707
+					else $data['source_type'] = 'flarm';
1708
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1709
+					$currentdate = date('Y-m-d H:i:s');
1710
+					$aprsdate = strtotime($data['datetime']);
1711
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1712
+					// Accept data if time <= system time + 20s
1713
+					//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'])))) {
1714
+					if (($data['source_type'] === 'modes') || isset($line['stealth']) && (!isset($data['hex']) || $data['hex'] != 'FFFFFF') && ($line['stealth'] === 0 || $line['stealth'] === '') && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1715 1715
 					$send = $SI->add($data);
1716
-				    } elseif ($data['source_type'] === 'ais') {
1716
+					} elseif ($data['source_type'] === 'ais') {
1717 1717
 					$data['type'] = '';
1718 1718
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1719
-				    } elseif (isset($line['stealth'])) {
1719
+					} elseif (isset($line['stealth'])) {
1720 1720
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1721 1721
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1722
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1723
-					    //$line['symbol'] === 'Balloon' ||
1724
-					    $line['symbol'] === 'Glider' || 
1725
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1726
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1727
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1728
-					    $send = $SI->add($data);
1729
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1730
-					    $line['symbol'] === 'Yacht (Sail)' || 
1731
-					    $line['symbol'] === 'Ship (Power Boat)')) {
1732
-					    $send = $MI->add($data);
1733
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1734
-					    $line['symbol'] === 'Car' || 
1735
-					    $line['symbol'] === 'Ambulance' || 
1736
-					    $line['symbol'] === 'Van' || 
1737
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1738
-					    $line['symbol'] === 'Motorcycle' || 
1739
-					    $line['symbol'] === 'Tractor' || 
1740
-					    $line['symbol'] === 'Police' || 
1741
-					    $line['symbol'] === 'Bike' || 
1742
-					    $line['symbol'] === 'Jogger' || 
1743
-					    $line['symbol'] === 'Horse' || 
1744
-					    $line['symbol'] === 'Bus' || 
1745
-					    $line['symbol'] === 'Jeep' || 
1746
-					    $line['symbol'] === 'Recreational Vehicle' || 
1747
-					    $line['symbol'] === 'Yacht (Sail)' || 
1748
-					    $line['symbol'] === 'Ship (Power Boat)' || 
1749
-					    $line['symbol'] === 'Firetruck' || 
1750
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1751
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1752
-					    $line['symbol'] === 'SUV' ||
1753
-					    $line['symbol'] === 'Snowmobile' ||
1754
-					    $line['symbol'] === 'Mobile Satellite Station')) {
1755
-				    //} 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') {
1722
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1723
+						//$line['symbol'] === 'Balloon' ||
1724
+						$line['symbol'] === 'Glider' || 
1725
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1726
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1727
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1728
+						$send = $SI->add($data);
1729
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1730
+						$line['symbol'] === 'Yacht (Sail)' || 
1731
+						$line['symbol'] === 'Ship (Power Boat)')) {
1732
+						$send = $MI->add($data);
1733
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1734
+						$line['symbol'] === 'Car' || 
1735
+						$line['symbol'] === 'Ambulance' || 
1736
+						$line['symbol'] === 'Van' || 
1737
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1738
+						$line['symbol'] === 'Motorcycle' || 
1739
+						$line['symbol'] === 'Tractor' || 
1740
+						$line['symbol'] === 'Police' || 
1741
+						$line['symbol'] === 'Bike' || 
1742
+						$line['symbol'] === 'Jogger' || 
1743
+						$line['symbol'] === 'Horse' || 
1744
+						$line['symbol'] === 'Bus' || 
1745
+						$line['symbol'] === 'Jeep' || 
1746
+						$line['symbol'] === 'Recreational Vehicle' || 
1747
+						$line['symbol'] === 'Yacht (Sail)' || 
1748
+						$line['symbol'] === 'Ship (Power Boat)' || 
1749
+						$line['symbol'] === 'Firetruck' || 
1750
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1751
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1752
+						$line['symbol'] === 'SUV' ||
1753
+						$line['symbol'] === 'Snowmobile' ||
1754
+						$line['symbol'] === 'Mobile Satellite Station')) {
1755
+					//} 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') {
1756 1756
 				//    } 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') {
1757 1757
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1758 1758
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1759
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1759
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1760 1760
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1761 1761
 					$Source->deleteOldLocationByType('gs');
1762 1762
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1764,7 +1764,7 @@  discard block
 block discarded – undo
1764 1764
 					} else {
1765 1765
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1766 1766
 					}
1767
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1767
+					} elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1768 1768
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1769 1769
 					if ($globalDebug) echo '# Weather Station added'."\n";
1770 1770
 					$Source->deleteOldLocationByType('wx');
@@ -1774,7 +1774,7 @@  discard block
 block discarded – undo
1774 1774
 					} else {
1775 1775
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1776 1776
 					}
1777
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1777
+					} elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1778 1778
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1779 1779
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1780 1780
 					$Source->deleteOldLocationByType('lightning');
@@ -1783,11 +1783,11 @@  discard block
 block discarded – undo
1783 1783
 					} else {
1784 1784
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1785 1785
 					}
1786
-				    } elseif ($globalDebug) {
1787
-				    	echo '/!\ Not added: '.$buffer."\n";
1788
-				    	print_r($line);
1789
-				    }
1790
-				    unset($data);
1786
+					} elseif ($globalDebug) {
1787
+						echo '/!\ Not added: '.$buffer."\n";
1788
+						print_r($line);
1789
+					}
1790
+					unset($data);
1791 1791
 				}
1792 1792
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1793 1793
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1806,12 +1806,12 @@  discard block
 block discarded – undo
1806 1806
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1807 1807
 					$globalSources[$nb]['last_weather_clean'] = time();
1808 1808
 				}
1809
-			    }
1809
+				}
1810 1810
 			} else {
1811
-			    $line = explode(',', $buffer);
1812
-    			    if (count($line) > 20) {
1813
-    			    	$data['hex'] = $line[4];
1814
-    				/*
1811
+				$line = explode(',', $buffer);
1812
+					if (count($line) > 20) {
1813
+						$data['hex'] = $line[4];
1814
+					/*
1815 1815
     				$data['datetime'] = $line[6].' '.$line[7];
1816 1816
     					date_default_timezone_set($globalTimezone);
1817 1817
     					$datetime = new DateTime($data['datetime']);
@@ -1819,31 +1819,31 @@  discard block
 block discarded – undo
1819 1819
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1820 1820
     					date_default_timezone_set('UTC');
1821 1821
     				*/
1822
-    				// Force datetime to current UTC datetime
1823
-    				date_default_timezone_set('UTC');
1824
-    				$data['datetime'] = date('Y-m-d H:i:s');
1825
-    				$data['ident'] = trim($line[10]);
1826
-    				$data['latitude'] = $line[14];
1827
-    				$data['longitude'] = $line[15];
1828
-    				$data['verticalrate'] = $line[16];
1829
-    				$data['emergency'] = $line[20];
1830
-    				$data['speed'] = $line[12];
1831
-    				$data['squawk'] = $line[17];
1832
-    				$data['altitude'] = $line[11];
1833
-    				$data['heading'] = $line[13];
1834
-    				$data['ground'] = $line[21];
1835
-    				$data['emergency'] = $line[19];
1836
-    				$data['format_source'] = 'sbs';
1822
+					// Force datetime to current UTC datetime
1823
+					date_default_timezone_set('UTC');
1824
+					$data['datetime'] = date('Y-m-d H:i:s');
1825
+					$data['ident'] = trim($line[10]);
1826
+					$data['latitude'] = $line[14];
1827
+					$data['longitude'] = $line[15];
1828
+					$data['verticalrate'] = $line[16];
1829
+					$data['emergency'] = $line[20];
1830
+					$data['speed'] = $line[12];
1831
+					$data['squawk'] = $line[17];
1832
+					$data['altitude'] = $line[11];
1833
+					$data['heading'] = $line[13];
1834
+					$data['ground'] = $line[21];
1835
+					$data['emergency'] = $line[19];
1836
+					$data['format_source'] = 'sbs';
1837 1837
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1838 1838
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
1839
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1839
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1840 1840
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1841
-    				$data['id_source'] = $id_source;
1842
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1843
-    				else $error = true;
1844
-    				unset($data);
1845
-    			    } else $error = true;
1846
-			    if ($error) {
1841
+					$data['id_source'] = $id_source;
1842
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1843
+					else $error = true;
1844
+					unset($data);
1845
+					} else $error = true;
1846
+				if ($error) {
1847 1847
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1848 1848
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1849 1849
 				} else {
@@ -1859,13 +1859,13 @@  discard block
 block discarded – undo
1859 1859
 					connect_all($sourceer);
1860 1860
 					$sourceer = array();
1861 1861
 				}
1862
-			    }
1862
+				}
1863 1863
 			}
1864 1864
 			// Sleep for xxx microseconds
1865 1865
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1866
-		    } else {
1866
+			} else {
1867 1867
 			if ($format === 'flightgearmp') {
1868
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1868
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1869 1869
 				//@socket_close($r);
1870 1870
 				sleep($globalMinFetch);
1871 1871
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1874,9 +1874,9 @@  discard block
 block discarded – undo
1874 1874
 				break;
1875 1875
 				
1876 1876
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1877
-			    if (isset($tt[$format])) $tt[$format]++;
1878
-			    else $tt[$format] = 0;
1879
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
1877
+				if (isset($tt[$format])) $tt[$format]++;
1878
+				else $tt[$format] = 0;
1879
+				if ($tt[$format] > 30 || $buffer === FALSE) {
1880 1880
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1881 1881
 				//@socket_close($r);
1882 1882
 				sleep(2);
@@ -1887,24 +1887,24 @@  discard block
 block discarded – undo
1887 1887
 				//connect_all($globalSources);
1888 1888
 				$tt[$format]=0;
1889 1889
 				break;
1890
-			    } 
1891
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1890
+				} 
1891
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1892
+			}
1892 1893
 			}
1893
-		    }
1894 1894
 		}
1895
-	    } else {
1895
+		} else {
1896 1896
 		$error = socket_strerror(socket_last_error());
1897 1897
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1898 1898
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1899 1899
 			if (isset($globalDebug)) echo "Restarting...\n";
1900 1900
 			// Restart the script if possible
1901 1901
 			if (is_array($sockets)) {
1902
-			    if ($globalDebug) echo "Shutdown all sockets...";
1902
+				if ($globalDebug) echo "Shutdown all sockets...";
1903 1903
 			    
1904
-			    foreach ($sockets as $sock) {
1904
+				foreach ($sockets as $sock) {
1905 1905
 				@socket_shutdown($sock,2);
1906 1906
 				@socket_close($sock);
1907
-			    }
1907
+				}
1908 1908
 			    
1909 1909
 			}
1910 1910
 			if ($globalDebug) echo "Waiting...";
@@ -1919,15 +1919,15 @@  discard block
 block discarded – undo
1919 1919
 			if ($globalDebug) echo "Restart all connections...";
1920 1920
 			connect_all($globalSources);
1921 1921
 		}
1922
-	    }
1922
+		}
1923 1923
 	}
1924 1924
 	if ($globalDaemon === false) {
1925
-	    if ($globalDebug) echo 'Check all...'."\n";
1926
-	    if (isset($SI)) $SI->checkAll();
1927
-	    if (isset($TI)) $TI->checkAll();
1928
-	    if (isset($MI)) $MI->checkAll();
1925
+		if ($globalDebug) echo 'Check all...'."\n";
1926
+		if (isset($SI)) $SI->checkAll();
1927
+		if (isset($TI)) $TI->checkAll();
1928
+		if (isset($MI)) $MI->checkAll();
1929
+	}
1929 1930
 	}
1930
-    }
1931 1931
 }
1932 1932
 
1933 1933
 ?>
Please login to merge, or discard this patch.