Completed
Push — master ( 2a365a...b6fed2 )
by Yannick
06:39
created
scripts/daemon-spotter.php 3 patches
Indentation   +594 added lines, -594 removed lines patch added patch discarded remove patch
@@ -19,26 +19,26 @@  discard block
 block discarded – undo
19 19
 // Check if schema is at latest version
20 20
 $Connection = new Connection();
21 21
 if ($Connection->latest() === false) {
22
-    echo "You MUST update to latest schema. Run install/index.php";
23
-    exit();
22
+	echo "You MUST update to latest schema. Run install/index.php";
23
+	exit();
24 24
 }
25 25
 
26 26
 
27 27
 // This is to be compatible with old version of settings.php
28 28
 if (!isset($globalSources)) {
29
-    if (isset($globalSBS1Hosts)) {
30
-        //$hosts = $globalSBS1Hosts;
31
-        foreach ($globalSBS1Hosts as $host) {
32
-	    $globalSources[] = array('host' => $host);
33
-    	}
34
-    } else {
35
-        if (!isset($globalSBS1Host)) {
36
-	    echo '$globalSources MUST be defined !';
37
-	    die;
29
+	if (isset($globalSBS1Hosts)) {
30
+		//$hosts = $globalSBS1Hosts;
31
+		foreach ($globalSBS1Hosts as $host) {
32
+		$globalSources[] = array('host' => $host);
33
+		}
34
+	} else {
35
+		if (!isset($globalSBS1Host)) {
36
+		echo '$globalSources MUST be defined !';
37
+		die;
38 38
 	}
39 39
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
40 40
 	$globalSources[] = array('host' => $globalSBS1Host.':'.$globalSBS1Port);
41
-    }
41
+	}
42 42
 }
43 43
 
44 44
 $options = getopt('s::',array('source::','server','idsource::'));
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 if (isset($options['idsource'])) $id_source = $options['idsource'];
51 51
 else $id_source = 1;
52 52
 if (isset($globalServer) && $globalServer) {
53
-    if ($globalDebug) echo "Using Server Mode\n";
54
-    $SI=new SpotterServer();
53
+	if ($globalDebug) echo "Using Server Mode\n";
54
+	$SI=new SpotterServer();
55 55
 } else $SI=new SpotterImport($Connection->db);
56 56
 //$APRS=new APRS($Connection->db);
57 57
 $SBS=new SBS($Connection->db);
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
 //$servertz = system('date +%Z');
62 62
 // signal handler - playing nice with sockets and dump1090
63 63
 if (function_exists('pcntl_fork')) {
64
-    pcntl_signal(SIGINT,  function($signo) {
65
-        global $sockets;
66
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
67
-        die("Bye!\n");
68
-    });
69
-    pcntl_signal_dispatch();
64
+	pcntl_signal(SIGINT,  function($signo) {
65
+		global $sockets;
66
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
67
+		die("Bye!\n");
68
+	});
69
+	pcntl_signal_dispatch();
70 70
 }
71 71
 
72 72
 // let's try and connect
@@ -74,146 +74,146 @@  discard block
 block discarded – undo
74 74
 $use_aprs = false;
75 75
 
76 76
 function create_socket($host, $port, &$errno, &$errstr) {
77
-    $ip = gethostbyname($host);
78
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
79
-    $r = @socket_connect($s, $ip, $port);
80
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
81
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
82
-        return $s;
83
-    }
84
-    $errno = socket_last_error($s);
85
-    $errstr = socket_strerror($errno);
86
-    socket_close($s);
87
-    return false;
77
+	$ip = gethostbyname($host);
78
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
79
+	$r = @socket_connect($s, $ip, $port);
80
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
81
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
82
+		return $s;
83
+	}
84
+	$errno = socket_last_error($s);
85
+	$errstr = socket_strerror($errno);
86
+	socket_close($s);
87
+	return false;
88 88
 }
89 89
 
90 90
 function create_socket_udp($host, $port, &$errno, &$errstr) {
91
-    echo "UDP !!";
92
-    $ip = gethostbyname($host);
93
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
94
-    $r = @socket_bind($s, $ip, $port);
95
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
96
-        return $s;
97
-    }
98
-    $errno = socket_last_error($s);
99
-    $errstr = socket_strerror($errno);
100
-    socket_close($s);
101
-    return false;
91
+	echo "UDP !!";
92
+	$ip = gethostbyname($host);
93
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
94
+	$r = @socket_bind($s, $ip, $port);
95
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
96
+		return $s;
97
+	}
98
+	$errno = socket_last_error($s);
99
+	$errstr = socket_strerror($errno);
100
+	socket_close($s);
101
+	return false;
102 102
 }
103 103
 
104 104
 function connect_all($hosts) {
105
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
107
-    foreach ($hosts as $id => $value) {
105
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
107
+	foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111 111
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
113
-        	//$formats[$id] = 'deltadbtxt';
114
-        	$globalSources[$id]['format'] = 'deltadbtxt';
115
-        	//$last_exec['deltadbtxt'] = 0;
116
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
118
-        	//$formats[$id] = 'vatsimtxt';
119
-        	$globalSources[$id]['format'] = 'vatsimtxt';
120
-        	//$last_exec['vatsimtxt'] = 0;
121
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
123
-        	//$formats[$id] = 'aircraftlistjson';
124
-        	$$globalSources[$id]['format'] = 'aircraftlistjson';
125
-        	//$last_exec['aircraftlistjson'] = 0;
126
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
128
-        	//$formats[$id] = 'radarvirtueljson';
129
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
130
-        	//$last_exec['radarvirtueljson'] = 0;
131
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
132
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
133
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
134
-        	    exit(0);
135
-        	}
136
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
137
-        	//$formats[$id] = 'planeupdatefaa';
138
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
139
-        	//$last_exec['planeupdatefaa'] = 0;
140
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
141
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
142
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
143
-        	    exit(0);
144
-        	}
145
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
146
-        	//$formats[$id] = 'phpvmacars';
147
-        	$globalSources[$id]['format'] = 'phpvmacars';
148
-        	//$last_exec['phpvmacars'] = 0;
149
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
150
-            } else if (preg_match('/whazzup/i',$host)) {
151
-        	//$formats[$id] = 'whazzup';
152
-        	$globalSources[$id]['format'] = 'whazzup';
153
-        	//$last_exec['whazzup'] = 0;
154
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
155
-            } else if (preg_match('/recentpireps/i',$host)) {
156
-        	//$formats[$id] = 'pirepsjson';
157
-        	$globalSources[$id]['format'] = 'pirepsjson';
158
-        	//$last_exec['pirepsjson'] = 0;
159
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
160
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
161
-        	//$formats[$id] = 'fr24json';
162
-        	$globalSources[$id]['format'] = 'fr24json';
163
-        	//$last_exec['fr24json'] = 0;
164
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
165
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
166
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
167
-        	    exit(0);
168
-        	}
169
-            //} else if (preg_match('/10001/',$host)) {
170
-            } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
171
-        	//$formats[$id] = 'tsv';
172
-        	$globalSources[$id]['format'] = 'tsv';
173
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
174
-            }
175
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
176
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
177
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
178
-	    $hostport = explode(':',$host);
179
-	    if (isset($hostport[1])) $port = $hostport[1];
180
-	    else $port = $globalSources[$id]['port'];
181
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
182
-        	$s = create_socket($host,$port, $errno, $errstr);
183
-    	    } else {
184
-        	$s = create_socket_udp($host,$port, $errno, $errstr);
185
-	    }
186
-	    if ($s) {
187
-    	        $sockets[$id] = $s;
188
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
189
-		    if (preg_match('/aprs/',$host)) {
112
+			if (preg_match('/deltadb.txt$/i',$host)) {
113
+			//$formats[$id] = 'deltadbtxt';
114
+			$globalSources[$id]['format'] = 'deltadbtxt';
115
+			//$last_exec['deltadbtxt'] = 0;
116
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
118
+			//$formats[$id] = 'vatsimtxt';
119
+			$globalSources[$id]['format'] = 'vatsimtxt';
120
+			//$last_exec['vatsimtxt'] = 0;
121
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
123
+			//$formats[$id] = 'aircraftlistjson';
124
+			$$globalSources[$id]['format'] = 'aircraftlistjson';
125
+			//$last_exec['aircraftlistjson'] = 0;
126
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
128
+			//$formats[$id] = 'radarvirtueljson';
129
+			$globalSources[$id]['format'] = 'radarvirtueljson';
130
+			//$last_exec['radarvirtueljson'] = 0;
131
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
132
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
133
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
134
+				exit(0);
135
+			}
136
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
137
+			//$formats[$id] = 'planeupdatefaa';
138
+			$globalSources[$id]['format'] = 'planeupdatefaa';
139
+			//$last_exec['planeupdatefaa'] = 0;
140
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
141
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
142
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
143
+				exit(0);
144
+			}
145
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
146
+			//$formats[$id] = 'phpvmacars';
147
+			$globalSources[$id]['format'] = 'phpvmacars';
148
+			//$last_exec['phpvmacars'] = 0;
149
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
150
+			} else if (preg_match('/whazzup/i',$host)) {
151
+			//$formats[$id] = 'whazzup';
152
+			$globalSources[$id]['format'] = 'whazzup';
153
+			//$last_exec['whazzup'] = 0;
154
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
155
+			} else if (preg_match('/recentpireps/i',$host)) {
156
+			//$formats[$id] = 'pirepsjson';
157
+			$globalSources[$id]['format'] = 'pirepsjson';
158
+			//$last_exec['pirepsjson'] = 0;
159
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
160
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
161
+			//$formats[$id] = 'fr24json';
162
+			$globalSources[$id]['format'] = 'fr24json';
163
+			//$last_exec['fr24json'] = 0;
164
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
165
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
166
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
167
+				exit(0);
168
+			}
169
+			//} else if (preg_match('/10001/',$host)) {
170
+			} else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
171
+			//$formats[$id] = 'tsv';
172
+			$globalSources[$id]['format'] = 'tsv';
173
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
174
+			}
175
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
176
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
177
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
178
+		$hostport = explode(':',$host);
179
+		if (isset($hostport[1])) $port = $hostport[1];
180
+		else $port = $globalSources[$id]['port'];
181
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
182
+			$s = create_socket($host,$port, $errno, $errstr);
183
+			} else {
184
+			$s = create_socket_udp($host,$port, $errno, $errstr);
185
+		}
186
+		if ($s) {
187
+				$sockets[$id] = $s;
188
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
189
+			if (preg_match('/aprs/',$host)) {
190 190
 			//$formats[$id] = 'aprs';
191 191
 			$globalSources[$id]['format'] = 'aprs';
192 192
 			//$aprs_connect = 0;
193 193
 			//$use_aprs = true;
194
-    		    } elseif ($port == '10001') {
195
-        		//$formats[$id] = 'tsv';
196
-        		$globalSources[$id]['format'] = 'tsv';
197
-		    } elseif ($port == '30002') {
198
-        		//$formats[$id] = 'raw';
199
-        		$globalSources[$id]['format'] = 'raw';
200
-		    } elseif ($port == '5001') {
201
-        		//$formats[$id] = 'raw';
202
-        		$globalSources[$id]['format'] = 'flightgearmp';
203
-		    } elseif ($port == '30005') {
194
+				} elseif ($port == '10001') {
195
+				//$formats[$id] = 'tsv';
196
+				$globalSources[$id]['format'] = 'tsv';
197
+			} elseif ($port == '30002') {
198
+				//$formats[$id] = 'raw';
199
+				$globalSources[$id]['format'] = 'raw';
200
+			} elseif ($port == '5001') {
201
+				//$formats[$id] = 'raw';
202
+				$globalSources[$id]['format'] = 'flightgearmp';
203
+			} elseif ($port == '30005') {
204 204
 			// Not yet supported
205
-        		//$formats[$id] = 'beast';
206
-        		$globalSources[$id]['format'] = 'beast';
207
-		    //} else $formats[$id] = 'sbs';
208
-		    } else $globalSources[$id]['format'] = 'sbs';
209
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
205
+				//$formats[$id] = 'beast';
206
+				$globalSources[$id]['format'] = 'beast';
207
+			//} else $formats[$id] = 'sbs';
208
+			} else $globalSources[$id]['format'] = 'sbs';
209
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
210 210
 		}
211 211
 		if ($globalDebug) echo 'Connection in progress to '.$host.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
212
-            } else {
212
+			} else {
213 213
 		if ($globalDebug) echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
214
-    	    }
215
-        }
216
-    }
214
+			}
215
+		}
216
+	}
217 217
 }
218 218
 if (!isset($globalMinFetch)) $globalMinFetch = 0;
219 219
 
@@ -236,13 +236,13 @@  discard block
 block discarded – undo
236 236
 
237 237
 // APRS Configuration
238 238
 foreach ($globalSources as $key => $source) {
239
-    if (isset($source['format']) && $source['format'] == 'aprs') {
239
+	if (isset($source['format']) && $source['format'] == 'aprs') {
240 240
 	$aprs_connect = 0;
241 241
 	$use_aprs = true;
242 242
 	break;
243
-    } elseif (!isset($source['format'])) {
244
-        $globalSources[$key]['format'] = 'auto';
245
-    }
243
+	} elseif (!isset($source['format'])) {
244
+		$globalSources[$key]['format'] = 'auto';
245
+	}
246 246
 }
247 247
 
248 248
 if ($use_aprs) {
@@ -281,53 +281,53 @@  discard block
 block discarded – undo
281 281
 
282 282
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
283 283
 while ($i > 0) {
284
-    if (!$globalDaemon) $i = $endtime-time();
285
-    // Delete old ATC
286
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
287
-        $ATC->deleteOldATC();
288
-    }
289
-    //foreach ($formats as $id => $value) {
290
-    foreach ($globalSources as $id => $value) {
284
+	if (!$globalDaemon) $i = $endtime-time();
285
+	// Delete old ATC
286
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
287
+		$ATC->deleteOldATC();
288
+	}
289
+	//foreach ($formats as $id => $value) {
290
+	foreach ($globalSources as $id => $value) {
291 291
 	//if ($value == 'deltadbtxt' && (time() - $last_exec['deltadbtxt'] > $globalMinFetch)) {
292 292
 	if ($value['format'] == 'deltadbtxt' && (time() - $value['last_exec'] > $globalMinFetch)) {
293
-	    //$buffer = $Common->getData($hosts[$id]);
294
-	    $buffer = $Common->getData($value['host']);
295
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
296
-	    $buffer = explode('\n',$buffer);
297
-	    foreach ($buffer as $line) {
298
-    		if ($line != '') {
299
-    		    $line = explode(',', $line);
300
-	            $data = array();
301
-	            $data['hex'] = $line[1]; // hex
302
-	            $data['ident'] = $line[2]; // ident
303
-	            $data['altitude'] = $line[3]; // altitude
304
-	            $data['speed'] = $line[4]; // speed
305
-	            $data['heading'] = $line[5]; // heading
306
-	            $data['latitude'] = $line[6]; // lat
307
-	            $data['longitude'] = $line[7]; // long
308
-	            $data['verticalrate'] = ''; // vertical rate
309
-	            $data['squawk'] = ''; // squawk
310
-	            $data['emergency'] = ''; // emergency
311
-		    $data['datetime'] = date('Y-m-d H:i:s');
312
-		    $data['format_source'] = 'deltadbtxt';
313
-    		    $data['id_source'] = $id_source;
314
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
315
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
316
-    		    $SI->add($data);
317
-		    unset($data);
318
-    		}
319
-    	    }
320
-    	    $value['last_exec'] = time();
293
+		//$buffer = $Common->getData($hosts[$id]);
294
+		$buffer = $Common->getData($value['host']);
295
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
296
+		$buffer = explode('\n',$buffer);
297
+		foreach ($buffer as $line) {
298
+			if ($line != '') {
299
+				$line = explode(',', $line);
300
+				$data = array();
301
+				$data['hex'] = $line[1]; // hex
302
+				$data['ident'] = $line[2]; // ident
303
+				$data['altitude'] = $line[3]; // altitude
304
+				$data['speed'] = $line[4]; // speed
305
+				$data['heading'] = $line[5]; // heading
306
+				$data['latitude'] = $line[6]; // lat
307
+				$data['longitude'] = $line[7]; // long
308
+				$data['verticalrate'] = ''; // vertical rate
309
+				$data['squawk'] = ''; // squawk
310
+				$data['emergency'] = ''; // emergency
311
+			$data['datetime'] = date('Y-m-d H:i:s');
312
+			$data['format_source'] = 'deltadbtxt';
313
+				$data['id_source'] = $id_source;
314
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
315
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
316
+				$SI->add($data);
317
+			unset($data);
318
+			}
319
+			}
320
+			$value['last_exec'] = time();
321 321
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
322 322
 	} elseif (($value['format'] == 'whazzup' && (time() - $value['last_exec'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $value['last_exec'] > $globalMinFetch))) {
323
-	    //$buffer = $Common->getData($hosts[$id]);
324
-	    $buffer = $Common->getData($value['host']);
325
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
326
-	    $buffer = explode('\n',$buffer);
327
-	    foreach ($buffer as $line) {
328
-    		if ($line != '') {
329
-    		    $line = explode(':', $line);
330
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
323
+		//$buffer = $Common->getData($hosts[$id]);
324
+		$buffer = $Common->getData($value['host']);
325
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
326
+		$buffer = explode('\n',$buffer);
327
+		foreach ($buffer as $line) {
328
+			if ($line != '') {
329
+				$line = explode(':', $line);
330
+				if (count($line) > 30 && $line[0] != 'callsign') {
331 331
 			$data = array();
332 332
 			$data['id'] = $line[1].'-'.$line[0];
333 333
 			$data['pilot_id'] = $line[1];
@@ -339,35 +339,35 @@  discard block
 block discarded – undo
339 339
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
340 340
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
341 341
 			$data['latitude'] = $line[5]; // lat
342
-	        	$data['longitude'] = $line[6]; // long
343
-	        	$data['verticalrate'] = ''; // vertical rate
344
-	        	$data['squawk'] = ''; // squawk
345
-	        	$data['emergency'] = ''; // emergency
346
-	        	$data['waypoints'] = $line[30];
342
+				$data['longitude'] = $line[6]; // long
343
+				$data['verticalrate'] = ''; // vertical rate
344
+				$data['squawk'] = ''; // squawk
345
+				$data['emergency'] = ''; // emergency
346
+				$data['waypoints'] = $line[30];
347 347
 			$data['datetime'] = date('Y-m-d H:i:s');
348 348
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
349
-		        $data['departure_airport_icao'] = $line[11];
350
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
351
-		        $data['arrival_airport_icao'] = $line[13];
349
+				$data['departure_airport_icao'] = $line[11];
350
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
351
+				$data['arrival_airport_icao'] = $line[13];
352 352
 			$data['frequency'] = $line[4];
353 353
 			$data['type'] = $line[18];
354 354
 			$data['range'] = $line[19];
355 355
 			if (isset($line[35])) $data['info'] = $line[35];
356
-    			$data['id_source'] = $id_source;
357
-	    		//$data['arrival_airport_time'] = ;
358
-	    		if ($line[9] != '') {
359
-	    		    $aircraft_data = explode('/',$line[9]);
360
-	    		    if (isset($aircraft_data[1])) {
361
-	    			$data['aircraft_icao'] = $aircraft_data[1];
362
-	    		    }
363
-        		}
364
-	    		/*
356
+				$data['id_source'] = $id_source;
357
+				//$data['arrival_airport_time'] = ;
358
+				if ($line[9] != '') {
359
+					$aircraft_data = explode('/',$line[9]);
360
+					if (isset($aircraft_data[1])) {
361
+					$data['aircraft_icao'] = $aircraft_data[1];
362
+					}
363
+				}
364
+				/*
365 365
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
366 366
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
367 367
 	    		*/
368
-	    		$data['format_source'] = $value['format'];
368
+				$data['format_source'] = $value['format'];
369 369
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
370
-    			if ($line[3] == 'PILOT') $SI->add($data);
370
+				if ($line[3] == 'PILOT') $SI->add($data);
371 371
 			elseif ($line[3] == 'ATC') {
372 372
 				//print_r($data);
373 373
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -385,212 +385,212 @@  discard block
 block discarded – undo
385 385
 				
386 386
 				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']);
387 387
 			}
388
-    			unset($data);
389
-    		    }
390
-    		}
391
-    	    }
392
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
393
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
394
-    	    $value['last_exec'] = time();
395
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
396
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
397
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
398
-	    if ($buffer != '') {
399
-	    $all_data = json_decode($buffer,true);
400
-	    if (isset($all_data['acList'])) {
388
+				unset($data);
389
+				}
390
+			}
391
+			}
392
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
393
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
394
+			$value['last_exec'] = time();
395
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
396
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
397
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
398
+		if ($buffer != '') {
399
+		$all_data = json_decode($buffer,true);
400
+		if (isset($all_data['acList'])) {
401 401
 		foreach ($all_data['acList'] as $line) {
402
-		    $data = array();
403
-		    $data['hex'] = $line['Icao']; // hex
404
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
405
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
406
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
407
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
408
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
409
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
410
-		    //$data['verticalrate'] = $line['']; // verticale rate
411
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
412
-		    $data['emergency'] = ''; // emergency
413
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
414
-		    /*
402
+			$data = array();
403
+			$data['hex'] = $line['Icao']; // hex
404
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
405
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
406
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
407
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
408
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
409
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
410
+			//$data['verticalrate'] = $line['']; // verticale rate
411
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
412
+			$data['emergency'] = ''; // emergency
413
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
414
+			/*
415 415
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
416 416
 		    else $data['datetime'] = date('Y-m-d H:i:s');
417 417
 		    */
418
-		    $data['datetime'] = date('Y-m-d H:i:s');
419
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
420
-	    	    $data['format_source'] = 'aircraftlistjson';
421
-		    $data['id_source'] = $id_source;
422
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
423
-		    if (isset($data['datetime'])) $SI->add($data);
424
-		    unset($data);
418
+			$data['datetime'] = date('Y-m-d H:i:s');
419
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
420
+				$data['format_source'] = 'aircraftlistjson';
421
+			$data['id_source'] = $id_source;
422
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
423
+			if (isset($data['datetime'])) $SI->add($data);
424
+			unset($data);
425 425
 		}
426
-	    } else {
426
+		} else {
427 427
 		foreach ($all_data as $line) {
428
-		    $data = array();
429
-		    $data['hex'] = $line['hex']; // hex
430
-		    $data['ident'] = $line['flight']; // ident
431
-		    $data['altitude'] = $line['altitude']; // altitude
432
-		    $data['speed'] = $line['speed']; // speed
433
-		    $data['heading'] = $line['track']; // heading
434
-		    $data['latitude'] = $line['lat']; // lat
435
-		    $data['longitude'] = $line['lon']; // long
436
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
437
-		    $data['squawk'] = $line['squawk']; // squawk
438
-		    $data['emergency'] = ''; // emergency
439
-		    $data['datetime'] = date('Y-m-d H:i:s');
440
-	    	    $data['format_source'] = 'aircraftlistjson';
441
-    		    $data['id_source'] = $id_source;
442
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
443
-		    $SI->add($data);
444
-		    unset($data);
428
+			$data = array();
429
+			$data['hex'] = $line['hex']; // hex
430
+			$data['ident'] = $line['flight']; // ident
431
+			$data['altitude'] = $line['altitude']; // altitude
432
+			$data['speed'] = $line['speed']; // speed
433
+			$data['heading'] = $line['track']; // heading
434
+			$data['latitude'] = $line['lat']; // lat
435
+			$data['longitude'] = $line['lon']; // long
436
+			$data['verticalrate'] = $line['vrt']; // verticale rate
437
+			$data['squawk'] = $line['squawk']; // squawk
438
+			$data['emergency'] = ''; // emergency
439
+			$data['datetime'] = date('Y-m-d H:i:s');
440
+				$data['format_source'] = 'aircraftlistjson';
441
+				$data['id_source'] = $id_source;
442
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
443
+			$SI->add($data);
444
+			unset($data);
445
+		}
445 446
 		}
446
-	    }
447
-	    }
448
-    	    //$last_exec['aircraftlistjson'] = time();
449
-    	    $value['last_exec'] = time();
450
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
451
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
452
-	    $buffer = $Common->getData($value['host']);
453
-	    $all_data = json_decode($buffer,true);
454
-	    if (isset($all_data['planes'])) {
447
+		}
448
+			//$last_exec['aircraftlistjson'] = time();
449
+			$value['last_exec'] = time();
450
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
451
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
452
+		$buffer = $Common->getData($value['host']);
453
+		$all_data = json_decode($buffer,true);
454
+		if (isset($all_data['planes'])) {
455 455
 		foreach ($all_data['planes'] as $key => $line) {
456
-		    $data = array();
457
-		    $data['hex'] = $key; // hex
458
-		    $data['ident'] = $line[3]; // ident
459
-		    $data['altitude'] = $line[6]; // altitude
460
-		    $data['speed'] = $line[8]; // speed
461
-		    $data['heading'] = $line[7]; // heading
462
-		    $data['latitude'] = $line[4]; // lat
463
-		    $data['longitude'] = $line[5]; // long
464
-		    //$data['verticalrate'] = $line[]; // verticale rate
465
-		    $data['squawk'] = $line[10]; // squawk
466
-		    $data['emergency'] = ''; // emergency
467
-		    $data['registration'] = $line[2];
468
-		    $data['aircraft_icao'] = $line[0];
469
-		    $deparr = explode('-',$line[1]);
470
-		    if (count($deparr) == 2) {
456
+			$data = array();
457
+			$data['hex'] = $key; // hex
458
+			$data['ident'] = $line[3]; // ident
459
+			$data['altitude'] = $line[6]; // altitude
460
+			$data['speed'] = $line[8]; // speed
461
+			$data['heading'] = $line[7]; // heading
462
+			$data['latitude'] = $line[4]; // lat
463
+			$data['longitude'] = $line[5]; // long
464
+			//$data['verticalrate'] = $line[]; // verticale rate
465
+			$data['squawk'] = $line[10]; // squawk
466
+			$data['emergency'] = ''; // emergency
467
+			$data['registration'] = $line[2];
468
+			$data['aircraft_icao'] = $line[0];
469
+			$deparr = explode('-',$line[1]);
470
+			if (count($deparr) == 2) {
471 471
 			$data['departure_airport_icao'] = $deparr[0];
472 472
 			$data['arrival_airport_icao'] = $deparr[1];
473
-		    }
474
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
475
-	    	    $data['format_source'] = 'planeupdatefaa';
476
-    		    $data['id_source'] = $id_source;
477
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
-		    $SI->add($data);
479
-		    unset($data);
473
+			}
474
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
475
+				$data['format_source'] = 'planeupdatefaa';
476
+				$data['id_source'] = $id_source;
477
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
+			$SI->add($data);
479
+			unset($data);
480
+		}
480 481
 		}
481
-	    }
482
-    	    //$last_exec['planeupdatefaa'] = time();
483
-    	    $value['last_exec'] = time();
484
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
485
-    	} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
486
-	    //$buffer = $Common->getData($hosts[$id]);
487
-	    $buffer = $Common->getData($value['host']);
488
-	    $all_data = json_decode($buffer,true);
489
-	    foreach ($all_data as $key => $line) {
482
+			//$last_exec['planeupdatefaa'] = time();
483
+			$value['last_exec'] = time();
484
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
485
+		} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
486
+		//$buffer = $Common->getData($hosts[$id]);
487
+		$buffer = $Common->getData($value['host']);
488
+		$all_data = json_decode($buffer,true);
489
+		foreach ($all_data as $key => $line) {
490 490
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
491
-		    $data = array();
492
-		    $data['hex'] = $line[0];
493
-		    $data['ident'] = $line[16]; //$line[13]
494
-	    	    $data['altitude'] = $line[4]; // altitude
495
-	    	    $data['speed'] = $line[5]; // speed
496
-	    	    $data['heading'] = $line[3]; // heading
497
-	    	    $data['latitude'] = $line[1]; // lat
498
-	    	    $data['longitude'] = $line[2]; // long
499
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
500
-	    	    $data['squawk'] = $line[6]; // squawk
501
-	    	    $data['aircraft_icao'] = $line[8];
502
-	    	    $data['registration'] = $line[9];
503
-		    $data['departure_airport_iata'] = $line[11];
504
-		    $data['arrival_airport_iata'] = $line[12];
505
-	    	    $data['emergency'] = ''; // emergency
506
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
507
-	    	    $data['format_source'] = 'fr24json';
508
-    		    $data['id_source'] = $id_source;
509
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
510
-		    $SI->add($data);
511
-		    unset($data);
491
+			$data = array();
492
+			$data['hex'] = $line[0];
493
+			$data['ident'] = $line[16]; //$line[13]
494
+				$data['altitude'] = $line[4]; // altitude
495
+				$data['speed'] = $line[5]; // speed
496
+				$data['heading'] = $line[3]; // heading
497
+				$data['latitude'] = $line[1]; // lat
498
+				$data['longitude'] = $line[2]; // long
499
+				$data['verticalrate'] = $line[15]; // verticale rate
500
+				$data['squawk'] = $line[6]; // squawk
501
+				$data['aircraft_icao'] = $line[8];
502
+				$data['registration'] = $line[9];
503
+			$data['departure_airport_iata'] = $line[11];
504
+			$data['arrival_airport_iata'] = $line[12];
505
+				$data['emergency'] = ''; // emergency
506
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
507
+				$data['format_source'] = 'fr24json';
508
+				$data['id_source'] = $id_source;
509
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
510
+			$SI->add($data);
511
+			unset($data);
512
+		}
512 513
 		}
513
-	    }
514
-    	    //$last_exec['fr24json'] = time();
515
-    	    $value['last_exec'] = time();
516
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
517
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
518
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
519
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
520
-	    //echo $buffer;
521
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
522
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
523
-	    $all_data = json_decode($buffer,true);
524
-	    if (json_last_error() != JSON_ERROR_NONE) {
514
+			//$last_exec['fr24json'] = time();
515
+			$value['last_exec'] = time();
516
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
517
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
518
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
519
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
520
+		//echo $buffer;
521
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
522
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
523
+		$all_data = json_decode($buffer,true);
524
+		if (json_last_error() != JSON_ERROR_NONE) {
525 525
 		die(json_last_error_msg());
526
-	    }
527
-	    if (isset($all_data['mrkrs'])) {
526
+		}
527
+		if (isset($all_data['mrkrs'])) {
528 528
 		foreach ($all_data['mrkrs'] as $key => $line) {
529
-		    if (isset($line['inf'])) {
529
+			if (isset($line['inf'])) {
530 530
 			$data = array();
531 531
 			$data['hex'] = $line['inf']['ia'];
532 532
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
533
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
534
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
535
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
536
-	    		$data['latitude'] = $line['pt'][0]; // lat
537
-	    		$data['longitude'] = $line['pt'][1]; // long
538
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
539
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
540
-	    		//$data['aircraft_icao'] = $line[8];
541
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
533
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
534
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
535
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
536
+				$data['latitude'] = $line['pt'][0]; // lat
537
+				$data['longitude'] = $line['pt'][1]; // long
538
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
539
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
540
+				//$data['aircraft_icao'] = $line[8];
541
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
542 542
 			//$data['departure_airport_iata'] = $line[11];
543 543
 			//$data['arrival_airport_iata'] = $line[12];
544
-	    		//$data['emergency'] = ''; // emergency
544
+				//$data['emergency'] = ''; // emergency
545 545
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
546
-	    		$data['format_source'] = 'radarvirtueljson';
547
-    			$data['id_source'] = $id_source;
546
+				$data['format_source'] = 'radarvirtueljson';
547
+				$data['id_source'] = $id_source;
548 548
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
549 549
 			$SI->add($data);
550 550
 			unset($data);
551
-		    }
551
+			}
552
+		}
552 553
 		}
553
-	    }
554
-    	    //$last_exec['radarvirtueljson'] = time();
555
-    	    $value['last_exec'] = time();
556
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
557
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
558
-	    //$buffer = $Common->getData($hosts[$id]);
559
-	    $buffer = $Common->getData($value['host']);
560
-	    $all_data = json_decode(utf8_encode($buffer),true);
554
+			//$last_exec['radarvirtueljson'] = time();
555
+			$value['last_exec'] = time();
556
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
557
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
558
+		//$buffer = $Common->getData($hosts[$id]);
559
+		$buffer = $Common->getData($value['host']);
560
+		$all_data = json_decode(utf8_encode($buffer),true);
561 561
 	    
562
-	    if (isset($all_data['pireps'])) {
563
-	        foreach ($all_data['pireps'] as $line) {
564
-		    $data = array();
565
-		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
566
-		    $data['ident'] = $line['callsign']; // ident
567
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
568
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
569
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
570
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
571
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
572
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
573
-		    $data['latitude'] = $line['lat']; // lat
574
-		    $data['longitude'] = $line['lon']; // long
575
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
576
-		    //$data['squawk'] = $line['squawk']; // squawk
577
-		    //$data['emergency'] = ''; // emergency
578
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
579
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
580
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
581
-		    //$data['arrival_airport_time'] = $line['arrtime'];
582
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
583
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
584
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
585
-		    else $data['info'] = '';
586
-		    $data['format_source'] = 'pireps';
587
-    		    $data['id_source'] = $id_source;
588
-		    $data['datetime'] = date('Y-m-d H:i:s');
589
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
590
-		    if ($line['icon'] == 'plane') {
562
+		if (isset($all_data['pireps'])) {
563
+			foreach ($all_data['pireps'] as $line) {
564
+			$data = array();
565
+			$data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
566
+			$data['ident'] = $line['callsign']; // ident
567
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
568
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
569
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
570
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
571
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
572
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
573
+			$data['latitude'] = $line['lat']; // lat
574
+			$data['longitude'] = $line['lon']; // long
575
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
576
+			//$data['squawk'] = $line['squawk']; // squawk
577
+			//$data['emergency'] = ''; // emergency
578
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
579
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
580
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
581
+			//$data['arrival_airport_time'] = $line['arrtime'];
582
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
583
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
584
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
585
+			else $data['info'] = '';
586
+			$data['format_source'] = 'pireps';
587
+				$data['id_source'] = $id_source;
588
+			$data['datetime'] = date('Y-m-d H:i:s');
589
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
590
+			if ($line['icon'] == 'plane') {
591 591
 			$SI->add($data);
592
-		    //    print_r($data);
593
-    		    } elseif ($line['icon'] == 'ct') {
592
+			//    print_r($data);
593
+				} elseif ($line['icon'] == 'ct') {
594 594
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
595 595
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
596 596
 			$typec = substr($data['ident'],-3);
@@ -605,103 +605,103 @@  discard block
 block discarded – undo
605 605
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
606 606
 			else $data['type'] = 'Observer';
607 607
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
608
-		    }
609
-		    unset($data);
608
+			}
609
+			unset($data);
610 610
 		}
611
-	    }
612
-    	    //$last_exec['pirepsjson'] = time();
613
-    	    $value['last_exec'] = time();
614
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
615
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
616
-	    //$buffer = $Common->getData($hosts[$id]);
617
-	    $buffer = $Common->getData($value['host']);
618
-	    $all_data = json_decode($buffer,true);
619
-	    if ($buffer != '' && is_array($all_data)) {
611
+		}
612
+			//$last_exec['pirepsjson'] = time();
613
+			$value['last_exec'] = time();
614
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
615
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
616
+		//$buffer = $Common->getData($hosts[$id]);
617
+		$buffer = $Common->getData($value['host']);
618
+		$all_data = json_decode($buffer,true);
619
+		if ($buffer != '' && is_array($all_data)) {
620 620
 		foreach ($all_data as $line) {
621
-	    	    $data = array();
622
-	    	    //$data['id'] = $line['id']; // id not usable
623
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
624
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
625
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
626
-	    	    $data['ident'] = $line['flightnum']; // ident
627
-	    	    $data['altitude'] = $line['alt']; // altitude
628
-	    	    $data['speed'] = $line['gs']; // speed
629
-	    	    $data['heading'] = $line['heading']; // heading
630
-	    	    $data['latitude'] = $line['lat']; // lat
631
-	    	    $data['longitude'] = $line['lng']; // long
632
-	    	    $data['verticalrate'] = ''; // verticale rate
633
-	    	    $data['squawk'] = ''; // squawk
634
-	    	    $data['emergency'] = ''; // emergency
635
-	    	    //$data['datetime'] = $line['lastupdate'];
636
-		    $data['datetime'] = date('Y-m-d H:i:s');
637
-	    	    $data['departure_airport_icao'] = $line['depicao'];
638
-	    	    $data['departure_airport_time'] = $line['deptime'];
639
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
640
-    		    $data['arrival_airport_time'] = $line['arrtime'];
641
-    		    $data['registration'] = $line['aircraft'];
642
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
643
-		    if (isset($line['aircraftname'])) {
621
+				$data = array();
622
+				//$data['id'] = $line['id']; // id not usable
623
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
624
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
625
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
626
+				$data['ident'] = $line['flightnum']; // ident
627
+				$data['altitude'] = $line['alt']; // altitude
628
+				$data['speed'] = $line['gs']; // speed
629
+				$data['heading'] = $line['heading']; // heading
630
+				$data['latitude'] = $line['lat']; // lat
631
+				$data['longitude'] = $line['lng']; // long
632
+				$data['verticalrate'] = ''; // verticale rate
633
+				$data['squawk'] = ''; // squawk
634
+				$data['emergency'] = ''; // emergency
635
+				//$data['datetime'] = $line['lastupdate'];
636
+			$data['datetime'] = date('Y-m-d H:i:s');
637
+				$data['departure_airport_icao'] = $line['depicao'];
638
+				$data['departure_airport_time'] = $line['deptime'];
639
+				$data['arrival_airport_icao'] = $line['arricao'];
640
+				$data['arrival_airport_time'] = $line['arrtime'];
641
+				$data['registration'] = $line['aircraft'];
642
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
643
+			if (isset($line['aircraftname'])) {
644 644
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
645 645
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
646
-	    		$aircraft_data = explode('-',$line['aircraftname']);
647
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
648
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
649
-	    		else {
650
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
651
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
652
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
653
-	    		}
654
-	    	    }
655
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
656
-    		    $data['id_source'] = $id_source;
657
-	    	    $data['format_source'] = 'phpvmacars';
658
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
659
-		    $SI->add($data);
660
-		    unset($data);
646
+				$aircraft_data = explode('-',$line['aircraftname']);
647
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
648
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
649
+				else {
650
+					$aircraft_data = explode(' ',$line['aircraftname']);
651
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
652
+					else $data['aircraft_icao'] = $line['aircraftname'];
653
+				}
654
+				}
655
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
656
+				$data['id_source'] = $id_source;
657
+				$data['format_source'] = 'phpvmacars';
658
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
659
+			$SI->add($data);
660
+			unset($data);
661 661
 		}
662
-	    }
663
-    	    //$last_exec['phpvmacars'] = time();
664
-    	    $value['last_exec'] = time();
662
+		}
663
+			//$last_exec['phpvmacars'] = time();
664
+			$value['last_exec'] = time();
665 665
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
666 666
 	} 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') {
667
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
668
-    	    $value['last_exec'] = time();
667
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
668
+			$value['last_exec'] = time();
669 669
 
670
-	    //$read = array( $sockets[$id] );
671
-	    $read = $sockets;
672
-	    $write = NULL;
673
-	    $e = NULL;
674
-	    $n = socket_select($read, $write, $e, $timeout);
675
-	    if ($e != NULL) var_dump($e);
676
-	    if ($n > 0) {
670
+		//$read = array( $sockets[$id] );
671
+		$read = $sockets;
672
+		$write = NULL;
673
+		$e = NULL;
674
+		$n = socket_select($read, $write, $e, $timeout);
675
+		if ($e != NULL) var_dump($e);
676
+		if ($n > 0) {
677 677
 		foreach ($read as $nb => $r) {
678
-		    //$value = $formats[$nb];
679
-		    $format = $globalSources[$nb]['format'];
680
-        	    //$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
681
-        	    $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
682
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
683
-        	    //echo $buffer."\n";
684
-		    // lets play nice and handle signals such as ctrl-c/kill properly
685
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
686
-		    $error = false;
687
-		    //$SI::del();
688
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
689
-		    // SBS format is CSV format
690
-		    if ($buffer != '') {
678
+			//$value = $formats[$nb];
679
+			$format = $globalSources[$nb]['format'];
680
+				//$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
681
+				$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
682
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
683
+				//echo $buffer."\n";
684
+			// lets play nice and handle signals such as ctrl-c/kill properly
685
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
686
+			$error = false;
687
+			//$SI::del();
688
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
689
+			// SBS format is CSV format
690
+			if ($buffer != '') {
691 691
 			$tt['format'] = 0;
692 692
 			if ($format == 'raw') {
693
-			    // AVR format
694
-			    $data = $SBS->parse($buffer);
695
-			    if (is_array($data)) {
693
+				// AVR format
694
+				$data = $SBS->parse($buffer);
695
+				if (is_array($data)) {
696 696
 				$data['datetime'] = date('Y-m-d H:i:s');
697 697
 				$data['format_source'] = 'raw';
698 698
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
699
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
700
-                                $SI->add($data);
701
-                            }
702
-                        } elseif ($format == 'flightgearsp') {
703
-                    	    //echo $buffer."\n";
704
-                    	    if (strlen($buffer) > 5) {
699
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
700
+								$SI->add($data);
701
+							}
702
+						} elseif ($format == 'flightgearsp') {
703
+							//echo $buffer."\n";
704
+							if (strlen($buffer) > 5) {
705 705
 				$line = explode(',',$buffer);
706 706
 				$data = array();
707 707
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -717,112 +717,112 @@  discard block
 block discarded – undo
717 717
 				$data['format_source'] = 'flightgearsp';
718 718
 				$SI->add($data);
719 719
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
720
-			    }
721
-                        } elseif ($format == 'acars') {
722
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
723
-			    $ACARS->add(trim($buffer));
724
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
725
-			    $ACARS->deleteLiveAcarsData();
720
+				}
721
+						} elseif ($format == 'acars') {
722
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
723
+				$ACARS->add(trim($buffer));
724
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
725
+				$ACARS->deleteLiveAcarsData();
726 726
 			} elseif ($format == 'flightgearmp') {
727
-			    if (substr($buffer,0,1) != '#') {
727
+				if (substr($buffer,0,1) != '#') {
728 728
 				$data = array();
729 729
 				//echo $buffer."\n";
730 730
 				$line = explode(' ',$buffer);
731 731
 				if (count($line) == 11) {
732
-				    $userserver = explode('@',$line[0]);
733
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
734
-				    $data['ident'] = $userserver[0];
735
-				    $data['registration'] = $userserver[0];
736
-				    $data['latitude'] = $line[4];
737
-				    $data['longitude'] = $line[5];
738
-				    $data['altitude'] = $line[6];
739
-				    $data['datetime'] = date('Y-m-d H:i:s');
740
-				    $aircraft_type = $line[10];
741
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
742
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
743
-				    $SI->add($data);
732
+					$userserver = explode('@',$line[0]);
733
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
734
+					$data['ident'] = $userserver[0];
735
+					$data['registration'] = $userserver[0];
736
+					$data['latitude'] = $line[4];
737
+					$data['longitude'] = $line[5];
738
+					$data['altitude'] = $line[6];
739
+					$data['datetime'] = date('Y-m-d H:i:s');
740
+					$aircraft_type = $line[10];
741
+					$aircraft_type = preg_split(':/:',$aircraft_type);
742
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
743
+					$SI->add($data);
744
+				}
744 745
 				}
745
-			    }
746 746
 			} elseif ($format == 'beast') {
747
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
748
-			    die;
747
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
748
+				die;
749 749
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
750
-			    $line = explode("\t", $buffer);
751
-			    for($k = 0; $k < count($line); $k=$k+2) {
750
+				$line = explode("\t", $buffer);
751
+				for($k = 0; $k < count($line); $k=$k+2) {
752 752
 				$key = $line[$k];
753
-			        $lined[$key] = $line[$k+1];
754
-			    }
755
-    			    if (count($lined) > 3) {
756
-    				$data['hex'] = $lined['hexid'];
757
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
758
-    				$data['datetime'] = date('Y-m-d H:i:s');;
759
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
760
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
761
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
762
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
763
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
764
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
765
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
766
-    				$data['id_source'] = $id_source;
767
-    				$data['format_source'] = 'tsv';
768
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
769
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
770
-    				$SI->add($data);
771
-    				unset($lined);
772
-    				unset($data);
773
-    			    } else $error = true;
753
+					$lined[$key] = $line[$k+1];
754
+				}
755
+					if (count($lined) > 3) {
756
+					$data['hex'] = $lined['hexid'];
757
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
758
+					$data['datetime'] = date('Y-m-d H:i:s');;
759
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
760
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
761
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
762
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
763
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
764
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
765
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
766
+					$data['id_source'] = $id_source;
767
+					$data['format_source'] = 'tsv';
768
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
769
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
770
+					$SI->add($data);
771
+					unset($lined);
772
+					unset($data);
773
+					} else $error = true;
774 774
 			} elseif ($format == 'aprs' && $use_aprs) {
775
-			    if ($aprs_connect == 0) {
775
+				if ($aprs_connect == 0) {
776 776
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
777 777
 				$aprs_connect = 1;
778
-			    }
779
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
778
+				}
779
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
780 780
 				$aprs_last_tx = time();
781 781
 				$data_aprs = "# Keep alive";
782 782
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
783
-			    }
784
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
785
-			    if (substr($buffer,0,1) != '#') {
783
+				}
784
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
785
+				if (substr($buffer,0,1) != '#') {
786 786
 				$line = $APRS->parse($buffer);
787 787
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
788
-				    $data = array();
789
-				    //print_r($line);
790
-				    $data['hex'] = $line['address'];
791
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
792
-				    //$data['datetime'] = date('Y-m-d H:i:s');
793
-				    $data['ident'] = $line['ident'];
794
-				    $data['latitude'] = $line['latitude'];
795
-				    $data['longitude'] = $line['longitude'];
796
-				    //$data['verticalrate'] = $line[16];
797
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
798
-				    else $data['speed'] = 0;
799
-				    $data['altitude'] = $line['altitude'];
800
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
801
-				    //else $data['heading'] = 0;
802
-				    $data['aircraft_type'] = $line['stealth'];
803
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
804
-    				    $data['id_source'] = $id_source;
805
-				    $data['format_source'] = 'aprs';
806
-				    $data['source_name'] = $line['source'];
807
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
808
-				    $currentdate = date('Y-m-d H:i:s');
809
-				    $aprsdate = strtotime($data['datetime']);
810
-				    // Accept data if time <= system time + 20s
811
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
812
-				    else {
788
+					$data = array();
789
+					//print_r($line);
790
+					$data['hex'] = $line['address'];
791
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
792
+					//$data['datetime'] = date('Y-m-d H:i:s');
793
+					$data['ident'] = $line['ident'];
794
+					$data['latitude'] = $line['latitude'];
795
+					$data['longitude'] = $line['longitude'];
796
+					//$data['verticalrate'] = $line[16];
797
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
798
+					else $data['speed'] = 0;
799
+					$data['altitude'] = $line['altitude'];
800
+					if (isset($line['course'])) $data['heading'] = $line['course'];
801
+					//else $data['heading'] = 0;
802
+					$data['aircraft_type'] = $line['stealth'];
803
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
804
+						$data['id_source'] = $id_source;
805
+					$data['format_source'] = 'aprs';
806
+					$data['source_name'] = $line['source'];
807
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
808
+					$currentdate = date('Y-m-d H:i:s');
809
+					$aprsdate = strtotime($data['datetime']);
810
+					// Accept data if time <= system time + 20s
811
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
812
+					else {
813 813
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
814 814
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
815
-				    }
816
-				    unset($data);
815
+					}
816
+					unset($data);
817 817
 				} 
818 818
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
819 819
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
820
-			    }
820
+				}
821 821
 			} else {
822
-			    $line = explode(',', $buffer);
823
-    			    if (count($line) > 20) {
824
-    			    	$data['hex'] = $line[4];
825
-    				/*
822
+				$line = explode(',', $buffer);
823
+					if (count($line) > 20) {
824
+						$data['hex'] = $line[4];
825
+					/*
826 826
     				$data['datetime'] = $line[6].' '.$line[7];
827 827
     					date_default_timezone_set($globalTimezone);
828 828
     					$datetime = new DateTime($data['datetime']);
@@ -830,27 +830,27 @@  discard block
 block discarded – undo
830 830
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
831 831
     					date_default_timezone_set('UTC');
832 832
     				*/
833
-    				// Force datetime to current UTC datetime
834
-    				$data['datetime'] = date('Y-m-d H:i:s');
835
-    				$data['ident'] = trim($line[10]);
836
-    				$data['latitude'] = $line[14];
837
-    				$data['longitude'] = $line[15];
838
-    				$data['verticalrate'] = $line[16];
839
-    				$data['emergency'] = $line[20];
840
-    				$data['speed'] = $line[12];
841
-    				$data['squawk'] = $line[17];
842
-    				$data['altitude'] = $line[11];
843
-    				$data['heading'] = $line[13];
844
-    				$data['ground'] = $line[21];
845
-    				$data['emergency'] = $line[19];
846
-    				$data['format_source'] = 'sbs';
833
+					// Force datetime to current UTC datetime
834
+					$data['datetime'] = date('Y-m-d H:i:s');
835
+					$data['ident'] = trim($line[10]);
836
+					$data['latitude'] = $line[14];
837
+					$data['longitude'] = $line[15];
838
+					$data['verticalrate'] = $line[16];
839
+					$data['emergency'] = $line[20];
840
+					$data['speed'] = $line[12];
841
+					$data['squawk'] = $line[17];
842
+					$data['altitude'] = $line[11];
843
+					$data['heading'] = $line[13];
844
+					$data['ground'] = $line[21];
845
+					$data['emergency'] = $line[19];
846
+					$data['format_source'] = 'sbs';
847 847
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
848
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
-    				$data['id_source'] = $id_source;
850
-    				$send = $SI->add($data);
851
-    				unset($data);
852
-    			    } else $error = true;
853
-			    if ($error) {
848
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
+					$data['id_source'] = $id_source;
850
+					$send = $SI->add($data);
851
+					unset($data);
852
+					} else $error = true;
853
+				if ($error) {
854 854
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
855 855
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
856 856
 				} else {
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
 					connect_all($sourceer);
867 867
 					$sourceer = array();
868 868
 				}
869
-			    }
869
+				}
870 870
 			}
871 871
 			// Sleep for xxx microseconds
872 872
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
873
-		    } else {
873
+			} else {
874 874
 			if ($format == 'flightgearmp') {
875
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
875
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
876 876
 				//@socket_close($r);
877 877
 				sleep($globalMinFetch);
878 878
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -881,9 +881,9 @@  discard block
 block discarded – undo
881 881
 				break;
882 882
 				
883 883
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
884
-			    if (isset($tt[$format])) $tt[$format]++;
885
-			    else $tt[$format] = 0;
886
-			    if ($tt[$format] > 30) {
884
+				if (isset($tt[$format])) $tt[$format]++;
885
+				else $tt[$format] = 0;
886
+				if ($tt[$format] > 30) {
887 887
 				if ($globalDebug)echo "ERROR : Reconnect ".$format."...";
888 888
 				//@socket_close($r);
889 889
 				sleep(2);
@@ -894,39 +894,39 @@  discard block
 block discarded – undo
894 894
 				//connect_all($globalSources);
895 895
 				$tt[$format]=0;
896 896
 				break;
897
-			    }
897
+				}
898
+			}
898 899
 			}
899
-		    }
900 900
 		}
901
-	    } else {
901
+		} else {
902 902
 		$error = socket_strerror(socket_last_error());
903 903
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
904 904
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
905 905
 			if (isset($globalDebug)) echo "Restarting...\n";
906 906
 			// Restart the script if possible
907 907
 			if (is_array($sockets)) {
908
-			    if ($globalDebug) echo "Shutdown all sockets...";
908
+				if ($globalDebug) echo "Shutdown all sockets...";
909 909
 			    
910
-			    foreach ($sockets as $sock) {
910
+				foreach ($sockets as $sock) {
911 911
 				@socket_shutdown($sock,2);
912 912
 				@socket_close($sock);
913
-			    }
913
+				}
914 914
 			    
915 915
 			}
916
-			    if ($globalDebug) echo "Restart all connections...";
917
-			    sleep(2);
918
-			    $time = time();
919
-			    //connect_all($hosts);
920
-			    $aprs_connect = 0;
921
-			    connect_all($globalSources);
916
+				if ($globalDebug) echo "Restart all connections...";
917
+				sleep(2);
918
+				$time = time();
919
+				//connect_all($hosts);
920
+				$aprs_connect = 0;
921
+				connect_all($globalSources);
922 922
 
923 923
 		}
924
-	    }
924
+		}
925 925
 	}
926 926
 	if ($globalDaemon == false) {
927
-	    $SI->checkAll();
927
+		$SI->checkAll();
928
+	}
928 929
 	}
929
-    }
930 930
 }
931 931
 
932 932
 ?>
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     }
42 42
 }
43 43
 
44
-$options = getopt('s::',array('source::','server','idsource::'));
44
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
45 45
 //if (isset($options['s'])) $hosts = array($options['s']);
46 46
 //elseif (isset($options['source'])) $hosts = array($options['source']);
47 47
 if (isset($options['s'])) $globalSources[] = array('host' => $options['s']);
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
 else $id_source = 1;
52 52
 if (isset($globalServer) && $globalServer) {
53 53
     if ($globalDebug) echo "Using Server Mode\n";
54
-    $SI=new SpotterServer();
55
-} else $SI=new SpotterImport($Connection->db);
54
+    $SI = new SpotterServer();
55
+} else $SI = new SpotterImport($Connection->db);
56 56
 //$APRS=new APRS($Connection->db);
57
-$SBS=new SBS($Connection->db);
58
-$ACARS=new ACARS($Connection->db);
59
-$Common=new Common();
57
+$SBS = new SBS($Connection->db);
58
+$ACARS = new ACARS($Connection->db);
59
+$Common = new Common();
60 60
 date_default_timezone_set('UTC');
61 61
 //$servertz = system('date +%Z');
62 62
 // signal handler - playing nice with sockets and dump1090
63 63
 if (function_exists('pcntl_fork')) {
64
-    pcntl_signal(SIGINT,  function($signo) {
64
+    pcntl_signal(SIGINT, function($signo) {
65 65
         global $sockets;
66 66
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
67 67
         die("Bye!\n");
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
 
104 104
 function connect_all($hosts) {
105 105
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
106
+    global $sockets, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs;
107 107
     foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
111
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
+            if (preg_match('/deltadb.txt$/i', $host)) {
113 113
         	//$formats[$id] = 'deltadbtxt';
114 114
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 115
         	//$last_exec['deltadbtxt'] = 0;
116 116
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
118 118
         	//$formats[$id] = 'vatsimtxt';
119 119
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 120
         	//$last_exec['vatsimtxt'] = 0;
121 121
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
123 123
         	//$formats[$id] = 'aircraftlistjson';
124 124
         	$$globalSources[$id]['format'] = 'aircraftlistjson';
125 125
         	//$last_exec['aircraftlistjson'] = 0;
126 126
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
127
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
128 128
         	//$formats[$id] = 'radarvirtueljson';
129 129
         	$globalSources[$id]['format'] = 'radarvirtueljson';
130 130
         	//$last_exec['radarvirtueljson'] = 0;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
134 134
         	    exit(0);
135 135
         	}
136
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
136
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
137 137
         	//$formats[$id] = 'planeupdatefaa';
138 138
         	$globalSources[$id]['format'] = 'planeupdatefaa';
139 139
         	//$last_exec['planeupdatefaa'] = 0;
@@ -142,22 +142,22 @@  discard block
 block discarded – undo
142 142
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
143 143
         	    exit(0);
144 144
         	}
145
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
145
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
146 146
         	//$formats[$id] = 'phpvmacars';
147 147
         	$globalSources[$id]['format'] = 'phpvmacars';
148 148
         	//$last_exec['phpvmacars'] = 0;
149 149
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
150
-            } else if (preg_match('/whazzup/i',$host)) {
150
+            } else if (preg_match('/whazzup/i', $host)) {
151 151
         	//$formats[$id] = 'whazzup';
152 152
         	$globalSources[$id]['format'] = 'whazzup';
153 153
         	//$last_exec['whazzup'] = 0;
154 154
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
155
-            } else if (preg_match('/recentpireps/i',$host)) {
155
+            } else if (preg_match('/recentpireps/i', $host)) {
156 156
         	//$formats[$id] = 'pirepsjson';
157 157
         	$globalSources[$id]['format'] = 'pirepsjson';
158 158
         	//$last_exec['pirepsjson'] = 0;
159 159
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
160
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
160
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
161 161
         	//$formats[$id] = 'fr24json';
162 162
         	$globalSources[$id]['format'] = 'fr24json';
163 163
         	//$last_exec['fr24json'] = 0;
@@ -167,26 +167,26 @@  discard block
 block discarded – undo
167 167
         	    exit(0);
168 168
         	}
169 169
             //} else if (preg_match('/10001/',$host)) {
170
-            } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
170
+            } else if (preg_match('/10001/', $host) || $globalSources[$id]['port'] == '10001') {
171 171
         	//$formats[$id] = 'tsv';
172 172
         	$globalSources[$id]['format'] = 'tsv';
173 173
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
174 174
             }
175
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
175
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
176 176
         	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
177
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
178
-	    $hostport = explode(':',$host);
177
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
178
+	    $hostport = explode(':', $host);
179 179
 	    if (isset($hostport[1])) $port = $hostport[1];
180 180
 	    else $port = $globalSources[$id]['port'];
181 181
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
182
-        	$s = create_socket($host,$port, $errno, $errstr);
182
+        	$s = create_socket($host, $port, $errno, $errstr);
183 183
     	    } else {
184
-        	$s = create_socket_udp($host,$port, $errno, $errstr);
184
+        	$s = create_socket_udp($host, $port, $errno, $errstr);
185 185
 	    }
186 186
 	    if ($s) {
187 187
     	        $sockets[$id] = $s;
188 188
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
189
-		    if (preg_match('/aprs/',$host)) {
189
+		    if (preg_match('/aprs/', $host)) {
190 190
 			//$formats[$id] = 'aprs';
191 191
 			$globalSources[$id]['format'] = 'aprs';
192 192
 			//$aprs_connect = 0;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
228 228
 else $timeout = 20;
229 229
 $errno = '';
230
-$errstr='';
230
+$errstr = '';
231 231
 
232 232
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
233 233
 /* Initiate connections to all the hosts simultaneously */
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 
248 248
 if ($use_aprs) {
249 249
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
250
-	$APRS=new APRS($Connection->db);
250
+	$APRS = new APRS($Connection->db);
251 251
 	$aprs_connect = 0;
252 252
 	$aprs_keep = 120;
253 253
 	$aprs_last_tx = time();
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	else $aprs_ssid = 'FAM';
259 259
 	//else $aprs_ssid = 'PerlEx';
260 260
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
261
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
261
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
262 262
 	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
263 263
 	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
264 264
 }
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 sleep(1);
269 269
 if ($globalDebug) echo "SCAN MODE \n\n";
270 270
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
271
-$endtime = time()+$globalCronEnd;
271
+$endtime = time() + $globalCronEnd;
272 272
 $i = 1;
273 273
 $tt = array();
274 274
 // Delete all ATC
275 275
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
276
-	$ATC=new ATC($Connection->db);
276
+	$ATC = new ATC($Connection->db);
277 277
 }
278 278
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
279 279
 	$ATC->deleteAll();
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
283 283
 while ($i > 0) {
284
-    if (!$globalDaemon) $i = $endtime-time();
284
+    if (!$globalDaemon) $i = $endtime - time();
285 285
     // Delete old ATC
286 286
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
287 287
         $ATC->deleteOldATC();
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	if ($value['format'] == 'deltadbtxt' && (time() - $value['last_exec'] > $globalMinFetch)) {
293 293
 	    //$buffer = $Common->getData($hosts[$id]);
294 294
 	    $buffer = $Common->getData($value['host']);
295
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
296
-	    $buffer = explode('\n',$buffer);
295
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
296
+	    $buffer = explode('\n', $buffer);
297 297
 	    foreach ($buffer as $line) {
298 298
     		if ($line != '') {
299 299
     		    $line = explode(',', $line);
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 	} elseif (($value['format'] == 'whazzup' && (time() - $value['last_exec'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $value['last_exec'] > $globalMinFetch))) {
323 323
 	    //$buffer = $Common->getData($hosts[$id]);
324 324
 	    $buffer = $Common->getData($value['host']);
325
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
326
-	    $buffer = explode('\n',$buffer);
325
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
326
+	    $buffer = explode('\n', $buffer);
327 327
 	    foreach ($buffer as $line) {
328 328
     		if ($line != '') {
329 329
     		    $line = explode(':', $line);
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 			$data['id'] = $line[1].'-'.$line[0];
333 333
 			$data['pilot_id'] = $line[1];
334 334
 			$data['pilot_name'] = $line[2];
335
-			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
335
+			$data['hex'] = str_pad(dechex($line[1]), 6, '000000', STR_PAD_LEFT);
336 336
 			$data['ident'] = $line[0]; // ident
337 337
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
338 338
 			$data['speed'] = $line[8]; // speed
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			$data['datetime'] = date('Y-m-d H:i:s');
348 348
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
349 349
 		        $data['departure_airport_icao'] = $line[11];
350
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
350
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
351 351
 		        $data['arrival_airport_icao'] = $line[13];
352 352
 			$data['frequency'] = $line[4];
353 353
 			$data['type'] = $line[18];
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
     			$data['id_source'] = $id_source;
357 357
 	    		//$data['arrival_airport_time'] = ;
358 358
 	    		if ($line[9] != '') {
359
-	    		    $aircraft_data = explode('/',$line[9]);
359
+	    		    $aircraft_data = explode('/', $line[9]);
360 360
 	    		    if (isset($aircraft_data[1])) {
361 361
 	    			$data['aircraft_icao'] = $aircraft_data[1];
362 362
 	    		    }
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
     			if ($line[3] == 'PILOT') $SI->add($data);
371 371
 			elseif ($line[3] == 'ATC') {
372 372
 				//print_r($data);
373
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
374
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
375
-				$typec = substr($data['ident'],-3);
373
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
374
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
375
+				$typec = substr($data['ident'], -3);
376 376
 				if ($typec == 'APP') $data['type'] = 'Approach';
377 377
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
378 378
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
384 384
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
385 385
 				
386
-				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']);
386
+				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']);
387 387
 			}
388 388
     			unset($data);
389 389
     		    }
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
     	    $value['last_exec'] = time();
395 395
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
396 396
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
397
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
397
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
398 398
 	    if ($buffer != '') {
399
-	    $all_data = json_decode($buffer,true);
399
+	    $all_data = json_decode($buffer, true);
400 400
 	    if (isset($all_data['acList'])) {
401 401
 		foreach ($all_data['acList'] as $line) {
402 402
 		    $data = array();
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
451 451
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
452 452
 	    $buffer = $Common->getData($value['host']);
453
-	    $all_data = json_decode($buffer,true);
453
+	    $all_data = json_decode($buffer, true);
454 454
 	    if (isset($all_data['planes'])) {
455 455
 		foreach ($all_data['planes'] as $key => $line) {
456 456
 		    $data = array();
@@ -466,12 +466,12 @@  discard block
 block discarded – undo
466 466
 		    $data['emergency'] = ''; // emergency
467 467
 		    $data['registration'] = $line[2];
468 468
 		    $data['aircraft_icao'] = $line[0];
469
-		    $deparr = explode('-',$line[1]);
469
+		    $deparr = explode('-', $line[1]);
470 470
 		    if (count($deparr) == 2) {
471 471
 			$data['departure_airport_icao'] = $deparr[0];
472 472
 			$data['arrival_airport_icao'] = $deparr[1];
473 473
 		    }
474
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
474
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
475 475
 	    	    $data['format_source'] = 'planeupdatefaa';
476 476
     		    $data['id_source'] = $id_source;
477 477
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
     	} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
486 486
 	    //$buffer = $Common->getData($hosts[$id]);
487 487
 	    $buffer = $Common->getData($value['host']);
488
-	    $all_data = json_decode($buffer,true);
488
+	    $all_data = json_decode($buffer, true);
489 489
 	    foreach ($all_data as $key => $line) {
490 490
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
491 491
 		    $data = array();
@@ -516,11 +516,11 @@  discard block
 block discarded – undo
516 516
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
517 517
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
518 518
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
519
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
519
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
520 520
 	    //echo $buffer;
521
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
522
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
523
-	    $all_data = json_decode($buffer,true);
521
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
522
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
523
+	    $all_data = json_decode($buffer, true);
524 524
 	    if (json_last_error() != JSON_ERROR_NONE) {
525 525
 		die(json_last_error_msg());
526 526
 	    }
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 			//$data['departure_airport_iata'] = $line[11];
543 543
 			//$data['arrival_airport_iata'] = $line[12];
544 544
 	    		//$data['emergency'] = ''; // emergency
545
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
545
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
546 546
 	    		$data['format_source'] = 'radarvirtueljson';
547 547
     			$data['id_source'] = $id_source;
548 548
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -557,12 +557,12 @@  discard block
 block discarded – undo
557 557
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
558 558
 	    //$buffer = $Common->getData($hosts[$id]);
559 559
 	    $buffer = $Common->getData($value['host']);
560
-	    $all_data = json_decode(utf8_encode($buffer),true);
560
+	    $all_data = json_decode(utf8_encode($buffer), true);
561 561
 	    
562 562
 	    if (isset($all_data['pireps'])) {
563 563
 	        foreach ($all_data['pireps'] as $line) {
564 564
 		    $data = array();
565
-		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
565
+		    $data['hex'] = str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT);
566 566
 		    $data['ident'] = $line['callsign']; // ident
567 567
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
568 568
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
 			$SI->add($data);
592 592
 		    //    print_r($data);
593 593
     		    } elseif ($line['icon'] == 'ct') {
594
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
595
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
596
-			$typec = substr($data['ident'],-3);
594
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
595
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
596
+			$typec = substr($data['ident'], -3);
597 597
 			$data['type'] = '';
598 598
 			if ($typec == 'APP') $data['type'] = 'Approach';
599 599
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
605 605
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
606 606
 			else $data['type'] = 'Observer';
607
-			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
607
+			echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name']);
608 608
 		    }
609 609
 		    unset($data);
610 610
 		}
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
616 616
 	    //$buffer = $Common->getData($hosts[$id]);
617 617
 	    $buffer = $Common->getData($value['host']);
618
-	    $all_data = json_decode($buffer,true);
618
+	    $all_data = json_decode($buffer, true);
619 619
 	    if ($buffer != '' && is_array($all_data)) {
620 620
 		foreach ($all_data as $line) {
621 621
 	    	    $data = array();
622 622
 	    	    //$data['id'] = $line['id']; // id not usable
623
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
623
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
624 624
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
625 625
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
626 626
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -642,12 +642,12 @@  discard block
 block discarded – undo
642 642
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
643 643
 		    if (isset($line['aircraftname'])) {
644 644
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
645
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
646
-	    		$aircraft_data = explode('-',$line['aircraftname']);
645
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
646
+	    		$aircraft_data = explode('-', $line['aircraftname']);
647 647
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
648 648
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
649 649
 	    		else {
650
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
650
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
651 651
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
652 652
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
653 653
 	    		}
@@ -678,14 +678,14 @@  discard block
 block discarded – undo
678 678
 		    //$value = $formats[$nb];
679 679
 		    $format = $globalSources[$nb]['format'];
680 680
         	    //$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
681
-        	    $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
681
+        	    $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
682 682
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
683 683
         	    //echo $buffer."\n";
684 684
 		    // lets play nice and handle signals such as ctrl-c/kill properly
685 685
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
686 686
 		    $error = false;
687 687
 		    //$SI::del();
688
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
688
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
689 689
 		    // SBS format is CSV format
690 690
 		    if ($buffer != '') {
691 691
 			$tt['format'] = 0;
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
                         } elseif ($format == 'flightgearsp') {
703 703
                     	    //echo $buffer."\n";
704 704
                     	    if (strlen($buffer) > 5) {
705
-				$line = explode(',',$buffer);
705
+				$line = explode(',', $buffer);
706 706
 				$data = array();
707 707
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
708
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
708
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
709 709
 				$data['ident'] = $line[6];
710 710
 				$data['aircraft_name'] = $line[7];
711 711
 				$data['longitude'] = $line[1];
@@ -716,21 +716,21 @@  discard block
 block discarded – undo
716 716
 				$data['datetime'] = date('Y-m-d H:i:s');
717 717
 				$data['format_source'] = 'flightgearsp';
718 718
 				$SI->add($data);
719
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
719
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
720 720
 			    }
721 721
                         } elseif ($format == 'acars') {
722 722
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
723 723
 			    $ACARS->add(trim($buffer));
724
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
724
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
725 725
 			    $ACARS->deleteLiveAcarsData();
726 726
 			} elseif ($format == 'flightgearmp') {
727
-			    if (substr($buffer,0,1) != '#') {
727
+			    if (substr($buffer, 0, 1) != '#') {
728 728
 				$data = array();
729 729
 				//echo $buffer."\n";
730
-				$line = explode(' ',$buffer);
730
+				$line = explode(' ', $buffer);
731 731
 				if (count($line) == 11) {
732
-				    $userserver = explode('@',$line[0]);
733
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
732
+				    $userserver = explode('@', $line[0]);
733
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
734 734
 				    $data['ident'] = $userserver[0];
735 735
 				    $data['registration'] = $userserver[0];
736 736
 				    $data['latitude'] = $line[4];
@@ -738,24 +738,24 @@  discard block
 block discarded – undo
738 738
 				    $data['altitude'] = $line[6];
739 739
 				    $data['datetime'] = date('Y-m-d H:i:s');
740 740
 				    $aircraft_type = $line[10];
741
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
742
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
741
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
742
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
743 743
 				    $SI->add($data);
744 744
 				}
745 745
 			    }
746 746
 			} elseif ($format == 'beast') {
747 747
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
748 748
 			    die;
749
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
749
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
750 750
 			    $line = explode("\t", $buffer);
751
-			    for($k = 0; $k < count($line); $k=$k+2) {
751
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
752 752
 				$key = $line[$k];
753
-			        $lined[$key] = $line[$k+1];
753
+			        $lined[$key] = $line[$k + 1];
754 754
 			    }
755 755
     			    if (count($lined) > 3) {
756 756
     				$data['hex'] = $lined['hexid'];
757 757
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
758
-    				$data['datetime'] = date('Y-m-d H:i:s');;
758
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
759 759
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
760 760
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
761 761
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -773,22 +773,22 @@  discard block
 block discarded – undo
773 773
     			    } else $error = true;
774 774
 			} elseif ($format == 'aprs' && $use_aprs) {
775 775
 			    if ($aprs_connect == 0) {
776
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
776
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
777 777
 				$aprs_connect = 1;
778 778
 			    }
779
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
779
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
780 780
 				$aprs_last_tx = time();
781 781
 				$data_aprs = "# Keep alive";
782
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
782
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
783 783
 			    }
784 784
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
785
-			    if (substr($buffer,0,1) != '#') {
785
+			    if (substr($buffer, 0, 1) != '#') {
786 786
 				$line = $APRS->parse($buffer);
787 787
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
788 788
 				    $data = array();
789 789
 				    //print_r($line);
790 790
 				    $data['hex'] = $line['address'];
791
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
791
+				    $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
792 792
 				    //$data['datetime'] = date('Y-m-d H:i:s');
793 793
 				    $data['ident'] = $line['ident'];
794 794
 				    $data['latitude'] = $line['latitude'];
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 				    $currentdate = date('Y-m-d H:i:s');
809 809
 				    $aprsdate = strtotime($data['datetime']);
810 810
 				    // Accept data if time <= system time + 20s
811
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
811
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate) + 20)) $send = $SI->add($data);
812 812
 				    else {
813 813
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
814 814
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 				connect_all($sourceee);
893 893
 				$sourceee = array();
894 894
 				//connect_all($globalSources);
895
-				$tt[$format]=0;
895
+				$tt[$format] = 0;
896 896
 				break;
897 897
 			    }
898 898
 			}
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 		}
901 901
 	    } else {
902 902
 		$error = socket_strerror(socket_last_error());
903
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
903
+		if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
904 904
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
905 905
 			if (isset($globalDebug)) echo "Restarting...\n";
906 906
 			// Restart the script if possible
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
 			    if ($globalDebug) echo "Shutdown all sockets...";
909 909
 			    
910 910
 			    foreach ($sockets as $sock) {
911
-				@socket_shutdown($sock,2);
911
+				@socket_shutdown($sock, 2);
912 912
 				@socket_close($sock);
913 913
 			    }
914 914
 			    
Please login to merge, or discard this patch.
Braces   +447 added lines, -156 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 
17
-if (!isset($globalDebug)) $globalDebug = FALSE;
17
+if (!isset($globalDebug)) {
18
+	$globalDebug = FALSE;
19
+}
18 20
 
19 21
 // Check if schema is at latest version
20 22
 $Connection = new Connection();
@@ -44,15 +46,27 @@  discard block
 block discarded – undo
44 46
 $options = getopt('s::',array('source::','server','idsource::'));
45 47
 //if (isset($options['s'])) $hosts = array($options['s']);
46 48
 //elseif (isset($options['source'])) $hosts = array($options['source']);
47
-if (isset($options['s'])) $globalSources[] = array('host' => $options['s']);
48
-elseif (isset($options['source'])) $globalSources[] = array('host' => $options['source']);
49
-if (isset($options['server'])) $globalServer = TRUE;
50
-if (isset($options['idsource'])) $id_source = $options['idsource'];
51
-else $id_source = 1;
49
+if (isset($options['s'])) {
50
+	$globalSources[] = array('host' => $options['s']);
51
+} elseif (isset($options['source'])) {
52
+	$globalSources[] = array('host' => $options['source']);
53
+}
54
+if (isset($options['server'])) {
55
+	$globalServer = TRUE;
56
+}
57
+if (isset($options['idsource'])) {
58
+	$id_source = $options['idsource'];
59
+} else {
60
+	$id_source = 1;
61
+}
52 62
 if (isset($globalServer) && $globalServer) {
53
-    if ($globalDebug) echo "Using Server Mode\n";
63
+    if ($globalDebug) {
64
+    	echo "Using Server Mode\n";
65
+    }
54 66
     $SI=new SpotterServer();
55
-} else $SI=new SpotterImport($Connection->db);
67
+} else {
68
+	$SI=new SpotterImport($Connection->db);
69
+}
56 70
 //$APRS=new APRS($Connection->db);
57 71
 $SBS=new SBS($Connection->db);
58 72
 $ACARS=new ACARS($Connection->db);
@@ -70,14 +84,18 @@  discard block
 block discarded – undo
70 84
 }
71 85
 
72 86
 // let's try and connect
73
-if ($globalDebug) echo "Connecting...\n";
87
+if ($globalDebug) {
88
+	echo "Connecting...\n";
89
+}
74 90
 $use_aprs = false;
75 91
 
76 92
 function create_socket($host, $port, &$errno, &$errstr) {
77 93
     $ip = gethostbyname($host);
78 94
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
79 95
     $r = @socket_connect($s, $ip, $port);
80
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
96
+    if (!socket_set_nonblock($s)) {
97
+    	echo "Unable to set nonblock on socket\n";
98
+    }
81 99
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
82 100
         return $s;
83 101
     }
@@ -113,22 +131,30 @@  discard block
 block discarded – undo
113 131
         	//$formats[$id] = 'deltadbtxt';
114 132
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 133
         	//$last_exec['deltadbtxt'] = 0;
116
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
134
+        	if ($globalDebug) {
135
+        		echo "Connect to deltadb source (".$host.")...\n";
136
+        	}
117 137
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
118 138
         	//$formats[$id] = 'vatsimtxt';
119 139
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 140
         	//$last_exec['vatsimtxt'] = 0;
121
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
141
+        	if ($globalDebug) {
142
+        		echo "Connect to vatsim source (".$host.")...\n";
143
+        	}
122 144
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
123 145
         	//$formats[$id] = 'aircraftlistjson';
124 146
         	$$globalSources[$id]['format'] = 'aircraftlistjson';
125 147
         	//$last_exec['aircraftlistjson'] = 0;
126
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
148
+        	if ($globalDebug) {
149
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
150
+        	}
127 151
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
128 152
         	//$formats[$id] = 'radarvirtueljson';
129 153
         	$globalSources[$id]['format'] = 'radarvirtueljson';
130 154
         	//$last_exec['radarvirtueljson'] = 0;
131
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
155
+        	if ($globalDebug) {
156
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
157
+        	}
132 158
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
133 159
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
134 160
         	    exit(0);
@@ -137,7 +163,9 @@  discard block
 block discarded – undo
137 163
         	//$formats[$id] = 'planeupdatefaa';
138 164
         	$globalSources[$id]['format'] = 'planeupdatefaa';
139 165
         	//$last_exec['planeupdatefaa'] = 0;
140
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
168
+        	}
141 169
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
142 170
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
143 171
         	    exit(0);
@@ -146,22 +174,30 @@  discard block
 block discarded – undo
146 174
         	//$formats[$id] = 'phpvmacars';
147 175
         	$globalSources[$id]['format'] = 'phpvmacars';
148 176
         	//$last_exec['phpvmacars'] = 0;
149
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
+        	if ($globalDebug) {
178
+        		echo "Connect to phpvmacars source (".$host.")...\n";
179
+        	}
150 180
             } else if (preg_match('/whazzup/i',$host)) {
151 181
         	//$formats[$id] = 'whazzup';
152 182
         	$globalSources[$id]['format'] = 'whazzup';
153 183
         	//$last_exec['whazzup'] = 0;
154
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to whazzup source (".$host.")...\n";
186
+        	}
155 187
             } else if (preg_match('/recentpireps/i',$host)) {
156 188
         	//$formats[$id] = 'pirepsjson';
157 189
         	$globalSources[$id]['format'] = 'pirepsjson';
158 190
         	//$last_exec['pirepsjson'] = 0;
159
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
+        	if ($globalDebug) {
192
+        		echo "Connect to pirepsjson source (".$host.")...\n";
193
+        	}
160 194
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
161 195
         	//$formats[$id] = 'fr24json';
162 196
         	$globalSources[$id]['format'] = 'fr24json';
163 197
         	//$last_exec['fr24json'] = 0;
164
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
198
+        	if ($globalDebug) {
199
+        		echo "Connect to fr24 source (".$host.")...\n";
200
+        	}
165 201
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
166 202
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
167 203
         	    exit(0);
@@ -170,14 +206,21 @@  discard block
 block discarded – undo
170 206
             } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
171 207
         	//$formats[$id] = 'tsv';
172 208
         	$globalSources[$id]['format'] = 'tsv';
173
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
209
+        	if ($globalDebug) {
210
+        		echo "Connect to tsv source (".$host.")...\n";
211
+        	}
174 212
             }
175 213
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
176
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
216
+        	}
177 217
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
178 218
 	    $hostport = explode(':',$host);
179
-	    if (isset($hostport[1])) $port = $hostport[1];
180
-	    else $port = $globalSources[$id]['port'];
219
+	    if (isset($hostport[1])) {
220
+	    	$port = $hostport[1];
221
+	    } else {
222
+	    	$port = $globalSources[$id]['port'];
223
+	    }
181 224
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
182 225
         	$s = create_socket($host,$port, $errno, $errstr);
183 226
     	    } else {
@@ -205,17 +248,25 @@  discard block
 block discarded – undo
205 248
         		//$formats[$id] = 'beast';
206 249
         		$globalSources[$id]['format'] = 'beast';
207 250
 		    //} else $formats[$id] = 'sbs';
208
-		    } else $globalSources[$id]['format'] = 'sbs';
251
+		    } else {
252
+		    	$globalSources[$id]['format'] = 'sbs';
253
+		    }
209 254
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
210 255
 		}
211
-		if ($globalDebug) echo 'Connection in progress to '.$host.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
256
+		if ($globalDebug) {
257
+			echo 'Connection in progress to '.$host.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
258
+		}
212 259
             } else {
213
-		if ($globalDebug) echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
260
+		if ($globalDebug) {
261
+			echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
262
+		}
214 263
     	    }
215 264
         }
216 265
     }
217 266
 }
218
-if (!isset($globalMinFetch)) $globalMinFetch = 0;
267
+if (!isset($globalMinFetch)) {
268
+	$globalMinFetch = 0;
269
+}
219 270
 
220 271
 // Initialize all
221 272
 $status = array();
@@ -223,13 +274,19 @@  discard block
 block discarded – undo
223 274
 $formats = array();
224 275
 $last_exec = array();
225 276
 $time = time();
226
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
227
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
228
-else $timeout = 20;
277
+if (isset($globalSourcesTimeout)) {
278
+	$timeout = $globalSourcesTimeOut;
279
+} else if (isset($globalSBS1TimeOut)) {
280
+	$timeout = $globalSBS1TimeOut;
281
+} else {
282
+	$timeout = 20;
283
+}
229 284
 $errno = '';
230 285
 $errstr='';
231 286
 
232
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
287
+if (!isset($globalDaemon)) {
288
+	$globalDaemon = TRUE;
289
+}
233 290
 /* Initiate connections to all the hosts simultaneously */
234 291
 //connect_all($hosts);
235 292
 connect_all($globalSources);
@@ -251,23 +308,41 @@  discard block
 block discarded – undo
251 308
 	$aprs_connect = 0;
252 309
 	$aprs_keep = 120;
253 310
 	$aprs_last_tx = time();
254
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
255
-	else $aprs_version = $globalName.' using FlightAirMap';
311
+	if (isset($globalAPRSversion)) {
312
+		$aprs_version = $globalAPRSversion;
313
+	} else {
314
+		$aprs_version = $globalName.' using FlightAirMap';
315
+	}
256 316
 	//else $aprs_version = 'Perl Example App';
257
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
258
-	else $aprs_ssid = 'FAM';
317
+	if (isset($globalAPRSssid)) {
318
+		$aprs_ssid = $globalAPRSssid;
319
+	} else {
320
+		$aprs_ssid = 'FAM';
321
+	}
259 322
 	//else $aprs_ssid = 'PerlEx';
260
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
261
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
262
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
263
-	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
264
-}
323
+	if (isset($globalAPRSfilter)) {
324
+		$aprs_filter = $globalAPRSfilter;
325
+	} else {
326
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
327
+	}
328
+	if ($aprs_filter != '') {
329
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
330
+	} else {
331
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
332
+	}
333
+	}
265 334
 
266 335
 // connected - lets do some work
267
-if ($globalDebug) echo "Connected!\n";
336
+if ($globalDebug) {
337
+	echo "Connected!\n";
338
+}
268 339
 sleep(1);
269
-if ($globalDebug) echo "SCAN MODE \n\n";
270
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
340
+if ($globalDebug) {
341
+	echo "SCAN MODE \n\n";
342
+}
343
+if (!isset($globalCronEnd)) {
344
+	$globalCronEnd = 60;
345
+}
271 346
 $endtime = time()+$globalCronEnd;
272 347
 $i = 1;
273 348
 $tt = array();
@@ -281,7 +356,9 @@  discard block
 block discarded – undo
281 356
 
282 357
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
283 358
 while ($i > 0) {
284
-    if (!$globalDaemon) $i = $endtime-time();
359
+    if (!$globalDaemon) {
360
+    	$i = $endtime-time();
361
+    }
285 362
     // Delete old ATC
286 363
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
287 364
         $ATC->deleteOldATC();
@@ -311,8 +388,12 @@  discard block
 block discarded – undo
311 388
 		    $data['datetime'] = date('Y-m-d H:i:s');
312 389
 		    $data['format_source'] = 'deltadbtxt';
313 390
     		    $data['id_source'] = $id_source;
314
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
315
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
391
+		    if (isset($value['name']) && $value['name'] != '') {
392
+		    	$data['source_name'] = $value['name'];
393
+		    }
394
+		    if (isset($value['sourcestats'])) {
395
+		    	$data['sourcestats'] = $value['sourcestats'];
396
+		    }
316 397
     		    $SI->add($data);
317 398
 		    unset($data);
318 399
     		}
@@ -334,10 +415,19 @@  discard block
 block discarded – undo
334 415
 			$data['pilot_name'] = $line[2];
335 416
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
336 417
 			$data['ident'] = $line[0]; // ident
337
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
418
+			if ($line[7] != '' && $line[7] != 0) {
419
+				$data['altitude'] = $line[7];
420
+			}
421
+			// altitude
338 422
 			$data['speed'] = $line[8]; // speed
339
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
340
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
423
+			if (isset($line[45])) {
424
+				$data['heading'] = $line[45];
425
+			}
426
+			// heading
427
+			elseif (isset($line[38])) {
428
+				$data['heading'] = $line[38];
429
+			}
430
+			// heading
341 431
 			$data['latitude'] = $line[5]; // lat
342 432
 	        	$data['longitude'] = $line[6]; // long
343 433
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -352,7 +442,9 @@  discard block
 block discarded – undo
352 442
 			$data['frequency'] = $line[4];
353 443
 			$data['type'] = $line[18];
354 444
 			$data['range'] = $line[19];
355
-			if (isset($line[35])) $data['info'] = $line[35];
445
+			if (isset($line[35])) {
446
+				$data['info'] = $line[35];
447
+			}
356 448
     			$data['id_source'] = $id_source;
357 449
 	    		//$data['arrival_airport_time'] = ;
358 450
 	    		if ($line[9] != '') {
@@ -366,22 +458,35 @@  discard block
 block discarded – undo
366 458
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
367 459
 	    		*/
368 460
 	    		$data['format_source'] = $value['format'];
369
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
370
-    			if ($line[3] == 'PILOT') $SI->add($data);
371
-			elseif ($line[3] == 'ATC') {
461
+			if (isset($value['name']) && $value['name'] != '') {
462
+				$data['source_name'] = $value['name'];
463
+			}
464
+    			if ($line[3] == 'PILOT') {
465
+    				$SI->add($data);
466
+    			} elseif ($line[3] == 'ATC') {
372 467
 				//print_r($data);
373 468
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
374 469
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
375 470
 				$typec = substr($data['ident'],-3);
376
-				if ($typec == 'APP') $data['type'] = 'Approach';
377
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
378
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
379
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
380
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
381
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
382
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
383
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
384
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
471
+				if ($typec == 'APP') {
472
+					$data['type'] = 'Approach';
473
+				} elseif ($typec == 'TWR') {
474
+					$data['type'] = 'Tower';
475
+				} elseif ($typec == 'OBS') {
476
+					$data['type'] = 'Observer';
477
+				} elseif ($typec == 'GND') {
478
+					$data['type'] = 'Ground';
479
+				} elseif ($typec == 'DEL') {
480
+					$data['type'] = 'Delivery';
481
+				} elseif ($typec == 'DEP') {
482
+					$data['type'] = 'Departure';
483
+				} elseif ($typec == 'FSS') {
484
+					$data['type'] = 'Flight Service Station';
485
+				} elseif ($typec == 'CTR') {
486
+					$data['type'] = 'Control Radar or Centre';
487
+				} elseif ($data['type'] == '') {
488
+					$data['type'] = 'Observer';
489
+				}
385 490
 				
386 491
 				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']);
387 492
 			}
@@ -401,26 +506,55 @@  discard block
 block discarded – undo
401 506
 		foreach ($all_data['acList'] as $line) {
402 507
 		    $data = array();
403 508
 		    $data['hex'] = $line['Icao']; // hex
404
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
405
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
406
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
407
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
408
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
409
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
509
+		    if (isset($line['Call'])) {
510
+		    	$data['ident'] = $line['Call'];
511
+		    }
512
+		    // ident
513
+		    if (isset($line['Alt'])) {
514
+		    	$data['altitude'] = $line['Alt'];
515
+		    }
516
+		    // altitude
517
+		    if (isset($line['Spd'])) {
518
+		    	$data['speed'] = $line['Spd'];
519
+		    }
520
+		    // speed
521
+		    if (isset($line['Trak'])) {
522
+		    	$data['heading'] = $line['Trak'];
523
+		    }
524
+		    // heading
525
+		    if (isset($line['Lat'])) {
526
+		    	$data['latitude'] = $line['Lat'];
527
+		    }
528
+		    // lat
529
+		    if (isset($line['Long'])) {
530
+		    	$data['longitude'] = $line['Long'];
531
+		    }
532
+		    // long
410 533
 		    //$data['verticalrate'] = $line['']; // verticale rate
411
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
534
+		    if (isset($line['Sqk'])) {
535
+		    	$data['squawk'] = $line['Sqk'];
536
+		    }
537
+		    // squawk
412 538
 		    $data['emergency'] = ''; // emergency
413
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
539
+		    if (isset($line['Reg'])) {
540
+		    	$data['registration'] = $line['Reg'];
541
+		    }
414 542
 		    /*
415 543
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
416 544
 		    else $data['datetime'] = date('Y-m-d H:i:s');
417 545
 		    */
418 546
 		    $data['datetime'] = date('Y-m-d H:i:s');
419
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
547
+		    if (isset($line['Type'])) {
548
+		    	$data['aircraft_icao'] = $line['Type'];
549
+		    }
420 550
 	    	    $data['format_source'] = 'aircraftlistjson';
421 551
 		    $data['id_source'] = $id_source;
422
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
423
-		    if (isset($data['datetime'])) $SI->add($data);
552
+		    if (isset($value['name']) && $value['name'] != '') {
553
+		    	$data['source_name'] = $value['name'];
554
+		    }
555
+		    if (isset($data['datetime'])) {
556
+		    	$SI->add($data);
557
+		    }
424 558
 		    unset($data);
425 559
 		}
426 560
 	    } else {
@@ -439,7 +573,9 @@  discard block
 block discarded – undo
439 573
 		    $data['datetime'] = date('Y-m-d H:i:s');
440 574
 	    	    $data['format_source'] = 'aircraftlistjson';
441 575
     		    $data['id_source'] = $id_source;
442
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
576
+		    if (isset($value['name']) && $value['name'] != '') {
577
+		    	$data['source_name'] = $value['name'];
578
+		    }
443 579
 		    $SI->add($data);
444 580
 		    unset($data);
445 581
 		}
@@ -474,7 +610,9 @@  discard block
 block discarded – undo
474 610
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
475 611
 	    	    $data['format_source'] = 'planeupdatefaa';
476 612
     		    $data['id_source'] = $id_source;
477
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
613
+		    if (isset($value['name']) && $value['name'] != '') {
614
+		    	$data['source_name'] = $value['name'];
615
+		    }
478 616
 		    $SI->add($data);
479 617
 		    unset($data);
480 618
 		}
@@ -506,7 +644,9 @@  discard block
 block discarded – undo
506 644
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
507 645
 	    	    $data['format_source'] = 'fr24json';
508 646
     		    $data['id_source'] = $id_source;
509
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
647
+		    if (isset($value['name']) && $value['name'] != '') {
648
+		    	$data['source_name'] = $value['name'];
649
+		    }
510 650
 		    $SI->add($data);
511 651
 		    unset($data);
512 652
 		}
@@ -529,23 +669,39 @@  discard block
 block discarded – undo
529 669
 		    if (isset($line['inf'])) {
530 670
 			$data = array();
531 671
 			$data['hex'] = $line['inf']['ia'];
532
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
672
+			if (isset($line['inf']['cs'])) {
673
+				$data['ident'] = $line['inf']['cs'];
674
+			}
675
+			//$line[13]
533 676
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
534
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
535
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
677
+	    		if (isset($line['inf']['gs'])) {
678
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
679
+	    		}
680
+	    		// speed
681
+	    		if (isset($line['inf']['tr'])) {
682
+	    			$data['heading'] = $line['inf']['tr'];
683
+	    		}
684
+	    		// heading
536 685
 	    		$data['latitude'] = $line['pt'][0]; // lat
537 686
 	    		$data['longitude'] = $line['pt'][1]; // long
538 687
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
539
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
688
+	    		if (isset($line['inf']['sq'])) {
689
+	    			$data['squawk'] = $line['inf']['sq'];
690
+	    		}
691
+	    		// squawk
540 692
 	    		//$data['aircraft_icao'] = $line[8];
541
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
693
+	    		if (isset($line['inf']['rc'])) {
694
+	    			$data['registration'] = $line['inf']['rc'];
695
+	    		}
542 696
 			//$data['departure_airport_iata'] = $line[11];
543 697
 			//$data['arrival_airport_iata'] = $line[12];
544 698
 	    		//$data['emergency'] = ''; // emergency
545 699
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
546 700
 	    		$data['format_source'] = 'radarvirtueljson';
547 701
     			$data['id_source'] = $id_source;
548
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
702
+			if (isset($value['name']) && $value['name'] != '') {
703
+				$data['source_name'] = $value['name'];
704
+			}
549 705
 			$SI->add($data);
550 706
 			unset($data);
551 707
 		    }
@@ -564,29 +720,62 @@  discard block
 block discarded – undo
564 720
 		    $data = array();
565 721
 		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
566 722
 		    $data['ident'] = $line['callsign']; // ident
567
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
568
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
569
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
570
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
571
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
572
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
723
+		    if (isset($line['pilotid'])) {
724
+		    	$data['pilot_id'] = $line['pilotid'];
725
+		    }
726
+		    // pilot id
727
+		    if (isset($line['name'])) {
728
+		    	$data['pilot_name'] = $line['name'];
729
+		    }
730
+		    // pilot name
731
+		    if (isset($line['alt'])) {
732
+		    	$data['altitude'] = $line['alt'];
733
+		    }
734
+		    // altitude
735
+		    if (isset($line['gs'])) {
736
+		    	$data['speed'] = $line['gs'];
737
+		    }
738
+		    // speed
739
+		    if (isset($line['heading'])) {
740
+		    	$data['heading'] = $line['heading'];
741
+		    }
742
+		    // heading
743
+		    if (isset($line['route'])) {
744
+		    	$data['waypoints'] = $line['route'];
745
+		    }
746
+		    // route
573 747
 		    $data['latitude'] = $line['lat']; // lat
574 748
 		    $data['longitude'] = $line['lon']; // long
575 749
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
576 750
 		    //$data['squawk'] = $line['squawk']; // squawk
577 751
 		    //$data['emergency'] = ''; // emergency
578
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
579
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
580
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
752
+		    if (isset($line['depicao'])) {
753
+		    	$data['departure_airport_icao'] = $line['depicao'];
754
+		    }
755
+		    if (isset($line['deptime'])) {
756
+		    	$data['departure_airport_time'] = $line['deptime'];
757
+		    }
758
+		    if (isset($line['arricao'])) {
759
+		    	$data['arrival_airport_icao'] = $line['arricao'];
760
+		    }
581 761
 		    //$data['arrival_airport_time'] = $line['arrtime'];
582
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
583
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
584
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
585
-		    else $data['info'] = '';
762
+		    if (isset($line['aircraft'])) {
763
+		    	$data['aircraft_icao'] = $line['aircraft'];
764
+		    }
765
+		    if (isset($line['transponder'])) {
766
+		    	$data['squawk'] = $line['transponder'];
767
+		    }
768
+		    if (isset($line['atis'])) {
769
+		    	$data['info'] = $line['atis'];
770
+		    } else {
771
+		    	$data['info'] = '';
772
+		    }
586 773
 		    $data['format_source'] = 'pireps';
587 774
     		    $data['id_source'] = $id_source;
588 775
 		    $data['datetime'] = date('Y-m-d H:i:s');
589
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
776
+		    if (isset($value['name']) && $value['name'] != '') {
777
+		    	$data['source_name'] = $value['name'];
778
+		    }
590 779
 		    if ($line['icon'] == 'plane') {
591 780
 			$SI->add($data);
592 781
 		    //    print_r($data);
@@ -595,15 +784,25 @@  discard block
 block discarded – undo
595 784
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
596 785
 			$typec = substr($data['ident'],-3);
597 786
 			$data['type'] = '';
598
-			if ($typec == 'APP') $data['type'] = 'Approach';
599
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
600
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
601
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
602
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
603
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
604
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
605
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
606
-			else $data['type'] = 'Observer';
787
+			if ($typec == 'APP') {
788
+				$data['type'] = 'Approach';
789
+			} elseif ($typec == 'TWR') {
790
+				$data['type'] = 'Tower';
791
+			} elseif ($typec == 'OBS') {
792
+				$data['type'] = 'Observer';
793
+			} elseif ($typec == 'GND') {
794
+				$data['type'] = 'Ground';
795
+			} elseif ($typec == 'DEL') {
796
+				$data['type'] = 'Delivery';
797
+			} elseif ($typec == 'DEP') {
798
+				$data['type'] = 'Departure';
799
+			} elseif ($typec == 'FSS') {
800
+				$data['type'] = 'Flight Service Station';
801
+			} elseif ($typec == 'CTR') {
802
+				$data['type'] = 'Control Radar or Centre';
803
+			} else {
804
+				$data['type'] = 'Observer';
805
+			}
607 806
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
608 807
 		    }
609 808
 		    unset($data);
@@ -621,8 +820,12 @@  discard block
 block discarded – undo
621 820
 	    	    $data = array();
622 821
 	    	    //$data['id'] = $line['id']; // id not usable
623 822
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
624
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
625
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
823
+	    	    if (isset($line['pilotname'])) {
824
+	    	    	$data['pilot_name'] = $line['pilotname'];
825
+	    	    }
826
+	    	    if (isset($line['pilotid'])) {
827
+	    	    	$data['pilot_id'] = $line['pilotid'];
828
+	    	    }
626 829
 	    	    $data['ident'] = $line['flightnum']; // ident
627 830
 	    	    $data['altitude'] = $line['alt']; // altitude
628 831
 	    	    $data['speed'] = $line['gs']; // speed
@@ -639,23 +842,35 @@  discard block
 block discarded – undo
639 842
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
640 843
     		    $data['arrival_airport_time'] = $line['arrtime'];
641 844
     		    $data['registration'] = $line['aircraft'];
642
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
845
+		    if (isset($line['route'])) {
846
+		    	$data['waypoints'] = $line['route'];
847
+		    }
848
+		    // route
643 849
 		    if (isset($line['aircraftname'])) {
644 850
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
645 851
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
646 852
 	    		$aircraft_data = explode('-',$line['aircraftname']);
647
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
648
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
649
-	    		else {
853
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
854
+	    			$data['aircraft_icao'] = $aircraft_data[0];
855
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
856
+	    			$data['aircraft_icao'] = $aircraft_data[1];
857
+	    		} else {
650 858
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
651
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
652
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
859
+	    		    if (isset($aircraft_data[1])) {
860
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
861
+	    		    } else {
862
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
863
+	    		    }
653 864
 	    		}
654 865
 	    	    }
655
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
866
+    		    if (isset($line['route'])) {
867
+    		    	$data['waypoints'] = $line['route'];
868
+    		    }
656 869
     		    $data['id_source'] = $id_source;
657 870
 	    	    $data['format_source'] = 'phpvmacars';
658
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
+		    if (isset($value['name']) && $value['name'] != '') {
872
+		    	$data['source_name'] = $value['name'];
873
+		    }
659 874
 		    $SI->add($data);
660 875
 		    unset($data);
661 876
 		}
@@ -664,7 +879,9 @@  discard block
 block discarded – undo
664 879
     	    $value['last_exec'] = time();
665 880
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
666 881
 	} 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') {
667
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
882
+	    if (function_exists('pcntl_fork')) {
883
+	    	pcntl_signal_dispatch();
884
+	    }
668 885
     	    $value['last_exec'] = time();
669 886
 
670 887
 	    //$read = array( $sockets[$id] );
@@ -672,7 +889,9 @@  discard block
 block discarded – undo
672 889
 	    $write = NULL;
673 890
 	    $e = NULL;
674 891
 	    $n = socket_select($read, $write, $e, $timeout);
675
-	    if ($e != NULL) var_dump($e);
892
+	    if ($e != NULL) {
893
+	    	var_dump($e);
894
+	    }
676 895
 	    if ($n > 0) {
677 896
 		foreach ($read as $nb => $r) {
678 897
 		    //$value = $formats[$nb];
@@ -695,8 +914,12 @@  discard block
 block discarded – undo
695 914
 			    if (is_array($data)) {
696 915
 				$data['datetime'] = date('Y-m-d H:i:s');
697 916
 				$data['format_source'] = 'raw';
698
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
699
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
917
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
918
+					$data['source_name'] = $globalSources[$nb]['name'];
919
+				}
920
+    				if (isset($globalSources[$nb]['sourcestats'])) {
921
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
922
+    				}
700 923
                                 $SI->add($data);
701 924
                             }
702 925
                         } elseif ($format == 'flightgearsp') {
@@ -719,7 +942,9 @@  discard block
 block discarded – undo
719 942
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
720 943
 			    }
721 944
                         } elseif ($format == 'acars') {
722
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
945
+                    	    if ($globalDebug) {
946
+                    	    	echo 'ACARS : '.$buffer."\n";
947
+                    	    }
723 948
 			    $ACARS->add(trim($buffer));
724 949
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
725 950
 			    $ACARS->deleteLiveAcarsData();
@@ -756,21 +981,41 @@  discard block
 block discarded – undo
756 981
     				$data['hex'] = $lined['hexid'];
757 982
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
758 983
     				$data['datetime'] = date('Y-m-d H:i:s');;
759
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
760
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
761
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
762
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
763
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
764
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
765
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
984
+    				if (isset($lined['ident'])) {
985
+    					$data['ident'] = $lined['ident'];
986
+    				}
987
+    				if (isset($lined['lat'])) {
988
+    					$data['latitude'] = $lined['lat'];
989
+    				}
990
+    				if (isset($lined['lon'])) {
991
+    					$data['longitude'] = $lined['lon'];
992
+    				}
993
+    				if (isset($lined['speed'])) {
994
+    					$data['speed'] = $lined['speed'];
995
+    				}
996
+    				if (isset($lined['squawk'])) {
997
+    					$data['squawk'] = $lined['squawk'];
998
+    				}
999
+    				if (isset($lined['alt'])) {
1000
+    					$data['altitude'] = $lined['alt'];
1001
+    				}
1002
+    				if (isset($lined['heading'])) {
1003
+    					$data['heading'] = $lined['heading'];
1004
+    				}
766 1005
     				$data['id_source'] = $id_source;
767 1006
     				$data['format_source'] = 'tsv';
768
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
769
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1007
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1008
+    					$data['source_name'] = $globalSources[$nb]['name'];
1009
+    				}
1010
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1011
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1012
+    				}
770 1013
     				$SI->add($data);
771 1014
     				unset($lined);
772 1015
     				unset($data);
773
-    			    } else $error = true;
1016
+    			    } else {
1017
+    			    	$error = true;
1018
+    			    }
774 1019
 			} elseif ($format == 'aprs' && $use_aprs) {
775 1020
 			    if ($aprs_connect == 0) {
776 1021
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -794,29 +1039,44 @@  discard block
 block discarded – undo
794 1039
 				    $data['latitude'] = $line['latitude'];
795 1040
 				    $data['longitude'] = $line['longitude'];
796 1041
 				    //$data['verticalrate'] = $line[16];
797
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
798
-				    else $data['speed'] = 0;
1042
+				    if (isset($line['speed'])) {
1043
+				    	$data['speed'] = $line['speed'];
1044
+				    } else {
1045
+				    	$data['speed'] = 0;
1046
+				    }
799 1047
 				    $data['altitude'] = $line['altitude'];
800
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
1048
+				    if (isset($line['course'])) {
1049
+				    	$data['heading'] = $line['course'];
1050
+				    }
801 1051
 				    //else $data['heading'] = 0;
802 1052
 				    $data['aircraft_type'] = $line['stealth'];
803
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1053
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1054
+				    	$data['noarchive'] = true;
1055
+				    }
804 1056
     				    $data['id_source'] = $id_source;
805 1057
 				    $data['format_source'] = 'aprs';
806 1058
 				    $data['source_name'] = $line['source'];
807
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1059
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1060
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1061
+    				    }
808 1062
 				    $currentdate = date('Y-m-d H:i:s');
809 1063
 				    $aprsdate = strtotime($data['datetime']);
810 1064
 				    // Accept data if time <= system time + 20s
811
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
812
-				    else {
813
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
814
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1065
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) {
1066
+				    	$send = $SI->add($data);
1067
+				    } else {
1068
+					if ($line['stealth'] != 0) {
1069
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1070
+					} else {
1071
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1072
+					}
815 1073
 				    }
816 1074
 				    unset($data);
817 1075
 				} 
818 1076
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
819
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1077
+				elseif ($line == true && $globalDebug) {
1078
+					echo '!! Failed : '.$buffer."!!\n";
1079
+				}
820 1080
 			    }
821 1081
 			} else {
822 1082
 			    $line = explode(',', $buffer);
@@ -844,24 +1104,38 @@  discard block
 block discarded – undo
844 1104
     				$data['ground'] = $line[21];
845 1105
     				$data['emergency'] = $line[19];
846 1106
     				$data['format_source'] = 'sbs';
847
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
848
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1107
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1108
+					$data['source_name'] = $globalSources[$nb]['name'];
1109
+				}
1110
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1111
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1112
+    				}
849 1113
     				$data['id_source'] = $id_source;
850 1114
     				$send = $SI->add($data);
851 1115
     				unset($data);
852
-    			    } else $error = true;
1116
+    			    } else {
1117
+    			    	$error = true;
1118
+    			    }
853 1119
 			    if ($error) {
854 1120
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
855
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1121
+					if ($globalDebug) {
1122
+						echo "Not a message. Ignoring... \n";
1123
+					}
856 1124
 				} else {
857
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1125
+					if ($globalDebug) {
1126
+						echo "Wrong line format. Ignoring... \n";
1127
+					}
858 1128
 					if ($globalDebug) {
859 1129
 						echo $buffer;
860 1130
 						print_r($line);
861 1131
 					}
862 1132
 					//socket_close($r);
863
-					if ($globalDebug) echo "Reconnect after an error...\n";
864
-					if ($format == 'aprs') $aprs_connect = 0;
1133
+					if ($globalDebug) {
1134
+						echo "Reconnect after an error...\n";
1135
+					}
1136
+					if ($format == 'aprs') {
1137
+						$aprs_connect = 0;
1138
+					}
865 1139
 					$sourceer[$nb] = $globalSources[$nb];
866 1140
 					connect_all($sourceer);
867 1141
 					$sourceer = array();
@@ -869,10 +1143,14 @@  discard block
 block discarded – undo
869 1143
 			    }
870 1144
 			}
871 1145
 			// Sleep for xxx microseconds
872
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1146
+			if (isset($globalSBSSleep)) {
1147
+				usleep($globalSBSSleep);
1148
+			}
873 1149
 		    } else {
874 1150
 			if ($format == 'flightgearmp') {
875
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1151
+			    	if ($globalDebug) {
1152
+			    		echo "Reconnect FlightGear MP...";
1153
+			    	}
876 1154
 				//@socket_close($r);
877 1155
 				sleep($globalMinFetch);
878 1156
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -881,10 +1159,15 @@  discard block
 block discarded – undo
881 1159
 				break;
882 1160
 				
883 1161
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
884
-			    if (isset($tt[$format])) $tt[$format]++;
885
-			    else $tt[$format] = 0;
1162
+			    if (isset($tt[$format])) {
1163
+			    	$tt[$format]++;
1164
+			    } else {
1165
+			    	$tt[$format] = 0;
1166
+			    }
886 1167
 			    if ($tt[$format] > 30) {
887
-				if ($globalDebug)echo "ERROR : Reconnect ".$format."...";
1168
+				if ($globalDebug) {
1169
+					echo "ERROR : Reconnect ".$format."...";
1170
+				}
888 1171
 				//@socket_close($r);
889 1172
 				sleep(2);
890 1173
 				$aprs_connect = 0;
@@ -900,12 +1183,18 @@  discard block
 block discarded – undo
900 1183
 		}
901 1184
 	    } else {
902 1185
 		$error = socket_strerror(socket_last_error());
903
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1186
+		if ($globalDebug) {
1187
+			echo "ERROR : socket_select give this error ".$error . "\n";
1188
+		}
904 1189
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
905
-			if (isset($globalDebug)) echo "Restarting...\n";
1190
+			if (isset($globalDebug)) {
1191
+				echo "Restarting...\n";
1192
+			}
906 1193
 			// Restart the script if possible
907 1194
 			if (is_array($sockets)) {
908
-			    if ($globalDebug) echo "Shutdown all sockets...";
1195
+			    if ($globalDebug) {
1196
+			    	echo "Shutdown all sockets...";
1197
+			    }
909 1198
 			    
910 1199
 			    foreach ($sockets as $sock) {
911 1200
 				@socket_shutdown($sock,2);
@@ -913,7 +1202,9 @@  discard block
 block discarded – undo
913 1202
 			    }
914 1203
 			    
915 1204
 			}
916
-			    if ($globalDebug) echo "Restart all connections...";
1205
+			    if ($globalDebug) {
1206
+			    	echo "Restart all connections...";
1207
+			    }
917 1208
 			    sleep(2);
918 1209
 			    $time = time();
919 1210
 			    //connect_all($hosts);
Please login to merge, or discard this patch.