Completed
Push — master ( 0c9c91...d02653 )
by Yannick
22:24 queued 05:51
created
scripts/daemon-spotter.php 3 patches
Indentation   +875 added lines, -875 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,155 +342,155 @@  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])) {
448
-	    $nn = stream_select($arr,$w,$e,$timeout);
449
-	    if ($nn > 0) {
447
+		if (isset($arr[$id])) {
448
+		$nn = stream_select($arr,$w,$e,$timeout);
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);
454
-		    foreach ($buffer as $line) {
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
+			foreach ($buffer as $line) {
455 455
 			if ($line != '') {
456
-			    $ais_data = $AIS->parse_line(trim($line));
457
-			    $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['type'])) $data['type'] = $ais_data['type'];
466
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
467
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
468
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
469
-			    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['timestamp'])) {
456
+				$ais_data = $AIS->parse_line(trim($line));
457
+				$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['type'])) $data['type'] = $ais_data['type'];
466
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
467
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
468
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
469
+				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['timestamp'])) {
471 471
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
472
-			    } else {
472
+				} else {
473 473
 				$data['datetime'] = date('Y-m-d H:i:s');
474
-			    }
475
-			    $data['format_source'] = 'aisnmeahttp';
476
-			    $data['id_source'] = $id_source;
477
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
478
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
479
-			    unset($data);
474
+				}
475
+				$data['format_source'] = 'aisnmeahttp';
476
+				$data['id_source'] = $id_source;
477
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
478
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
479
+				unset($data);
480
+			}
480 481
 			}
481
-		    }
482 482
 		}
483 483
 		}
484
-	    }
484
+		}
485 485
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
486
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
487
-	    if ($buffer != '') {
486
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
487
+		if ($buffer != '') {
488 488
 		//echo $buffer;
489 489
 		$all_data = json_decode($buffer,true);
490 490
 		//print_r($all_data);
491 491
 		if (isset($all_data[0]['DATA'])) {
492 492
 		foreach ($all_data[0]['DATA'] as $line) {
493
-		    if ($line != '') {
493
+			if ($line != '') {
494 494
 			$data = array();
495 495
 			$data['ident'] = $line['NAME'];
496 496
 			$data['mmsi'] = $line['MMSI'];
@@ -507,89 +507,89 @@  discard block
 block discarded – undo
507 507
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
508 508
 			$MI->add($data);
509 509
 			unset($data);
510
-		    }
510
+			}
511 511
 		}
512 512
 		}
513 513
 		
514
-	    }
515
-    	    $last_exec[$id]['last'] = time();
514
+		}
515
+			$last_exec[$id]['last'] = time();
516 516
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
517
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
518
-	    if ($buffer != '') {
517
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
518
+		if ($buffer != '') {
519 519
 		$all_data = json_decode($buffer,true);
520 520
 		if (isset($all_data[0]['mmsi'])) {
521
-		    foreach ($all_data as $line) {
521
+			foreach ($all_data as $line) {
522 522
 			if ($line != '') {
523
-			    $data = array();
524
-			    $data['ident'] = $line['shipname'];
525
-			    $data['callsign'] = $line['callsign'];
526
-			    $data['mmsi'] = $line['mmsi'];
527
-			    $data['speed'] = $line['sog'];
528
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
529
-			    $data['latitude'] = $line['latitude'];
530
-			    $data['longitude'] = $line['longitude'];
531
-			    $data['type_id'] = $line['shiptype'];
532
-			    $data['arrival_code'] = $line['destination'];
533
-			    $data['datetime'] = $line['time'];
534
-			    $data['format_source'] = 'boatbeaconapp';
535
-			    $data['id_source'] = $id_source;
536
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
537
-			    $MI->add($data);
538
-			    unset($data);
523
+				$data = array();
524
+				$data['ident'] = $line['shipname'];
525
+				$data['callsign'] = $line['callsign'];
526
+				$data['mmsi'] = $line['mmsi'];
527
+				$data['speed'] = $line['sog'];
528
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
529
+				$data['latitude'] = $line['latitude'];
530
+				$data['longitude'] = $line['longitude'];
531
+				$data['type_id'] = $line['shiptype'];
532
+				$data['arrival_code'] = $line['destination'];
533
+				$data['datetime'] = $line['time'];
534
+				$data['format_source'] = 'boatbeaconapp';
535
+				$data['id_source'] = $id_source;
536
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
537
+				$MI->add($data);
538
+				unset($data);
539
+			}
539 540
 			}
540
-		    }
541 541
 		}
542 542
 		
543
-	    }
544
-    	    $last_exec[$id]['last'] = time();
543
+		}
544
+			$last_exec[$id]['last'] = time();
545 545
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
546
-	    echo 'download...';
547
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
548
-	    echo 'done !'."\n";
549
-	    if ($buffer != '') $reset = 0;
550
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
551
-	    $buffer = explode('\n',$buffer);
552
-	    foreach ($buffer as $line) {
546
+		echo 'download...';
547
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
548
+		echo 'done !'."\n";
549
+		if ($buffer != '') $reset = 0;
550
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
551
+		$buffer = explode('\n',$buffer);
552
+		foreach ($buffer as $line) {
553 553
 		if ($line != '') {
554
-		    $data = array();
555
-		    $data['mmsi'] = (int)substr($line,0,9);
556
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
557
-		    //$data['status'] = substr($line,21,2);
558
-		    //$data['type'] = substr($line,24,3);
559
-		    $data['latitude'] = substr($line,29,9);
560
-		    $data['longitude'] = substr($line,41,9);
561
-		    $data['speed'] = round(substr($line,51,5));
562
-		    //$data['course'] = substr($line,57,5);
563
-		    $data['heading'] = round(substr($line,63,3));
564
-		    //$data['draft'] = substr($line,67,4);
565
-		    //$data['length'] = substr($line,72,3);
566
-		    //$data['beam'] = substr($line,76,2);
567
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
568
-		    //$data['callsign'] = trim(substr($line,100,7);
569
-		    //$data['dest'] = substr($line,108,20);
570
-		    //$data['etaDate'] = substr($line,129,5);
571
-		    //$data['etaTime'] = substr($line,135,5);
572
-		    $data['format_source'] = 'shipplotter';
573
-    		    $data['id_source'] = $id_source;
574
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
575
-		    //print_r($data);
576
-		    echo 'Add...'."\n";
577
-		    $MI->add($data);
578
-		    unset($data);
554
+			$data = array();
555
+			$data['mmsi'] = (int)substr($line,0,9);
556
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
557
+			//$data['status'] = substr($line,21,2);
558
+			//$data['type'] = substr($line,24,3);
559
+			$data['latitude'] = substr($line,29,9);
560
+			$data['longitude'] = substr($line,41,9);
561
+			$data['speed'] = round(substr($line,51,5));
562
+			//$data['course'] = substr($line,57,5);
563
+			$data['heading'] = round(substr($line,63,3));
564
+			//$data['draft'] = substr($line,67,4);
565
+			//$data['length'] = substr($line,72,3);
566
+			//$data['beam'] = substr($line,76,2);
567
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
568
+			//$data['callsign'] = trim(substr($line,100,7);
569
+			//$data['dest'] = substr($line,108,20);
570
+			//$data['etaDate'] = substr($line,129,5);
571
+			//$data['etaTime'] = substr($line,135,5);
572
+			$data['format_source'] = 'shipplotter';
573
+				$data['id_source'] = $id_source;
574
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
575
+			//print_r($data);
576
+			echo 'Add...'."\n";
577
+			$MI->add($data);
578
+			unset($data);
579 579
 		}
580
-    	    }
581
-    	    $last_exec[$id]['last'] = time();
580
+			}
581
+			$last_exec[$id]['last'] = time();
582 582
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
583 583
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
584
-	    //$buffer = $Common->getData($hosts[$id]);
585
-	    $buffer = $Common->getData($value['host']);
586
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
587
-	    $buffer = explode('\n',$buffer);
588
-	    $reset = 0;
589
-	    foreach ($buffer as $line) {
590
-    		if ($line != '') {
591
-    		    $line = explode(':', $line);
592
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
584
+		//$buffer = $Common->getData($hosts[$id]);
585
+		$buffer = $Common->getData($value['host']);
586
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
587
+		$buffer = explode('\n',$buffer);
588
+		$reset = 0;
589
+		foreach ($buffer as $line) {
590
+			if ($line != '') {
591
+				$line = explode(':', $line);
592
+				if (count($line) > 30 && $line[0] != 'callsign') {
593 593
 			$data = array();
594 594
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
595 595
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -602,37 +602,37 @@  discard block
 block discarded – undo
602 602
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
603 603
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
604 604
 			$data['latitude'] = $line[5]; // lat
605
-	        	$data['longitude'] = $line[6]; // long
606
-	        	$data['verticalrate'] = ''; // vertical rate
607
-	        	$data['squawk'] = ''; // squawk
608
-	        	$data['emergency'] = ''; // emergency
609
-	        	$data['waypoints'] = $line[30];
605
+				$data['longitude'] = $line[6]; // long
606
+				$data['verticalrate'] = ''; // vertical rate
607
+				$data['squawk'] = ''; // squawk
608
+				$data['emergency'] = ''; // emergency
609
+				$data['waypoints'] = $line[30];
610 610
 			$data['datetime'] = date('Y-m-d H:i:s');
611 611
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
612 612
 			//if (isset($line[37])) $data['last_update'] = $line[37];
613
-		        $data['departure_airport_icao'] = $line[11];
614
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
615
-		        $data['arrival_airport_icao'] = $line[13];
613
+				$data['departure_airport_icao'] = $line[11];
614
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
615
+				$data['arrival_airport_icao'] = $line[13];
616 616
 			$data['frequency'] = $line[4];
617 617
 			$data['type'] = $line[18];
618 618
 			$data['range'] = $line[19];
619 619
 			if (isset($line[35])) $data['info'] = $line[35];
620
-    			$data['id_source'] = $id_source;
621
-	    		//$data['arrival_airport_time'] = ;
622
-	    		if ($line[9] != '') {
623
-	    		    $aircraft_data = explode('/',$line[9]);
624
-	    		    if (isset($aircraft_data[1])) {
625
-	    			$data['aircraft_icao'] = $aircraft_data[1];
626
-	    		    }
627
-        		}
628
-	    		/*
620
+				$data['id_source'] = $id_source;
621
+				//$data['arrival_airport_time'] = ;
622
+				if ($line[9] != '') {
623
+					$aircraft_data = explode('/',$line[9]);
624
+					if (isset($aircraft_data[1])) {
625
+					$data['aircraft_icao'] = $aircraft_data[1];
626
+					}
627
+				}
628
+				/*
629 629
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
630 630
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
631 631
 	    		*/
632
-	    		$data['format_source'] = $value['format'];
632
+				$data['format_source'] = $value['format'];
633 633
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
634 634
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
635
-    			if ($line[3] == 'PILOT') $SI->add($data);
635
+				if ($line[3] == 'PILOT') $SI->add($data);
636 636
 			elseif ($line[3] == 'ATC') {
637 637
 				//print_r($data);
638 638
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -650,254 +650,254 @@  discard block
 block discarded – undo
650 650
 				if (!isset($data['source_name'])) $data['source_name'] = '';
651 651
 				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']);
652 652
 			}
653
-    			unset($data);
654
-    		    }
655
-    		}
656
-    	    }
657
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
658
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
659
-    	    $last_exec[$id]['last'] = time();
660
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
661
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
662
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
663
-	    if ($buffer != '') {
664
-	    $all_data = json_decode($buffer,true);
665
-	    if (isset($all_data['acList'])) {
653
+				unset($data);
654
+				}
655
+			}
656
+			}
657
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
658
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
659
+			$last_exec[$id]['last'] = time();
660
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
661
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
662
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
663
+		if ($buffer != '') {
664
+		$all_data = json_decode($buffer,true);
665
+		if (isset($all_data['acList'])) {
666 666
 		$reset = 0;
667 667
 		foreach ($all_data['acList'] as $line) {
668
-		    $data = array();
669
-		    $data['hex'] = $line['Icao']; // hex
670
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
671
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
672
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
673
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
674
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
675
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
676
-		    //$data['verticalrate'] = $line['']; // verticale rate
677
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
678
-		    $data['emergency'] = ''; // emergency
679
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
680
-		    /*
668
+			$data = array();
669
+			$data['hex'] = $line['Icao']; // hex
670
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
671
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
672
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
673
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
674
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
675
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
676
+			//$data['verticalrate'] = $line['']; // verticale rate
677
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
678
+			$data['emergency'] = ''; // emergency
679
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
680
+			/*
681 681
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
682 682
 		    else $data['datetime'] = date('Y-m-d H:i:s');
683 683
 		    */
684
-		    $data['datetime'] = date('Y-m-d H:i:s');
685
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
686
-	    	    $data['format_source'] = 'aircraftlistjson';
687
-		    $data['id_source'] = $id_source;
688
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
689
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
690
-		    if (isset($data['latitude'])) $SI->add($data);
691
-		    unset($data);
684
+			$data['datetime'] = date('Y-m-d H:i:s');
685
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
686
+				$data['format_source'] = 'aircraftlistjson';
687
+			$data['id_source'] = $id_source;
688
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
689
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
690
+			if (isset($data['latitude'])) $SI->add($data);
691
+			unset($data);
692 692
 		}
693
-	    } elseif (is_array($all_data)) {
693
+		} elseif (is_array($all_data)) {
694 694
 		$reset = 0;
695 695
 		foreach ($all_data as $line) {
696
-		    $data = array();
697
-		    $data['hex'] = $line['hex']; // hex
698
-		    $data['ident'] = $line['flight']; // ident
699
-		    $data['altitude'] = $line['altitude']; // altitude
700
-		    $data['speed'] = $line['speed']; // speed
701
-		    $data['heading'] = $line['track']; // heading
702
-		    $data['latitude'] = $line['lat']; // lat
703
-		    $data['longitude'] = $line['lon']; // long
704
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
705
-		    $data['squawk'] = $line['squawk']; // squawk
706
-		    $data['emergency'] = ''; // emergency
707
-		    $data['datetime'] = date('Y-m-d H:i:s');
708
-	    	    $data['format_source'] = 'aircraftlistjson';
709
-    		    $data['id_source'] = $id_source;
710
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
711
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
712
-		    $SI->add($data);
713
-		    unset($data);
696
+			$data = array();
697
+			$data['hex'] = $line['hex']; // hex
698
+			$data['ident'] = $line['flight']; // ident
699
+			$data['altitude'] = $line['altitude']; // altitude
700
+			$data['speed'] = $line['speed']; // speed
701
+			$data['heading'] = $line['track']; // heading
702
+			$data['latitude'] = $line['lat']; // lat
703
+			$data['longitude'] = $line['lon']; // long
704
+			$data['verticalrate'] = $line['vrt']; // verticale rate
705
+			$data['squawk'] = $line['squawk']; // squawk
706
+			$data['emergency'] = ''; // emergency
707
+			$data['datetime'] = date('Y-m-d H:i:s');
708
+				$data['format_source'] = 'aircraftlistjson';
709
+				$data['id_source'] = $id_source;
710
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
711
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
712
+			$SI->add($data);
713
+			unset($data);
714 714
 		}
715
-	    }
716
-	    }
717
-    	    //$last_exec['aircraftlistjson'] = time();
718
-    	    $last_exec[$id]['last'] = time();
719
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
720
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
721
-	    $buffer = $Common->getData($value['host']);
722
-	    $all_data = json_decode($buffer,true);
723
-	    if (isset($all_data['planes'])) {
715
+		}
716
+		}
717
+			//$last_exec['aircraftlistjson'] = time();
718
+			$last_exec[$id]['last'] = time();
719
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
720
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
721
+		$buffer = $Common->getData($value['host']);
722
+		$all_data = json_decode($buffer,true);
723
+		if (isset($all_data['planes'])) {
724 724
 		$reset = 0;
725 725
 		foreach ($all_data['planes'] as $key => $line) {
726
-		    $data = array();
727
-		    $data['hex'] = $key; // hex
728
-		    $data['ident'] = $line[3]; // ident
729
-		    $data['altitude'] = $line[6]; // altitude
730
-		    $data['speed'] = $line[8]; // speed
731
-		    $data['heading'] = $line[7]; // heading
732
-		    $data['latitude'] = $line[4]; // lat
733
-		    $data['longitude'] = $line[5]; // long
734
-		    //$data['verticalrate'] = $line[]; // verticale rate
735
-		    $data['squawk'] = $line[10]; // squawk
736
-		    $data['emergency'] = ''; // emergency
737
-		    $data['registration'] = $line[2];
738
-		    $data['aircraft_icao'] = $line[0];
739
-		    $deparr = explode('-',$line[1]);
740
-		    if (count($deparr) == 2) {
726
+			$data = array();
727
+			$data['hex'] = $key; // hex
728
+			$data['ident'] = $line[3]; // ident
729
+			$data['altitude'] = $line[6]; // altitude
730
+			$data['speed'] = $line[8]; // speed
731
+			$data['heading'] = $line[7]; // heading
732
+			$data['latitude'] = $line[4]; // lat
733
+			$data['longitude'] = $line[5]; // long
734
+			//$data['verticalrate'] = $line[]; // verticale rate
735
+			$data['squawk'] = $line[10]; // squawk
736
+			$data['emergency'] = ''; // emergency
737
+			$data['registration'] = $line[2];
738
+			$data['aircraft_icao'] = $line[0];
739
+			$deparr = explode('-',$line[1]);
740
+			if (count($deparr) == 2) {
741 741
 			$data['departure_airport_icao'] = $deparr[0];
742 742
 			$data['arrival_airport_icao'] = $deparr[1];
743
-		    }
744
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
745
-	    	    $data['format_source'] = 'planeupdatefaa';
746
-    		    $data['id_source'] = $id_source;
747
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
748
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
749
-		    $SI->add($data);
750
-		    unset($data);
743
+			}
744
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
745
+				$data['format_source'] = 'planeupdatefaa';
746
+				$data['id_source'] = $id_source;
747
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
748
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
749
+			$SI->add($data);
750
+			unset($data);
751 751
 		}
752
-	    }
753
-    	    //$last_exec['planeupdatefaa'] = time();
754
-    	    $last_exec[$id]['last'] = time();
755
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
756
-	    $buffer = $Common->getData($value['host']);
757
-	    $all_data = json_decode($buffer,true);
758
-	    if (isset($all_data['states'])) {
752
+		}
753
+			//$last_exec['planeupdatefaa'] = time();
754
+			$last_exec[$id]['last'] = time();
755
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
756
+		$buffer = $Common->getData($value['host']);
757
+		$all_data = json_decode($buffer,true);
758
+		if (isset($all_data['states'])) {
759 759
 		$reset = 0;
760 760
 		foreach ($all_data['states'] as $key => $line) {
761
-		    $data = array();
762
-		    $data['hex'] = $line[0]; // hex
763
-		    $data['ident'] = trim($line[1]); // ident
764
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
765
-		    $data['speed'] = round($line[9]*1.94384); // speed
766
-		    $data['heading'] = round($line[10]); // heading
767
-		    $data['latitude'] = $line[5]; // lat
768
-		    $data['longitude'] = $line[6]; // long
769
-		    $data['verticalrate'] = $line[11]; // verticale rate
770
-		    //$data['squawk'] = $line[10]; // squawk
771
-		    //$data['emergency'] = ''; // emergency
772
-		    //$data['registration'] = $line[2];
773
-		    //$data['aircraft_icao'] = $line[0];
774
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
775
-	    	    $data['format_source'] = 'opensky';
776
-    		    $data['id_source'] = $id_source;
777
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
778
-		    $SI->add($data);
779
-		    unset($data);
761
+			$data = array();
762
+			$data['hex'] = $line[0]; // hex
763
+			$data['ident'] = trim($line[1]); // ident
764
+			$data['altitude'] = round($line[7]*3.28084); // altitude
765
+			$data['speed'] = round($line[9]*1.94384); // speed
766
+			$data['heading'] = round($line[10]); // heading
767
+			$data['latitude'] = $line[5]; // lat
768
+			$data['longitude'] = $line[6]; // long
769
+			$data['verticalrate'] = $line[11]; // verticale rate
770
+			//$data['squawk'] = $line[10]; // squawk
771
+			//$data['emergency'] = ''; // emergency
772
+			//$data['registration'] = $line[2];
773
+			//$data['aircraft_icao'] = $line[0];
774
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
775
+				$data['format_source'] = 'opensky';
776
+				$data['id_source'] = $id_source;
777
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
778
+			$SI->add($data);
779
+			unset($data);
780 780
 		}
781
-	    }
782
-    	    //$last_exec['planeupdatefaa'] = time();
783
-    	    $last_exec[$id]['last'] = time();
784
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
785
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
786
-	    //$buffer = $Common->getData($hosts[$id]);
787
-	    $buffer = $Common->getData($value['host']);
788
-	    $all_data = json_decode($buffer,true);
789
-	    if (!empty($all_data)) $reset = 0;
790
-	    foreach ($all_data as $key => $line) {
781
+		}
782
+			//$last_exec['planeupdatefaa'] = time();
783
+			$last_exec[$id]['last'] = time();
784
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
785
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
786
+		//$buffer = $Common->getData($hosts[$id]);
787
+		$buffer = $Common->getData($value['host']);
788
+		$all_data = json_decode($buffer,true);
789
+		if (!empty($all_data)) $reset = 0;
790
+		foreach ($all_data as $key => $line) {
791 791
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
792
-		    $data = array();
793
-		    $data['hex'] = $line[0];
794
-		    $data['ident'] = $line[16]; //$line[13]
795
-	    	    $data['altitude'] = $line[4]; // altitude
796
-	    	    $data['speed'] = $line[5]; // speed
797
-	    	    $data['heading'] = $line[3]; // heading
798
-	    	    $data['latitude'] = $line[1]; // lat
799
-	    	    $data['longitude'] = $line[2]; // long
800
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
801
-	    	    $data['squawk'] = $line[6]; // squawk
802
-	    	    $data['aircraft_icao'] = $line[8];
803
-	    	    $data['registration'] = $line[9];
804
-		    $data['departure_airport_iata'] = $line[11];
805
-		    $data['arrival_airport_iata'] = $line[12];
806
-	    	    $data['emergency'] = ''; // emergency
807
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
808
-	    	    $data['format_source'] = 'fr24json';
809
-    		    $data['id_source'] = $id_source;
810
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
811
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
812
-		    $SI->add($data);
813
-		    unset($data);
792
+			$data = array();
793
+			$data['hex'] = $line[0];
794
+			$data['ident'] = $line[16]; //$line[13]
795
+				$data['altitude'] = $line[4]; // altitude
796
+				$data['speed'] = $line[5]; // speed
797
+				$data['heading'] = $line[3]; // heading
798
+				$data['latitude'] = $line[1]; // lat
799
+				$data['longitude'] = $line[2]; // long
800
+				$data['verticalrate'] = $line[15]; // verticale rate
801
+				$data['squawk'] = $line[6]; // squawk
802
+				$data['aircraft_icao'] = $line[8];
803
+				$data['registration'] = $line[9];
804
+			$data['departure_airport_iata'] = $line[11];
805
+			$data['arrival_airport_iata'] = $line[12];
806
+				$data['emergency'] = ''; // emergency
807
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
808
+				$data['format_source'] = 'fr24json';
809
+				$data['id_source'] = $id_source;
810
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
811
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
812
+			$SI->add($data);
813
+			unset($data);
814
+		}
814 815
 		}
815
-	    }
816
-    	    //$last_exec['fr24json'] = time();
817
-    	    $last_exec[$id]['last'] = time();
818
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
819
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
820
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
821
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
822
-	    //echo $buffer;
823
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
824
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
825
-	    $all_data = json_decode($buffer,true);
826
-	    if (json_last_error() != JSON_ERROR_NONE) {
816
+			//$last_exec['fr24json'] = time();
817
+			$last_exec[$id]['last'] = time();
818
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
819
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
820
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
821
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
822
+		//echo $buffer;
823
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
824
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
825
+		$all_data = json_decode($buffer,true);
826
+		if (json_last_error() != JSON_ERROR_NONE) {
827 827
 		die(json_last_error_msg());
828
-	    }
829
-	    if (isset($all_data['mrkrs'])) {
828
+		}
829
+		if (isset($all_data['mrkrs'])) {
830 830
 		$reset = 0;
831 831
 		foreach ($all_data['mrkrs'] as $key => $line) {
832
-		    if (isset($line['inf'])) {
832
+			if (isset($line['inf'])) {
833 833
 			$data = array();
834 834
 			$data['hex'] = $line['inf']['ia'];
835 835
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
836
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
837
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
838
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
839
-	    		$data['latitude'] = $line['pt'][0]; // lat
840
-	    		$data['longitude'] = $line['pt'][1]; // long
841
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
842
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
843
-	    		//$data['aircraft_icao'] = $line[8];
844
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
836
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
837
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
838
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
839
+				$data['latitude'] = $line['pt'][0]; // lat
840
+				$data['longitude'] = $line['pt'][1]; // long
841
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
842
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
843
+				//$data['aircraft_icao'] = $line[8];
844
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
845 845
 			//$data['departure_airport_iata'] = $line[11];
846 846
 			//$data['arrival_airport_iata'] = $line[12];
847
-	    		//$data['emergency'] = ''; // emergency
847
+				//$data['emergency'] = ''; // emergency
848 848
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
849
-	    		$data['format_source'] = 'radarvirtueljson';
850
-    			$data['id_source'] = $id_source;
849
+				$data['format_source'] = 'radarvirtueljson';
850
+				$data['id_source'] = $id_source;
851 851
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
852 852
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
853 853
 			$SI->add($data);
854 854
 			unset($data);
855
-		    }
855
+			}
856
+		}
856 857
 		}
857
-	    }
858
-    	    //$last_exec['radarvirtueljson'] = time();
859
-    	    $last_exec[$id]['last'] = time();
860
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
861
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
862
-	    //$buffer = $Common->getData($hosts[$id]);
863
-	    $buffer = $Common->getData($value['host'].'?'.time());
864
-	    $all_data = json_decode(utf8_encode($buffer),true);
858
+			//$last_exec['radarvirtueljson'] = time();
859
+			$last_exec[$id]['last'] = time();
860
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
861
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
862
+		//$buffer = $Common->getData($hosts[$id]);
863
+		$buffer = $Common->getData($value['host'].'?'.time());
864
+		$all_data = json_decode(utf8_encode($buffer),true);
865 865
 	    
866
-	    if (isset($all_data['pireps'])) {
866
+		if (isset($all_data['pireps'])) {
867 867
 		$reset = 0;
868
-	        foreach ($all_data['pireps'] as $line) {
869
-		    $data = array();
870
-		    $data['id'] = $line['id'];
871
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
872
-		    $data['ident'] = $line['callsign']; // ident
873
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
874
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
875
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
876
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
877
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
878
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
879
-		    $data['latitude'] = $line['lat']; // lat
880
-		    $data['longitude'] = $line['lon']; // long
881
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
882
-		    //$data['squawk'] = $line['squawk']; // squawk
883
-		    //$data['emergency'] = ''; // emergency
884
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
885
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
886
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
887
-		    //$data['arrival_airport_time'] = $line['arrtime'];
888
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
889
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
890
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
891
-		    else $data['info'] = '';
892
-		    $data['format_source'] = 'pireps';
893
-    		    $data['id_source'] = $id_source;
894
-		    $data['datetime'] = date('Y-m-d H:i:s');
895
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
896
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
897
-		    if ($line['icon'] == 'plane') {
868
+			foreach ($all_data['pireps'] as $line) {
869
+			$data = array();
870
+			$data['id'] = $line['id'];
871
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
872
+			$data['ident'] = $line['callsign']; // ident
873
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
874
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
875
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
876
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
877
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
878
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
879
+			$data['latitude'] = $line['lat']; // lat
880
+			$data['longitude'] = $line['lon']; // long
881
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
882
+			//$data['squawk'] = $line['squawk']; // squawk
883
+			//$data['emergency'] = ''; // emergency
884
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
885
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
886
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
887
+			//$data['arrival_airport_time'] = $line['arrtime'];
888
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
889
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
890
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
891
+			else $data['info'] = '';
892
+			$data['format_source'] = 'pireps';
893
+				$data['id_source'] = $id_source;
894
+			$data['datetime'] = date('Y-m-d H:i:s');
895
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
896
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
897
+			if ($line['icon'] == 'plane') {
898 898
 			$SI->add($data);
899
-		    //    print_r($data);
900
-    		    } elseif ($line['icon'] == 'ct') {
899
+			//    print_r($data);
900
+				} elseif ($line['icon'] == 'ct') {
901 901
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
902 902
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
903 903
 			$typec = substr($data['ident'],-3);
@@ -912,196 +912,196 @@  discard block
 block discarded – undo
912 912
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
913 913
 			else $data['type'] = 'Observer';
914 914
 			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']);
915
-		    }
916
-		    unset($data);
915
+			}
916
+			unset($data);
917
+		}
917 918
 		}
918
-	    }
919
-    	    //$last_exec['pirepsjson'] = time();
920
-    	    $last_exec[$id]['last'] = time();
921
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
922
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
923
-	    //$buffer = $Common->getData($hosts[$id]);
924
-	    if ($globalDebug) echo 'Get Data...'."\n";
925
-	    $buffer = $Common->getData($value['host']);
926
-	    $all_data = json_decode($buffer,true);
927
-	    if ($buffer != '' && is_array($all_data)) {
919
+			//$last_exec['pirepsjson'] = time();
920
+			$last_exec[$id]['last'] = time();
921
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
922
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
923
+		//$buffer = $Common->getData($hosts[$id]);
924
+		if ($globalDebug) echo 'Get Data...'."\n";
925
+		$buffer = $Common->getData($value['host']);
926
+		$all_data = json_decode($buffer,true);
927
+		if ($buffer != '' && is_array($all_data)) {
928 928
 		$reset = 0;
929 929
 		foreach ($all_data as $line) {
930
-	    	    $data = array();
931
-	    	    //$data['id'] = $line['id']; // id not usable
932
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
933
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
934
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
935
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
936
-	    	    $data['ident'] = $line['flightnum']; // ident
937
-	    	    $data['altitude'] = $line['alt']; // altitude
938
-	    	    $data['speed'] = $line['gs']; // speed
939
-	    	    $data['heading'] = $line['heading']; // heading
940
-	    	    $data['latitude'] = $line['lat']; // lat
941
-	    	    $data['longitude'] = $line['lng']; // long
942
-	    	    $data['verticalrate'] = ''; // verticale rate
943
-	    	    $data['squawk'] = ''; // squawk
944
-	    	    $data['emergency'] = ''; // emergency
945
-	    	    //$data['datetime'] = $line['lastupdate'];
946
-	    	    $data['last_update'] = $line['lastupdate'];
947
-		    $data['datetime'] = date('Y-m-d H:i:s');
948
-	    	    $data['departure_airport_icao'] = $line['depicao'];
949
-	    	    $data['departure_airport_time'] = $line['deptime'];
950
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
951
-    		    $data['arrival_airport_time'] = $line['arrtime'];
952
-    		    $data['registration'] = $line['aircraft'];
953
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
954
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
955
-		    if (isset($line['aircraftname'])) {
930
+				$data = array();
931
+				//$data['id'] = $line['id']; // id not usable
932
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
933
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
934
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
935
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
936
+				$data['ident'] = $line['flightnum']; // ident
937
+				$data['altitude'] = $line['alt']; // altitude
938
+				$data['speed'] = $line['gs']; // speed
939
+				$data['heading'] = $line['heading']; // heading
940
+				$data['latitude'] = $line['lat']; // lat
941
+				$data['longitude'] = $line['lng']; // long
942
+				$data['verticalrate'] = ''; // verticale rate
943
+				$data['squawk'] = ''; // squawk
944
+				$data['emergency'] = ''; // emergency
945
+				//$data['datetime'] = $line['lastupdate'];
946
+				$data['last_update'] = $line['lastupdate'];
947
+			$data['datetime'] = date('Y-m-d H:i:s');
948
+				$data['departure_airport_icao'] = $line['depicao'];
949
+				$data['departure_airport_time'] = $line['deptime'];
950
+				$data['arrival_airport_icao'] = $line['arricao'];
951
+				$data['arrival_airport_time'] = $line['arrtime'];
952
+				$data['registration'] = $line['aircraft'];
953
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
954
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
955
+			if (isset($line['aircraftname'])) {
956 956
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
957 957
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
958
-	    		$aircraft_data = explode('-',$line['aircraftname']);
959
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
960
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
961
-	    		else {
962
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
963
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
964
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
965
-	    		}
966
-	    	    }
967
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
968
-    		    $data['id_source'] = $id_source;
969
-	    	    $data['format_source'] = 'phpvmacars';
970
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
971
-		    $SI->add($data);
972
-		    unset($data);
958
+				$aircraft_data = explode('-',$line['aircraftname']);
959
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
960
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
961
+				else {
962
+					$aircraft_data = explode(' ',$line['aircraftname']);
963
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
964
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
965
+				}
966
+				}
967
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
968
+				$data['id_source'] = $id_source;
969
+				$data['format_source'] = 'phpvmacars';
970
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
971
+			$SI->add($data);
972
+			unset($data);
973 973
 		}
974 974
 		if ($globalDebug) echo 'No more data...'."\n";
975 975
 		unset($buffer);
976 976
 		unset($all_data);
977
-	    }
978
-    	    //$last_exec['phpvmacars'] = time();
979
-    	    $last_exec[$id]['last'] = time();
980
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
981
-	    //$buffer = $Common->getData($hosts[$id]);
982
-	    if ($globalDebug) echo 'Get Data...'."\n";
983
-	    $buffer = $Common->getData($value['host']);
984
-	    $all_data = json_decode($buffer,true);
985
-	    if ($buffer != '' && is_array($all_data)) {
977
+		}
978
+			//$last_exec['phpvmacars'] = time();
979
+			$last_exec[$id]['last'] = time();
980
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
981
+		//$buffer = $Common->getData($hosts[$id]);
982
+		if ($globalDebug) echo 'Get Data...'."\n";
983
+		$buffer = $Common->getData($value['host']);
984
+		$all_data = json_decode($buffer,true);
985
+		if ($buffer != '' && is_array($all_data)) {
986 986
 		$reset = 0;
987 987
 		foreach ($all_data as $line) {
988
-	    	    $data = array();
989
-	    	    //$data['id'] = $line['id']; // id not usable
990
-	    	    $data['id'] = trim($line['flight_id']);
991
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
992
-	    	    $data['pilot_name'] = $line['pilot_name'];
993
-	    	    $data['pilot_id'] = $line['pilot_id'];
994
-	    	    $data['ident'] = trim($line['callsign']); // ident
995
-	    	    $data['altitude'] = $line['altitude']; // altitude
996
-	    	    $data['speed'] = $line['gs']; // speed
997
-	    	    $data['heading'] = $line['heading']; // heading
998
-	    	    $data['latitude'] = $line['latitude']; // lat
999
-	    	    $data['longitude'] = $line['longitude']; // long
1000
-	    	    $data['verticalrate'] = ''; // verticale rate
1001
-	    	    $data['squawk'] = ''; // squawk
1002
-	    	    $data['emergency'] = ''; // emergency
1003
-	    	    //$data['datetime'] = $line['lastupdate'];
1004
-	    	    $data['last_update'] = $line['last_update'];
1005
-		    $data['datetime'] = date('Y-m-d H:i:s');
1006
-	    	    $data['departure_airport_icao'] = $line['departure'];
1007
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1008
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1009
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1010
-    		    //$data['registration'] = $line['aircraft'];
1011
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1012
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1013
-    		    $data['id_source'] = $id_source;
1014
-	    	    $data['format_source'] = 'vam';
1015
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1016
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1017
-		    $SI->add($data);
1018
-		    unset($data);
988
+				$data = array();
989
+				//$data['id'] = $line['id']; // id not usable
990
+				$data['id'] = trim($line['flight_id']);
991
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
992
+				$data['pilot_name'] = $line['pilot_name'];
993
+				$data['pilot_id'] = $line['pilot_id'];
994
+				$data['ident'] = trim($line['callsign']); // ident
995
+				$data['altitude'] = $line['altitude']; // altitude
996
+				$data['speed'] = $line['gs']; // speed
997
+				$data['heading'] = $line['heading']; // heading
998
+				$data['latitude'] = $line['latitude']; // lat
999
+				$data['longitude'] = $line['longitude']; // long
1000
+				$data['verticalrate'] = ''; // verticale rate
1001
+				$data['squawk'] = ''; // squawk
1002
+				$data['emergency'] = ''; // emergency
1003
+				//$data['datetime'] = $line['lastupdate'];
1004
+				$data['last_update'] = $line['last_update'];
1005
+			$data['datetime'] = date('Y-m-d H:i:s');
1006
+				$data['departure_airport_icao'] = $line['departure'];
1007
+				//$data['departure_airport_time'] = $line['departure_time'];
1008
+				$data['arrival_airport_icao'] = $line['arrival'];
1009
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1010
+				//$data['registration'] = $line['aircraft'];
1011
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1012
+				$data['aircraft_icao'] = $line['plane_type'];
1013
+				$data['id_source'] = $id_source;
1014
+				$data['format_source'] = 'vam';
1015
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1016
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1017
+			$SI->add($data);
1018
+			unset($data);
1019 1019
 		}
1020 1020
 		if ($globalDebug) echo 'No more data...'."\n";
1021 1021
 		unset($buffer);
1022 1022
 		unset($all_data);
1023
-	    }
1024
-    	    //$last_exec['phpvmacars'] = time();
1025
-    	    $last_exec[$id]['last'] = time();
1023
+		}
1024
+			//$last_exec['phpvmacars'] = time();
1025
+			$last_exec[$id]['last'] = time();
1026 1026
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1027 1027
 	} 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') {
1028
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1029
-    	    //$last_exec[$id]['last'] = time();
1028
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1029
+			//$last_exec[$id]['last'] = time();
1030 1030
 
1031
-	    //$read = array( $sockets[$id] );
1032
-	    $read = $sockets;
1033
-	    $write = NULL;
1034
-	    $e = NULL;
1035
-	    $n = socket_select($read, $write, $e, $timeout);
1036
-	    if ($e != NULL) var_dump($e);
1037
-	    if ($n > 0) {
1031
+		//$read = array( $sockets[$id] );
1032
+		$read = $sockets;
1033
+		$write = NULL;
1034
+		$e = NULL;
1035
+		$n = socket_select($read, $write, $e, $timeout);
1036
+		if ($e != NULL) var_dump($e);
1037
+		if ($n > 0) {
1038 1038
 		$reset = 0;
1039 1039
 		foreach ($read as $nb => $r) {
1040
-		    //$value = $formats[$nb];
1041
-		    $format = $globalSources[$nb]['format'];
1042
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1040
+			//$value = $formats[$nb];
1041
+			$format = $globalSources[$nb]['format'];
1042
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1043 1043
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1044
-		    } elseif ($format == 'vrstcp') {
1044
+			} elseif ($format == 'vrstcp') {
1045 1045
 			$buffer = @socket_read($r, 6000);
1046
-		    } else {
1046
+			} else {
1047 1047
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1048
-		    }
1049
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1050
-		    //echo $buffer."\n";
1051
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1052
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1053
-		    $error = false;
1054
-		    //$SI::del();
1055
-		    if ($format == 'vrstcp') {
1048
+			}
1049
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1050
+			//echo $buffer."\n";
1051
+			// lets play nice and handle signals such as ctrl-c/kill properly
1052
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1053
+			$error = false;
1054
+			//$SI::del();
1055
+			if ($format == 'vrstcp') {
1056 1056
 			$buffer = explode('},{',$buffer);
1057
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1058
-		    // SBS format is CSV format
1059
-		    if ($buffer !== FALSE && $buffer != '') {
1057
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1058
+			// SBS format is CSV format
1059
+			if ($buffer !== FALSE && $buffer != '') {
1060 1060
 			$tt[$format] = 0;
1061 1061
 			if ($format == 'acarssbs3') {
1062
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1063
-			    $ACARS->add(trim($buffer));
1064
-			    $ACARS->deleteLiveAcarsData();
1062
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1063
+				$ACARS->add(trim($buffer));
1064
+				$ACARS->deleteLiveAcarsData();
1065 1065
 			} elseif ($format == 'raw') {
1066
-			    // AVR format
1067
-			    $data = $SBS->parse($buffer);
1068
-			    if (is_array($data)) {
1066
+				// AVR format
1067
+				$data = $SBS->parse($buffer);
1068
+				if (is_array($data)) {
1069 1069
 				$data['datetime'] = date('Y-m-d H:i:s');
1070 1070
 				$data['format_source'] = 'raw';
1071 1071
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1072 1072
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1073 1073
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1074 1074
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1075
-			    }
1075
+				}
1076 1076
 			} elseif ($format == 'ais') {
1077
-			    $ais_data = $AIS->parse_line(trim($buffer));
1078
-			    $data = array();
1079
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1080
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1081
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1082
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1083
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1084
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1085
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1086
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1087
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1088
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1089
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1090
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1091
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1077
+				$ais_data = $AIS->parse_line(trim($buffer));
1078
+				$data = array();
1079
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1080
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1081
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1082
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1083
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1084
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1085
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1086
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1087
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1088
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1089
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1090
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1091
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1092 1092
 
1093
-			    if (isset($ais_data['timestamp'])) {
1093
+				if (isset($ais_data['timestamp'])) {
1094 1094
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1095
-			    } else {
1095
+				} else {
1096 1096
 				$data['datetime'] = date('Y-m-d H:i:s');
1097
-			    }
1098
-			    $data['format_source'] = 'aisnmea';
1099
-    			    $data['id_source'] = $id_source;
1100
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1101
-			    unset($data);
1102
-                        } elseif ($format == 'flightgearsp') {
1103
-                    	    //echo $buffer."\n";
1104
-                    	    if (strlen($buffer) > 5) {
1097
+				}
1098
+				$data['format_source'] = 'aisnmea';
1099
+					$data['id_source'] = $id_source;
1100
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1101
+				unset($data);
1102
+						} elseif ($format == 'flightgearsp') {
1103
+							//echo $buffer."\n";
1104
+							if (strlen($buffer) > 5) {
1105 1105
 				$line = explode(',',$buffer);
1106 1106
 				$data = array();
1107 1107
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1118,38 +1118,38 @@  discard block
 block discarded – undo
1118 1118
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1119 1119
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1120 1120
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1121
-			    }
1122
-                        } elseif ($format == 'acars') {
1123
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1124
-			    $ACARS->add(trim($buffer));
1125
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1126
-			    $ACARS->deleteLiveAcarsData();
1121
+				}
1122
+						} elseif ($format == 'acars') {
1123
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1124
+				$ACARS->add(trim($buffer));
1125
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1126
+				$ACARS->deleteLiveAcarsData();
1127 1127
 			} elseif ($format == 'flightgearmp') {
1128
-			    if (substr($buffer,0,1) != '#') {
1128
+				if (substr($buffer,0,1) != '#') {
1129 1129
 				$data = array();
1130 1130
 				//echo $buffer."\n";
1131 1131
 				$line = explode(' ',$buffer);
1132 1132
 				if (count($line) == 11) {
1133
-				    $userserver = explode('@',$line[0]);
1134
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1135
-				    $data['ident'] = $userserver[0];
1136
-				    $data['registration'] = $userserver[0];
1137
-				    $data['latitude'] = $line[4];
1138
-				    $data['longitude'] = $line[5];
1139
-				    $data['altitude'] = $line[6];
1140
-				    $data['datetime'] = date('Y-m-d H:i:s');
1141
-				    $aircraft_type = $line[10];
1142
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1143
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1144
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1145
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1133
+					$userserver = explode('@',$line[0]);
1134
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1135
+					$data['ident'] = $userserver[0];
1136
+					$data['registration'] = $userserver[0];
1137
+					$data['latitude'] = $line[4];
1138
+					$data['longitude'] = $line[5];
1139
+					$data['altitude'] = $line[6];
1140
+					$data['datetime'] = date('Y-m-d H:i:s');
1141
+					$aircraft_type = $line[10];
1142
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1143
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1144
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1145
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1146
+				}
1146 1147
 				}
1147
-			    }
1148 1148
 			} elseif ($format == 'beast') {
1149
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1150
-			    die;
1149
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1150
+				die;
1151 1151
 			} elseif ($format == 'vrstcp') {
1152
-			    foreach($buffer as $all_data) {
1152
+				foreach($buffer as $all_data) {
1153 1153
 				$line = json_decode('{'.$all_data.'}',true);
1154 1154
 				$data = array();
1155 1155
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1169,106 +1169,106 @@  discard block
 block discarded – undo
1169 1169
 				*/
1170 1170
 				$data['datetime'] = date('Y-m-d H:i:s');
1171 1171
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1172
-		    		$data['format_source'] = 'vrstcp';
1172
+					$data['format_source'] = 'vrstcp';
1173 1173
 				$data['id_source'] = $id_source;
1174 1174
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1175 1175
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1176 1176
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1177 1177
 				unset($data);
1178
-			    }
1178
+				}
1179 1179
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1180
-			    $line = explode("\t", $buffer);
1181
-			    for($k = 0; $k < count($line); $k=$k+2) {
1180
+				$line = explode("\t", $buffer);
1181
+				for($k = 0; $k < count($line); $k=$k+2) {
1182 1182
 				$key = $line[$k];
1183
-			        $lined[$key] = $line[$k+1];
1184
-			    }
1185
-    			    if (count($lined) > 3) {
1186
-    				$data['hex'] = $lined['hexid'];
1187
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1188
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1189
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1190
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1191
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1192
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1193
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1194
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1195
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1196
-    				$data['id_source'] = $id_source;
1197
-    				$data['format_source'] = 'tsv';
1198
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1199
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1183
+					$lined[$key] = $line[$k+1];
1184
+				}
1185
+					if (count($lined) > 3) {
1186
+					$data['hex'] = $lined['hexid'];
1187
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1188
+					$data['datetime'] = date('Y-m-d H:i:s');;
1189
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1190
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1191
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1192
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1193
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1194
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1195
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1196
+					$data['id_source'] = $id_source;
1197
+					$data['format_source'] = 'tsv';
1198
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1199
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1200 1200
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1201
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1202
-    				unset($lined);
1203
-    				unset($data);
1204
-    			    } else $error = true;
1201
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1202
+					unset($lined);
1203
+					unset($data);
1204
+					} else $error = true;
1205 1205
 			} elseif ($format == 'aprs' && $use_aprs) {
1206
-			    if ($aprs_connect == 0) {
1206
+				if ($aprs_connect == 0) {
1207 1207
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1208 1208
 				$aprs_connect = 1;
1209
-			    }
1209
+				}
1210 1210
 			    
1211
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1211
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1212 1212
 				$aprs_last_tx = time();
1213 1213
 				$data_aprs = "# Keep alive";
1214 1214
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1215
-			    }
1215
+				}
1216 1216
 			    
1217
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1218
-			    //echo 'APRS data : '.$buffer."\n";
1219
-			    $buffer = str_replace('APRS <- ','',$buffer);
1220
-			    $buffer = str_replace('APRS -> ','',$buffer);
1221
-			    //echo $buffer."\n";
1222
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1217
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1218
+				//echo 'APRS data : '.$buffer."\n";
1219
+				$buffer = str_replace('APRS <- ','',$buffer);
1220
+				$buffer = str_replace('APRS -> ','',$buffer);
1221
+				//echo $buffer."\n";
1222
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1223 1223
 				$line = $APRS->parse($buffer);
1224 1224
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1225 1225
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1226
-				    $aprs_last_tx = time();
1227
-				    $data = array();
1228
-				    //print_r($line);
1229
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1230
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1231
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1232
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1233
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1234
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1235
-				    $data['latitude'] = $line['latitude'];
1236
-				    $data['longitude'] = $line['longitude'];
1237
-				    //$data['verticalrate'] = $line[16];
1238
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1239
-				    else $data['speed'] = 0;
1240
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1241
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1242
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1243
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1244
-				    //else $data['heading'] = 0;
1245
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1246
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE)) $data['noarchive'] = true;
1247
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1248
-    				    $data['id_source'] = $id_source;
1249
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1250
-				    else $data['format_source'] = 'aprs';
1251
-				    $data['source_name'] = $line['source'];
1252
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1253
-				    else $data['source_type'] = 'flarm';
1254
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1255
-				    $currentdate = date('Y-m-d H:i:s');
1256
-				    $aprsdate = strtotime($data['datetime']);
1257
-				    // Accept data if time <= system time + 20s
1258
-				    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'])))) {
1226
+					$aprs_last_tx = time();
1227
+					$data = array();
1228
+					//print_r($line);
1229
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1230
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1231
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1232
+					else $data['datetime'] = date('Y-m-d H:i:s');
1233
+					//$data['datetime'] = date('Y-m-d H:i:s');
1234
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1235
+					$data['latitude'] = $line['latitude'];
1236
+					$data['longitude'] = $line['longitude'];
1237
+					//$data['verticalrate'] = $line[16];
1238
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1239
+					else $data['speed'] = 0;
1240
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1241
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1242
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1243
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1244
+					//else $data['heading'] = 0;
1245
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1246
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE)) $data['noarchive'] = true;
1247
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1248
+						$data['id_source'] = $id_source;
1249
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1250
+					else $data['format_source'] = 'aprs';
1251
+					$data['source_name'] = $line['source'];
1252
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1253
+					else $data['source_type'] = 'flarm';
1254
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1255
+					$currentdate = date('Y-m-d H:i:s');
1256
+					$aprsdate = strtotime($data['datetime']);
1257
+					// Accept data if time <= system time + 20s
1258
+					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'])))) {
1259 1259
 					$send = $SI->add($data);
1260
-				    } elseif ($data['source_type'] == 'ais') {
1260
+					} elseif ($data['source_type'] == 'ais') {
1261 1261
 					echo 'add...'."\n";
1262 1262
 					$send = $MI->add($data);
1263
-				    } elseif (isset($line['stealth'])) {
1263
+					} elseif (isset($line['stealth'])) {
1264 1264
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1265 1265
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1266
-				    //} 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')) {
1267
-				    } 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') {
1266
+					//} 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')) {
1267
+					} 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') {
1268 1268
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1269 1269
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1270
-				    }
1271
-				    unset($data);
1270
+					}
1271
+					unset($data);
1272 1272
 				} 
1273 1273
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1274 1274
 					echo '!! Weather Station not yet supported'."\n";
@@ -1278,12 +1278,12 @@  discard block
 block discarded – undo
1278 1278
 				}
1279 1279
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1280 1280
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1281
-			    }
1281
+				}
1282 1282
 			} else {
1283
-			    $line = explode(',', $buffer);
1284
-    			    if (count($line) > 20) {
1285
-    			    	$data['hex'] = $line[4];
1286
-    				/*
1283
+				$line = explode(',', $buffer);
1284
+					if (count($line) > 20) {
1285
+						$data['hex'] = $line[4];
1286
+					/*
1287 1287
     				$data['datetime'] = $line[6].' '.$line[7];
1288 1288
     					date_default_timezone_set($globalTimezone);
1289 1289
     					$datetime = new DateTime($data['datetime']);
@@ -1291,30 +1291,30 @@  discard block
 block discarded – undo
1291 1291
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1292 1292
     					date_default_timezone_set('UTC');
1293 1293
     				*/
1294
-    				// Force datetime to current UTC datetime
1295
-    				date_default_timezone_set('UTC');
1296
-    				$data['datetime'] = date('Y-m-d H:i:s');
1297
-    				$data['ident'] = trim($line[10]);
1298
-    				$data['latitude'] = $line[14];
1299
-    				$data['longitude'] = $line[15];
1300
-    				$data['verticalrate'] = $line[16];
1301
-    				$data['emergency'] = $line[20];
1302
-    				$data['speed'] = $line[12];
1303
-    				$data['squawk'] = $line[17];
1304
-    				$data['altitude'] = $line[11];
1305
-    				$data['heading'] = $line[13];
1306
-    				$data['ground'] = $line[21];
1307
-    				$data['emergency'] = $line[19];
1308
-    				$data['format_source'] = 'sbs';
1294
+					// Force datetime to current UTC datetime
1295
+					date_default_timezone_set('UTC');
1296
+					$data['datetime'] = date('Y-m-d H:i:s');
1297
+					$data['ident'] = trim($line[10]);
1298
+					$data['latitude'] = $line[14];
1299
+					$data['longitude'] = $line[15];
1300
+					$data['verticalrate'] = $line[16];
1301
+					$data['emergency'] = $line[20];
1302
+					$data['speed'] = $line[12];
1303
+					$data['squawk'] = $line[17];
1304
+					$data['altitude'] = $line[11];
1305
+					$data['heading'] = $line[13];
1306
+					$data['ground'] = $line[21];
1307
+					$data['emergency'] = $line[19];
1308
+					$data['format_source'] = 'sbs';
1309 1309
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1310
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1310
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1311 1311
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1312
-    				$data['id_source'] = $id_source;
1313
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1314
-    				else $error = true;
1315
-    				unset($data);
1316
-    			    } else $error = true;
1317
-			    if ($error) {
1312
+					$data['id_source'] = $id_source;
1313
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1314
+					else $error = true;
1315
+					unset($data);
1316
+					} else $error = true;
1317
+				if ($error) {
1318 1318
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1319 1319
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1320 1320
 				} else {
@@ -1330,13 +1330,13 @@  discard block
 block discarded – undo
1330 1330
 					connect_all($sourceer);
1331 1331
 					$sourceer = array();
1332 1332
 				}
1333
-			    }
1333
+				}
1334 1334
 			}
1335 1335
 			// Sleep for xxx microseconds
1336 1336
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1337
-		    } else {
1337
+			} else {
1338 1338
 			if ($format == 'flightgearmp') {
1339
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1339
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1340 1340
 				//@socket_close($r);
1341 1341
 				sleep($globalMinFetch);
1342 1342
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1345,9 +1345,9 @@  discard block
 block discarded – undo
1345 1345
 				break;
1346 1346
 				
1347 1347
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1348
-			    if (isset($tt[$format])) $tt[$format]++;
1349
-			    else $tt[$format] = 0;
1350
-			    if ($tt[$format] > 30) {
1348
+				if (isset($tt[$format])) $tt[$format]++;
1349
+				else $tt[$format] = 0;
1350
+				if ($tt[$format] > 30) {
1351 1351
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1352 1352
 				//@socket_close($r);
1353 1353
 				sleep(2);
@@ -1358,23 +1358,23 @@  discard block
 block discarded – undo
1358 1358
 				//connect_all($globalSources);
1359 1359
 				$tt[$format]=0;
1360 1360
 				break;
1361
-			    }
1361
+				}
1362
+			}
1362 1363
 			}
1363
-		    }
1364 1364
 		}
1365
-	    } else {
1365
+		} else {
1366 1366
 		$error = socket_strerror(socket_last_error());
1367 1367
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1368 1368
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1369 1369
 			if (isset($globalDebug)) echo "Restarting...\n";
1370 1370
 			// Restart the script if possible
1371 1371
 			if (is_array($sockets)) {
1372
-			    if ($globalDebug) echo "Shutdown all sockets...";
1372
+				if ($globalDebug) echo "Shutdown all sockets...";
1373 1373
 			    
1374
-			    foreach ($sockets as $sock) {
1374
+				foreach ($sockets as $sock) {
1375 1375
 				@socket_shutdown($sock,2);
1376 1376
 				@socket_close($sock);
1377
-			    }
1377
+				}
1378 1378
 			    
1379 1379
 			}
1380 1380
 			if ($globalDebug) echo "Restart all connections...";
@@ -1388,13 +1388,13 @@  discard block
 block discarded – undo
1388 1388
 			if ($reset > 100) exit('Too many attempts...');
1389 1389
 			connect_all($globalSources);
1390 1390
 		}
1391
-	    }
1391
+		}
1392 1392
 	}
1393 1393
 	if ($globalDaemon === false) {
1394
-	    if ($globalDebug) echo 'Check all...'."\n";
1395
-	    $SI->checkAll();
1394
+		if ($globalDebug) echo 'Check all...'."\n";
1395
+		$SI->checkAll();
1396
+	}
1396 1397
 	}
1397
-    }
1398 1398
 }
1399 1399
 
1400 1400
 ?>
Please login to merge, or discard this patch.
Spacing   +140 added lines, -140 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));
@@ -466,9 +466,9 @@  discard block
 block discarded – undo
466 466
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
467 467
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
468 468
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
469
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
469
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
470 470
 			    if (isset($ais_data['timestamp'])) {
471
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
471
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
472 472
 			    } else {
473 473
 				$data['datetime'] = date('Y-m-d H:i:s');
474 474
 			    }
@@ -483,10 +483,10 @@  discard block
 block discarded – undo
483 483
 		}
484 484
 	    }
485 485
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
486
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
486
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
487 487
 	    if ($buffer != '') {
488 488
 		//echo $buffer;
489
-		$all_data = json_decode($buffer,true);
489
+		$all_data = json_decode($buffer, true);
490 490
 		//print_r($all_data);
491 491
 		if (isset($all_data[0]['DATA'])) {
492 492
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
502 502
 			$data['imo'] = $line['IMO'];
503 503
 			//$data['arrival_code'] = $ais_data['destination'];
504
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
504
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
505 505
 			$data['format_source'] = 'myshiptracking';
506 506
 			$data['id_source'] = $id_source;
507 507
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -514,9 +514,9 @@  discard block
 block discarded – undo
514 514
 	    }
515 515
     	    $last_exec[$id]['last'] = time();
516 516
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
517
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
517
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
518 518
 	    if ($buffer != '') {
519
-		$all_data = json_decode($buffer,true);
519
+		$all_data = json_decode($buffer, true);
520 520
 		if (isset($all_data[0]['mmsi'])) {
521 521
 		    foreach ($all_data as $line) {
522 522
 			if ($line != '') {
@@ -544,27 +544,27 @@  discard block
 block discarded – undo
544 544
     	    $last_exec[$id]['last'] = time();
545 545
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
546 546
 	    echo 'download...';
547
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
547
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
548 548
 	    echo 'done !'."\n";
549 549
 	    if ($buffer != '') $reset = 0;
550
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
551
-	    $buffer = explode('\n',$buffer);
550
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
551
+	    $buffer = explode('\n', $buffer);
552 552
 	    foreach ($buffer as $line) {
553 553
 		if ($line != '') {
554 554
 		    $data = array();
555
-		    $data['mmsi'] = (int)substr($line,0,9);
556
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
555
+		    $data['mmsi'] = (int) substr($line, 0, 9);
556
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
557 557
 		    //$data['status'] = substr($line,21,2);
558 558
 		    //$data['type'] = substr($line,24,3);
559
-		    $data['latitude'] = substr($line,29,9);
560
-		    $data['longitude'] = substr($line,41,9);
561
-		    $data['speed'] = round(substr($line,51,5));
559
+		    $data['latitude'] = substr($line, 29, 9);
560
+		    $data['longitude'] = substr($line, 41, 9);
561
+		    $data['speed'] = round(substr($line, 51, 5));
562 562
 		    //$data['course'] = substr($line,57,5);
563
-		    $data['heading'] = round(substr($line,63,3));
563
+		    $data['heading'] = round(substr($line, 63, 3));
564 564
 		    //$data['draft'] = substr($line,67,4);
565 565
 		    //$data['length'] = substr($line,72,3);
566 566
 		    //$data['beam'] = substr($line,76,2);
567
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
567
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
568 568
 		    //$data['callsign'] = trim(substr($line,100,7);
569 569
 		    //$data['dest'] = substr($line,108,20);
570 570
 		    //$data['etaDate'] = substr($line,129,5);
@@ -583,8 +583,8 @@  discard block
 block discarded – undo
583 583
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
584 584
 	    //$buffer = $Common->getData($hosts[$id]);
585 585
 	    $buffer = $Common->getData($value['host']);
586
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
587
-	    $buffer = explode('\n',$buffer);
586
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
587
+	    $buffer = explode('\n', $buffer);
588 588
 	    $reset = 0;
589 589
 	    foreach ($buffer as $line) {
590 590
     		if ($line != '') {
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
596 596
 			$data['pilot_id'] = $line[1];
597 597
 			$data['pilot_name'] = $line[2];
598
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
598
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
599 599
 			$data['ident'] = $line[0]; // ident
600 600
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
601 601
 			$data['speed'] = $line[8]; // speed
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
612 612
 			//if (isset($line[37])) $data['last_update'] = $line[37];
613 613
 		        $data['departure_airport_icao'] = $line[11];
614
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
614
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
615 615
 		        $data['arrival_airport_icao'] = $line[13];
616 616
 			$data['frequency'] = $line[4];
617 617
 			$data['type'] = $line[18];
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
     			$data['id_source'] = $id_source;
621 621
 	    		//$data['arrival_airport_time'] = ;
622 622
 	    		if ($line[9] != '') {
623
-	    		    $aircraft_data = explode('/',$line[9]);
623
+	    		    $aircraft_data = explode('/', $line[9]);
624 624
 	    		    if (isset($aircraft_data[1])) {
625 625
 	    			$data['aircraft_icao'] = $aircraft_data[1];
626 626
 	    		    }
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
     			if ($line[3] == 'PILOT') $SI->add($data);
636 636
 			elseif ($line[3] == 'ATC') {
637 637
 				//print_r($data);
638
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
639
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
640
-				$typec = substr($data['ident'],-3);
638
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
639
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
640
+				$typec = substr($data['ident'], -3);
641 641
 				if ($typec == 'APP') $data['type'] = 'Approach';
642 642
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
643 643
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
649 649
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
650 650
 				if (!isset($data['source_name'])) $data['source_name'] = '';
651
-				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']);
651
+				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']);
652 652
 			}
653 653
     			unset($data);
654 654
     		    }
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 659
     	    $last_exec[$id]['last'] = time();
660 660
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
661 661
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
662
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
662
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
663 663
 	    if ($buffer != '') {
664
-	    $all_data = json_decode($buffer,true);
664
+	    $all_data = json_decode($buffer, true);
665 665
 	    if (isset($all_data['acList'])) {
666 666
 		$reset = 0;
667 667
 		foreach ($all_data['acList'] as $line) {
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
720 720
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
721 721
 	    $buffer = $Common->getData($value['host']);
722
-	    $all_data = json_decode($buffer,true);
722
+	    $all_data = json_decode($buffer, true);
723 723
 	    if (isset($all_data['planes'])) {
724 724
 		$reset = 0;
725 725
 		foreach ($all_data['planes'] as $key => $line) {
@@ -736,12 +736,12 @@  discard block
 block discarded – undo
736 736
 		    $data['emergency'] = ''; // emergency
737 737
 		    $data['registration'] = $line[2];
738 738
 		    $data['aircraft_icao'] = $line[0];
739
-		    $deparr = explode('-',$line[1]);
739
+		    $deparr = explode('-', $line[1]);
740 740
 		    if (count($deparr) == 2) {
741 741
 			$data['departure_airport_icao'] = $deparr[0];
742 742
 			$data['arrival_airport_icao'] = $deparr[1];
743 743
 		    }
744
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
744
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
745 745
 	    	    $data['format_source'] = 'planeupdatefaa';
746 746
     		    $data['id_source'] = $id_source;
747 747
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
     	    $last_exec[$id]['last'] = time();
755 755
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
756 756
 	    $buffer = $Common->getData($value['host']);
757
-	    $all_data = json_decode($buffer,true);
757
+	    $all_data = json_decode($buffer, true);
758 758
 	    if (isset($all_data['states'])) {
759 759
 		$reset = 0;
760 760
 		foreach ($all_data['states'] as $key => $line) {
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 		    //$data['emergency'] = ''; // emergency
772 772
 		    //$data['registration'] = $line[2];
773 773
 		    //$data['aircraft_icao'] = $line[0];
774
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
774
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
775 775
 	    	    $data['format_source'] = 'opensky';
776 776
     		    $data['id_source'] = $id_source;
777 777
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
786 786
 	    //$buffer = $Common->getData($hosts[$id]);
787 787
 	    $buffer = $Common->getData($value['host']);
788
-	    $all_data = json_decode($buffer,true);
788
+	    $all_data = json_decode($buffer, true);
789 789
 	    if (!empty($all_data)) $reset = 0;
790 790
 	    foreach ($all_data as $key => $line) {
791 791
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
819 819
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
820 820
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
821
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
821
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
822 822
 	    //echo $buffer;
823
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
824
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
825
-	    $all_data = json_decode($buffer,true);
823
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
824
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
825
+	    $all_data = json_decode($buffer, true);
826 826
 	    if (json_last_error() != JSON_ERROR_NONE) {
827 827
 		die(json_last_error_msg());
828 828
 	    }
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 			//$data['departure_airport_iata'] = $line[11];
846 846
 			//$data['arrival_airport_iata'] = $line[12];
847 847
 	    		//$data['emergency'] = ''; // emergency
848
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
848
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
849 849
 	    		$data['format_source'] = 'radarvirtueljson';
850 850
     			$data['id_source'] = $id_source;
851 851
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -861,14 +861,14 @@  discard block
 block discarded – undo
861 861
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
862 862
 	    //$buffer = $Common->getData($hosts[$id]);
863 863
 	    $buffer = $Common->getData($value['host'].'?'.time());
864
-	    $all_data = json_decode(utf8_encode($buffer),true);
864
+	    $all_data = json_decode(utf8_encode($buffer), true);
865 865
 	    
866 866
 	    if (isset($all_data['pireps'])) {
867 867
 		$reset = 0;
868 868
 	        foreach ($all_data['pireps'] as $line) {
869 869
 		    $data = array();
870 870
 		    $data['id'] = $line['id'];
871
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
871
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
872 872
 		    $data['ident'] = $line['callsign']; // ident
873 873
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
874 874
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -898,9 +898,9 @@  discard block
 block discarded – undo
898 898
 			$SI->add($data);
899 899
 		    //    print_r($data);
900 900
     		    } elseif ($line['icon'] == 'ct') {
901
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
902
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
903
-			$typec = substr($data['ident'],-3);
901
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
902
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
903
+			$typec = substr($data['ident'], -3);
904 904
 			$data['type'] = '';
905 905
 			if ($typec == 'APP') $data['type'] = 'Approach';
906 906
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
912 912
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
913 913
 			else $data['type'] = 'Observer';
914
-			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']);
914
+			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']);
915 915
 		    }
916 916
 		    unset($data);
917 917
 		}
@@ -923,14 +923,14 @@  discard block
 block discarded – undo
923 923
 	    //$buffer = $Common->getData($hosts[$id]);
924 924
 	    if ($globalDebug) echo 'Get Data...'."\n";
925 925
 	    $buffer = $Common->getData($value['host']);
926
-	    $all_data = json_decode($buffer,true);
926
+	    $all_data = json_decode($buffer, true);
927 927
 	    if ($buffer != '' && is_array($all_data)) {
928 928
 		$reset = 0;
929 929
 		foreach ($all_data as $line) {
930 930
 	    	    $data = array();
931 931
 	    	    //$data['id'] = $line['id']; // id not usable
932 932
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
933
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
933
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
934 934
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
935 935
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
936 936
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -954,14 +954,14 @@  discard block
 block discarded – undo
954 954
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
955 955
 		    if (isset($line['aircraftname'])) {
956 956
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
957
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
958
-	    		$aircraft_data = explode('-',$line['aircraftname']);
957
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
958
+	    		$aircraft_data = explode('-', $line['aircraftname']);
959 959
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
960 960
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
961 961
 	    		else {
962
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
963
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
964
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
962
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
963
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
964
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
965 965
 	    		}
966 966
 	    	    }
967 967
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -981,14 +981,14 @@  discard block
 block discarded – undo
981 981
 	    //$buffer = $Common->getData($hosts[$id]);
982 982
 	    if ($globalDebug) echo 'Get Data...'."\n";
983 983
 	    $buffer = $Common->getData($value['host']);
984
-	    $all_data = json_decode($buffer,true);
984
+	    $all_data = json_decode($buffer, true);
985 985
 	    if ($buffer != '' && is_array($all_data)) {
986 986
 		$reset = 0;
987 987
 		foreach ($all_data as $line) {
988 988
 	    	    $data = array();
989 989
 	    	    //$data['id'] = $line['id']; // id not usable
990 990
 	    	    $data['id'] = trim($line['flight_id']);
991
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
991
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
992 992
 	    	    $data['pilot_name'] = $line['pilot_name'];
993 993
 	    	    $data['pilot_id'] = $line['pilot_id'];
994 994
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1040,11 +1040,11 @@  discard block
 block discarded – undo
1040 1040
 		    //$value = $formats[$nb];
1041 1041
 		    $format = $globalSources[$nb]['format'];
1042 1042
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1043
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1043
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1044 1044
 		    } elseif ($format == 'vrstcp') {
1045 1045
 			$buffer = @socket_read($r, 6000);
1046 1046
 		    } else {
1047
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1047
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1048 1048
 		    }
1049 1049
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1050 1050
 		    //echo $buffer."\n";
@@ -1053,8 +1053,8 @@  discard block
 block discarded – undo
1053 1053
 		    $error = false;
1054 1054
 		    //$SI::del();
1055 1055
 		    if ($format == 'vrstcp') {
1056
-			$buffer = explode('},{',$buffer);
1057
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1056
+			$buffer = explode('},{', $buffer);
1057
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1058 1058
 		    // SBS format is CSV format
1059 1059
 		    if ($buffer !== FALSE && $buffer != '') {
1060 1060
 			$tt[$format] = 0;
@@ -1087,11 +1087,11 @@  discard block
 block discarded – undo
1087 1087
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1088 1088
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1089 1089
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1090
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1090
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1091 1091
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1092 1092
 
1093 1093
 			    if (isset($ais_data['timestamp'])) {
1094
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1094
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1095 1095
 			    } else {
1096 1096
 				$data['datetime'] = date('Y-m-d H:i:s');
1097 1097
 			    }
@@ -1102,10 +1102,10 @@  discard block
 block discarded – undo
1102 1102
                         } elseif ($format == 'flightgearsp') {
1103 1103
                     	    //echo $buffer."\n";
1104 1104
                     	    if (strlen($buffer) > 5) {
1105
-				$line = explode(',',$buffer);
1105
+				$line = explode(',', $buffer);
1106 1106
 				$data = array();
1107 1107
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1108
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1108
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1109 1109
 				$data['ident'] = $line[6];
1110 1110
 				$data['aircraft_name'] = $line[7];
1111 1111
 				$data['longitude'] = $line[1];
@@ -1117,21 +1117,21 @@  discard block
 block discarded – undo
1117 1117
 				$data['format_source'] = 'flightgearsp';
1118 1118
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1119 1119
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1120
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1120
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1121 1121
 			    }
1122 1122
                         } elseif ($format == 'acars') {
1123 1123
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1124 1124
 			    $ACARS->add(trim($buffer));
1125
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1125
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1126 1126
 			    $ACARS->deleteLiveAcarsData();
1127 1127
 			} elseif ($format == 'flightgearmp') {
1128
-			    if (substr($buffer,0,1) != '#') {
1128
+			    if (substr($buffer, 0, 1) != '#') {
1129 1129
 				$data = array();
1130 1130
 				//echo $buffer."\n";
1131
-				$line = explode(' ',$buffer);
1131
+				$line = explode(' ', $buffer);
1132 1132
 				if (count($line) == 11) {
1133
-				    $userserver = explode('@',$line[0]);
1134
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1133
+				    $userserver = explode('@', $line[0]);
1134
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1135 1135
 				    $data['ident'] = $userserver[0];
1136 1136
 				    $data['registration'] = $userserver[0];
1137 1137
 				    $data['latitude'] = $line[4];
@@ -1139,8 +1139,8 @@  discard block
 block discarded – undo
1139 1139
 				    $data['altitude'] = $line[6];
1140 1140
 				    $data['datetime'] = date('Y-m-d H:i:s');
1141 1141
 				    $aircraft_type = $line[10];
1142
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1143
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1142
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1143
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1144 1144
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1145 1145
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1146 1146
 				}
@@ -1149,8 +1149,8 @@  discard block
 block discarded – undo
1149 1149
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1150 1150
 			    die;
1151 1151
 			} elseif ($format == 'vrstcp') {
1152
-			    foreach($buffer as $all_data) {
1153
-				$line = json_decode('{'.$all_data.'}',true);
1152
+			    foreach ($buffer as $all_data) {
1153
+				$line = json_decode('{'.$all_data.'}', true);
1154 1154
 				$data = array();
1155 1155
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1156 1156
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1176,16 +1176,16 @@  discard block
 block discarded – undo
1176 1176
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1177 1177
 				unset($data);
1178 1178
 			    }
1179
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1179
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1180 1180
 			    $line = explode("\t", $buffer);
1181
-			    for($k = 0; $k < count($line); $k=$k+2) {
1181
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1182 1182
 				$key = $line[$k];
1183
-			        $lined[$key] = $line[$k+1];
1183
+			        $lined[$key] = $line[$k + 1];
1184 1184
 			    }
1185 1185
     			    if (count($lined) > 3) {
1186 1186
     				$data['hex'] = $lined['hexid'];
1187 1187
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1188
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1188
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1189 1189
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1190 1190
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1191 1191
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1204,22 +1204,22 @@  discard block
 block discarded – undo
1204 1204
     			    } else $error = true;
1205 1205
 			} elseif ($format == 'aprs' && $use_aprs) {
1206 1206
 			    if ($aprs_connect == 0) {
1207
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1207
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1208 1208
 				$aprs_connect = 1;
1209 1209
 			    }
1210 1210
 			    
1211
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1211
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1212 1212
 				$aprs_last_tx = time();
1213 1213
 				$data_aprs = "# Keep alive";
1214
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1214
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1215 1215
 			    }
1216 1216
 			    
1217 1217
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1218 1218
 			    //echo 'APRS data : '.$buffer."\n";
1219
-			    $buffer = str_replace('APRS <- ','',$buffer);
1220
-			    $buffer = str_replace('APRS -> ','',$buffer);
1219
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1220
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1221 1221
 			    //echo $buffer."\n";
1222
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1222
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1223 1223
 				$line = $APRS->parse($buffer);
1224 1224
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1225 1225
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 				    //print_r($line);
1229 1229
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1230 1230
 				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1231
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1231
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1232 1232
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1233 1233
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1234 1234
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1255,7 +1255,7 @@  discard block
 block discarded – undo
1255 1255
 				    $currentdate = date('Y-m-d H:i:s');
1256 1256
 				    $aprsdate = strtotime($data['datetime']);
1257 1257
 				    // Accept data if time <= system time + 20s
1258
-				    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'])))) {
1258
+				    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'])))) {
1259 1259
 					$send = $SI->add($data);
1260 1260
 				    } elseif ($data['source_type'] == 'ais') {
1261 1261
 					echo 'add...'."\n";
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 				connect_all($sourceee);
1357 1357
 				$sourceee = array();
1358 1358
 				//connect_all($globalSources);
1359
-				$tt[$format]=0;
1359
+				$tt[$format] = 0;
1360 1360
 				break;
1361 1361
 			    }
1362 1362
 			}
@@ -1365,14 +1365,14 @@  discard block
 block discarded – undo
1365 1365
 	    } else {
1366 1366
 		$error = socket_strerror(socket_last_error());
1367 1367
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1368
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1368
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1369 1369
 			if (isset($globalDebug)) echo "Restarting...\n";
1370 1370
 			// Restart the script if possible
1371 1371
 			if (is_array($sockets)) {
1372 1372
 			    if ($globalDebug) echo "Shutdown all sockets...";
1373 1373
 			    
1374 1374
 			    foreach ($sockets as $sock) {
1375
-				@socket_shutdown($sock,2);
1375
+				@socket_shutdown($sock, 2);
1376 1376
 				@socket_close($sock);
1377 1377
 			    }
1378 1378
 			    
Please login to merge, or discard this patch.
Braces   +878 added lines, -301 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,18 +619,42 @@  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['type'])) $data['type'] = $ais_data['type'];
466
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
467
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
468
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
469
-			    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['type'])) {
644
+			    	$data['type'] = $ais_data['type'];
645
+			    }
646
+			    if (isset($ais_data['imo'])) {
647
+			    	$data['imo'] = $ais_data['imo'];
648
+			    }
649
+			    if (isset($ais_data['callsign'])) {
650
+			    	$data['callsign'] = $ais_data['callsign'];
651
+			    }
652
+			    if (isset($ais_data['destination'])) {
653
+			    	$data['arrival_code'] = $ais_data['destination'];
654
+			    }
655
+			    if (isset($ais_data['eta_ts'])) {
656
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
657
+			    }
470 658
 			    if (isset($ais_data['timestamp'])) {
471 659
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
472 660
 			    } else {
@@ -474,8 +662,12 @@  discard block
 block discarded – undo
474 662
 			    }
475 663
 			    $data['format_source'] = 'aisnmeahttp';
476 664
 			    $data['id_source'] = $id_source;
477
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
478
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
665
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
666
+			    	$data['noarchive'] = true;
667
+			    }
668
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
669
+			    	$MI->add($data);
670
+			    }
479 671
 			    unset($data);
480 672
 			}
481 673
 		    }
@@ -504,7 +696,9 @@  discard block
 block discarded – undo
504 696
 			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
505 697
 			$data['format_source'] = 'myshiptracking';
506 698
 			$data['id_source'] = $id_source;
507
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
699
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
700
+				$data['noarchive'] = true;
701
+			}
508 702
 			$MI->add($data);
509 703
 			unset($data);
510 704
 		    }
@@ -525,7 +719,9 @@  discard block
 block discarded – undo
525 719
 			    $data['callsign'] = $line['callsign'];
526 720
 			    $data['mmsi'] = $line['mmsi'];
527 721
 			    $data['speed'] = $line['sog'];
528
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
722
+			    if ($line['heading'] != '511') {
723
+			    	$data['heading'] = $line['heading'];
724
+			    }
529 725
 			    $data['latitude'] = $line['latitude'];
530 726
 			    $data['longitude'] = $line['longitude'];
531 727
 			    $data['type_id'] = $line['shiptype'];
@@ -533,7 +729,9 @@  discard block
 block discarded – undo
533 729
 			    $data['datetime'] = $line['time'];
534 730
 			    $data['format_source'] = 'boatbeaconapp';
535 731
 			    $data['id_source'] = $id_source;
536
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
732
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
733
+			    	$data['noarchive'] = true;
734
+			    }
537 735
 			    $MI->add($data);
538 736
 			    unset($data);
539 737
 			}
@@ -546,7 +744,9 @@  discard block
 block discarded – undo
546 744
 	    echo 'download...';
547 745
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
548 746
 	    echo 'done !'."\n";
549
-	    if ($buffer != '') $reset = 0;
747
+	    if ($buffer != '') {
748
+	    	$reset = 0;
749
+	    }
550 750
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
551 751
 	    $buffer = explode('\n',$buffer);
552 752
 	    foreach ($buffer as $line) {
@@ -571,7 +771,9 @@  discard block
 block discarded – undo
571 771
 		    //$data['etaTime'] = substr($line,135,5);
572 772
 		    $data['format_source'] = 'shipplotter';
573 773
     		    $data['id_source'] = $id_source;
574
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
774
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
775
+		    	$data['noarchive'] = true;
776
+		    }
575 777
 		    //print_r($data);
576 778
 		    echo 'Add...'."\n";
577 779
 		    $MI->add($data);
@@ -591,16 +793,28 @@  discard block
 block discarded – undo
591 793
     		    $line = explode(':', $line);
592 794
     		    if (count($line) > 30 && $line[0] != 'callsign') {
593 795
 			$data = array();
594
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
595
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
796
+			if (isset($line[37]) && $line[37] != '') {
797
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
798
+			} else {
799
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
800
+			}
596 801
 			$data['pilot_id'] = $line[1];
597 802
 			$data['pilot_name'] = $line[2];
598 803
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
599 804
 			$data['ident'] = $line[0]; // ident
600
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
805
+			if ($line[7] != '' && $line[7] != 0) {
806
+				$data['altitude'] = $line[7];
807
+			}
808
+			// altitude
601 809
 			$data['speed'] = $line[8]; // speed
602
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
603
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
810
+			if (isset($line[45])) {
811
+				$data['heading'] = $line[45];
812
+			}
813
+			// heading
814
+			elseif (isset($line[38])) {
815
+				$data['heading'] = $line[38];
816
+			}
817
+			// heading
604 818
 			$data['latitude'] = $line[5]; // lat
605 819
 	        	$data['longitude'] = $line[6]; // long
606 820
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -616,7 +830,9 @@  discard block
 block discarded – undo
616 830
 			$data['frequency'] = $line[4];
617 831
 			$data['type'] = $line[18];
618 832
 			$data['range'] = $line[19];
619
-			if (isset($line[35])) $data['info'] = $line[35];
833
+			if (isset($line[35])) {
834
+				$data['info'] = $line[35];
835
+			}
620 836
     			$data['id_source'] = $id_source;
621 837
 	    		//$data['arrival_airport_time'] = ;
622 838
 	    		if ($line[9] != '') {
@@ -630,25 +846,44 @@  discard block
 block discarded – undo
630 846
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
631 847
 	    		*/
632 848
 	    		$data['format_source'] = $value['format'];
633
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
634
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
635
-    			if ($line[3] == 'PILOT') $SI->add($data);
636
-			elseif ($line[3] == 'ATC') {
849
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
850
+				$data['noarchive'] = true;
851
+			}
852
+			if (isset($value['name']) && $value['name'] != '') {
853
+				$data['source_name'] = $value['name'];
854
+			}
855
+    			if ($line[3] == 'PILOT') {
856
+    				$SI->add($data);
857
+    			} elseif ($line[3] == 'ATC') {
637 858
 				//print_r($data);
638 859
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
639 860
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
640 861
 				$typec = substr($data['ident'],-3);
641
-				if ($typec == 'APP') $data['type'] = 'Approach';
642
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
643
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
644
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
645
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
646
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
647
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
648
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
649
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
650
-				if (!isset($data['source_name'])) $data['source_name'] = '';
651
-				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']);
862
+				if ($typec == 'APP') {
863
+					$data['type'] = 'Approach';
864
+				} elseif ($typec == 'TWR') {
865
+					$data['type'] = 'Tower';
866
+				} elseif ($typec == 'OBS') {
867
+					$data['type'] = 'Observer';
868
+				} elseif ($typec == 'GND') {
869
+					$data['type'] = 'Ground';
870
+				} elseif ($typec == 'DEL') {
871
+					$data['type'] = 'Delivery';
872
+				} elseif ($typec == 'DEP') {
873
+					$data['type'] = 'Departure';
874
+				} elseif ($typec == 'FSS') {
875
+					$data['type'] = 'Flight Service Station';
876
+				} elseif ($typec == 'CTR') {
877
+					$data['type'] = 'Control Radar or Centre';
878
+				} elseif ($data['type'] == '') {
879
+					$data['type'] = 'Observer';
880
+				}
881
+				if (!isset($data['source_name'])) {
882
+					$data['source_name'] = '';
883
+				}
884
+				if (isset($ATC)) {
885
+					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']);
886
+				}
652 887
 			}
653 888
     			unset($data);
654 889
     		    }
@@ -667,27 +902,58 @@  discard block
 block discarded – undo
667 902
 		foreach ($all_data['acList'] as $line) {
668 903
 		    $data = array();
669 904
 		    $data['hex'] = $line['Icao']; // hex
670
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
671
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
672
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
673
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
674
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
675
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
905
+		    if (isset($line['Call'])) {
906
+		    	$data['ident'] = $line['Call'];
907
+		    }
908
+		    // ident
909
+		    if (isset($line['Alt'])) {
910
+		    	$data['altitude'] = $line['Alt'];
911
+		    }
912
+		    // altitude
913
+		    if (isset($line['Spd'])) {
914
+		    	$data['speed'] = $line['Spd'];
915
+		    }
916
+		    // speed
917
+		    if (isset($line['Trak'])) {
918
+		    	$data['heading'] = $line['Trak'];
919
+		    }
920
+		    // heading
921
+		    if (isset($line['Lat'])) {
922
+		    	$data['latitude'] = $line['Lat'];
923
+		    }
924
+		    // lat
925
+		    if (isset($line['Long'])) {
926
+		    	$data['longitude'] = $line['Long'];
927
+		    }
928
+		    // long
676 929
 		    //$data['verticalrate'] = $line['']; // verticale rate
677
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
930
+		    if (isset($line['Sqk'])) {
931
+		    	$data['squawk'] = $line['Sqk'];
932
+		    }
933
+		    // squawk
678 934
 		    $data['emergency'] = ''; // emergency
679
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
935
+		    if (isset($line['Reg'])) {
936
+		    	$data['registration'] = $line['Reg'];
937
+		    }
680 938
 		    /*
681 939
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
682 940
 		    else $data['datetime'] = date('Y-m-d H:i:s');
683 941
 		    */
684 942
 		    $data['datetime'] = date('Y-m-d H:i:s');
685
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
943
+		    if (isset($line['Type'])) {
944
+		    	$data['aircraft_icao'] = $line['Type'];
945
+		    }
686 946
 	    	    $data['format_source'] = 'aircraftlistjson';
687 947
 		    $data['id_source'] = $id_source;
688
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
689
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
690
-		    if (isset($data['latitude'])) $SI->add($data);
948
+		    if (isset($value['name']) && $value['name'] != '') {
949
+		    	$data['source_name'] = $value['name'];
950
+		    }
951
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
952
+		    	$data['noarchive'] = true;
953
+		    }
954
+		    if (isset($data['latitude'])) {
955
+		    	$SI->add($data);
956
+		    }
691 957
 		    unset($data);
692 958
 		}
693 959
 	    } elseif (is_array($all_data)) {
@@ -707,8 +973,12 @@  discard block
 block discarded – undo
707 973
 		    $data['datetime'] = date('Y-m-d H:i:s');
708 974
 	    	    $data['format_source'] = 'aircraftlistjson';
709 975
     		    $data['id_source'] = $id_source;
710
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
711
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
976
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
977
+		    	$data['noarchive'] = true;
978
+		    }
979
+		    if (isset($value['name']) && $value['name'] != '') {
980
+		    	$data['source_name'] = $value['name'];
981
+		    }
712 982
 		    $SI->add($data);
713 983
 		    unset($data);
714 984
 		}
@@ -744,8 +1014,12 @@  discard block
 block discarded – undo
744 1014
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
745 1015
 	    	    $data['format_source'] = 'planeupdatefaa';
746 1016
     		    $data['id_source'] = $id_source;
747
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
748
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1017
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1018
+		    	$data['noarchive'] = true;
1019
+		    }
1020
+		    if (isset($value['name']) && $value['name'] != '') {
1021
+		    	$data['source_name'] = $value['name'];
1022
+		    }
749 1023
 		    $SI->add($data);
750 1024
 		    unset($data);
751 1025
 		}
@@ -774,7 +1048,9 @@  discard block
 block discarded – undo
774 1048
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
775 1049
 	    	    $data['format_source'] = 'opensky';
776 1050
     		    $data['id_source'] = $id_source;
777
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1051
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1052
+		    	$data['noarchive'] = true;
1053
+		    }
778 1054
 		    $SI->add($data);
779 1055
 		    unset($data);
780 1056
 		}
@@ -786,7 +1062,9 @@  discard block
 block discarded – undo
786 1062
 	    //$buffer = $Common->getData($hosts[$id]);
787 1063
 	    $buffer = $Common->getData($value['host']);
788 1064
 	    $all_data = json_decode($buffer,true);
789
-	    if (!empty($all_data)) $reset = 0;
1065
+	    if (!empty($all_data)) {
1066
+	    	$reset = 0;
1067
+	    }
790 1068
 	    foreach ($all_data as $key => $line) {
791 1069
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
792 1070
 		    $data = array();
@@ -807,8 +1085,12 @@  discard block
 block discarded – undo
807 1085
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
808 1086
 	    	    $data['format_source'] = 'fr24json';
809 1087
     		    $data['id_source'] = $id_source;
810
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
811
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1088
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1089
+		    	$data['noarchive'] = true;
1090
+		    }
1091
+		    if (isset($value['name']) && $value['name'] != '') {
1092
+		    	$data['source_name'] = $value['name'];
1093
+		    }
812 1094
 		    $SI->add($data);
813 1095
 		    unset($data);
814 1096
 		}
@@ -832,24 +1114,42 @@  discard block
 block discarded – undo
832 1114
 		    if (isset($line['inf'])) {
833 1115
 			$data = array();
834 1116
 			$data['hex'] = $line['inf']['ia'];
835
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1117
+			if (isset($line['inf']['cs'])) {
1118
+				$data['ident'] = $line['inf']['cs'];
1119
+			}
1120
+			//$line[13]
836 1121
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
837
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
838
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1122
+	    		if (isset($line['inf']['gs'])) {
1123
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1124
+	    		}
1125
+	    		// speed
1126
+	    		if (isset($line['inf']['tr'])) {
1127
+	    			$data['heading'] = $line['inf']['tr'];
1128
+	    		}
1129
+	    		// heading
839 1130
 	    		$data['latitude'] = $line['pt'][0]; // lat
840 1131
 	    		$data['longitude'] = $line['pt'][1]; // long
841 1132
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
842
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1133
+	    		if (isset($line['inf']['sq'])) {
1134
+	    			$data['squawk'] = $line['inf']['sq'];
1135
+	    		}
1136
+	    		// squawk
843 1137
 	    		//$data['aircraft_icao'] = $line[8];
844
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1138
+	    		if (isset($line['inf']['rc'])) {
1139
+	    			$data['registration'] = $line['inf']['rc'];
1140
+	    		}
845 1141
 			//$data['departure_airport_iata'] = $line[11];
846 1142
 			//$data['arrival_airport_iata'] = $line[12];
847 1143
 	    		//$data['emergency'] = ''; // emergency
848 1144
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
849 1145
 	    		$data['format_source'] = 'radarvirtueljson';
850 1146
     			$data['id_source'] = $id_source;
851
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
852
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1147
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1148
+				$data['noarchive'] = true;
1149
+			}
1150
+			if (isset($value['name']) && $value['name'] != '') {
1151
+				$data['source_name'] = $value['name'];
1152
+			}
853 1153
 			$SI->add($data);
854 1154
 			unset($data);
855 1155
 		    }
@@ -870,30 +1170,65 @@  discard block
 block discarded – undo
870 1170
 		    $data['id'] = $line['id'];
871 1171
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
872 1172
 		    $data['ident'] = $line['callsign']; // ident
873
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
874
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
875
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
876
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
877
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
878
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1173
+		    if (isset($line['pilotid'])) {
1174
+		    	$data['pilot_id'] = $line['pilotid'];
1175
+		    }
1176
+		    // pilot id
1177
+		    if (isset($line['name'])) {
1178
+		    	$data['pilot_name'] = $line['name'];
1179
+		    }
1180
+		    // pilot name
1181
+		    if (isset($line['alt'])) {
1182
+		    	$data['altitude'] = $line['alt'];
1183
+		    }
1184
+		    // altitude
1185
+		    if (isset($line['gs'])) {
1186
+		    	$data['speed'] = $line['gs'];
1187
+		    }
1188
+		    // speed
1189
+		    if (isset($line['heading'])) {
1190
+		    	$data['heading'] = $line['heading'];
1191
+		    }
1192
+		    // heading
1193
+		    if (isset($line['route'])) {
1194
+		    	$data['waypoints'] = $line['route'];
1195
+		    }
1196
+		    // route
879 1197
 		    $data['latitude'] = $line['lat']; // lat
880 1198
 		    $data['longitude'] = $line['lon']; // long
881 1199
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
882 1200
 		    //$data['squawk'] = $line['squawk']; // squawk
883 1201
 		    //$data['emergency'] = ''; // emergency
884
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
885
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
886
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1202
+		    if (isset($line['depicao'])) {
1203
+		    	$data['departure_airport_icao'] = $line['depicao'];
1204
+		    }
1205
+		    if (isset($line['deptime'])) {
1206
+		    	$data['departure_airport_time'] = $line['deptime'];
1207
+		    }
1208
+		    if (isset($line['arricao'])) {
1209
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1210
+		    }
887 1211
 		    //$data['arrival_airport_time'] = $line['arrtime'];
888
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
889
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
890
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
891
-		    else $data['info'] = '';
1212
+		    if (isset($line['aircraft'])) {
1213
+		    	$data['aircraft_icao'] = $line['aircraft'];
1214
+		    }
1215
+		    if (isset($line['transponder'])) {
1216
+		    	$data['squawk'] = $line['transponder'];
1217
+		    }
1218
+		    if (isset($line['atis'])) {
1219
+		    	$data['info'] = $line['atis'];
1220
+		    } else {
1221
+		    	$data['info'] = '';
1222
+		    }
892 1223
 		    $data['format_source'] = 'pireps';
893 1224
     		    $data['id_source'] = $id_source;
894 1225
 		    $data['datetime'] = date('Y-m-d H:i:s');
895
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
896
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1226
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1227
+		    	$data['noarchive'] = true;
1228
+		    }
1229
+		    if (isset($value['name']) && $value['name'] != '') {
1230
+		    	$data['source_name'] = $value['name'];
1231
+		    }
897 1232
 		    if ($line['icon'] == 'plane') {
898 1233
 			$SI->add($data);
899 1234
 		    //    print_r($data);
@@ -902,16 +1237,28 @@  discard block
 block discarded – undo
902 1237
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
903 1238
 			$typec = substr($data['ident'],-3);
904 1239
 			$data['type'] = '';
905
-			if ($typec == 'APP') $data['type'] = 'Approach';
906
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
907
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
908
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
909
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
910
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
911
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
912
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
913
-			else $data['type'] = 'Observer';
914
-			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']);
1240
+			if ($typec == 'APP') {
1241
+				$data['type'] = 'Approach';
1242
+			} elseif ($typec == 'TWR') {
1243
+				$data['type'] = 'Tower';
1244
+			} elseif ($typec == 'OBS') {
1245
+				$data['type'] = 'Observer';
1246
+			} elseif ($typec == 'GND') {
1247
+				$data['type'] = 'Ground';
1248
+			} elseif ($typec == 'DEL') {
1249
+				$data['type'] = 'Delivery';
1250
+			} elseif ($typec == 'DEP') {
1251
+				$data['type'] = 'Departure';
1252
+			} elseif ($typec == 'FSS') {
1253
+				$data['type'] = 'Flight Service Station';
1254
+			} elseif ($typec == 'CTR') {
1255
+				$data['type'] = 'Control Radar or Centre';
1256
+			} else {
1257
+				$data['type'] = 'Observer';
1258
+			}
1259
+			if (isset($ATC)) {
1260
+				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']);
1261
+			}
915 1262
 		    }
916 1263
 		    unset($data);
917 1264
 		}
@@ -921,7 +1268,9 @@  discard block
 block discarded – undo
921 1268
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
922 1269
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
923 1270
 	    //$buffer = $Common->getData($hosts[$id]);
924
-	    if ($globalDebug) echo 'Get Data...'."\n";
1271
+	    if ($globalDebug) {
1272
+	    	echo 'Get Data...'."\n";
1273
+	    }
925 1274
 	    $buffer = $Common->getData($value['host']);
926 1275
 	    $all_data = json_decode($buffer,true);
927 1276
 	    if ($buffer != '' && is_array($all_data)) {
@@ -929,10 +1278,16 @@  discard block
 block discarded – undo
929 1278
 		foreach ($all_data as $line) {
930 1279
 	    	    $data = array();
931 1280
 	    	    //$data['id'] = $line['id']; // id not usable
932
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1281
+	    	    if (isset($line['pilotid'])) {
1282
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1283
+	    	    }
933 1284
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
934
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
935
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1285
+	    	    if (isset($line['pilotname'])) {
1286
+	    	    	$data['pilot_name'] = $line['pilotname'];
1287
+	    	    }
1288
+	    	    if (isset($line['pilotid'])) {
1289
+	    	    	$data['pilot_id'] = $line['pilotid'];
1290
+	    	    }
936 1291
 	    	    $data['ident'] = $line['flightnum']; // ident
937 1292
 	    	    $data['altitude'] = $line['alt']; // altitude
938 1293
 	    	    $data['speed'] = $line['gs']; // speed
@@ -950,28 +1305,44 @@  discard block
 block discarded – undo
950 1305
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
951 1306
     		    $data['arrival_airport_time'] = $line['arrtime'];
952 1307
     		    $data['registration'] = $line['aircraft'];
953
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
954
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1308
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1309
+		    	$data['noarchive'] = true;
1310
+		    }
1311
+		    if (isset($line['route'])) {
1312
+		    	$data['waypoints'] = $line['route'];
1313
+		    }
1314
+		    // route
955 1315
 		    if (isset($line['aircraftname'])) {
956 1316
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
957 1317
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
958 1318
 	    		$aircraft_data = explode('-',$line['aircraftname']);
959
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
960
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
961
-	    		else {
1319
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1320
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1321
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1322
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1323
+	    		} else {
962 1324
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
963
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
964
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1325
+	    		    if (isset($aircraft_data[1])) {
1326
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1327
+	    		    } else {
1328
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1329
+	    		    }
965 1330
 	    		}
966 1331
 	    	    }
967
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1332
+    		    if (isset($line['route'])) {
1333
+    		    	$data['waypoints'] = $line['route'];
1334
+    		    }
968 1335
     		    $data['id_source'] = $id_source;
969 1336
 	    	    $data['format_source'] = 'phpvmacars';
970
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1337
+		    if (isset($value['name']) && $value['name'] != '') {
1338
+		    	$data['source_name'] = $value['name'];
1339
+		    }
971 1340
 		    $SI->add($data);
972 1341
 		    unset($data);
973 1342
 		}
974
-		if ($globalDebug) echo 'No more data...'."\n";
1343
+		if ($globalDebug) {
1344
+			echo 'No more data...'."\n";
1345
+		}
975 1346
 		unset($buffer);
976 1347
 		unset($all_data);
977 1348
 	    }
@@ -979,7 +1350,9 @@  discard block
 block discarded – undo
979 1350
     	    $last_exec[$id]['last'] = time();
980 1351
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
981 1352
 	    //$buffer = $Common->getData($hosts[$id]);
982
-	    if ($globalDebug) echo 'Get Data...'."\n";
1353
+	    if ($globalDebug) {
1354
+	    	echo 'Get Data...'."\n";
1355
+	    }
983 1356
 	    $buffer = $Common->getData($value['host']);
984 1357
 	    $all_data = json_decode($buffer,true);
985 1358
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1008,16 +1381,25 @@  discard block
 block discarded – undo
1008 1381
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1009 1382
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1010 1383
     		    //$data['registration'] = $line['aircraft'];
1011
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1384
+		    if (isset($line['route'])) {
1385
+		    	$data['waypoints'] = $line['route'];
1386
+		    }
1387
+		    // route
1012 1388
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1013 1389
     		    $data['id_source'] = $id_source;
1014 1390
 	    	    $data['format_source'] = 'vam';
1015
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1016
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1391
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1392
+		    	$data['noarchive'] = true;
1393
+		    }
1394
+		    if (isset($value['name']) && $value['name'] != '') {
1395
+		    	$data['source_name'] = $value['name'];
1396
+		    }
1017 1397
 		    $SI->add($data);
1018 1398
 		    unset($data);
1019 1399
 		}
1020
-		if ($globalDebug) echo 'No more data...'."\n";
1400
+		if ($globalDebug) {
1401
+			echo 'No more data...'."\n";
1402
+		}
1021 1403
 		unset($buffer);
1022 1404
 		unset($all_data);
1023 1405
 	    }
@@ -1025,7 +1407,9 @@  discard block
 block discarded – undo
1025 1407
     	    $last_exec[$id]['last'] = time();
1026 1408
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1027 1409
 	} 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') {
1028
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1410
+	    if (function_exists('pcntl_fork')) {
1411
+	    	pcntl_signal_dispatch();
1412
+	    }
1029 1413
     	    //$last_exec[$id]['last'] = time();
1030 1414
 
1031 1415
 	    //$read = array( $sockets[$id] );
@@ -1033,7 +1417,9 @@  discard block
 block discarded – undo
1033 1417
 	    $write = NULL;
1034 1418
 	    $e = NULL;
1035 1419
 	    $n = socket_select($read, $write, $e, $timeout);
1036
-	    if ($e != NULL) var_dump($e);
1420
+	    if ($e != NULL) {
1421
+	    	var_dump($e);
1422
+	    }
1037 1423
 	    if ($n > 0) {
1038 1424
 		$reset = 0;
1039 1425
 		foreach ($read as $nb => $r) {
@@ -1054,12 +1440,16 @@  discard block
 block discarded – undo
1054 1440
 		    //$SI::del();
1055 1441
 		    if ($format == 'vrstcp') {
1056 1442
 			$buffer = explode('},{',$buffer);
1057
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1443
+		    } else {
1444
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1445
+		    }
1058 1446
 		    // SBS format is CSV format
1059 1447
 		    if ($buffer !== FALSE && $buffer != '') {
1060 1448
 			$tt[$format] = 0;
1061 1449
 			if ($format == 'acarssbs3') {
1062
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1450
+			    if ($globalDebug) {
1451
+			    	echo 'ACARS : '.$buffer."\n";
1452
+			    }
1063 1453
 			    $ACARS->add(trim($buffer));
1064 1454
 			    $ACARS->deleteLiveAcarsData();
1065 1455
 			} elseif ($format == 'raw') {
@@ -1068,27 +1458,61 @@  discard block
 block discarded – undo
1068 1458
 			    if (is_array($data)) {
1069 1459
 				$data['datetime'] = date('Y-m-d H:i:s');
1070 1460
 				$data['format_source'] = 'raw';
1071
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1072
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1073
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1074
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1461
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1462
+					$data['source_name'] = $globalSources[$nb]['name'];
1463
+				}
1464
+				if (isset($globalSources[$nb]['sourcestats'])) {
1465
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1466
+				}
1467
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1468
+					$data['noarchive'] = true;
1469
+				}
1470
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1471
+					$SI->add($data);
1472
+				}
1075 1473
 			    }
1076 1474
 			} elseif ($format == 'ais') {
1077 1475
 			    $ais_data = $AIS->parse_line(trim($buffer));
1078 1476
 			    $data = array();
1079
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1080
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1081
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1082
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1083
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1084
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1085
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1086
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1087
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1088
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1089
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1090
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1091
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1477
+			    if (isset($ais_data['ident'])) {
1478
+			    	$data['ident'] = $ais_data['ident'];
1479
+			    }
1480
+			    if (isset($ais_data['mmsi'])) {
1481
+			    	$data['mmsi'] = $ais_data['mmsi'];
1482
+			    }
1483
+			    if (isset($ais_data['speed'])) {
1484
+			    	$data['speed'] = $ais_data['speed'];
1485
+			    }
1486
+			    if (isset($ais_data['heading'])) {
1487
+			    	$data['heading'] = $ais_data['heading'];
1488
+			    }
1489
+			    if (isset($ais_data['latitude'])) {
1490
+			    	$data['latitude'] = $ais_data['latitude'];
1491
+			    }
1492
+			    if (isset($ais_data['longitude'])) {
1493
+			    	$data['longitude'] = $ais_data['longitude'];
1494
+			    }
1495
+			    if (isset($ais_data['status'])) {
1496
+			    	$data['status'] = $ais_data['status'];
1497
+			    }
1498
+			    if (isset($ais_data['type'])) {
1499
+			    	$data['type'] = $ais_data['type'];
1500
+			    }
1501
+			    if (isset($ais_data['imo'])) {
1502
+			    	$data['imo'] = $ais_data['imo'];
1503
+			    }
1504
+			    if (isset($ais_data['callsign'])) {
1505
+			    	$data['callsign'] = $ais_data['callsign'];
1506
+			    }
1507
+			    if (isset($ais_data['destination'])) {
1508
+			    	$data['arrival_code'] = $ais_data['destination'];
1509
+			    }
1510
+			    if (isset($ais_data['eta_ts'])) {
1511
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1512
+			    }
1513
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1514
+			    	$data['noarchive'] = true;
1515
+			    }
1092 1516
 
1093 1517
 			    if (isset($ais_data['timestamp'])) {
1094 1518
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1097,7 +1521,9 @@  discard block
 block discarded – undo
1097 1521
 			    }
1098 1522
 			    $data['format_source'] = 'aisnmea';
1099 1523
     			    $data['id_source'] = $id_source;
1100
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1524
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1525
+			    	$MI->add($data);
1526
+			    }
1101 1527
 			    unset($data);
1102 1528
                         } elseif ($format == 'flightgearsp') {
1103 1529
                     	    //echo $buffer."\n";
@@ -1115,12 +1541,18 @@  discard block
 block discarded – undo
1115 1541
 				$data['speed'] = round($line[5]*1.94384);
1116 1542
 				$data['datetime'] = date('Y-m-d H:i:s');
1117 1543
 				$data['format_source'] = 'flightgearsp';
1118
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1119
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1544
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1545
+					$data['noarchive'] = true;
1546
+				}
1547
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1548
+					$SI->add($data);
1549
+				}
1120 1550
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1121 1551
 			    }
1122 1552
                         } elseif ($format == 'acars') {
1123
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1553
+                    	    if ($globalDebug) {
1554
+                    	    	echo 'ACARS : '.$buffer."\n";
1555
+                    	    }
1124 1556
 			    $ACARS->add(trim($buffer));
1125 1557
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1126 1558
 			    $ACARS->deleteLiveAcarsData();
@@ -1141,8 +1573,12 @@  discard block
 block discarded – undo
1141 1573
 				    $aircraft_type = $line[10];
1142 1574
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1143 1575
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1144
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1145
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1576
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1577
+				    	$data['noarchive'] = true;
1578
+				    }
1579
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1580
+				    	$SI->add($data);
1581
+				    }
1146 1582
 				}
1147 1583
 			    }
1148 1584
 			} elseif ($format == 'beast') {
@@ -1152,28 +1588,62 @@  discard block
 block discarded – undo
1152 1588
 			    foreach($buffer as $all_data) {
1153 1589
 				$line = json_decode('{'.$all_data.'}',true);
1154 1590
 				$data = array();
1155
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1156
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1157
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1158
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1159
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1160
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1161
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1591
+				if (isset($line['Icao'])) {
1592
+					$data['hex'] = $line['Icao'];
1593
+				}
1594
+				// hex
1595
+				if (isset($line['Call'])) {
1596
+					$data['ident'] = $line['Call'];
1597
+				}
1598
+				// ident
1599
+				if (isset($line['Alt'])) {
1600
+					$data['altitude'] = $line['Alt'];
1601
+				}
1602
+				// altitude
1603
+				if (isset($line['Spd'])) {
1604
+					$data['speed'] = $line['Spd'];
1605
+				}
1606
+				// speed
1607
+				if (isset($line['Trak'])) {
1608
+					$data['heading'] = $line['Trak'];
1609
+				}
1610
+				// heading
1611
+				if (isset($line['Lat'])) {
1612
+					$data['latitude'] = $line['Lat'];
1613
+				}
1614
+				// lat
1615
+				if (isset($line['Long'])) {
1616
+					$data['longitude'] = $line['Long'];
1617
+				}
1618
+				// long
1162 1619
 				//$data['verticalrate'] = $line['']; // verticale rate
1163
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1620
+				if (isset($line['Sqk'])) {
1621
+					$data['squawk'] = $line['Sqk'];
1622
+				}
1623
+				// squawk
1164 1624
 				$data['emergency'] = ''; // emergency
1165
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1625
+				if (isset($line['Reg'])) {
1626
+					$data['registration'] = $line['Reg'];
1627
+				}
1166 1628
 				/*
1167 1629
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1168 1630
 				else $data['datetime'] = date('Y-m-d H:i:s');
1169 1631
 				*/
1170 1632
 				$data['datetime'] = date('Y-m-d H:i:s');
1171
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1633
+				if (isset($line['Type'])) {
1634
+					$data['aircraft_icao'] = $line['Type'];
1635
+				}
1172 1636
 		    		$data['format_source'] = 'vrstcp';
1173 1637
 				$data['id_source'] = $id_source;
1174
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1175
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1176
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1638
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1639
+					$data['noarchive'] = true;
1640
+				}
1641
+				if (isset($value['name']) && $value['name'] != '') {
1642
+					$data['source_name'] = $value['name'];
1643
+				}
1644
+				if (isset($data['latitude']) && isset($data['hex'])) {
1645
+					$SI->add($data);
1646
+				}
1177 1647
 				unset($data);
1178 1648
 			    }
1179 1649
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1186,22 +1656,46 @@  discard block
 block discarded – undo
1186 1656
     				$data['hex'] = $lined['hexid'];
1187 1657
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1188 1658
     				$data['datetime'] = date('Y-m-d H:i:s');;
1189
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1190
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1191
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1192
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1193
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1194
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1195
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1659
+    				if (isset($lined['ident'])) {
1660
+    					$data['ident'] = $lined['ident'];
1661
+    				}
1662
+    				if (isset($lined['lat'])) {
1663
+    					$data['latitude'] = $lined['lat'];
1664
+    				}
1665
+    				if (isset($lined['lon'])) {
1666
+    					$data['longitude'] = $lined['lon'];
1667
+    				}
1668
+    				if (isset($lined['speed'])) {
1669
+    					$data['speed'] = $lined['speed'];
1670
+    				}
1671
+    				if (isset($lined['squawk'])) {
1672
+    					$data['squawk'] = $lined['squawk'];
1673
+    				}
1674
+    				if (isset($lined['alt'])) {
1675
+    					$data['altitude'] = $lined['alt'];
1676
+    				}
1677
+    				if (isset($lined['heading'])) {
1678
+    					$data['heading'] = $lined['heading'];
1679
+    				}
1196 1680
     				$data['id_source'] = $id_source;
1197 1681
     				$data['format_source'] = 'tsv';
1198
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1199
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1200
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1201
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1682
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1683
+    					$data['source_name'] = $globalSources[$nb]['name'];
1684
+    				}
1685
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1686
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1687
+    				}
1688
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1689
+					$data['noarchive'] = true;
1690
+				}
1691
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1692
+    					$SI->add($data);
1693
+    				}
1202 1694
     				unset($lined);
1203 1695
     				unset($data);
1204
-    			    } else $error = true;
1696
+    			    } else {
1697
+    			    	$error = true;
1698
+    			    }
1205 1699
 			} elseif ($format == 'aprs' && $use_aprs) {
1206 1700
 			    if ($aprs_connect == 0) {
1207 1701
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1226,32 +1720,66 @@  discard block
 block discarded – undo
1226 1720
 				    $aprs_last_tx = time();
1227 1721
 				    $data = array();
1228 1722
 				    //print_r($line);
1229
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1230
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1231
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1232
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1723
+				    if (isset($line['address'])) {
1724
+				    	$data['hex'] = $line['address'];
1725
+				    }
1726
+				    if (isset($line['mmsi'])) {
1727
+				    	$data['mmsi'] = $line['mmsi'];
1728
+				    }
1729
+				    if (isset($line['timestamp'])) {
1730
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1731
+				    } else {
1732
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1733
+				    }
1233 1734
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1234
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1735
+				    if (isset($line['ident'])) {
1736
+				    	$data['ident'] = $line['ident'];
1737
+				    }
1235 1738
 				    $data['latitude'] = $line['latitude'];
1236 1739
 				    $data['longitude'] = $line['longitude'];
1237 1740
 				    //$data['verticalrate'] = $line[16];
1238
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1239
-				    else $data['speed'] = 0;
1240
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1241
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1242
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1243
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1741
+				    if (isset($line['speed'])) {
1742
+				    	$data['speed'] = $line['speed'];
1743
+				    } else {
1744
+				    	$data['speed'] = 0;
1745
+				    }
1746
+				    if (isset($line['altitude'])) {
1747
+				    	$data['altitude'] = $line['altitude'];
1748
+				    }
1749
+				    if (isset($line['comment'])) {
1750
+				    	$data['comment'] = $line['comment'];
1751
+				    }
1752
+				    if (isset($line['symbol'])) {
1753
+				    	$data['type'] = $line['symbol'];
1754
+				    }
1755
+				    if (isset($line['heading'])) {
1756
+				    	$data['heading'] = $line['heading'];
1757
+				    }
1244 1758
 				    //else $data['heading'] = 0;
1245
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1246
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE)) $data['noarchive'] = true;
1247
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1759
+				    if (isset($line['stealth'])) {
1760
+				    	$data['aircraft_type'] = $line['stealth'];
1761
+				    }
1762
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE)) {
1763
+				    	$data['noarchive'] = true;
1764
+				    }
1765
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1766
+				    	$data['noarchive'] = true;
1767
+				    }
1248 1768
     				    $data['id_source'] = $id_source;
1249
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1250
-				    else $data['format_source'] = 'aprs';
1769
+    				    if (isset($line['format_source'])) {
1770
+    				    	$data['format_source'] = $line['format_source'];
1771
+    				    } else {
1772
+				    	$data['format_source'] = 'aprs';
1773
+				    }
1251 1774
 				    $data['source_name'] = $line['source'];
1252
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1253
-				    else $data['source_type'] = 'flarm';
1254
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1775
+				    if (isset($line['source_type'])) {
1776
+				    	$data['source_type'] = $line['source_type'];
1777
+				    } else {
1778
+				    	$data['source_type'] = 'flarm';
1779
+				    }
1780
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1781
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1782
+    				    }
1255 1783
 				    $currentdate = date('Y-m-d H:i:s');
1256 1784
 				    $aprsdate = strtotime($data['datetime']);
1257 1785
 				    // Accept data if time <= system time + 20s
@@ -1261,19 +1789,22 @@  discard block
 block discarded – undo
1261 1789
 					echo 'add...'."\n";
1262 1790
 					$send = $MI->add($data);
1263 1791
 				    } elseif (isset($line['stealth'])) {
1264
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1265
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1792
+					if ($line['stealth'] != 0) {
1793
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1794
+					} else {
1795
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1796
+					}
1266 1797
 				    //} 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')) {
1267 1798
 				    } 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') {
1268 1799
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1269
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1800
+					if (isset($globalTracker) && $globalTracker) {
1801
+						$send = $TI->add($data);
1802
+					}
1270 1803
 				    }
1271 1804
 				    unset($data);
1272
-				} 
1273
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1805
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1274 1806
 					echo '!! Weather Station not yet supported'."\n";
1275
-				}
1276
-				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')) {
1807
+				} 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')) {
1277 1808
 					echo '!! Car & Trucks not yet supported'."\n";
1278 1809
 				}
1279 1810
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1306,26 +1837,45 @@  discard block
 block discarded – undo
1306 1837
     				$data['ground'] = $line[21];
1307 1838
     				$data['emergency'] = $line[19];
1308 1839
     				$data['format_source'] = 'sbs';
1309
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1310
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1311
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1840
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1841
+					$data['source_name'] = $globalSources[$nb]['name'];
1842
+				}
1843
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1844
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1845
+    				}
1846
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1847
+					$data['noarchive'] = true;
1848
+				}
1312 1849
     				$data['id_source'] = $id_source;
1313
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1314
-    				else $error = true;
1850
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1851
+    					$send = $SI->add($data);
1852
+    				} else {
1853
+    					$error = true;
1854
+    				}
1315 1855
     				unset($data);
1316
-    			    } else $error = true;
1856
+    			    } else {
1857
+    			    	$error = true;
1858
+    			    }
1317 1859
 			    if ($error) {
1318 1860
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1319
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1861
+					if ($globalDebug) {
1862
+						echo "Not a message. Ignoring... \n";
1863
+					}
1320 1864
 				} else {
1321
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1865
+					if ($globalDebug) {
1866
+						echo "Wrong line format. Ignoring... \n";
1867
+					}
1322 1868
 					if ($globalDebug) {
1323 1869
 						echo $buffer;
1324 1870
 						//print_r($line);
1325 1871
 					}
1326 1872
 					//socket_close($r);
1327
-					if ($globalDebug) echo "Reconnect after an error...\n";
1328
-					if ($format == 'aprs') $aprs_connect = 0;
1873
+					if ($globalDebug) {
1874
+						echo "Reconnect after an error...\n";
1875
+					}
1876
+					if ($format == 'aprs') {
1877
+						$aprs_connect = 0;
1878
+					}
1329 1879
 					$sourceer[$nb] = $globalSources[$nb];
1330 1880
 					connect_all($sourceer);
1331 1881
 					$sourceer = array();
@@ -1333,10 +1883,14 @@  discard block
 block discarded – undo
1333 1883
 			    }
1334 1884
 			}
1335 1885
 			// Sleep for xxx microseconds
1336
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1886
+			if (isset($globalSBSSleep)) {
1887
+				usleep($globalSBSSleep);
1888
+			}
1337 1889
 		    } else {
1338 1890
 			if ($format == 'flightgearmp') {
1339
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1891
+			    	if ($globalDebug) {
1892
+			    		echo "Reconnect FlightGear MP...";
1893
+			    	}
1340 1894
 				//@socket_close($r);
1341 1895
 				sleep($globalMinFetch);
1342 1896
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1345,10 +1899,15 @@  discard block
 block discarded – undo
1345 1899
 				break;
1346 1900
 				
1347 1901
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1348
-			    if (isset($tt[$format])) $tt[$format]++;
1349
-			    else $tt[$format] = 0;
1902
+			    if (isset($tt[$format])) {
1903
+			    	$tt[$format]++;
1904
+			    } else {
1905
+			    	$tt[$format] = 0;
1906
+			    }
1350 1907
 			    if ($tt[$format] > 30) {
1351
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1908
+				if ($globalDebug) {
1909
+					echo "ERROR : Reconnect ".$format."...";
1910
+				}
1352 1911
 				//@socket_close($r);
1353 1912
 				sleep(2);
1354 1913
 				$aprs_connect = 0;
@@ -1365,11 +1924,17 @@  discard block
 block discarded – undo
1365 1924
 	    } else {
1366 1925
 		$error = socket_strerror(socket_last_error());
1367 1926
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1368
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1369
-			if (isset($globalDebug)) echo "Restarting...\n";
1927
+			if ($globalDebug) {
1928
+				echo "ERROR : socket_select give this error ".$error . "\n";
1929
+			}
1930
+			if (isset($globalDebug)) {
1931
+				echo "Restarting...\n";
1932
+			}
1370 1933
 			// Restart the script if possible
1371 1934
 			if (is_array($sockets)) {
1372
-			    if ($globalDebug) echo "Shutdown all sockets...";
1935
+			    if ($globalDebug) {
1936
+			    	echo "Shutdown all sockets...";
1937
+			    }
1373 1938
 			    
1374 1939
 			    foreach ($sockets as $sock) {
1375 1940
 				@socket_shutdown($sock,2);
@@ -1377,21 +1942,33 @@  discard block
 block discarded – undo
1377 1942
 			    }
1378 1943
 			    
1379 1944
 			}
1380
-			if ($globalDebug) echo "Restart all connections...";
1945
+			if ($globalDebug) {
1946
+				echo "Restart all connections...";
1947
+			}
1381 1948
 			sleep(2);
1382 1949
 			$time = time();
1383 1950
 			//connect_all($hosts);
1384 1951
 			$aprs_connect = 0;
1385
-			if ($reset%5 == 0) sleep(20);
1386
-			if ($reset%10 == 0) sleep(100);
1387
-			if ($reset%20 == 0) sleep(200);
1388
-			if ($reset > 100) exit('Too many attempts...');
1952
+			if ($reset%5 == 0) {
1953
+				sleep(20);
1954
+			}
1955
+			if ($reset%10 == 0) {
1956
+				sleep(100);
1957
+			}
1958
+			if ($reset%20 == 0) {
1959
+				sleep(200);
1960
+			}
1961
+			if ($reset > 100) {
1962
+				exit('Too many attempts...');
1963
+			}
1389 1964
 			connect_all($globalSources);
1390 1965
 		}
1391 1966
 	    }
1392 1967
 	}
1393 1968
 	if ($globalDaemon === false) {
1394
-	    if ($globalDebug) echo 'Check all...'."\n";
1969
+	    if ($globalDebug) {
1970
+	    	echo 'Check all...'."\n";
1971
+	    }
1395 1972
 	    $SI->checkAll();
1396 1973
 	}
1397 1974
     }
Please login to merge, or discard this patch.