Completed
Push — master ( df3bbc...431371 )
by Yannick
26:06
created
scripts/daemon-spotter.php 3 patches
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,30 +1819,30 @@  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
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1838
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1839 1839
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1840
-    				$data['id_source'] = $id_source;
1841
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1842
-    				else $error = true;
1843
-    				unset($data);
1844
-    			    } else $error = true;
1845
-			    if ($error) {
1840
+					$data['id_source'] = $id_source;
1841
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1842
+					else $error = true;
1843
+					unset($data);
1844
+					} else $error = true;
1845
+				if ($error) {
1846 1846
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1847 1847
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1848 1848
 				} else {
@@ -1858,13 +1858,13 @@  discard block
 block discarded – undo
1858 1858
 					connect_all($sourceer);
1859 1859
 					$sourceer = array();
1860 1860
 				}
1861
-			    }
1861
+				}
1862 1862
 			}
1863 1863
 			// Sleep for xxx microseconds
1864 1864
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1865
-		    } else {
1865
+			} else {
1866 1866
 			if ($format === 'flightgearmp') {
1867
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1867
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1868 1868
 				//@socket_close($r);
1869 1869
 				sleep($globalMinFetch);
1870 1870
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1873,9 +1873,9 @@  discard block
 block discarded – undo
1873 1873
 				break;
1874 1874
 				
1875 1875
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1876
-			    if (isset($tt[$format])) $tt[$format]++;
1877
-			    else $tt[$format] = 0;
1878
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
1876
+				if (isset($tt[$format])) $tt[$format]++;
1877
+				else $tt[$format] = 0;
1878
+				if ($tt[$format] > 30 || $buffer === FALSE) {
1879 1879
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1880 1880
 				//@socket_close($r);
1881 1881
 				sleep(2);
@@ -1886,24 +1886,24 @@  discard block
 block discarded – undo
1886 1886
 				//connect_all($globalSources);
1887 1887
 				$tt[$format]=0;
1888 1888
 				break;
1889
-			    } 
1890
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1889
+				} 
1890
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1891
+			}
1891 1892
 			}
1892
-		    }
1893 1893
 		}
1894
-	    } else {
1894
+		} else {
1895 1895
 		$error = socket_strerror(socket_last_error());
1896 1896
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1897 1897
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1898 1898
 			if (isset($globalDebug)) echo "Restarting...\n";
1899 1899
 			// Restart the script if possible
1900 1900
 			if (is_array($sockets)) {
1901
-			    if ($globalDebug) echo "Shutdown all sockets...";
1901
+				if ($globalDebug) echo "Shutdown all sockets...";
1902 1902
 			    
1903
-			    foreach ($sockets as $sock) {
1903
+				foreach ($sockets as $sock) {
1904 1904
 				@socket_shutdown($sock,2);
1905 1905
 				@socket_close($sock);
1906
-			    }
1906
+				}
1907 1907
 			    
1908 1908
 			}
1909 1909
 			if ($globalDebug) echo "Waiting...";
@@ -1918,15 +1918,15 @@  discard block
 block discarded – undo
1918 1918
 			if ($globalDebug) echo "Restart all connections...";
1919 1919
 			connect_all($globalSources);
1920 1920
 		}
1921
-	    }
1921
+		}
1922 1922
 	}
1923 1923
 	if ($globalDaemon === false) {
1924
-	    if ($globalDebug) echo 'Check all...'."\n";
1925
-	    if (isset($SI)) $SI->checkAll();
1926
-	    if (isset($TI)) $TI->checkAll();
1927
-	    if (isset($MI)) $MI->checkAll();
1924
+		if ($globalDebug) echo 'Check all...'."\n";
1925
+		if (isset($SI)) $SI->checkAll();
1926
+		if (isset($TI)) $TI->checkAll();
1927
+		if (isset($MI)) $MI->checkAll();
1928
+	}
1928 1929
 	}
1929
-    }
1930 1930
 }
1931 1931
 
1932 1932
 ?>
Please login to merge, or discard this patch.
Spacing   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
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() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,40 +150,40 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 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;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 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
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
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 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
176
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftjson';
178 178
         	$globalSources[$id]['format'] = 'aircraftjson';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
180 180
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraft$/i',$host)) {
181
+    	    } else if (preg_match('/aircraft$/i', $host)) {
182 182
         	//$formats[$id] = 'planefinderclient';
183 183
         	$globalSources[$id]['format'] = 'planefinderclient';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
186
-    	    } else if (preg_match('/opensky/i',$host)) {
186
+    	    } else if (preg_match('/opensky/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftlistjson';
188 188
         	$globalSources[$id]['format'] = 'opensky';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         	    exit(0);
201 201
         	}
202 202
     	    */
203
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
203
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
204 204
         	//$formats[$id] = 'planeupdatefaa';
205 205
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 206
         	//$last_exec['planeupdatefaa'] = 0;
@@ -209,37 +209,37 @@  discard block
 block discarded – undo
209 209
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 210
         	    exit(0);
211 211
         	}
212
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
212
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'phpvmacars';
215 215
         	//$last_exec['phpvmacars'] = 0;
216 216
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
217
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
217
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
218 218
         	//$formats[$id] = 'phpvmacars';
219 219
         	$globalSources[$id]['format'] = 'vaos';
220 220
         	//$last_exec['phpvmacars'] = 0;
221 221
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
222
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
222
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'vam';
225 225
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
226
-            } else if (preg_match('/whazzup/i',$host)) {
226
+            } else if (preg_match('/whazzup/i', $host)) {
227 227
         	//$formats[$id] = 'whazzup';
228 228
         	$globalSources[$id]['format'] = 'whazzup';
229 229
         	//$last_exec['whazzup'] = 0;
230 230
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
231
-            } else if (preg_match('/blitzortung/i',$host)) {
231
+            } else if (preg_match('/blitzortung/i', $host)) {
232 232
         	$globalSources[$id]['format'] = 'blitzortung';
233 233
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
234
-            } else if (preg_match('/airwhere/i',$host)) {
234
+            } else if (preg_match('/airwhere/i', $host)) {
235 235
         	$globalSources[$id]['format'] = 'airwhere';
236 236
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
237
-            } else if (preg_match('/recentpireps/i',$host)) {
237
+            } else if (preg_match('/recentpireps/i', $host)) {
238 238
         	//$formats[$id] = 'pirepsjson';
239 239
         	$globalSources[$id]['format'] = 'pirepsjson';
240 240
         	//$last_exec['pirepsjson'] = 0;
241 241
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
242
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
242
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
243 243
         	//$formats[$id] = 'fr24json';
244 244
         	$globalSources[$id]['format'] = 'fr24json';
245 245
         	//$last_exec['fr24json'] = 0;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 249
         	    exit(0);
250 250
         	}
251
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
251
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
252 252
         	//$formats[$id] = 'fr24json';
253 253
         	$globalSources[$id]['format'] = 'myshiptracking';
254 254
         	//$last_exec['fr24json'] = 0;
@@ -258,21 +258,21 @@  discard block
 block discarded – undo
258 258
         	    exit(0);
259 259
         	}
260 260
             //} else if (preg_match('/10001/',$host)) {
261
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
261
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 262
         	//$formats[$id] = 'tsv';
263 263
         	$globalSources[$id]['format'] = 'tsv';
264 264
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
265 265
             }
266
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
266
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
267 267
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
268
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
269 269
     		    if ($idf !== false) {
270 270
     			$httpfeeds[$id] = $idf;
271 271
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
272 272
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
273 273
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
274
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
275
-	    $hostport = explode(':',$host);
274
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
275
+	    $hostport = explode(':', $host);
276 276
 	    if (isset($hostport[1])) {
277 277
 		$port = $hostport[1];
278 278
 		$hostn = $hostport[0];
@@ -282,19 +282,19 @@  discard block
 block discarded – undo
282 282
 	    }
283 283
 	    $Common = new Common();
284 284
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
285
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
285
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
286 286
     	    } else {
287
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
287
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
288 288
 	    }
289 289
 	    if ($s) {
290 290
     	        $sockets[$id] = $s;
291 291
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
292
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
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 299
     		    } elseif ($port == '10001') {
300 300
         		//$formats[$id] = 'tsv';
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
336 336
 else $timeout = 20;
337 337
 $errno = '';
338
-$errstr='';
338
+$errstr = '';
339 339
 
340 340
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
341 341
 /* Initiate connections to all the hosts simultaneously */
@@ -343,7 +343,7 @@  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 348
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
349 349
 }
@@ -373,16 +373,16 @@  discard block
 block discarded – undo
373 373
 
374 374
 if ($use_aprs) {
375 375
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
376
-	$APRS=new APRS();
376
+	$APRS = new APRS();
377 377
 	$aprs_connect = 0;
378 378
 	$aprs_keep = 120;
379 379
 	$aprs_last_tx = time();
380 380
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
381
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
381
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
382 382
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
383
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
383
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
384 384
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
385
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
385
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386 386
 	if ($aprs_full) $aprs_filter = '';
387 387
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
388 388
 	else $aprs_pass = '-1';
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
 sleep(1);
397 397
 if ($globalDebug) echo "SCAN MODE \n\n";
398 398
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
399
-$endtime = time()+$globalCronEnd;
399
+$endtime = time() + $globalCronEnd;
400 400
 $i = 1;
401 401
 $tt = array();
402 402
 // Delete all ATC
403 403
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
404
-	$ATC=new ATC($Connection->db);
404
+	$ATC = new ATC($Connection->db);
405 405
 }
406 406
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
407 407
 	$ATC->deleteAll();
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 while ($i > 0) {
412 412
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
413 413
 
414
-    if (!$globalDaemon) $i = $endtime-time();
414
+    if (!$globalDaemon) $i = $endtime - time();
415 415
     // Delete old ATC
416 416
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
417 417
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 	}
426 426
 	if ($max < $globalMinFetch) {
427 427
 	    if ($globalDebug) echo 'Sleeping...'."\n";
428
-	    sleep($globalMinFetch-$max+2);
428
+	    sleep($globalMinFetch - $max + 2);
429 429
 	}
430 430
     }
431 431
 
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	    //$buffer = $Common->getData($hosts[$id]);
445 445
 	    $buffer = $Common->getData($value['host']);
446 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);
447
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
448
+	    $buffer = explode('\n', $buffer);
449 449
 	    foreach ($buffer as $line) {
450 450
     		if ($line != '' && count($line) > 7) {
451 451
     		    $line = explode(',', $line);
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
 	    )
479 479
 	) {
480 480
 	    date_default_timezone_set('CET');
481
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
481
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
482 482
 	    date_default_timezone_set('UTC');
483 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);
484
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
485
+	    $buffer = explode('\n', $buffer);
486 486
 	    foreach ($buffer as $line) {
487 487
 		if ($line != '') {
488 488
 		    //echo "'".$line."'\n";
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 		    $ais_data = $AIS->parse_line(trim($line));
491 491
 		    $data = array();
492 492
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
493
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
493
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
494 494
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
495 495
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
496 496
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
503 503
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
504 504
 		    if (isset($ais_data['timestamp'])) {
505
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
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 507
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
508 508
 			    $add = true;
@@ -525,21 +525,21 @@  discard block
 block discarded – undo
525 525
 	    $w = $e = null;
526 526
 	    
527 527
 	    if (isset($arr[$id])) {
528
-		$nn = stream_select($arr,$w,$e,$timeout);
528
+		$nn = stream_select($arr, $w, $e, $timeout);
529 529
 		if ($nn > 0) {
530 530
 		    foreach ($httpfeeds as $feed) {
531
-			$buffer = stream_get_line($feed,2000,"\n");
531
+			$buffer = stream_get_line($feed, 2000, "\n");
532 532
 			if ($buffer === FALSE) {
533 533
 			    connect_all($globalSources);
534 534
 			}
535
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
536
-			$buffer = explode('\n',$buffer);
535
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
536
+			$buffer = explode('\n', $buffer);
537 537
 			foreach ($buffer as $line) {
538 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'];
542
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
542
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
543 543
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
544 544
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
545 545
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -551,9 +551,9 @@  discard block
 block discarded – undo
551 551
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
552 552
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553 553
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
554
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
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 558
 				    $data['datetime'] = date('Y-m-d H:i:s');
559 559
 				}
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
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');
588
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
589 589
 	    if ($buffer != '') {
590 590
 		//echo $buffer;
591
-		$all_data = json_decode($buffer,true);
591
+		$all_data = json_decode($buffer, true);
592 592
 		//print_r($all_data);
593 593
 		if (isset($all_data[0]['DATA'])) {
594 594
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 			    $data['ident'] = $line['NAME'];
598 598
 			    $data['mmsi'] = $line['MMSI'];
599 599
 			    if (strlen($data['mmsi']) > 9) {
600
-				$data['mmsi'] = substr($data['mmsi'],-9);
600
+				$data['mmsi'] = substr($data['mmsi'], -9);
601 601
 			    }
602 602
 			    $data['speed'] = $line['SOG'];
603 603
 			    $data['heading'] = $line['COG'];
@@ -607,8 +607,8 @@  discard block
 block discarded – undo
607 607
 			    //$data['type_id'] = $line['TYPE'];
608 608
 			    $data['imo'] = $line['IMO'];
609 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']);
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 612
 			    $data['format_source'] = 'myshiptracking';
613 613
 			    $data['id_source'] = $id_source;
614 614
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -625,16 +625,16 @@  discard block
 block discarded – undo
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']));
628
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
629 629
 	    if ($buffer != '') {
630
-		$all_data = json_decode($buffer,true);
630
+		$all_data = json_decode($buffer, true);
631 631
 		if (isset($all_data[0]['mmsi'])) {
632 632
 		    foreach ($all_data as $line) {
633 633
 			if ($line != '') {
634 634
 			    $data = array();
635 635
 			    $data['ident'] = $line['shipname'];
636 636
 			    $data['callsign'] = $line['callsign'];
637
-			    $data['mmsi'] = substr($line['mmsi'],-9);
637
+			    $data['mmsi'] = substr($line['mmsi'], -9);
638 638
 			    $data['speed'] = $line['sog'];
639 639
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
640 640
 			    $data['latitude'] = $line['latitude'];
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
 	) {
662 662
 	    $buffer = $Common->getData($value['host']);
663 663
 	    if ($buffer != '') {
664
-		$all_data = json_decode($buffer,true);
664
+		$all_data = json_decode($buffer, true);
665 665
 		if (isset($all_data['features'][0]['id'])) {
666 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'];
670 670
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
671
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
671
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
672 672
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
673 673
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
674 674
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -695,31 +695,31 @@  discard block
 block discarded – undo
695 695
 	    )
696 696
 	) {
697 697
 	    echo 'download...';
698
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
698
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
699 699
 	    echo 'done !'."\n";
700 700
 	    // FIXME: Need more work
701 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);
702
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
703
+	    $buffer = explode('\n', $buffer);
704 704
 	    foreach ($buffer as $line) {
705 705
 		if ($line != '') {
706 706
 		    $data = array();
707 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));
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 715
 		    //$data['course'] = substr($line,57,5);
716
-		    $data['heading'] = round(substr($line,63,3));
716
+		    $data['heading'] = round(substr($line, 63, 3));
717 717
 		    //$data['draft'] = substr($line,67,4);
718 718
 		    //$data['length'] = substr($line,72,3);
719 719
 		    //$data['beam'] = substr($line,76,2);
720
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
720
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
721 721
 		    //$data['callsign'] = trim(substr($line,100,7);
722
-		    $data['arrival_code'] = substr($line,108,20);
722
+		    $data['arrival_code'] = substr($line, 108, 20);
723 723
 		    //$data['etaDate'] = substr($line,129,5);
724 724
 		    //$data['etaTime'] = substr($line,135,5);
725 725
 		    $data['format_source'] = 'shipplotter';
@@ -750,8 +750,8 @@  discard block
 block discarded – undo
750 750
 	) {
751 751
 	    //$buffer = $Common->getData($hosts[$id]);
752 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);
753
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
754
+	    $buffer = explode('\n', $buffer);
755 755
 	    $reset = 0;
756 756
 	    foreach ($buffer as $line) {
757 757
     		if ($line != '') {
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
763 763
 			$data['pilot_id'] = $line[1];
764 764
 			$data['pilot_name'] = $line[2];
765
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
765
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
766 766
 			$data['ident'] = $line[0]; // ident
767 767
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
768 768
 			$data['speed'] = $line[8]; // speed
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
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 780
 		        $data['departure_airport_icao'] = $line[11];
781
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
781
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
782 782
 		        $data['arrival_airport_icao'] = $line[13];
783 783
 			$data['frequency'] = $line[4];
784 784
 			$data['type'] = $line[18];
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
     			$data['id_source'] = $id_source;
788 788
 	    		//$data['arrival_airport_time'] = ;
789 789
 	    		if ($line[9] != '') {
790
-	    		    $aircraft_data = explode('/',$line[9]);
790
+	    		    $aircraft_data = explode('/', $line[9]);
791 791
 	    		    if (isset($aircraft_data[1])) {
792 792
 	    			$data['aircraft_icao'] = $aircraft_data[1];
793 793
 	    		    }
@@ -802,9 +802,9 @@  discard block
 block discarded – undo
802 802
     			if ($line[3] === 'PILOT') $SI->add($data);
803 803
 			elseif ($line[3] === 'ATC') {
804 804
 				//print_r($data);
805
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
806
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
807
-				$typec = substr($data['ident'],-3);
805
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
806
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
807
+				$typec = substr($data['ident'], -3);
808 808
 				if ($typec === 'APP') $data['type'] = 'Approach';
809 809
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
810 810
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -816,8 +816,8 @@  discard block
 block discarded – undo
816 816
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
817 817
 				if (!isset($data['source_name'])) $data['source_name'] = '';
818 818
 				if (isset($ATC)) {
819
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
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']);
819
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
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 823
     			unset($data);
@@ -833,24 +833,24 @@  discard block
 block discarded – undo
833 833
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
834 834
     	    )
835 835
     	) {
836
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
836
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
837 837
 	    if ($buffer != '') {
838 838
 		$all_data = simplexml_load_string($buffer);
839
-		foreach($all_data->children() as $childdata) {
839
+		foreach ($all_data->children() as $childdata) {
840 840
 			$data = array();
841 841
 			$line = $childdata;
842 842
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
843
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
844
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
845
-			$data['latitude'] = (float)$line['pktLatitude'];
846
-			$data['longitude'] = (float)$line['pktLongitude'];
847
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
848
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
849
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
843
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
844
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
845
+			$data['latitude'] = (float) $line['pktLatitude'];
846
+			$data['longitude'] = (float) $line['pktLongitude'];
847
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
848
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
849
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
850 850
 			$data['altitude_relative'] = 'AMSL';
851
-			$data['pilot_id'] = (int)$line['pktPilotID'];
851
+			$data['pilot_id'] = (int) $line['pktPilotID'];
852 852
 			$data['aircraft_icao'] = 'PARAGLIDER';
853
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
853
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
854 854
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
855 855
 			$data['format_source'] = $value['format'];
856 856
 			$SI->add($data);
@@ -858,22 +858,22 @@  discard block
 block discarded – undo
858 858
 		}
859 859
 	    }
860 860
 	    $Source->deleteOldLocationByType('gs');
861
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
861
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
862 862
 	    if ($buffer != '') {
863 863
 		$all_data = simplexml_load_string($buffer);
864
-		foreach($all_data->children() as $childdata) {
864
+		foreach ($all_data->children() as $childdata) {
865 865
 			$data = array();
866 866
 			$line = $childdata;
867
-			$data['id'] = (int)$line['gsID'];
868
-			$data['latitude'] = (float)$line['gsLatitude'];
869
-			$data['longitude'] = (float)$line['gsLongitude'];
870
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
867
+			$data['id'] = (int) $line['gsID'];
868
+			$data['latitude'] = (float) $line['gsLatitude'];
869
+			$data['longitude'] = (float) $line['gsLongitude'];
870
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
871 871
 			$data['altitude_relative'] = 'AMSL';
872
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
872
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
873 873
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
874
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
874
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
875 875
 			} else {
876
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
876
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
877 877
 			}
878 878
 			unset($data);
879 879
 		}
@@ -891,9 +891,9 @@  discard block
 block discarded – undo
891 891
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
892 892
 	    )
893 893
 	) {
894
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
894
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
895 895
 	    if ($buffer != '') {
896
-	        $all_data = json_decode($buffer,true);
896
+	        $all_data = json_decode($buffer, true);
897 897
 		if (isset($all_data['acList'])) {
898 898
 		    $reset = 0;
899 899
 		    foreach ($all_data['acList'] as $line) {
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
910 910
 			$data['emergency'] = ''; // emergency
911 911
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
912
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
912
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
913 913
 			else $data['datetime'] = date('Y-m-d H:i:s');
914 914
 			//$data['datetime'] = date('Y-m-d H:i:s');
915 915
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 			$data['verticalrate'] = $line['vrt']; // verticale rate
935 935
 			$data['squawk'] = $line['squawk']; // squawk
936 936
 			$data['emergency'] = ''; // emergency
937
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
937
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
938 938
 			else $data['datetime'] = date('Y-m-d H:i:s');
939 939
 			$data['format_source'] = 'aircraftlistjson';
940 940
 			$data['id_source'] = $id_source;
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
     	    )
956 956
     	) {
957 957
 	    $buffer = $Common->getData($value['host']);
958
-	    $all_data = json_decode($buffer,true);
958
+	    $all_data = json_decode($buffer, true);
959 959
 	    if (isset($all_data['planes'])) {
960 960
 		$reset = 0;
961 961
 		foreach ($all_data['planes'] as $key => $line) {
@@ -972,12 +972,12 @@  discard block
 block discarded – undo
972 972
 		    $data['emergency'] = ''; // emergency
973 973
 		    $data['registration'] = $line[2];
974 974
 		    $data['aircraft_icao'] = $line[0];
975
-		    $deparr = explode('-',$line[1]);
975
+		    $deparr = explode('-', $line[1]);
976 976
 		    if (count($deparr) === 2) {
977 977
 			$data['departure_airport_icao'] = $deparr[0];
978 978
 			$data['arrival_airport_icao'] = $deparr[1];
979 979
 		    }
980
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
980
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
981 981
 	    	    $data['format_source'] = 'planeupdatefaa';
982 982
     		    $data['id_source'] = $id_source;
983 983
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 	    )
996 996
 	) {
997 997
 	    $buffer = $Common->getData($value['host']);
998
-	    $all_data = json_decode($buffer,true);
998
+	    $all_data = json_decode($buffer, true);
999 999
 	    if (isset($all_data['states'])) {
1000 1000
 		$reset = 0;
1001 1001
 		foreach ($all_data['states'] as $key => $line) {
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 		    //$data['emergency'] = ''; // emergency
1013 1013
 		    //$data['registration'] = $line[2];
1014 1014
 		    //$data['aircraft_icao'] = $line[0];
1015
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1015
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1016 1016
 		    $data['format_source'] = 'opensky';
1017 1017
 		    $data['id_source'] = $id_source;
1018 1018
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	    )
1030 1030
 	) {
1031 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) {
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 1036
 		    $data = array();
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 	    )
1069 1069
 	) {
1070 1070
 	    $buffer = $Common->getData($value['host']);
1071
-	    $all_data = json_decode($buffer,true);
1071
+	    $all_data = json_decode($buffer, true);
1072 1072
 	    if (isset($all_data['aircraft'])) {
1073 1073
 		$reset = 0;
1074 1074
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 		    //$data['emergency'] = ''; // emergency
1086 1086
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1087 1087
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1088
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1088
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1089 1089
 		    $data['format_source'] = 'planefinderclient';
1090 1090
 		    $data['id_source'] = $id_source;
1091 1091
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 	) {
1105 1105
 	    //$buffer = $Common->getData($hosts[$id]);
1106 1106
 	    $buffer = $Common->getData($value['host']);
1107
-	    $all_data = json_decode($buffer,true);
1107
+	    $all_data = json_decode($buffer, true);
1108 1108
 	    if (!empty($all_data)) $reset = 0;
1109 1109
 	    foreach ($all_data as $key => $line) {
1110 1110
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1142,11 +1142,11 @@  discard block
 block discarded – undo
1142 1142
 	    )
1143 1143
 	) {
1144 1144
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1145
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1145
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1146 1146
 	    //echo $buffer;
1147
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1148
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1149
-	    $all_data = json_decode($buffer,true);
1147
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1148
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1149
+	    $all_data = json_decode($buffer, true);
1150 1150
 	    if (json_last_error() != JSON_ERROR_NONE) {
1151 1151
 		die(json_last_error_msg());
1152 1152
 	    }
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 			//$data['departure_airport_iata'] = $line[11];
1170 1170
 			//$data['arrival_airport_iata'] = $line[12];
1171 1171
 	    		//$data['emergency'] = ''; // emergency
1172
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1172
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1173 1173
 	    		$data['format_source'] = 'radarvirtueljson';
1174 1174
     			$data['id_source'] = $id_source;
1175 1175
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1190,14 +1190,14 @@  discard block
 block discarded – undo
1190 1190
 	) {
1191 1191
 	    //$buffer = $Common->getData($hosts[$id]);
1192 1192
 	    $buffer = $Common->getData($value['host'].'?'.time());
1193
-	    $all_data = json_decode(utf8_encode($buffer),true);
1193
+	    $all_data = json_decode(utf8_encode($buffer), true);
1194 1194
 	    
1195 1195
 	    if (isset($all_data['pireps'])) {
1196 1196
 		$reset = 0;
1197 1197
 	        foreach ($all_data['pireps'] as $line) {
1198 1198
 		    $data = array();
1199 1199
 		    $data['id'] = $line['id'];
1200
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1200
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1201 1201
 		    $data['ident'] = $line['callsign']; // ident
1202 1202
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1203 1203
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1227,9 +1227,9 @@  discard block
 block discarded – undo
1227 1227
 			$SI->add($data);
1228 1228
 		    //    print_r($data);
1229 1229
     		    } elseif ($line['icon'] === 'ct') {
1230
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1231
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1232
-			$typec = substr($data['ident'],-3);
1230
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1231
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1232
+			$typec = substr($data['ident'], -3);
1233 1233
 			$data['type'] = '';
1234 1234
 			if ($typec === 'APP') $data['type'] = 'Approach';
1235 1235
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1241 1241
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1242 1242
 			else $data['type'] = 'Observer';
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']);
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 1244
 		    }
1245 1245
 		    unset($data);
1246 1246
 		}
@@ -1257,14 +1257,14 @@  discard block
 block discarded – undo
1257 1257
 	    //$buffer = $Common->getData($hosts[$id]);
1258 1258
 	    if ($globalDebug) echo 'Get Data...'."\n";
1259 1259
 	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1260
+	    $all_data = json_decode($buffer, true);
1261 1261
 	    if ($buffer != '' && is_array($all_data)) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data as $line) {
1264 1264
 	    	    $data = array();
1265 1265
 	    	    //$data['id'] = $line['id']; // id not usable
1266 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
1267
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1268 1268
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1269 1269
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1270 1270
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
 	    	    //$data['datetime'] = $line['lastupdate'];
1280 1280
 	    	    //$data['last_update'] = $line['lastupdate'];
1281 1281
 	    	    if (isset($value['timezone'])) {
1282
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1282
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1283 1283
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1284 1284
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1285 1285
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1295,14 +1295,14 @@  discard block
 block discarded – undo
1295 1295
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1296 1296
 		    if (isset($line['aircraftname'])) {
1297 1297
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1298
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1299
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1298
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1299
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1300 1300
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1301 1301
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1302 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']);
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 1306
 	    		}
1307 1307
 	    	    }
1308 1308
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
 	    //$buffer = $Common->getData($hosts[$id]);
1328 1328
 	    if ($globalDebug) echo 'Get Data...'."\n";
1329 1329
 	    $buffer = $Common->getData($value['host']);
1330
-	    $all_data = json_decode($buffer,true);
1330
+	    $all_data = json_decode($buffer, true);
1331 1331
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1332 1332
 		$reset = 0;
1333 1333
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1339 1339
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1340 1340
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1341
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1341
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1342 1342
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1343 1343
 	    	    $data['altitude'] = $line['altitude']; // altitude
1344 1344
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 	    	    //$data['squawk'] = ''; // squawk
1350 1350
 	    	    //$data['emergency'] = ''; // emergency
1351 1351
 	    	    if (isset($value['timezone'])) {
1352
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1352
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1353 1353
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1354 1354
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1355 1355
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1385,14 +1385,14 @@  discard block
 block discarded – undo
1385 1385
 	    //$buffer = $Common->getData($hosts[$id]);
1386 1386
 	    if ($globalDebug) echo 'Get Data...'."\n";
1387 1387
 	    $buffer = $Common->getData($value['host']);
1388
-	    $all_data = json_decode($buffer,true);
1388
+	    $all_data = json_decode($buffer, true);
1389 1389
 	    if ($buffer != '' && is_array($all_data)) {
1390 1390
 		$reset = 0;
1391 1391
 		foreach ($all_data as $line) {
1392 1392
 	    	    $data = array();
1393 1393
 	    	    //$data['id'] = $line['id']; // id not usable
1394 1394
 	    	    $data['id'] = trim($line['flight_id']);
1395
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1395
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1396 1396
 	    	    $data['pilot_name'] = $line['pilot_name'];
1397 1397
 	    	    $data['pilot_id'] = $line['pilot_id'];
1398 1398
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1436,24 +1436,24 @@  discard block
 block discarded – undo
1436 1436
 	    //$buffer = $Common->getData($hosts[$id]);
1437 1437
 	    if ($globalDebug) echo 'Get Data...'."\n";
1438 1438
 	    $buffer = $Common->getData($value['host']);
1439
-	    $all_data = json_decode($buffer,true);
1439
+	    $all_data = json_decode($buffer, true);
1440 1440
 	    if ($buffer != '') {
1441 1441
 		$Source->deleteLocationBySource('blitzortung');
1442
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1443
-		$buffer = explode('\n',$buffer);
1442
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1443
+		$buffer = explode('\n', $buffer);
1444 1444
 		foreach ($buffer as $buffer_line) {
1445
-		    $line = json_decode($buffer_line,true);
1445
+		    $line = json_decode($buffer_line, true);
1446 1446
 		    if (isset($line['time'])) {
1447 1447
 			$data = array();
1448 1448
 			$data['altitude'] = $line['alt']; // altitude
1449 1449
 			$data['latitude'] = $line['lat']; // lat
1450 1450
 			$data['longitude'] = $line['lon']; // long
1451
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1451
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1452 1452
 			$data['id_source'] = $id_source;
1453 1453
 			$data['format_source'] = 'blitzortung';
1454 1454
 			$SI->add($data);
1455 1455
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1456
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
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
 		}
@@ -1476,11 +1476,11 @@  discard block
 block discarded – undo
1476 1476
 		    //$value = $formats[$nb];
1477 1477
 		    $format = $globalSources[$nb]['format'];
1478 1478
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1479
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1479
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1480 1480
 		    } elseif ($format === 'vrstcp') {
1481 1481
 			$buffer = @socket_read($r, 6000);
1482 1482
 		    } else {
1483
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1483
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1484 1484
 		    }
1485 1485
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1486 1486
 		    //echo $buffer."\n";
@@ -1490,8 +1490,8 @@  discard block
 block discarded – undo
1490 1490
 		    //$SI::del();
1491 1491
 		    if ($buffer !== FALSE) {
1492 1492
 			if ($format === 'vrstcp') {
1493
-			    $buffer = explode('},{',$buffer);
1494
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1493
+			    $buffer = explode('},{', $buffer);
1494
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1495 1495
 		    }
1496 1496
 		    // SBS format is CSV format
1497 1497
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
 			    $ais_data = $AIS->parse_line(trim($buffer));
1516 1516
 			    $data = array();
1517 1517
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1518
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1518
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1519 1519
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1520 1520
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1521 1521
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1526,13 +1526,13 @@  discard block
 block discarded – undo
1526 1526
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1527 1527
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1528 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']);
1529
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1530 1530
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1531 1531
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1532 1532
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1533 1533
 
1534 1534
 			    if (isset($ais_data['timestamp'])) {
1535
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1535
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1536 1536
 			    } else {
1537 1537
 				$data['datetime'] = date('Y-m-d H:i:s');
1538 1538
 			    }
@@ -1543,10 +1543,10 @@  discard block
 block discarded – undo
1543 1543
                         } elseif ($format === 'flightgearsp') {
1544 1544
                     	    //echo $buffer."\n";
1545 1545
                     	    if (strlen($buffer) > 5) {
1546
-				$line = explode(',',$buffer);
1546
+				$line = explode(',', $buffer);
1547 1547
 				$data = array();
1548 1548
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1549
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1549
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1550 1550
 				$data['ident'] = $line[6];
1551 1551
 				$data['aircraft_name'] = $line[7];
1552 1552
 				$data['longitude'] = $line[1];
@@ -1563,16 +1563,16 @@  discard block
 block discarded – undo
1563 1563
                         } elseif ($format === 'acars') {
1564 1564
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1565 1565
 			    $ACARS->add(trim($buffer));
1566
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1566
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1567 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
-				$line = explode(' ',$buffer);
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
1574
+				    $userserver = explode('@', $line[0]);
1575
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1576 1576
 				    $data['ident'] = $userserver[0];
1577 1577
 				    $data['registration'] = $userserver[0];
1578 1578
 				    $data['latitude'] = $line[4];
@@ -1580,8 +1580,8 @@  discard block
 block discarded – undo
1580 1580
 				    $data['altitude'] = $line[6];
1581 1581
 				    $data['datetime'] = date('Y-m-d H:i:s');
1582 1582
 				    $aircraft_type = $line[10];
1583
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1584
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1583
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1584
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1585 1585
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1586 1586
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1587 1587
 				}
@@ -1590,8 +1590,8 @@  discard block
 block discarded – undo
1590 1590
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1591 1591
 			    die;
1592 1592
 			} elseif ($format === 'vrstcp') {
1593
-			    foreach($buffer as $all_data) {
1594
-				$line = json_decode('{'.$all_data.'}',true);
1593
+			    foreach ($buffer as $all_data) {
1594
+				$line = json_decode('{'.$all_data.'}', true);
1595 1595
 				$data = array();
1596 1596
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1597 1597
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1617,16 +1617,16 @@  discard block
 block discarded – undo
1617 1617
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1618 1618
 				unset($data);
1619 1619
 			    }
1620
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1620
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1621 1621
 			    $line = explode("\t", $buffer);
1622
-			    for($k = 0; $k < count($line); $k=$k+2) {
1622
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1623 1623
 				$key = $line[$k];
1624
-			        $lined[$key] = $line[$k+1];
1624
+			        $lined[$key] = $line[$k + 1];
1625 1625
 			    }
1626 1626
     			    if (count($lined) > 3) {
1627 1627
     				$data['hex'] = $lined['hexid'];
1628 1628
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1629
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1629
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1630 1630
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1631 1631
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1632 1632
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1645,23 +1645,23 @@  discard block
 block discarded – undo
1645 1645
     			    } else $error = true;
1646 1646
 			} elseif ($format === 'aprs' && $use_aprs) {
1647 1647
 			    if ($aprs_connect === 0) {
1648
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
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
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1655
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1656 1656
 			    }
1657 1657
 			    
1658 1658
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1659 1659
 			    //echo 'APRS data : '.$buffer."\n";
1660
-			    $buffer = str_replace('APRS <- ','',$buffer);
1661
-			    $buffer = str_replace('APRS -> ','',$buffer);
1660
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1661
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1662 1662
 			    //echo $buffer."\n";
1663 1663
 			    date_default_timezone_set('UTC');
1664
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
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']))) {
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1677 1677
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1678 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']);
1679
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1680 1680
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1681 1681
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1682 1682
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1759,29 +1759,29 @@  discard block
 block discarded – undo
1759 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
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1763
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1762
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1763
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1764 1764
 					} else {
1765
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1765
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1766 1766
 					}
1767 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');
1771 1771
 					$weather_data = json_encode($line);
1772
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1773
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1772
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1773
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1774 1774
 					} else {
1775
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
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 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');
1781
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1782
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1781
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1782
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1783 1783
 					} else {
1784
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
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 1786
 				    } elseif ($globalDebug) {
1787 1787
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
 				    unset($data);
1791 1791
 				}
1792 1792
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1793
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1793
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1794 1794
 				}
1795 1795
 				/*
1796 1796
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] === 'Car' || $line['symbol'] === 'Ambulance' || $line['symbol'] === 'Van' || $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || $line['symbol'] === 'Motorcycle')) {
@@ -1799,7 +1799,7 @@  discard block
 block discarded – undo
1799 1799
 				*/
1800 1800
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1801 1801
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1802
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1802
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1803 1803
 					$Source->deleteOldLocationByType('lightning');
1804 1804
 					$Source->deleteOldLocationByType('wx');
1805 1805
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1884,7 +1884,7 @@  discard block
 block discarded – undo
1884 1884
 				connect_all($sourceee);
1885 1885
 				$sourceee = array();
1886 1886
 				//connect_all($globalSources);
1887
-				$tt[$format]=0;
1887
+				$tt[$format] = 0;
1888 1888
 				break;
1889 1889
 			    } 
1890 1890
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1894,14 +1894,14 @@  discard block
 block discarded – undo
1894 1894
 	    } else {
1895 1895
 		$error = socket_strerror(socket_last_error());
1896 1896
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1897
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1897
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1898 1898
 			if (isset($globalDebug)) echo "Restarting...\n";
1899 1899
 			// Restart the script if possible
1900 1900
 			if (is_array($sockets)) {
1901 1901
 			    if ($globalDebug) echo "Shutdown all sockets...";
1902 1902
 			    
1903 1903
 			    foreach ($sockets as $sock) {
1904
-				@socket_shutdown($sock,2);
1904
+				@socket_shutdown($sock, 2);
1905 1905
 				@socket_close($sock);
1906 1906
 			    }
1907 1907
 			    
Please login to merge, or discard this patch.
Braces   +1190 added lines, -399 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,32 +211,44 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftjson';
178 233
         	$globalSources[$id]['format'] = 'aircraftjson';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to aircraft.json source (".$host.")...\n";
237
+        	}
181 238
     	    } else if (preg_match('/aircraft$/i',$host)) {
182 239
         	//$formats[$id] = 'planefinderclient';
183 240
         	$globalSources[$id]['format'] = 'planefinderclient';
184 241
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
242
+        	if ($globalDebug) {
243
+        		echo "Connect to planefinderclient source (".$host.")...\n";
244
+        	}
186 245
     	    } else if (preg_match('/opensky/i',$host)) {
187 246
         	//$formats[$id] = 'aircraftlistjson';
188 247
         	$globalSources[$id]['format'] = 'opensky';
189 248
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to opensky source (".$host.")...\n";
251
+        	}
191 252
     	    /*
192 253
     	    // Disabled for now, site change source format
193 254
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -204,7 +265,9 @@  discard block
 block discarded – undo
204 265
         	//$formats[$id] = 'planeupdatefaa';
205 266
         	$globalSources[$id]['format'] = 'planeupdatefaa';
206 267
         	//$last_exec['planeupdatefaa'] = 0;
207
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
268
+        	if ($globalDebug) {
269
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
270
+        	}
208 271
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
209 272
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
210 273
         	    exit(0);
@@ -213,37 +276,53 @@  discard block
 block discarded – undo
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'phpvmacars';
215 278
         	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
279
+        	if ($globalDebug) {
280
+        		echo "Connect to phpvmacars source (".$host.")...\n";
281
+        	}
217 282
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
218 283
         	//$formats[$id] = 'phpvmacars';
219 284
         	$globalSources[$id]['format'] = 'vaos';
220 285
         	//$last_exec['phpvmacars'] = 0;
221
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
286
+        	if ($globalDebug) {
287
+        		echo "Connect to vaos source (".$host.")...\n";
288
+        	}
222 289
             } else if (preg_match('/VAM-json.php$/i',$host)) {
223 290
         	//$formats[$id] = 'phpvmacars';
224 291
         	$globalSources[$id]['format'] = 'vam';
225
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
292
+        	if ($globalDebug) {
293
+        		echo "Connect to Vam source (".$host.")...\n";
294
+        	}
226 295
             } else if (preg_match('/whazzup/i',$host)) {
227 296
         	//$formats[$id] = 'whazzup';
228 297
         	$globalSources[$id]['format'] = 'whazzup';
229 298
         	//$last_exec['whazzup'] = 0;
230
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
299
+        	if ($globalDebug) {
300
+        		echo "Connect to whazzup source (".$host.")...\n";
301
+        	}
231 302
             } else if (preg_match('/blitzortung/i',$host)) {
232 303
         	$globalSources[$id]['format'] = 'blitzortung';
233
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
304
+        	if ($globalDebug) {
305
+        		echo "Connect to blitzortung source (".$host.")...\n";
306
+        	}
234 307
             } else if (preg_match('/airwhere/i',$host)) {
235 308
         	$globalSources[$id]['format'] = 'airwhere';
236
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to airwhere source (".$host.")...\n";
311
+        	}
237 312
             } else if (preg_match('/recentpireps/i',$host)) {
238 313
         	//$formats[$id] = 'pirepsjson';
239 314
         	$globalSources[$id]['format'] = 'pirepsjson';
240 315
         	//$last_exec['pirepsjson'] = 0;
241
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
316
+        	if ($globalDebug) {
317
+        		echo "Connect to pirepsjson source (".$host.")...\n";
318
+        	}
242 319
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
243 320
         	//$formats[$id] = 'fr24json';
244 321
         	$globalSources[$id]['format'] = 'fr24json';
245 322
         	//$last_exec['fr24json'] = 0;
246
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
323
+        	if ($globalDebug) {
324
+        		echo "Connect to fr24 source (".$host.")...\n";
325
+        	}
247 326
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
248 327
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
249 328
         	    exit(0);
@@ -252,7 +331,9 @@  discard block
 block discarded – undo
252 331
         	//$formats[$id] = 'fr24json';
253 332
         	$globalSources[$id]['format'] = 'myshiptracking';
254 333
         	//$last_exec['fr24json'] = 0;
255
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
334
+        	if ($globalDebug) {
335
+        		echo "Connect to myshiptracking source (".$host.")...\n";
336
+        	}
256 337
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
257 338
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
258 339
         	    exit(0);
@@ -261,16 +342,24 @@  discard block
 block discarded – undo
261 342
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
262 343
         	//$formats[$id] = 'tsv';
263 344
         	$globalSources[$id]['format'] = 'tsv';
264
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
345
+        	if ($globalDebug) {
346
+        		echo "Connect to tsv source (".$host.")...\n";
347
+        	}
265 348
             }
266 349
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
267 350
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
268 351
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
269 352
     		    if ($idf !== false) {
270 353
     			$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";
354
+        		if ($globalDebug) {
355
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
356
+        		}
357
+    		    } elseif ($globalDebug) {
358
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
359
+    		    }
360
+    		} elseif ($globalDebug) {
361
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
362
+    		}
274 363
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
275 364
 	    $hostport = explode(':',$host);
276 365
 	    if (isset($hostport[1])) {
@@ -310,19 +399,27 @@  discard block
 block discarded – undo
310 399
         		//$formats[$id] = 'beast';
311 400
         		$globalSources[$id]['format'] = 'beast';
312 401
 		    //} else $formats[$id] = 'sbs';
313
-		    } else $globalSources[$id]['format'] = 'sbs';
402
+		    } else {
403
+		    	$globalSources[$id]['format'] = 'sbs';
404
+		    }
314 405
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
315 406
 		}
316
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
407
+		if ($globalDebug) {
408
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
409
+		}
317 410
             } else {
318
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
411
+		if ($globalDebug) {
412
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
413
+		}
319 414
 		sleep(10);
320 415
 		connect_all($hosts);
321 416
     	    }
322 417
         }
323 418
     }
324 419
 }
325
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
420
+if (!isset($globalMinFetch)) {
421
+	$globalMinFetch = 15;
422
+}
326 423
 
327 424
 // Initialize all
328 425
 $status = array();
@@ -331,13 +428,19 @@  discard block
 block discarded – undo
331 428
 $formats = array();
332 429
 $last_exec = array();
333 430
 $time = time();
334
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
335
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
336
-else $timeout = 20;
431
+if (isset($globalSourcesTimeout)) {
432
+	$timeout = $globalSourcesTimeOut;
433
+} else if (isset($globalSBS1TimeOut)) {
434
+	$timeout = $globalSBS1TimeOut;
435
+} else {
436
+	$timeout = 20;
437
+}
337 438
 $errno = '';
338 439
 $errstr='';
339 440
 
340
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
441
+if (!isset($globalDaemon)) {
442
+	$globalDaemon = TRUE;
443
+}
341 444
 /* Initiate connections to all the hosts simultaneously */
342 445
 //connect_all($hosts);
343 446
 //connect_all($globalSources);
@@ -366,7 +469,9 @@  discard block
 block discarded – undo
366 469
     if (isset($source['format']) && $source['format'] == 'aprs') {
367 470
 	$aprs_connect = 0;
368 471
 	$use_aprs = true;
369
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
472
+	if (isset($source['port']) && $source['port'] == '10152') {
473
+		$aprs_full = true;
474
+	}
370 475
 	break;
371 476
     }
372 477
 }
@@ -377,25 +482,46 @@  discard block
 block discarded – undo
377 482
 	$aprs_connect = 0;
378 483
 	$aprs_keep = 120;
379 484
 	$aprs_last_tx = time();
380
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
381
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
382
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
383
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
384
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
385
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
386
-	if ($aprs_full) $aprs_filter = '';
387
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
388
-	else $aprs_pass = '-1';
485
+	if (isset($globalAPRSversion)) {
486
+		$aprs_version = $globalAPRSversion;
487
+	} else {
488
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
489
+	}
490
+	if (isset($globalAPRSssid)) {
491
+		$aprs_ssid = $globalAPRSssid;
492
+	} else {
493
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
494
+	}
495
+	if (isset($globalAPRSfilter)) {
496
+		$aprs_filter = $globalAPRSfilter;
497
+	} else {
498
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
499
+	}
500
+	if ($aprs_full) {
501
+		$aprs_filter = '';
502
+	}
503
+	if (isset($globalAPRSpass)) {
504
+		$aprs_pass = $globalAPRSpass;
505
+	} else {
506
+		$aprs_pass = '-1';
507
+	}
389 508
 
390
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
391
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
392
-}
509
+	if ($aprs_filter != '') {
510
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
511
+	} else {
512
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
513
+	}
514
+	}
393 515
 
394 516
 // connected - lets do some work
395 517
 //if ($globalDebug) echo "Connected!\n";
396 518
 sleep(1);
397
-if ($globalDebug) echo "SCAN MODE \n\n";
398
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
519
+if ($globalDebug) {
520
+	echo "SCAN MODE \n\n";
521
+}
522
+if (!isset($globalCronEnd)) {
523
+	$globalCronEnd = 60;
524
+}
399 525
 $endtime = time()+$globalCronEnd;
400 526
 $i = 1;
401 527
 $tt = array();
@@ -409,22 +535,32 @@  discard block
 block discarded – undo
409 535
 
410 536
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
411 537
 while ($i > 0) {
412
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
538
+    if (function_exists('pcntl_fork')) {
539
+    	pcntl_signal_dispatch();
540
+    }
413 541
 
414
-    if (!$globalDaemon) $i = $endtime-time();
542
+    if (!$globalDaemon) {
543
+    	$i = $endtime-time();
544
+    }
415 545
     // Delete old ATC
416 546
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
417
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
547
+	if ($globalDebug) {
548
+		echo 'Delete old ATC...'."\n";
549
+	}
418 550
         $ATC->deleteOldATC();
419 551
     }
420 552
     
421 553
     if (count($last_exec) == count($globalSources)) {
422 554
 	$max = $globalMinFetch;
423 555
 	foreach ($last_exec as $last) {
424
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
556
+	    if ((time() - $last['last']) < $max) {
557
+	    	$max = time() - $last['last'];
558
+	    }
425 559
 	}
426 560
 	if ($max < $globalMinFetch) {
427
-	    if ($globalDebug) echo 'Sleeping...'."\n";
561
+	    if ($globalDebug) {
562
+	    	echo 'Sleeping...'."\n";
563
+	    }
428 564
 	    sleep($globalMinFetch-$max+2);
429 565
 	}
430 566
     }
@@ -434,7 +570,9 @@  discard block
 block discarded – undo
434 570
     foreach ($globalSources as $id => $value) {
435 571
 	date_default_timezone_set('UTC');
436 572
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
437
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
573
+	if (!isset($last_exec[$id]['last'])) {
574
+		$last_exec[$id]['last'] = 0;
575
+	}
438 576
 	if ($value['format'] === 'deltadbtxt' && 
439 577
 	    (
440 578
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -443,7 +581,9 @@  discard block
 block discarded – undo
443 581
 	) {
444 582
 	    //$buffer = $Common->getData($hosts[$id]);
445 583
 	    $buffer = $Common->getData($value['host']);
446
-	    if ($buffer != '') $reset = 0;
584
+	    if ($buffer != '') {
585
+	    	$reset = 0;
586
+	    }
447 587
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
448 588
 	    $buffer = explode('\n',$buffer);
449 589
 	    foreach ($buffer as $line) {
@@ -452,20 +592,41 @@  discard block
 block discarded – undo
452 592
 	            $data = array();
453 593
 	            $data['hex'] = $line[1]; // hex
454 594
 	            $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
595
+	            if (isset($line[3])) {
596
+	            	$data['altitude'] = $line[3];
597
+	            }
598
+	            // altitude
599
+	            if (isset($line[4])) {
600
+	            	$data['speed'] = $line[4];
601
+	            }
602
+	            // speed
603
+	            if (isset($line[5])) {
604
+	            	$data['heading'] = $line[5];
605
+	            }
606
+	            // heading
607
+	            if (isset($line[6])) {
608
+	            	$data['latitude'] = $line[6];
609
+	            }
610
+	            // lat
611
+	            if (isset($line[7])) {
612
+	            	$data['longitude'] = $line[7];
613
+	            }
614
+	            // long
460 615
 	            $data['verticalrate'] = ''; // vertical rate
461 616
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
462 617
 	            $data['emergency'] = ''; // emergency
463 618
 		    $data['datetime'] = date('Y-m-d H:i:s');
464 619
 		    $data['format_source'] = 'deltadbtxt';
465 620
     		    $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'];
621
+		    if (isset($value['name']) && $value['name'] != '') {
622
+		    	$data['source_name'] = $value['name'];
623
+		    }
624
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
625
+		    	$data['noarchive'] = true;
626
+		    }
627
+		    if (isset($value['sourcestats'])) {
628
+		    	$data['sourcestats'] = $value['sourcestats'];
629
+		    }
469 630
     		    $SI->add($data);
470 631
 		    unset($data);
471 632
     		}
@@ -480,7 +641,9 @@  discard block
 block discarded – undo
480 641
 	    date_default_timezone_set('CET');
481 642
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
482 643
 	    date_default_timezone_set('UTC');
483
-	    if ($buffer != '') $reset = 0;
644
+	    if ($buffer != '') {
645
+	    	$reset = 0;
646
+	    }
484 647
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
485 648
 	    $buffer = explode('\n',$buffer);
486 649
 	    foreach ($buffer as $line) {
@@ -489,18 +652,42 @@  discard block
 block discarded – undo
489 652
 		    $add = false;
490 653
 		    $ais_data = $AIS->parse_line(trim($line));
491 654
 		    $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'];
655
+		    if (isset($ais_data['ident'])) {
656
+		    	$data['ident'] = $ais_data['ident'];
657
+		    }
658
+		    if (isset($ais_data['mmsi'])) {
659
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
660
+		    }
661
+		    if (isset($ais_data['speed'])) {
662
+		    	$data['speed'] = $ais_data['speed'];
663
+		    }
664
+		    if (isset($ais_data['heading'])) {
665
+		    	$data['heading'] = $ais_data['heading'];
666
+		    }
667
+		    if (isset($ais_data['latitude'])) {
668
+		    	$data['latitude'] = $ais_data['latitude'];
669
+		    }
670
+		    if (isset($ais_data['longitude'])) {
671
+		    	$data['longitude'] = $ais_data['longitude'];
672
+		    }
673
+		    if (isset($ais_data['status'])) {
674
+		    	$data['status'] = $ais_data['status'];
675
+		    }
676
+		    if (isset($ais_data['statusid'])) {
677
+		    	$data['status_id'] = $ais_data['statusid'];
678
+		    }
679
+		    if (isset($ais_data['type'])) {
680
+		    	$data['type'] = $ais_data['type'];
681
+		    }
682
+		    if (isset($ais_data['typeid'])) {
683
+		    	$data['type_id'] = $ais_data['typeid'];
684
+		    }
685
+		    if (isset($ais_data['imo'])) {
686
+		    	$data['imo'] = $ais_data['imo'];
687
+		    }
688
+		    if (isset($ais_data['callsign'])) {
689
+		    	$data['callsign'] = $ais_data['callsign'];
690
+		    }
504 691
 		    if (isset($ais_data['timestamp'])) {
505 692
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
506 693
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -514,8 +701,12 @@  discard block
 block discarded – undo
514 701
 		    $data['format_source'] = 'aisnmeatxt';
515 702
     		    $data['id_source'] = $id_source;
516 703
 		    //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);
704
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
705
+		    	$data['noarchive'] = true;
706
+		    }
707
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
708
+		    	$MI->add($data);
709
+		    }
519 710
 		    unset($data);
520 711
 		}
521 712
     	    }
@@ -538,20 +729,48 @@  discard block
 block discarded – undo
538 729
 			    if ($line != '') {
539 730
 				$ais_data = $AIS->parse_line(trim($line));
540 731
 				$data = array();
541
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
542
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
543
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
544
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
545
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
546
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
547
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
548
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
549
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
550
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
551
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
552
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
554
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
732
+				if (isset($ais_data['ident'])) {
733
+					$data['ident'] = $ais_data['ident'];
734
+				}
735
+				if (isset($ais_data['mmsi'])) {
736
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
737
+				}
738
+				if (isset($ais_data['speed'])) {
739
+					$data['speed'] = $ais_data['speed'];
740
+				}
741
+				if (isset($ais_data['heading'])) {
742
+					$data['heading'] = $ais_data['heading'];
743
+				}
744
+				if (isset($ais_data['latitude'])) {
745
+					$data['latitude'] = $ais_data['latitude'];
746
+				}
747
+				if (isset($ais_data['longitude'])) {
748
+					$data['longitude'] = $ais_data['longitude'];
749
+				}
750
+				if (isset($ais_data['status'])) {
751
+					$data['status'] = $ais_data['status'];
752
+				}
753
+				if (isset($ais_data['statusid'])) {
754
+					$data['status_id'] = $ais_data['statusid'];
755
+				}
756
+				if (isset($ais_data['type'])) {
757
+					$data['type'] = $ais_data['type'];
758
+				}
759
+				if (isset($ais_data['typeid'])) {
760
+					$data['type_id'] = $ais_data['typeid'];
761
+				}
762
+				if (isset($ais_data['imo'])) {
763
+					$data['imo'] = $ais_data['imo'];
764
+				}
765
+				if (isset($ais_data['callsign'])) {
766
+					$data['callsign'] = $ais_data['callsign'];
767
+				}
768
+				if (isset($ais_data['destination'])) {
769
+					$data['arrival_code'] = $ais_data['destination'];
770
+				}
771
+				if (isset($ais_data['eta_ts'])) {
772
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
773
+				}
555 774
 				if (isset($ais_data['timestamp'])) {
556 775
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
557 776
 				} else {
@@ -559,18 +778,27 @@  discard block
 block discarded – undo
559 778
 				}
560 779
 				$data['format_source'] = 'aisnmeahttp';
561 780
 				$data['id_source'] = $id_source;
562
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
563
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
781
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
782
+					$data['noarchive'] = true;
783
+				}
784
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
785
+					$MI->add($data);
786
+				}
564 787
 				unset($data);
565 788
 			    }
566 789
 			}
567 790
 		    }
568 791
 		} else {
569 792
 		    $format = $value['format'];
570
-		    if (isset($tt[$format])) $tt[$format]++;
571
-		    else $tt[$format] = 0;
793
+		    if (isset($tt[$format])) {
794
+		    	$tt[$format]++;
795
+		    } else {
796
+		    	$tt[$format] = 0;
797
+		    }
572 798
 		    if ($tt[$format] > 30) {
573
-			if ($globalDebug) echo 'Reconnect...'."\n";
799
+			if ($globalDebug) {
800
+				echo 'Reconnect...'."\n";
801
+			}
574 802
 			sleep(2);
575 803
 			//$sourceeen[] = $value;
576 804
 			//connect_all($sourceeen);
@@ -606,12 +834,18 @@  discard block
 block discarded – undo
606 834
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
607 835
 			    //$data['type_id'] = $line['TYPE'];
608 836
 			    $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']));
837
+			    if ($line['DEST'] != '') {
838
+			    	$data['arrival_code'] = $line['DEST'];
839
+			    }
840
+			    if ($line['ARV'] != '') {
841
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
842
+			    }
611 843
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
612 844
 			    $data['format_source'] = 'myshiptracking';
613 845
 			    $data['id_source'] = $id_source;
614
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
846
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
847
+			    	$data['noarchive'] = true;
848
+			    }
615 849
 			    $MI->add($data);
616 850
 			    unset($data);
617 851
 			}
@@ -636,7 +870,9 @@  discard block
 block discarded – undo
636 870
 			    $data['callsign'] = $line['callsign'];
637 871
 			    $data['mmsi'] = substr($line['mmsi'],-9);
638 872
 			    $data['speed'] = $line['sog'];
639
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
873
+			    if ($line['heading'] != '511') {
874
+			    	$data['heading'] = $line['heading'];
875
+			    }
640 876
 			    $data['latitude'] = $line['latitude'];
641 877
 			    $data['longitude'] = $line['longitude'];
642 878
 			    $data['type_id'] = $line['shiptype'];
@@ -644,7 +880,9 @@  discard block
 block discarded – undo
644 880
 			    $data['datetime'] = $line['time'];
645 881
 			    $data['format_source'] = 'boatbeaconapp';
646 882
 			    $data['id_source'] = $id_source;
647
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
883
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
884
+			    	$data['noarchive'] = true;
885
+			    }
648 886
 			    $MI->add($data);
649 887
 			    unset($data);
650 888
 			}
@@ -666,22 +904,44 @@  discard block
 block discarded – undo
666 904
 		    foreach ($all_data['features'] as $line) {
667 905
 			print_r($line);
668 906
 			$data = array();
669
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
670
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
671
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
672
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
673
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
674
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
907
+			if (isset($line['properties']['name'])) {
908
+				$data['ident'] = $line['properties']['name'];
909
+			}
910
+			if (isset($line['properties']['callsign'])) {
911
+				$data['callsign'] = $line['properties']['callsign'];
912
+			}
913
+			if (isset($line['properties']['mmsi'])) {
914
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
915
+			}
916
+			if (isset($line['properties']['imo'])) {
917
+				$data['imo'] = $line['properties']['imo'];
918
+			}
919
+			if (isset($line['properties']['speed'])) {
920
+				$data['speed'] = $line['properties']['speed'];
921
+			}
922
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
923
+				$data['heading'] = $line['properties']['heading'];
924
+			}
675 925
 			$data['latitude'] = $line['geometry']['coordinates'][1];
676 926
 			$data['longitude'] = $line['geometry']['coordinates'][0];
677
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
678
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
679
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
927
+			if (isset($line['properties']['vesselType'])) {
928
+				$data['type'] = $line['properties']['vesselType'];
929
+			}
930
+			if (isset($line['properties']['destination'])) {
931
+				$data['arrival_code'] = $line['properties']['destination'];
932
+			}
933
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
934
+				$data['arrival_date'] = $line['properties']['eta'];
935
+			}
680 936
 			$data['format_source'] = 'boatnerd';
681 937
 			$data['id_source'] = $id_source;
682 938
 			$data['datetime'] = date('Y-m-d H:i:s');
683
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
684
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
939
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
940
+				$data['noarchive'] = true;
941
+			}
942
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
943
+				$MI->add($data);
944
+			}
685 945
 			unset($data);
686 946
 		    }
687 947
 		}
@@ -698,7 +958,9 @@  discard block
 block discarded – undo
698 958
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
699 959
 	    echo 'done !'."\n";
700 960
 	    // FIXME: Need more work
701
-	    if ($buffer != '') $reset = 0;
961
+	    if ($buffer != '') {
962
+	    	$reset = 0;
963
+	    }
702 964
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
703 965
 	    $buffer = explode('\n',$buffer);
704 966
 	    foreach ($buffer as $line) {
@@ -724,7 +986,9 @@  discard block
 block discarded – undo
724 986
 		    //$data['etaTime'] = substr($line,135,5);
725 987
 		    $data['format_source'] = 'shipplotter';
726 988
     		    $data['id_source'] = $id_source;
727
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
989
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
990
+		    	$data['noarchive'] = true;
991
+		    }
728 992
 		    //print_r($data);
729 993
 		    echo 'Add...'."\n";
730 994
 		    $MI->add($data);
@@ -758,16 +1022,28 @@  discard block
 block discarded – undo
758 1022
     		    $line = explode(':', $line);
759 1023
     		    if (count($line) > 30 && $line[0] != 'callsign') {
760 1024
 			$data = array();
761
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
762
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1025
+			if (isset($line[37]) && $line[37] != '') {
1026
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1027
+			} else {
1028
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1029
+			}
763 1030
 			$data['pilot_id'] = $line[1];
764 1031
 			$data['pilot_name'] = $line[2];
765 1032
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
766 1033
 			$data['ident'] = $line[0]; // ident
767
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1034
+			if ($line[7] != '' && $line[7] != 0) {
1035
+				$data['altitude'] = $line[7];
1036
+			}
1037
+			// altitude
768 1038
 			$data['speed'] = $line[8]; // speed
769
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
770
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1039
+			if (isset($line[45])) {
1040
+				$data['heading'] = $line[45];
1041
+			}
1042
+			// heading
1043
+			elseif (isset($line[38])) {
1044
+				$data['heading'] = $line[38];
1045
+			}
1046
+			// heading
771 1047
 			$data['latitude'] = $line[5]; // lat
772 1048
 	        	$data['longitude'] = $line[6]; // long
773 1049
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -783,7 +1059,9 @@  discard block
 block discarded – undo
783 1059
 			$data['frequency'] = $line[4];
784 1060
 			$data['type'] = $line[18];
785 1061
 			$data['range'] = $line[19];
786
-			if (isset($line[35])) $data['info'] = $line[35];
1062
+			if (isset($line[35])) {
1063
+				$data['info'] = $line[35];
1064
+			}
787 1065
     			$data['id_source'] = $id_source;
788 1066
 	    		//$data['arrival_airport_time'] = ;
789 1067
 	    		if ($line[9] != '') {
@@ -797,27 +1075,47 @@  discard block
 block discarded – undo
797 1075
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
798 1076
 	    		*/
799 1077
 	    		$data['format_source'] = $value['format'];
800
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
801
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
802
-    			if ($line[3] === 'PILOT') $SI->add($data);
803
-			elseif ($line[3] === 'ATC') {
1078
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1079
+				$data['noarchive'] = true;
1080
+			}
1081
+			if (isset($value['name']) && $value['name'] != '') {
1082
+				$data['source_name'] = $value['name'];
1083
+			}
1084
+    			if ($line[3] === 'PILOT') {
1085
+    				$SI->add($data);
1086
+    			} elseif ($line[3] === 'ATC') {
804 1087
 				//print_r($data);
805 1088
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
806 1089
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
807 1090
 				$typec = substr($data['ident'],-3);
808
-				if ($typec === 'APP') $data['type'] = 'Approach';
809
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
810
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
811
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
812
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
813
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
814
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
815
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
816
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
817
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1091
+				if ($typec === 'APP') {
1092
+					$data['type'] = 'Approach';
1093
+				} elseif ($typec === 'TWR') {
1094
+					$data['type'] = 'Tower';
1095
+				} elseif ($typec === 'OBS') {
1096
+					$data['type'] = 'Observer';
1097
+				} elseif ($typec === 'GND') {
1098
+					$data['type'] = 'Ground';
1099
+				} elseif ($typec === 'DEL') {
1100
+					$data['type'] = 'Delivery';
1101
+				} elseif ($typec === 'DEP') {
1102
+					$data['type'] = 'Departure';
1103
+				} elseif ($typec === 'FSS') {
1104
+					$data['type'] = 'Flight Service Station';
1105
+				} elseif ($typec === 'CTR') {
1106
+					$data['type'] = 'Control Radar or Centre';
1107
+				} elseif ($data['type'] === '') {
1108
+					$data['type'] = 'Observer';
1109
+				}
1110
+				if (!isset($data['source_name'])) {
1111
+					$data['source_name'] = '';
1112
+				}
818 1113
 				if (isset($ATC)) {
819
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
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']);
1114
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1115
+						echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
1116
+					} else {
1117
+						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']);
1118
+					}
821 1119
 				}
822 1120
 			}
823 1121
     			unset($data);
@@ -844,14 +1142,20 @@  discard block
 block discarded – undo
844 1142
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
845 1143
 			$data['latitude'] = (float)$line['pktLatitude'];
846 1144
 			$data['longitude'] = (float)$line['pktLongitude'];
847
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
848
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1145
+			if ((float)$line['pktTrack'] != 0) {
1146
+				$data['heading'] = (float)$line['pktTrack'];
1147
+			}
1148
+			if ((int)$line['pktSpeed'] != 0) {
1149
+				$data['speed'] = (int)$line['pktSpeed'];
1150
+			}
849 1151
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
850 1152
 			$data['altitude_relative'] = 'AMSL';
851 1153
 			$data['pilot_id'] = (int)$line['pktPilotID'];
852 1154
 			$data['aircraft_icao'] = 'PARAGLIDER';
853 1155
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
854
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1156
+			if (isset($pilot_data[4])) {
1157
+				$data['pilot_name'] = $pilot_data[4];
1158
+			}
855 1159
 			$data['format_source'] = $value['format'];
856 1160
 			$SI->add($data);
857 1161
 			unset($data);
@@ -899,25 +1203,59 @@  discard block
 block discarded – undo
899 1203
 		    foreach ($all_data['acList'] as $line) {
900 1204
 			$data = array();
901 1205
 			$data['hex'] = $line['Icao']; // hex
902
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
903
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
904
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
905
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
906
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
907
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1206
+			if (isset($line['Call'])) {
1207
+				$data['ident'] = $line['Call'];
1208
+			}
1209
+			// ident
1210
+			if (isset($line['Alt'])) {
1211
+				$data['altitude'] = $line['Alt'];
1212
+			}
1213
+			// altitude
1214
+			if (isset($line['Spd'])) {
1215
+				$data['speed'] = $line['Spd'];
1216
+			}
1217
+			// speed
1218
+			if (isset($line['Trak'])) {
1219
+				$data['heading'] = $line['Trak'];
1220
+			}
1221
+			// heading
1222
+			if (isset($line['Lat'])) {
1223
+				$data['latitude'] = $line['Lat'];
1224
+			}
1225
+			// lat
1226
+			if (isset($line['Long'])) {
1227
+				$data['longitude'] = $line['Long'];
1228
+			}
1229
+			// long
908 1230
 			//$data['verticalrate'] = $line['']; // verticale rate
909
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1231
+			if (isset($line['Sqk'])) {
1232
+				$data['squawk'] = $line['Sqk'];
1233
+			}
1234
+			// squawk
910 1235
 			$data['emergency'] = ''; // emergency
911
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
912
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
913
-			else $data['datetime'] = date('Y-m-d H:i:s');
1236
+			if (isset($line['Reg'])) {
1237
+				$data['registration'] = $line['Reg'];
1238
+			}
1239
+			if (isset($line['PosTime'])) {
1240
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1241
+			} else {
1242
+				$data['datetime'] = date('Y-m-d H:i:s');
1243
+			}
914 1244
 			//$data['datetime'] = date('Y-m-d H:i:s');
915
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1245
+			if (isset($line['Type'])) {
1246
+				$data['aircraft_icao'] = $line['Type'];
1247
+			}
916 1248
 			$data['format_source'] = 'aircraftlistjson';
917 1249
 			$data['id_source'] = $id_source;
918
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
919
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
920
-			if (isset($data['latitude'])) $SI->add($data);
1250
+			if (isset($value['name']) && $value['name'] != '') {
1251
+				$data['source_name'] = $value['name'];
1252
+			}
1253
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1254
+				$data['noarchive'] = true;
1255
+			}
1256
+			if (isset($data['latitude'])) {
1257
+				$SI->add($data);
1258
+			}
921 1259
 			unset($data);
922 1260
 		    }
923 1261
 		} elseif (is_array($all_data)) {
@@ -934,17 +1272,26 @@  discard block
 block discarded – undo
934 1272
 			$data['verticalrate'] = $line['vrt']; // verticale rate
935 1273
 			$data['squawk'] = $line['squawk']; // squawk
936 1274
 			$data['emergency'] = ''; // emergency
937
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
938
-			else $data['datetime'] = date('Y-m-d H:i:s');
1275
+			if (isset($line['PosTime'])) {
1276
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1277
+			} else {
1278
+				$data['datetime'] = date('Y-m-d H:i:s');
1279
+			}
939 1280
 			$data['format_source'] = 'aircraftlistjson';
940 1281
 			$data['id_source'] = $id_source;
941
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
942
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1282
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1283
+				$data['noarchive'] = true;
1284
+			}
1285
+			if (isset($value['name']) && $value['name'] != '') {
1286
+				$data['source_name'] = $value['name'];
1287
+			}
943 1288
 			$SI->add($data);
944 1289
 			unset($data);
945 1290
 		    }
946 1291
 		}
947
-	    } elseif ($globalDebug) echo 'No data'."\n";
1292
+	    } elseif ($globalDebug) {
1293
+	    	echo 'No data'."\n";
1294
+	    }
948 1295
     	    //$last_exec['aircraftlistjson'] = time();
949 1296
     	    $last_exec[$id]['last'] = time();
950 1297
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -980,8 +1327,12 @@  discard block
 block discarded – undo
980 1327
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
981 1328
 	    	    $data['format_source'] = 'planeupdatefaa';
982 1329
     		    $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'];
1330
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1331
+		    	$data['noarchive'] = true;
1332
+		    }
1333
+		    if (isset($value['name']) && $value['name'] != '') {
1334
+		    	$data['source_name'] = $value['name'];
1335
+		    }
985 1336
 		    $SI->add($data);
986 1337
 		    unset($data);
987 1338
 		}
@@ -1015,7 +1366,9 @@  discard block
 block discarded – undo
1015 1366
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1016 1367
 		    $data['format_source'] = 'opensky';
1017 1368
 		    $data['id_source'] = $id_source;
1018
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1369
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1370
+		    	$data['noarchive'] = true;
1371
+		    }
1019 1372
 		    $SI->add($data);
1020 1373
 		    unset($data);
1021 1374
 		}
@@ -1035,15 +1388,42 @@  discard block
 block discarded – undo
1035 1388
 		foreach ($all_data['aircraft'] as $key => $line) {
1036 1389
 		    $data = array();
1037 1390
 		    // 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
1391
+		    if (isset($line['hex'])) {
1392
+		    	$data['hex'] = $line['hex'];
1393
+		    }
1394
+		    // hex
1395
+		    if (isset($line['flight'])) {
1396
+		    	$data['ident'] = trim($line['flight']);
1397
+		    }
1398
+		    // ident
1399
+		    if (isset($line['altitude'])) {
1400
+		    	$data['altitude'] = $line['altitude'];
1401
+		    }
1402
+		    // altitude
1403
+		    if (isset($line['speed'])) {
1404
+		    	$data['speed'] = $line['speed'];
1405
+		    }
1406
+		    // speed
1407
+		    if (isset($line['track'])) {
1408
+		    	$data['heading'] = $line['track'];
1409
+		    }
1410
+		    // heading
1411
+		    if (isset($line['lat'])) {
1412
+		    	$data['latitude'] = $line['lat'];
1413
+		    }
1414
+		    // lat
1415
+		    if (isset($line['lon'])) {
1416
+		    	$data['longitude'] = $line['lon'];
1417
+		    }
1418
+		    // long
1419
+		    if (isset($line['vert_rate'])) {
1420
+		    	$data['verticalrate'] = $line['vert_rate'];
1421
+		    }
1422
+		    // verticale rate
1423
+		    if (isset($line['squawk'])) {
1424
+		    	$data['squawk'] = $line['squawk'];
1425
+		    }
1426
+		    // squawk
1047 1427
 		    //$data['emergency'] = ''; // emergency
1048 1428
 		    //$data['registration'] = $line[2];
1049 1429
 		    //$data['aircraft_icao'] = $line[0];
@@ -1051,10 +1431,17 @@  discard block
 block discarded – undo
1051 1431
 		    $data['format_source'] = 'aircraftjson';
1052 1432
 		    $data['id_source'] = $id_source;
1053 1433
 		    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;
1434
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1435
+			    	$data['source_name'] = $value['name'].'_MLAT';
1436
+			    } else {
1437
+			    	$data['source_name'] = $value['name'];
1438
+			    }
1439
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1440
+		    	$data['source_name'] = 'MLAT';
1441
+		    }
1442
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1443
+		    	$data['noarchive'] = true;
1444
+		    }
1058 1445
 		    $SI->add($data);
1059 1446
 		    unset($data);
1060 1447
 		}
@@ -1074,22 +1461,54 @@  discard block
 block discarded – undo
1074 1461
 		foreach ($all_data['aircraft'] as $key => $line) {
1075 1462
 		    $data = array();
1076 1463
 		    $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
1464
+		    if (isset($line['callsign'])) {
1465
+		    	$data['ident'] = trim($line['callsign']);
1466
+		    }
1467
+		    // ident
1468
+		    if (isset($line['altitude'])) {
1469
+		    	$data['altitude'] = $line['altitude'];
1470
+		    }
1471
+		    // altitude
1472
+		    if (isset($line['speed'])) {
1473
+		    	$data['speed'] = $line['speed'];
1474
+		    }
1475
+		    // speed
1476
+		    if (isset($line['heading'])) {
1477
+		    	$data['heading'] = $line['heading'];
1478
+		    }
1479
+		    // heading
1480
+		    if (isset($line['lat'])) {
1481
+		    	$data['latitude'] = $line['lat'];
1482
+		    }
1483
+		    // lat
1484
+		    if (isset($line['lon'])) {
1485
+		    	$data['longitude'] = $line['lon'];
1486
+		    }
1487
+		    // long
1488
+		    if (isset($line['vert_rate'])) {
1489
+		    	$data['verticalrate'] = $line['vert_rate'];
1490
+		    }
1491
+		    // verticale rate
1492
+		    if (isset($line['squawk'])) {
1493
+		    	$data['squawk'] = $line['squawk'];
1494
+		    }
1495
+		    // squawk
1085 1496
 		    //$data['emergency'] = ''; // emergency
1086
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1087
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1497
+		    if (isset($line['reg'])) {
1498
+		    	$data['registration'] = $line['reg'];
1499
+		    }
1500
+		    if (isset($line['type'])) {
1501
+		    	$data['aircraft_icao'] = $line['type'];
1502
+		    }
1088 1503
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1089 1504
 		    $data['format_source'] = 'planefinderclient';
1090 1505
 		    $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;
1506
+		    if (isset($value['name']) && $value['name'] != '') {
1507
+		    	$data['source_name'] = $value['name'];
1508
+		    }
1509
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1510
+		    	$data['noarchive'] = true;
1511
+		    }
1093 1512
 		    $SI->add($data);
1094 1513
 		    unset($data);
1095 1514
 		}
@@ -1105,7 +1524,9 @@  discard block
 block discarded – undo
1105 1524
 	    //$buffer = $Common->getData($hosts[$id]);
1106 1525
 	    $buffer = $Common->getData($value['host']);
1107 1526
 	    $all_data = json_decode($buffer,true);
1108
-	    if (!empty($all_data)) $reset = 0;
1527
+	    if (!empty($all_data)) {
1528
+	    	$reset = 0;
1529
+	    }
1109 1530
 	    foreach ($all_data as $key => $line) {
1110 1531
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1111 1532
 		    $data = array();
@@ -1126,8 +1547,12 @@  discard block
 block discarded – undo
1126 1547
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1127 1548
 	    	    $data['format_source'] = 'fr24json';
1128 1549
     		    $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'];
1550
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1551
+		    	$data['noarchive'] = true;
1552
+		    }
1553
+		    if (isset($value['name']) && $value['name'] != '') {
1554
+		    	$data['source_name'] = $value['name'];
1555
+		    }
1131 1556
 		    $SI->add($data);
1132 1557
 		    unset($data);
1133 1558
 		}
@@ -1156,24 +1581,42 @@  discard block
 block discarded – undo
1156 1581
 		    if (isset($line['inf'])) {
1157 1582
 			$data = array();
1158 1583
 			$data['hex'] = $line['inf']['ia'];
1159
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1584
+			if (isset($line['inf']['cs'])) {
1585
+				$data['ident'] = $line['inf']['cs'];
1586
+			}
1587
+			//$line[13]
1160 1588
 	    		$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
1589
+	    		if (isset($line['inf']['gs'])) {
1590
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1591
+	    		}
1592
+	    		// speed
1593
+	    		if (isset($line['inf']['tr'])) {
1594
+	    			$data['heading'] = $line['inf']['tr'];
1595
+	    		}
1596
+	    		// heading
1163 1597
 	    		$data['latitude'] = $line['pt'][0]; // lat
1164 1598
 	    		$data['longitude'] = $line['pt'][1]; // long
1165 1599
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1166
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1600
+	    		if (isset($line['inf']['sq'])) {
1601
+	    			$data['squawk'] = $line['inf']['sq'];
1602
+	    		}
1603
+	    		// squawk
1167 1604
 	    		//$data['aircraft_icao'] = $line[8];
1168
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1605
+	    		if (isset($line['inf']['rc'])) {
1606
+	    			$data['registration'] = $line['inf']['rc'];
1607
+	    		}
1169 1608
 			//$data['departure_airport_iata'] = $line[11];
1170 1609
 			//$data['arrival_airport_iata'] = $line[12];
1171 1610
 	    		//$data['emergency'] = ''; // emergency
1172 1611
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1173 1612
 	    		$data['format_source'] = 'radarvirtueljson';
1174 1613
     			$data['id_source'] = $id_source;
1175
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1176
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1614
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1615
+				$data['noarchive'] = true;
1616
+			}
1617
+			if (isset($value['name']) && $value['name'] != '') {
1618
+				$data['source_name'] = $value['name'];
1619
+			}
1177 1620
 			$SI->add($data);
1178 1621
 			unset($data);
1179 1622
 		    }
@@ -1199,30 +1642,65 @@  discard block
 block discarded – undo
1199 1642
 		    $data['id'] = $line['id'];
1200 1643
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1201 1644
 		    $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
1645
+		    if (isset($line['pilotid'])) {
1646
+		    	$data['pilot_id'] = $line['pilotid'];
1647
+		    }
1648
+		    // pilot id
1649
+		    if (isset($line['name'])) {
1650
+		    	$data['pilot_name'] = $line['name'];
1651
+		    }
1652
+		    // pilot name
1653
+		    if (isset($line['alt'])) {
1654
+		    	$data['altitude'] = $line['alt'];
1655
+		    }
1656
+		    // altitude
1657
+		    if (isset($line['gs'])) {
1658
+		    	$data['speed'] = $line['gs'];
1659
+		    }
1660
+		    // speed
1661
+		    if (isset($line['heading'])) {
1662
+		    	$data['heading'] = $line['heading'];
1663
+		    }
1664
+		    // heading
1665
+		    if (isset($line['route'])) {
1666
+		    	$data['waypoints'] = $line['route'];
1667
+		    }
1668
+		    // route
1208 1669
 		    $data['latitude'] = $line['lat']; // lat
1209 1670
 		    $data['longitude'] = $line['lon']; // long
1210 1671
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1211 1672
 		    //$data['squawk'] = $line['squawk']; // squawk
1212 1673
 		    //$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'];
1674
+		    if (isset($line['depicao'])) {
1675
+		    	$data['departure_airport_icao'] = $line['depicao'];
1676
+		    }
1677
+		    if (isset($line['deptime'])) {
1678
+		    	$data['departure_airport_time'] = $line['deptime'];
1679
+		    }
1680
+		    if (isset($line['arricao'])) {
1681
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1682
+		    }
1216 1683
 		    //$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'] = '';
1684
+		    if (isset($line['aircraft'])) {
1685
+		    	$data['aircraft_icao'] = $line['aircraft'];
1686
+		    }
1687
+		    if (isset($line['transponder'])) {
1688
+		    	$data['squawk'] = $line['transponder'];
1689
+		    }
1690
+		    if (isset($line['atis'])) {
1691
+		    	$data['info'] = $line['atis'];
1692
+		    } else {
1693
+		    	$data['info'] = '';
1694
+		    }
1221 1695
 		    $data['format_source'] = 'pireps';
1222 1696
     		    $data['id_source'] = $id_source;
1223 1697
 		    $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'];
1698
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1699
+		    	$data['noarchive'] = true;
1700
+		    }
1701
+		    if (isset($value['name']) && $value['name'] != '') {
1702
+		    	$data['source_name'] = $value['name'];
1703
+		    }
1226 1704
 		    if ($line['icon'] === 'plane') {
1227 1705
 			$SI->add($data);
1228 1706
 		    //    print_r($data);
@@ -1231,16 +1709,28 @@  discard block
 block discarded – undo
1231 1709
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1232 1710
 			$typec = substr($data['ident'],-3);
1233 1711
 			$data['type'] = '';
1234
-			if ($typec === 'APP') $data['type'] = 'Approach';
1235
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1236
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1237
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1238
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1239
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1240
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1241
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1242
-			else $data['type'] = 'Observer';
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']);
1712
+			if ($typec === 'APP') {
1713
+				$data['type'] = 'Approach';
1714
+			} elseif ($typec === 'TWR') {
1715
+				$data['type'] = 'Tower';
1716
+			} elseif ($typec === 'OBS') {
1717
+				$data['type'] = 'Observer';
1718
+			} elseif ($typec === 'GND') {
1719
+				$data['type'] = 'Ground';
1720
+			} elseif ($typec === 'DEL') {
1721
+				$data['type'] = 'Delivery';
1722
+			} elseif ($typec === 'DEP') {
1723
+				$data['type'] = 'Departure';
1724
+			} elseif ($typec === 'FSS') {
1725
+				$data['type'] = 'Flight Service Station';
1726
+			} elseif ($typec === 'CTR') {
1727
+				$data['type'] = 'Control Radar or Centre';
1728
+			} else {
1729
+				$data['type'] = 'Observer';
1730
+			}
1731
+			if (isset($ATC)) {
1732
+				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']);
1733
+			}
1244 1734
 		    }
1245 1735
 		    unset($data);
1246 1736
 		}
@@ -1255,7 +1745,9 @@  discard block
 block discarded – undo
1255 1745
 	    )
1256 1746
 	) {
1257 1747
 	    //$buffer = $Common->getData($hosts[$id]);
1258
-	    if ($globalDebug) echo 'Get Data...'."\n";
1748
+	    if ($globalDebug) {
1749
+	    	echo 'Get Data...'."\n";
1750
+	    }
1259 1751
 	    $buffer = $Common->getData($value['host']);
1260 1752
 	    $all_data = json_decode($buffer,true);
1261 1753
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1263,10 +1755,16 @@  discard block
 block discarded – undo
1263 1755
 		foreach ($all_data as $line) {
1264 1756
 	    	    $data = array();
1265 1757
 	    	    //$data['id'] = $line['id']; // id not usable
1266
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1758
+	    	    if (isset($line['pilotid'])) {
1759
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1760
+	    	    }
1267 1761
 	    	    $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'];
1762
+	    	    if (isset($line['pilotname'])) {
1763
+	    	    	$data['pilot_name'] = $line['pilotname'];
1764
+	    	    }
1765
+	    	    if (isset($line['pilotid'])) {
1766
+	    	    	$data['pilot_id'] = $line['pilotid'];
1767
+	    	    }
1270 1768
 	    	    $data['ident'] = $line['flightnum']; // ident
1271 1769
 	    	    $data['altitude'] = $line['alt']; // altitude
1272 1770
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1282,7 +1780,9 @@  discard block
 block discarded – undo
1282 1780
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1283 1781
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1284 1782
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1285
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1783
+	    	    } else {
1784
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1785
+	    	    }
1286 1786
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1287 1787
 	    	    $data['departure_airport_time'] = $line['deptime'];
1288 1788
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1290,29 +1790,47 @@  discard block
 block discarded – undo
1290 1790
     		    if (isset($line['registration'])) {
1291 1791
     			$data['registration'] = $line['registration'];
1292 1792
     			//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
1793
+    		    } else {
1794
+    		    	$data['registration'] = $line['aircraft'];
1795
+    		    }
1796
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1797
+		    	$data['noarchive'] = true;
1798
+		    }
1799
+		    if (isset($line['route'])) {
1800
+		    	$data['waypoints'] = $line['route'];
1801
+		    }
1802
+		    // route
1296 1803
 		    if (isset($line['aircraftname'])) {
1297 1804
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1298 1805
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1299 1806
 	    		$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 {
1807
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1808
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1809
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1810
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1811
+	    		} else {
1303 1812
 	    		    $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']);
1813
+	    		    if (isset($aircraft_data[1])) {
1814
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1815
+	    		    } else {
1816
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1817
+	    		    }
1306 1818
 	    		}
1307 1819
 	    	    }
1308
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1820
+    		    if (isset($line['route'])) {
1821
+    		    	$data['waypoints'] = $line['route'];
1822
+    		    }
1309 1823
     		    $data['id_source'] = $id_source;
1310 1824
 	    	    $data['format_source'] = 'phpvmacars';
1311
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1825
+		    if (isset($value['name']) && $value['name'] != '') {
1826
+		    	$data['source_name'] = $value['name'];
1827
+		    }
1312 1828
 		    $SI->add($data);
1313 1829
 		    unset($data);
1314 1830
 		}
1315
-		if ($globalDebug) echo 'No more data...'."\n";
1831
+		if ($globalDebug) {
1832
+			echo 'No more data...'."\n";
1833
+		}
1316 1834
 		unset($buffer);
1317 1835
 		unset($all_data);
1318 1836
 	    }
@@ -1325,7 +1843,9 @@  discard block
 block discarded – undo
1325 1843
 	    )
1326 1844
 	) {
1327 1845
 	    //$buffer = $Common->getData($hosts[$id]);
1328
-	    if ($globalDebug) echo 'Get Data...'."\n";
1846
+	    if ($globalDebug) {
1847
+	    	echo 'Get Data...'."\n";
1848
+	    }
1329 1849
 	    $buffer = $Common->getData($value['host']);
1330 1850
 	    $all_data = json_decode($buffer,true);
1331 1851
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1336,10 +1856,16 @@  discard block
 block discarded – undo
1336 1856
 	    	    //$data['id'] = $line['id']; // id not usable
1337 1857
 	    	    $data['id'] = $line['id'];
1338 1858
 	    	    //$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'];
1859
+	    	    if (isset($line['user']['username'])) {
1860
+	    	    	$data['pilot_name'] = $line['user']['username'];
1861
+	    	    }
1862
+	    	    if (isset($line['user_id'])) {
1863
+	    	    	$data['pilot_id'] = $line['user_id'];
1864
+	    	    }
1341 1865
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1342
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1866
+	    	    if (is_numeric($data['ident'])) {
1867
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1868
+	    	    }
1343 1869
 	    	    $data['altitude'] = $line['altitude']; // altitude
1344 1870
 	    	    $data['speed'] = $line['groundspeed']; // speed
1345 1871
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1352,7 +1878,9 @@  discard block
 block discarded – undo
1352 1878
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1353 1879
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1354 1880
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1355
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1881
+	    	    } else {
1882
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1883
+	    	    }
1356 1884
 	    	    
1357 1885
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1358 1886
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1360,17 +1888,26 @@  discard block
 block discarded – undo
1360 1888
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1361 1889
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1362 1890
 
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
1891
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1892
+		    	$data['noarchive'] = true;
1893
+		    }
1894
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1895
+		    	$data['waypoints'] = $line['bid']['route'];
1896
+		    }
1897
+		    // route
1365 1898
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1366 1899
 
1367 1900
     		    $data['id_source'] = $id_source;
1368 1901
 	    	    $data['format_source'] = 'vaos';
1369
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1902
+		    if (isset($value['name']) && $value['name'] != '') {
1903
+		    	$data['source_name'] = $value['name'];
1904
+		    }
1370 1905
 		    $SI->add($data);
1371 1906
 		    unset($data);
1372 1907
 		}
1373
-		if ($globalDebug) echo 'No more data...'."\n";
1908
+		if ($globalDebug) {
1909
+			echo 'No more data...'."\n";
1910
+		}
1374 1911
 		unset($buffer);
1375 1912
 		unset($all_data);
1376 1913
 	    }
@@ -1383,7 +1920,9 @@  discard block
 block discarded – undo
1383 1920
 	    )
1384 1921
 	) {
1385 1922
 	    //$buffer = $Common->getData($hosts[$id]);
1386
-	    if ($globalDebug) echo 'Get Data...'."\n";
1923
+	    if ($globalDebug) {
1924
+	    	echo 'Get Data...'."\n";
1925
+	    }
1387 1926
 	    $buffer = $Common->getData($value['host']);
1388 1927
 	    $all_data = json_decode($buffer,true);
1389 1928
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1412,16 +1951,25 @@  discard block
 block discarded – undo
1412 1951
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1413 1952
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1414 1953
     		    //$data['registration'] = $line['aircraft'];
1415
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1954
+		    if (isset($line['route'])) {
1955
+		    	$data['waypoints'] = $line['route'];
1956
+		    }
1957
+		    // route
1416 1958
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1417 1959
     		    $data['id_source'] = $id_source;
1418 1960
 	    	    $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'];
1961
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1962
+		    	$data['noarchive'] = true;
1963
+		    }
1964
+		    if (isset($value['name']) && $value['name'] != '') {
1965
+		    	$data['source_name'] = $value['name'];
1966
+		    }
1421 1967
 		    $SI->add($data);
1422 1968
 		    unset($data);
1423 1969
 		}
1424
-		if ($globalDebug) echo 'No more data...'."\n";
1970
+		if ($globalDebug) {
1971
+			echo 'No more data...'."\n";
1972
+		}
1425 1973
 		unset($buffer);
1426 1974
 		unset($all_data);
1427 1975
 	    }
@@ -1434,7 +1982,9 @@  discard block
 block discarded – undo
1434 1982
 	    )
1435 1983
 	) {
1436 1984
 	    //$buffer = $Common->getData($hosts[$id]);
1437
-	    if ($globalDebug) echo 'Get Data...'."\n";
1985
+	    if ($globalDebug) {
1986
+	    	echo 'Get Data...'."\n";
1987
+	    }
1438 1988
 	    $buffer = $Common->getData($value['host']);
1439 1989
 	    $all_data = json_decode($buffer,true);
1440 1990
 	    if ($buffer != '') {
@@ -1452,12 +2002,16 @@  discard block
 block discarded – undo
1452 2002
 			$data['id_source'] = $id_source;
1453 2003
 			$data['format_source'] = 'blitzortung';
1454 2004
 			$SI->add($data);
1455
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2005
+			if ($globalDebug) {
2006
+				echo '☈ Lightning added'."\n";
2007
+			}
1456 2008
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1457 2009
 			unset($data);
1458 2010
 		    }
1459 2011
 		}
1460
-		if ($globalDebug) echo 'No more data...'."\n";
2012
+		if ($globalDebug) {
2013
+			echo 'No more data...'."\n";
2014
+		}
1461 2015
 		unset($buffer);
1462 2016
 	    }
1463 2017
 	    $last_exec[$id]['last'] = time();
@@ -1469,7 +2023,9 @@  discard block
 block discarded – undo
1469 2023
 	    $write = NULL;
1470 2024
 	    $e = NULL;
1471 2025
 	    $n = socket_select($read, $write, $e, $timeout);
1472
-	    if ($e != NULL) var_dump($e);
2026
+	    if ($e != NULL) {
2027
+	    	var_dump($e);
2028
+	    }
1473 2029
 	    if ($n > 0) {
1474 2030
 		$reset = 0;
1475 2031
 		foreach ($read as $nb => $r) {
@@ -1491,13 +2047,17 @@  discard block
 block discarded – undo
1491 2047
 		    if ($buffer !== FALSE) {
1492 2048
 			if ($format === 'vrstcp') {
1493 2049
 			    $buffer = explode('},{',$buffer);
1494
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2050
+			} else {
2051
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2052
+			}
1495 2053
 		    }
1496 2054
 		    // SBS format is CSV format
1497 2055
 		    if ($buffer !== FALSE && $buffer !== '') {
1498 2056
 			$tt[$format] = 0;
1499 2057
 			if ($format === 'acarssbs3') {
1500
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2058
+			    if ($globalDebug) {
2059
+			    	echo 'ACARS : '.$buffer."\n";
2060
+			    }
1501 2061
 			    $ACARS->add(trim($buffer));
1502 2062
 			    $ACARS->deleteLiveAcarsData();
1503 2063
 			} elseif ($format === 'raw') {
@@ -1506,30 +2066,70 @@  discard block
 block discarded – undo
1506 2066
 			    if (is_array($data)) {
1507 2067
 				$data['datetime'] = date('Y-m-d H:i:s');
1508 2068
 				$data['format_source'] = 'raw';
1509
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1510
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1511
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1512
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2069
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2070
+					$data['source_name'] = $globalSources[$nb]['name'];
2071
+				}
2072
+				if (isset($globalSources[$nb]['sourcestats'])) {
2073
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2074
+				}
2075
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2076
+					$data['noarchive'] = true;
2077
+				}
2078
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2079
+					$SI->add($data);
2080
+				}
1513 2081
 			    }
1514 2082
 			} elseif ($format === 'ais') {
1515 2083
 			    $ais_data = $AIS->parse_line(trim($buffer));
1516 2084
 			    $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'];
2085
+			    if (isset($ais_data['ident'])) {
2086
+			    	$data['ident'] = $ais_data['ident'];
2087
+			    }
2088
+			    if (isset($ais_data['mmsi'])) {
2089
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2090
+			    }
2091
+			    if (isset($ais_data['speed'])) {
2092
+			    	$data['speed'] = $ais_data['speed'];
2093
+			    }
2094
+			    if (isset($ais_data['heading'])) {
2095
+			    	$data['heading'] = $ais_data['heading'];
2096
+			    }
2097
+			    if (isset($ais_data['latitude'])) {
2098
+			    	$data['latitude'] = $ais_data['latitude'];
2099
+			    }
2100
+			    if (isset($ais_data['longitude'])) {
2101
+			    	$data['longitude'] = $ais_data['longitude'];
2102
+			    }
2103
+			    if (isset($ais_data['status'])) {
2104
+			    	$data['status'] = $ais_data['status'];
2105
+			    }
2106
+			    if (isset($ais_data['statusid'])) {
2107
+			    	$data['status_id'] = $ais_data['statusid'];
2108
+			    }
2109
+			    if (isset($ais_data['type'])) {
2110
+			    	$data['type'] = $ais_data['type'];
2111
+			    }
2112
+			    if (isset($ais_data['imo'])) {
2113
+			    	$data['imo'] = $ais_data['imo'];
2114
+			    }
2115
+			    if (isset($ais_data['callsign'])) {
2116
+			    	$data['callsign'] = $ais_data['callsign'];
2117
+			    }
2118
+			    if (isset($ais_data['destination'])) {
2119
+			    	$data['arrival_code'] = $ais_data['destination'];
2120
+			    }
2121
+			    if (isset($ais_data['eta_ts'])) {
2122
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2123
+			    }
2124
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2125
+			    	$data['noarchive'] = true;
2126
+			    }
2127
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2128
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2129
+			    }
2130
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2131
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2132
+			    }
1533 2133
 
1534 2134
 			    if (isset($ais_data['timestamp'])) {
1535 2135
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1538,7 +2138,9 @@  discard block
 block discarded – undo
1538 2138
 			    }
1539 2139
 			    $data['format_source'] = 'aisnmea';
1540 2140
     			    $data['id_source'] = $id_source;
1541
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2141
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2142
+			    	$MI->add($data);
2143
+			    }
1542 2144
 			    unset($data);
1543 2145
                         } elseif ($format === 'flightgearsp') {
1544 2146
                     	    //echo $buffer."\n";
@@ -1556,12 +2158,18 @@  discard block
 block discarded – undo
1556 2158
 				$data['speed'] = round($line[5]*1.94384);
1557 2159
 				$data['datetime'] = date('Y-m-d H:i:s');
1558 2160
 				$data['format_source'] = 'flightgearsp';
1559
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1560
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2161
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2162
+					$data['noarchive'] = true;
2163
+				}
2164
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2165
+					$SI->add($data);
2166
+				}
1561 2167
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1562 2168
 			    }
1563 2169
                         } elseif ($format === 'acars') {
1564
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2170
+                    	    if ($globalDebug) {
2171
+                    	    	echo 'ACARS : '.$buffer."\n";
2172
+                    	    }
1565 2173
 			    $ACARS->add(trim($buffer));
1566 2174
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1567 2175
 			    $ACARS->deleteLiveAcarsData();
@@ -1582,8 +2190,12 @@  discard block
 block discarded – undo
1582 2190
 				    $aircraft_type = $line[10];
1583 2191
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1584 2192
 				    $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);
2193
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2194
+				    	$data['noarchive'] = true;
2195
+				    }
2196
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2197
+				    	$SI->add($data);
2198
+				    }
1587 2199
 				}
1588 2200
 			    }
1589 2201
 			} elseif ($format === 'beast') {
@@ -1593,28 +2205,62 @@  discard block
 block discarded – undo
1593 2205
 			    foreach($buffer as $all_data) {
1594 2206
 				$line = json_decode('{'.$all_data.'}',true);
1595 2207
 				$data = array();
1596
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1597
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1598
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1599
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1600
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1601
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1602
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2208
+				if (isset($line['Icao'])) {
2209
+					$data['hex'] = $line['Icao'];
2210
+				}
2211
+				// hex
2212
+				if (isset($line['Call'])) {
2213
+					$data['ident'] = $line['Call'];
2214
+				}
2215
+				// ident
2216
+				if (isset($line['Alt'])) {
2217
+					$data['altitude'] = $line['Alt'];
2218
+				}
2219
+				// altitude
2220
+				if (isset($line['Spd'])) {
2221
+					$data['speed'] = $line['Spd'];
2222
+				}
2223
+				// speed
2224
+				if (isset($line['Trak'])) {
2225
+					$data['heading'] = $line['Trak'];
2226
+				}
2227
+				// heading
2228
+				if (isset($line['Lat'])) {
2229
+					$data['latitude'] = $line['Lat'];
2230
+				}
2231
+				// lat
2232
+				if (isset($line['Long'])) {
2233
+					$data['longitude'] = $line['Long'];
2234
+				}
2235
+				// long
1603 2236
 				//$data['verticalrate'] = $line['']; // verticale rate
1604
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2237
+				if (isset($line['Sqk'])) {
2238
+					$data['squawk'] = $line['Sqk'];
2239
+				}
2240
+				// squawk
1605 2241
 				$data['emergency'] = ''; // emergency
1606
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2242
+				if (isset($line['Reg'])) {
2243
+					$data['registration'] = $line['Reg'];
2244
+				}
1607 2245
 				/*
1608 2246
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1609 2247
 				else $data['datetime'] = date('Y-m-d H:i:s');
1610 2248
 				*/
1611 2249
 				$data['datetime'] = date('Y-m-d H:i:s');
1612
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2250
+				if (isset($line['Type'])) {
2251
+					$data['aircraft_icao'] = $line['Type'];
2252
+				}
1613 2253
 		    		$data['format_source'] = 'vrstcp';
1614 2254
 				$data['id_source'] = $id_source;
1615
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1616
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1617
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2255
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2256
+					$data['noarchive'] = true;
2257
+				}
2258
+				if (isset($value['name']) && $value['name'] != '') {
2259
+					$data['source_name'] = $value['name'];
2260
+				}
2261
+				if (isset($data['latitude']) && isset($data['hex'])) {
2262
+					$SI->add($data);
2263
+				}
1618 2264
 				unset($data);
1619 2265
 			    }
1620 2266
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1627,22 +2273,46 @@  discard block
 block discarded – undo
1627 2273
     				$data['hex'] = $lined['hexid'];
1628 2274
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1629 2275
     				$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'];
2276
+    				if (isset($lined['ident'])) {
2277
+    					$data['ident'] = $lined['ident'];
2278
+    				}
2279
+    				if (isset($lined['lat'])) {
2280
+    					$data['latitude'] = $lined['lat'];
2281
+    				}
2282
+    				if (isset($lined['lon'])) {
2283
+    					$data['longitude'] = $lined['lon'];
2284
+    				}
2285
+    				if (isset($lined['speed'])) {
2286
+    					$data['speed'] = $lined['speed'];
2287
+    				}
2288
+    				if (isset($lined['squawk'])) {
2289
+    					$data['squawk'] = $lined['squawk'];
2290
+    				}
2291
+    				if (isset($lined['alt'])) {
2292
+    					$data['altitude'] = $lined['alt'];
2293
+    				}
2294
+    				if (isset($lined['heading'])) {
2295
+    					$data['heading'] = $lined['heading'];
2296
+    				}
1637 2297
     				$data['id_source'] = $id_source;
1638 2298
     				$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
-				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);
2299
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2300
+    					$data['source_name'] = $globalSources[$nb]['name'];
2301
+    				}
2302
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2303
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2304
+    				}
2305
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2306
+					$data['noarchive'] = true;
2307
+				}
2308
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2309
+    					$SI->add($data);
2310
+    				}
1643 2311
     				unset($lined);
1644 2312
     				unset($data);
1645
-    			    } else $error = true;
2313
+    			    } else {
2314
+    			    	$error = true;
2315
+    			    }
1646 2316
 			} elseif ($format === 'aprs' && $use_aprs) {
1647 2317
 			    if ($aprs_connect === 0) {
1648 2318
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1668,63 +2338,121 @@  discard block
 block discarded – undo
1668 2338
 				    $aprs_last_tx = time();
1669 2339
 				    $data = array();
1670 2340
 				    //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');
2341
+				    if (isset($line['address'])) {
2342
+				    	$data['hex'] = $line['address'];
2343
+				    }
2344
+				    if (isset($line['mmsi'])) {
2345
+				    	$data['mmsi'] = $line['mmsi'];
2346
+				    }
2347
+				    if (isset($line['imo'])) {
2348
+				    	$data['imo'] = $line['imo'];
2349
+				    }
2350
+				    if (isset($line['squawk'])) {
2351
+				    	$data['squawk'] = $line['squawk'];
2352
+				    }
2353
+				    if (isset($line['arrival_code'])) {
2354
+				    	$data['arrival_code'] = $line['arrival_code'];
2355
+				    }
2356
+				    if (isset($line['arrival_date'])) {
2357
+				    	$data['arrival_date'] = $line['arrival_date'];
2358
+				    }
2359
+				    if (isset($line['typeid'])) {
2360
+				    	$data['type_id'] = $line['typeid'];
2361
+				    }
2362
+				    if (isset($line['statusid'])) {
2363
+				    	$data['status_id'] = $line['statusid'];
2364
+				    }
2365
+				    if (isset($line['timestamp'])) {
2366
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2367
+				    } else {
2368
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2369
+				    }
1681 2370
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1682
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2371
+				    if (isset($line['ident'])) {
2372
+				    	$data['ident'] = $line['ident'];
2373
+				    }
1683 2374
 				    $data['latitude'] = $line['latitude'];
1684 2375
 				    $data['longitude'] = $line['longitude'];
1685 2376
 				    //$data['verticalrate'] = $line[16];
1686
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2377
+				    if (isset($line['speed'])) {
2378
+				    	$data['speed'] = $line['speed'];
2379
+				    }
1687 2380
 				    //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'];
2381
+				    if (isset($line['altitude'])) {
2382
+				    	$data['altitude'] = $line['altitude'];
2383
+				    }
2384
+				    if (isset($line['comment'])) {
2385
+				    	$data['comment'] = $line['comment'];
2386
+				    }
2387
+				    if (isset($line['symbol'])) {
2388
+				    	$data['type'] = $line['symbol'];
2389
+				    }
1691 2390
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1692 2391
 				    
1693
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2392
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2393
+				    	$data['heading'] = $line['heading'];
2394
+				    }
1694 2395
 				    //else echo 'No heading...'."\n";
1695 2396
 				    //else $data['heading'] = 0;
1696
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2397
+				    if (isset($line['stealth'])) {
2398
+				    	$data['aircraft_type'] = $line['stealth'];
2399
+				    }
1697 2400
 				    //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;
2401
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2402
+				    	$data['noarchive'] = true;
2403
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2404
+				    	$data['noarchive'] = false;
2405
+				    }
2406
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2407
+				    	$data['noarchive'] = true;
2408
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2409
+				    	$data['noarchive'] = false;
2410
+				    }
1702 2411
     				    $data['id_source'] = $id_source;
1703
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1704
-				    else $data['format_source'] = 'aprs';
2412
+    				    if (isset($line['format_source'])) {
2413
+    				    	$data['format_source'] = $line['format_source'];
2414
+    				    } else {
2415
+				    	$data['format_source'] = 'aprs';
2416
+				    }
1705 2417
 				    $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'];
2418
+				    if (isset($line['source_type'])) {
2419
+				    	$data['source_type'] = $line['source_type'];
2420
+				    } else {
2421
+				    	$data['source_type'] = 'flarm';
2422
+				    }
2423
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2424
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2425
+    				    }
1709 2426
 				    $currentdate = date('Y-m-d H:i:s');
1710 2427
 				    $aprsdate = strtotime($data['datetime']);
1711
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2428
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2429
+				    	$data['altitude_relative'] = 'AMSL';
2430
+				    }
1712 2431
 				    // Accept data if time <= system time + 20s
1713 2432
 				    //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 2433
 				    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 2434
 					$send = $SI->add($data);
1716 2435
 				    } elseif ($data['source_type'] === 'ais') {
1717 2436
 					$data['type'] = '';
1718
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2437
+					if (isset($globalMarine) && $globalMarine) {
2438
+						$send = $MI->add($data);
2439
+					}
1719 2440
 				    } elseif (isset($line['stealth'])) {
1720
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1721
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2441
+					if ($line['stealth'] != 0) {
2442
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2443
+					} else {
2444
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2445
+					}
1722 2446
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1723 2447
 					    //$line['symbol'] === 'Balloon' ||
1724 2448
 					    $line['symbol'] === 'Glider' || 
1725 2449
 					    $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';
2450
+					    if ($line['symbol'] === 'Ballon') {
2451
+					    	$data['aircraft_icao'] = 'BALL';
2452
+					    }
2453
+					    if ($line['symbol'] === 'Glider') {
2454
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2455
+					    }
1728 2456
 					    $send = $SI->add($data);
1729 2457
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1730 2458
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -1755,9 +2483,13 @@  discard block
 block discarded – undo
1755 2483
 				    //} 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 2484
 				//    } 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 2485
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1758
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2486
+					if (isset($globalTracker) && $globalTracker) {
2487
+						$send = $TI->add($data);
2488
+					}
1759 2489
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1760
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2490
+					if (!isset($data['altitude'])) {
2491
+						$data['altitude'] = 0;
2492
+					}
1761 2493
 					$Source->deleteOldLocationByType('gs');
1762 2494
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1763 2495
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1766,7 +2498,9 @@  discard block
 block discarded – undo
1766 2498
 					}
1767 2499
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1768 2500
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1769
-					if ($globalDebug) echo '# Weather Station added'."\n";
2501
+					if ($globalDebug) {
2502
+						echo '# Weather Station added'."\n";
2503
+					}
1770 2504
 					$Source->deleteOldLocationByType('wx');
1771 2505
 					$weather_data = json_encode($line);
1772 2506
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1776,7 +2510,9 @@  discard block
 block discarded – undo
1776 2510
 					}
1777 2511
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1778 2512
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1779
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2513
+					if ($globalDebug) {
2514
+						echo '☈ Lightning added'."\n";
2515
+					}
1780 2516
 					$Source->deleteOldLocationByType('lightning');
1781 2517
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1782 2518
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1788,8 +2524,7 @@  discard block
 block discarded – undo
1788 2524
 				    	print_r($line);
1789 2525
 				    }
1790 2526
 				    unset($data);
1791
-				}
1792
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2527
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1793 2528
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1794 2529
 				}
1795 2530
 				/*
@@ -1798,7 +2533,9 @@  discard block
 block discarded – undo
1798 2533
 				}
1799 2534
 				*/
1800 2535
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1801
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2536
+				elseif ($line === true && $globalDebug) {
2537
+					echo '!! Failed : '.$buffer."!!\n";
2538
+				}
1802 2539
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1803 2540
 					$Source->deleteOldLocationByType('lightning');
1804 2541
 					$Source->deleteOldLocationByType('wx');
@@ -1834,26 +2571,45 @@  discard block
 block discarded – undo
1834 2571
     				$data['ground'] = $line[21];
1835 2572
     				$data['emergency'] = $line[19];
1836 2573
     				$data['format_source'] = 'sbs';
1837
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1838
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1839
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2574
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2575
+					$data['source_name'] = $globalSources[$nb]['name'];
2576
+				}
2577
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2578
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2579
+    				}
2580
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2581
+					$data['noarchive'] = true;
2582
+				}
1840 2583
     				$data['id_source'] = $id_source;
1841
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1842
-    				else $error = true;
2584
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2585
+    					$send = $SI->add($data);
2586
+    				} else {
2587
+    					$error = true;
2588
+    				}
1843 2589
     				unset($data);
1844
-    			    } else $error = true;
2590
+    			    } else {
2591
+    			    	$error = true;
2592
+    			    }
1845 2593
 			    if ($error) {
1846 2594
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1847
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2595
+					if ($globalDebug) {
2596
+						echo "Not a message. Ignoring... \n";
2597
+					}
1848 2598
 				} else {
1849
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2599
+					if ($globalDebug) {
2600
+						echo "Wrong line format. Ignoring... \n";
2601
+					}
1850 2602
 					if ($globalDebug) {
1851 2603
 						echo $buffer;
1852 2604
 						//print_r($line);
1853 2605
 					}
1854 2606
 					//socket_close($r);
1855
-					if ($globalDebug) echo "Reconnect after an error...\n";
1856
-					if ($format === 'aprs') $aprs_connect = 0;
2607
+					if ($globalDebug) {
2608
+						echo "Reconnect after an error...\n";
2609
+					}
2610
+					if ($format === 'aprs') {
2611
+						$aprs_connect = 0;
2612
+					}
1857 2613
 					$sourceer[$nb] = $globalSources[$nb];
1858 2614
 					connect_all($sourceer);
1859 2615
 					$sourceer = array();
@@ -1861,10 +2617,14 @@  discard block
 block discarded – undo
1861 2617
 			    }
1862 2618
 			}
1863 2619
 			// Sleep for xxx microseconds
1864
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2620
+			if (isset($globalSBSSleep)) {
2621
+				usleep($globalSBSSleep);
2622
+			}
1865 2623
 		    } else {
1866 2624
 			if ($format === 'flightgearmp') {
1867
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2625
+			    	if ($globalDebug) {
2626
+			    		echo "Reconnect FlightGear MP...";
2627
+			    	}
1868 2628
 				//@socket_close($r);
1869 2629
 				sleep($globalMinFetch);
1870 2630
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1873,10 +2633,15 @@  discard block
 block discarded – undo
1873 2633
 				break;
1874 2634
 				
1875 2635
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1876
-			    if (isset($tt[$format])) $tt[$format]++;
1877
-			    else $tt[$format] = 0;
2636
+			    if (isset($tt[$format])) {
2637
+			    	$tt[$format]++;
2638
+			    } else {
2639
+			    	$tt[$format] = 0;
2640
+			    }
1878 2641
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1879
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2642
+				if ($globalDebug) {
2643
+					echo "ERROR : Reconnect ".$format."...";
2644
+				}
1880 2645
 				//@socket_close($r);
1881 2646
 				sleep(2);
1882 2647
 				$aprs_connect = 0;
@@ -1894,11 +2659,17 @@  discard block
 block discarded – undo
1894 2659
 	    } else {
1895 2660
 		$error = socket_strerror(socket_last_error());
1896 2661
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1897
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1898
-			if (isset($globalDebug)) echo "Restarting...\n";
2662
+			if ($globalDebug) {
2663
+				echo "ERROR : socket_select give this error ".$error . "\n";
2664
+			}
2665
+			if (isset($globalDebug)) {
2666
+				echo "Restarting...\n";
2667
+			}
1899 2668
 			// Restart the script if possible
1900 2669
 			if (is_array($sockets)) {
1901
-			    if ($globalDebug) echo "Shutdown all sockets...";
2670
+			    if ($globalDebug) {
2671
+			    	echo "Shutdown all sockets...";
2672
+			    }
1902 2673
 			    
1903 2674
 			    foreach ($sockets as $sock) {
1904 2675
 				@socket_shutdown($sock,2);
@@ -1906,25 +2677,45 @@  discard block
 block discarded – undo
1906 2677
 			    }
1907 2678
 			    
1908 2679
 			}
1909
-			if ($globalDebug) echo "Waiting...";
2680
+			if ($globalDebug) {
2681
+				echo "Waiting...";
2682
+			}
1910 2683
 			sleep(2);
1911 2684
 			$time = time();
1912 2685
 			//connect_all($hosts);
1913 2686
 			$aprs_connect = 0;
1914
-			if ($reset%5 === 0) sleep(20);
1915
-			if ($reset%10 === 0) sleep(100);
1916
-			if ($reset%20 === 0) sleep(200);
1917
-			if ($reset > 100) exit('Too many attempts...');
1918
-			if ($globalDebug) echo "Restart all connections...";
2687
+			if ($reset%5 === 0) {
2688
+				sleep(20);
2689
+			}
2690
+			if ($reset%10 === 0) {
2691
+				sleep(100);
2692
+			}
2693
+			if ($reset%20 === 0) {
2694
+				sleep(200);
2695
+			}
2696
+			if ($reset > 100) {
2697
+				exit('Too many attempts...');
2698
+			}
2699
+			if ($globalDebug) {
2700
+				echo "Restart all connections...";
2701
+			}
1919 2702
 			connect_all($globalSources);
1920 2703
 		}
1921 2704
 	    }
1922 2705
 	}
1923 2706
 	if ($globalDaemon === false) {
1924
-	    if ($globalDebug) echo 'Check all...'."\n";
1925
-	    if (isset($SI)) $SI->checkAll();
1926
-	    if (isset($TI)) $TI->checkAll();
1927
-	    if (isset($MI)) $MI->checkAll();
2707
+	    if ($globalDebug) {
2708
+	    	echo 'Check all...'."\n";
2709
+	    }
2710
+	    if (isset($SI)) {
2711
+	    	$SI->checkAll();
2712
+	    }
2713
+	    if (isset($TI)) {
2714
+	    	$TI->checkAll();
2715
+	    }
2716
+	    if (isset($MI)) {
2717
+	    	$MI->checkAll();
2718
+	    }
1928 2719
 	}
1929 2720
     }
1930 2721
 }
Please login to merge, or discard this patch.