Completed
Push — master ( b076e3...d91afc )
by Yannick
37:02
created
scripts/daemon-spotter.php 3 patches
Indentation   +1214 added lines, -1214 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) {
18
-    require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19 19
 }
20 20
 if (isset($globalMarine) && $globalMarine) {
21
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25 25
 if (!isset($globalDebug)) $globalDebug = FALSE;
26 26
 
27 27
 if ($globalInstalled === FALSE) {
28
-    echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
-    sleep(5);
30
-    die();
28
+	echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
+	sleep(5);
30
+	die();
31 31
 }
32 32
 
33 33
 
34 34
 // Check if schema is at latest version
35 35
 $Connection = new Connection();
36 36
 if ($Connection->connectionExists() === false) {
37
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
-    exit();
37
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
+	exit();
39 39
 }
40 40
 if ($Connection->latest() === false) {
41
-    echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
-    exit();
41
+	echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
+	exit();
43 43
 }
44 44
 if (PHP_SAPI != 'cli') {
45
-    echo "This script MUST be called from console, not a web browser.";
45
+	echo "This script MUST be called from console, not a web browser.";
46 46
 //    exit();
47 47
 }
48 48
 
49 49
 // This is to be compatible with old version of settings.php
50 50
 if (!isset($globalSources)) {
51
-    if (isset($globalSBS1Hosts)) {
52
-        //$hosts = $globalSBS1Hosts;
53
-        foreach ($globalSBS1Hosts as $host) {
54
-	    $globalSources[] = array('host' => $host);
55
-    	}
56
-    } else {
57
-        if (!isset($globalSBS1Host)) {
58
-	    echo '$globalSources MUST be defined !';
59
-	    die;
51
+	if (isset($globalSBS1Hosts)) {
52
+		//$hosts = $globalSBS1Hosts;
53
+		foreach ($globalSBS1Hosts as $host) {
54
+		$globalSources[] = array('host' => $host);
55
+		}
56
+	} else {
57
+		if (!isset($globalSBS1Host)) {
58
+		echo '$globalSources MUST be defined !';
59
+		die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62 62
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
63
-    }
63
+	}
64 64
 }
65 65
 
66 66
 $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'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70
-    $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
70
+	$globalSources = array();
71
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
+	else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74
-    $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
74
+	$globalSources = array();
75
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
+	else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
79 79
 	$globalServerAPRS = TRUE;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 if (isset($options['idsource'])) $id_source = $options['idsource'];
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
115
+	if ($globalDebug) echo "Using Server Mode\n";
116
+	$SI=new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
126
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
126
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 128
 }
129 129
 
130 130
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
131 131
 if (isset($globalMarine) && $globalMarine) {
132
-    $AIS = new AIS();
133
-    $MI = new MarineImport($Connection->db);
132
+	$AIS = new AIS();
133
+	$MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136 136
 $SBS=new SBS();
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
147
-        global $sockets;
148
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
-        die("Bye!\n");
150
-    });
151
-    pcntl_signal_dispatch();
146
+	pcntl_signal(SIGINT,  function() {
147
+		global $sockets;
148
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
+		die("Bye!\n");
150
+	});
151
+	pcntl_signal_dispatch();
152 152
 }
153 153
 
154 154
 // let's try and connect
@@ -158,47 +158,47 @@  discard block
 block discarded – undo
158 158
 $reset = 0;
159 159
 
160 160
 function connect_all($hosts) {
161
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
-    $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
165
-    foreach ($hosts as $id => $value) {
161
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
+	$reset++;
164
+	if ($globalDebug) echo 'Connect to all...'."\n";
165
+	foreach ($hosts as $id => $value) {
166 166
 	$host = $value['host'];
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170 170
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
172
-        	//$formats[$id] = 'deltadbtxt';
173
-        	$globalSources[$id]['format'] = 'deltadbtxt';
174
-        	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
-        	//$formats[$id] = 'vatsimtxt';
178
-        	$globalSources[$id]['format'] = 'vatsimtxt';
179
-        	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182
-        	//$formats[$id] = 'aircraftlistjson';
183
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
187
-        	//$formats[$id] = 'aircraftjson';
188
-        	$globalSources[$id]['format'] = 'aircraftjson';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
192
-        	//$formats[$id] = 'planefinderclient';
193
-        	$globalSources[$id]['format'] = 'planefinderclient';
194
-        	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
197
-        	//$formats[$id] = 'aircraftlistjson';
198
-        	$globalSources[$id]['format'] = 'opensky';
199
-        	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
-    	    /*
171
+			if (preg_match('/deltadb.txt$/i',$host)) {
172
+			//$formats[$id] = 'deltadbtxt';
173
+			$globalSources[$id]['format'] = 'deltadbtxt';
174
+			//$last_exec['deltadbtxt'] = 0;
175
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
+			//$formats[$id] = 'vatsimtxt';
178
+			$globalSources[$id]['format'] = 'vatsimtxt';
179
+			//$last_exec['vatsimtxt'] = 0;
180
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
182
+			//$formats[$id] = 'aircraftlistjson';
183
+			$globalSources[$id]['format'] = 'aircraftlistjson';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
+			} else if (preg_match('/aircraft.json$/i',$host)) {
187
+			//$formats[$id] = 'aircraftjson';
188
+			$globalSources[$id]['format'] = 'aircraftjson';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
+			} else if (preg_match('/aircraft$/i',$host)) {
192
+			//$formats[$id] = 'planefinderclient';
193
+			$globalSources[$id]['format'] = 'planefinderclient';
194
+			//$last_exec['aircraftlistjson'] = 0;
195
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
+			} else if (preg_match('/opensky/i',$host)) {
197
+			//$formats[$id] = 'aircraftlistjson';
198
+			$globalSources[$id]['format'] = 'opensky';
199
+			//$last_exec['aircraftlistjson'] = 0;
200
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
+			/*
202 202
     	    // Disabled for now, site change source format
203 203
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
204 204
         	//$formats[$id] = 'radarvirtueljson';
@@ -210,131 +210,131 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
-        	//$formats[$id] = 'planeupdatefaa';
215
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
216
-        	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
-        	    exit(0);
221
-        	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'phpvmacars';
225
-        	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
-        	//$formats[$id] = 'phpvmacars';
229
-        	$globalSources[$id]['format'] = 'vaos';
230
-        	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
233
-        	//$formats[$id] = 'phpvmacars';
234
-        	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
237
-        	//$formats[$id] = 'whazzup';
238
-        	$globalSources[$id]['format'] = 'whazzup';
239
-        	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
242
-        	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
245
-        	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
248
-        	//$formats[$id] = 'pirepsjson';
249
-        	$globalSources[$id]['format'] = 'pirepsjson';
250
-        	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
-        	//$formats[$id] = 'fr24json';
254
-        	$globalSources[$id]['format'] = 'fr24json';
255
-        	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
-        	    exit(0);
260
-        	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
262
-        	//$formats[$id] = 'fr24json';
263
-        	$globalSources[$id]['format'] = 'myshiptracking';
264
-        	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
-        	    exit(0);
269
-        	}
270
-            //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
-        	//$formats[$id] = 'tsv';
273
-        	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
-            }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
-    		    if ($idf !== false) {
280
-    			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
288
-	    if (isset($hostport[1])) {
213
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
+			//$formats[$id] = 'planeupdatefaa';
215
+			$globalSources[$id]['format'] = 'planeupdatefaa';
216
+			//$last_exec['planeupdatefaa'] = 0;
217
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
+				exit(0);
221
+			}
222
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'phpvmacars';
225
+			//$last_exec['phpvmacars'] = 0;
226
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
+			//$formats[$id] = 'phpvmacars';
229
+			$globalSources[$id]['format'] = 'vaos';
230
+			//$last_exec['phpvmacars'] = 0;
231
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
233
+			//$formats[$id] = 'phpvmacars';
234
+			$globalSources[$id]['format'] = 'vam';
235
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
+			} else if (preg_match('/whazzup/i',$host)) {
237
+			//$formats[$id] = 'whazzup';
238
+			$globalSources[$id]['format'] = 'whazzup';
239
+			//$last_exec['whazzup'] = 0;
240
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
+			} else if (preg_match('/blitzortung/i',$host)) {
242
+			$globalSources[$id]['format'] = 'blitzortung';
243
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
+			} else if (preg_match('/airwhere/i',$host)) {
245
+			$globalSources[$id]['format'] = 'airwhere';
246
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
+			} else if (preg_match('/recentpireps/i',$host)) {
248
+			//$formats[$id] = 'pirepsjson';
249
+			$globalSources[$id]['format'] = 'pirepsjson';
250
+			//$last_exec['pirepsjson'] = 0;
251
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
+			//$formats[$id] = 'fr24json';
254
+			$globalSources[$id]['format'] = 'fr24json';
255
+			//$last_exec['fr24json'] = 0;
256
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
+				exit(0);
260
+			}
261
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
262
+			//$formats[$id] = 'fr24json';
263
+			$globalSources[$id]['format'] = 'myshiptracking';
264
+			//$last_exec['fr24json'] = 0;
265
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
+				exit(0);
269
+			}
270
+			//} else if (preg_match('/10001/',$host)) {
271
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
+			//$formats[$id] = 'tsv';
273
+			$globalSources[$id]['format'] = 'tsv';
274
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
+			}
276
+		} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
+			if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
+				if ($idf !== false) {
280
+				$httpfeeds[$id] = $idf;
281
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
+			} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
+			elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
+			elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
+		$hostport = explode(':',$host);
288
+		if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
291
-	    } else {
291
+		} else {
292 292
 		$port = $globalSources[$id]['port'];
293 293
 		$hostn = $globalSources[$id]['host'];
294
-	    }
295
-	    $Common = new Common();
296
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
-    	    } else {
299
-    		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
-	    }
302
-	    if ($s) {
303
-    	        $sockets[$id] = $s;
304
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
294
+		}
295
+		$Common = new Common();
296
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
+			} else {
299
+			$udp = true;
300
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
+		}
302
+		if ($s) {
303
+				$sockets[$id] = $s;
304
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312
-    		    } elseif ($port == '10001') {
313
-        		//$formats[$id] = 'tsv';
314
-        		$globalSources[$id]['format'] = 'tsv';
315
-		    } elseif ($port == '30002') {
316
-        		//$formats[$id] = 'raw';
317
-        		$globalSources[$id]['format'] = 'raw';
318
-		    } elseif ($port == '5001') {
319
-        		//$formats[$id] = 'raw';
320
-        		$globalSources[$id]['format'] = 'flightgearmp';
321
-		    } elseif ($port == '30005') {
312
+				} elseif ($port == '10001') {
313
+				//$formats[$id] = 'tsv';
314
+				$globalSources[$id]['format'] = 'tsv';
315
+			} elseif ($port == '30002') {
316
+				//$formats[$id] = 'raw';
317
+				$globalSources[$id]['format'] = 'raw';
318
+			} elseif ($port == '5001') {
319
+				//$formats[$id] = 'raw';
320
+				$globalSources[$id]['format'] = 'flightgearmp';
321
+			} elseif ($port == '30005') {
322 322
 			// Not yet supported
323
-        		//$formats[$id] = 'beast';
324
-        		$globalSources[$id]['format'] = 'beast';
325
-		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
327
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
323
+				//$formats[$id] = 'beast';
324
+				$globalSources[$id]['format'] = 'beast';
325
+			//} else $formats[$id] = 'sbs';
326
+			} else $globalSources[$id]['format'] = 'sbs';
327
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 328
 		}
329 329
 		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330 330
 		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
331
-            } else {
331
+			} else {
332 332
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
333 333
 		sleep(10);
334 334
 		connect_all($hosts);
335
-    	    }
336
-        }
337
-    }
335
+			}
336
+		}
337
+	}
338 338
 }
339 339
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
340 340
 
@@ -357,9 +357,9 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
361 361
 } else {
362
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
362
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
364 364
 
365 365
 // APRS Configuration
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	die;
369 369
 }
370 370
 foreach ($globalSources as $key => $source) {
371
-    if (!isset($source['format'])) {
372
-        $globalSources[$key]['format'] = 'auto';
373
-    }
374
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
375
-        unset($globalSources[$key]);
376
-    }
371
+	if (!isset($source['format'])) {
372
+		$globalSources[$key]['format'] = 'auto';
373
+	}
374
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
375
+		unset($globalSources[$key]);
376
+	}
377 377
 }
378 378
 connect_all($globalSources);
379 379
 foreach ($globalSources as $key => $source) {
380
-    if (isset($source['format']) && $source['format'] == 'aprs') {
380
+	if (isset($source['format']) && $source['format'] == 'aprs') {
381 381
 	$aprs_connect = 0;
382 382
 	$use_aprs = true;
383 383
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
384 384
 	break;
385
-    }
385
+	}
386 386
 }
387 387
 
388 388
 if ($use_aprs) {
@@ -423,173 +423,173 @@  discard block
 block discarded – undo
423 423
 
424 424
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 425
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
426
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
429
-    // Delete old ATC
430
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
428
+	if (!$globalDaemon) $i = $endtime-time();
429
+	// Delete old ATC
430
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
432
-        $ATC->deleteOldATC();
433
-    }
432
+		$ATC->deleteOldATC();
433
+	}
434 434
     
435
-    if (count($last_exec) == count($globalSources)) {
435
+	if (count($last_exec) == count($globalSources)) {
436 436
 	$max = $globalMinFetch;
437 437
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
438
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
441
+		if ($globalDebug) echo 'Sleeping...'."\n";
442
+		sleep($globalMinFetch-$max+2);
443
+	}
443 444
 	}
444
-    }
445 445
 
446 446
     
447
-    //foreach ($formats as $id => $value) {
448
-    foreach ($globalSources as $id => $value) {
447
+	//foreach ($formats as $id => $value) {
448
+	foreach ($globalSources as $id => $value) {
449 449
 	date_default_timezone_set('UTC');
450 450
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451 451
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452 452
 	if ($value['format'] === 'deltadbtxt' && 
453
-	    (
453
+		(
454 454
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
455 455
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
456
-	    )
456
+		)
457 457
 	) {
458
-        //$buffer = $Common->getData($hosts[$id]);
459
-        $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
461
-        $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
-        $buffer = explode('\n', $buffer);
463
-        foreach ($buffer as $line) {
464
-            if ($line != '' && count($line) > 7) {
465
-                $line = explode(',', $line);
466
-                $data = array();
467
-                $data['hex'] = $line[1]; // hex
468
-                $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
-                $data['verticalrate'] = ''; // vertical rate
475
-                //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
-                $data['emergency'] = ''; // emergency
477
-                $data['datetime'] = date('Y-m-d H:i:s');
478
-                $data['format_source'] = 'deltadbtxt';
479
-                $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
-                $SI->add($data);
484
-                unset($data);
485
-            }
486
-        }
487
-        $last_exec[$id]['last'] = time();
488
-    } elseif ($value['format'] === 'radarcapejson' &&
489
-            (
490
-                (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
-                (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
-            )
493
-        ) {
494
-            //$buffer = $Common->getData($hosts[$id]);
495
-            $buffer = $Common->getData($value['host']);
496
-            if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
498
-                foreach ($all_data as $line) {
499
-                    $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
-                    $data['hex'] = $line['hex']; // hex
502
-                    $data['ident'] = $line['fli']; // ident
503
-                    $data['altitude'] = $line['alt']; // altitude
504
-                    $data['speed'] = $line['spd']; // speed
505
-                    $data['heading'] = $line['trk']; // heading
506
-                    $data['latitude'] = $line['lat']; // lat
507
-                    $data['longitude'] = $line['lon']; // long
508
-                    $data['verticalrate'] = $line['vrt']; // vertical rate
509
-                    $data['squawk'] = $line['squ']; // squawk
510
-                    $data['ground'] = $line['gda']; // ground
511
-                    $data['registration'] = $line['reg'];
512
-                    //$data['emergency'] = ''; // emergency
513
-                    $data['datetime'] = date('Y-m-d H:i:s');
514
-                    $data['format_source'] = 'radarcapejson';
515
-                    $data['id_source'] = $id_source;
516
-                    if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
458
+		//$buffer = $Common->getData($hosts[$id]);
459
+		$buffer = $Common->getData($value['host']);
460
+		if ($buffer != '') $reset = 0;
461
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
+		$buffer = explode('\n', $buffer);
463
+		foreach ($buffer as $line) {
464
+			if ($line != '' && count($line) > 7) {
465
+				$line = explode(',', $line);
466
+				$data = array();
467
+				$data['hex'] = $line[1]; // hex
468
+				$data['ident'] = $line[2]; // ident
469
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
+				$data['verticalrate'] = ''; // vertical rate
475
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
+				$data['emergency'] = ''; // emergency
477
+				$data['datetime'] = date('Y-m-d H:i:s');
478
+				$data['format_source'] = 'deltadbtxt';
479
+				$data['id_source'] = $id_source;
480
+				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
+				if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
+				$SI->add($data);
484
+				unset($data);
485
+			}
486
+		}
487
+		$last_exec[$id]['last'] = time();
488
+	} elseif ($value['format'] === 'radarcapejson' &&
489
+			(
490
+				(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
+				(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
+			)
493
+		) {
494
+			//$buffer = $Common->getData($hosts[$id]);
495
+			$buffer = $Common->getData($value['host']);
496
+			if ($buffer != '') {
497
+				$all_data = json_decode($buffer,true);
498
+				foreach ($all_data as $line) {
499
+					$data = array();
500
+					$data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
+					$data['hex'] = $line['hex']; // hex
502
+					$data['ident'] = $line['fli']; // ident
503
+					$data['altitude'] = $line['alt']; // altitude
504
+					$data['speed'] = $line['spd']; // speed
505
+					$data['heading'] = $line['trk']; // heading
506
+					$data['latitude'] = $line['lat']; // lat
507
+					$data['longitude'] = $line['lon']; // long
508
+					$data['verticalrate'] = $line['vrt']; // vertical rate
509
+					$data['squawk'] = $line['squ']; // squawk
510
+					$data['ground'] = $line['gda']; // ground
511
+					$data['registration'] = $line['reg'];
512
+					//$data['emergency'] = ''; // emergency
513
+					$data['datetime'] = date('Y-m-d H:i:s');
514
+					$data['format_source'] = 'radarcapejson';
515
+					$data['id_source'] = $id_source;
516
+					if (isset($value['name']) && $value['name'] != '') {
517
+						if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
+						else $data['source_name'] = $value['name'];
519
+					} elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
+					if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
+					if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
522 522
 
523
-                    $SI->add($data);
524
-                    unset($data);
525
-                }
526
-            }
527
-            $last_exec[$id]['last'] = time();
523
+					$SI->add($data);
524
+					unset($data);
525
+				}
526
+			}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] === 'aisnmeatxt' && 
529
-	    (
529
+		(
530 530
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
531 531
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
532
-	    )
532
+		)
533 533
 	) {
534
-	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
-	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
540
-	    foreach ($buffer as $line) {
534
+		date_default_timezone_set('CET');
535
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
+		date_default_timezone_set('UTC');
537
+		if ($buffer != '') $reset = 0;
538
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
+		$buffer = explode('\n',$buffer);
540
+		foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542
-		    //echo "'".$line."'\n";
543
-		    $add = false;
544
-		    $ais_data = $AIS->parse_line(trim($line));
545
-		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
-		    if (isset($ais_data['timestamp'])) {
542
+			//echo "'".$line."'\n";
543
+			$add = false;
544
+			$ais_data = $AIS->parse_line(trim($line));
545
+			$data = array();
546
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
+			if (isset($ais_data['timestamp'])) {
559 559
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
-			    $add = true;
561
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
+				$add = true;
563 563
 			}
564
-		    } else {
564
+			} else {
565 565
 			$data['datetime'] = date('Y-m-d H:i:s');
566 566
 			$add = true;
567
-		    }
568
-		    $data['format_source'] = 'aisnmeatxt';
569
-    		    $data['id_source'] = $id_source;
570
-		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
-		    unset($data);
567
+			}
568
+			$data['format_source'] = 'aisnmeatxt';
569
+				$data['id_source'] = $id_source;
570
+			//print_r($data);
571
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
+			unset($data);
574 574
 		}
575
-    	    }
576
-    	    $last_exec[$id]['last'] = time();
575
+			}
576
+			$last_exec[$id]['last'] = time();
577 577
 	} elseif ($value['format'] === 'aisnmeahttp') {
578
-	    $arr = $httpfeeds;
579
-	    $w = $e = null;
578
+		$arr = $httpfeeds;
579
+		$w = $e = null;
580 580
 	    
581
-	    if (isset($arr[$id])) {
581
+		if (isset($arr[$id])) {
582 582
 		$nn = stream_select($arr,$w,$e,$timeout);
583 583
 		if ($nn > 0) {
584
-		    foreach ($httpfeeds as $feed) {
584
+			foreach ($httpfeeds as $feed) {
585 585
 			$buffer = stream_get_line($feed,2000,"\n");
586 586
 			if ($buffer === FALSE) {
587
-			    connect_all($globalSources);
587
+				connect_all($globalSources);
588 588
 			}
589 589
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590 590
 			$buffer = explode('\n',$buffer);
591 591
 			foreach ($buffer as $line) {
592
-			    if ($line != '') {
592
+				if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -607,117 +607,117 @@  discard block
 block discarded – undo
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608 608
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 611
 				} else {
612
-				    $data['datetime'] = date('Y-m-d H:i:s');
612
+					$data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
614 614
 				$data['format_source'] = 'aisnmeahttp';
615 615
 				$data['id_source'] = $id_source;
616 616
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617 617
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
618 618
 				unset($data);
619
-			    }
619
+				}
620
+			}
620 621
 			}
621
-		    }
622 622
 		} else {
623
-		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
626
-		    if ($tt[$format] > 30) {
623
+			$format = $value['format'];
624
+			if (isset($tt[$format])) $tt[$format]++;
625
+			else $tt[$format] = 0;
626
+			if ($tt[$format] > 30) {
627 627
 			if ($globalDebug) echo 'Reconnect...'."\n";
628 628
 			sleep(2);
629 629
 			//$sourceeen[] = $value;
630 630
 			//connect_all($sourceeen);
631 631
 			//$sourceeen = array();
632 632
 			connect_all($globalSources);
633
-		    }
633
+			}
634
+		}
634 635
 		}
635
-	    }
636 636
 	} elseif ($value['format'] === 'myshiptracking' && 
637
-	    (
637
+		(
638 638
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640
-	    )
640
+		)
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
643
-	    if ($buffer != '') {
642
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
643
+		if ($buffer != '') {
644 644
 		//echo $buffer;
645 645
 		$all_data = json_decode($buffer,true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648
-		    foreach ($all_data[0]['DATA'] as $line) {
648
+			foreach ($all_data[0]['DATA'] as $line) {
649 649
 			if ($line != '') {
650
-			    $data = array();
651
-			    $data['ident'] = $line['NAME'];
652
-			    $data['mmsi'] = $line['MMSI'];
653
-			    if (strlen($data['mmsi']) > 9) {
650
+				$data = array();
651
+				$data['ident'] = $line['NAME'];
652
+				$data['mmsi'] = $line['MMSI'];
653
+				if (strlen($data['mmsi']) > 9) {
654 654
 				$data['mmsi'] = substr($data['mmsi'],-9);
655
-			    }
656
-			    $data['speed'] = $line['SOG'];
657
-			    $data['heading'] = $line['COG'];
658
-			    $data['latitude'] = $line['LAT'];
659
-			    $data['longitude'] = $line['LNG'];
660
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
-			    //$data['type_id'] = $line['TYPE'];
662
-			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
-			    $data['format_source'] = 'myshiptracking';
667
-			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
-			    $MI->add($data);
670
-			    unset($data);
655
+				}
656
+				$data['speed'] = $line['SOG'];
657
+				$data['heading'] = $line['COG'];
658
+				$data['latitude'] = $line['LAT'];
659
+				$data['longitude'] = $line['LNG'];
660
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
+				//$data['type_id'] = $line['TYPE'];
662
+				$data['imo'] = $line['IMO'];
663
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
+				$data['format_source'] = 'myshiptracking';
667
+				$data['id_source'] = $id_source;
668
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
+				$MI->add($data);
670
+				unset($data);
671
+			}
671 672
 			}
672
-		    }
673 673
 		}
674
-	    }
675
-	    $last_exec[$id]['last'] = time();
674
+		}
675
+		$last_exec[$id]['last'] = time();
676 676
 	} elseif ($value['format'] === 'boatbeaconapp' && 
677
-	    (
677
+		(
678 678
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680
-	    )
680
+		)
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
-	    if ($buffer != '') {
682
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
+		if ($buffer != '') {
684 684
 		$all_data = json_decode($buffer,true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686
-		    foreach ($all_data as $line) {
686
+			foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688
-			    $data = array();
689
-			    $data['ident'] = $line['shipname'];
690
-			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
692
-			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
-			    $data['latitude'] = $line['latitude'];
695
-			    $data['longitude'] = $line['longitude'];
696
-			    $data['type_id'] = $line['shiptype'];
697
-			    $data['arrival_code'] = $line['destination'];
698
-			    $data['datetime'] = $line['time'];
699
-			    $data['format_source'] = 'boatbeaconapp';
700
-			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-			    $MI->add($data);
703
-			    unset($data);
688
+				$data = array();
689
+				$data['ident'] = $line['shipname'];
690
+				$data['callsign'] = $line['callsign'];
691
+				$data['mmsi'] = substr($line['mmsi'],-9);
692
+				$data['speed'] = $line['sog'];
693
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
+				$data['latitude'] = $line['latitude'];
695
+				$data['longitude'] = $line['longitude'];
696
+				$data['type_id'] = $line['shiptype'];
697
+				$data['arrival_code'] = $line['destination'];
698
+				$data['datetime'] = $line['time'];
699
+				$data['format_source'] = 'boatbeaconapp';
700
+				$data['id_source'] = $id_source;
701
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+				$MI->add($data);
703
+				unset($data);
704
+			}
704 705
 			}
705
-		    }
706 706
 		}
707 707
 		
708
-	    }
709
-    	    $last_exec[$id]['last'] = time();
708
+		}
709
+			$last_exec[$id]['last'] = time();
710 710
 	} elseif ($value['format'] === 'boatnerd' && 
711
-	    (
711
+		(
712 712
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
713 713
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
714
-	    )
714
+		)
715 715
 	) {
716
-	    $buffer = $Common->getData($value['host']);
717
-	    if ($buffer != '') {
716
+		$buffer = $Common->getData($value['host']);
717
+		if ($buffer != '') {
718 718
 		$all_data = json_decode($buffer,true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720
-		    foreach ($all_data['features'] as $line) {
720
+			foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -737,75 +737,75 @@  discard block
 block discarded – undo
737 737
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738 738
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
739 739
 			unset($data);
740
-		    }
740
+			}
741 741
 		}
742 742
 		
743
-	    }
744
-    	    $last_exec[$id]['last'] = time();
743
+		}
744
+			$last_exec[$id]['last'] = time();
745 745
 	} elseif ($value['format'] === 'shipplotter' && 
746
-	    (
746
+		(
747 747
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
748 748
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749
-	    )
749
+		)
750 750
 	) {
751
-	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
754
-	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
758
-	    foreach ($buffer as $line) {
751
+		if ($globalDebug) echo 'download...';
752
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
+		if ($globalDebug) echo 'done !'."\n";
754
+		// FIXME: Need more work
755
+		if ($buffer != '') $reset = 0;
756
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
+		$buffer = explode('\n',$buffer);
758
+		foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760
-		    $data = array();
761
-		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
769
-		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
771
-		    //$data['draft'] = substr($line,67,4);
772
-		    //$data['length'] = substr($line,72,3);
773
-		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
-		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
777
-		    //$data['etaDate'] = substr($line,129,5);
778
-		    //$data['etaTime'] = substr($line,135,5);
779
-		    $data['format_source'] = 'shipplotter';
780
-    		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
-		    //print_r($data);
783
-		    //echo 'Add...'."\n";
784
-		    $MI->add($data);
785
-		    unset($data);
760
+			$data = array();
761
+			//echo $line."\n";
762
+			$data['mmsi'] = (int)substr($line,0,9);
763
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
+			$data['status_id'] = substr($line,21,2);
765
+			$data['type_id'] = substr($line,24,3);
766
+			$data['latitude'] = substr($line,29,9);
767
+			$data['longitude'] = substr($line,41,9);
768
+			$data['speed'] = round(substr($line,51,5));
769
+			//$data['course'] = substr($line,57,5);
770
+			$data['heading'] = round(substr($line,63,3));
771
+			//$data['draft'] = substr($line,67,4);
772
+			//$data['length'] = substr($line,72,3);
773
+			//$data['beam'] = substr($line,76,2);
774
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
+			//$data['callsign'] = trim(substr($line,100,7);
776
+			$data['arrival_code'] = substr($line,108,20);
777
+			//$data['etaDate'] = substr($line,129,5);
778
+			//$data['etaTime'] = substr($line,135,5);
779
+			$data['format_source'] = 'shipplotter';
780
+				$data['id_source'] = $id_source;
781
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
+			//print_r($data);
783
+			//echo 'Add...'."\n";
784
+			$MI->add($data);
785
+			unset($data);
786 786
 		}
787
-    	    }
788
-    	    $last_exec[$id]['last'] = time();
787
+			}
788
+			$last_exec[$id]['last'] = time();
789 789
 	} elseif ($value['format'] === 'sailawayfull' && 
790
-	    (
790
+		(
791 791
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 10*60))
792
-	    )
792
+		)
793 793
 	) {
794
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
794
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
795 795
 		echo 'Sailaway API key MUST be defined';
796 796
 		exit(0);
797
-	    }
798
-	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
797
+		}
798
+		$sailawayoption = array('key' => $globalSailaway['key']);
799
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
801 801
 
802
-	    for ($i = 0; $i <= 1; $i++) {
802
+		for ($i = 0; $i <= 1; $i++) {
803 803
 		if ($globalDebug) echo '! Download... ';
804 804
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2');
805 805
 		if ($globalDebug) echo 'done'."\n";
806 806
 		if ($buffer != '') {
807
-		    $all_data = json_decode($buffer,true);
808
-		    if (isset($all_data['missions'])) {
807
+			$all_data = json_decode($buffer,true);
808
+			if (isset($all_data['missions'])) {
809 809
 			foreach ($all_data['missions'] as $mission) {
810 810
 				$mission_user = $mission['usrname'];
811 811
 				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
@@ -832,16 +832,16 @@  discard block
 block discarded – undo
832 832
 					$MI->race_add($datar);
833 833
 				}
834 834
 			}
835
-		    }
835
+			}
836 836
 		}
837 837
 		sleep(10*60);
838
-	    }
839
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
840
-	    if ($buffer != '') {
838
+		}
839
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
840
+		if ($buffer != '') {
841 841
 		$data = json_decode($buffer,true);
842 842
 		//print_r($data);
843 843
 		if (isset($data['boats'])) {
844
-		    foreach ($data['boats'] as $sail) {
844
+			foreach ($data['boats'] as $sail) {
845 845
 			$data = array();
846 846
 			$data['id'] = $sail['ubtnr'];
847 847
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -861,17 +861,17 @@  discard block
 block discarded – undo
861 861
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
862 862
 			$MI->add($data);
863 863
 			unset($data);
864
-		    }
864
+			}
865 865
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
866
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
866
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
867 867
 
868
-    	    $last_exec[$id]['last'] = time();
868
+			$last_exec[$id]['last'] = time();
869 869
 	} elseif ($value['format'] === 'sailaway' && 
870
-	    (
870
+		(
871 871
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
872
-	    )
872
+		)
873 873
 	) {
874
-	    /*
874
+		/*
875 875
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
876 876
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
877 877
 		//echo $authsailaway;
@@ -882,20 +882,20 @@  discard block
 block discarded – undo
882 882
 		}
883 883
 	    }
884 884
 	    */
885
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
885
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
886 886
 		echo 'Sailaway API key MUST be defined';
887 887
 		exit(0);
888
-	    }
889
-	    if ($globalDebug) echo '! Download... ';
890
-	    $sailawayoption = array('key' => $globalSailaway['key']);
891
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
892
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
893
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
894
-	    if ($buffer != '') {
888
+		}
889
+		if ($globalDebug) echo '! Download... ';
890
+		$sailawayoption = array('key' => $globalSailaway['key']);
891
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
892
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
893
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
894
+		if ($buffer != '') {
895 895
 		$data = json_decode($buffer,true);
896 896
 		//print_r($data);
897 897
 		if (isset($data['boats'])) {
898
-		    foreach ($data['boats'] as $sail) {
898
+			foreach ($data['boats'] as $sail) {
899 899
 			$data = array();
900 900
 			$data['id'] = $sail['ubtnr'];
901 901
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -915,35 +915,35 @@  discard block
 block discarded – undo
915 915
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
916 916
 			$MI->add($data);
917 917
 			unset($data);
918
-		    }
918
+			}
919 919
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
920
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
921
-    	    $last_exec[$id]['last'] = time();
920
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
921
+			$last_exec[$id]['last'] = time();
922 922
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
923 923
 	} elseif (
924
-	    (
924
+		(
925 925
 		$value['format'] === 'whazzup' && 
926 926
 		(
927
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
928
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
927
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
928
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
929 929
 		)
930
-	    ) || (
930
+		) || (
931 931
 		$value['format'] === 'vatsimtxt' && 
932 932
 		(
933
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
934
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
933
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
934
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
935
+		)
935 936
 		)
936
-	    )
937 937
 	) {
938
-	    //$buffer = $Common->getData($hosts[$id]);
939
-	    $buffer = $Common->getData($value['host']);
940
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
941
-	    $buffer = explode('\n',$buffer);
942
-	    $reset = 0;
943
-	    foreach ($buffer as $line) {
944
-    		if ($line != '') {
945
-    		    $line = explode(':', $line);
946
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
938
+		//$buffer = $Common->getData($hosts[$id]);
939
+		$buffer = $Common->getData($value['host']);
940
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
941
+		$buffer = explode('\n',$buffer);
942
+		$reset = 0;
943
+		foreach ($buffer as $line) {
944
+			if ($line != '') {
945
+				$line = explode(':', $line);
946
+				if (count($line) > 30 && $line[0] != 'callsign') {
947 947
 			$data = array();
948 948
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
949 949
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -956,37 +956,37 @@  discard block
 block discarded – undo
956 956
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
957 957
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
958 958
 			$data['latitude'] = $line[5]; // lat
959
-	        	$data['longitude'] = $line[6]; // long
960
-	        	$data['verticalrate'] = ''; // vertical rate
961
-	        	$data['squawk'] = ''; // squawk
962
-	        	$data['emergency'] = ''; // emergency
963
-	        	$data['waypoints'] = $line[30];
959
+				$data['longitude'] = $line[6]; // long
960
+				$data['verticalrate'] = ''; // vertical rate
961
+				$data['squawk'] = ''; // squawk
962
+				$data['emergency'] = ''; // emergency
963
+				$data['waypoints'] = $line[30];
964 964
 			$data['datetime'] = date('Y-m-d H:i:s');
965 965
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
966 966
 			//if (isset($line[37])) $data['last_update'] = $line[37];
967
-		        $data['departure_airport_icao'] = $line[11];
968
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
969
-		        $data['arrival_airport_icao'] = $line[13];
967
+				$data['departure_airport_icao'] = $line[11];
968
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
969
+				$data['arrival_airport_icao'] = $line[13];
970 970
 			$data['frequency'] = $line[4];
971 971
 			$data['type'] = $line[18];
972 972
 			$data['range'] = $line[19];
973 973
 			if (isset($line[35])) $data['info'] = $line[35];
974
-    			$data['id_source'] = $id_source;
975
-	    		//$data['arrival_airport_time'] = ;
976
-	    		if ($line[9] != '') {
977
-	    		    $aircraft_data = explode('/',$line[9]);
978
-	    		    if (isset($aircraft_data[1])) {
979
-	    			$data['aircraft_icao'] = $aircraft_data[1];
980
-	    		    }
981
-        		}
982
-	    		/*
974
+				$data['id_source'] = $id_source;
975
+				//$data['arrival_airport_time'] = ;
976
+				if ($line[9] != '') {
977
+					$aircraft_data = explode('/',$line[9]);
978
+					if (isset($aircraft_data[1])) {
979
+					$data['aircraft_icao'] = $aircraft_data[1];
980
+					}
981
+				}
982
+				/*
983 983
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
984 984
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
985 985
 	    		*/
986
-	    		$data['format_source'] = $value['format'];
986
+				$data['format_source'] = $value['format'];
987 987
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
988 988
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
-    			if ($line[3] === 'PILOT') $SI->add($data);
989
+				if ($line[3] === 'PILOT') $SI->add($data);
990 990
 			elseif ($line[3] === 'ATC') {
991 991
 				//print_r($data);
992 992
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -1007,21 +1007,21 @@  discard block
 block discarded – undo
1007 1007
 					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']);
1008 1008
 				}
1009 1009
 			}
1010
-    			unset($data);
1011
-    		    }
1012
-    		}
1013
-    	    }
1014
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
1015
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1016
-    	    $last_exec[$id]['last'] = time();
1017
-    	} elseif ($value['format'] === 'airwhere' && 
1018
-    	    (
1019
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1020
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1021
-    	    )
1022
-    	) {
1023
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1024
-	    if ($buffer != '') {
1010
+				unset($data);
1011
+				}
1012
+			}
1013
+			}
1014
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
1015
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1016
+			$last_exec[$id]['last'] = time();
1017
+		} elseif ($value['format'] === 'airwhere' && 
1018
+			(
1019
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1020
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1021
+			)
1022
+		) {
1023
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1024
+		if ($buffer != '') {
1025 1025
 		$all_data = simplexml_load_string($buffer);
1026 1026
 		foreach($all_data->children() as $childdata) {
1027 1027
 			$data = array();
@@ -1043,10 +1043,10 @@  discard block
 block discarded – undo
1043 1043
 			$SI->add($data);
1044 1044
 			unset($data);
1045 1045
 		}
1046
-	    }
1047
-	    $Source->deleteOldLocationByType('gs');
1048
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1049
-	    if ($buffer != '') {
1046
+		}
1047
+		$Source->deleteOldLocationByType('gs');
1048
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1049
+		if ($buffer != '') {
1050 1050
 		$all_data = simplexml_load_string($buffer);
1051 1051
 		foreach($all_data->children() as $childdata) {
1052 1052
 			$data = array();
@@ -1064,8 +1064,8 @@  discard block
 block discarded – undo
1064 1064
 			}
1065 1065
 			unset($data);
1066 1066
 		}
1067
-	    }
1068
-	    $last_exec[$id]['last'] = time();
1067
+		}
1068
+		$last_exec[$id]['last'] = time();
1069 1069
 	/*
1070 1070
 	} if ($value['format'] === 'aircraftlistjson') {
1071 1071
 	    print_r($globalSources);
@@ -1073,17 +1073,17 @@  discard block
 block discarded – undo
1073 1073
 	    echo $globalMinFetch;
1074 1074
 	*/
1075 1075
 	} elseif ($value['format'] === 'aircraftlistjson' && 
1076
-	    (
1076
+		(
1077 1077
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1078 1078
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1079
-	    )
1079
+		)
1080 1080
 	) {
1081
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1082
-	    if ($buffer != '') {
1083
-	        $all_data = json_decode($buffer,true);
1081
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
1082
+		if ($buffer != '') {
1083
+			$all_data = json_decode($buffer,true);
1084 1084
 		if (isset($all_data['acList'])) {
1085
-		    $reset = 0;
1086
-		    foreach ($all_data['acList'] as $line) {
1085
+			$reset = 0;
1086
+			foreach ($all_data['acList'] as $line) {
1087 1087
 			$data = array();
1088 1088
 			$data['hex'] = $line['Icao']; // hex
1089 1089
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1106,10 +1106,10 @@  discard block
 block discarded – undo
1106 1106
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1107 1107
 			if (isset($data['latitude'])) $SI->add($data);
1108 1108
 			unset($data);
1109
-		    }
1109
+			}
1110 1110
 		} elseif (is_array($all_data)) {
1111
-		    $reset = 0;
1112
-		    foreach ($all_data as $line) {
1111
+			$reset = 0;
1112
+			foreach ($all_data as $line) {
1113 1113
 			$data = array();
1114 1114
 			$data['hex'] = $line['hex']; // hex
1115 1115
 			$data['ident'] = $line['flight']; // ident
@@ -1129,291 +1129,291 @@  discard block
 block discarded – undo
1129 1129
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1130 1130
 			$SI->add($data);
1131 1131
 			unset($data);
1132
-		    }
1132
+			}
1133 1133
 		}
1134
-	    } elseif ($globalDebug) echo 'No data'."\n";
1135
-    	    //$last_exec['aircraftlistjson'] = time();
1136
-    	    $last_exec[$id]['last'] = time();
1137
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1138
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
1139
-    	    (
1140
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1141
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1142
-    	    )
1143
-    	) {
1144
-	    $buffer = $Common->getData($value['host']);
1145
-	    $all_data = json_decode($buffer,true);
1146
-	    if (isset($all_data['planes'])) {
1134
+		} elseif ($globalDebug) echo 'No data'."\n";
1135
+			//$last_exec['aircraftlistjson'] = time();
1136
+			$last_exec[$id]['last'] = time();
1137
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1138
+		} elseif ($value['format'] === 'planeupdatefaa' && 
1139
+			(
1140
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1141
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1142
+			)
1143
+		) {
1144
+		$buffer = $Common->getData($value['host']);
1145
+		$all_data = json_decode($buffer,true);
1146
+		if (isset($all_data['planes'])) {
1147 1147
 		$reset = 0;
1148 1148
 		foreach ($all_data['planes'] as $key => $line) {
1149
-		    $data = array();
1150
-		    $data['hex'] = $key; // hex
1151
-		    $data['ident'] = $line[3]; // ident
1152
-		    $data['altitude'] = $line[6]; // altitude
1153
-		    $data['speed'] = $line[8]; // speed
1154
-		    $data['heading'] = $line[7]; // heading
1155
-		    $data['latitude'] = $line[4]; // lat
1156
-		    $data['longitude'] = $line[5]; // long
1157
-		    //$data['verticalrate'] = $line[]; // verticale rate
1158
-		    $data['squawk'] = $line[10]; // squawk
1159
-		    $data['emergency'] = ''; // emergency
1160
-		    $data['registration'] = $line[2];
1161
-		    $data['aircraft_icao'] = $line[0];
1162
-		    $deparr = explode('-',$line[1]);
1163
-		    if (count($deparr) === 2) {
1149
+			$data = array();
1150
+			$data['hex'] = $key; // hex
1151
+			$data['ident'] = $line[3]; // ident
1152
+			$data['altitude'] = $line[6]; // altitude
1153
+			$data['speed'] = $line[8]; // speed
1154
+			$data['heading'] = $line[7]; // heading
1155
+			$data['latitude'] = $line[4]; // lat
1156
+			$data['longitude'] = $line[5]; // long
1157
+			//$data['verticalrate'] = $line[]; // verticale rate
1158
+			$data['squawk'] = $line[10]; // squawk
1159
+			$data['emergency'] = ''; // emergency
1160
+			$data['registration'] = $line[2];
1161
+			$data['aircraft_icao'] = $line[0];
1162
+			$deparr = explode('-',$line[1]);
1163
+			if (count($deparr) === 2) {
1164 1164
 			$data['departure_airport_icao'] = $deparr[0];
1165 1165
 			$data['arrival_airport_icao'] = $deparr[1];
1166
-		    }
1167
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1168
-	    	    $data['format_source'] = 'planeupdatefaa';
1169
-    		    $data['id_source'] = $id_source;
1170
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1171
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1172
-		    $SI->add($data);
1173
-		    unset($data);
1166
+			}
1167
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1168
+				$data['format_source'] = 'planeupdatefaa';
1169
+				$data['id_source'] = $id_source;
1170
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1171
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1172
+			$SI->add($data);
1173
+			unset($data);
1174 1174
 		}
1175
-	    }
1176
-	    //$last_exec['planeupdatefaa'] = time();
1177
-	    $last_exec[$id]['last'] = time();
1175
+		}
1176
+		//$last_exec['planeupdatefaa'] = time();
1177
+		$last_exec[$id]['last'] = time();
1178 1178
 	} elseif ($value['format'] === 'opensky' && 
1179
-	    (
1179
+		(
1180 1180
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1181 1181
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1182
-	    )
1182
+		)
1183 1183
 	) {
1184
-	    $buffer = $Common->getData($value['host']);
1185
-	    $all_data = json_decode($buffer,true);
1186
-	    if (isset($all_data['states'])) {
1184
+		$buffer = $Common->getData($value['host']);
1185
+		$all_data = json_decode($buffer,true);
1186
+		if (isset($all_data['states'])) {
1187 1187
 		$reset = 0;
1188 1188
 		foreach ($all_data['states'] as $key => $line) {
1189
-		    $data = array();
1190
-		    $data['hex'] = $line[0]; // hex
1191
-		    $data['ident'] = trim($line[1]); // ident
1192
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1193
-		    $data['speed'] = round($line[9]*1.94384); // speed
1194
-		    $data['heading'] = round($line[10]); // heading
1195
-		    $data['latitude'] = $line[6]; // lat
1196
-		    $data['longitude'] = $line[5]; // long
1197
-		    $data['verticalrate'] = $line[11]; // verticale rate
1198
-		    //$data['squawk'] = $line[10]; // squawk
1199
-		    //$data['emergency'] = ''; // emergency
1200
-		    //$data['registration'] = $line[2];
1201
-		    //$data['aircraft_icao'] = $line[0];
1202
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1203
-		    $data['format_source'] = 'opensky';
1204
-		    $data['id_source'] = $id_source;
1205
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1206
-		    $SI->add($data);
1207
-		    unset($data);
1189
+			$data = array();
1190
+			$data['hex'] = $line[0]; // hex
1191
+			$data['ident'] = trim($line[1]); // ident
1192
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1193
+			$data['speed'] = round($line[9]*1.94384); // speed
1194
+			$data['heading'] = round($line[10]); // heading
1195
+			$data['latitude'] = $line[6]; // lat
1196
+			$data['longitude'] = $line[5]; // long
1197
+			$data['verticalrate'] = $line[11]; // verticale rate
1198
+			//$data['squawk'] = $line[10]; // squawk
1199
+			//$data['emergency'] = ''; // emergency
1200
+			//$data['registration'] = $line[2];
1201
+			//$data['aircraft_icao'] = $line[0];
1202
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1203
+			$data['format_source'] = 'opensky';
1204
+			$data['id_source'] = $id_source;
1205
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1206
+			$SI->add($data);
1207
+			unset($data);
1208 1208
 		}
1209
-	    }
1210
-	    //$last_exec['planeupdatefaa'] = time();
1211
-	    $last_exec[$id]['last'] = time();
1209
+		}
1210
+		//$last_exec['planeupdatefaa'] = time();
1211
+		$last_exec[$id]['last'] = time();
1212 1212
 	} elseif ($value['format'] === 'aircraftjson' && 
1213
-	    (
1213
+		(
1214 1214
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1215 1215
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1216
-	    )
1216
+		)
1217 1217
 	) {
1218
-	    $buffer = $Common->getData($value['host']);
1219
-	    $all_data = json_decode($buffer,true);
1220
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1218
+		$buffer = $Common->getData($value['host']);
1219
+		$all_data = json_decode($buffer,true);
1220
+		if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1221 1221
 		$reset = 0;
1222 1222
 		foreach ($all_data['aircraft'] as $key => $line) {
1223
-		    $data = array();
1224
-		    // add support for ground vehicule with ~ in front of hex
1225
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1226
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1227
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1228
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1229
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1230
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1231
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1232
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1233
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1234
-		    //$data['emergency'] = ''; // emergency
1235
-		    //$data['registration'] = $line[2];
1236
-		    //$data['aircraft_icao'] = $line[0];
1237
-		    $data['datetime'] = date('Y-m-d H:i:s');
1238
-		    $data['format_source'] = 'aircraftjson';
1239
-		    $data['id_source'] = $id_source;
1240
-		    if (isset($value['name']) && $value['name'] != '') {
1241
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1242
-			    else $data['source_name'] = $value['name'];
1243
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1244
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1245
-		    $SI->add($data);
1246
-		    unset($data);
1223
+			$data = array();
1224
+			// add support for ground vehicule with ~ in front of hex
1225
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1226
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1227
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1228
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1229
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1230
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1231
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1232
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1233
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1234
+			//$data['emergency'] = ''; // emergency
1235
+			//$data['registration'] = $line[2];
1236
+			//$data['aircraft_icao'] = $line[0];
1237
+			$data['datetime'] = date('Y-m-d H:i:s');
1238
+			$data['format_source'] = 'aircraftjson';
1239
+			$data['id_source'] = $id_source;
1240
+			if (isset($value['name']) && $value['name'] != '') {
1241
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1242
+				else $data['source_name'] = $value['name'];
1243
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1244
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1245
+			$SI->add($data);
1246
+			unset($data);
1247 1247
 		}
1248
-	    }
1249
-	    //$last_exec['planeupdatefaa'] = time();
1250
-	    $last_exec[$id]['last'] = time();
1248
+		}
1249
+		//$last_exec['planeupdatefaa'] = time();
1250
+		$last_exec[$id]['last'] = time();
1251 1251
 	} elseif ($value['format'] === 'planefinderclient' && 
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($value['host']);
1258
-	    $all_data = json_decode($buffer,true);
1259
-	    if (isset($all_data['aircraft'])) {
1257
+		$buffer = $Common->getData($value['host']);
1258
+		$all_data = json_decode($buffer,true);
1259
+		if (isset($all_data['aircraft'])) {
1260 1260
 		$reset = 0;
1261 1261
 		foreach ($all_data['aircraft'] as $key => $line) {
1262
-		    $data = array();
1263
-		    $data['hex'] = $key; // hex
1264
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1265
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1266
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1267
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1268
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1269
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1270
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1271
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1272
-		    //$data['emergency'] = ''; // emergency
1273
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1274
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1275
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1276
-		    $data['format_source'] = 'planefinderclient';
1277
-		    $data['id_source'] = $id_source;
1278
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1279
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1280
-		    $SI->add($data);
1281
-		    unset($data);
1262
+			$data = array();
1263
+			$data['hex'] = $key; // hex
1264
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1265
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1266
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1267
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1268
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1269
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1270
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1271
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1272
+			//$data['emergency'] = ''; // emergency
1273
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1274
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1275
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1276
+			$data['format_source'] = 'planefinderclient';
1277
+			$data['id_source'] = $id_source;
1278
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1279
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1280
+			$SI->add($data);
1281
+			unset($data);
1282 1282
 		}
1283
-	    }
1284
-	    $last_exec[$id]['last'] = time();
1283
+		}
1284
+		$last_exec[$id]['last'] = time();
1285 1285
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1286 1286
 	} elseif ($value['format'] === 'fr24json' && 
1287
-	    (
1287
+		(
1288 1288
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1289 1289
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1290
-	    )
1290
+		)
1291 1291
 	) {
1292
-	    //$buffer = $Common->getData($hosts[$id]);
1293
-	    $buffer = $Common->getData($value['host']);
1294
-	    $all_data = json_decode($buffer,true);
1295
-	    if (!empty($all_data)) $reset = 0;
1296
-	    foreach ($all_data as $key => $line) {
1292
+		//$buffer = $Common->getData($hosts[$id]);
1293
+		$buffer = $Common->getData($value['host']);
1294
+		$all_data = json_decode($buffer,true);
1295
+		if (!empty($all_data)) $reset = 0;
1296
+		foreach ($all_data as $key => $line) {
1297 1297
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1298
-		    $data = array();
1299
-		    $data['hex'] = $line[0];
1300
-		    $data['ident'] = $line[16]; //$line[13]
1301
-	    	    $data['altitude'] = $line[4]; // altitude
1302
-	    	    $data['speed'] = $line[5]; // speed
1303
-	    	    $data['heading'] = $line[3]; // heading
1304
-	    	    $data['latitude'] = $line[1]; // lat
1305
-	    	    $data['longitude'] = $line[2]; // long
1306
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1307
-	    	    $data['squawk'] = $line[6]; // squawk
1308
-	    	    $data['aircraft_icao'] = $line[8];
1309
-	    	    $data['registration'] = $line[9];
1310
-		    $data['departure_airport_iata'] = $line[11];
1311
-		    $data['arrival_airport_iata'] = $line[12];
1312
-	    	    $data['emergency'] = ''; // emergency
1313
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1314
-	    	    $data['format_source'] = 'fr24json';
1315
-    		    $data['id_source'] = $id_source;
1316
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1317
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1318
-		    $SI->add($data);
1319
-		    unset($data);
1298
+			$data = array();
1299
+			$data['hex'] = $line[0];
1300
+			$data['ident'] = $line[16]; //$line[13]
1301
+				$data['altitude'] = $line[4]; // altitude
1302
+				$data['speed'] = $line[5]; // speed
1303
+				$data['heading'] = $line[3]; // heading
1304
+				$data['latitude'] = $line[1]; // lat
1305
+				$data['longitude'] = $line[2]; // long
1306
+				$data['verticalrate'] = $line[15]; // verticale rate
1307
+				$data['squawk'] = $line[6]; // squawk
1308
+				$data['aircraft_icao'] = $line[8];
1309
+				$data['registration'] = $line[9];
1310
+			$data['departure_airport_iata'] = $line[11];
1311
+			$data['arrival_airport_iata'] = $line[12];
1312
+				$data['emergency'] = ''; // emergency
1313
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1314
+				$data['format_source'] = 'fr24json';
1315
+				$data['id_source'] = $id_source;
1316
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1317
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1318
+			$SI->add($data);
1319
+			unset($data);
1320 1320
 		}
1321
-	    }
1322
-	    //$last_exec['fr24json'] = time();
1323
-	    $last_exec[$id]['last'] = time();
1321
+		}
1322
+		//$last_exec['fr24json'] = time();
1323
+		$last_exec[$id]['last'] = time();
1324 1324
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1325 1325
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1326
-	    (
1326
+		(
1327 1327
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1328 1328
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1329
-	    )
1329
+		)
1330 1330
 	) {
1331
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1332
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1333
-	    //echo $buffer;
1334
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1335
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1336
-	    $all_data = json_decode($buffer,true);
1337
-	    if (json_last_error() != JSON_ERROR_NONE) {
1331
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1332
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1333
+		//echo $buffer;
1334
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1335
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1336
+		$all_data = json_decode($buffer,true);
1337
+		if (json_last_error() != JSON_ERROR_NONE) {
1338 1338
 		die(json_last_error_msg());
1339
-	    }
1340
-	    if (isset($all_data['mrkrs'])) {
1339
+		}
1340
+		if (isset($all_data['mrkrs'])) {
1341 1341
 		$reset = 0;
1342 1342
 		foreach ($all_data['mrkrs'] as $key => $line) {
1343
-		    if (isset($line['inf'])) {
1343
+			if (isset($line['inf'])) {
1344 1344
 			$data = array();
1345 1345
 			$data['hex'] = $line['inf']['ia'];
1346 1346
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1347
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1348
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1349
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1350
-	    		$data['latitude'] = $line['pt'][0]; // lat
1351
-	    		$data['longitude'] = $line['pt'][1]; // long
1352
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1353
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1354
-	    		//$data['aircraft_icao'] = $line[8];
1355
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1347
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1348
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1349
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1350
+				$data['latitude'] = $line['pt'][0]; // lat
1351
+				$data['longitude'] = $line['pt'][1]; // long
1352
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1353
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1354
+				//$data['aircraft_icao'] = $line[8];
1355
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1356 1356
 			//$data['departure_airport_iata'] = $line[11];
1357 1357
 			//$data['arrival_airport_iata'] = $line[12];
1358
-	    		//$data['emergency'] = ''; // emergency
1358
+				//$data['emergency'] = ''; // emergency
1359 1359
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1360
-	    		$data['format_source'] = 'radarvirtueljson';
1361
-    			$data['id_source'] = $id_source;
1360
+				$data['format_source'] = 'radarvirtueljson';
1361
+				$data['id_source'] = $id_source;
1362 1362
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1363 1363
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1364 1364
 			$SI->add($data);
1365 1365
 			unset($data);
1366
-		    }
1366
+			}
1367 1367
 		}
1368
-	    }
1369
-	    //$last_exec['radarvirtueljson'] = time();
1370
-	    $last_exec[$id]['last'] = time();
1368
+		}
1369
+		//$last_exec['radarvirtueljson'] = time();
1370
+		$last_exec[$id]['last'] = time();
1371 1371
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1372 1372
 	} elseif ($value['format'] === 'pirepsjson' && 
1373
-	    (
1373
+		(
1374 1374
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1375 1375
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1376
-	    )
1376
+		)
1377 1377
 	) {
1378
-	    //$buffer = $Common->getData($hosts[$id]);
1379
-	    $buffer = $Common->getData($value['host'].'?'.time());
1380
-	    $all_data = json_decode(utf8_encode($buffer),true);
1378
+		//$buffer = $Common->getData($hosts[$id]);
1379
+		$buffer = $Common->getData($value['host'].'?'.time());
1380
+		$all_data = json_decode(utf8_encode($buffer),true);
1381 1381
 	    
1382
-	    if (isset($all_data['pireps'])) {
1382
+		if (isset($all_data['pireps'])) {
1383 1383
 		$reset = 0;
1384
-	        foreach ($all_data['pireps'] as $line) {
1385
-		    $data = array();
1386
-		    $data['id'] = $line['id'];
1387
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1388
-		    $data['ident'] = $line['callsign']; // ident
1389
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1390
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1391
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1392
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1393
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1394
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1395
-		    $data['latitude'] = $line['lat']; // lat
1396
-		    $data['longitude'] = $line['lon']; // long
1397
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1398
-		    //$data['squawk'] = $line['squawk']; // squawk
1399
-		    //$data['emergency'] = ''; // emergency
1400
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1401
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1402
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1403
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1404
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1405
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1406
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1407
-		    else $data['info'] = '';
1408
-		    $data['format_source'] = 'pireps';
1409
-    		    $data['id_source'] = $id_source;
1410
-		    $data['datetime'] = date('Y-m-d H:i:s');
1411
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1412
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1413
-		    if ($line['icon'] === 'plane') {
1384
+			foreach ($all_data['pireps'] as $line) {
1385
+			$data = array();
1386
+			$data['id'] = $line['id'];
1387
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1388
+			$data['ident'] = $line['callsign']; // ident
1389
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1390
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1391
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1392
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1393
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1394
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1395
+			$data['latitude'] = $line['lat']; // lat
1396
+			$data['longitude'] = $line['lon']; // long
1397
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1398
+			//$data['squawk'] = $line['squawk']; // squawk
1399
+			//$data['emergency'] = ''; // emergency
1400
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1401
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1402
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1403
+			//$data['arrival_airport_time'] = $line['arrtime'];
1404
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1405
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1406
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1407
+			else $data['info'] = '';
1408
+			$data['format_source'] = 'pireps';
1409
+				$data['id_source'] = $id_source;
1410
+			$data['datetime'] = date('Y-m-d H:i:s');
1411
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1412
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1413
+			if ($line['icon'] === 'plane') {
1414 1414
 			$SI->add($data);
1415
-		    //    print_r($data);
1416
-    		    } elseif ($line['icon'] === 'ct') {
1415
+			//    print_r($data);
1416
+				} elseif ($line['icon'] === 'ct') {
1417 1417
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1418 1418
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1419 1419
 			$typec = substr($data['ident'],-3);
@@ -1428,209 +1428,209 @@  discard block
 block discarded – undo
1428 1428
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1429 1429
 			else $data['type'] = 'Observer';
1430 1430
 			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']);
1431
-		    }
1432
-		    unset($data);
1431
+			}
1432
+			unset($data);
1433 1433
 		}
1434
-	    }
1435
-	    //$last_exec['pirepsjson'] = time();
1436
-	    $last_exec[$id]['last'] = time();
1434
+		}
1435
+		//$last_exec['pirepsjson'] = time();
1436
+		$last_exec[$id]['last'] = time();
1437 1437
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1438 1438
 	} elseif ($value['format'] === 'phpvmacars' && 
1439
-	    (
1439
+		(
1440 1440
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1441 1441
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1442
-	    )
1442
+		)
1443 1443
 	) {
1444
-	    //$buffer = $Common->getData($hosts[$id]);
1445
-	    if ($globalDebug) echo 'Get Data...'."\n";
1446
-	    $buffer = $Common->getData($value['host']);
1447
-	    $all_data = json_decode($buffer,true);
1448
-	    if ($buffer != '' && is_array($all_data)) {
1444
+		//$buffer = $Common->getData($hosts[$id]);
1445
+		if ($globalDebug) echo 'Get Data...'."\n";
1446
+		$buffer = $Common->getData($value['host']);
1447
+		$all_data = json_decode($buffer,true);
1448
+		if ($buffer != '' && is_array($all_data)) {
1449 1449
 		$reset = 0;
1450 1450
 		foreach ($all_data as $line) {
1451
-	    	    $data = array();
1452
-	    	    //$data['id'] = $line['id']; // id not usable
1453
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1454
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1455
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1456
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1457
-	    	    $data['ident'] = $line['flightnum']; // ident
1458
-	    	    $data['altitude'] = $line['alt']; // altitude
1459
-	    	    $data['speed'] = $line['gs']; // speed
1460
-	    	    $data['heading'] = $line['heading']; // heading
1461
-	    	    $data['latitude'] = $line['lat']; // lat
1462
-	    	    $data['longitude'] = $line['lng']; // long
1463
-	    	    $data['verticalrate'] = ''; // verticale rate
1464
-	    	    $data['squawk'] = ''; // squawk
1465
-	    	    $data['emergency'] = ''; // emergency
1466
-	    	    //$data['datetime'] = $line['lastupdate'];
1467
-	    	    //$data['last_update'] = $line['lastupdate'];
1468
-	    	    if (isset($value['timezone'])) {
1469
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1470
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1471
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1472
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1473
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1474
-	    	    $data['departure_airport_time'] = $line['deptime'];
1475
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1476
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1477
-    		    if (isset($line['registration'])) {
1478
-    			$data['registration'] = $line['registration'];
1479
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1480
-    		    } else $data['registration'] = $line['aircraft'];
1481
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1483
-		    if (isset($line['aircraftname'])) {
1451
+				$data = array();
1452
+				//$data['id'] = $line['id']; // id not usable
1453
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1454
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1455
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1456
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1457
+				$data['ident'] = $line['flightnum']; // ident
1458
+				$data['altitude'] = $line['alt']; // altitude
1459
+				$data['speed'] = $line['gs']; // speed
1460
+				$data['heading'] = $line['heading']; // heading
1461
+				$data['latitude'] = $line['lat']; // lat
1462
+				$data['longitude'] = $line['lng']; // long
1463
+				$data['verticalrate'] = ''; // verticale rate
1464
+				$data['squawk'] = ''; // squawk
1465
+				$data['emergency'] = ''; // emergency
1466
+				//$data['datetime'] = $line['lastupdate'];
1467
+				//$data['last_update'] = $line['lastupdate'];
1468
+				if (isset($value['timezone'])) {
1469
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1470
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1471
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1472
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1473
+				$data['departure_airport_icao'] = $line['depicao'];
1474
+				$data['departure_airport_time'] = $line['deptime'];
1475
+				$data['arrival_airport_icao'] = $line['arricao'];
1476
+				$data['arrival_airport_time'] = $line['arrtime'];
1477
+				if (isset($line['registration'])) {
1478
+				$data['registration'] = $line['registration'];
1479
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1480
+				} else $data['registration'] = $line['aircraft'];
1481
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1483
+			if (isset($line['aircraftname'])) {
1484 1484
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1485 1485
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1486
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1487
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1488
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1489
-	    		else {
1490
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1491
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1492
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1493
-	    		}
1494
-	    	    }
1495
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1496
-    		    $data['id_source'] = $id_source;
1497
-	    	    $data['format_source'] = 'phpvmacars';
1498
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1499
-		    $SI->add($data);
1500
-		    unset($data);
1486
+				$aircraft_data = explode('-',$line['aircraftname']);
1487
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1488
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1489
+				else {
1490
+					$aircraft_data = explode(' ',$line['aircraftname']);
1491
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1492
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1493
+				}
1494
+				}
1495
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1496
+				$data['id_source'] = $id_source;
1497
+				$data['format_source'] = 'phpvmacars';
1498
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1499
+			$SI->add($data);
1500
+			unset($data);
1501 1501
 		}
1502 1502
 		if ($globalDebug) echo 'No more data...'."\n";
1503 1503
 		unset($buffer);
1504 1504
 		unset($all_data);
1505
-	    }
1506
-	    //$last_exec['phpvmacars'] = time();
1507
-	    $last_exec[$id]['last'] = time();
1505
+		}
1506
+		//$last_exec['phpvmacars'] = time();
1507
+		$last_exec[$id]['last'] = time();
1508 1508
 	} elseif ($value['format'] === 'vaos' && 
1509
-	    (
1509
+		(
1510 1510
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1511 1511
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1512
-	    )
1512
+		)
1513 1513
 	) {
1514
-	    //$buffer = $Common->getData($hosts[$id]);
1515
-	    if ($globalDebug) echo 'Get Data...'."\n";
1516
-	    $buffer = $Common->getData($value['host']);
1517
-	    $all_data = json_decode($buffer,true);
1518
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1514
+		//$buffer = $Common->getData($hosts[$id]);
1515
+		if ($globalDebug) echo 'Get Data...'."\n";
1516
+		$buffer = $Common->getData($value['host']);
1517
+		$all_data = json_decode($buffer,true);
1518
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1519 1519
 		$reset = 0;
1520 1520
 		foreach ($all_data['ACARSData'] as $line) {
1521
-		    //print_r($line);
1522
-	    	    $data = array();
1523
-	    	    //$data['id'] = $line['id']; // id not usable
1524
-	    	    $data['id'] = $line['id'];
1525
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1526
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1527
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1528
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1529
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1530
-	    	    $data['altitude'] = $line['altitude']; // altitude
1531
-	    	    $data['speed'] = $line['groundspeed']; // speed
1532
-	    	    $data['heading'] = $line['heading']; // heading
1533
-	    	    $data['latitude'] = $line['lat']; // lat
1534
-	    	    $data['longitude'] = $line['lon']; // long
1535
-	    	    //$data['verticalrate'] = ''; // verticale rate
1536
-	    	    //$data['squawk'] = ''; // squawk
1537
-	    	    //$data['emergency'] = ''; // emergency
1538
-	    	    if (isset($value['timezone'])) {
1539
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1540
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1541
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1542
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1521
+			//print_r($line);
1522
+				$data = array();
1523
+				//$data['id'] = $line['id']; // id not usable
1524
+				$data['id'] = $line['id'];
1525
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1526
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1527
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1528
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1529
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1530
+				$data['altitude'] = $line['altitude']; // altitude
1531
+				$data['speed'] = $line['groundspeed']; // speed
1532
+				$data['heading'] = $line['heading']; // heading
1533
+				$data['latitude'] = $line['lat']; // lat
1534
+				$data['longitude'] = $line['lon']; // long
1535
+				//$data['verticalrate'] = ''; // verticale rate
1536
+				//$data['squawk'] = ''; // squawk
1537
+				//$data['emergency'] = ''; // emergency
1538
+				if (isset($value['timezone'])) {
1539
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1540
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1541
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1542
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1543 1543
 	    	    
1544
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1545
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1546
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1547
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1548
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1544
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1545
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1546
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1547
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1548
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1549 1549
 
1550
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1551
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1552
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1550
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1551
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1552
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1553 1553
 
1554
-    		    $data['id_source'] = $id_source;
1555
-	    	    $data['format_source'] = 'vaos';
1556
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1557
-		    $SI->add($data);
1558
-		    unset($data);
1554
+				$data['id_source'] = $id_source;
1555
+				$data['format_source'] = 'vaos';
1556
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1557
+			$SI->add($data);
1558
+			unset($data);
1559 1559
 		}
1560 1560
 		if ($globalDebug) echo 'No more data...'."\n";
1561 1561
 		unset($buffer);
1562 1562
 		unset($all_data);
1563
-	    }
1564
-	    //$last_exec['phpvmacars'] = time();
1565
-	    $last_exec[$id]['last'] = time();
1563
+		}
1564
+		//$last_exec['phpvmacars'] = time();
1565
+		$last_exec[$id]['last'] = time();
1566 1566
 	} elseif ($value['format'] === 'vam' && 
1567
-	    (
1567
+		(
1568 1568
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1569 1569
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1570
-	    )
1570
+		)
1571 1571
 	) {
1572
-	    //$buffer = $Common->getData($hosts[$id]);
1573
-	    if ($globalDebug) echo 'Get Data...'."\n";
1574
-	    $buffer = $Common->getData($value['host']);
1575
-	    $all_data = json_decode($buffer,true);
1576
-	    if ($buffer != '' && is_array($all_data)) {
1572
+		//$buffer = $Common->getData($hosts[$id]);
1573
+		if ($globalDebug) echo 'Get Data...'."\n";
1574
+		$buffer = $Common->getData($value['host']);
1575
+		$all_data = json_decode($buffer,true);
1576
+		if ($buffer != '' && is_array($all_data)) {
1577 1577
 		$reset = 0;
1578 1578
 		foreach ($all_data as $line) {
1579
-	    	    $data = array();
1580
-	    	    //$data['id'] = $line['id']; // id not usable
1581
-	    	    $data['id'] = trim($line['flight_id']);
1582
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1583
-	    	    $data['pilot_name'] = $line['pilot_name'];
1584
-	    	    $data['pilot_id'] = $line['pilot_id'];
1585
-	    	    $data['ident'] = trim($line['callsign']); // ident
1586
-	    	    $data['altitude'] = $line['altitude']; // altitude
1587
-	    	    $data['speed'] = $line['gs']; // speed
1588
-	    	    $data['heading'] = $line['heading']; // heading
1589
-	    	    $data['latitude'] = $line['latitude']; // lat
1590
-	    	    $data['longitude'] = $line['longitude']; // long
1591
-	    	    $data['verticalrate'] = ''; // verticale rate
1592
-	    	    $data['squawk'] = ''; // squawk
1593
-	    	    $data['emergency'] = ''; // emergency
1594
-	    	    //$data['datetime'] = $line['lastupdate'];
1595
-	    	    $data['last_update'] = $line['last_update'];
1596
-		    $data['datetime'] = date('Y-m-d H:i:s');
1597
-	    	    $data['departure_airport_icao'] = $line['departure'];
1598
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1599
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1600
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1601
-    		    //$data['registration'] = $line['aircraft'];
1602
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1603
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1604
-    		    $data['id_source'] = $id_source;
1605
-	    	    $data['format_source'] = 'vam';
1606
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1607
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1608
-		    $SI->add($data);
1609
-		    unset($data);
1579
+				$data = array();
1580
+				//$data['id'] = $line['id']; // id not usable
1581
+				$data['id'] = trim($line['flight_id']);
1582
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1583
+				$data['pilot_name'] = $line['pilot_name'];
1584
+				$data['pilot_id'] = $line['pilot_id'];
1585
+				$data['ident'] = trim($line['callsign']); // ident
1586
+				$data['altitude'] = $line['altitude']; // altitude
1587
+				$data['speed'] = $line['gs']; // speed
1588
+				$data['heading'] = $line['heading']; // heading
1589
+				$data['latitude'] = $line['latitude']; // lat
1590
+				$data['longitude'] = $line['longitude']; // long
1591
+				$data['verticalrate'] = ''; // verticale rate
1592
+				$data['squawk'] = ''; // squawk
1593
+				$data['emergency'] = ''; // emergency
1594
+				//$data['datetime'] = $line['lastupdate'];
1595
+				$data['last_update'] = $line['last_update'];
1596
+			$data['datetime'] = date('Y-m-d H:i:s');
1597
+				$data['departure_airport_icao'] = $line['departure'];
1598
+				//$data['departure_airport_time'] = $line['departure_time'];
1599
+				$data['arrival_airport_icao'] = $line['arrival'];
1600
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1601
+				//$data['registration'] = $line['aircraft'];
1602
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1603
+				$data['aircraft_icao'] = $line['plane_type'];
1604
+				$data['id_source'] = $id_source;
1605
+				$data['format_source'] = 'vam';
1606
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1607
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1608
+			$SI->add($data);
1609
+			unset($data);
1610 1610
 		}
1611 1611
 		if ($globalDebug) echo 'No more data...'."\n";
1612 1612
 		unset($buffer);
1613 1613
 		unset($all_data);
1614
-	    }
1615
-	    //$last_exec['phpvmacars'] = time();
1616
-	    $last_exec[$id]['last'] = time();
1614
+		}
1615
+		//$last_exec['phpvmacars'] = time();
1616
+		$last_exec[$id]['last'] = time();
1617 1617
 	} elseif ($value['format'] === 'blitzortung' && 
1618
-	    (
1618
+		(
1619 1619
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1620 1620
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1621
-	    )
1621
+		)
1622 1622
 	) {
1623
-	    //$buffer = $Common->getData($hosts[$id]);
1624
-	    if ($globalDebug) echo 'Get Data...'."\n";
1625
-	    $buffer = $Common->getData($value['host']);
1626
-	    $all_data = json_decode($buffer,true);
1627
-	    if ($buffer != '') {
1623
+		//$buffer = $Common->getData($hosts[$id]);
1624
+		if ($globalDebug) echo 'Get Data...'."\n";
1625
+		$buffer = $Common->getData($value['host']);
1626
+		$all_data = json_decode($buffer,true);
1627
+		if ($buffer != '') {
1628 1628
 		$Source->deleteLocationBySource('blitzortung');
1629 1629
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1630 1630
 		$buffer = explode('\n',$buffer);
1631 1631
 		foreach ($buffer as $buffer_line) {
1632
-		    $line = json_decode($buffer_line,true);
1633
-		    if (isset($line['time'])) {
1632
+			$line = json_decode($buffer_line,true);
1633
+			if (isset($line['time'])) {
1634 1634
 			$data = array();
1635 1635
 			$data['altitude'] = $line['alt']; // altitude
1636 1636
 			$data['latitude'] = $line['lat']; // lat
@@ -1642,92 +1642,92 @@  discard block
 block discarded – undo
1642 1642
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1643 1643
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1644 1644
 			unset($data);
1645
-		    }
1645
+			}
1646 1646
 		}
1647 1647
 		if ($globalDebug) echo 'No more data...'."\n";
1648 1648
 		unset($buffer);
1649
-	    }
1650
-	    $last_exec[$id]['last'] = time();
1649
+		}
1650
+		$last_exec[$id]['last'] = time();
1651 1651
 	} elseif ($value['format'] === 'acarsjson') {
1652
-        $arr = $httpfeeds;
1653
-        $w = $e = null;
1654
-        if (isset($arr[$id])) {
1655
-            $nn = stream_select($arr,$w,$e,$timeout);
1656
-            if ($nn > 0) {
1657
-                foreach ($httpfeeds as $feed) {
1658
-                    $buffer = stream_get_line($feed,2000,"\n");
1659
-                    if ($buffer === FALSE) {
1660
-                        connect_all($globalSources);
1661
-                    }
1662
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1663
-                    $buffer = explode('\n',$buffer);
1664
-                    foreach ($buffer as $line) {
1665
-                        if ($line != '') {
1666
-                            $line = json_decode($line, true);
1667
-                            if (!empty($line)) {
1668
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1669
-                                $ACARS->deleteLiveAcarsData();
1670
-                            }
1671
-                        }
1672
-                    }
1673
-                }
1674
-            } else {
1675
-                $format = $value['format'];
1676
-                if (isset($tt[$format])) $tt[$format]++;
1677
-                else $tt[$format] = 0;
1678
-                if ($tt[$format] > 30) {
1679
-                    if ($globalDebug) echo 'Reconnect...'."\n";
1680
-                    sleep(2);
1681
-                    //$sourceeen[] = $value;
1682
-                    //connect_all($sourceeen);
1683
-                    //$sourceeen = array();
1684
-                    connect_all($globalSources);
1685
-                }
1686
-            }
1687
-        }
1652
+		$arr = $httpfeeds;
1653
+		$w = $e = null;
1654
+		if (isset($arr[$id])) {
1655
+			$nn = stream_select($arr,$w,$e,$timeout);
1656
+			if ($nn > 0) {
1657
+				foreach ($httpfeeds as $feed) {
1658
+					$buffer = stream_get_line($feed,2000,"\n");
1659
+					if ($buffer === FALSE) {
1660
+						connect_all($globalSources);
1661
+					}
1662
+					$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1663
+					$buffer = explode('\n',$buffer);
1664
+					foreach ($buffer as $line) {
1665
+						if ($line != '') {
1666
+							$line = json_decode($line, true);
1667
+							if (!empty($line)) {
1668
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1669
+								$ACARS->deleteLiveAcarsData();
1670
+							}
1671
+						}
1672
+					}
1673
+				}
1674
+			} else {
1675
+				$format = $value['format'];
1676
+				if (isset($tt[$format])) $tt[$format]++;
1677
+				else $tt[$format] = 0;
1678
+				if ($tt[$format] > 30) {
1679
+					if ($globalDebug) echo 'Reconnect...'."\n";
1680
+					sleep(2);
1681
+					//$sourceeen[] = $value;
1682
+					//connect_all($sourceeen);
1683
+					//$sourceeen = array();
1684
+					connect_all($globalSources);
1685
+				}
1686
+			}
1687
+		}
1688 1688
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1689 1689
 	} 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'] === 'acarsjsonudp' || $value['format'] === 'acarssbs3' || $value['format'] === 'ais' || $value['format'] === 'vrstcp') {
1690
-	    //$last_exec[$id]['last'] = time();
1691
-	    //$read = array( $sockets[$id] );
1692
-	    $read = $sockets;
1693
-	    $write = NULL;
1694
-	    $e = NULL;
1695
-	    $n = socket_select($read, $write, $e, $timeout);
1696
-	    if ($e != NULL) var_dump($e);
1697
-	    if ($n > 0) {
1690
+		//$last_exec[$id]['last'] = time();
1691
+		//$read = array( $sockets[$id] );
1692
+		$read = $sockets;
1693
+		$write = NULL;
1694
+		$e = NULL;
1695
+		$n = socket_select($read, $write, $e, $timeout);
1696
+		if ($e != NULL) var_dump($e);
1697
+		if ($n > 0) {
1698 1698
 		$reset = 0;
1699 1699
 		foreach ($read as $nb => $r) {
1700
-		    //$value = $formats[$nb];
1701
-		    $format = $globalSources[$nb]['format'];
1702
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1700
+			//$value = $formats[$nb];
1701
+			$format = $globalSources[$nb]['format'];
1702
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1703 1703
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1704
-		    } elseif ($format === 'vrstcp') {
1704
+			} elseif ($format === 'vrstcp') {
1705 1705
 			$buffer = @socket_read($r, 6000);
1706
-		    } else {
1706
+			} else {
1707 1707
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1708
-		    }
1709
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1710
-		    //echo $buffer."\n";
1711
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1712
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1713
-		    $error = false;
1714
-		    //$SI::del();
1715
-		    if ($buffer !== FALSE) {
1708
+			}
1709
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1710
+			//echo $buffer."\n";
1711
+			// lets play nice and handle signals such as ctrl-c/kill properly
1712
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1713
+			$error = false;
1714
+			//$SI::del();
1715
+			if ($buffer !== FALSE) {
1716 1716
 			if ($format === 'vrstcp') {
1717
-			    $buffer = explode('},{',$buffer);
1717
+				$buffer = explode('},{',$buffer);
1718 1718
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1719
-		    }
1720
-		    // SBS format is CSV format
1721
-		    if ($buffer !== FALSE && $buffer !== '') {
1719
+			}
1720
+			// SBS format is CSV format
1721
+			if ($buffer !== FALSE && $buffer !== '') {
1722 1722
 			$tt[$format] = 0;
1723 1723
 			if ($format === 'acarssbs3') {
1724
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1725
-			    $ACARS->add(trim($buffer));
1726
-			    $ACARS->deleteLiveAcarsData();
1724
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1725
+				$ACARS->add(trim($buffer));
1726
+				$ACARS->deleteLiveAcarsData();
1727 1727
 			} elseif ($format === 'raw') {
1728
-			    // AVR format
1729
-			    $data = $SBS->parse($buffer);
1730
-			    if (is_array($data)) {
1728
+				// AVR format
1729
+				$data = $SBS->parse($buffer);
1730
+				if (is_array($data)) {
1731 1731
 				//if (!empty($data)) print_r($data);
1732 1732
 				$data['datetime'] = date('Y-m-d H:i:s');
1733 1733
 				$data['format_source'] = 'raw';
@@ -1737,39 +1737,39 @@  discard block
 block discarded – undo
1737 1737
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1738 1738
 				$SI->add($data);
1739 1739
 				unset($data);
1740
-			    }
1740
+				}
1741 1741
 			} elseif ($format === 'ais') {
1742
-			    $ais_data = $AIS->parse_line(trim($buffer));
1743
-			    $data = array();
1744
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1745
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1746
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1747
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1748
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1749
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1750
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1751
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1752
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1753
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1754
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1755
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1756
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1757
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1758
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1759
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1742
+				$ais_data = $AIS->parse_line(trim($buffer));
1743
+				$data = array();
1744
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1745
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1746
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1747
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1748
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1749
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1750
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1751
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1752
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1753
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1754
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1755
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1756
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1757
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1758
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1759
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1760 1760
 
1761
-			    if (isset($ais_data['timestamp'])) {
1761
+				if (isset($ais_data['timestamp'])) {
1762 1762
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1763
-			    } else {
1763
+				} else {
1764 1764
 				$data['datetime'] = date('Y-m-d H:i:s');
1765
-			    }
1766
-			    $data['format_source'] = 'aisnmea';
1767
-    			    $data['id_source'] = $id_source;
1768
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1769
-			    unset($data);
1770
-                        } elseif ($format === 'flightgearsp') {
1771
-                    	    //echo $buffer."\n";
1772
-                    	    if (strlen($buffer) > 5) {
1765
+				}
1766
+				$data['format_source'] = 'aisnmea';
1767
+					$data['id_source'] = $id_source;
1768
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1769
+				unset($data);
1770
+						} elseif ($format === 'flightgearsp') {
1771
+							//echo $buffer."\n";
1772
+							if (strlen($buffer) > 5) {
1773 1773
 				$line = explode(',',$buffer);
1774 1774
 				$data = array();
1775 1775
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1786,47 +1786,47 @@  discard block
 block discarded – undo
1786 1786
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1787 1787
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1788 1788
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1789
-			    }
1790
-                        } elseif ($format === 'acars') {
1791
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1792
-			    $ACARS->add(trim($buffer));
1793
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1794
-			    $ACARS->deleteLiveAcarsData();
1789
+				}
1790
+						} elseif ($format === 'acars') {
1791
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1792
+				$ACARS->add(trim($buffer));
1793
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1794
+				$ACARS->deleteLiveAcarsData();
1795 1795
 			} elseif ($format === 'acarsjsonudp') {
1796
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1797
-                            $line = json_decode(trim($buffer), true);
1798
-                            if (!empty($line)) {
1796
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1797
+							$line = json_decode(trim($buffer), true);
1798
+							if (!empty($line)) {
1799 1799
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1800
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1801
-                                $ACARS->deleteLiveAcarsData();
1802
-                            }
1803
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1800
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1801
+								$ACARS->deleteLiveAcarsData();
1802
+							}
1803
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1804 1804
 			} elseif ($format === 'flightgearmp') {
1805
-			    if (substr($buffer,0,1) != '#') {
1805
+				if (substr($buffer,0,1) != '#') {
1806 1806
 				$data = array();
1807 1807
 				//echo $buffer."\n";
1808 1808
 				$line = explode(' ',$buffer);
1809 1809
 				if (count($line) === 11) {
1810
-				    $userserver = explode('@',$line[0]);
1811
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1812
-				    $data['ident'] = $userserver[0];
1813
-				    $data['registration'] = $userserver[0];
1814
-				    $data['latitude'] = $line[4];
1815
-				    $data['longitude'] = $line[5];
1816
-				    $data['altitude'] = $line[6];
1817
-				    $data['datetime'] = date('Y-m-d H:i:s');
1818
-				    $aircraft_type = $line[10];
1819
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1820
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1821
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1822
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1810
+					$userserver = explode('@',$line[0]);
1811
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1812
+					$data['ident'] = $userserver[0];
1813
+					$data['registration'] = $userserver[0];
1814
+					$data['latitude'] = $line[4];
1815
+					$data['longitude'] = $line[5];
1816
+					$data['altitude'] = $line[6];
1817
+					$data['datetime'] = date('Y-m-d H:i:s');
1818
+					$aircraft_type = $line[10];
1819
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1820
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1821
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1822
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1823
+				}
1823 1824
 				}
1824
-			    }
1825 1825
 			} elseif ($format === 'beast') {
1826
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1827
-			    die;
1826
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1827
+				die;
1828 1828
 			} elseif ($format === 'vrstcp') {
1829
-			    foreach($buffer as $all_data) {
1829
+				foreach($buffer as $all_data) {
1830 1830
 				$line = json_decode('{'.$all_data.'}',true);
1831 1831
 				$data = array();
1832 1832
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1846,158 +1846,158 @@  discard block
 block discarded – undo
1846 1846
 				*/
1847 1847
 				$data['datetime'] = date('Y-m-d H:i:s');
1848 1848
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1849
-		    		$data['format_source'] = 'vrstcp';
1849
+					$data['format_source'] = 'vrstcp';
1850 1850
 				$data['id_source'] = $id_source;
1851 1851
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1852 1852
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1853 1853
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1854 1854
 				unset($data);
1855
-			    }
1855
+				}
1856 1856
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1857
-			    $line = explode("\t", $buffer);
1858
-			    for($k = 0; $k < count($line); $k=$k+2) {
1857
+				$line = explode("\t", $buffer);
1858
+				for($k = 0; $k < count($line); $k=$k+2) {
1859 1859
 				$key = $line[$k];
1860
-			        $lined[$key] = $line[$k+1];
1861
-			    }
1862
-    			    if (count($lined) > 3) {
1863
-    				$data['hex'] = $lined['hexid'];
1864
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1865
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1866
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1867
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1868
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1869
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1870
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1871
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1872
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1873
-    				$data['id_source'] = $id_source;
1874
-    				$data['format_source'] = 'tsv';
1875
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1876
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1860
+					$lined[$key] = $line[$k+1];
1861
+				}
1862
+					if (count($lined) > 3) {
1863
+					$data['hex'] = $lined['hexid'];
1864
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1865
+					$data['datetime'] = date('Y-m-d H:i:s');;
1866
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1867
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1868
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1869
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1870
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1871
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1872
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1873
+					$data['id_source'] = $id_source;
1874
+					$data['format_source'] = 'tsv';
1875
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1876
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1877 1877
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1878
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1879
-    				unset($lined);
1880
-    				unset($data);
1881
-    			    } else $error = true;
1878
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1879
+					unset($lined);
1880
+					unset($data);
1881
+					} else $error = true;
1882 1882
 			} elseif ($format === 'aprs' && $use_aprs) {
1883
-			    if ($aprs_connect === 0) {
1883
+				if ($aprs_connect === 0) {
1884 1884
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1885 1885
 				$aprs_connect = 1;
1886
-			    }
1886
+				}
1887 1887
 			    
1888
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1888
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1889 1889
 				$aprs_last_tx = time();
1890 1890
 				$data_aprs = "# Keep alive";
1891 1891
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1892
-			    }
1892
+				}
1893 1893
 			    
1894
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1895
-			    //echo 'APRS data : '.$buffer."\n";
1896
-			    $buffer = str_replace('APRS <- ','',$buffer);
1897
-			    $buffer = str_replace('APRS -> ','',$buffer);
1898
-			    //echo $buffer."\n";
1899
-			    date_default_timezone_set('UTC');
1900
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1894
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1895
+				//echo 'APRS data : '.$buffer."\n";
1896
+				$buffer = str_replace('APRS <- ','',$buffer);
1897
+				$buffer = str_replace('APRS -> ','',$buffer);
1898
+				//echo $buffer."\n";
1899
+				date_default_timezone_set('UTC');
1900
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1901 1901
 				$line = $APRS->parse($buffer);
1902 1902
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1903 1903
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1904
-				    $aprs_last_tx = time();
1905
-				    $data = array();
1906
-				    //print_r($line);
1907
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1908
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1909
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1910
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1911
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1912
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1913
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1914
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1915
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1916
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1917
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1918
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1919
-				    $data['latitude'] = $line['latitude'];
1920
-				    $data['longitude'] = $line['longitude'];
1921
-				    //$data['verticalrate'] = $line[16];
1922
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1923
-				    //else $data['speed'] = 0;
1924
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1925
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1926
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1927
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1904
+					$aprs_last_tx = time();
1905
+					$data = array();
1906
+					//print_r($line);
1907
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1908
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1909
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1910
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1911
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1912
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1913
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1914
+					if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1915
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1916
+					else $data['datetime'] = date('Y-m-d H:i:s');
1917
+					//$data['datetime'] = date('Y-m-d H:i:s');
1918
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1919
+					$data['latitude'] = $line['latitude'];
1920
+					$data['longitude'] = $line['longitude'];
1921
+					//$data['verticalrate'] = $line[16];
1922
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1923
+					//else $data['speed'] = 0;
1924
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1925
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1926
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1927
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1928 1928
 				    
1929
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1930
-				    //else echo 'No heading...'."\n";
1931
-				    //else $data['heading'] = 0;
1932
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1933
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1934
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1935
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1936
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1937
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1938
-    				    $data['id_source'] = $id_source;
1939
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1940
-				    else $data['format_source'] = 'aprs';
1941
-				    $data['source_name'] = $line['source'];
1942
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1943
-				    else $data['source_type'] = 'flarm';
1944
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1945
-				    $currentdate = date('Y-m-d H:i:s');
1946
-				    $aprsdate = strtotime($data['datetime']);
1947
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1948
-				    // Accept data if time <= system time + 20s
1949
-				    //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'])))) {
1950
-				    if (
1929
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1930
+					//else echo 'No heading...'."\n";
1931
+					//else $data['heading'] = 0;
1932
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1933
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1934
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1935
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1936
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1937
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1938
+						$data['id_source'] = $id_source;
1939
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1940
+					else $data['format_source'] = 'aprs';
1941
+					$data['source_name'] = $line['source'];
1942
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1943
+					else $data['source_type'] = 'flarm';
1944
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1945
+					$currentdate = date('Y-m-d H:i:s');
1946
+					$aprsdate = strtotime($data['datetime']);
1947
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1948
+					// Accept data if time <= system time + 20s
1949
+					//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'])))) {
1950
+					if (
1951 1951
 					($data['source_type'] === 'modes') || 
1952 1952
 					isset($line['stealth']) && 
1953 1953
 					(!isset($data['hex']) || $data['hex'] != 'FFFFFF') && 
1954 1954
 					 ($line['stealth'] === 0 || $line['stealth'] == '') && 
1955 1955
 					 (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1956 1956
 					$send = $SI->add($data);
1957
-				    } elseif ($data['source_type'] === 'ais') {
1957
+					} elseif ($data['source_type'] === 'ais') {
1958 1958
 					$data['type'] = '';
1959 1959
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1960
-				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1960
+					} elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1961 1961
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1962
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1963
-					    //$line['symbol'] === 'Balloon' ||
1964
-					    $line['symbol'] === 'Glider' || 
1965
-					    $line['symbol'] === 'No. Plane' || 
1966
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1967
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1968
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1969
-					    $send = $SI->add($data);
1970
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1971
-					    $line['symbol'] === 'Yacht (Sail)' || 
1972
-					    $line['symbol'] === 'Ship (Power Boat)')) {
1973
-					    $send = $MI->add($data);
1974
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1975
-					    $line['symbol'] === 'Car' || 
1976
-					    $line['symbol'] === 'Ambulance' || 
1977
-					    $line['symbol'] === 'Van' || 
1978
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1979
-					    $line['symbol'] === 'Motorcycle' || 
1980
-					    $line['symbol'] === 'Tractor' || 
1981
-					    $line['symbol'] === 'Police' || 
1982
-					    $line['symbol'] === 'Bike' || 
1983
-					    $line['symbol'] === 'Jogger' || 
1984
-					    $line['symbol'] === 'Horse' || 
1985
-					    $line['symbol'] === 'Bus' || 
1986
-					    $line['symbol'] === 'Jeep' || 
1987
-					    $line['symbol'] === 'Recreational Vehicle' || 
1988
-					    $line['symbol'] === 'Yacht (Sail)' || 
1989
-					    $line['symbol'] === 'Ship (Power Boat)' || 
1990
-					    $line['symbol'] === 'Firetruck' || 
1991
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1992
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1993
-					    $line['symbol'] === 'SUV' ||
1994
-					    $line['symbol'] === 'Snowmobile' ||
1995
-					    $line['symbol'] === 'Mobile Satellite Station')) {
1996
-				    //} 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') {
1962
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1963
+						//$line['symbol'] === 'Balloon' ||
1964
+						$line['symbol'] === 'Glider' || 
1965
+						$line['symbol'] === 'No. Plane' || 
1966
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1967
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1968
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1969
+						$send = $SI->add($data);
1970
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1971
+						$line['symbol'] === 'Yacht (Sail)' || 
1972
+						$line['symbol'] === 'Ship (Power Boat)')) {
1973
+						$send = $MI->add($data);
1974
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1975
+						$line['symbol'] === 'Car' || 
1976
+						$line['symbol'] === 'Ambulance' || 
1977
+						$line['symbol'] === 'Van' || 
1978
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
1979
+						$line['symbol'] === 'Motorcycle' || 
1980
+						$line['symbol'] === 'Tractor' || 
1981
+						$line['symbol'] === 'Police' || 
1982
+						$line['symbol'] === 'Bike' || 
1983
+						$line['symbol'] === 'Jogger' || 
1984
+						$line['symbol'] === 'Horse' || 
1985
+						$line['symbol'] === 'Bus' || 
1986
+						$line['symbol'] === 'Jeep' || 
1987
+						$line['symbol'] === 'Recreational Vehicle' || 
1988
+						$line['symbol'] === 'Yacht (Sail)' || 
1989
+						$line['symbol'] === 'Ship (Power Boat)' || 
1990
+						$line['symbol'] === 'Firetruck' || 
1991
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
1992
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
1993
+						$line['symbol'] === 'SUV' ||
1994
+						$line['symbol'] === 'Snowmobile' ||
1995
+						$line['symbol'] === 'Mobile Satellite Station')) {
1996
+					//} 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') {
1997 1997
 				//    } 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') {
1998 1998
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1999 1999
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2000
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2000
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2001 2001
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2002 2002
 					$Source->deleteOldLocationByType('gs');
2003 2003
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -2005,7 +2005,7 @@  discard block
 block discarded – undo
2005 2005
 					} else {
2006 2006
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2007 2007
 					}
2008
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2008
+					} elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2009 2009
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2010 2010
 					if ($globalDebug) echo '# Weather Station added'."\n";
2011 2011
 					$Source->deleteOldLocationByType('wx');
@@ -2015,7 +2015,7 @@  discard block
 block discarded – undo
2015 2015
 					} else {
2016 2016
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2017 2017
 					}
2018
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2018
+					} elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2019 2019
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2020 2020
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2021 2021
 					$Source->deleteOldLocationByType('lightning');
@@ -2024,11 +2024,11 @@  discard block
 block discarded – undo
2024 2024
 					} else {
2025 2025
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2026 2026
 					}
2027
-				    } elseif ($globalDebug) {
2028
-				    	echo '/!\ Not added: '.$buffer."\n";
2029
-				    	print_r($line);
2030
-				    }
2031
-				    unset($data);
2027
+					} elseif ($globalDebug) {
2028
+						echo '/!\ Not added: '.$buffer."\n";
2029
+						print_r($line);
2030
+					}
2031
+					unset($data);
2032 2032
 				}
2033 2033
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2034 2034
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -2047,13 +2047,13 @@  discard block
 block discarded – undo
2047 2047
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
2048 2048
 					$globalSources[$nb]['last_weather_clean'] = time();
2049 2049
 				}
2050
-			    }
2050
+				}
2051 2051
 			} else {
2052
-			    $line = explode(',', $buffer);
2053
-			    //print_r($line);
2054
-    			    if (count($line) > 20) {
2055
-    			    	$data['hex'] = $line[4];
2056
-    				/*
2052
+				$line = explode(',', $buffer);
2053
+				//print_r($line);
2054
+					if (count($line) > 20) {
2055
+						$data['hex'] = $line[4];
2056
+					/*
2057 2057
     				$data['datetime'] = $line[6].' '.$line[7];
2058 2058
     					date_default_timezone_set($globalTimezone);
2059 2059
     					$datetime = new DateTime($data['datetime']);
@@ -2061,31 +2061,31 @@  discard block
 block discarded – undo
2061 2061
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
2062 2062
     					date_default_timezone_set('UTC');
2063 2063
     				*/
2064
-    				// Force datetime to current UTC datetime
2065
-    				date_default_timezone_set('UTC');
2066
-    				$data['datetime'] = date('Y-m-d H:i:s');
2067
-    				$data['ident'] = trim($line[10]);
2068
-    				$data['latitude'] = $line[14];
2069
-    				$data['longitude'] = $line[15];
2070
-    				$data['verticalrate'] = $line[16];
2071
-    				$data['emergency'] = $line[20];
2072
-    				$data['speed'] = $line[12];
2073
-    				$data['squawk'] = $line[17];
2074
-    				$data['altitude'] = $line[11];
2075
-    				$data['heading'] = $line[13];
2076
-    				$data['ground'] = $line[21];
2077
-    				$data['emergency'] = $line[19];
2078
-    				$data['format_source'] = 'sbs';
2064
+					// Force datetime to current UTC datetime
2065
+					date_default_timezone_set('UTC');
2066
+					$data['datetime'] = date('Y-m-d H:i:s');
2067
+					$data['ident'] = trim($line[10]);
2068
+					$data['latitude'] = $line[14];
2069
+					$data['longitude'] = $line[15];
2070
+					$data['verticalrate'] = $line[16];
2071
+					$data['emergency'] = $line[20];
2072
+					$data['speed'] = $line[12];
2073
+					$data['squawk'] = $line[17];
2074
+					$data['altitude'] = $line[11];
2075
+					$data['heading'] = $line[13];
2076
+					$data['ground'] = $line[21];
2077
+					$data['emergency'] = $line[19];
2078
+					$data['format_source'] = 'sbs';
2079 2079
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2080 2080
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2081 2081
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2082 2082
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2083
-    				$data['id_source'] = $id_source;
2084
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2085
-    				else $error = true;
2086
-    				unset($data);
2087
-    			    } else $error = true;
2088
-			    if ($error) {
2083
+					$data['id_source'] = $id_source;
2084
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2085
+					else $error = true;
2086
+					unset($data);
2087
+					} else $error = true;
2088
+				if ($error) {
2089 2089
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2090 2090
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
2091 2091
 				} else {
@@ -2101,13 +2101,13 @@  discard block
 block discarded – undo
2101 2101
 					connect_all($sourceer);
2102 2102
 					$sourceer = array();
2103 2103
 				}
2104
-			    }
2104
+				}
2105 2105
 			}
2106 2106
 			// Sleep for xxx microseconds
2107 2107
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2108
-		    } else {
2108
+			} else {
2109 2109
 			if ($format === 'flightgearmp') {
2110
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2110
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
2111 2111
 				//@socket_close($r);
2112 2112
 				sleep($globalMinFetch);
2113 2113
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2116,9 +2116,9 @@  discard block
 block discarded – undo
2116 2116
 				break;
2117 2117
 				
2118 2118
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2119
-			    if (isset($tt[$format])) $tt[$format]++;
2120
-			    else $tt[$format] = 0;
2121
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
2119
+				if (isset($tt[$format])) $tt[$format]++;
2120
+				else $tt[$format] = 0;
2121
+				if ($tt[$format] > 30 || $buffer === FALSE) {
2122 2122
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2123 2123
 				//@socket_close($r);
2124 2124
 				sleep(2);
@@ -2129,24 +2129,24 @@  discard block
 block discarded – undo
2129 2129
 				//connect_all($globalSources);
2130 2130
 				$tt[$format]=0;
2131 2131
 				break;
2132
-			    } 
2133
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2132
+				} 
2133
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2134
+			}
2134 2135
 			}
2135
-		    }
2136 2136
 		}
2137
-	    } else {
2137
+		} else {
2138 2138
 		$error = socket_strerror(socket_last_error());
2139 2139
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2140 2140
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2141 2141
 			if (isset($globalDebug)) echo "Restarting...\n";
2142 2142
 			// Restart the script if possible
2143 2143
 			if (is_array($sockets)) {
2144
-			    if ($globalDebug) echo "Shutdown all sockets...";
2144
+				if ($globalDebug) echo "Shutdown all sockets...";
2145 2145
 			    
2146
-			    foreach ($sockets as $sock) {
2146
+				foreach ($sockets as $sock) {
2147 2147
 				@socket_shutdown($sock,2);
2148 2148
 				@socket_close($sock);
2149
-			    }
2149
+				}
2150 2150
 			    
2151 2151
 			}
2152 2152
 			if ($globalDebug) echo "Waiting...";
@@ -2161,15 +2161,15 @@  discard block
 block discarded – undo
2161 2161
 			if ($globalDebug) echo "Restart all connections...";
2162 2162
 			connect_all($globalSources);
2163 2163
 		}
2164
-	    }
2164
+		}
2165 2165
 	}
2166 2166
 	if ($globalDaemon === false) {
2167
-	    if ($globalDebug) echo 'Check all...'."\n";
2168
-	    if (isset($SI)) $SI->checkAll();
2169
-	    if (isset($TI)) $TI->checkAll();
2170
-	    if (isset($MI)) $MI->checkAll();
2167
+		if ($globalDebug) echo 'Check all...'."\n";
2168
+		if (isset($SI)) $SI->checkAll();
2169
+		if (isset($TI)) $TI->checkAll();
2170
+		if (isset($MI)) $MI->checkAll();
2171
+	}
2171 2172
 	}
2172
-    }
2173 2173
 }
2174 2174
 
2175 2175
 ?>
Please login to merge, or discard this patch.
Spacing   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 	    die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
62
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
63 63
     }
64 64
 }
65 65
 
66
-$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'));
66
+$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'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70 70
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
71
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
72 72
     else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74 74
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
76 76
     else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115 115
     if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
116
+    $SI = new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
120 120
     $SI->connect();
121 121
 */
122
-} else $SI=new SpotterImport($Connection->db);
122
+} else $SI = new SpotterImport($Connection->db);
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
     $MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136
-$SBS=new SBS();
136
+$SBS = new SBS();
137 137
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
138
-	$ACARS=new ACARS($Connection->db,true);
139
-	$Source=new Source($Connection->db);
138
+	$ACARS = new ACARS($Connection->db, true);
139
+	$Source = new Source($Connection->db);
140 140
 }
141
-$Common=new Common();
141
+$Common = new Common();
142 142
 date_default_timezone_set('UTC');
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
146
+    pcntl_signal(SIGINT, function() {
147 147
         global $sockets;
148 148
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149 149
         die("Bye!\n");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
 function connect_all($hosts) {
161 161
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
162
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
163 163
     $reset++;
164 164
     if ($globalDebug) echo 'Connect to all...'."\n";
165 165
     foreach ($hosts as $id => $value) {
@@ -167,33 +167,33 @@  discard block
 block discarded – undo
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
170
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
+            if (preg_match('/deltadb.txt$/i', $host)) {
172 172
         	//$formats[$id] = 'deltadbtxt';
173 173
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 174
         	//$last_exec['deltadbtxt'] = 0;
175 175
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
176
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
177 177
         	//$formats[$id] = 'vatsimtxt';
178 178
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 179
         	//$last_exec['vatsimtxt'] = 0;
180 180
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
181
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
182 182
         	//$formats[$id] = 'aircraftlistjson';
183 183
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
186
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftjson';
188 188
         	$globalSources[$id]['format'] = 'aircraftjson';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
190 190
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
191
+    	    } else if (preg_match('/aircraft$/i', $host)) {
192 192
         	//$formats[$id] = 'planefinderclient';
193 193
         	$globalSources[$id]['format'] = 'planefinderclient';
194 194
         	//$last_exec['aircraftlistjson'] = 0;
195 195
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
196
+    	    } else if (preg_match('/opensky/i', $host)) {
197 197
         	//$formats[$id] = 'aircraftlistjson';
198 198
         	$globalSources[$id]['format'] = 'opensky';
199 199
         	//$last_exec['aircraftlistjson'] = 0;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
213
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
214 214
         	//$formats[$id] = 'planeupdatefaa';
215 215
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 216
         	//$last_exec['planeupdatefaa'] = 0;
@@ -219,37 +219,37 @@  discard block
 block discarded – undo
219 219
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 220
         	    exit(0);
221 221
         	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
222
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'phpvmacars';
225 225
         	//$last_exec['phpvmacars'] = 0;
226 226
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
227
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
228 228
         	//$formats[$id] = 'phpvmacars';
229 229
         	$globalSources[$id]['format'] = 'vaos';
230 230
         	//$last_exec['phpvmacars'] = 0;
231 231
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
232
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
233 233
         	//$formats[$id] = 'phpvmacars';
234 234
         	$globalSources[$id]['format'] = 'vam';
235 235
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
236
+            } else if (preg_match('/whazzup/i', $host)) {
237 237
         	//$formats[$id] = 'whazzup';
238 238
         	$globalSources[$id]['format'] = 'whazzup';
239 239
         	//$last_exec['whazzup'] = 0;
240 240
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
241
+            } else if (preg_match('/blitzortung/i', $host)) {
242 242
         	$globalSources[$id]['format'] = 'blitzortung';
243 243
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
244
+            } else if (preg_match('/airwhere/i', $host)) {
245 245
         	$globalSources[$id]['format'] = 'airwhere';
246 246
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
247
+            } else if (preg_match('/recentpireps/i', $host)) {
248 248
         	//$formats[$id] = 'pirepsjson';
249 249
         	$globalSources[$id]['format'] = 'pirepsjson';
250 250
         	//$last_exec['pirepsjson'] = 0;
251 251
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
252
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
253 253
         	//$formats[$id] = 'fr24json';
254 254
         	$globalSources[$id]['format'] = 'fr24json';
255 255
         	//$last_exec['fr24json'] = 0;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 259
         	    exit(0);
260 260
         	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
261
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
262 262
         	//$formats[$id] = 'fr24json';
263 263
         	$globalSources[$id]['format'] = 'myshiptracking';
264 264
         	//$last_exec['fr24json'] = 0;
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
         	    exit(0);
269 269
         	}
270 270
             //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
271
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 272
         	//$formats[$id] = 'tsv';
273 273
         	$globalSources[$id]['format'] = 'tsv';
274 274
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275 275
             }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
276
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 277
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
278
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
279 279
     		    if ($idf !== false) {
280 280
     			$httpfeeds[$id] = $idf;
281 281
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284 284
     		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285 285
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
286
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
287
+	    $hostport = explode(':', $host);
288 288
 	    if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
@@ -294,20 +294,20 @@  discard block
 block discarded – undo
294 294
 	    }
295 295
 	    $Common = new Common();
296 296
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
297
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
298 298
     	    } else {
299 299
     		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
300
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
301 301
 	    }
302 302
 	    if ($s) {
303 303
     	        $sockets[$id] = $s;
304 304
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
305
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312 312
     		    } elseif ($port == '10001') {
313 313
         		//$formats[$id] = 'tsv';
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350 350
 else $timeout = 20;
351 351
 $errno = '';
352
-$errstr='';
352
+$errstr = '';
353 353
 
354 354
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
355 355
 /* Initiate connections to all the hosts simultaneously */
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
361 361
 } else {
362 362
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
@@ -387,16 +387,16 @@  discard block
 block discarded – undo
387 387
 
388 388
 if ($use_aprs) {
389 389
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
390
-	$APRS=new APRS();
390
+	$APRS = new APRS();
391 391
 	$aprs_connect = 0;
392 392
 	$aprs_keep = 120;
393 393
 	$aprs_last_tx = time();
394 394
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
395
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
396 396
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
397
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
398 398
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
399
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400 400
 	if ($aprs_full) $aprs_filter = '';
401 401
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402 402
 	else $aprs_pass = '-1';
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 sleep(1);
411 411
 if ($globalDebug) echo "SCAN MODE \n\n";
412 412
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
413
-$endtime = time()+$globalCronEnd;
413
+$endtime = time() + $globalCronEnd;
414 414
 $i = 1;
415 415
 $tt = array();
416 416
 // Delete all ATC
417 417
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
418
-	$ATC=new ATC($Connection->db);
418
+	$ATC = new ATC($Connection->db);
419 419
 }
420 420
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
421 421
 	$ATC->deleteAll();
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 while ($i > 0) {
426 426
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
428
+    if (!$globalDaemon) $i = $endtime - time();
429 429
     // Delete old ATC
430 430
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441 441
 	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
442
+	    sleep($globalMinFetch - $max + 2);
443 443
 	}
444 444
     }
445 445
 
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
             //$buffer = $Common->getData($hosts[$id]);
495 495
             $buffer = $Common->getData($value['host']);
496 496
             if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
497
+                $all_data = json_decode($buffer, true);
498 498
                 foreach ($all_data as $line) {
499 499
                     $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
500
+                    $data['datetime'] = date('Y-m-d H:i:s', $line['uti']);
501 501
                     $data['hex'] = $line['hex']; // hex
502 502
                     $data['ident'] = $line['fli']; // ident
503 503
                     $data['altitude'] = $line['alt']; // altitude
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	    )
533 533
 	) {
534 534
 	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
535
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
536 536
 	    date_default_timezone_set('UTC');
537 537
 	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
538
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
539
+	    $buffer = explode('\n', $buffer);
540 540
 	    foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542 542
 		    //echo "'".$line."'\n";
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 		    $ais_data = $AIS->parse_line(trim($line));
545 545
 		    $data = array();
546 546
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
547
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
548 548
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549 549
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550 550
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557 557
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558 558
 		    if (isset($ais_data['timestamp'])) {
559
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
559
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561 561
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562 562
 			    $add = true;
@@ -579,21 +579,21 @@  discard block
 block discarded – undo
579 579
 	    $w = $e = null;
580 580
 	    
581 581
 	    if (isset($arr[$id])) {
582
-		$nn = stream_select($arr,$w,$e,$timeout);
582
+		$nn = stream_select($arr, $w, $e, $timeout);
583 583
 		if ($nn > 0) {
584 584
 		    foreach ($httpfeeds as $feed) {
585
-			$buffer = stream_get_line($feed,2000,"\n");
585
+			$buffer = stream_get_line($feed, 2000, "\n");
586 586
 			if ($buffer === FALSE) {
587 587
 			    connect_all($globalSources);
588 588
 			}
589
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590
-			$buffer = explode('\n',$buffer);
589
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
590
+			$buffer = explode('\n', $buffer);
591 591
 			foreach ($buffer as $line) {
592 592
 			    if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
596
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
597 597
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598 598
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599 599
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -605,9 +605,9 @@  discard block
 block discarded – undo
605 605
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606 606
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
608
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
611 611
 				} else {
612 612
 				    $data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640 640
 	    )
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
642
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
643 643
 	    if ($buffer != '') {
644 644
 		//echo $buffer;
645
-		$all_data = json_decode($buffer,true);
645
+		$all_data = json_decode($buffer, true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648 648
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 			    $data['ident'] = $line['NAME'];
652 652
 			    $data['mmsi'] = $line['MMSI'];
653 653
 			    if (strlen($data['mmsi']) > 9) {
654
-				$data['mmsi'] = substr($data['mmsi'],-9);
654
+				$data['mmsi'] = substr($data['mmsi'], -9);
655 655
 			    }
656 656
 			    $data['speed'] = $line['SOG'];
657 657
 			    $data['heading'] = $line['COG'];
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 			    //$data['type_id'] = $line['TYPE'];
662 662
 			    $data['imo'] = $line['IMO'];
663 663
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
664
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
665
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
666 666
 			    $data['format_source'] = 'myshiptracking';
667 667
 			    $data['id_source'] = $id_source;
668 668
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680 680
 	    )
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
682
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
683 683
 	    if ($buffer != '') {
684
-		$all_data = json_decode($buffer,true);
684
+		$all_data = json_decode($buffer, true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686 686
 		    foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688 688
 			    $data = array();
689 689
 			    $data['ident'] = $line['shipname'];
690 690
 			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
691
+			    $data['mmsi'] = substr($line['mmsi'], -9);
692 692
 			    $data['speed'] = $line['sog'];
693 693
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694 694
 			    $data['latitude'] = $line['latitude'];
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
 	) {
716 716
 	    $buffer = $Common->getData($value['host']);
717 717
 	    if ($buffer != '') {
718
-		$all_data = json_decode($buffer,true);
718
+		$all_data = json_decode($buffer, true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720 720
 		    foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724 724
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
725
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
726 726
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727 727
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728 728
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -749,31 +749,31 @@  discard block
 block discarded – undo
749 749
 	    )
750 750
 	) {
751 751
 	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
752
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
753 753
 	    if ($globalDebug) echo 'done !'."\n";
754 754
 	    // FIXME: Need more work
755 755
 	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
756
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
757
+	    $buffer = explode('\n', $buffer);
758 758
 	    foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760 760
 		    $data = array();
761 761
 		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
762
+		    $data['mmsi'] = (int) substr($line, 0, 9);
763
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
764
+		    $data['status_id'] = substr($line, 21, 2);
765
+		    $data['type_id'] = substr($line, 24, 3);
766
+		    $data['latitude'] = substr($line, 29, 9);
767
+		    $data['longitude'] = substr($line, 41, 9);
768
+		    $data['speed'] = round(substr($line, 51, 5));
769 769
 		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
770
+		    $data['heading'] = round(substr($line, 63, 3));
771 771
 		    //$data['draft'] = substr($line,67,4);
772 772
 		    //$data['length'] = substr($line,72,3);
773 773
 		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
774
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
775 775
 		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
776
+		    $data['arrival_code'] = substr($line, 108, 20);
777 777
 		    //$data['etaDate'] = substr($line,129,5);
778 778
 		    //$data['etaTime'] = substr($line,135,5);
779 779
 		    $data['format_source'] = 'shipplotter';
@@ -796,20 +796,20 @@  discard block
 block discarded – undo
796 796
 		exit(0);
797 797
 	    }
798 798
 	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
799
+	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption, array('usrnr' => $globalSailaway['usrnr']));
800
+	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption, array('ubtnr' => $globalSailaway['ubtnr']));
801 801
 
802 802
 	    for ($i = 0; $i <= 1; $i++) {
803 803
 		if ($globalDebug) echo '! Download... ';
804 804
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2');
805 805
 		if ($globalDebug) echo 'done'."\n";
806 806
 		if ($buffer != '') {
807
-		    $all_data = json_decode($buffer,true);
807
+		    $all_data = json_decode($buffer, true);
808 808
 		    if (isset($all_data['missions'])) {
809 809
 			foreach ($all_data['missions'] as $mission) {
810 810
 				$mission_user = $mission['usrname'];
811
-				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
812
-				if (!(!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race'])))) {
811
+				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle']));
812
+				if (!(!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race'])))) {
813 813
 					$bufferm = '';
814 814
 					$racebuffer = '';
815 815
 				}
@@ -818,8 +818,8 @@  discard block
 block discarded – undo
818 818
 					$datar = array();
819 819
 					$datar['id'] = $mission['misnr'];
820 820
 					$datar['desc'] = $race_data['mission']['misdescr'];
821
-					$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
822
-					$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle'])));
821
+					$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($race_data['mission']['usrname'])));
822
+					$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle'])));
823 823
 					$datar['startdate'] = $mission['misstartdatetime'];
824 824
 					/*
825 825
 					$markers = array();
@@ -836,9 +836,9 @@  discard block
 block discarded – undo
836 836
 		}
837 837
 		sleep(10*60);
838 838
 	    }
839
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
839
+	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption), 'get', '', '', '', '', 30);
840 840
 	    if ($buffer != '') {
841
-		$data = json_decode($buffer,true);
841
+		$data = json_decode($buffer, true);
842 842
 		//print_r($data);
843 843
 		if (isset($data['boats'])) {
844 844
 		    foreach ($data['boats'] as $sail) {
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
 			$data['longitude'] = $sail['ubtlon'];
851 851
 			$data['type_id'] = 36;
852 852
 			$data['heading'] = $sail['ubtheading'];
853
-			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
853
+			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
854 854
 			$data['captain_name'] = $sail['usrname'];
855
-			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
855
+			$allboats = array('Sailaway Cruiser 38', 'Mini Transat', 'Caribbean Rose', '52&#39; Cruising Cat', '50&#39; Performance Cruiser', 'Nordic Folkboat');
856 856
 			$boattype = $sail['ubtbtpnr'];
857
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
858
-			$data['speed'] = round($sail['ubtspeed']*3.6,2);
857
+			if (isset($allboats[$boattype - 1])) $data['type'] = $allboats[$boattype - 1];
858
+			$data['speed'] = round($sail['ubtspeed']*3.6, 2);
859 859
 			$data['format_source'] = 'sailaway';
860 860
 			$data['id_source'] = $id_source;
861 861
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -888,11 +888,11 @@  discard block
 block discarded – undo
888 888
 	    }
889 889
 	    if ($globalDebug) echo '! Download... ';
890 890
 	    $sailawayoption = array('key' => $globalSailaway['key']);
891
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
892
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
893
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
891
+	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption, array('usrnr' => $globalSailaway['usrnr']));
892
+	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption, array('ubtnr' => $globalSailaway['ubtnr']));
893
+	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption), 'get', '', '', '', '', 30);
894 894
 	    if ($buffer != '') {
895
-		$data = json_decode($buffer,true);
895
+		$data = json_decode($buffer, true);
896 896
 		//print_r($data);
897 897
 		if (isset($data['boats'])) {
898 898
 		    foreach ($data['boats'] as $sail) {
@@ -904,12 +904,12 @@  discard block
 block discarded – undo
904 904
 			$data['longitude'] = $sail['ubtlon'];
905 905
 			$data['type_id'] = 36;
906 906
 			$data['heading'] = $sail['ubtheading'];
907
-			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
907
+			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
908 908
 			$data['captain_name'] = $sail['usrname'];
909
-			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
909
+			$allboats = array('Sailaway Cruiser 38', 'Mini Transat', 'Caribbean Rose', '52&#39; Cruising Cat', '50&#39; Performance Cruiser', 'Nordic Folkboat');
910 910
 			$boattype = $sail['ubtbtpnr'];
911
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
912
-			$data['speed'] = round($sail['ubtspeed']*3.6,2);
911
+			if (isset($allboats[$boattype - 1])) $data['type'] = $allboats[$boattype - 1];
912
+			$data['speed'] = round($sail['ubtspeed']*3.6, 2);
913 913
 			$data['format_source'] = 'sailaway';
914 914
 			$data['id_source'] = $id_source;
915 915
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -937,8 +937,8 @@  discard block
 block discarded – undo
937 937
 	) {
938 938
 	    //$buffer = $Common->getData($hosts[$id]);
939 939
 	    $buffer = $Common->getData($value['host']);
940
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
941
-	    $buffer = explode('\n',$buffer);
940
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
941
+	    $buffer = explode('\n', $buffer);
942 942
 	    $reset = 0;
943 943
 	    foreach ($buffer as $line) {
944 944
     		if ($line != '') {
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
950 950
 			$data['pilot_id'] = $line[1];
951 951
 			$data['pilot_name'] = $line[2];
952
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
952
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
953 953
 			$data['ident'] = $line[0]; // ident
954 954
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
955 955
 			$data['speed'] = $line[8]; // speed
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
966 966
 			//if (isset($line[37])) $data['last_update'] = $line[37];
967 967
 		        $data['departure_airport_icao'] = $line[11];
968
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
968
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
969 969
 		        $data['arrival_airport_icao'] = $line[13];
970 970
 			$data['frequency'] = $line[4];
971 971
 			$data['type'] = $line[18];
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
     			$data['id_source'] = $id_source;
975 975
 	    		//$data['arrival_airport_time'] = ;
976 976
 	    		if ($line[9] != '') {
977
-	    		    $aircraft_data = explode('/',$line[9]);
977
+	    		    $aircraft_data = explode('/', $line[9]);
978 978
 	    		    if (isset($aircraft_data[1])) {
979 979
 	    			$data['aircraft_icao'] = $aircraft_data[1];
980 980
 	    		    }
@@ -989,9 +989,9 @@  discard block
 block discarded – undo
989 989
     			if ($line[3] === 'PILOT') $SI->add($data);
990 990
 			elseif ($line[3] === 'ATC') {
991 991
 				//print_r($data);
992
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
993
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
994
-				$typec = substr($data['ident'],-3);
992
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
993
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
994
+				$typec = substr($data['ident'], -3);
995 995
 				if ($typec === 'APP') $data['type'] = 'Approach';
996 996
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
997 997
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -1003,8 +1003,8 @@  discard block
 block discarded – undo
1003 1003
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
1004 1004
 				if (!isset($data['source_name'])) $data['source_name'] = '';
1005 1005
 				if (isset($ATC)) {
1006
-					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']);
1007
-					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']);
1006
+					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']);
1007
+					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']);
1008 1008
 				}
1009 1009
 			}
1010 1010
     			unset($data);
@@ -1020,24 +1020,24 @@  discard block
 block discarded – undo
1020 1020
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1021 1021
     	    )
1022 1022
     	) {
1023
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1023
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
1024 1024
 	    if ($buffer != '') {
1025 1025
 		$all_data = simplexml_load_string($buffer);
1026
-		foreach($all_data->children() as $childdata) {
1026
+		foreach ($all_data->children() as $childdata) {
1027 1027
 			$data = array();
1028 1028
 			$line = $childdata;
1029 1029
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
1030
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
1031
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1032
-			$data['latitude'] = (float)$line['pktLatitude'];
1033
-			$data['longitude'] = (float)$line['pktLongitude'];
1034
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1035
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1036
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1030
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
1031
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
1032
+			$data['latitude'] = (float) $line['pktLatitude'];
1033
+			$data['longitude'] = (float) $line['pktLongitude'];
1034
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
1035
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
1036
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
1037 1037
 			$data['altitude_relative'] = 'AMSL';
1038
-			$data['pilot_id'] = (int)$line['pktPilotID'];
1038
+			$data['pilot_id'] = (int) $line['pktPilotID'];
1039 1039
 			$data['aircraft_icao'] = 'PARAGLIDER';
1040
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1040
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1041 1041
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1042 1042
 			$data['format_source'] = $value['format'];
1043 1043
 			$SI->add($data);
@@ -1045,22 +1045,22 @@  discard block
 block discarded – undo
1045 1045
 		}
1046 1046
 	    }
1047 1047
 	    $Source->deleteOldLocationByType('gs');
1048
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1048
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
1049 1049
 	    if ($buffer != '') {
1050 1050
 		$all_data = simplexml_load_string($buffer);
1051
-		foreach($all_data->children() as $childdata) {
1051
+		foreach ($all_data->children() as $childdata) {
1052 1052
 			$data = array();
1053 1053
 			$line = $childdata;
1054
-			$data['id'] = (int)$line['gsID'];
1055
-			$data['latitude'] = (float)$line['gsLatitude'];
1056
-			$data['longitude'] = (float)$line['gsLongitude'];
1057
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
1054
+			$data['id'] = (int) $line['gsID'];
1055
+			$data['latitude'] = (float) $line['gsLatitude'];
1056
+			$data['longitude'] = (float) $line['gsLongitude'];
1057
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
1058 1058
 			$data['altitude_relative'] = 'AMSL';
1059
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
1059
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
1060 1060
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
1061
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1061
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1062 1062
 			} else {
1063
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1063
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1064 1064
 			}
1065 1065
 			unset($data);
1066 1066
 		}
@@ -1078,9 +1078,9 @@  discard block
 block discarded – undo
1078 1078
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1079 1079
 	    )
1080 1080
 	) {
1081
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1081
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
1082 1082
 	    if ($buffer != '') {
1083
-	        $all_data = json_decode($buffer,true);
1083
+	        $all_data = json_decode($buffer, true);
1084 1084
 		if (isset($all_data['acList'])) {
1085 1085
 		    $reset = 0;
1086 1086
 		    foreach ($all_data['acList'] as $line) {
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1097 1097
 			$data['emergency'] = ''; // emergency
1098 1098
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1099
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1099
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1100 1100
 			else $data['datetime'] = date('Y-m-d H:i:s');
1101 1101
 			//$data['datetime'] = date('Y-m-d H:i:s');
1102 1102
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1122 1122
 			$data['squawk'] = $line['squawk']; // squawk
1123 1123
 			$data['emergency'] = ''; // emergency
1124
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1124
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1125 1125
 			else $data['datetime'] = date('Y-m-d H:i:s');
1126 1126
 			$data['format_source'] = 'aircraftlistjson';
1127 1127
 			$data['id_source'] = $id_source;
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
     	    )
1143 1143
     	) {
1144 1144
 	    $buffer = $Common->getData($value['host']);
1145
-	    $all_data = json_decode($buffer,true);
1145
+	    $all_data = json_decode($buffer, true);
1146 1146
 	    if (isset($all_data['planes'])) {
1147 1147
 		$reset = 0;
1148 1148
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1159,12 +1159,12 @@  discard block
 block discarded – undo
1159 1159
 		    $data['emergency'] = ''; // emergency
1160 1160
 		    $data['registration'] = $line[2];
1161 1161
 		    $data['aircraft_icao'] = $line[0];
1162
-		    $deparr = explode('-',$line[1]);
1162
+		    $deparr = explode('-', $line[1]);
1163 1163
 		    if (count($deparr) === 2) {
1164 1164
 			$data['departure_airport_icao'] = $deparr[0];
1165 1165
 			$data['arrival_airport_icao'] = $deparr[1];
1166 1166
 		    }
1167
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1167
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1168 1168
 	    	    $data['format_source'] = 'planeupdatefaa';
1169 1169
     		    $data['id_source'] = $id_source;
1170 1170
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
 	    )
1183 1183
 	) {
1184 1184
 	    $buffer = $Common->getData($value['host']);
1185
-	    $all_data = json_decode($buffer,true);
1185
+	    $all_data = json_decode($buffer, true);
1186 1186
 	    if (isset($all_data['states'])) {
1187 1187
 		$reset = 0;
1188 1188
 		foreach ($all_data['states'] as $key => $line) {
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 		    //$data['emergency'] = ''; // emergency
1200 1200
 		    //$data['registration'] = $line[2];
1201 1201
 		    //$data['aircraft_icao'] = $line[0];
1202
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1202
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1203 1203
 		    $data['format_source'] = 'opensky';
1204 1204
 		    $data['id_source'] = $id_source;
1205 1205
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1216,8 +1216,8 @@  discard block
 block discarded – undo
1216 1216
 	    )
1217 1217
 	) {
1218 1218
 	    $buffer = $Common->getData($value['host']);
1219
-	    $all_data = json_decode($buffer,true);
1220
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1219
+	    $all_data = json_decode($buffer, true);
1220
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1221 1221
 		$reset = 0;
1222 1222
 		foreach ($all_data['aircraft'] as $key => $line) {
1223 1223
 		    $data = array();
@@ -1255,7 +1255,7 @@  discard block
 block discarded – undo
1255 1255
 	    )
1256 1256
 	) {
1257 1257
 	    $buffer = $Common->getData($value['host']);
1258
-	    $all_data = json_decode($buffer,true);
1258
+	    $all_data = json_decode($buffer, true);
1259 1259
 	    if (isset($all_data['aircraft'])) {
1260 1260
 		$reset = 0;
1261 1261
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
 		    //$data['emergency'] = ''; // emergency
1273 1273
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1274 1274
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1275
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1275
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1276 1276
 		    $data['format_source'] = 'planefinderclient';
1277 1277
 		    $data['id_source'] = $id_source;
1278 1278
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 	) {
1292 1292
 	    //$buffer = $Common->getData($hosts[$id]);
1293 1293
 	    $buffer = $Common->getData($value['host']);
1294
-	    $all_data = json_decode($buffer,true);
1294
+	    $all_data = json_decode($buffer, true);
1295 1295
 	    if (!empty($all_data)) $reset = 0;
1296 1296
 	    foreach ($all_data as $key => $line) {
1297 1297
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1329,11 +1329,11 @@  discard block
 block discarded – undo
1329 1329
 	    )
1330 1330
 	) {
1331 1331
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1332
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1332
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1333 1333
 	    //echo $buffer;
1334
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1335
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1336
-	    $all_data = json_decode($buffer,true);
1334
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1335
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1336
+	    $all_data = json_decode($buffer, true);
1337 1337
 	    if (json_last_error() != JSON_ERROR_NONE) {
1338 1338
 		die(json_last_error_msg());
1339 1339
 	    }
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 			//$data['departure_airport_iata'] = $line[11];
1357 1357
 			//$data['arrival_airport_iata'] = $line[12];
1358 1358
 	    		//$data['emergency'] = ''; // emergency
1359
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1359
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1360 1360
 	    		$data['format_source'] = 'radarvirtueljson';
1361 1361
     			$data['id_source'] = $id_source;
1362 1362
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1377,14 +1377,14 @@  discard block
 block discarded – undo
1377 1377
 	) {
1378 1378
 	    //$buffer = $Common->getData($hosts[$id]);
1379 1379
 	    $buffer = $Common->getData($value['host'].'?'.time());
1380
-	    $all_data = json_decode(utf8_encode($buffer),true);
1380
+	    $all_data = json_decode(utf8_encode($buffer), true);
1381 1381
 	    
1382 1382
 	    if (isset($all_data['pireps'])) {
1383 1383
 		$reset = 0;
1384 1384
 	        foreach ($all_data['pireps'] as $line) {
1385 1385
 		    $data = array();
1386 1386
 		    $data['id'] = $line['id'];
1387
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1387
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1388 1388
 		    $data['ident'] = $line['callsign']; // ident
1389 1389
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1390 1390
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1414,9 +1414,9 @@  discard block
 block discarded – undo
1414 1414
 			$SI->add($data);
1415 1415
 		    //    print_r($data);
1416 1416
     		    } elseif ($line['icon'] === 'ct') {
1417
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1418
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1419
-			$typec = substr($data['ident'],-3);
1417
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1418
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1419
+			$typec = substr($data['ident'], -3);
1420 1420
 			$data['type'] = '';
1421 1421
 			if ($typec === 'APP') $data['type'] = 'Approach';
1422 1422
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1428 1428
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1429 1429
 			else $data['type'] = 'Observer';
1430
-			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']);
1430
+			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']);
1431 1431
 		    }
1432 1432
 		    unset($data);
1433 1433
 		}
@@ -1444,14 +1444,14 @@  discard block
 block discarded – undo
1444 1444
 	    //$buffer = $Common->getData($hosts[$id]);
1445 1445
 	    if ($globalDebug) echo 'Get Data...'."\n";
1446 1446
 	    $buffer = $Common->getData($value['host']);
1447
-	    $all_data = json_decode($buffer,true);
1447
+	    $all_data = json_decode($buffer, true);
1448 1448
 	    if ($buffer != '' && is_array($all_data)) {
1449 1449
 		$reset = 0;
1450 1450
 		foreach ($all_data as $line) {
1451 1451
 	    	    $data = array();
1452 1452
 	    	    //$data['id'] = $line['id']; // id not usable
1453 1453
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1454
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1454
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1455 1455
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1456 1456
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1457 1457
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 	    	    //$data['datetime'] = $line['lastupdate'];
1467 1467
 	    	    //$data['last_update'] = $line['lastupdate'];
1468 1468
 	    	    if (isset($value['timezone'])) {
1469
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1469
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1470 1470
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1471 1471
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1472 1472
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1482,14 +1482,14 @@  discard block
 block discarded – undo
1482 1482
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1483 1483
 		    if (isset($line['aircraftname'])) {
1484 1484
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1485
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1486
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1485
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1486
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1487 1487
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1488 1488
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1489 1489
 	    		else {
1490
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1491
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1492
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1490
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1491
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1492
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1493 1493
 	    		}
1494 1494
 	    	    }
1495 1495
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1514,7 +1514,7 @@  discard block
 block discarded – undo
1514 1514
 	    //$buffer = $Common->getData($hosts[$id]);
1515 1515
 	    if ($globalDebug) echo 'Get Data...'."\n";
1516 1516
 	    $buffer = $Common->getData($value['host']);
1517
-	    $all_data = json_decode($buffer,true);
1517
+	    $all_data = json_decode($buffer, true);
1518 1518
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1519 1519
 		$reset = 0;
1520 1520
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1526 1526
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1527 1527
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1528
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1528
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1529 1529
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1530 1530
 	    	    $data['altitude'] = $line['altitude']; // altitude
1531 1531
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 	    	    //$data['squawk'] = ''; // squawk
1537 1537
 	    	    //$data['emergency'] = ''; // emergency
1538 1538
 	    	    if (isset($value['timezone'])) {
1539
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1539
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1540 1540
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1541 1541
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1542 1542
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1572,14 +1572,14 @@  discard block
 block discarded – undo
1572 1572
 	    //$buffer = $Common->getData($hosts[$id]);
1573 1573
 	    if ($globalDebug) echo 'Get Data...'."\n";
1574 1574
 	    $buffer = $Common->getData($value['host']);
1575
-	    $all_data = json_decode($buffer,true);
1575
+	    $all_data = json_decode($buffer, true);
1576 1576
 	    if ($buffer != '' && is_array($all_data)) {
1577 1577
 		$reset = 0;
1578 1578
 		foreach ($all_data as $line) {
1579 1579
 	    	    $data = array();
1580 1580
 	    	    //$data['id'] = $line['id']; // id not usable
1581 1581
 	    	    $data['id'] = trim($line['flight_id']);
1582
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1582
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1583 1583
 	    	    $data['pilot_name'] = $line['pilot_name'];
1584 1584
 	    	    $data['pilot_id'] = $line['pilot_id'];
1585 1585
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1623,24 +1623,24 @@  discard block
 block discarded – undo
1623 1623
 	    //$buffer = $Common->getData($hosts[$id]);
1624 1624
 	    if ($globalDebug) echo 'Get Data...'."\n";
1625 1625
 	    $buffer = $Common->getData($value['host']);
1626
-	    $all_data = json_decode($buffer,true);
1626
+	    $all_data = json_decode($buffer, true);
1627 1627
 	    if ($buffer != '') {
1628 1628
 		$Source->deleteLocationBySource('blitzortung');
1629
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1630
-		$buffer = explode('\n',$buffer);
1629
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1630
+		$buffer = explode('\n', $buffer);
1631 1631
 		foreach ($buffer as $buffer_line) {
1632
-		    $line = json_decode($buffer_line,true);
1632
+		    $line = json_decode($buffer_line, true);
1633 1633
 		    if (isset($line['time'])) {
1634 1634
 			$data = array();
1635 1635
 			$data['altitude'] = $line['alt']; // altitude
1636 1636
 			$data['latitude'] = $line['lat']; // lat
1637 1637
 			$data['longitude'] = $line['lon']; // long
1638
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1638
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1639 1639
 			$data['id_source'] = $id_source;
1640 1640
 			$data['format_source'] = 'blitzortung';
1641 1641
 			$SI->add($data);
1642 1642
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1643
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1643
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1644 1644
 			unset($data);
1645 1645
 		    }
1646 1646
 		}
@@ -1652,15 +1652,15 @@  discard block
 block discarded – undo
1652 1652
         $arr = $httpfeeds;
1653 1653
         $w = $e = null;
1654 1654
         if (isset($arr[$id])) {
1655
-            $nn = stream_select($arr,$w,$e,$timeout);
1655
+            $nn = stream_select($arr, $w, $e, $timeout);
1656 1656
             if ($nn > 0) {
1657 1657
                 foreach ($httpfeeds as $feed) {
1658
-                    $buffer = stream_get_line($feed,2000,"\n");
1658
+                    $buffer = stream_get_line($feed, 2000, "\n");
1659 1659
                     if ($buffer === FALSE) {
1660 1660
                         connect_all($globalSources);
1661 1661
                     }
1662
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1663
-                    $buffer = explode('\n',$buffer);
1662
+                    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1663
+                    $buffer = explode('\n', $buffer);
1664 1664
                     foreach ($buffer as $line) {
1665 1665
                         if ($line != '') {
1666 1666
                             $line = json_decode($line, true);
@@ -1700,11 +1700,11 @@  discard block
 block discarded – undo
1700 1700
 		    //$value = $formats[$nb];
1701 1701
 		    $format = $globalSources[$nb]['format'];
1702 1702
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1703
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1703
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1704 1704
 		    } elseif ($format === 'vrstcp') {
1705 1705
 			$buffer = @socket_read($r, 6000);
1706 1706
 		    } else {
1707
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1707
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1708 1708
 		    }
1709 1709
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1710 1710
 		    //echo $buffer."\n";
@@ -1714,8 +1714,8 @@  discard block
 block discarded – undo
1714 1714
 		    //$SI::del();
1715 1715
 		    if ($buffer !== FALSE) {
1716 1716
 			if ($format === 'vrstcp') {
1717
-			    $buffer = explode('},{',$buffer);
1718
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1717
+			    $buffer = explode('},{', $buffer);
1718
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1719 1719
 		    }
1720 1720
 		    // SBS format is CSV format
1721 1721
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1742,7 +1742,7 @@  discard block
 block discarded – undo
1742 1742
 			    $ais_data = $AIS->parse_line(trim($buffer));
1743 1743
 			    $data = array();
1744 1744
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1745
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1745
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1746 1746
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1747 1747
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1748 1748
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1753,13 +1753,13 @@  discard block
 block discarded – undo
1753 1753
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1754 1754
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1755 1755
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1756
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1756
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1757 1757
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1758 1758
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1759 1759
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1760 1760
 
1761 1761
 			    if (isset($ais_data['timestamp'])) {
1762
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1762
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1763 1763
 			    } else {
1764 1764
 				$data['datetime'] = date('Y-m-d H:i:s');
1765 1765
 			    }
@@ -1770,10 +1770,10 @@  discard block
 block discarded – undo
1770 1770
                         } elseif ($format === 'flightgearsp') {
1771 1771
                     	    //echo $buffer."\n";
1772 1772
                     	    if (strlen($buffer) > 5) {
1773
-				$line = explode(',',$buffer);
1773
+				$line = explode(',', $buffer);
1774 1774
 				$data = array();
1775 1775
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1776
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1776
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1777 1777
 				$data['ident'] = $line[6];
1778 1778
 				$data['aircraft_name'] = $line[7];
1779 1779
 				$data['longitude'] = $line[1];
@@ -1790,25 +1790,25 @@  discard block
 block discarded – undo
1790 1790
                         } elseif ($format === 'acars') {
1791 1791
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1792 1792
 			    $ACARS->add(trim($buffer));
1793
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1793
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1794 1794
 			    $ACARS->deleteLiveAcarsData();
1795 1795
 			} elseif ($format === 'acarsjsonudp') {
1796 1796
 			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1797 1797
                             $line = json_decode(trim($buffer), true);
1798 1798
                             if (!empty($line)) {
1799
-				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1799
+				$line = array_merge(array('text' => '', 'tail' => '', 'label' => '', 'block_id' => '', 'flight' => '', 'msgno' => ''), $line);
1800 1800
                                 $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1801 1801
                                 $ACARS->deleteLiveAcarsData();
1802 1802
                             }
1803
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1803
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1804 1804
 			} elseif ($format === 'flightgearmp') {
1805
-			    if (substr($buffer,0,1) != '#') {
1805
+			    if (substr($buffer, 0, 1) != '#') {
1806 1806
 				$data = array();
1807 1807
 				//echo $buffer."\n";
1808
-				$line = explode(' ',$buffer);
1808
+				$line = explode(' ', $buffer);
1809 1809
 				if (count($line) === 11) {
1810
-				    $userserver = explode('@',$line[0]);
1811
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1810
+				    $userserver = explode('@', $line[0]);
1811
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1812 1812
 				    $data['ident'] = $userserver[0];
1813 1813
 				    $data['registration'] = $userserver[0];
1814 1814
 				    $data['latitude'] = $line[4];
@@ -1816,8 +1816,8 @@  discard block
 block discarded – undo
1816 1816
 				    $data['altitude'] = $line[6];
1817 1817
 				    $data['datetime'] = date('Y-m-d H:i:s');
1818 1818
 				    $aircraft_type = $line[10];
1819
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1820
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1819
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1820
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1821 1821
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1822 1822
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1823 1823
 				}
@@ -1826,8 +1826,8 @@  discard block
 block discarded – undo
1826 1826
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1827 1827
 			    die;
1828 1828
 			} elseif ($format === 'vrstcp') {
1829
-			    foreach($buffer as $all_data) {
1830
-				$line = json_decode('{'.$all_data.'}',true);
1829
+			    foreach ($buffer as $all_data) {
1830
+				$line = json_decode('{'.$all_data.'}', true);
1831 1831
 				$data = array();
1832 1832
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1833 1833
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1853,16 +1853,16 @@  discard block
 block discarded – undo
1853 1853
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1854 1854
 				unset($data);
1855 1855
 			    }
1856
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1856
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1857 1857
 			    $line = explode("\t", $buffer);
1858
-			    for($k = 0; $k < count($line); $k=$k+2) {
1858
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1859 1859
 				$key = $line[$k];
1860
-			        $lined[$key] = $line[$k+1];
1860
+			        $lined[$key] = $line[$k + 1];
1861 1861
 			    }
1862 1862
     			    if (count($lined) > 3) {
1863 1863
     				$data['hex'] = $lined['hexid'];
1864 1864
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1865
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1865
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1866 1866
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1867 1867
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1868 1868
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1881,23 +1881,23 @@  discard block
 block discarded – undo
1881 1881
     			    } else $error = true;
1882 1882
 			} elseif ($format === 'aprs' && $use_aprs) {
1883 1883
 			    if ($aprs_connect === 0) {
1884
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1884
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1885 1885
 				$aprs_connect = 1;
1886 1886
 			    }
1887 1887
 			    
1888
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1888
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1889 1889
 				$aprs_last_tx = time();
1890 1890
 				$data_aprs = "# Keep alive";
1891
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1891
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1892 1892
 			    }
1893 1893
 			    
1894 1894
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1895 1895
 			    //echo 'APRS data : '.$buffer."\n";
1896
-			    $buffer = str_replace('APRS <- ','',$buffer);
1897
-			    $buffer = str_replace('APRS -> ','',$buffer);
1896
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1897
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1898 1898
 			    //echo $buffer."\n";
1899 1899
 			    date_default_timezone_set('UTC');
1900
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1900
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1901 1901
 				$line = $APRS->parse($buffer);
1902 1902
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1903 1903
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1913 1913
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1914 1914
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1915
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1915
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1916 1916
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1917 1917
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1918 1918
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -2000,29 +2000,29 @@  discard block
 block discarded – undo
2000 2000
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2001 2001
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2002 2002
 					$Source->deleteOldLocationByType('gs');
2003
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2004
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2003
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
2004
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2005 2005
 					} else {
2006
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2006
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2007 2007
 					}
2008 2008
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2009 2009
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2010 2010
 					if ($globalDebug) echo '# Weather Station added'."\n";
2011 2011
 					$Source->deleteOldLocationByType('wx');
2012 2012
 					$weather_data = json_encode($line);
2013
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
2014
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2013
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
2014
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2015 2015
 					} else {
2016
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2016
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2017 2017
 					}
2018 2018
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2019 2019
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2020 2020
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2021 2021
 					$Source->deleteOldLocationByType('lightning');
2022
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2023
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2022
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
2023
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2024 2024
 					} else {
2025
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2025
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2026 2026
 					}
2027 2027
 				    } elseif ($globalDebug) {
2028 2028
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -2031,7 +2031,7 @@  discard block
 block discarded – undo
2031 2031
 				    unset($data);
2032 2032
 				}
2033 2033
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2034
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2034
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
2035 2035
 				}
2036 2036
 				/*
2037 2037
 				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')) {
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
 				*/
2041 2041
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2042 2042
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2043
-				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2043
+				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
2044 2044
 					$Source->deleteOldLocationByType('lightning');
2045 2045
 					$Source->deleteOldLocationByType('wx');
2046 2046
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -2127,7 +2127,7 @@  discard block
 block discarded – undo
2127 2127
 				connect_all($sourceee);
2128 2128
 				$sourceee = array();
2129 2129
 				//connect_all($globalSources);
2130
-				$tt[$format]=0;
2130
+				$tt[$format] = 0;
2131 2131
 				break;
2132 2132
 			    } 
2133 2133
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -2137,14 +2137,14 @@  discard block
 block discarded – undo
2137 2137
 	    } else {
2138 2138
 		$error = socket_strerror(socket_last_error());
2139 2139
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2140
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2140
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
2141 2141
 			if (isset($globalDebug)) echo "Restarting...\n";
2142 2142
 			// Restart the script if possible
2143 2143
 			if (is_array($sockets)) {
2144 2144
 			    if ($globalDebug) echo "Shutdown all sockets...";
2145 2145
 			    
2146 2146
 			    foreach ($sockets as $sock) {
2147
-				@socket_shutdown($sock,2);
2147
+				@socket_shutdown($sock, 2);
2148 2148
 				@socket_close($sock);
2149 2149
 			    }
2150 2150
 			    
Please login to merge, or discard this patch.
Braces   +1269 added lines, -427 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
26 28
 
27 29
 if ($globalInstalled === FALSE) {
28 30
     echo "This script MUST be run after install script. Use your web browser to run install/index.php";
@@ -68,66 +70,107 @@  discard block
 block discarded – undo
68 70
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 71
 if (isset($options['s'])) {
70 72
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
73
-} elseif (isset($options['source'])) {
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['s']);
77
+    }
78
+    } elseif (isset($options['source'])) {
74 79
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
77
-}
80
+    if (isset($options['format'])) {
81
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
82
+    } else {
83
+    	$globalSources[] = array('host' => $options['source']);
84
+    }
85
+    }
78 86
 if (isset($options['aprsserverhost'])) {
79 87
 	$globalServerAPRS = TRUE;
80 88
 	$globalServerAPRShost = $options['aprsserverhost'];
81 89
 }
82
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
83
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
84
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
85
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
90
+if (isset($options['aprsserverport'])) {
91
+	$globalServerAPRSport = $options['aprsserverport'];
92
+}
93
+if (isset($options['aprsserverssid'])) {
94
+	$globalServerAPRSssid = $options['aprsserverssid'];
95
+}
96
+if (isset($options['aprsserverpass'])) {
97
+	$globalServerAPRSpass = $options['aprsserverpass'];
98
+}
99
+if (isset($options['noaprsserver'])) {
100
+	$globalServerAPRS = FALSE;
101
+}
86 102
 if (isset($options['enable-aircraft'])) {
87
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
103
+	if ($globalDebug) {
104
+		echo 'Enable Aircraft mode'."\n";
105
+	}
88 106
 	$globalAircraft = TRUE; 
89 107
 }
90 108
 if (isset($options['disable-aircraft'])) {
91
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
109
+	if ($globalDebug) {
110
+		echo 'Disable Aircraft mode'."\n";
111
+	}
92 112
 	$globalAircraft = FALSE;
93 113
 }
94 114
 if (isset($options['enable-tracker'])) {
95
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
115
+	if ($globalDebug) {
116
+		echo 'Enable Tracker mode'."\n";
117
+	}
96 118
 	$globalTracker = TRUE; 
97 119
 }
98 120
 if (isset($options['disable-tracker'])) {
99
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
121
+	if ($globalDebug) {
122
+		echo 'Disable Tracker mode'."\n";
123
+	}
100 124
 	$globalTracker = FALSE;
101 125
 }
102 126
 if (isset($options['enable-marine'])) {
103
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
127
+	if ($globalDebug) {
128
+		echo 'Enable Marine mode'."\n";
129
+	}
104 130
 	$globalMarine = TRUE;
105 131
 }
106 132
 if (isset($options['disable-marine'])) {
107
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
133
+	if ($globalDebug) {
134
+		echo 'Disable Marine mode'."\n";
135
+	}
108 136
 	$globalMarine = FALSE;
109 137
 }
110
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
111
-if (isset($options['server'])) $globalServer = TRUE;
112
-if (isset($options['idsource'])) $id_source = $options['idsource'];
113
-else $id_source = 1;
138
+if (isset($options['nodaemon'])) {
139
+	$globalDaemon = FALSE;
140
+}
141
+if (isset($options['server'])) {
142
+	$globalServer = TRUE;
143
+}
144
+if (isset($options['idsource'])) {
145
+	$id_source = $options['idsource'];
146
+} else {
147
+	$id_source = 1;
148
+}
114 149
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
150
+    if ($globalDebug) {
151
+    	echo "Using Server Mode\n";
152
+    }
116 153
     $SI=new SpotterServer();
117 154
 /*
118 155
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 156
     $SI = new adsb2aprs();
120 157
     $SI->connect();
121 158
 */
122
-} else $SI=new SpotterImport($Connection->db);
159
+} else {
160
+	$SI=new SpotterImport($Connection->db);
161
+}
123 162
 
124
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
163
+if (isset($globalTracker) && $globalTracker) {
164
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
165
+}
125 166
 if (isset($globalMarine) && $globalMarine) {
126 167
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
127 168
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 169
 }
129 170
 
130
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
171
+if (isset($globalTracker) && $globalTracker) {
172
+	$TI = new TrackerImport($Connection->db);
173
+}
131 174
 if (isset($globalMarine) && $globalMarine) {
132 175
     $AIS = new AIS();
133 176
     $MI = new MarineImport($Connection->db);
@@ -152,7 +195,9 @@  discard block
 block discarded – undo
152 195
 }
153 196
 
154 197
 // let's try and connect
155
-if ($globalDebug) echo "Connecting...\n";
198
+if ($globalDebug) {
199
+	echo "Connecting...\n";
200
+}
156 201
 $use_aprs = false;
157 202
 $aprs_full = false;
158 203
 $reset = 0;
@@ -161,7 +206,9 @@  discard block
 block discarded – undo
161 206
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162 207
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163 208
     $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
209
+    if ($globalDebug) {
210
+    	echo 'Connect to all...'."\n";
211
+    }
165 212
     foreach ($hosts as $id => $value) {
166 213
 	$host = $value['host'];
167 214
 	$udp = false;
@@ -172,32 +219,44 @@  discard block
 block discarded – undo
172 219
         	//$formats[$id] = 'deltadbtxt';
173 220
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 221
         	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to deltadb source (".$host.")...\n";
224
+        	}
176 225
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177 226
         	//$formats[$id] = 'vatsimtxt';
178 227
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 228
         	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to vatsim source (".$host.")...\n";
231
+        	}
181 232
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182 233
         	//$formats[$id] = 'aircraftlistjson';
183 234
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 235
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
238
+        	}
186 239
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
187 240
         	//$formats[$id] = 'aircraftjson';
188 241
         	$globalSources[$id]['format'] = 'aircraftjson';
189 242
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
243
+        	if ($globalDebug) {
244
+        		echo "Connect to aircraft.json source (".$host.")...\n";
245
+        	}
191 246
     	    } else if (preg_match('/aircraft$/i',$host)) {
192 247
         	//$formats[$id] = 'planefinderclient';
193 248
         	$globalSources[$id]['format'] = 'planefinderclient';
194 249
         	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
250
+        	if ($globalDebug) {
251
+        		echo "Connect to planefinderclient source (".$host.")...\n";
252
+        	}
196 253
     	    } else if (preg_match('/opensky/i',$host)) {
197 254
         	//$formats[$id] = 'aircraftlistjson';
198 255
         	$globalSources[$id]['format'] = 'opensky';
199 256
         	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
257
+        	if ($globalDebug) {
258
+        		echo "Connect to opensky source (".$host.")...\n";
259
+        	}
201 260
     	    /*
202 261
     	    // Disabled for now, site change source format
203 262
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -214,7 +273,9 @@  discard block
 block discarded – undo
214 273
         	//$formats[$id] = 'planeupdatefaa';
215 274
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 275
         	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
276
+        	if ($globalDebug) {
277
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
278
+        	}
218 279
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219 280
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 281
         	    exit(0);
@@ -223,37 +284,53 @@  discard block
 block discarded – undo
223 284
         	//$formats[$id] = 'phpvmacars';
224 285
         	$globalSources[$id]['format'] = 'phpvmacars';
225 286
         	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
287
+        	if ($globalDebug) {
288
+        		echo "Connect to phpvmacars source (".$host.")...\n";
289
+        	}
227 290
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228 291
         	//$formats[$id] = 'phpvmacars';
229 292
         	$globalSources[$id]['format'] = 'vaos';
230 293
         	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
294
+        	if ($globalDebug) {
295
+        		echo "Connect to vaos source (".$host.")...\n";
296
+        	}
232 297
             } else if (preg_match('/VAM-json.php$/i',$host)) {
233 298
         	//$formats[$id] = 'phpvmacars';
234 299
         	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
300
+        	if ($globalDebug) {
301
+        		echo "Connect to Vam source (".$host.")...\n";
302
+        	}
236 303
             } else if (preg_match('/whazzup/i',$host)) {
237 304
         	//$formats[$id] = 'whazzup';
238 305
         	$globalSources[$id]['format'] = 'whazzup';
239 306
         	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
307
+        	if ($globalDebug) {
308
+        		echo "Connect to whazzup source (".$host.")...\n";
309
+        	}
241 310
             } else if (preg_match('/blitzortung/i',$host)) {
242 311
         	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
312
+        	if ($globalDebug) {
313
+        		echo "Connect to blitzortung source (".$host.")...\n";
314
+        	}
244 315
             } else if (preg_match('/airwhere/i',$host)) {
245 316
         	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
317
+        	if ($globalDebug) {
318
+        		echo "Connect to airwhere source (".$host.")...\n";
319
+        	}
247 320
             } else if (preg_match('/recentpireps/i',$host)) {
248 321
         	//$formats[$id] = 'pirepsjson';
249 322
         	$globalSources[$id]['format'] = 'pirepsjson';
250 323
         	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
324
+        	if ($globalDebug) {
325
+        		echo "Connect to pirepsjson source (".$host.")...\n";
326
+        	}
252 327
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253 328
         	//$formats[$id] = 'fr24json';
254 329
         	$globalSources[$id]['format'] = 'fr24json';
255 330
         	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
331
+        	if ($globalDebug) {
332
+        		echo "Connect to fr24 source (".$host.")...\n";
333
+        	}
257 334
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258 335
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 336
         	    exit(0);
@@ -262,7 +339,9 @@  discard block
 block discarded – undo
262 339
         	//$formats[$id] = 'fr24json';
263 340
         	$globalSources[$id]['format'] = 'myshiptracking';
264 341
         	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
342
+        	if ($globalDebug) {
343
+        		echo "Connect to myshiptracking source (".$host.")...\n";
344
+        	}
266 345
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267 346
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268 347
         	    exit(0);
@@ -271,18 +350,28 @@  discard block
 block discarded – undo
271 350
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 351
         	//$formats[$id] = 'tsv';
273 352
         	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
353
+        	if ($globalDebug) {
354
+        		echo "Connect to tsv source (".$host.")...\n";
355
+        	}
275 356
             }
276 357
         } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 358
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278 359
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279 360
     		    if ($idf !== false) {
280 361
     			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
362
+        		if ($globalDebug) {
363
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
364
+        		}
365
+    		    } elseif ($globalDebug) {
366
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
367
+    		    }
368
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') {
369
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
370
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') {
371
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
372
+    		} elseif ($globalDebug) {
373
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
374
+    		}
286 375
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287 376
 	    $hostport = explode(':',$host);
288 377
 	    if (isset($hostport[1])) {
@@ -323,20 +412,29 @@  discard block
 block discarded – undo
323 412
         		//$formats[$id] = 'beast';
324 413
         		$globalSources[$id]['format'] = 'beast';
325 414
 		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
415
+		    } else {
416
+		    	$globalSources[$id]['format'] = 'sbs';
417
+		    }
327 418
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 419
 		}
329
-		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330
-		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
420
+		if ($globalDebug && $udp) {
421
+			echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
422
+		} elseif ($globalDebug) {
423
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
424
+		}
331 425
             } else {
332
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
426
+		if ($globalDebug) {
427
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
428
+		}
333 429
 		sleep(10);
334 430
 		connect_all($hosts);
335 431
     	    }
336 432
         }
337 433
     }
338 434
 }
339
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
435
+if (!isset($globalMinFetch)) {
436
+	$globalMinFetch = 15;
437
+}
340 438
 
341 439
 // Initialize all
342 440
 $status = array();
@@ -345,13 +443,19 @@  discard block
 block discarded – undo
345 443
 $formats = array();
346 444
 $last_exec = array();
347 445
 $time = time();
348
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
349
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350
-else $timeout = 20;
446
+if (isset($globalSourcesTimeout)) {
447
+	$timeout = $globalSourcesTimeOut;
448
+} else if (isset($globalSBS1TimeOut)) {
449
+	$timeout = $globalSBS1TimeOut;
450
+} else {
451
+	$timeout = 20;
452
+}
351 453
 $errno = '';
352 454
 $errstr='';
353 455
 
354
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
456
+if (!isset($globalDaemon)) {
457
+	$globalDaemon = TRUE;
458
+}
355 459
 /* Initiate connections to all the hosts simultaneously */
356 460
 //connect_all($hosts);
357 461
 //connect_all($globalSources);
@@ -380,7 +484,9 @@  discard block
 block discarded – undo
380 484
     if (isset($source['format']) && $source['format'] == 'aprs') {
381 485
 	$aprs_connect = 0;
382 486
 	$use_aprs = true;
383
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
487
+	if (isset($source['port']) && $source['port'] == '10152') {
488
+		$aprs_full = true;
489
+	}
384 490
 	break;
385 491
     }
386 492
 }
@@ -391,25 +497,46 @@  discard block
 block discarded – undo
391 497
 	$aprs_connect = 0;
392 498
 	$aprs_keep = 120;
393 499
 	$aprs_last_tx = time();
394
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
396
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
398
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400
-	if ($aprs_full) $aprs_filter = '';
401
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalAPRSssid)) {
506
+		$aprs_ssid = $globalAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalAPRSfilter)) {
511
+		$aprs_filter = $globalAPRSfilter;
512
+	} else {
513
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
514
+	}
515
+	if ($aprs_full) {
516
+		$aprs_filter = '';
517
+	}
518
+	if (isset($globalAPRSpass)) {
519
+		$aprs_pass = $globalAPRSpass;
520
+	} else {
521
+		$aprs_pass = '-1';
522
+	}
403 523
 
404
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
405
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
406
-}
524
+	if ($aprs_filter != '') {
525
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
526
+	} else {
527
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
528
+	}
529
+	}
407 530
 
408 531
 // connected - lets do some work
409 532
 //if ($globalDebug) echo "Connected!\n";
410 533
 sleep(1);
411
-if ($globalDebug) echo "SCAN MODE \n\n";
412
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
534
+if ($globalDebug) {
535
+	echo "SCAN MODE \n\n";
536
+}
537
+if (!isset($globalCronEnd)) {
538
+	$globalCronEnd = 60;
539
+}
413 540
 $endtime = time()+$globalCronEnd;
414 541
 $i = 1;
415 542
 $tt = array();
@@ -423,22 +550,32 @@  discard block
 block discarded – undo
423 550
 
424 551
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 552
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
553
+    if (function_exists('pcntl_fork')) {
554
+    	pcntl_signal_dispatch();
555
+    }
427 556
 
428
-    if (!$globalDaemon) $i = $endtime-time();
557
+    if (!$globalDaemon) {
558
+    	$i = $endtime-time();
559
+    }
429 560
     // Delete old ATC
430 561
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
562
+	if ($globalDebug) {
563
+		echo 'Delete old ATC...'."\n";
564
+	}
432 565
         $ATC->deleteOldATC();
433 566
     }
434 567
     
435 568
     if (count($last_exec) == count($globalSources)) {
436 569
 	$max = $globalMinFetch;
437 570
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
571
+	    if ((time() - $last['last']) < $max) {
572
+	    	$max = time() - $last['last'];
573
+	    }
439 574
 	}
440 575
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
576
+	    if ($globalDebug) {
577
+	    	echo 'Sleeping...'."\n";
578
+	    }
442 579
 	    sleep($globalMinFetch-$max+2);
443 580
 	}
444 581
     }
@@ -448,7 +585,9 @@  discard block
 block discarded – undo
448 585
     foreach ($globalSources as $id => $value) {
449 586
 	date_default_timezone_set('UTC');
450 587
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
588
+	if (!isset($last_exec[$id]['last'])) {
589
+		$last_exec[$id]['last'] = 0;
590
+	}
452 591
 	if ($value['format'] === 'deltadbtxt' && 
453 592
 	    (
454 593
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -457,7 +596,9 @@  discard block
 block discarded – undo
457 596
 	) {
458 597
         //$buffer = $Common->getData($hosts[$id]);
459 598
         $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
599
+        if ($buffer != '') {
600
+        	$reset = 0;
601
+        }
461 602
         $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462 603
         $buffer = explode('\n', $buffer);
463 604
         foreach ($buffer as $line) {
@@ -466,20 +607,41 @@  discard block
 block discarded – undo
466 607
                 $data = array();
467 608
                 $data['hex'] = $line[1]; // hex
468 609
                 $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
610
+                if (isset($line[3])) {
611
+                	$data['altitude'] = $line[3];
612
+                }
613
+                // altitude
614
+                if (isset($line[4])) {
615
+                	$data['speed'] = $line[4];
616
+                }
617
+                // speed
618
+                if (isset($line[5])) {
619
+                	$data['heading'] = $line[5];
620
+                }
621
+                // heading
622
+                if (isset($line[6])) {
623
+                	$data['latitude'] = $line[6];
624
+                }
625
+                // lat
626
+                if (isset($line[7])) {
627
+                	$data['longitude'] = $line[7];
628
+                }
629
+                // long
474 630
                 $data['verticalrate'] = ''; // vertical rate
475 631
                 //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476 632
                 $data['emergency'] = ''; // emergency
477 633
                 $data['datetime'] = date('Y-m-d H:i:s');
478 634
                 $data['format_source'] = 'deltadbtxt';
479 635
                 $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
636
+                if (isset($value['name']) && $value['name'] != '') {
637
+                	$data['source_name'] = $value['name'];
638
+                }
639
+                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
640
+                	$data['noarchive'] = true;
641
+                }
642
+                if (isset($value['sourcestats'])) {
643
+                	$data['sourcestats'] = $value['sourcestats'];
644
+                }
483 645
                 $SI->add($data);
484 646
                 unset($data);
485 647
             }
@@ -514,11 +676,20 @@  discard block
 block discarded – undo
514 676
                     $data['format_source'] = 'radarcapejson';
515 677
                     $data['id_source'] = $id_source;
516 678
                     if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
679
+                        if (isset($line['src']) && !$line['src'] == 'M') {
680
+                        	$data['source_name'] = $value['name'].'_MLAT';
681
+                        } else {
682
+                        	$data['source_name'] = $value['name'];
683
+                        }
684
+                    } elseif (isset($line['src']) && $line['src'] == 'M') {
685
+                    	$data['source_name'] = 'MLAT';
686
+                    }
687
+                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
688
+                    	$data['noarchive'] = true;
689
+                    }
690
+                    if (isset($value['sourcestats'])) {
691
+                    	$data['sourcestats'] = $value['sourcestats'];
692
+                    }
522 693
 
523 694
                     $SI->add($data);
524 695
                     unset($data);
@@ -534,7 +705,9 @@  discard block
 block discarded – undo
534 705
 	    date_default_timezone_set('CET');
535 706
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536 707
 	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
708
+	    if ($buffer != '') {
709
+	    	$reset = 0;
710
+	    }
538 711
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539 712
 	    $buffer = explode('\n',$buffer);
540 713
 	    foreach ($buffer as $line) {
@@ -543,18 +716,42 @@  discard block
 block discarded – undo
543 716
 		    $add = false;
544 717
 		    $ais_data = $AIS->parse_line(trim($line));
545 718
 		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
719
+		    if (isset($ais_data['ident'])) {
720
+		    	$data['ident'] = $ais_data['ident'];
721
+		    }
722
+		    if (isset($ais_data['mmsi'])) {
723
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
724
+		    }
725
+		    if (isset($ais_data['speed'])) {
726
+		    	$data['speed'] = $ais_data['speed'];
727
+		    }
728
+		    if (isset($ais_data['heading'])) {
729
+		    	$data['heading'] = $ais_data['heading'];
730
+		    }
731
+		    if (isset($ais_data['latitude'])) {
732
+		    	$data['latitude'] = $ais_data['latitude'];
733
+		    }
734
+		    if (isset($ais_data['longitude'])) {
735
+		    	$data['longitude'] = $ais_data['longitude'];
736
+		    }
737
+		    if (isset($ais_data['status'])) {
738
+		    	$data['status'] = $ais_data['status'];
739
+		    }
740
+		    if (isset($ais_data['statusid'])) {
741
+		    	$data['status_id'] = $ais_data['statusid'];
742
+		    }
743
+		    if (isset($ais_data['type'])) {
744
+		    	$data['type'] = $ais_data['type'];
745
+		    }
746
+		    if (isset($ais_data['typeid'])) {
747
+		    	$data['type_id'] = $ais_data['typeid'];
748
+		    }
749
+		    if (isset($ais_data['imo'])) {
750
+		    	$data['imo'] = $ais_data['imo'];
751
+		    }
752
+		    if (isset($ais_data['callsign'])) {
753
+		    	$data['callsign'] = $ais_data['callsign'];
754
+		    }
558 755
 		    if (isset($ais_data['timestamp'])) {
559 756
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 757
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -568,8 +765,12 @@  discard block
 block discarded – undo
568 765
 		    $data['format_source'] = 'aisnmeatxt';
569 766
     		    $data['id_source'] = $id_source;
570 767
 		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
768
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
769
+		    	$data['noarchive'] = true;
770
+		    }
771
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
772
+		    	$MI->add($data);
773
+		    }
573 774
 		    unset($data);
574 775
 		}
575 776
     	    }
@@ -592,20 +793,48 @@  discard block
 block discarded – undo
592 793
 			    if ($line != '') {
593 794
 				$ais_data = $AIS->parse_line(trim($line));
594 795
 				$data = array();
595
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
597
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
600
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
601
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
602
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
603
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
604
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
605
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
796
+				if (isset($ais_data['ident'])) {
797
+					$data['ident'] = $ais_data['ident'];
798
+				}
799
+				if (isset($ais_data['mmsi'])) {
800
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
801
+				}
802
+				if (isset($ais_data['speed'])) {
803
+					$data['speed'] = $ais_data['speed'];
804
+				}
805
+				if (isset($ais_data['heading'])) {
806
+					$data['heading'] = $ais_data['heading'];
807
+				}
808
+				if (isset($ais_data['latitude'])) {
809
+					$data['latitude'] = $ais_data['latitude'];
810
+				}
811
+				if (isset($ais_data['longitude'])) {
812
+					$data['longitude'] = $ais_data['longitude'];
813
+				}
814
+				if (isset($ais_data['status'])) {
815
+					$data['status'] = $ais_data['status'];
816
+				}
817
+				if (isset($ais_data['statusid'])) {
818
+					$data['status_id'] = $ais_data['statusid'];
819
+				}
820
+				if (isset($ais_data['type'])) {
821
+					$data['type'] = $ais_data['type'];
822
+				}
823
+				if (isset($ais_data['typeid'])) {
824
+					$data['type_id'] = $ais_data['typeid'];
825
+				}
826
+				if (isset($ais_data['imo'])) {
827
+					$data['imo'] = $ais_data['imo'];
828
+				}
829
+				if (isset($ais_data['callsign'])) {
830
+					$data['callsign'] = $ais_data['callsign'];
831
+				}
832
+				if (isset($ais_data['destination'])) {
833
+					$data['arrival_code'] = $ais_data['destination'];
834
+				}
835
+				if (isset($ais_data['eta_ts'])) {
836
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
837
+				}
609 838
 				if (isset($ais_data['timestamp'])) {
610 839
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 840
 				} else {
@@ -613,18 +842,27 @@  discard block
 block discarded – undo
613 842
 				}
614 843
 				$data['format_source'] = 'aisnmeahttp';
615 844
 				$data['id_source'] = $id_source;
616
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
845
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
846
+					$data['noarchive'] = true;
847
+				}
848
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
849
+					$MI->add($data);
850
+				}
618 851
 				unset($data);
619 852
 			    }
620 853
 			}
621 854
 		    }
622 855
 		} else {
623 856
 		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
857
+		    if (isset($tt[$format])) {
858
+		    	$tt[$format]++;
859
+		    } else {
860
+		    	$tt[$format] = 0;
861
+		    }
626 862
 		    if ($tt[$format] > 30) {
627
-			if ($globalDebug) echo 'Reconnect...'."\n";
863
+			if ($globalDebug) {
864
+				echo 'Reconnect...'."\n";
865
+			}
628 866
 			sleep(2);
629 867
 			//$sourceeen[] = $value;
630 868
 			//connect_all($sourceeen);
@@ -660,12 +898,18 @@  discard block
 block discarded – undo
660 898
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661 899
 			    //$data['type_id'] = $line['TYPE'];
662 900
 			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
901
+			    if ($line['DEST'] != '') {
902
+			    	$data['arrival_code'] = $line['DEST'];
903
+			    }
904
+			    if ($line['ARV'] != '') {
905
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
906
+			    }
665 907
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666 908
 			    $data['format_source'] = 'myshiptracking';
667 909
 			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
910
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
911
+			    	$data['noarchive'] = true;
912
+			    }
669 913
 			    $MI->add($data);
670 914
 			    unset($data);
671 915
 			}
@@ -690,7 +934,9 @@  discard block
 block discarded – undo
690 934
 			    $data['callsign'] = $line['callsign'];
691 935
 			    $data['mmsi'] = substr($line['mmsi'],-9);
692 936
 			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
937
+			    if ($line['heading'] != '511') {
938
+			    	$data['heading'] = $line['heading'];
939
+			    }
694 940
 			    $data['latitude'] = $line['latitude'];
695 941
 			    $data['longitude'] = $line['longitude'];
696 942
 			    $data['type_id'] = $line['shiptype'];
@@ -698,7 +944,9 @@  discard block
 block discarded – undo
698 944
 			    $data['datetime'] = $line['time'];
699 945
 			    $data['format_source'] = 'boatbeaconapp';
700 946
 			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
948
+			    	$data['noarchive'] = true;
949
+			    }
702 950
 			    $MI->add($data);
703 951
 			    unset($data);
704 952
 			}
@@ -720,22 +968,44 @@  discard block
 block discarded – undo
720 968
 		    foreach ($all_data['features'] as $line) {
721 969
 			print_r($line);
722 970
 			$data = array();
723
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
726
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
971
+			if (isset($line['properties']['name'])) {
972
+				$data['ident'] = $line['properties']['name'];
973
+			}
974
+			if (isset($line['properties']['callsign'])) {
975
+				$data['callsign'] = $line['properties']['callsign'];
976
+			}
977
+			if (isset($line['properties']['mmsi'])) {
978
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
979
+			}
980
+			if (isset($line['properties']['imo'])) {
981
+				$data['imo'] = $line['properties']['imo'];
982
+			}
983
+			if (isset($line['properties']['speed'])) {
984
+				$data['speed'] = $line['properties']['speed'];
985
+			}
986
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
987
+				$data['heading'] = $line['properties']['heading'];
988
+			}
729 989
 			$data['latitude'] = $line['geometry']['coordinates'][1];
730 990
 			$data['longitude'] = $line['geometry']['coordinates'][0];
731
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
732
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
733
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
991
+			if (isset($line['properties']['vesselType'])) {
992
+				$data['type'] = $line['properties']['vesselType'];
993
+			}
994
+			if (isset($line['properties']['destination'])) {
995
+				$data['arrival_code'] = $line['properties']['destination'];
996
+			}
997
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
998
+				$data['arrival_date'] = $line['properties']['eta'];
999
+			}
734 1000
 			$data['format_source'] = 'boatnerd';
735 1001
 			$data['id_source'] = $id_source;
736 1002
 			$data['datetime'] = date('Y-m-d H:i:s');
737
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
1003
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1004
+				$data['noarchive'] = true;
1005
+			}
1006
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
1007
+				$MI->add($data);
1008
+			}
739 1009
 			unset($data);
740 1010
 		    }
741 1011
 		}
@@ -748,11 +1018,17 @@  discard block
 block discarded – undo
748 1018
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749 1019
 	    )
750 1020
 	) {
751
-	    if ($globalDebug) echo 'download...';
1021
+	    if ($globalDebug) {
1022
+	    	echo 'download...';
1023
+	    }
752 1024
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
1025
+	    if ($globalDebug) {
1026
+	    	echo 'done !'."\n";
1027
+	    }
754 1028
 	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
1029
+	    if ($buffer != '') {
1030
+	    	$reset = 0;
1031
+	    }
756 1032
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757 1033
 	    $buffer = explode('\n',$buffer);
758 1034
 	    foreach ($buffer as $line) {
@@ -778,7 +1054,9 @@  discard block
 block discarded – undo
778 1054
 		    //$data['etaTime'] = substr($line,135,5);
779 1055
 		    $data['format_source'] = 'shipplotter';
780 1056
     		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1057
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1058
+		    	$data['noarchive'] = true;
1059
+		    }
782 1060
 		    //print_r($data);
783 1061
 		    //echo 'Add...'."\n";
784 1062
 		    $MI->add($data);
@@ -796,13 +1074,21 @@  discard block
 block discarded – undo
796 1074
 		exit(0);
797 1075
 	    }
798 1076
 	    $sailawayoption = array('key' => $globalSailaway['key']);
799
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
800
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1077
+	    if (isset($globalSailaway['usrnr'])) {
1078
+	    	$sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
1079
+	    }
1080
+	    if (isset($globalSailaway['ubtnr'])) {
1081
+	    	$sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1082
+	    }
801 1083
 
802 1084
 	    for ($i = 0; $i <= 1; $i++) {
803
-		if ($globalDebug) echo '! Download... ';
1085
+		if ($globalDebug) {
1086
+			echo '! Download... ';
1087
+		}
804 1088
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race='.$i.'&tutorial=0&hist=1&racetype=2&challengetype=2');
805
-		if ($globalDebug) echo 'done'."\n";
1089
+		if ($globalDebug) {
1090
+			echo 'done'."\n";
1091
+		}
806 1092
 		if ($buffer != '') {
807 1093
 		    $all_data = json_decode($buffer,true);
808 1094
 		    if (isset($all_data['missions'])) {
@@ -845,7 +1131,9 @@  discard block
 block discarded – undo
845 1131
 			$data = array();
846 1132
 			$data['id'] = $sail['ubtnr'];
847 1133
 			$data['datetime'] = date('Y-m-d H:i:s');
848
-			if ($sail['online'] == '1') $data['last_update'] = date('Y-m-d H:i:s');
1134
+			if ($sail['online'] == '1') {
1135
+				$data['last_update'] = date('Y-m-d H:i:s');
1136
+			}
849 1137
 			$data['latitude'] = $sail['ubtlat'];
850 1138
 			$data['longitude'] = $sail['ubtlon'];
851 1139
 			$data['type_id'] = 36;
@@ -854,16 +1142,24 @@  discard block
 block discarded – undo
854 1142
 			$data['captain_name'] = $sail['usrname'];
855 1143
 			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
856 1144
 			$boattype = $sail['ubtbtpnr'];
857
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
1145
+			if (isset($allboats[$boattype-1])) {
1146
+				$data['type'] = $allboats[$boattype-1];
1147
+			}
858 1148
 			$data['speed'] = round($sail['ubtspeed']*3.6,2);
859 1149
 			$data['format_source'] = 'sailaway';
860 1150
 			$data['id_source'] = $id_source;
861
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1151
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1152
+				$data['noarchive'] = true;
1153
+			}
862 1154
 			$MI->add($data);
863 1155
 			unset($data);
864 1156
 		    }
865
-		} elseif ($globalDebug) echo 'Error in JSON parsing';
866
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
1157
+		} elseif ($globalDebug) {
1158
+			echo 'Error in JSON parsing';
1159
+		}
1160
+	    } elseif ($globalDebug) {
1161
+	    	echo 'Empty result !'."\n";
1162
+	    }
867 1163
 
868 1164
     	    $last_exec[$id]['last'] = time();
869 1165
 	} elseif ($value['format'] === 'sailaway' && 
@@ -886,10 +1182,16 @@  discard block
 block discarded – undo
886 1182
 		echo 'Sailaway API key MUST be defined';
887 1183
 		exit(0);
888 1184
 	    }
889
-	    if ($globalDebug) echo '! Download... ';
1185
+	    if ($globalDebug) {
1186
+	    	echo '! Download... ';
1187
+	    }
890 1188
 	    $sailawayoption = array('key' => $globalSailaway['key']);
891
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
892
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1189
+	    if (isset($globalSailaway['usrnr'])) {
1190
+	    	$sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
1191
+	    }
1192
+	    if (isset($globalSailaway['ubtnr'])) {
1193
+	    	$sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1194
+	    }
893 1195
 	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
894 1196
 	    if ($buffer != '') {
895 1197
 		$data = json_decode($buffer,true);
@@ -899,7 +1201,9 @@  discard block
 block discarded – undo
899 1201
 			$data = array();
900 1202
 			$data['id'] = $sail['ubtnr'];
901 1203
 			$data['datetime'] = date('Y-m-d H:i:s');
902
-			if ($sail['online'] == '1') $data['last_update'] = date('Y-m-d H:i:s');
1204
+			if ($sail['online'] == '1') {
1205
+				$data['last_update'] = date('Y-m-d H:i:s');
1206
+			}
903 1207
 			$data['latitude'] = $sail['ubtlat'];
904 1208
 			$data['longitude'] = $sail['ubtlon'];
905 1209
 			$data['type_id'] = 36;
@@ -908,16 +1212,24 @@  discard block
 block discarded – undo
908 1212
 			$data['captain_name'] = $sail['usrname'];
909 1213
 			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
910 1214
 			$boattype = $sail['ubtbtpnr'];
911
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
1215
+			if (isset($allboats[$boattype-1])) {
1216
+				$data['type'] = $allboats[$boattype-1];
1217
+			}
912 1218
 			$data['speed'] = round($sail['ubtspeed']*3.6,2);
913 1219
 			$data['format_source'] = 'sailaway';
914 1220
 			$data['id_source'] = $id_source;
915
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1221
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1222
+				$data['noarchive'] = true;
1223
+			}
916 1224
 			$MI->add($data);
917 1225
 			unset($data);
918 1226
 		    }
919
-		} elseif ($globalDebug) echo 'Error in JSON parsing';
920
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
1227
+		} elseif ($globalDebug) {
1228
+			echo 'Error in JSON parsing';
1229
+		}
1230
+	    } elseif ($globalDebug) {
1231
+	    	echo 'Empty result !'."\n";
1232
+	    }
921 1233
     	    $last_exec[$id]['last'] = time();
922 1234
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
923 1235
 	} elseif (
@@ -945,16 +1257,28 @@  discard block
 block discarded – undo
945 1257
     		    $line = explode(':', $line);
946 1258
     		    if (count($line) > 30 && $line[0] != 'callsign') {
947 1259
 			$data = array();
948
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
949
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1260
+			if (isset($line[37]) && $line[37] != '') {
1261
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1262
+			} else {
1263
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1264
+			}
950 1265
 			$data['pilot_id'] = $line[1];
951 1266
 			$data['pilot_name'] = $line[2];
952 1267
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
953 1268
 			$data['ident'] = $line[0]; // ident
954
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1269
+			if ($line[7] != '' && $line[7] != 0) {
1270
+				$data['altitude'] = $line[7];
1271
+			}
1272
+			// altitude
955 1273
 			$data['speed'] = $line[8]; // speed
956
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
957
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1274
+			if (isset($line[45])) {
1275
+				$data['heading'] = $line[45];
1276
+			}
1277
+			// heading
1278
+			elseif (isset($line[38])) {
1279
+				$data['heading'] = $line[38];
1280
+			}
1281
+			// heading
958 1282
 			$data['latitude'] = $line[5]; // lat
959 1283
 	        	$data['longitude'] = $line[6]; // long
960 1284
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -970,7 +1294,9 @@  discard block
 block discarded – undo
970 1294
 			$data['frequency'] = $line[4];
971 1295
 			$data['type'] = $line[18];
972 1296
 			$data['range'] = $line[19];
973
-			if (isset($line[35])) $data['info'] = $line[35];
1297
+			if (isset($line[35])) {
1298
+				$data['info'] = $line[35];
1299
+			}
974 1300
     			$data['id_source'] = $id_source;
975 1301
 	    		//$data['arrival_airport_time'] = ;
976 1302
 	    		if ($line[9] != '') {
@@ -984,27 +1310,47 @@  discard block
 block discarded – undo
984 1310
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
985 1311
 	    		*/
986 1312
 	    		$data['format_source'] = $value['format'];
987
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
988
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
-    			if ($line[3] === 'PILOT') $SI->add($data);
990
-			elseif ($line[3] === 'ATC') {
1313
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1314
+				$data['noarchive'] = true;
1315
+			}
1316
+			if (isset($value['name']) && $value['name'] != '') {
1317
+				$data['source_name'] = $value['name'];
1318
+			}
1319
+    			if ($line[3] === 'PILOT') {
1320
+    				$SI->add($data);
1321
+    			} elseif ($line[3] === 'ATC') {
991 1322
 				//print_r($data);
992 1323
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
993 1324
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
994 1325
 				$typec = substr($data['ident'],-3);
995
-				if ($typec === 'APP') $data['type'] = 'Approach';
996
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
997
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
998
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
999
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1000
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
1001
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1002
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1003
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
1004
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1326
+				if ($typec === 'APP') {
1327
+					$data['type'] = 'Approach';
1328
+				} elseif ($typec === 'TWR') {
1329
+					$data['type'] = 'Tower';
1330
+				} elseif ($typec === 'OBS') {
1331
+					$data['type'] = 'Observer';
1332
+				} elseif ($typec === 'GND') {
1333
+					$data['type'] = 'Ground';
1334
+				} elseif ($typec === 'DEL') {
1335
+					$data['type'] = 'Delivery';
1336
+				} elseif ($typec === 'DEP') {
1337
+					$data['type'] = 'Departure';
1338
+				} elseif ($typec === 'FSS') {
1339
+					$data['type'] = 'Flight Service Station';
1340
+				} elseif ($typec === 'CTR') {
1341
+					$data['type'] = 'Control Radar or Centre';
1342
+				} elseif ($data['type'] === '') {
1343
+					$data['type'] = 'Observer';
1344
+				}
1345
+				if (!isset($data['source_name'])) {
1346
+					$data['source_name'] = '';
1347
+				}
1005 1348
 				if (isset($ATC)) {
1006
-					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']);
1007
-					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']);
1349
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1350
+						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']);
1351
+					} else {
1352
+						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']);
1353
+					}
1008 1354
 				}
1009 1355
 			}
1010 1356
     			unset($data);
@@ -1031,14 +1377,20 @@  discard block
 block discarded – undo
1031 1377
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1032 1378
 			$data['latitude'] = (float)$line['pktLatitude'];
1033 1379
 			$data['longitude'] = (float)$line['pktLongitude'];
1034
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1035
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1380
+			if ((float)$line['pktTrack'] != 0) {
1381
+				$data['heading'] = (float)$line['pktTrack'];
1382
+			}
1383
+			if ((int)$line['pktSpeed'] != 0) {
1384
+				$data['speed'] = (int)$line['pktSpeed'];
1385
+			}
1036 1386
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1037 1387
 			$data['altitude_relative'] = 'AMSL';
1038 1388
 			$data['pilot_id'] = (int)$line['pktPilotID'];
1039 1389
 			$data['aircraft_icao'] = 'PARAGLIDER';
1040 1390
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1041
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1391
+			if (isset($pilot_data[4])) {
1392
+				$data['pilot_name'] = $pilot_data[4];
1393
+			}
1042 1394
 			$data['format_source'] = $value['format'];
1043 1395
 			$SI->add($data);
1044 1396
 			unset($data);
@@ -1086,25 +1438,59 @@  discard block
 block discarded – undo
1086 1438
 		    foreach ($all_data['acList'] as $line) {
1087 1439
 			$data = array();
1088 1440
 			$data['hex'] = $line['Icao']; // hex
1089
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1090
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1091
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1092
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1093
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1094
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1441
+			if (isset($line['Call'])) {
1442
+				$data['ident'] = $line['Call'];
1443
+			}
1444
+			// ident
1445
+			if (isset($line['Alt'])) {
1446
+				$data['altitude'] = $line['Alt'];
1447
+			}
1448
+			// altitude
1449
+			if (isset($line['Spd'])) {
1450
+				$data['speed'] = $line['Spd'];
1451
+			}
1452
+			// speed
1453
+			if (isset($line['Trak'])) {
1454
+				$data['heading'] = $line['Trak'];
1455
+			}
1456
+			// heading
1457
+			if (isset($line['Lat'])) {
1458
+				$data['latitude'] = $line['Lat'];
1459
+			}
1460
+			// lat
1461
+			if (isset($line['Long'])) {
1462
+				$data['longitude'] = $line['Long'];
1463
+			}
1464
+			// long
1095 1465
 			//$data['verticalrate'] = $line['']; // verticale rate
1096
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1466
+			if (isset($line['Sqk'])) {
1467
+				$data['squawk'] = $line['Sqk'];
1468
+			}
1469
+			// squawk
1097 1470
 			$data['emergency'] = ''; // emergency
1098
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1099
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1100
-			else $data['datetime'] = date('Y-m-d H:i:s');
1471
+			if (isset($line['Reg'])) {
1472
+				$data['registration'] = $line['Reg'];
1473
+			}
1474
+			if (isset($line['PosTime'])) {
1475
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1476
+			} else {
1477
+				$data['datetime'] = date('Y-m-d H:i:s');
1478
+			}
1101 1479
 			//$data['datetime'] = date('Y-m-d H:i:s');
1102
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1480
+			if (isset($line['Type'])) {
1481
+				$data['aircraft_icao'] = $line['Type'];
1482
+			}
1103 1483
 			$data['format_source'] = 'aircraftlistjson';
1104 1484
 			$data['id_source'] = $id_source;
1105
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1106
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1107
-			if (isset($data['latitude'])) $SI->add($data);
1485
+			if (isset($value['name']) && $value['name'] != '') {
1486
+				$data['source_name'] = $value['name'];
1487
+			}
1488
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1489
+				$data['noarchive'] = true;
1490
+			}
1491
+			if (isset($data['latitude'])) {
1492
+				$SI->add($data);
1493
+			}
1108 1494
 			unset($data);
1109 1495
 		    }
1110 1496
 		} elseif (is_array($all_data)) {
@@ -1121,17 +1507,26 @@  discard block
 block discarded – undo
1121 1507
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1122 1508
 			$data['squawk'] = $line['squawk']; // squawk
1123 1509
 			$data['emergency'] = ''; // emergency
1124
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1125
-			else $data['datetime'] = date('Y-m-d H:i:s');
1510
+			if (isset($line['PosTime'])) {
1511
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1512
+			} else {
1513
+				$data['datetime'] = date('Y-m-d H:i:s');
1514
+			}
1126 1515
 			$data['format_source'] = 'aircraftlistjson';
1127 1516
 			$data['id_source'] = $id_source;
1128
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1129
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1517
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1518
+				$data['noarchive'] = true;
1519
+			}
1520
+			if (isset($value['name']) && $value['name'] != '') {
1521
+				$data['source_name'] = $value['name'];
1522
+			}
1130 1523
 			$SI->add($data);
1131 1524
 			unset($data);
1132 1525
 		    }
1133 1526
 		}
1134
-	    } elseif ($globalDebug) echo 'No data'."\n";
1527
+	    } elseif ($globalDebug) {
1528
+	    	echo 'No data'."\n";
1529
+	    }
1135 1530
     	    //$last_exec['aircraftlistjson'] = time();
1136 1531
     	    $last_exec[$id]['last'] = time();
1137 1532
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -1167,8 +1562,12 @@  discard block
 block discarded – undo
1167 1562
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1168 1563
 	    	    $data['format_source'] = 'planeupdatefaa';
1169 1564
     		    $data['id_source'] = $id_source;
1170
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1171
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1565
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1566
+		    	$data['noarchive'] = true;
1567
+		    }
1568
+		    if (isset($value['name']) && $value['name'] != '') {
1569
+		    	$data['source_name'] = $value['name'];
1570
+		    }
1172 1571
 		    $SI->add($data);
1173 1572
 		    unset($data);
1174 1573
 		}
@@ -1202,7 +1601,9 @@  discard block
 block discarded – undo
1202 1601
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1203 1602
 		    $data['format_source'] = 'opensky';
1204 1603
 		    $data['id_source'] = $id_source;
1205
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1604
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1605
+		    	$data['noarchive'] = true;
1606
+		    }
1206 1607
 		    $SI->add($data);
1207 1608
 		    unset($data);
1208 1609
 		}
@@ -1222,15 +1623,42 @@  discard block
 block discarded – undo
1222 1623
 		foreach ($all_data['aircraft'] as $key => $line) {
1223 1624
 		    $data = array();
1224 1625
 		    // add support for ground vehicule with ~ in front of hex
1225
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1226
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1227
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1228
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1229
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1230
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1231
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1232
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1233
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1626
+		    if (isset($line['hex'])) {
1627
+		    	$data['hex'] = $line['hex'];
1628
+		    }
1629
+		    // hex
1630
+		    if (isset($line['flight'])) {
1631
+		    	$data['ident'] = trim($line['flight']);
1632
+		    }
1633
+		    // ident
1634
+		    if (isset($line['altitude'])) {
1635
+		    	$data['altitude'] = $line['altitude'];
1636
+		    }
1637
+		    // altitude
1638
+		    if (isset($line['speed'])) {
1639
+		    	$data['speed'] = $line['speed'];
1640
+		    }
1641
+		    // speed
1642
+		    if (isset($line['track'])) {
1643
+		    	$data['heading'] = $line['track'];
1644
+		    }
1645
+		    // heading
1646
+		    if (isset($line['lat'])) {
1647
+		    	$data['latitude'] = $line['lat'];
1648
+		    }
1649
+		    // lat
1650
+		    if (isset($line['lon'])) {
1651
+		    	$data['longitude'] = $line['lon'];
1652
+		    }
1653
+		    // long
1654
+		    if (isset($line['vert_rate'])) {
1655
+		    	$data['verticalrate'] = $line['vert_rate'];
1656
+		    }
1657
+		    // verticale rate
1658
+		    if (isset($line['squawk'])) {
1659
+		    	$data['squawk'] = $line['squawk'];
1660
+		    }
1661
+		    // squawk
1234 1662
 		    //$data['emergency'] = ''; // emergency
1235 1663
 		    //$data['registration'] = $line[2];
1236 1664
 		    //$data['aircraft_icao'] = $line[0];
@@ -1238,10 +1666,17 @@  discard block
 block discarded – undo
1238 1666
 		    $data['format_source'] = 'aircraftjson';
1239 1667
 		    $data['id_source'] = $id_source;
1240 1668
 		    if (isset($value['name']) && $value['name'] != '') {
1241
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1242
-			    else $data['source_name'] = $value['name'];
1243
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1244
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1669
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1670
+			    	$data['source_name'] = $value['name'].'_MLAT';
1671
+			    } else {
1672
+			    	$data['source_name'] = $value['name'];
1673
+			    }
1674
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1675
+		    	$data['source_name'] = 'MLAT';
1676
+		    }
1677
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1678
+		    	$data['noarchive'] = true;
1679
+		    }
1245 1680
 		    $SI->add($data);
1246 1681
 		    unset($data);
1247 1682
 		}
@@ -1261,22 +1696,54 @@  discard block
 block discarded – undo
1261 1696
 		foreach ($all_data['aircraft'] as $key => $line) {
1262 1697
 		    $data = array();
1263 1698
 		    $data['hex'] = $key; // hex
1264
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1265
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1266
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1267
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1268
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1269
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1270
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1271
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1699
+		    if (isset($line['callsign'])) {
1700
+		    	$data['ident'] = trim($line['callsign']);
1701
+		    }
1702
+		    // ident
1703
+		    if (isset($line['altitude'])) {
1704
+		    	$data['altitude'] = $line['altitude'];
1705
+		    }
1706
+		    // altitude
1707
+		    if (isset($line['speed'])) {
1708
+		    	$data['speed'] = $line['speed'];
1709
+		    }
1710
+		    // speed
1711
+		    if (isset($line['heading'])) {
1712
+		    	$data['heading'] = $line['heading'];
1713
+		    }
1714
+		    // heading
1715
+		    if (isset($line['lat'])) {
1716
+		    	$data['latitude'] = $line['lat'];
1717
+		    }
1718
+		    // lat
1719
+		    if (isset($line['lon'])) {
1720
+		    	$data['longitude'] = $line['lon'];
1721
+		    }
1722
+		    // long
1723
+		    if (isset($line['vert_rate'])) {
1724
+		    	$data['verticalrate'] = $line['vert_rate'];
1725
+		    }
1726
+		    // verticale rate
1727
+		    if (isset($line['squawk'])) {
1728
+		    	$data['squawk'] = $line['squawk'];
1729
+		    }
1730
+		    // squawk
1272 1731
 		    //$data['emergency'] = ''; // emergency
1273
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1274
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1732
+		    if (isset($line['reg'])) {
1733
+		    	$data['registration'] = $line['reg'];
1734
+		    }
1735
+		    if (isset($line['type'])) {
1736
+		    	$data['aircraft_icao'] = $line['type'];
1737
+		    }
1275 1738
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1276 1739
 		    $data['format_source'] = 'planefinderclient';
1277 1740
 		    $data['id_source'] = $id_source;
1278
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1279
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1741
+		    if (isset($value['name']) && $value['name'] != '') {
1742
+		    	$data['source_name'] = $value['name'];
1743
+		    }
1744
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1745
+		    	$data['noarchive'] = true;
1746
+		    }
1280 1747
 		    $SI->add($data);
1281 1748
 		    unset($data);
1282 1749
 		}
@@ -1292,7 +1759,9 @@  discard block
 block discarded – undo
1292 1759
 	    //$buffer = $Common->getData($hosts[$id]);
1293 1760
 	    $buffer = $Common->getData($value['host']);
1294 1761
 	    $all_data = json_decode($buffer,true);
1295
-	    if (!empty($all_data)) $reset = 0;
1762
+	    if (!empty($all_data)) {
1763
+	    	$reset = 0;
1764
+	    }
1296 1765
 	    foreach ($all_data as $key => $line) {
1297 1766
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1298 1767
 		    $data = array();
@@ -1313,8 +1782,12 @@  discard block
 block discarded – undo
1313 1782
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1314 1783
 	    	    $data['format_source'] = 'fr24json';
1315 1784
     		    $data['id_source'] = $id_source;
1316
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1317
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1785
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1786
+		    	$data['noarchive'] = true;
1787
+		    }
1788
+		    if (isset($value['name']) && $value['name'] != '') {
1789
+		    	$data['source_name'] = $value['name'];
1790
+		    }
1318 1791
 		    $SI->add($data);
1319 1792
 		    unset($data);
1320 1793
 		}
@@ -1343,24 +1816,42 @@  discard block
 block discarded – undo
1343 1816
 		    if (isset($line['inf'])) {
1344 1817
 			$data = array();
1345 1818
 			$data['hex'] = $line['inf']['ia'];
1346
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1819
+			if (isset($line['inf']['cs'])) {
1820
+				$data['ident'] = $line['inf']['cs'];
1821
+			}
1822
+			//$line[13]
1347 1823
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1348
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1349
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1824
+	    		if (isset($line['inf']['gs'])) {
1825
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1826
+	    		}
1827
+	    		// speed
1828
+	    		if (isset($line['inf']['tr'])) {
1829
+	    			$data['heading'] = $line['inf']['tr'];
1830
+	    		}
1831
+	    		// heading
1350 1832
 	    		$data['latitude'] = $line['pt'][0]; // lat
1351 1833
 	    		$data['longitude'] = $line['pt'][1]; // long
1352 1834
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1353
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1835
+	    		if (isset($line['inf']['sq'])) {
1836
+	    			$data['squawk'] = $line['inf']['sq'];
1837
+	    		}
1838
+	    		// squawk
1354 1839
 	    		//$data['aircraft_icao'] = $line[8];
1355
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1840
+	    		if (isset($line['inf']['rc'])) {
1841
+	    			$data['registration'] = $line['inf']['rc'];
1842
+	    		}
1356 1843
 			//$data['departure_airport_iata'] = $line[11];
1357 1844
 			//$data['arrival_airport_iata'] = $line[12];
1358 1845
 	    		//$data['emergency'] = ''; // emergency
1359 1846
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1360 1847
 	    		$data['format_source'] = 'radarvirtueljson';
1361 1848
     			$data['id_source'] = $id_source;
1362
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1363
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1849
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1850
+				$data['noarchive'] = true;
1851
+			}
1852
+			if (isset($value['name']) && $value['name'] != '') {
1853
+				$data['source_name'] = $value['name'];
1854
+			}
1364 1855
 			$SI->add($data);
1365 1856
 			unset($data);
1366 1857
 		    }
@@ -1386,30 +1877,65 @@  discard block
 block discarded – undo
1386 1877
 		    $data['id'] = $line['id'];
1387 1878
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1388 1879
 		    $data['ident'] = $line['callsign']; // ident
1389
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1390
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1391
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1392
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1393
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1394
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1880
+		    if (isset($line['pilotid'])) {
1881
+		    	$data['pilot_id'] = $line['pilotid'];
1882
+		    }
1883
+		    // pilot id
1884
+		    if (isset($line['name'])) {
1885
+		    	$data['pilot_name'] = $line['name'];
1886
+		    }
1887
+		    // pilot name
1888
+		    if (isset($line['alt'])) {
1889
+		    	$data['altitude'] = $line['alt'];
1890
+		    }
1891
+		    // altitude
1892
+		    if (isset($line['gs'])) {
1893
+		    	$data['speed'] = $line['gs'];
1894
+		    }
1895
+		    // speed
1896
+		    if (isset($line['heading'])) {
1897
+		    	$data['heading'] = $line['heading'];
1898
+		    }
1899
+		    // heading
1900
+		    if (isset($line['route'])) {
1901
+		    	$data['waypoints'] = $line['route'];
1902
+		    }
1903
+		    // route
1395 1904
 		    $data['latitude'] = $line['lat']; // lat
1396 1905
 		    $data['longitude'] = $line['lon']; // long
1397 1906
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1398 1907
 		    //$data['squawk'] = $line['squawk']; // squawk
1399 1908
 		    //$data['emergency'] = ''; // emergency
1400
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1401
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1402
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1909
+		    if (isset($line['depicao'])) {
1910
+		    	$data['departure_airport_icao'] = $line['depicao'];
1911
+		    }
1912
+		    if (isset($line['deptime'])) {
1913
+		    	$data['departure_airport_time'] = $line['deptime'];
1914
+		    }
1915
+		    if (isset($line['arricao'])) {
1916
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1917
+		    }
1403 1918
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1404
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1405
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1406
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1407
-		    else $data['info'] = '';
1919
+		    if (isset($line['aircraft'])) {
1920
+		    	$data['aircraft_icao'] = $line['aircraft'];
1921
+		    }
1922
+		    if (isset($line['transponder'])) {
1923
+		    	$data['squawk'] = $line['transponder'];
1924
+		    }
1925
+		    if (isset($line['atis'])) {
1926
+		    	$data['info'] = $line['atis'];
1927
+		    } else {
1928
+		    	$data['info'] = '';
1929
+		    }
1408 1930
 		    $data['format_source'] = 'pireps';
1409 1931
     		    $data['id_source'] = $id_source;
1410 1932
 		    $data['datetime'] = date('Y-m-d H:i:s');
1411
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1412
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1933
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1934
+		    	$data['noarchive'] = true;
1935
+		    }
1936
+		    if (isset($value['name']) && $value['name'] != '') {
1937
+		    	$data['source_name'] = $value['name'];
1938
+		    }
1413 1939
 		    if ($line['icon'] === 'plane') {
1414 1940
 			$SI->add($data);
1415 1941
 		    //    print_r($data);
@@ -1418,16 +1944,28 @@  discard block
 block discarded – undo
1418 1944
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1419 1945
 			$typec = substr($data['ident'],-3);
1420 1946
 			$data['type'] = '';
1421
-			if ($typec === 'APP') $data['type'] = 'Approach';
1422
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1423
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1424
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1425
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1426
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1427
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1428
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1429
-			else $data['type'] = 'Observer';
1430
-			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']);
1947
+			if ($typec === 'APP') {
1948
+				$data['type'] = 'Approach';
1949
+			} elseif ($typec === 'TWR') {
1950
+				$data['type'] = 'Tower';
1951
+			} elseif ($typec === 'OBS') {
1952
+				$data['type'] = 'Observer';
1953
+			} elseif ($typec === 'GND') {
1954
+				$data['type'] = 'Ground';
1955
+			} elseif ($typec === 'DEL') {
1956
+				$data['type'] = 'Delivery';
1957
+			} elseif ($typec === 'DEP') {
1958
+				$data['type'] = 'Departure';
1959
+			} elseif ($typec === 'FSS') {
1960
+				$data['type'] = 'Flight Service Station';
1961
+			} elseif ($typec === 'CTR') {
1962
+				$data['type'] = 'Control Radar or Centre';
1963
+			} else {
1964
+				$data['type'] = 'Observer';
1965
+			}
1966
+			if (isset($ATC)) {
1967
+				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']);
1968
+			}
1431 1969
 		    }
1432 1970
 		    unset($data);
1433 1971
 		}
@@ -1442,7 +1980,9 @@  discard block
 block discarded – undo
1442 1980
 	    )
1443 1981
 	) {
1444 1982
 	    //$buffer = $Common->getData($hosts[$id]);
1445
-	    if ($globalDebug) echo 'Get Data...'."\n";
1983
+	    if ($globalDebug) {
1984
+	    	echo 'Get Data...'."\n";
1985
+	    }
1446 1986
 	    $buffer = $Common->getData($value['host']);
1447 1987
 	    $all_data = json_decode($buffer,true);
1448 1988
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1450,10 +1990,16 @@  discard block
 block discarded – undo
1450 1990
 		foreach ($all_data as $line) {
1451 1991
 	    	    $data = array();
1452 1992
 	    	    //$data['id'] = $line['id']; // id not usable
1453
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1993
+	    	    if (isset($line['pilotid'])) {
1994
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1995
+	    	    }
1454 1996
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1455
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1456
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1997
+	    	    if (isset($line['pilotname'])) {
1998
+	    	    	$data['pilot_name'] = $line['pilotname'];
1999
+	    	    }
2000
+	    	    if (isset($line['pilotid'])) {
2001
+	    	    	$data['pilot_id'] = $line['pilotid'];
2002
+	    	    }
1457 2003
 	    	    $data['ident'] = $line['flightnum']; // ident
1458 2004
 	    	    $data['altitude'] = $line['alt']; // altitude
1459 2005
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1469,7 +2015,9 @@  discard block
 block discarded – undo
1469 2015
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1470 2016
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1471 2017
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1472
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2018
+	    	    } else {
2019
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2020
+	    	    }
1473 2021
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1474 2022
 	    	    $data['departure_airport_time'] = $line['deptime'];
1475 2023
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1477,29 +2025,47 @@  discard block
 block discarded – undo
1477 2025
     		    if (isset($line['registration'])) {
1478 2026
     			$data['registration'] = $line['registration'];
1479 2027
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1480
-    		    } else $data['registration'] = $line['aircraft'];
1481
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1482
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2028
+    		    } else {
2029
+    		    	$data['registration'] = $line['aircraft'];
2030
+    		    }
2031
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2032
+		    	$data['noarchive'] = true;
2033
+		    }
2034
+		    if (isset($line['route'])) {
2035
+		    	$data['waypoints'] = $line['route'];
2036
+		    }
2037
+		    // route
1483 2038
 		    if (isset($line['aircraftname'])) {
1484 2039
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1485 2040
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1486 2041
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1487
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1488
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1489
-	    		else {
2042
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
2043
+	    			$data['aircraft_icao'] = $aircraft_data[0];
2044
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
2045
+	    			$data['aircraft_icao'] = $aircraft_data[1];
2046
+	    		} else {
1490 2047
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1491
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1492
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2048
+	    		    if (isset($aircraft_data[1])) {
2049
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
2050
+	    		    } else {
2051
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2052
+	    		    }
1493 2053
 	    		}
1494 2054
 	    	    }
1495
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
2055
+    		    if (isset($line['route'])) {
2056
+    		    	$data['waypoints'] = $line['route'];
2057
+    		    }
1496 2058
     		    $data['id_source'] = $id_source;
1497 2059
 	    	    $data['format_source'] = 'phpvmacars';
1498
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2060
+		    if (isset($value['name']) && $value['name'] != '') {
2061
+		    	$data['source_name'] = $value['name'];
2062
+		    }
1499 2063
 		    $SI->add($data);
1500 2064
 		    unset($data);
1501 2065
 		}
1502
-		if ($globalDebug) echo 'No more data...'."\n";
2066
+		if ($globalDebug) {
2067
+			echo 'No more data...'."\n";
2068
+		}
1503 2069
 		unset($buffer);
1504 2070
 		unset($all_data);
1505 2071
 	    }
@@ -1512,7 +2078,9 @@  discard block
 block discarded – undo
1512 2078
 	    )
1513 2079
 	) {
1514 2080
 	    //$buffer = $Common->getData($hosts[$id]);
1515
-	    if ($globalDebug) echo 'Get Data...'."\n";
2081
+	    if ($globalDebug) {
2082
+	    	echo 'Get Data...'."\n";
2083
+	    }
1516 2084
 	    $buffer = $Common->getData($value['host']);
1517 2085
 	    $all_data = json_decode($buffer,true);
1518 2086
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1523,10 +2091,16 @@  discard block
 block discarded – undo
1523 2091
 	    	    //$data['id'] = $line['id']; // id not usable
1524 2092
 	    	    $data['id'] = $line['id'];
1525 2093
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1526
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1527
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
2094
+	    	    if (isset($line['user']['username'])) {
2095
+	    	    	$data['pilot_name'] = $line['user']['username'];
2096
+	    	    }
2097
+	    	    if (isset($line['user_id'])) {
2098
+	    	    	$data['pilot_id'] = $line['user_id'];
2099
+	    	    }
1528 2100
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1529
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2101
+	    	    if (is_numeric($data['ident'])) {
2102
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2103
+	    	    }
1530 2104
 	    	    $data['altitude'] = $line['altitude']; // altitude
1531 2105
 	    	    $data['speed'] = $line['groundspeed']; // speed
1532 2106
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1539,7 +2113,9 @@  discard block
 block discarded – undo
1539 2113
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1540 2114
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1541 2115
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1542
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2116
+	    	    } else {
2117
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2118
+	    	    }
1543 2119
 	    	    
1544 2120
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1545 2121
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1547,17 +2123,26 @@  discard block
 block discarded – undo
1547 2123
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1548 2124
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1549 2125
 
1550
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1551
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
2126
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2127
+		    	$data['noarchive'] = true;
2128
+		    }
2129
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
2130
+		    	$data['waypoints'] = $line['bid']['route'];
2131
+		    }
2132
+		    // route
1552 2133
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1553 2134
 
1554 2135
     		    $data['id_source'] = $id_source;
1555 2136
 	    	    $data['format_source'] = 'vaos';
1556
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2137
+		    if (isset($value['name']) && $value['name'] != '') {
2138
+		    	$data['source_name'] = $value['name'];
2139
+		    }
1557 2140
 		    $SI->add($data);
1558 2141
 		    unset($data);
1559 2142
 		}
1560
-		if ($globalDebug) echo 'No more data...'."\n";
2143
+		if ($globalDebug) {
2144
+			echo 'No more data...'."\n";
2145
+		}
1561 2146
 		unset($buffer);
1562 2147
 		unset($all_data);
1563 2148
 	    }
@@ -1570,7 +2155,9 @@  discard block
 block discarded – undo
1570 2155
 	    )
1571 2156
 	) {
1572 2157
 	    //$buffer = $Common->getData($hosts[$id]);
1573
-	    if ($globalDebug) echo 'Get Data...'."\n";
2158
+	    if ($globalDebug) {
2159
+	    	echo 'Get Data...'."\n";
2160
+	    }
1574 2161
 	    $buffer = $Common->getData($value['host']);
1575 2162
 	    $all_data = json_decode($buffer,true);
1576 2163
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1599,16 +2186,25 @@  discard block
 block discarded – undo
1599 2186
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1600 2187
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1601 2188
     		    //$data['registration'] = $line['aircraft'];
1602
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2189
+		    if (isset($line['route'])) {
2190
+		    	$data['waypoints'] = $line['route'];
2191
+		    }
2192
+		    // route
1603 2193
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1604 2194
     		    $data['id_source'] = $id_source;
1605 2195
 	    	    $data['format_source'] = 'vam';
1606
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1607
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2196
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2197
+		    	$data['noarchive'] = true;
2198
+		    }
2199
+		    if (isset($value['name']) && $value['name'] != '') {
2200
+		    	$data['source_name'] = $value['name'];
2201
+		    }
1608 2202
 		    $SI->add($data);
1609 2203
 		    unset($data);
1610 2204
 		}
1611
-		if ($globalDebug) echo 'No more data...'."\n";
2205
+		if ($globalDebug) {
2206
+			echo 'No more data...'."\n";
2207
+		}
1612 2208
 		unset($buffer);
1613 2209
 		unset($all_data);
1614 2210
 	    }
@@ -1621,7 +2217,9 @@  discard block
 block discarded – undo
1621 2217
 	    )
1622 2218
 	) {
1623 2219
 	    //$buffer = $Common->getData($hosts[$id]);
1624
-	    if ($globalDebug) echo 'Get Data...'."\n";
2220
+	    if ($globalDebug) {
2221
+	    	echo 'Get Data...'."\n";
2222
+	    }
1625 2223
 	    $buffer = $Common->getData($value['host']);
1626 2224
 	    $all_data = json_decode($buffer,true);
1627 2225
 	    if ($buffer != '') {
@@ -1639,12 +2237,16 @@  discard block
 block discarded – undo
1639 2237
 			$data['id_source'] = $id_source;
1640 2238
 			$data['format_source'] = 'blitzortung';
1641 2239
 			$SI->add($data);
1642
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2240
+			if ($globalDebug) {
2241
+				echo '☈ Lightning added'."\n";
2242
+			}
1643 2243
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1644 2244
 			unset($data);
1645 2245
 		    }
1646 2246
 		}
1647
-		if ($globalDebug) echo 'No more data...'."\n";
2247
+		if ($globalDebug) {
2248
+			echo 'No more data...'."\n";
2249
+		}
1648 2250
 		unset($buffer);
1649 2251
 	    }
1650 2252
 	    $last_exec[$id]['last'] = time();
@@ -1673,10 +2275,15 @@  discard block
 block discarded – undo
1673 2275
                 }
1674 2276
             } else {
1675 2277
                 $format = $value['format'];
1676
-                if (isset($tt[$format])) $tt[$format]++;
1677
-                else $tt[$format] = 0;
2278
+                if (isset($tt[$format])) {
2279
+                	$tt[$format]++;
2280
+                } else {
2281
+                	$tt[$format] = 0;
2282
+                }
1678 2283
                 if ($tt[$format] > 30) {
1679
-                    if ($globalDebug) echo 'Reconnect...'."\n";
2284
+                    if ($globalDebug) {
2285
+                    	echo 'Reconnect...'."\n";
2286
+                    }
1680 2287
                     sleep(2);
1681 2288
                     //$sourceeen[] = $value;
1682 2289
                     //connect_all($sourceeen);
@@ -1693,7 +2300,9 @@  discard block
 block discarded – undo
1693 2300
 	    $write = NULL;
1694 2301
 	    $e = NULL;
1695 2302
 	    $n = socket_select($read, $write, $e, $timeout);
1696
-	    if ($e != NULL) var_dump($e);
2303
+	    if ($e != NULL) {
2304
+	    	var_dump($e);
2305
+	    }
1697 2306
 	    if ($n > 0) {
1698 2307
 		$reset = 0;
1699 2308
 		foreach ($read as $nb => $r) {
@@ -1715,13 +2324,17 @@  discard block
 block discarded – undo
1715 2324
 		    if ($buffer !== FALSE) {
1716 2325
 			if ($format === 'vrstcp') {
1717 2326
 			    $buffer = explode('},{',$buffer);
1718
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2327
+			} else {
2328
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2329
+			}
1719 2330
 		    }
1720 2331
 		    // SBS format is CSV format
1721 2332
 		    if ($buffer !== FALSE && $buffer !== '') {
1722 2333
 			$tt[$format] = 0;
1723 2334
 			if ($format === 'acarssbs3') {
1724
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2335
+			    if ($globalDebug) {
2336
+			    	echo 'ACARS : '.$buffer."\n";
2337
+			    }
1725 2338
 			    $ACARS->add(trim($buffer));
1726 2339
 			    $ACARS->deleteLiveAcarsData();
1727 2340
 			} elseif ($format === 'raw') {
@@ -1731,9 +2344,15 @@  discard block
 block discarded – undo
1731 2344
 				//if (!empty($data)) print_r($data);
1732 2345
 				$data['datetime'] = date('Y-m-d H:i:s');
1733 2346
 				$data['format_source'] = 'raw';
1734
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1735
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1736
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2347
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2348
+					$data['source_name'] = $globalSources[$nb]['name'];
2349
+				}
2350
+				if (isset($globalSources[$nb]['sourcestats'])) {
2351
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2352
+				}
2353
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2354
+					$data['noarchive'] = true;
2355
+				}
1737 2356
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1738 2357
 				$SI->add($data);
1739 2358
 				unset($data);
@@ -1741,22 +2360,54 @@  discard block
 block discarded – undo
1741 2360
 			} elseif ($format === 'ais') {
1742 2361
 			    $ais_data = $AIS->parse_line(trim($buffer));
1743 2362
 			    $data = array();
1744
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1745
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1746
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1747
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1748
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1749
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1750
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1751
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1752
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1753
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1754
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1755
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1756
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1757
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1758
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1759
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2363
+			    if (isset($ais_data['ident'])) {
2364
+			    	$data['ident'] = $ais_data['ident'];
2365
+			    }
2366
+			    if (isset($ais_data['mmsi'])) {
2367
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2368
+			    }
2369
+			    if (isset($ais_data['speed'])) {
2370
+			    	$data['speed'] = $ais_data['speed'];
2371
+			    }
2372
+			    if (isset($ais_data['heading'])) {
2373
+			    	$data['heading'] = $ais_data['heading'];
2374
+			    }
2375
+			    if (isset($ais_data['latitude'])) {
2376
+			    	$data['latitude'] = $ais_data['latitude'];
2377
+			    }
2378
+			    if (isset($ais_data['longitude'])) {
2379
+			    	$data['longitude'] = $ais_data['longitude'];
2380
+			    }
2381
+			    if (isset($ais_data['status'])) {
2382
+			    	$data['status'] = $ais_data['status'];
2383
+			    }
2384
+			    if (isset($ais_data['statusid'])) {
2385
+			    	$data['status_id'] = $ais_data['statusid'];
2386
+			    }
2387
+			    if (isset($ais_data['type'])) {
2388
+			    	$data['type'] = $ais_data['type'];
2389
+			    }
2390
+			    if (isset($ais_data['imo'])) {
2391
+			    	$data['imo'] = $ais_data['imo'];
2392
+			    }
2393
+			    if (isset($ais_data['callsign'])) {
2394
+			    	$data['callsign'] = $ais_data['callsign'];
2395
+			    }
2396
+			    if (isset($ais_data['destination'])) {
2397
+			    	$data['arrival_code'] = $ais_data['destination'];
2398
+			    }
2399
+			    if (isset($ais_data['eta_ts'])) {
2400
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2401
+			    }
2402
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2403
+			    	$data['noarchive'] = true;
2404
+			    }
2405
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2406
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2407
+			    }
2408
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2409
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2410
+			    }
1760 2411
 
1761 2412
 			    if (isset($ais_data['timestamp'])) {
1762 2413
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1765,7 +2416,9 @@  discard block
 block discarded – undo
1765 2416
 			    }
1766 2417
 			    $data['format_source'] = 'aisnmea';
1767 2418
     			    $data['id_source'] = $id_source;
1768
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2419
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2420
+			    	$MI->add($data);
2421
+			    }
1769 2422
 			    unset($data);
1770 2423
                         } elseif ($format === 'flightgearsp') {
1771 2424
                     	    //echo $buffer."\n";
@@ -1783,17 +2436,25 @@  discard block
 block discarded – undo
1783 2436
 				$data['speed'] = round($line[5]*1.94384);
1784 2437
 				$data['datetime'] = date('Y-m-d H:i:s');
1785 2438
 				$data['format_source'] = 'flightgearsp';
1786
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1787
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2439
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2440
+					$data['noarchive'] = true;
2441
+				}
2442
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2443
+					$SI->add($data);
2444
+				}
1788 2445
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1789 2446
 			    }
1790 2447
                         } elseif ($format === 'acars') {
1791
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2448
+                    	    if ($globalDebug) {
2449
+                    	    	echo 'ACARS : '.$buffer."\n";
2450
+                    	    }
1792 2451
 			    $ACARS->add(trim($buffer));
1793 2452
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1794 2453
 			    $ACARS->deleteLiveAcarsData();
1795 2454
 			} elseif ($format === 'acarsjsonudp') {
1796
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2455
+			    if ($globalDebug) {
2456
+			    	echo 'ACARS : '.$buffer."\n";
2457
+			    }
1797 2458
                             $line = json_decode(trim($buffer), true);
1798 2459
                             if (!empty($line)) {
1799 2460
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
@@ -1818,8 +2479,12 @@  discard block
 block discarded – undo
1818 2479
 				    $aircraft_type = $line[10];
1819 2480
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1820 2481
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1821
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1822
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2482
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2483
+				    	$data['noarchive'] = true;
2484
+				    }
2485
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2486
+				    	$SI->add($data);
2487
+				    }
1823 2488
 				}
1824 2489
 			    }
1825 2490
 			} elseif ($format === 'beast') {
@@ -1829,28 +2494,62 @@  discard block
 block discarded – undo
1829 2494
 			    foreach($buffer as $all_data) {
1830 2495
 				$line = json_decode('{'.$all_data.'}',true);
1831 2496
 				$data = array();
1832
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1833
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1834
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1835
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1836
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1837
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1838
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2497
+				if (isset($line['Icao'])) {
2498
+					$data['hex'] = $line['Icao'];
2499
+				}
2500
+				// hex
2501
+				if (isset($line['Call'])) {
2502
+					$data['ident'] = $line['Call'];
2503
+				}
2504
+				// ident
2505
+				if (isset($line['Alt'])) {
2506
+					$data['altitude'] = $line['Alt'];
2507
+				}
2508
+				// altitude
2509
+				if (isset($line['Spd'])) {
2510
+					$data['speed'] = $line['Spd'];
2511
+				}
2512
+				// speed
2513
+				if (isset($line['Trak'])) {
2514
+					$data['heading'] = $line['Trak'];
2515
+				}
2516
+				// heading
2517
+				if (isset($line['Lat'])) {
2518
+					$data['latitude'] = $line['Lat'];
2519
+				}
2520
+				// lat
2521
+				if (isset($line['Long'])) {
2522
+					$data['longitude'] = $line['Long'];
2523
+				}
2524
+				// long
1839 2525
 				//$data['verticalrate'] = $line['']; // verticale rate
1840
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2526
+				if (isset($line['Sqk'])) {
2527
+					$data['squawk'] = $line['Sqk'];
2528
+				}
2529
+				// squawk
1841 2530
 				$data['emergency'] = ''; // emergency
1842
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2531
+				if (isset($line['Reg'])) {
2532
+					$data['registration'] = $line['Reg'];
2533
+				}
1843 2534
 				/*
1844 2535
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1845 2536
 				else $data['datetime'] = date('Y-m-d H:i:s');
1846 2537
 				*/
1847 2538
 				$data['datetime'] = date('Y-m-d H:i:s');
1848
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2539
+				if (isset($line['Type'])) {
2540
+					$data['aircraft_icao'] = $line['Type'];
2541
+				}
1849 2542
 		    		$data['format_source'] = 'vrstcp';
1850 2543
 				$data['id_source'] = $id_source;
1851
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1852
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1853
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2544
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2545
+					$data['noarchive'] = true;
2546
+				}
2547
+				if (isset($value['name']) && $value['name'] != '') {
2548
+					$data['source_name'] = $value['name'];
2549
+				}
2550
+				if (isset($data['latitude']) && isset($data['hex'])) {
2551
+					$SI->add($data);
2552
+				}
1854 2553
 				unset($data);
1855 2554
 			    }
1856 2555
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1863,22 +2562,46 @@  discard block
 block discarded – undo
1863 2562
     				$data['hex'] = $lined['hexid'];
1864 2563
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1865 2564
     				$data['datetime'] = date('Y-m-d H:i:s');;
1866
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1867
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1868
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1869
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1870
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1871
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1872
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2565
+    				if (isset($lined['ident'])) {
2566
+    					$data['ident'] = $lined['ident'];
2567
+    				}
2568
+    				if (isset($lined['lat'])) {
2569
+    					$data['latitude'] = $lined['lat'];
2570
+    				}
2571
+    				if (isset($lined['lon'])) {
2572
+    					$data['longitude'] = $lined['lon'];
2573
+    				}
2574
+    				if (isset($lined['speed'])) {
2575
+    					$data['speed'] = $lined['speed'];
2576
+    				}
2577
+    				if (isset($lined['squawk'])) {
2578
+    					$data['squawk'] = $lined['squawk'];
2579
+    				}
2580
+    				if (isset($lined['alt'])) {
2581
+    					$data['altitude'] = $lined['alt'];
2582
+    				}
2583
+    				if (isset($lined['heading'])) {
2584
+    					$data['heading'] = $lined['heading'];
2585
+    				}
1873 2586
     				$data['id_source'] = $id_source;
1874 2587
     				$data['format_source'] = 'tsv';
1875
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1876
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1877
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1878
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2588
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2589
+    					$data['source_name'] = $globalSources[$nb]['name'];
2590
+    				}
2591
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2592
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2593
+    				}
2594
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2595
+					$data['noarchive'] = true;
2596
+				}
2597
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2598
+    					$SI->add($data);
2599
+    				}
1879 2600
     				unset($lined);
1880 2601
     				unset($data);
1881
-    			    } else $error = true;
2602
+    			    } else {
2603
+    			    	$error = true;
2604
+    			    }
1882 2605
 			} elseif ($format === 'aprs' && $use_aprs) {
1883 2606
 			    if ($aprs_connect === 0) {
1884 2607
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1904,47 +2627,96 @@  discard block
 block discarded – undo
1904 2627
 				    $aprs_last_tx = time();
1905 2628
 				    $data = array();
1906 2629
 				    //print_r($line);
1907
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1908
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1909
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1910
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1911
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1912
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1913
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1914
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1915
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1916
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2630
+				    if (isset($line['address'])) {
2631
+				    	$data['hex'] = $line['address'];
2632
+				    }
2633
+				    if (isset($line['mmsi'])) {
2634
+				    	$data['mmsi'] = $line['mmsi'];
2635
+				    }
2636
+				    if (isset($line['imo'])) {
2637
+				    	$data['imo'] = $line['imo'];
2638
+				    }
2639
+				    if (isset($line['squawk'])) {
2640
+				    	$data['squawk'] = $line['squawk'];
2641
+				    }
2642
+				    if (isset($line['arrival_code'])) {
2643
+				    	$data['arrival_code'] = $line['arrival_code'];
2644
+				    }
2645
+				    if (isset($line['arrival_date'])) {
2646
+				    	$data['arrival_date'] = $line['arrival_date'];
2647
+				    }
2648
+				    if (isset($line['typeid'])) {
2649
+				    	$data['type_id'] = $line['typeid'];
2650
+				    }
2651
+				    if (isset($line['statusid'])) {
2652
+				    	$data['status_id'] = $line['statusid'];
2653
+				    }
2654
+				    if (isset($line['timestamp'])) {
2655
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2656
+				    } else {
2657
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2658
+				    }
1917 2659
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1918
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2660
+				    if (isset($line['ident'])) {
2661
+				    	$data['ident'] = $line['ident'];
2662
+				    }
1919 2663
 				    $data['latitude'] = $line['latitude'];
1920 2664
 				    $data['longitude'] = $line['longitude'];
1921 2665
 				    //$data['verticalrate'] = $line[16];
1922
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2666
+				    if (isset($line['speed'])) {
2667
+				    	$data['speed'] = $line['speed'];
2668
+				    }
1923 2669
 				    //else $data['speed'] = 0;
1924
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1925
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1926
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2670
+				    if (isset($line['altitude'])) {
2671
+				    	$data['altitude'] = $line['altitude'];
2672
+				    }
2673
+				    if (isset($line['comment'])) {
2674
+				    	$data['comment'] = $line['comment'];
2675
+				    }
2676
+				    if (isset($line['symbol'])) {
2677
+				    	$data['type'] = $line['symbol'];
2678
+				    }
1927 2679
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1928 2680
 				    
1929
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2681
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2682
+				    	$data['heading'] = $line['heading'];
2683
+				    }
1930 2684
 				    //else echo 'No heading...'."\n";
1931 2685
 				    //else $data['heading'] = 0;
1932
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2686
+				    if (isset($line['stealth'])) {
2687
+				    	$data['aircraft_type'] = $line['stealth'];
2688
+				    }
1933 2689
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1934
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1935
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1936
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1937
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2690
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2691
+				    	$data['noarchive'] = true;
2692
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2693
+				    	$data['noarchive'] = false;
2694
+				    }
2695
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2696
+				    	$data['noarchive'] = true;
2697
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2698
+				    	$data['noarchive'] = false;
2699
+				    }
1938 2700
     				    $data['id_source'] = $id_source;
1939
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1940
-				    else $data['format_source'] = 'aprs';
2701
+    				    if (isset($line['format_source'])) {
2702
+    				    	$data['format_source'] = $line['format_source'];
2703
+    				    } else {
2704
+				    	$data['format_source'] = 'aprs';
2705
+				    }
1941 2706
 				    $data['source_name'] = $line['source'];
1942
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1943
-				    else $data['source_type'] = 'flarm';
1944
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2707
+				    if (isset($line['source_type'])) {
2708
+				    	$data['source_type'] = $line['source_type'];
2709
+				    } else {
2710
+				    	$data['source_type'] = 'flarm';
2711
+				    }
2712
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2713
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2714
+    				    }
1945 2715
 				    $currentdate = date('Y-m-d H:i:s');
1946 2716
 				    $aprsdate = strtotime($data['datetime']);
1947
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2717
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2718
+				    	$data['altitude_relative'] = 'AMSL';
2719
+				    }
1948 2720
 				    // Accept data if time <= system time + 20s
1949 2721
 				    //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'])))) {
1950 2722
 				    if (
@@ -1956,7 +2728,9 @@  discard block
 block discarded – undo
1956 2728
 					$send = $SI->add($data);
1957 2729
 				    } elseif ($data['source_type'] === 'ais') {
1958 2730
 					$data['type'] = '';
1959
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2731
+					if (isset($globalMarine) && $globalMarine) {
2732
+						$send = $MI->add($data);
2733
+					}
1960 2734
 				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
1961 2735
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1962 2736
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
@@ -1964,8 +2738,12 @@  discard block
 block discarded – undo
1964 2738
 					    $line['symbol'] === 'Glider' || 
1965 2739
 					    $line['symbol'] === 'No. Plane' || 
1966 2740
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1967
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1968
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2741
+					    if ($line['symbol'] === 'Ballon') {
2742
+					    	$data['aircraft_icao'] = 'BALL';
2743
+					    }
2744
+					    if ($line['symbol'] === 'Glider') {
2745
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2746
+					    }
1969 2747
 					    $send = $SI->add($data);
1970 2748
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1971 2749
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -1996,9 +2774,13 @@  discard block
 block discarded – undo
1996 2774
 				    //} 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') {
1997 2775
 				//    } 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') {
1998 2776
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1999
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2777
+					if (isset($globalTracker) && $globalTracker) {
2778
+						$send = $TI->add($data);
2779
+					}
2000 2780
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2001
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2781
+					if (!isset($data['altitude'])) {
2782
+						$data['altitude'] = 0;
2783
+					}
2002 2784
 					$Source->deleteOldLocationByType('gs');
2003 2785
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2004 2786
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -2007,7 +2789,9 @@  discard block
 block discarded – undo
2007 2789
 					}
2008 2790
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2009 2791
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2010
-					if ($globalDebug) echo '# Weather Station added'."\n";
2792
+					if ($globalDebug) {
2793
+						echo '# Weather Station added'."\n";
2794
+					}
2011 2795
 					$Source->deleteOldLocationByType('wx');
2012 2796
 					$weather_data = json_encode($line);
2013 2797
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -2017,7 +2801,9 @@  discard block
 block discarded – undo
2017 2801
 					}
2018 2802
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2019 2803
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2020
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2804
+					if ($globalDebug) {
2805
+						echo '☈ Lightning added'."\n";
2806
+					}
2021 2807
 					$Source->deleteOldLocationByType('lightning');
2022 2808
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2023 2809
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -2029,8 +2815,7 @@  discard block
 block discarded – undo
2029 2815
 				    	print_r($line);
2030 2816
 				    }
2031 2817
 				    unset($data);
2032
-				}
2033
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2818
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2034 2819
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2035 2820
 				}
2036 2821
 				/*
@@ -2039,7 +2824,9 @@  discard block
 block discarded – undo
2039 2824
 				}
2040 2825
 				*/
2041 2826
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2042
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2827
+				elseif ($line === true && $globalDebug) {
2828
+					echo '!! Failed : '.$buffer."!!\n";
2829
+				}
2043 2830
 				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2044 2831
 					$Source->deleteOldLocationByType('lightning');
2045 2832
 					$Source->deleteOldLocationByType('wx');
@@ -2076,27 +2863,47 @@  discard block
 block discarded – undo
2076 2863
     				$data['ground'] = $line[21];
2077 2864
     				$data['emergency'] = $line[19];
2078 2865
     				$data['format_source'] = 'sbs';
2079
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2080
-				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2081
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2082
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2866
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2867
+					$data['source_name'] = $globalSources[$nb]['name'];
2868
+				} elseif ($line[0] == 'MLAT') {
2869
+					$data['source_name'] = 'MLAT';
2870
+				}
2871
+				if (isset($globalSources[$nb]['sourcestats'])) {
2872
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2873
+				}
2874
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2875
+					$data['noarchive'] = true;
2876
+				}
2083 2877
     				$data['id_source'] = $id_source;
2084
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2085
-    				else $error = true;
2878
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2879
+    					$send = $SI->add($data);
2880
+    				} else {
2881
+    					$error = true;
2882
+    				}
2086 2883
     				unset($data);
2087
-    			    } else $error = true;
2884
+    			    } else {
2885
+    			    	$error = true;
2886
+    			    }
2088 2887
 			    if ($error) {
2089 2888
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2090
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2889
+					if ($globalDebug) {
2890
+						echo "Not a message. Ignoring... \n";
2891
+					}
2091 2892
 				} else {
2092
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2893
+					if ($globalDebug) {
2894
+						echo "Wrong line format. Ignoring... \n";
2895
+					}
2093 2896
 					if ($globalDebug) {
2094 2897
 						echo $buffer;
2095 2898
 						//print_r($line);
2096 2899
 					}
2097 2900
 					//socket_close($r);
2098
-					if ($globalDebug) echo "Reconnect after an error...\n";
2099
-					if ($format === 'aprs') $aprs_connect = 0;
2901
+					if ($globalDebug) {
2902
+						echo "Reconnect after an error...\n";
2903
+					}
2904
+					if ($format === 'aprs') {
2905
+						$aprs_connect = 0;
2906
+					}
2100 2907
 					$sourceer[$nb] = $globalSources[$nb];
2101 2908
 					connect_all($sourceer);
2102 2909
 					$sourceer = array();
@@ -2104,10 +2911,14 @@  discard block
 block discarded – undo
2104 2911
 			    }
2105 2912
 			}
2106 2913
 			// Sleep for xxx microseconds
2107
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2914
+			if (isset($globalSBSSleep)) {
2915
+				usleep($globalSBSSleep);
2916
+			}
2108 2917
 		    } else {
2109 2918
 			if ($format === 'flightgearmp') {
2110
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2919
+			    	if ($globalDebug) {
2920
+			    		echo "Reconnect FlightGear MP...";
2921
+			    	}
2111 2922
 				//@socket_close($r);
2112 2923
 				sleep($globalMinFetch);
2113 2924
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2116,10 +2927,15 @@  discard block
 block discarded – undo
2116 2927
 				break;
2117 2928
 				
2118 2929
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2119
-			    if (isset($tt[$format])) $tt[$format]++;
2120
-			    else $tt[$format] = 0;
2930
+			    if (isset($tt[$format])) {
2931
+			    	$tt[$format]++;
2932
+			    } else {
2933
+			    	$tt[$format] = 0;
2934
+			    }
2121 2935
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
2122
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2936
+				if ($globalDebug) {
2937
+					echo "ERROR : Reconnect ".$format."...";
2938
+				}
2123 2939
 				//@socket_close($r);
2124 2940
 				sleep(2);
2125 2941
 				$aprs_connect = 0;
@@ -2137,11 +2953,17 @@  discard block
 block discarded – undo
2137 2953
 	    } else {
2138 2954
 		$error = socket_strerror(socket_last_error());
2139 2955
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2140
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2141
-			if (isset($globalDebug)) echo "Restarting...\n";
2956
+			if ($globalDebug) {
2957
+				echo "ERROR : socket_select give this error ".$error . "\n";
2958
+			}
2959
+			if (isset($globalDebug)) {
2960
+				echo "Restarting...\n";
2961
+			}
2142 2962
 			// Restart the script if possible
2143 2963
 			if (is_array($sockets)) {
2144
-			    if ($globalDebug) echo "Shutdown all sockets...";
2964
+			    if ($globalDebug) {
2965
+			    	echo "Shutdown all sockets...";
2966
+			    }
2145 2967
 			    
2146 2968
 			    foreach ($sockets as $sock) {
2147 2969
 				@socket_shutdown($sock,2);
@@ -2149,25 +2971,45 @@  discard block
 block discarded – undo
2149 2971
 			    }
2150 2972
 			    
2151 2973
 			}
2152
-			if ($globalDebug) echo "Waiting...";
2974
+			if ($globalDebug) {
2975
+				echo "Waiting...";
2976
+			}
2153 2977
 			sleep(2);
2154 2978
 			$time = time();
2155 2979
 			//connect_all($hosts);
2156 2980
 			$aprs_connect = 0;
2157
-			if ($reset%5 === 0) sleep(20);
2158
-			if ($reset%10 === 0) sleep(100);
2159
-			if ($reset%20 === 0) sleep(200);
2160
-			if ($reset > 100) exit('Too many attempts...');
2161
-			if ($globalDebug) echo "Restart all connections...";
2981
+			if ($reset%5 === 0) {
2982
+				sleep(20);
2983
+			}
2984
+			if ($reset%10 === 0) {
2985
+				sleep(100);
2986
+			}
2987
+			if ($reset%20 === 0) {
2988
+				sleep(200);
2989
+			}
2990
+			if ($reset > 100) {
2991
+				exit('Too many attempts...');
2992
+			}
2993
+			if ($globalDebug) {
2994
+				echo "Restart all connections...";
2995
+			}
2162 2996
 			connect_all($globalSources);
2163 2997
 		}
2164 2998
 	    }
2165 2999
 	}
2166 3000
 	if ($globalDaemon === false) {
2167
-	    if ($globalDebug) echo 'Check all...'."\n";
2168
-	    if (isset($SI)) $SI->checkAll();
2169
-	    if (isset($TI)) $TI->checkAll();
2170
-	    if (isset($MI)) $MI->checkAll();
3001
+	    if ($globalDebug) {
3002
+	    	echo 'Check all...'."\n";
3003
+	    }
3004
+	    if (isset($SI)) {
3005
+	    	$SI->checkAll();
3006
+	    }
3007
+	    if (isset($TI)) {
3008
+	    	$TI->checkAll();
3009
+	    }
3010
+	    if (isset($MI)) {
3011
+	    	$MI->checkAll();
3012
+	    }
2171 3013
 	}
2172 3014
     }
2173 3015
 }
Please login to merge, or discard this patch.