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