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