Completed
Push — master ( 04cc20...60bf6d )
by Yannick
08:30
created
scripts/daemon-spotter.php 3 patches
Indentation   +859 added lines, -859 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,48 +24,48 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','nodaemon','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['nodaemon'])) $globalDaemon = FALSE;
63 63
 if (isset($options['server'])) $globalServer = TRUE;
64 64
 if (isset($options['idsource'])) $id_source = $options['idsource'];
65 65
 else $id_source = 1;
66 66
 if (isset($globalServer) && $globalServer) {
67
-    if ($globalDebug) echo "Using Server Mode\n";
68
-    $SI=new SpotterServer();
67
+	if ($globalDebug) echo "Using Server Mode\n";
68
+	$SI=new SpotterServer();
69 69
 /*
70 70
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
71 71
     $SI = new adsb2aprs();
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 } else $SI=new SpotterImport($Connection->db);
75 75
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
76 76
 if (isset($globalMarine) && $globalMarine) {
77
-    $AIS = new AIS();
78
-    $MI = new MarineImport($Connection->db);
77
+	$AIS = new AIS();
78
+	$MI = new MarineImport($Connection->db);
79 79
 }
80 80
 //$APRS=new APRS($Connection->db);
81 81
 $SBS=new SBS();
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 //$servertz = system('date +%Z');
86 86
 // signal handler - playing nice with sockets and dump1090
87 87
 if (function_exists('pcntl_fork')) {
88
-    pcntl_signal(SIGINT,  function() {
89
-        global $sockets;
90
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
91
-        die("Bye!\n");
92
-    });
93
-    pcntl_signal_dispatch();
88
+	pcntl_signal(SIGINT,  function() {
89
+		global $sockets;
90
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
91
+		die("Bye!\n");
92
+	});
93
+	pcntl_signal_dispatch();
94 94
 }
95 95
 
96 96
 // let's try and connect
@@ -100,153 +100,153 @@  discard block
 block discarded – undo
100 100
 $reset = 0;
101 101
 
102 102
 function connect_all($hosts) {
103
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
105
-    $reset++;
106
-    if ($globalDebug) echo 'Connect to all...'."\n";
107
-    foreach ($hosts as $id => $value) {
103
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
105
+	$reset++;
106
+	if ($globalDebug) echo 'Connect to all...'."\n";
107
+	foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111 111
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
113
-        	//$formats[$id] = 'deltadbtxt';
114
-        	$globalSources[$id]['format'] = 'deltadbtxt';
115
-        	//$last_exec['deltadbtxt'] = 0;
116
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
118
-        	//$formats[$id] = 'vatsimtxt';
119
-        	$globalSources[$id]['format'] = 'vatsimtxt';
120
-        	//$last_exec['vatsimtxt'] = 0;
121
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
123
-        	//$formats[$id] = 'aircraftlistjson';
124
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
125
-        	//$last_exec['aircraftlistjson'] = 0;
126
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/opensky/i',$host)) {
128
-        	//$formats[$id] = 'aircraftlistjson';
129
-        	$globalSources[$id]['format'] = 'opensky';
130
-        	//$last_exec['aircraftlistjson'] = 0;
131
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
132
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
133
-        	//$formats[$id] = 'radarvirtueljson';
134
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
135
-        	//$last_exec['radarvirtueljson'] = 0;
136
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
137
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
138
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139
-        	    exit(0);
140
-        	}
141
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
142
-        	//$formats[$id] = 'planeupdatefaa';
143
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
144
-        	//$last_exec['planeupdatefaa'] = 0;
145
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
146
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
147
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148
-        	    exit(0);
149
-        	}
150
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
151
-        	//$formats[$id] = 'phpvmacars';
152
-        	$globalSources[$id]['format'] = 'phpvmacars';
153
-        	//$last_exec['phpvmacars'] = 0;
154
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
155
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
156
-        	//$formats[$id] = 'phpvmacars';
157
-        	$globalSources[$id]['format'] = 'vam';
158
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
159
-            } else if (preg_match('/whazzup/i',$host)) {
160
-        	//$formats[$id] = 'whazzup';
161
-        	$globalSources[$id]['format'] = 'whazzup';
162
-        	//$last_exec['whazzup'] = 0;
163
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
164
-            } else if (preg_match('/recentpireps/i',$host)) {
165
-        	//$formats[$id] = 'pirepsjson';
166
-        	$globalSources[$id]['format'] = 'pirepsjson';
167
-        	//$last_exec['pirepsjson'] = 0;
168
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
169
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
170
-        	//$formats[$id] = 'fr24json';
171
-        	$globalSources[$id]['format'] = 'fr24json';
172
-        	//$last_exec['fr24json'] = 0;
173
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
174
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
175
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176
-        	    exit(0);
177
-        	}
178
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
179
-        	//$formats[$id] = 'fr24json';
180
-        	$globalSources[$id]['format'] = 'myshiptracking';
181
-        	//$last_exec['fr24json'] = 0;
182
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
183
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
184
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
185
-        	    exit(0);
186
-        	}
187
-            //} else if (preg_match('/10001/',$host)) {
188
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189
-        	//$formats[$id] = 'tsv';
190
-        	$globalSources[$id]['format'] = 'tsv';
191
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
192
-            }
193
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
194
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
196
-    		    if ($idf !== false) {
197
-    			$httpfeeds[$id] = $idf;
198
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
199
-    		    }
200
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
202
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203
-	    $hostport = explode(':',$host);
204
-	    if (isset($hostport[1])) {
112
+			if (preg_match('/deltadb.txt$/i',$host)) {
113
+			//$formats[$id] = 'deltadbtxt';
114
+			$globalSources[$id]['format'] = 'deltadbtxt';
115
+			//$last_exec['deltadbtxt'] = 0;
116
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
118
+			//$formats[$id] = 'vatsimtxt';
119
+			$globalSources[$id]['format'] = 'vatsimtxt';
120
+			//$last_exec['vatsimtxt'] = 0;
121
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
123
+			//$formats[$id] = 'aircraftlistjson';
124
+			$globalSources[$id]['format'] = 'aircraftlistjson';
125
+			//$last_exec['aircraftlistjson'] = 0;
126
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
+			} else if (preg_match('/opensky/i',$host)) {
128
+			//$formats[$id] = 'aircraftlistjson';
129
+			$globalSources[$id]['format'] = 'opensky';
130
+			//$last_exec['aircraftlistjson'] = 0;
131
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
132
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
133
+			//$formats[$id] = 'radarvirtueljson';
134
+			$globalSources[$id]['format'] = 'radarvirtueljson';
135
+			//$last_exec['radarvirtueljson'] = 0;
136
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
137
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
138
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139
+				exit(0);
140
+			}
141
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
142
+			//$formats[$id] = 'planeupdatefaa';
143
+			$globalSources[$id]['format'] = 'planeupdatefaa';
144
+			//$last_exec['planeupdatefaa'] = 0;
145
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
146
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
147
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148
+				exit(0);
149
+			}
150
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
151
+			//$formats[$id] = 'phpvmacars';
152
+			$globalSources[$id]['format'] = 'phpvmacars';
153
+			//$last_exec['phpvmacars'] = 0;
154
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
155
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
156
+			//$formats[$id] = 'phpvmacars';
157
+			$globalSources[$id]['format'] = 'vam';
158
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
159
+			} else if (preg_match('/whazzup/i',$host)) {
160
+			//$formats[$id] = 'whazzup';
161
+			$globalSources[$id]['format'] = 'whazzup';
162
+			//$last_exec['whazzup'] = 0;
163
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
164
+			} else if (preg_match('/recentpireps/i',$host)) {
165
+			//$formats[$id] = 'pirepsjson';
166
+			$globalSources[$id]['format'] = 'pirepsjson';
167
+			//$last_exec['pirepsjson'] = 0;
168
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
169
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
170
+			//$formats[$id] = 'fr24json';
171
+			$globalSources[$id]['format'] = 'fr24json';
172
+			//$last_exec['fr24json'] = 0;
173
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
174
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
175
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176
+				exit(0);
177
+			}
178
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
179
+			//$formats[$id] = 'fr24json';
180
+			$globalSources[$id]['format'] = 'myshiptracking';
181
+			//$last_exec['fr24json'] = 0;
182
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
183
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
184
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
185
+				exit(0);
186
+			}
187
+			//} else if (preg_match('/10001/',$host)) {
188
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189
+			//$formats[$id] = 'tsv';
190
+			$globalSources[$id]['format'] = 'tsv';
191
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
192
+			}
193
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
194
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
196
+				if ($idf !== false) {
197
+				$httpfeeds[$id] = $idf;
198
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
199
+				}
200
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
202
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203
+		$hostport = explode(':',$host);
204
+		if (isset($hostport[1])) {
205 205
 		$port = $hostport[1];
206 206
 		$hostn = $hostport[0];
207
-	    } else {
207
+		} else {
208 208
 		$port = $globalSources[$id]['port'];
209 209
 		$hostn = $globalSources[$id]['host'];
210
-	    }
211
-	    $Common = new Common();
212
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
213
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
214
-    	    } else {
215
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
216
-	    }
217
-	    if ($s) {
218
-    	        $sockets[$id] = $s;
219
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
220
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
210
+		}
211
+		$Common = new Common();
212
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
213
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
214
+			} else {
215
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
216
+		}
217
+		if ($s) {
218
+				$sockets[$id] = $s;
219
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
220
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
221 221
 			//$formats[$id] = 'aprs';
222 222
 			$globalSources[$id]['format'] = 'aprs';
223 223
 			//$aprs_connect = 0;
224 224
 			//$use_aprs = true;
225
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
225
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
226 226
 			$globalSources[$id]['format'] = 'vrstcp';
227
-    		    } elseif ($port == '10001') {
228
-        		//$formats[$id] = 'tsv';
229
-        		$globalSources[$id]['format'] = 'tsv';
230
-		    } elseif ($port == '30002') {
231
-        		//$formats[$id] = 'raw';
232
-        		$globalSources[$id]['format'] = 'raw';
233
-		    } elseif ($port == '5001') {
234
-        		//$formats[$id] = 'raw';
235
-        		$globalSources[$id]['format'] = 'flightgearmp';
236
-		    } elseif ($port == '30005') {
227
+				} elseif ($port == '10001') {
228
+				//$formats[$id] = 'tsv';
229
+				$globalSources[$id]['format'] = 'tsv';
230
+			} elseif ($port == '30002') {
231
+				//$formats[$id] = 'raw';
232
+				$globalSources[$id]['format'] = 'raw';
233
+			} elseif ($port == '5001') {
234
+				//$formats[$id] = 'raw';
235
+				$globalSources[$id]['format'] = 'flightgearmp';
236
+			} elseif ($port == '30005') {
237 237
 			// Not yet supported
238
-        		//$formats[$id] = 'beast';
239
-        		$globalSources[$id]['format'] = 'beast';
240
-		    //} else $formats[$id] = 'sbs';
241
-		    } else $globalSources[$id]['format'] = 'sbs';
242
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
238
+				//$formats[$id] = 'beast';
239
+				$globalSources[$id]['format'] = 'beast';
240
+			//} else $formats[$id] = 'sbs';
241
+			} else $globalSources[$id]['format'] = 'sbs';
242
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
243 243
 		}
244 244
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
245
-            } else {
245
+			} else {
246 246
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
247
-    	    }
248
-        }
249
-    }
247
+			}
248
+		}
249
+	}
250 250
 }
251 251
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
252 252
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 //connect_all($globalSources);
270 270
 
271 271
 if (isset($globalProxy) && $globalProxy) {
272
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
272
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
273 273
 } else {
274
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
274
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
275 275
 }
276 276
 
277 277
 // APRS Configuration
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 	die;
281 281
 }
282 282
 foreach ($globalSources as $key => $source) {
283
-    if (!isset($source['format'])) {
284
-        $globalSources[$key]['format'] = 'auto';
285
-    }
283
+	if (!isset($source['format'])) {
284
+		$globalSources[$key]['format'] = 'auto';
285
+	}
286 286
 }
287 287
 connect_all($globalSources);
288 288
 foreach ($globalSources as $key => $source) {
289
-    if (isset($source['format']) && $source['format'] == 'aprs') {
289
+	if (isset($source['format']) && $source['format'] == 'aprs') {
290 290
 	$aprs_connect = 0;
291 291
 	$use_aprs = true;
292 292
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
293 293
 	break;
294
-    }
294
+	}
295 295
 }
296 296
 
297 297
 if ($use_aprs) {
@@ -333,152 +333,152 @@  discard block
 block discarded – undo
333 333
 
334 334
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
335 335
 while ($i > 0) {
336
-    if (!$globalDaemon) $i = $endtime-time();
337
-    // Delete old ATC
338
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336
+	if (!$globalDaemon) $i = $endtime-time();
337
+	// Delete old ATC
338
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
339 339
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
340
-        $ATC->deleteOldATC();
341
-    }
340
+		$ATC->deleteOldATC();
341
+	}
342 342
     
343
-    //if (count($last_exec) > 0) {
344
-    if (count($last_exec) == count($globalSources)) {
343
+	//if (count($last_exec) > 0) {
344
+	if (count($last_exec) == count($globalSources)) {
345 345
 	$max = $globalMinFetch;
346 346
 	foreach ($last_exec as $last) {
347
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
347
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
348 348
 	}
349 349
 	if ($max != $globalMinFetch) {
350
-	    if ($globalDebug) echo 'Sleeping...'."\n";
351
-	    sleep($globalMinFetch-$max+2);
350
+		if ($globalDebug) echo 'Sleeping...'."\n";
351
+		sleep($globalMinFetch-$max+2);
352
+	}
352 353
 	}
353
-    }
354 354
 
355 355
     
356
-    //foreach ($formats as $id => $value) {
357
-    foreach ($globalSources as $id => $value) {
356
+	//foreach ($formats as $id => $value) {
357
+	foreach ($globalSources as $id => $value) {
358 358
 	date_default_timezone_set('UTC');
359 359
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
360 360
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
361
-	    //$buffer = $Common->getData($hosts[$id]);
362
-	    $buffer = $Common->getData($value['host']);
363
-	    if ($buffer != '') $reset = 0;
364
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
365
-	    $buffer = explode('\n',$buffer);
366
-	    foreach ($buffer as $line) {
367
-    		if ($line != '' && count($line) > 7) {
368
-    		    $line = explode(',', $line);
369
-	            $data = array();
370
-	            $data['hex'] = $line[1]; // hex
371
-	            $data['ident'] = $line[2]; // ident
372
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
373
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
374
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
375
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
376
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
377
-	            $data['verticalrate'] = ''; // vertical rate
378
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
379
-	            $data['emergency'] = ''; // emergency
380
-		    $data['datetime'] = date('Y-m-d H:i:s');
381
-		    $data['format_source'] = 'deltadbtxt';
382
-    		    $data['id_source'] = $id_source;
383
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
384
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
385
-    		    $SI->add($data);
386
-		    unset($data);
387
-    		}
388
-    	    }
389
-    	    $last_exec[$id]['last'] = time();
361
+		//$buffer = $Common->getData($hosts[$id]);
362
+		$buffer = $Common->getData($value['host']);
363
+		if ($buffer != '') $reset = 0;
364
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
365
+		$buffer = explode('\n',$buffer);
366
+		foreach ($buffer as $line) {
367
+			if ($line != '' && count($line) > 7) {
368
+				$line = explode(',', $line);
369
+				$data = array();
370
+				$data['hex'] = $line[1]; // hex
371
+				$data['ident'] = $line[2]; // ident
372
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
373
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
374
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
375
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
376
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
377
+				$data['verticalrate'] = ''; // vertical rate
378
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
379
+				$data['emergency'] = ''; // emergency
380
+			$data['datetime'] = date('Y-m-d H:i:s');
381
+			$data['format_source'] = 'deltadbtxt';
382
+				$data['id_source'] = $id_source;
383
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
384
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
385
+				$SI->add($data);
386
+			unset($data);
387
+			}
388
+			}
389
+			$last_exec[$id]['last'] = time();
390 390
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
391
-	    date_default_timezone_set('CET');
392
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
393
-	    date_default_timezone_set('UTC');
394
-	    if ($buffer != '') $reset = 0;
395
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
396
-	    $buffer = explode('\n',$buffer);
397
-	    foreach ($buffer as $line) {
391
+		date_default_timezone_set('CET');
392
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
393
+		date_default_timezone_set('UTC');
394
+		if ($buffer != '') $reset = 0;
395
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
396
+		$buffer = explode('\n',$buffer);
397
+		foreach ($buffer as $line) {
398 398
 		if ($line != '') {
399
-		    echo "'".$line."'\n";
400
-		    $add = false;
401
-		    $ais_data = $AIS->parse_line(trim($line));
402
-		    $data = array();
403
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
404
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
405
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
406
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
407
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
408
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
409
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
410
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
411
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
412
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
413
-		    if (isset($ais_data['timestamp'])) {
399
+			echo "'".$line."'\n";
400
+			$add = false;
401
+			$ais_data = $AIS->parse_line(trim($line));
402
+			$data = array();
403
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
404
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
405
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
406
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
407
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
408
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
409
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
410
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
411
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
412
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
413
+			if (isset($ais_data['timestamp'])) {
414 414
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
415 415
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
416
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
417
-			    $add = true;
416
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
417
+				$add = true;
418 418
 			}
419
-		    } else {
419
+			} else {
420 420
 			$data['datetime'] = date('Y-m-d H:i:s');
421 421
 			$add = true;
422
-		    }
423
-		    $data['format_source'] = 'aisnmeatxt';
424
-    		    $data['id_source'] = $id_source;
425
-		    print_r($data);
426
-		    echo 'Add...'."\n";
427
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
428
-		    unset($data);
422
+			}
423
+			$data['format_source'] = 'aisnmeatxt';
424
+				$data['id_source'] = $id_source;
425
+			print_r($data);
426
+			echo 'Add...'."\n";
427
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
428
+			unset($data);
429 429
 		}
430
-    	    }
431
-    	    $last_exec[$id]['last'] = time();
430
+			}
431
+			$last_exec[$id]['last'] = time();
432 432
 	} elseif ($value['format'] == 'aisnmeahttp') {
433
-	    $arr = $httpfeeds;
434
-	    $w = $e = null;
433
+		$arr = $httpfeeds;
434
+		$w = $e = null;
435 435
 	    
436
-	    if (isset($arr[$id])) {
437
-	    $nn = stream_select($arr,$w,$e,$timeout);
438
-	    if ($nn > 0) {
436
+		if (isset($arr[$id])) {
437
+		$nn = stream_select($arr,$w,$e,$timeout);
438
+		if ($nn > 0) {
439 439
 		foreach ($httpfeeds as $feed) {
440
-		    $buffer = stream_get_line($feed,2000,"\n");
441
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
442
-		    $buffer = explode('\n',$buffer);
443
-		    foreach ($buffer as $line) {
440
+			$buffer = stream_get_line($feed,2000,"\n");
441
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
442
+			$buffer = explode('\n',$buffer);
443
+			foreach ($buffer as $line) {
444 444
 			if ($line != '') {
445
-			    $ais_data = $AIS->parse_line(trim($line));
446
-			    $data = array();
447
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
448
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
449
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
450
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
451
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
452
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
453
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
454
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
455
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
456
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
457
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
458
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
459
-			    if (isset($ais_data['timestamp'])) {
445
+				$ais_data = $AIS->parse_line(trim($line));
446
+				$data = array();
447
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
448
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
449
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
450
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
451
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
452
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
453
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
454
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
455
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
456
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
457
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
458
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
459
+				if (isset($ais_data['timestamp'])) {
460 460
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
461
-			    } else {
461
+				} else {
462 462
 				$data['datetime'] = date('Y-m-d H:i:s');
463
-			    }
464
-			    $data['format_source'] = 'aisnmeahttp';
465
-			    $data['id_source'] = $id_source;
466
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
467
-			    unset($data);
463
+				}
464
+				$data['format_source'] = 'aisnmeahttp';
465
+				$data['id_source'] = $id_source;
466
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
467
+				unset($data);
468 468
 			}
469
-		    }
469
+			}
470
+		}
470 471
 		}
471 472
 		}
472
-	    }
473 473
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
474
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
475
-	    if ($buffer != '') {
474
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
475
+		if ($buffer != '') {
476 476
 		//echo $buffer;
477 477
 		$all_data = json_decode($buffer,true);
478 478
 		//print_r($all_data);
479 479
 		if (isset($all_data[0]['DATA'])) {
480 480
 		foreach ($all_data[0]['DATA'] as $line) {
481
-		    if ($line != '') {
481
+			if ($line != '') {
482 482
 			$data = array();
483 483
 			$data['ident'] = $line['NAME'];
484 484
 			$data['mmsi'] = $line['MMSI'];
@@ -494,87 +494,87 @@  discard block
 block discarded – undo
494 494
 			$data['id_source'] = $id_source;
495 495
 			$MI->add($data);
496 496
 			unset($data);
497
-		    }
497
+			}
498 498
 		}
499 499
 		}
500 500
 		
501
-	    }
502
-    	    $last_exec[$id]['last'] = time();
501
+		}
502
+			$last_exec[$id]['last'] = time();
503 503
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
504
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
505
-	    if ($buffer != '') {
504
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
505
+		if ($buffer != '') {
506 506
 		$all_data = json_decode($buffer,true);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508
-		    foreach ($all_data as $line) {
508
+			foreach ($all_data as $line) {
509 509
 			if ($line != '') {
510
-			    $data = array();
511
-			    $data['ident'] = $line['shipname'];
512
-			    $data['callsign'] = $line['callsign'];
513
-			    $data['mmsi'] = $line['mmsi'];
514
-			    $data['speed'] = $line['sog'];
515
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
516
-			    $data['latitude'] = $line['latitude'];
517
-			    $data['longitude'] = $line['longitude'];
518
-			    $data['type_id'] = $line['shiptype'];
519
-			    $data['arrival_code'] = $line['destination'];
520
-			    $data['datetime'] = $line['time'];
521
-			    $data['format_source'] = 'boatbeaconapp';
522
-			    $data['id_source'] = $id_source;
523
-			    $MI->add($data);
524
-			    unset($data);
510
+				$data = array();
511
+				$data['ident'] = $line['shipname'];
512
+				$data['callsign'] = $line['callsign'];
513
+				$data['mmsi'] = $line['mmsi'];
514
+				$data['speed'] = $line['sog'];
515
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
516
+				$data['latitude'] = $line['latitude'];
517
+				$data['longitude'] = $line['longitude'];
518
+				$data['type_id'] = $line['shiptype'];
519
+				$data['arrival_code'] = $line['destination'];
520
+				$data['datetime'] = $line['time'];
521
+				$data['format_source'] = 'boatbeaconapp';
522
+				$data['id_source'] = $id_source;
523
+				$MI->add($data);
524
+				unset($data);
525
+			}
525 526
 			}
526
-		    }
527 527
 		}
528 528
 		
529
-	    }
530
-    	    $last_exec[$id]['last'] = time();
529
+		}
530
+			$last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532
-	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
-	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
538
-	    foreach ($buffer as $line) {
532
+		echo 'download...';
533
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
+		echo 'done !'."\n";
535
+		if ($buffer != '') $reset = 0;
536
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
+		$buffer = explode('\n',$buffer);
538
+		foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540
-		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
-		    //$data['status'] = substr($line,21,2);
544
-		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
548
-		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
550
-		    //$data['draft'] = substr($line,67,4);
551
-		    //$data['length'] = substr($line,72,3);
552
-		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
-		    //$data['callsign'] = trim(substr($line,100,7);
555
-		    //$data['dest'] = substr($line,108,20);
556
-		    //$data['etaDate'] = substr($line,129,5);
557
-		    //$data['etaTime'] = substr($line,135,5);
558
-		    $data['format_source'] = 'shipplotter';
559
-    		    $data['id_source'] = $id_source;
560
-		    print_r($data);
561
-		    echo 'Add...'."\n";
562
-		    $MI->add($data);
563
-		    unset($data);
540
+			$data = array();
541
+			$data['mmsi'] = (int)substr($line,0,9);
542
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
+			//$data['status'] = substr($line,21,2);
544
+			//$data['type'] = substr($line,24,3);
545
+			$data['latitude'] = substr($line,29,9);
546
+			$data['longitude'] = substr($line,41,9);
547
+			$data['speed'] = round(substr($line,51,5));
548
+			//$data['course'] = substr($line,57,5);
549
+			$data['heading'] = round(substr($line,63,3));
550
+			//$data['draft'] = substr($line,67,4);
551
+			//$data['length'] = substr($line,72,3);
552
+			//$data['beam'] = substr($line,76,2);
553
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
+			//$data['callsign'] = trim(substr($line,100,7);
555
+			//$data['dest'] = substr($line,108,20);
556
+			//$data['etaDate'] = substr($line,129,5);
557
+			//$data['etaTime'] = substr($line,135,5);
558
+			$data['format_source'] = 'shipplotter';
559
+				$data['id_source'] = $id_source;
560
+			print_r($data);
561
+			echo 'Add...'."\n";
562
+			$MI->add($data);
563
+			unset($data);
564 564
 		}
565
-    	    }
566
-    	    $last_exec[$id]['last'] = time();
565
+			}
566
+			$last_exec[$id]['last'] = time();
567 567
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569
-	    //$buffer = $Common->getData($hosts[$id]);
570
-	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
573
-	    $reset = 0;
574
-	    foreach ($buffer as $line) {
575
-    		if ($line != '') {
576
-    		    $line = explode(':', $line);
577
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
569
+		//$buffer = $Common->getData($hosts[$id]);
570
+		$buffer = $Common->getData($value['host']);
571
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
+		$buffer = explode('\n',$buffer);
573
+		$reset = 0;
574
+		foreach ($buffer as $line) {
575
+			if ($line != '') {
576
+				$line = explode(':', $line);
577
+				if (count($line) > 30 && $line[0] != 'callsign') {
578 578
 			$data = array();
579 579
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -587,36 +587,36 @@  discard block
 block discarded – undo
587 587
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588 588
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
589 589
 			$data['latitude'] = $line[5]; // lat
590
-	        	$data['longitude'] = $line[6]; // long
591
-	        	$data['verticalrate'] = ''; // vertical rate
592
-	        	$data['squawk'] = ''; // squawk
593
-	        	$data['emergency'] = ''; // emergency
594
-	        	$data['waypoints'] = $line[30];
590
+				$data['longitude'] = $line[6]; // long
591
+				$data['verticalrate'] = ''; // vertical rate
592
+				$data['squawk'] = ''; // squawk
593
+				$data['emergency'] = ''; // emergency
594
+				$data['waypoints'] = $line[30];
595 595
 			$data['datetime'] = date('Y-m-d H:i:s');
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598
-		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
-		        $data['arrival_airport_icao'] = $line[13];
598
+				$data['departure_airport_icao'] = $line[11];
599
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
+				$data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
603 603
 			$data['range'] = $line[19];
604 604
 			if (isset($line[35])) $data['info'] = $line[35];
605
-    			$data['id_source'] = $id_source;
606
-	    		//$data['arrival_airport_time'] = ;
607
-	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
609
-	    		    if (isset($aircraft_data[1])) {
610
-	    			$data['aircraft_icao'] = $aircraft_data[1];
611
-	    		    }
612
-        		}
613
-	    		/*
605
+				$data['id_source'] = $id_source;
606
+				//$data['arrival_airport_time'] = ;
607
+				if ($line[9] != '') {
608
+					$aircraft_data = explode('/',$line[9]);
609
+					if (isset($aircraft_data[1])) {
610
+					$data['aircraft_icao'] = $aircraft_data[1];
611
+					}
612
+				}
613
+				/*
614 614
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
615 615
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 616
 	    		*/
617
-	    		$data['format_source'] = $value['format'];
617
+				$data['format_source'] = $value['format'];
618 618
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
619
+				if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622 622
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -634,247 +634,247 @@  discard block
 block discarded – undo
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635 635
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
636 636
 			}
637
-    			unset($data);
638
-    		    }
639
-    		}
640
-    	    }
641
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
-    	    $last_exec[$id]['last'] = time();
644
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
647
-	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
649
-	    if (isset($all_data['acList'])) {
637
+				unset($data);
638
+				}
639
+			}
640
+			}
641
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
+			$last_exec[$id]['last'] = time();
644
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
647
+		if ($buffer != '') {
648
+		$all_data = json_decode($buffer,true);
649
+		if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
652
-		    $data = array();
653
-		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
-		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
-		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
-		    /*
652
+			$data = array();
653
+			$data['hex'] = $line['Icao']; // hex
654
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
+			//$data['verticalrate'] = $line['']; // verticale rate
661
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
+			$data['emergency'] = ''; // emergency
663
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
+			/*
665 665
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 666
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 667
 		    */
668
-		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
-	    	    $data['format_source'] = 'aircraftlistjson';
671
-		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['latitude'])) $SI->add($data);
674
-		    unset($data);
668
+			$data['datetime'] = date('Y-m-d H:i:s');
669
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
+				$data['format_source'] = 'aircraftlistjson';
671
+			$data['id_source'] = $id_source;
672
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
+			if (isset($data['latitude'])) $SI->add($data);
674
+			unset($data);
675 675
 		}
676
-	    } elseif (is_array($all_data)) {
676
+		} elseif (is_array($all_data)) {
677 677
 		$reset = 0;
678 678
 		foreach ($all_data as $line) {
679
-		    $data = array();
680
-		    $data['hex'] = $line['hex']; // hex
681
-		    $data['ident'] = $line['flight']; // ident
682
-		    $data['altitude'] = $line['altitude']; // altitude
683
-		    $data['speed'] = $line['speed']; // speed
684
-		    $data['heading'] = $line['track']; // heading
685
-		    $data['latitude'] = $line['lat']; // lat
686
-		    $data['longitude'] = $line['lon']; // long
687
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
688
-		    $data['squawk'] = $line['squawk']; // squawk
689
-		    $data['emergency'] = ''; // emergency
690
-		    $data['datetime'] = date('Y-m-d H:i:s');
691
-	    	    $data['format_source'] = 'aircraftlistjson';
692
-    		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
-		    $SI->add($data);
695
-		    unset($data);
679
+			$data = array();
680
+			$data['hex'] = $line['hex']; // hex
681
+			$data['ident'] = $line['flight']; // ident
682
+			$data['altitude'] = $line['altitude']; // altitude
683
+			$data['speed'] = $line['speed']; // speed
684
+			$data['heading'] = $line['track']; // heading
685
+			$data['latitude'] = $line['lat']; // lat
686
+			$data['longitude'] = $line['lon']; // long
687
+			$data['verticalrate'] = $line['vrt']; // verticale rate
688
+			$data['squawk'] = $line['squawk']; // squawk
689
+			$data['emergency'] = ''; // emergency
690
+			$data['datetime'] = date('Y-m-d H:i:s');
691
+				$data['format_source'] = 'aircraftlistjson';
692
+				$data['id_source'] = $id_source;
693
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
+			$SI->add($data);
695
+			unset($data);
696
+		}
696 697
 		}
697
-	    }
698
-	    }
699
-    	    //$last_exec['aircraftlistjson'] = time();
700
-    	    $last_exec[$id]['last'] = time();
701
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
-	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
705
-	    if (isset($all_data['planes'])) {
698
+		}
699
+			//$last_exec['aircraftlistjson'] = time();
700
+			$last_exec[$id]['last'] = time();
701
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
+		$buffer = $Common->getData($value['host']);
704
+		$all_data = json_decode($buffer,true);
705
+		if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
708
-		    $data = array();
709
-		    $data['hex'] = $key; // hex
710
-		    $data['ident'] = $line[3]; // ident
711
-		    $data['altitude'] = $line[6]; // altitude
712
-		    $data['speed'] = $line[8]; // speed
713
-		    $data['heading'] = $line[7]; // heading
714
-		    $data['latitude'] = $line[4]; // lat
715
-		    $data['longitude'] = $line[5]; // long
716
-		    //$data['verticalrate'] = $line[]; // verticale rate
717
-		    $data['squawk'] = $line[10]; // squawk
718
-		    $data['emergency'] = ''; // emergency
719
-		    $data['registration'] = $line[2];
720
-		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
722
-		    if (count($deparr) == 2) {
708
+			$data = array();
709
+			$data['hex'] = $key; // hex
710
+			$data['ident'] = $line[3]; // ident
711
+			$data['altitude'] = $line[6]; // altitude
712
+			$data['speed'] = $line[8]; // speed
713
+			$data['heading'] = $line[7]; // heading
714
+			$data['latitude'] = $line[4]; // lat
715
+			$data['longitude'] = $line[5]; // long
716
+			//$data['verticalrate'] = $line[]; // verticale rate
717
+			$data['squawk'] = $line[10]; // squawk
718
+			$data['emergency'] = ''; // emergency
719
+			$data['registration'] = $line[2];
720
+			$data['aircraft_icao'] = $line[0];
721
+			$deparr = explode('-',$line[1]);
722
+			if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725
-		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
-	    	    $data['format_source'] = 'planeupdatefaa';
728
-    		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
-		    $SI->add($data);
731
-		    unset($data);
725
+			}
726
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
+				$data['format_source'] = 'planeupdatefaa';
728
+				$data['id_source'] = $id_source;
729
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
+			$SI->add($data);
731
+			unset($data);
732
+		}
732 733
 		}
733
-	    }
734
-    	    //$last_exec['planeupdatefaa'] = time();
735
-    	    $last_exec[$id]['last'] = time();
736
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
-	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
739
-	    if (isset($all_data['states'])) {
734
+			//$last_exec['planeupdatefaa'] = time();
735
+			$last_exec[$id]['last'] = time();
736
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
+		$buffer = $Common->getData($value['host']);
738
+		$all_data = json_decode($buffer,true);
739
+		if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
742
-		    $data = array();
743
-		    $data['hex'] = $line[0]; // hex
744
-		    $data['ident'] = trim($line[1]); // ident
745
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
746
-		    $data['speed'] = round($line[9]*1.94384); // speed
747
-		    $data['heading'] = round($line[10]); // heading
748
-		    $data['latitude'] = $line[5]; // lat
749
-		    $data['longitude'] = $line[6]; // long
750
-		    $data['verticalrate'] = $line[11]; // verticale rate
751
-		    //$data['squawk'] = $line[10]; // squawk
752
-		    //$data['emergency'] = ''; // emergency
753
-		    //$data['registration'] = $line[2];
754
-		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
-	    	    $data['format_source'] = 'opensky';
757
-    		    $data['id_source'] = $id_source;
758
-		    $SI->add($data);
759
-		    unset($data);
742
+			$data = array();
743
+			$data['hex'] = $line[0]; // hex
744
+			$data['ident'] = trim($line[1]); // ident
745
+			$data['altitude'] = round($line[7]*3.28084); // altitude
746
+			$data['speed'] = round($line[9]*1.94384); // speed
747
+			$data['heading'] = round($line[10]); // heading
748
+			$data['latitude'] = $line[5]; // lat
749
+			$data['longitude'] = $line[6]; // long
750
+			$data['verticalrate'] = $line[11]; // verticale rate
751
+			//$data['squawk'] = $line[10]; // squawk
752
+			//$data['emergency'] = ''; // emergency
753
+			//$data['registration'] = $line[2];
754
+			//$data['aircraft_icao'] = $line[0];
755
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
+				$data['format_source'] = 'opensky';
757
+				$data['id_source'] = $id_source;
758
+			$SI->add($data);
759
+			unset($data);
760
+		}
760 761
 		}
761
-	    }
762
-    	    //$last_exec['planeupdatefaa'] = time();
763
-    	    $last_exec[$id]['last'] = time();
764
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
-	    //$buffer = $Common->getData($hosts[$id]);
767
-	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
770
-	    foreach ($all_data as $key => $line) {
762
+			//$last_exec['planeupdatefaa'] = time();
763
+			$last_exec[$id]['last'] = time();
764
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
+		//$buffer = $Common->getData($hosts[$id]);
767
+		$buffer = $Common->getData($value['host']);
768
+		$all_data = json_decode($buffer,true);
769
+		if (!empty($all_data)) $reset = 0;
770
+		foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772
-		    $data = array();
773
-		    $data['hex'] = $line[0];
774
-		    $data['ident'] = $line[16]; //$line[13]
775
-	    	    $data['altitude'] = $line[4]; // altitude
776
-	    	    $data['speed'] = $line[5]; // speed
777
-	    	    $data['heading'] = $line[3]; // heading
778
-	    	    $data['latitude'] = $line[1]; // lat
779
-	    	    $data['longitude'] = $line[2]; // long
780
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
781
-	    	    $data['squawk'] = $line[6]; // squawk
782
-	    	    $data['aircraft_icao'] = $line[8];
783
-	    	    $data['registration'] = $line[9];
784
-		    $data['departure_airport_iata'] = $line[11];
785
-		    $data['arrival_airport_iata'] = $line[12];
786
-	    	    $data['emergency'] = ''; // emergency
787
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
-	    	    $data['format_source'] = 'fr24json';
789
-    		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
-		    $SI->add($data);
792
-		    unset($data);
772
+			$data = array();
773
+			$data['hex'] = $line[0];
774
+			$data['ident'] = $line[16]; //$line[13]
775
+				$data['altitude'] = $line[4]; // altitude
776
+				$data['speed'] = $line[5]; // speed
777
+				$data['heading'] = $line[3]; // heading
778
+				$data['latitude'] = $line[1]; // lat
779
+				$data['longitude'] = $line[2]; // long
780
+				$data['verticalrate'] = $line[15]; // verticale rate
781
+				$data['squawk'] = $line[6]; // squawk
782
+				$data['aircraft_icao'] = $line[8];
783
+				$data['registration'] = $line[9];
784
+			$data['departure_airport_iata'] = $line[11];
785
+			$data['arrival_airport_iata'] = $line[12];
786
+				$data['emergency'] = ''; // emergency
787
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
+				$data['format_source'] = 'fr24json';
789
+				$data['id_source'] = $id_source;
790
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
+			$SI->add($data);
792
+			unset($data);
793
+		}
793 794
 		}
794
-	    }
795
-    	    //$last_exec['fr24json'] = time();
796
-    	    $last_exec[$id]['last'] = time();
797
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
801
-	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
805
-	    if (json_last_error() != JSON_ERROR_NONE) {
795
+			//$last_exec['fr24json'] = time();
796
+			$last_exec[$id]['last'] = time();
797
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
801
+		//echo $buffer;
802
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
803
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
+		$all_data = json_decode($buffer,true);
805
+		if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807
-	    }
808
-	    if (isset($all_data['mrkrs'])) {
807
+		}
808
+		if (isset($all_data['mrkrs'])) {
809 809
 		$reset = 0;
810 810
 		foreach ($all_data['mrkrs'] as $key => $line) {
811
-		    if (isset($line['inf'])) {
811
+			if (isset($line['inf'])) {
812 812
 			$data = array();
813 813
 			$data['hex'] = $line['inf']['ia'];
814 814
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
815
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
-	    		$data['latitude'] = $line['pt'][0]; // lat
819
-	    		$data['longitude'] = $line['pt'][1]; // long
820
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
-	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
815
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
+				$data['latitude'] = $line['pt'][0]; // lat
819
+				$data['longitude'] = $line['pt'][1]; // long
820
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
+				//$data['aircraft_icao'] = $line[8];
823
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826
-	    		//$data['emergency'] = ''; // emergency
826
+				//$data['emergency'] = ''; // emergency
827 827
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828
-	    		$data['format_source'] = 'radarvirtueljson';
829
-    			$data['id_source'] = $id_source;
828
+				$data['format_source'] = 'radarvirtueljson';
829
+				$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
831 831
 			$SI->add($data);
832 832
 			unset($data);
833
-		    }
833
+			}
834 834
 		}
835
-	    }
836
-    	    //$last_exec['radarvirtueljson'] = time();
837
-    	    $last_exec[$id]['last'] = time();
838
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
-	    //$buffer = $Common->getData($hosts[$id]);
841
-	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
835
+		}
836
+			//$last_exec['radarvirtueljson'] = time();
837
+			$last_exec[$id]['last'] = time();
838
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
+		//$buffer = $Common->getData($hosts[$id]);
841
+		$buffer = $Common->getData($value['host'].'?'.time());
842
+		$all_data = json_decode(utf8_encode($buffer),true);
843 843
 	    
844
-	    if (isset($all_data['pireps'])) {
844
+		if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846
-	        foreach ($all_data['pireps'] as $line) {
847
-		    $data = array();
848
-		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
-		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
-		    $data['latitude'] = $line['lat']; // lat
858
-		    $data['longitude'] = $line['lon']; // long
859
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860
-		    //$data['squawk'] = $line['squawk']; // squawk
861
-		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
-		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
870
-		    $data['format_source'] = 'pireps';
871
-    		    $data['id_source'] = $id_source;
872
-		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
-		    if ($line['icon'] == 'plane') {
846
+			foreach ($all_data['pireps'] as $line) {
847
+			$data = array();
848
+			$data['id'] = $line['id'];
849
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
+			$data['ident'] = $line['callsign']; // ident
851
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
+			$data['latitude'] = $line['lat']; // lat
858
+			$data['longitude'] = $line['lon']; // long
859
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
860
+			//$data['squawk'] = $line['squawk']; // squawk
861
+			//$data['emergency'] = ''; // emergency
862
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
+			//$data['arrival_airport_time'] = $line['arrtime'];
866
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
869
+			else $data['info'] = '';
870
+			$data['format_source'] = 'pireps';
871
+				$data['id_source'] = $id_source;
872
+			$data['datetime'] = date('Y-m-d H:i:s');
873
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
+			if ($line['icon'] == 'plane') {
875 875
 			$SI->add($data);
876
-		    //    print_r($data);
877
-    		    } elseif ($line['icon'] == 'ct') {
876
+			//    print_r($data);
877
+				} elseif ($line['icon'] == 'ct') {
878 878
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879 879
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 880
 			$typec = substr($data['ident'],-3);
@@ -889,190 +889,190 @@  discard block
 block discarded – undo
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891 891
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
892
-		    }
893
-		    unset($data);
892
+			}
893
+			unset($data);
894 894
 		}
895
-	    }
896
-    	    //$last_exec['pirepsjson'] = time();
897
-    	    $last_exec[$id]['last'] = time();
898
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
-	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
902
-	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
904
-	    if ($buffer != '' && is_array($all_data)) {
895
+		}
896
+			//$last_exec['pirepsjson'] = time();
897
+			$last_exec[$id]['last'] = time();
898
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
+		//$buffer = $Common->getData($hosts[$id]);
901
+		if ($globalDebug) echo 'Get Data...'."\n";
902
+		$buffer = $Common->getData($value['host']);
903
+		$all_data = json_decode($buffer,true);
904
+		if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907
-	    	    $data = array();
908
-	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
-	    	    $data['ident'] = $line['flightnum']; // ident
914
-	    	    $data['altitude'] = $line['alt']; // altitude
915
-	    	    $data['speed'] = $line['gs']; // speed
916
-	    	    $data['heading'] = $line['heading']; // heading
917
-	    	    $data['latitude'] = $line['lat']; // lat
918
-	    	    $data['longitude'] = $line['lng']; // long
919
-	    	    $data['verticalrate'] = ''; // verticale rate
920
-	    	    $data['squawk'] = ''; // squawk
921
-	    	    $data['emergency'] = ''; // emergency
922
-	    	    //$data['datetime'] = $line['lastupdate'];
923
-	    	    $data['last_update'] = $line['lastupdate'];
924
-		    $data['datetime'] = date('Y-m-d H:i:s');
925
-	    	    $data['departure_airport_icao'] = $line['depicao'];
926
-	    	    $data['departure_airport_time'] = $line['deptime'];
927
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
928
-    		    $data['arrival_airport_time'] = $line['arrtime'];
929
-    		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
-		    if (isset($line['aircraftname'])) {
907
+				$data = array();
908
+				//$data['id'] = $line['id']; // id not usable
909
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
+				$data['ident'] = $line['flightnum']; // ident
914
+				$data['altitude'] = $line['alt']; // altitude
915
+				$data['speed'] = $line['gs']; // speed
916
+				$data['heading'] = $line['heading']; // heading
917
+				$data['latitude'] = $line['lat']; // lat
918
+				$data['longitude'] = $line['lng']; // long
919
+				$data['verticalrate'] = ''; // verticale rate
920
+				$data['squawk'] = ''; // squawk
921
+				$data['emergency'] = ''; // emergency
922
+				//$data['datetime'] = $line['lastupdate'];
923
+				$data['last_update'] = $line['lastupdate'];
924
+			$data['datetime'] = date('Y-m-d H:i:s');
925
+				$data['departure_airport_icao'] = $line['depicao'];
926
+				$data['departure_airport_time'] = $line['deptime'];
927
+				$data['arrival_airport_icao'] = $line['arricao'];
928
+				$data['arrival_airport_time'] = $line['arrtime'];
929
+				$data['registration'] = $line['aircraft'];
930
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
+			if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 933
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941
-	    		}
942
-	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
-    		    $data['id_source'] = $id_source;
945
-	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
-		    $SI->add($data);
948
-		    unset($data);
934
+				$aircraft_data = explode('-',$line['aircraftname']);
935
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
+				else {
938
+					$aircraft_data = explode(' ',$line['aircraftname']);
939
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
+					else $data['aircraft_icao'] = $line['aircraftname'];
941
+				}
942
+				}
943
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
+				$data['id_source'] = $id_source;
945
+				$data['format_source'] = 'phpvmacars';
946
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
+			$SI->add($data);
948
+			unset($data);
949 949
 		}
950 950
 		if ($globalDebug) echo 'No more data...'."\n";
951 951
 		unset($buffer);
952 952
 		unset($all_data);
953
-	    }
954
-    	    //$last_exec['phpvmacars'] = time();
955
-    	    $last_exec[$id]['last'] = time();
956
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
-	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
959
-	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
961
-	    if ($buffer != '' && is_array($all_data)) {
953
+		}
954
+			//$last_exec['phpvmacars'] = time();
955
+			$last_exec[$id]['last'] = time();
956
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
+		//$buffer = $Common->getData($hosts[$id]);
958
+		if ($globalDebug) echo 'Get Data...'."\n";
959
+		$buffer = $Common->getData($value['host']);
960
+		$all_data = json_decode($buffer,true);
961
+		if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964
-	    	    $data = array();
965
-	    	    //$data['id'] = $line['id']; // id not usable
966
-	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
-	    	    $data['pilot_name'] = $line['pilot_name'];
969
-	    	    $data['pilot_id'] = $line['pilot_id'];
970
-	    	    $data['ident'] = trim($line['callsign']); // ident
971
-	    	    $data['altitude'] = $line['altitude']; // altitude
972
-	    	    $data['speed'] = $line['gs']; // speed
973
-	    	    $data['heading'] = $line['heading']; // heading
974
-	    	    $data['latitude'] = $line['latitude']; // lat
975
-	    	    $data['longitude'] = $line['longitude']; // long
976
-	    	    $data['verticalrate'] = ''; // verticale rate
977
-	    	    $data['squawk'] = ''; // squawk
978
-	    	    $data['emergency'] = ''; // emergency
979
-	    	    //$data['datetime'] = $line['lastupdate'];
980
-	    	    $data['last_update'] = $line['last_update'];
981
-		    $data['datetime'] = date('Y-m-d H:i:s');
982
-	    	    $data['departure_airport_icao'] = $line['departure'];
983
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
984
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
985
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
986
-    		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
-	    	    $data['aircraft_icao'] = $line['plane_type'];
989
-    		    $data['id_source'] = $id_source;
990
-	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
-		    $SI->add($data);
993
-		    unset($data);
964
+				$data = array();
965
+				//$data['id'] = $line['id']; // id not usable
966
+				$data['id'] = trim($line['flight_id']);
967
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
+				$data['pilot_name'] = $line['pilot_name'];
969
+				$data['pilot_id'] = $line['pilot_id'];
970
+				$data['ident'] = trim($line['callsign']); // ident
971
+				$data['altitude'] = $line['altitude']; // altitude
972
+				$data['speed'] = $line['gs']; // speed
973
+				$data['heading'] = $line['heading']; // heading
974
+				$data['latitude'] = $line['latitude']; // lat
975
+				$data['longitude'] = $line['longitude']; // long
976
+				$data['verticalrate'] = ''; // verticale rate
977
+				$data['squawk'] = ''; // squawk
978
+				$data['emergency'] = ''; // emergency
979
+				//$data['datetime'] = $line['lastupdate'];
980
+				$data['last_update'] = $line['last_update'];
981
+			$data['datetime'] = date('Y-m-d H:i:s');
982
+				$data['departure_airport_icao'] = $line['departure'];
983
+				//$data['departure_airport_time'] = $line['departure_time'];
984
+				$data['arrival_airport_icao'] = $line['arrival'];
985
+				//$data['arrival_airport_time'] = $line['arrival_time'];
986
+				//$data['registration'] = $line['aircraft'];
987
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
+				$data['aircraft_icao'] = $line['plane_type'];
989
+				$data['id_source'] = $id_source;
990
+				$data['format_source'] = 'vam';
991
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
+			$SI->add($data);
993
+			unset($data);
994 994
 		}
995 995
 		if ($globalDebug) echo 'No more data...'."\n";
996 996
 		unset($buffer);
997 997
 		unset($all_data);
998
-	    }
999
-    	    //$last_exec['phpvmacars'] = time();
1000
-    	    $last_exec[$id]['last'] = time();
998
+		}
999
+			//$last_exec['phpvmacars'] = time();
1000
+			$last_exec[$id]['last'] = time();
1001 1001
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1002
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
-    	    //$last_exec[$id]['last'] = time();
1003
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
+			//$last_exec[$id]['last'] = time();
1005 1005
 
1006
-	    //$read = array( $sockets[$id] );
1007
-	    $read = $sockets;
1008
-	    $write = NULL;
1009
-	    $e = NULL;
1010
-	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1012
-	    if ($n > 0) {
1006
+		//$read = array( $sockets[$id] );
1007
+		$read = $sockets;
1008
+		$write = NULL;
1009
+		$e = NULL;
1010
+		$n = socket_select($read, $write, $e, $timeout);
1011
+		if ($e != NULL) var_dump($e);
1012
+		if ($n > 0) {
1013 1013
 		$reset = 0;
1014 1014
 		foreach ($read as $nb => $r) {
1015
-		    //$value = $formats[$nb];
1016
-		    $format = $globalSources[$nb]['format'];
1017
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
-        	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
-	    	    }
1022
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
-        	    //echo $buffer."\n";
1024
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1025
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
-		    $error = false;
1027
-		    //$SI::del();
1028
-		    if ($format == 'vrstcp') {
1015
+			//$value = $formats[$nb];
1016
+			$format = $globalSources[$nb]['format'];
1017
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1018
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
+				} else {
1020
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
+				}
1022
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
+				//echo $buffer."\n";
1024
+			// lets play nice and handle signals such as ctrl-c/kill properly
1025
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
+			$error = false;
1027
+			//$SI::del();
1028
+			if ($format == 'vrstcp') {
1029 1029
 			$buffer = explode('},{',$buffer);
1030
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1031
-		    // SBS format is CSV format
1032
-		    if ($buffer != '') {
1030
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1031
+			// SBS format is CSV format
1032
+			if ($buffer != '') {
1033 1033
 			$tt[$format] = 0;
1034 1034
 			if ($format == 'acarssbs3') {
1035
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1036
-			    $ACARS->add(trim($buffer));
1037
-			    $ACARS->deleteLiveAcarsData();
1035
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1036
+				$ACARS->add(trim($buffer));
1037
+				$ACARS->deleteLiveAcarsData();
1038 1038
 			} elseif ($format == 'raw') {
1039
-			    // AVR format
1040
-			    $data = $SBS->parse($buffer);
1041
-			    if (is_array($data)) {
1039
+				// AVR format
1040
+				$data = $SBS->parse($buffer);
1041
+				if (is_array($data)) {
1042 1042
 				$data['datetime'] = date('Y-m-d H:i:s');
1043 1043
 				$data['format_source'] = 'raw';
1044 1044
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1045
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1046
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1047
-                            }
1048
-                        } elseif ($format == 'ais') {
1049
-			    $ais_data = $AIS->parse_line(trim($buffer));
1050
-			    $data = array();
1051
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1052
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1053
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1054
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1055
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1056
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1057
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1058
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1059
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1060
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1061
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1062
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1045
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1046
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1047
+							}
1048
+						} elseif ($format == 'ais') {
1049
+				$ais_data = $AIS->parse_line(trim($buffer));
1050
+				$data = array();
1051
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1052
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1053
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1054
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1055
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1056
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1057
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1058
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1059
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1060
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1061
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1062
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1063 1063
 
1064
-			    if (isset($ais_data['timestamp'])) {
1064
+				if (isset($ais_data['timestamp'])) {
1065 1065
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1066
-			    } else {
1066
+				} else {
1067 1067
 				$data['datetime'] = date('Y-m-d H:i:s');
1068
-			    }
1069
-			    $data['format_source'] = 'aisnmea';
1070
-    			    $data['id_source'] = $id_source;
1071
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1072
-			    unset($data);
1073
-                        } elseif ($format == 'flightgearsp') {
1074
-                    	    //echo $buffer."\n";
1075
-                    	    if (strlen($buffer) > 5) {
1068
+				}
1069
+				$data['format_source'] = 'aisnmea';
1070
+					$data['id_source'] = $id_source;
1071
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1072
+				unset($data);
1073
+						} elseif ($format == 'flightgearsp') {
1074
+							//echo $buffer."\n";
1075
+							if (strlen($buffer) > 5) {
1076 1076
 				$line = explode(',',$buffer);
1077 1077
 				$data = array();
1078 1078
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1088,37 +1088,37 @@  discard block
 block discarded – undo
1088 1088
 				$data['format_source'] = 'flightgearsp';
1089 1089
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1090 1090
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1091
-			    }
1092
-                        } elseif ($format == 'acars') {
1093
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1094
-			    $ACARS->add(trim($buffer));
1095
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1096
-			    $ACARS->deleteLiveAcarsData();
1091
+				}
1092
+						} elseif ($format == 'acars') {
1093
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1094
+				$ACARS->add(trim($buffer));
1095
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1096
+				$ACARS->deleteLiveAcarsData();
1097 1097
 			} elseif ($format == 'flightgearmp') {
1098
-			    if (substr($buffer,0,1) != '#') {
1098
+				if (substr($buffer,0,1) != '#') {
1099 1099
 				$data = array();
1100 1100
 				//echo $buffer."\n";
1101 1101
 				$line = explode(' ',$buffer);
1102 1102
 				if (count($line) == 11) {
1103
-				    $userserver = explode('@',$line[0]);
1104
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1105
-				    $data['ident'] = $userserver[0];
1106
-				    $data['registration'] = $userserver[0];
1107
-				    $data['latitude'] = $line[4];
1108
-				    $data['longitude'] = $line[5];
1109
-				    $data['altitude'] = $line[6];
1110
-				    $data['datetime'] = date('Y-m-d H:i:s');
1111
-				    $aircraft_type = $line[10];
1112
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1113
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1114
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1103
+					$userserver = explode('@',$line[0]);
1104
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1105
+					$data['ident'] = $userserver[0];
1106
+					$data['registration'] = $userserver[0];
1107
+					$data['latitude'] = $line[4];
1108
+					$data['longitude'] = $line[5];
1109
+					$data['altitude'] = $line[6];
1110
+					$data['datetime'] = date('Y-m-d H:i:s');
1111
+					$aircraft_type = $line[10];
1112
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1113
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1114
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1115
+				}
1115 1116
 				}
1116
-			    }
1117 1117
 			} elseif ($format == 'beast') {
1118
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1119
-			    die;
1118
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1119
+				die;
1120 1120
 			} elseif ($format == 'vrstcp') {
1121
-			    foreach($buffer as $all_data) {
1121
+				foreach($buffer as $all_data) {
1122 1122
 				$line = json_decode('{'.$all_data.'}',true);
1123 1123
 				$data = array();
1124 1124
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1138,100 +1138,100 @@  discard block
 block discarded – undo
1138 1138
 				*/
1139 1139
 				$data['datetime'] = date('Y-m-d H:i:s');
1140 1140
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1141
-		    		$data['format_source'] = 'vrstcp';
1141
+					$data['format_source'] = 'vrstcp';
1142 1142
 				$data['id_source'] = $id_source;
1143 1143
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1144 1144
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1145 1145
 				unset($data);
1146
-			    }
1146
+				}
1147 1147
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1148
-			    $line = explode("\t", $buffer);
1149
-			    for($k = 0; $k < count($line); $k=$k+2) {
1148
+				$line = explode("\t", $buffer);
1149
+				for($k = 0; $k < count($line); $k=$k+2) {
1150 1150
 				$key = $line[$k];
1151
-			        $lined[$key] = $line[$k+1];
1152
-			    }
1153
-    			    if (count($lined) > 3) {
1154
-    				$data['hex'] = $lined['hexid'];
1155
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1156
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1157
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1158
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1159
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1160
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1161
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1162
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1163
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1164
-    				$data['id_source'] = $id_source;
1165
-    				$data['format_source'] = 'tsv';
1166
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1167
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1168
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1169
-    				unset($lined);
1170
-    				unset($data);
1171
-    			    } else $error = true;
1151
+					$lined[$key] = $line[$k+1];
1152
+				}
1153
+					if (count($lined) > 3) {
1154
+					$data['hex'] = $lined['hexid'];
1155
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1156
+					$data['datetime'] = date('Y-m-d H:i:s');;
1157
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1158
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1159
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1160
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1161
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1162
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1163
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1164
+					$data['id_source'] = $id_source;
1165
+					$data['format_source'] = 'tsv';
1166
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1167
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1168
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1169
+					unset($lined);
1170
+					unset($data);
1171
+					} else $error = true;
1172 1172
 			} elseif ($format == 'aprs' && $use_aprs) {
1173
-			    if ($aprs_connect == 0) {
1173
+				if ($aprs_connect == 0) {
1174 1174
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1175 1175
 				$aprs_connect = 1;
1176
-			    }
1176
+				}
1177 1177
 			    
1178
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1178
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1179 1179
 				$aprs_last_tx = time();
1180 1180
 				$data_aprs = "# Keep alive";
1181 1181
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1182
-			    }
1182
+				}
1183 1183
 			    
1184
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1185
-			    //echo 'APRS data : '.$buffer."\n";
1186
-			    $buffer = str_replace('APRS <- ','',$buffer);
1187
-			    $buffer = str_replace('APRS -> ','',$buffer);
1188
-			    echo $buffer."\n";
1189
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1184
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1185
+				//echo 'APRS data : '.$buffer."\n";
1186
+				$buffer = str_replace('APRS <- ','',$buffer);
1187
+				$buffer = str_replace('APRS -> ','',$buffer);
1188
+				echo $buffer."\n";
1189
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1190 1190
 				$line = $APRS->parse($buffer);
1191 1191
 				//print_r($line);
1192 1192
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1193 1193
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']))) {
1194
-				    $aprs_last_tx = time();
1195
-				    $data = array();
1196
-				    //print_r($line);
1197
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1198
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1199
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1200
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1201
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1202
-				    $data['latitude'] = $line['latitude'];
1203
-				    $data['longitude'] = $line['longitude'];
1204
-				    //$data['verticalrate'] = $line[16];
1205
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1206
-				    else $data['speed'] = 0;
1207
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1208
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1209
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1210
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1211
-				    //else $data['heading'] = 0;
1212
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1213
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1214
-    				    $data['id_source'] = $id_source;
1215
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1216
-				    else $data['format_source'] = 'aprs';
1217
-				    $data['source_name'] = $line['source'];
1218
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1219
-				    else $data['source_type'] = 'flarm';
1220
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1221
-				    $currentdate = date('Y-m-d H:i:s');
1222
-				    $aprsdate = strtotime($data['datetime']);
1223
-				    // Accept data if time <= system time + 20s
1224
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1194
+					$aprs_last_tx = time();
1195
+					$data = array();
1196
+					//print_r($line);
1197
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1198
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1199
+					else $data['datetime'] = date('Y-m-d H:i:s');
1200
+					//$data['datetime'] = date('Y-m-d H:i:s');
1201
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1202
+					$data['latitude'] = $line['latitude'];
1203
+					$data['longitude'] = $line['longitude'];
1204
+					//$data['verticalrate'] = $line[16];
1205
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1206
+					else $data['speed'] = 0;
1207
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1208
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1209
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1210
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1211
+					//else $data['heading'] = 0;
1212
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1213
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1214
+						$data['id_source'] = $id_source;
1215
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1216
+					else $data['format_source'] = 'aprs';
1217
+					$data['source_name'] = $line['source'];
1218
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1219
+					else $data['source_type'] = 'flarm';
1220
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1221
+					$currentdate = date('Y-m-d H:i:s');
1222
+					$aprsdate = strtotime($data['datetime']);
1223
+					// Accept data if time <= system time + 20s
1224
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1225 1225
 					$send = $SI->add($data);
1226
-				    } elseif (isset($line['stealth'])) {
1226
+					} elseif (isset($line['stealth'])) {
1227 1227
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1228 1228
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1229
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1230
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1229
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1230
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1231 1231
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1232 1232
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1233
-				    }
1234
-				    unset($data);
1233
+					}
1234
+					unset($data);
1235 1235
 				} 
1236 1236
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1237 1237
 					echo '!! Weather Station not yet supported'."\n";
@@ -1241,12 +1241,12 @@  discard block
 block discarded – undo
1241 1241
 				}
1242 1242
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1243 1243
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1244
-			    }
1244
+				}
1245 1245
 			} else {
1246
-			    $line = explode(',', $buffer);
1247
-    			    if (count($line) > 20) {
1248
-    			    	$data['hex'] = $line[4];
1249
-    				/*
1246
+				$line = explode(',', $buffer);
1247
+					if (count($line) > 20) {
1248
+						$data['hex'] = $line[4];
1249
+					/*
1250 1250
     				$data['datetime'] = $line[6].' '.$line[7];
1251 1251
     					date_default_timezone_set($globalTimezone);
1252 1252
     					$datetime = new DateTime($data['datetime']);
@@ -1254,29 +1254,29 @@  discard block
 block discarded – undo
1254 1254
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1255 1255
     					date_default_timezone_set('UTC');
1256 1256
     				*/
1257
-    				// Force datetime to current UTC datetime
1258
-    				date_default_timezone_set('UTC');
1259
-    				$data['datetime'] = date('Y-m-d H:i:s');
1260
-    				$data['ident'] = trim($line[10]);
1261
-    				$data['latitude'] = $line[14];
1262
-    				$data['longitude'] = $line[15];
1263
-    				$data['verticalrate'] = $line[16];
1264
-    				$data['emergency'] = $line[20];
1265
-    				$data['speed'] = $line[12];
1266
-    				$data['squawk'] = $line[17];
1267
-    				$data['altitude'] = $line[11];
1268
-    				$data['heading'] = $line[13];
1269
-    				$data['ground'] = $line[21];
1270
-    				$data['emergency'] = $line[19];
1271
-    				$data['format_source'] = 'sbs';
1257
+					// Force datetime to current UTC datetime
1258
+					date_default_timezone_set('UTC');
1259
+					$data['datetime'] = date('Y-m-d H:i:s');
1260
+					$data['ident'] = trim($line[10]);
1261
+					$data['latitude'] = $line[14];
1262
+					$data['longitude'] = $line[15];
1263
+					$data['verticalrate'] = $line[16];
1264
+					$data['emergency'] = $line[20];
1265
+					$data['speed'] = $line[12];
1266
+					$data['squawk'] = $line[17];
1267
+					$data['altitude'] = $line[11];
1268
+					$data['heading'] = $line[13];
1269
+					$data['ground'] = $line[21];
1270
+					$data['emergency'] = $line[19];
1271
+					$data['format_source'] = 'sbs';
1272 1272
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1273
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1274
-    				$data['id_source'] = $id_source;
1275
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1276
-    				else $error = true;
1277
-    				unset($data);
1278
-    			    } else $error = true;
1279
-			    if ($error) {
1273
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1274
+					$data['id_source'] = $id_source;
1275
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1276
+					else $error = true;
1277
+					unset($data);
1278
+					} else $error = true;
1279
+				if ($error) {
1280 1280
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1281 1281
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1282 1282
 				} else {
@@ -1292,13 +1292,13 @@  discard block
 block discarded – undo
1292 1292
 					connect_all($sourceer);
1293 1293
 					$sourceer = array();
1294 1294
 				}
1295
-			    }
1295
+				}
1296 1296
 			}
1297 1297
 			// Sleep for xxx microseconds
1298 1298
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1299
-		    } else {
1299
+			} else {
1300 1300
 			if ($format == 'flightgearmp') {
1301
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1301
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1302 1302
 				//@socket_close($r);
1303 1303
 				sleep($globalMinFetch);
1304 1304
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1307,9 +1307,9 @@  discard block
 block discarded – undo
1307 1307
 				break;
1308 1308
 				
1309 1309
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1310
-			    if (isset($tt[$format])) $tt[$format]++;
1311
-			    else $tt[$format] = 0;
1312
-			    if ($tt[$format] > 30) {
1310
+				if (isset($tt[$format])) $tt[$format]++;
1311
+				else $tt[$format] = 0;
1312
+				if ($tt[$format] > 30) {
1313 1313
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1314 1314
 				//@socket_close($r);
1315 1315
 				sleep(2);
@@ -1320,23 +1320,23 @@  discard block
 block discarded – undo
1320 1320
 				//connect_all($globalSources);
1321 1321
 				$tt[$format]=0;
1322 1322
 				break;
1323
-			    }
1323
+				}
1324
+			}
1324 1325
 			}
1325
-		    }
1326 1326
 		}
1327
-	    } else {
1327
+		} else {
1328 1328
 		$error = socket_strerror(socket_last_error());
1329 1329
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1330 1330
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1331 1331
 			if (isset($globalDebug)) echo "Restarting...\n";
1332 1332
 			// Restart the script if possible
1333 1333
 			if (is_array($sockets)) {
1334
-			    if ($globalDebug) echo "Shutdown all sockets...";
1334
+				if ($globalDebug) echo "Shutdown all sockets...";
1335 1335
 			    
1336
-			    foreach ($sockets as $sock) {
1336
+				foreach ($sockets as $sock) {
1337 1337
 				@socket_shutdown($sock,2);
1338 1338
 				@socket_close($sock);
1339
-			    }
1339
+				}
1340 1340
 			    
1341 1341
 			}
1342 1342
 			if ($globalDebug) echo "Restart all connections...";
@@ -1347,13 +1347,13 @@  discard block
 block discarded – undo
1347 1347
 			if ($reset > 40) exit('Too many attempts...');
1348 1348
 			connect_all($globalSources);
1349 1349
 		}
1350
-	    }
1350
+		}
1351 1351
 	}
1352 1352
 	if ($globalDaemon === false) {
1353
-	    if ($globalDebug) echo 'Check all...'."\n";
1354
-	    $SI->checkAll();
1353
+		if ($globalDebug) echo 'Check all...'."\n";
1354
+		$SI->checkAll();
1355
+	}
1355 1356
 	}
1356
-    }
1357 1357
 }
1358 1358
 
1359 1359
 ?>
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','nodaemon','idsource::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 else $id_source = 1;
66 66
 if (isset($globalServer) && $globalServer) {
67 67
     if ($globalDebug) echo "Using Server Mode\n";
68
-    $SI=new SpotterServer();
68
+    $SI = new SpotterServer();
69 69
 /*
70 70
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
71 71
     $SI = new adsb2aprs();
72 72
     $SI->connect();
73 73
 */
74
-} else $SI=new SpotterImport($Connection->db);
74
+} else $SI = new SpotterImport($Connection->db);
75 75
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
76 76
 if (isset($globalMarine) && $globalMarine) {
77 77
     $AIS = new AIS();
78 78
     $MI = new MarineImport($Connection->db);
79 79
 }
80 80
 //$APRS=new APRS($Connection->db);
81
-$SBS=new SBS();
82
-$ACARS=new ACARS($Connection->db);
83
-$Common=new Common();
81
+$SBS = new SBS();
82
+$ACARS = new ACARS($Connection->db);
83
+$Common = new Common();
84 84
 date_default_timezone_set('UTC');
85 85
 //$servertz = system('date +%Z');
86 86
 // signal handler - playing nice with sockets and dump1090
87 87
 if (function_exists('pcntl_fork')) {
88
-    pcntl_signal(SIGINT,  function() {
88
+    pcntl_signal(SIGINT, function() {
89 89
         global $sockets;
90 90
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
91 91
         die("Bye!\n");
@@ -101,35 +101,35 @@  discard block
 block discarded – undo
101 101
 
102 102
 function connect_all($hosts) {
103 103
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
105 105
     $reset++;
106 106
     if ($globalDebug) echo 'Connect to all...'."\n";
107 107
     foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
111
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
+            if (preg_match('/deltadb.txt$/i', $host)) {
113 113
         	//$formats[$id] = 'deltadbtxt';
114 114
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 115
         	//$last_exec['deltadbtxt'] = 0;
116 116
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
118 118
         	//$formats[$id] = 'vatsimtxt';
119 119
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 120
         	//$last_exec['vatsimtxt'] = 0;
121 121
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
123 123
         	//$formats[$id] = 'aircraftlistjson';
124 124
         	$globalSources[$id]['format'] = 'aircraftlistjson';
125 125
         	//$last_exec['aircraftlistjson'] = 0;
126 126
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/opensky/i',$host)) {
127
+    	    } else if (preg_match('/opensky/i', $host)) {
128 128
         	//$formats[$id] = 'aircraftlistjson';
129 129
         	$globalSources[$id]['format'] = 'opensky';
130 130
         	//$last_exec['aircraftlistjson'] = 0;
131 131
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
132
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
133 133
         	//$formats[$id] = 'radarvirtueljson';
134 134
         	$globalSources[$id]['format'] = 'radarvirtueljson';
135 135
         	//$last_exec['radarvirtueljson'] = 0;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139 139
         	    exit(0);
140 140
         	}
141
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
142 142
         	//$formats[$id] = 'planeupdatefaa';
143 143
         	$globalSources[$id]['format'] = 'planeupdatefaa';
144 144
         	//$last_exec['planeupdatefaa'] = 0;
@@ -147,26 +147,26 @@  discard block
 block discarded – undo
147 147
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148 148
         	    exit(0);
149 149
         	}
150
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
151 151
         	//$formats[$id] = 'phpvmacars';
152 152
         	$globalSources[$id]['format'] = 'phpvmacars';
153 153
         	//$last_exec['phpvmacars'] = 0;
154 154
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
155
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
156 156
         	//$formats[$id] = 'phpvmacars';
157 157
         	$globalSources[$id]['format'] = 'vam';
158 158
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
159
-            } else if (preg_match('/whazzup/i',$host)) {
159
+            } else if (preg_match('/whazzup/i', $host)) {
160 160
         	//$formats[$id] = 'whazzup';
161 161
         	$globalSources[$id]['format'] = 'whazzup';
162 162
         	//$last_exec['whazzup'] = 0;
163 163
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
164
-            } else if (preg_match('/recentpireps/i',$host)) {
164
+            } else if (preg_match('/recentpireps/i', $host)) {
165 165
         	//$formats[$id] = 'pirepsjson';
166 166
         	$globalSources[$id]['format'] = 'pirepsjson';
167 167
         	//$last_exec['pirepsjson'] = 0;
168 168
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
169
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
170 170
         	//$formats[$id] = 'fr24json';
171 171
         	$globalSources[$id]['format'] = 'fr24json';
172 172
         	//$last_exec['fr24json'] = 0;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176 176
         	    exit(0);
177 177
         	}
178
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
179 179
         	//$formats[$id] = 'fr24json';
180 180
         	$globalSources[$id]['format'] = 'myshiptracking';
181 181
         	//$last_exec['fr24json'] = 0;
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         	    exit(0);
186 186
         	}
187 187
             //} else if (preg_match('/10001/',$host)) {
188
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189 189
         	//$formats[$id] = 'tsv';
190 190
         	$globalSources[$id]['format'] = 'tsv';
191 191
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
192 192
             }
193
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
194 194
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
196 196
     		    if ($idf !== false) {
197 197
     			$httpfeeds[$id] = $idf;
198 198
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
199 199
     		    }
200 200
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201 201
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
202
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203
-	    $hostport = explode(':',$host);
202
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
203
+	    $hostport = explode(':', $host);
204 204
 	    if (isset($hostport[1])) {
205 205
 		$port = $hostport[1];
206 206
 		$hostn = $hostport[0];
@@ -210,19 +210,19 @@  discard block
 block discarded – undo
210 210
 	    }
211 211
 	    $Common = new Common();
212 212
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
213
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
214 214
     	    } else {
215
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
216 216
 	    }
217 217
 	    if ($s) {
218 218
     	        $sockets[$id] = $s;
219 219
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
220
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
221 221
 			//$formats[$id] = 'aprs';
222 222
 			$globalSources[$id]['format'] = 'aprs';
223 223
 			//$aprs_connect = 0;
224 224
 			//$use_aprs = true;
225
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
225
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
226 226
 			$globalSources[$id]['format'] = 'vrstcp';
227 227
     		    } elseif ($port == '10001') {
228 228
         		//$formats[$id] = 'tsv';
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
262 262
 else $timeout = 20;
263 263
 $errno = '';
264
-$errstr='';
264
+$errstr = '';
265 265
 
266 266
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
267 267
 /* Initiate connections to all the hosts simultaneously */
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 //connect_all($globalSources);
270 270
 
271 271
 if (isset($globalProxy) && $globalProxy) {
272
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
272
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
273 273
 } else {
274 274
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
275 275
 }
@@ -296,16 +296,16 @@  discard block
 block discarded – undo
296 296
 
297 297
 if ($use_aprs) {
298 298
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
299
-	$APRS=new APRS();
299
+	$APRS = new APRS();
300 300
 	$aprs_connect = 0;
301 301
 	$aprs_keep = 120;
302 302
 	$aprs_last_tx = time();
303 303
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
304
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
304
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
305 305
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
306
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
306
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
307 307
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
308
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
308
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
309 309
 	if ($aprs_full) $aprs_filter = '';
310 310
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
311 311
 	else $aprs_pass = '-1';
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 sleep(1);
321 321
 if ($globalDebug) echo "SCAN MODE \n\n";
322 322
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
323
-$endtime = time()+$globalCronEnd;
323
+$endtime = time() + $globalCronEnd;
324 324
 $i = 1;
325 325
 $tt = array();
326 326
 // Delete all ATC
327 327
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
328
-	$ATC=new ATC($Connection->db);
328
+	$ATC = new ATC($Connection->db);
329 329
 }
330 330
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
331 331
 	$ATC->deleteAll();
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 
334 334
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
335 335
 while ($i > 0) {
336
-    if (!$globalDaemon) $i = $endtime-time();
336
+    if (!$globalDaemon) $i = $endtime - time();
337 337
     // Delete old ATC
338 338
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
339 339
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	}
349 349
 	if ($max != $globalMinFetch) {
350 350
 	    if ($globalDebug) echo 'Sleeping...'."\n";
351
-	    sleep($globalMinFetch-$max+2);
351
+	    sleep($globalMinFetch - $max + 2);
352 352
 	}
353 353
     }
354 354
 
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 	    //$buffer = $Common->getData($hosts[$id]);
362 362
 	    $buffer = $Common->getData($value['host']);
363 363
 	    if ($buffer != '') $reset = 0;
364
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
365
-	    $buffer = explode('\n',$buffer);
364
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
365
+	    $buffer = explode('\n', $buffer);
366 366
 	    foreach ($buffer as $line) {
367 367
     		if ($line != '' && count($line) > 7) {
368 368
     		    $line = explode(',', $line);
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
     	    $last_exec[$id]['last'] = time();
390 390
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
391 391
 	    date_default_timezone_set('CET');
392
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
392
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
393 393
 	    date_default_timezone_set('UTC');
394 394
 	    if ($buffer != '') $reset = 0;
395
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
396
-	    $buffer = explode('\n',$buffer);
395
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
396
+	    $buffer = explode('\n', $buffer);
397 397
 	    foreach ($buffer as $line) {
398 398
 		if ($line != '') {
399 399
 		    echo "'".$line."'\n";
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
412 412
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
413 413
 		    if (isset($ais_data['timestamp'])) {
414
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
414
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
415 415
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
416 416
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
417 417
 			    $add = true;
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 	    $w = $e = null;
435 435
 	    
436 436
 	    if (isset($arr[$id])) {
437
-	    $nn = stream_select($arr,$w,$e,$timeout);
437
+	    $nn = stream_select($arr, $w, $e, $timeout);
438 438
 	    if ($nn > 0) {
439 439
 		foreach ($httpfeeds as $feed) {
440
-		    $buffer = stream_get_line($feed,2000,"\n");
441
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
442
-		    $buffer = explode('\n',$buffer);
440
+		    $buffer = stream_get_line($feed, 2000, "\n");
441
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
442
+		    $buffer = explode('\n', $buffer);
443 443
 		    foreach ($buffer as $line) {
444 444
 			if ($line != '') {
445 445
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
456 456
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
457 457
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
458
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
458
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
459 459
 			    if (isset($ais_data['timestamp'])) {
460
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
460
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
461 461
 			    } else {
462 462
 				$data['datetime'] = date('Y-m-d H:i:s');
463 463
 			    }
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
 		}
472 472
 	    }
473 473
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
474
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
474
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
475 475
 	    if ($buffer != '') {
476 476
 		//echo $buffer;
477
-		$all_data = json_decode($buffer,true);
477
+		$all_data = json_decode($buffer, true);
478 478
 		//print_r($all_data);
479 479
 		if (isset($all_data[0]['DATA'])) {
480 480
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
490 490
 			$data['imo'] = $line['IMO'];
491 491
 			//$data['arrival_code'] = $ais_data['destination'];
492
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
492
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
493 493
 			$data['format_source'] = 'myshiptracking';
494 494
 			$data['id_source'] = $id_source;
495 495
 			$MI->add($data);
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
 	    }
502 502
     	    $last_exec[$id]['last'] = time();
503 503
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
504
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
504
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
505 505
 	    if ($buffer != '') {
506
-		$all_data = json_decode($buffer,true);
506
+		$all_data = json_decode($buffer, true);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508 508
 		    foreach ($all_data as $line) {
509 509
 			if ($line != '') {
@@ -530,27 +530,27 @@  discard block
 block discarded – undo
530 530
     	    $last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532 532
 	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
533
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
534 534
 	    echo 'done !'."\n";
535 535
 	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
536
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+	    $buffer = explode('\n', $buffer);
538 538
 	    foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540 540
 		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
541
+		    $data['mmsi'] = (int) substr($line, 0, 9);
542
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
543 543
 		    //$data['status'] = substr($line,21,2);
544 544
 		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
545
+		    $data['latitude'] = substr($line, 29, 9);
546
+		    $data['longitude'] = substr($line, 41, 9);
547
+		    $data['speed'] = round(substr($line, 51, 5));
548 548
 		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
549
+		    $data['heading'] = round(substr($line, 63, 3));
550 550
 		    //$data['draft'] = substr($line,67,4);
551 551
 		    //$data['length'] = substr($line,72,3);
552 552
 		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
553
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
554 554
 		    //$data['callsign'] = trim(substr($line,100,7);
555 555
 		    //$data['dest'] = substr($line,108,20);
556 556
 		    //$data['etaDate'] = substr($line,129,5);
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569 569
 	    //$buffer = $Common->getData($hosts[$id]);
570 570
 	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
571
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
572
+	    $buffer = explode('\n', $buffer);
573 573
 	    $reset = 0;
574 574
 	    foreach ($buffer as $line) {
575 575
     		if ($line != '') {
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
581 581
 			$data['pilot_id'] = $line[1];
582 582
 			$data['pilot_name'] = $line[2];
583
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
583
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
584 584
 			$data['ident'] = $line[0]; // ident
585 585
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
586 586
 			$data['speed'] = $line[8]; // speed
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598 598
 		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
599
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
600 600
 		        $data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
     			$data['id_source'] = $id_source;
606 606
 	    		//$data['arrival_airport_time'] = ;
607 607
 	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
608
+	    		    $aircraft_data = explode('/', $line[9]);
609 609
 	    		    if (isset($aircraft_data[1])) {
610 610
 	    			$data['aircraft_icao'] = $aircraft_data[1];
611 611
 	    		    }
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
     			if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624
-				$typec = substr($data['ident'],-3);
622
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
623
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
624
+				$typec = substr($data['ident'], -3);
625 625
 				if ($typec == 'APP') $data['type'] = 'Approach';
626 626
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627 627
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633 633
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
635
+				if (isset($ATC)) echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
636 636
 			}
637 637
     			unset($data);
638 638
     		    }
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
     	    $last_exec[$id]['last'] = time();
644 644
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645 645
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
646
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
647 647
 	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
648
+	    $all_data = json_decode($buffer, true);
649 649
 	    if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702 702
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703 703
 	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
704
+	    $all_data = json_decode($buffer, true);
705 705
 	    if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
@@ -718,12 +718,12 @@  discard block
 block discarded – undo
718 718
 		    $data['emergency'] = ''; // emergency
719 719
 		    $data['registration'] = $line[2];
720 720
 		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
721
+		    $deparr = explode('-', $line[1]);
722 722
 		    if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725 725
 		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
726
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
727 727
 	    	    $data['format_source'] = 'planeupdatefaa';
728 728
     		    $data['id_source'] = $id_source;
729 729
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
     	    $last_exec[$id]['last'] = time();
736 736
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737 737
 	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
738
+	    $all_data = json_decode($buffer, true);
739 739
 	    if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		    //$data['emergency'] = ''; // emergency
753 753
 		    //$data['registration'] = $line[2];
754 754
 		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
755
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
756 756
 	    	    $data['format_source'] = 'opensky';
757 757
     		    $data['id_source'] = $id_source;
758 758
 		    $SI->add($data);
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766 766
 	    //$buffer = $Common->getData($hosts[$id]);
767 767
 	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
768
+	    $all_data = json_decode($buffer, true);
769 769
 	    if (!empty($all_data)) $reset = 0;
770 770
 	    foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -797,11 +797,11 @@  discard block
 block discarded – undo
797 797
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798 798
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799 799
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
800
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
801 801
 	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
802
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
803
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
804
+	    $all_data = json_decode($buffer, true);
805 805
 	    if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807 807
 	    }
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826 826
 	    		//$data['emergency'] = ''; // emergency
827
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
827
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
828 828
 	    		$data['format_source'] = 'radarvirtueljson';
829 829
     			$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -839,14 +839,14 @@  discard block
 block discarded – undo
839 839
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840 840
 	    //$buffer = $Common->getData($hosts[$id]);
841 841
 	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
842
+	    $all_data = json_decode(utf8_encode($buffer), true);
843 843
 	    
844 844
 	    if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846 846
 	        foreach ($all_data['pireps'] as $line) {
847 847
 		    $data = array();
848 848
 		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
849
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
850 850
 		    $data['ident'] = $line['callsign']; // ident
851 851
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852 852
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -875,9 +875,9 @@  discard block
 block discarded – undo
875 875
 			$SI->add($data);
876 876
 		    //    print_r($data);
877 877
     		    } elseif ($line['icon'] == 'ct') {
878
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880
-			$typec = substr($data['ident'],-3);
878
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
879
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
880
+			$typec = substr($data['ident'], -3);
881 881
 			$data['type'] = '';
882 882
 			if ($typec == 'APP') $data['type'] = 'Approach';
883 883
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
891
+			if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']);
892 892
 		    }
893 893
 		    unset($data);
894 894
 		}
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
 	    //$buffer = $Common->getData($hosts[$id]);
901 901
 	    if ($globalDebug) echo 'Get Data...'."\n";
902 902
 	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
903
+	    $all_data = json_decode($buffer, true);
904 904
 	    if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907 907
 	    	    $data = array();
908 908
 	    	    //$data['id'] = $line['id']; // id not usable
909 909
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
910
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
911 911
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912 912
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913 913
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -930,12 +930,12 @@  discard block
 block discarded – undo
930 930
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931 931
 		    if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
933
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
934
+	    		$aircraft_data = explode('-', $line['aircraftname']);
935 935
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936 936
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937 937
 	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
938
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
939 939
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940 940
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941 941
 	    		}
@@ -957,14 +957,14 @@  discard block
 block discarded – undo
957 957
 	    //$buffer = $Common->getData($hosts[$id]);
958 958
 	    if ($globalDebug) echo 'Get Data...'."\n";
959 959
 	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
960
+	    $all_data = json_decode($buffer, true);
961 961
 	    if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964 964
 	    	    $data = array();
965 965
 	    	    //$data['id'] = $line['id']; // id not usable
966 966
 	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
967
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
968 968
 	    	    $data['pilot_name'] = $line['pilot_name'];
969 969
 	    	    $data['pilot_id'] = $line['pilot_id'];
970 970
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1015,9 +1015,9 @@  discard block
 block discarded – undo
1015 1015
 		    //$value = $formats[$nb];
1016 1016
 		    $format = $globalSources[$nb]['format'];
1017 1017
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1018
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1019 1019
         	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1020
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1021 1021
 	    	    }
1022 1022
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023 1023
         	    //echo $buffer."\n";
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 		    $error = false;
1027 1027
 		    //$SI::del();
1028 1028
 		    if ($format == 'vrstcp') {
1029
-			$buffer = explode('},{',$buffer);
1030
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
+			$buffer = explode('},{', $buffer);
1030
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1031 1031
 		    // SBS format is CSV format
1032 1032
 		    if ($buffer != '') {
1033 1033
 			$tt[$format] = 0;
@@ -1059,10 +1059,10 @@  discard block
 block discarded – undo
1059 1059
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1060 1060
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1061 1061
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1062
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1062
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1063 1063
 
1064 1064
 			    if (isset($ais_data['timestamp'])) {
1065
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1065
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1066 1066
 			    } else {
1067 1067
 				$data['datetime'] = date('Y-m-d H:i:s');
1068 1068
 			    }
@@ -1073,10 +1073,10 @@  discard block
 block discarded – undo
1073 1073
                         } elseif ($format == 'flightgearsp') {
1074 1074
                     	    //echo $buffer."\n";
1075 1075
                     	    if (strlen($buffer) > 5) {
1076
-				$line = explode(',',$buffer);
1076
+				$line = explode(',', $buffer);
1077 1077
 				$data = array();
1078 1078
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1079
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1079
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1080 1080
 				$data['ident'] = $line[6];
1081 1081
 				$data['aircraft_name'] = $line[7];
1082 1082
 				$data['longitude'] = $line[1];
@@ -1087,21 +1087,21 @@  discard block
 block discarded – undo
1087 1087
 				$data['datetime'] = date('Y-m-d H:i:s');
1088 1088
 				$data['format_source'] = 'flightgearsp';
1089 1089
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1090
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1090
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1091 1091
 			    }
1092 1092
                         } elseif ($format == 'acars') {
1093 1093
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1094 1094
 			    $ACARS->add(trim($buffer));
1095
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1095
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1096 1096
 			    $ACARS->deleteLiveAcarsData();
1097 1097
 			} elseif ($format == 'flightgearmp') {
1098
-			    if (substr($buffer,0,1) != '#') {
1098
+			    if (substr($buffer, 0, 1) != '#') {
1099 1099
 				$data = array();
1100 1100
 				//echo $buffer."\n";
1101
-				$line = explode(' ',$buffer);
1101
+				$line = explode(' ', $buffer);
1102 1102
 				if (count($line) == 11) {
1103
-				    $userserver = explode('@',$line[0]);
1104
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
+				    $userserver = explode('@', $line[0]);
1104
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1105 1105
 				    $data['ident'] = $userserver[0];
1106 1106
 				    $data['registration'] = $userserver[0];
1107 1107
 				    $data['latitude'] = $line[4];
@@ -1109,8 +1109,8 @@  discard block
 block discarded – undo
1109 1109
 				    $data['altitude'] = $line[6];
1110 1110
 				    $data['datetime'] = date('Y-m-d H:i:s');
1111 1111
 				    $aircraft_type = $line[10];
1112
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1113
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1113
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1114 1114
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1115 1115
 				}
1116 1116
 			    }
@@ -1118,8 +1118,8 @@  discard block
 block discarded – undo
1118 1118
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1119 1119
 			    die;
1120 1120
 			} elseif ($format == 'vrstcp') {
1121
-			    foreach($buffer as $all_data) {
1122
-				$line = json_decode('{'.$all_data.'}',true);
1121
+			    foreach ($buffer as $all_data) {
1122
+				$line = json_decode('{'.$all_data.'}', true);
1123 1123
 				$data = array();
1124 1124
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1125 1125
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1144,16 +1144,16 @@  discard block
 block discarded – undo
1144 1144
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1145 1145
 				unset($data);
1146 1146
 			    }
1147
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1147
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1148 1148
 			    $line = explode("\t", $buffer);
1149
-			    for($k = 0; $k < count($line); $k=$k+2) {
1149
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1150 1150
 				$key = $line[$k];
1151
-			        $lined[$key] = $line[$k+1];
1151
+			        $lined[$key] = $line[$k + 1];
1152 1152
 			    }
1153 1153
     			    if (count($lined) > 3) {
1154 1154
     				$data['hex'] = $lined['hexid'];
1155 1155
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1156
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1156
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1157 1157
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1158 1158
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1159 1159
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1171,22 +1171,22 @@  discard block
 block discarded – undo
1171 1171
     			    } else $error = true;
1172 1172
 			} elseif ($format == 'aprs' && $use_aprs) {
1173 1173
 			    if ($aprs_connect == 0) {
1174
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1174
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1175 1175
 				$aprs_connect = 1;
1176 1176
 			    }
1177 1177
 			    
1178
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1178
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1179 1179
 				$aprs_last_tx = time();
1180 1180
 				$data_aprs = "# Keep alive";
1181
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1181
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1182 1182
 			    }
1183 1183
 			    
1184 1184
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1185 1185
 			    //echo 'APRS data : '.$buffer."\n";
1186
-			    $buffer = str_replace('APRS <- ','',$buffer);
1187
-			    $buffer = str_replace('APRS -> ','',$buffer);
1186
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1187
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1188 1188
 			    echo $buffer."\n";
1189
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1189
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1190 1190
 				$line = $APRS->parse($buffer);
1191 1191
 				//print_r($line);
1192 1192
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
 				    $data = array();
1196 1196
 				    //print_r($line);
1197 1197
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1198
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1198
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1199 1199
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1200 1200
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1201 1201
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
 				    $currentdate = date('Y-m-d H:i:s');
1222 1222
 				    $aprsdate = strtotime($data['datetime']);
1223 1223
 				    // Accept data if time <= system time + 20s
1224
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1224
+				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1225 1225
 					$send = $SI->add($data);
1226 1226
 				    } elseif (isset($line['stealth'])) {
1227 1227
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1318,7 +1318,7 @@  discard block
 block discarded – undo
1318 1318
 				connect_all($sourceee);
1319 1319
 				$sourceee = array();
1320 1320
 				//connect_all($globalSources);
1321
-				$tt[$format]=0;
1321
+				$tt[$format] = 0;
1322 1322
 				break;
1323 1323
 			    }
1324 1324
 			}
@@ -1327,14 +1327,14 @@  discard block
 block discarded – undo
1327 1327
 	    } else {
1328 1328
 		$error = socket_strerror(socket_last_error());
1329 1329
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1330
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1330
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1331 1331
 			if (isset($globalDebug)) echo "Restarting...\n";
1332 1332
 			// Restart the script if possible
1333 1333
 			if (is_array($sockets)) {
1334 1334
 			    if ($globalDebug) echo "Shutdown all sockets...";
1335 1335
 			    
1336 1336
 			    foreach ($sockets as $sock) {
1337
-				@socket_shutdown($sock,2);
1337
+				@socket_shutdown($sock, 2);
1338 1338
 				@socket_close($sock);
1339 1339
 			    }
1340 1340
 			    
Please login to merge, or discard this patch.
Braces   +769 added lines, -262 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,20 +63,33 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
63
-if (isset($options['server'])) $globalServer = TRUE;
64
-if (isset($options['idsource'])) $id_source = $options['idsource'];
65
-else $id_source = 1;
66
+if (isset($options['nodaemon'])) {
67
+	$globalDaemon = FALSE;
68
+}
69
+if (isset($options['server'])) {
70
+	$globalServer = TRUE;
71
+}
72
+if (isset($options['idsource'])) {
73
+	$id_source = $options['idsource'];
74
+} else {
75
+	$id_source = 1;
76
+}
66 77
 if (isset($globalServer) && $globalServer) {
67
-    if ($globalDebug) echo "Using Server Mode\n";
78
+    if ($globalDebug) {
79
+    	echo "Using Server Mode\n";
80
+    }
68 81
     $SI=new SpotterServer();
69 82
 /*
70 83
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
71 84
     $SI = new adsb2aprs();
72 85
     $SI->connect();
73 86
 */
74
-} else $SI=new SpotterImport($Connection->db);
75
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
87
+} else {
88
+	$SI=new SpotterImport($Connection->db);
89
+}
90
+if (isset($globalTracker) && $globalTracker) {
91
+	$TI = new TrackerImport($Connection->db);
92
+}
76 93
 if (isset($globalMarine) && $globalMarine) {
77 94
     $AIS = new AIS();
78 95
     $MI = new MarineImport($Connection->db);
@@ -94,7 +111,9 @@  discard block
 block discarded – undo
94 111
 }
95 112
 
96 113
 // let's try and connect
97
-if ($globalDebug) echo "Connecting...\n";
114
+if ($globalDebug) {
115
+	echo "Connecting...\n";
116
+}
98 117
 $use_aprs = false;
99 118
 $aprs_full = false;
100 119
 $reset = 0;
@@ -103,7 +122,9 @@  discard block
 block discarded – undo
103 122
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104 123
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
105 124
     $reset++;
106
-    if ($globalDebug) echo 'Connect to all...'."\n";
125
+    if ($globalDebug) {
126
+    	echo 'Connect to all...'."\n";
127
+    }
107 128
     foreach ($hosts as $id => $value) {
108 129
 	$host = $value['host'];
109 130
 	$globalSources[$id]['last_exec'] = 0;
@@ -113,27 +134,37 @@  discard block
 block discarded – undo
113 134
         	//$formats[$id] = 'deltadbtxt';
114 135
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 136
         	//$last_exec['deltadbtxt'] = 0;
116
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
137
+        	if ($globalDebug) {
138
+        		echo "Connect to deltadb source (".$host.")...\n";
139
+        	}
117 140
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
118 141
         	//$formats[$id] = 'vatsimtxt';
119 142
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 143
         	//$last_exec['vatsimtxt'] = 0;
121
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
+        	if ($globalDebug) {
145
+        		echo "Connect to vatsim source (".$host.")...\n";
146
+        	}
122 147
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
123 148
         	//$formats[$id] = 'aircraftlistjson';
124 149
         	$globalSources[$id]['format'] = 'aircraftlistjson';
125 150
         	//$last_exec['aircraftlistjson'] = 0;
126
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
151
+        	if ($globalDebug) {
152
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
153
+        	}
127 154
     	    } else if (preg_match('/opensky/i',$host)) {
128 155
         	//$formats[$id] = 'aircraftlistjson';
129 156
         	$globalSources[$id]['format'] = 'opensky';
130 157
         	//$last_exec['aircraftlistjson'] = 0;
131
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
158
+        	if ($globalDebug) {
159
+        		echo "Connect to opensky source (".$host.")...\n";
160
+        	}
132 161
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
133 162
         	//$formats[$id] = 'radarvirtueljson';
134 163
         	$globalSources[$id]['format'] = 'radarvirtueljson';
135 164
         	//$last_exec['radarvirtueljson'] = 0;
136
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
165
+        	if ($globalDebug) {
166
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
167
+        	}
137 168
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
138 169
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139 170
         	    exit(0);
@@ -142,7 +173,9 @@  discard block
 block discarded – undo
142 173
         	//$formats[$id] = 'planeupdatefaa';
143 174
         	$globalSources[$id]['format'] = 'planeupdatefaa';
144 175
         	//$last_exec['planeupdatefaa'] = 0;
145
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
176
+        	if ($globalDebug) {
177
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
178
+        	}
146 179
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
147 180
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148 181
         	    exit(0);
@@ -151,26 +184,36 @@  discard block
 block discarded – undo
151 184
         	//$formats[$id] = 'phpvmacars';
152 185
         	$globalSources[$id]['format'] = 'phpvmacars';
153 186
         	//$last_exec['phpvmacars'] = 0;
154
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
187
+        	if ($globalDebug) {
188
+        		echo "Connect to phpvmacars source (".$host.")...\n";
189
+        	}
155 190
             } else if (preg_match('/VAM-json.php$/i',$host)) {
156 191
         	//$formats[$id] = 'phpvmacars';
157 192
         	$globalSources[$id]['format'] = 'vam';
158
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
193
+        	if ($globalDebug) {
194
+        		echo "Connect to Vam source (".$host.")...\n";
195
+        	}
159 196
             } else if (preg_match('/whazzup/i',$host)) {
160 197
         	//$formats[$id] = 'whazzup';
161 198
         	$globalSources[$id]['format'] = 'whazzup';
162 199
         	//$last_exec['whazzup'] = 0;
163
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
200
+        	if ($globalDebug) {
201
+        		echo "Connect to whazzup source (".$host.")...\n";
202
+        	}
164 203
             } else if (preg_match('/recentpireps/i',$host)) {
165 204
         	//$formats[$id] = 'pirepsjson';
166 205
         	$globalSources[$id]['format'] = 'pirepsjson';
167 206
         	//$last_exec['pirepsjson'] = 0;
168
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
207
+        	if ($globalDebug) {
208
+        		echo "Connect to pirepsjson source (".$host.")...\n";
209
+        	}
169 210
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
170 211
         	//$formats[$id] = 'fr24json';
171 212
         	$globalSources[$id]['format'] = 'fr24json';
172 213
         	//$last_exec['fr24json'] = 0;
173
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to fr24 source (".$host.")...\n";
216
+        	}
174 217
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
175 218
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176 219
         	    exit(0);
@@ -179,7 +222,9 @@  discard block
 block discarded – undo
179 222
         	//$formats[$id] = 'fr24json';
180 223
         	$globalSources[$id]['format'] = 'myshiptracking';
181 224
         	//$last_exec['fr24json'] = 0;
182
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
225
+        	if ($globalDebug) {
226
+        		echo "Connect to myshiptracking source (".$host.")...\n";
227
+        	}
183 228
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
184 229
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
185 230
         	    exit(0);
@@ -188,17 +233,24 @@  discard block
 block discarded – undo
188 233
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189 234
         	//$formats[$id] = 'tsv';
190 235
         	$globalSources[$id]['format'] = 'tsv';
191
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to tsv source (".$host.")...\n";
238
+        	}
192 239
             }
193 240
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
194 241
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195 242
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
196 243
     		    if ($idf !== false) {
197 244
     			$httpfeeds[$id] = $idf;
198
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
245
+        		if ($globalDebug) {
246
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
247
+        		}
248
+    		    } elseif ($globalDebug) {
249
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
199 250
     		    }
200
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
251
+    		} elseif ($globalDebug) {
252
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
253
+    		}
202 254
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203 255
 	    $hostport = explode(':',$host);
204 256
 	    if (isset($hostport[1])) {
@@ -238,17 +290,25 @@  discard block
 block discarded – undo
238 290
         		//$formats[$id] = 'beast';
239 291
         		$globalSources[$id]['format'] = 'beast';
240 292
 		    //} else $formats[$id] = 'sbs';
241
-		    } else $globalSources[$id]['format'] = 'sbs';
293
+		    } else {
294
+		    	$globalSources[$id]['format'] = 'sbs';
295
+		    }
242 296
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
243 297
 		}
244
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
298
+		if ($globalDebug) {
299
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
300
+		}
245 301
             } else {
246
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
302
+		if ($globalDebug) {
303
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
304
+		}
247 305
     	    }
248 306
         }
249 307
     }
250 308
 }
251
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
309
+if (!isset($globalMinFetch)) {
310
+	$globalMinFetch = 15;
311
+}
252 312
 
253 313
 // Initialize all
254 314
 $status = array();
@@ -257,13 +317,19 @@  discard block
 block discarded – undo
257 317
 $formats = array();
258 318
 $last_exec = array();
259 319
 $time = time();
260
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
261
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
262
-else $timeout = 20;
320
+if (isset($globalSourcesTimeout)) {
321
+	$timeout = $globalSourcesTimeOut;
322
+} else if (isset($globalSBS1TimeOut)) {
323
+	$timeout = $globalSBS1TimeOut;
324
+} else {
325
+	$timeout = 20;
326
+}
263 327
 $errno = '';
264 328
 $errstr='';
265 329
 
266
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
330
+if (!isset($globalDaemon)) {
331
+	$globalDaemon = TRUE;
332
+}
267 333
 /* Initiate connections to all the hosts simultaneously */
268 334
 //connect_all($hosts);
269 335
 //connect_all($globalSources);
@@ -289,7 +355,9 @@  discard block
 block discarded – undo
289 355
     if (isset($source['format']) && $source['format'] == 'aprs') {
290 356
 	$aprs_connect = 0;
291 357
 	$use_aprs = true;
292
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
358
+	if (isset($source['port']) && $source['port'] == '10152') {
359
+		$aprs_full = true;
360
+	}
293 361
 	break;
294 362
     }
295 363
 }
@@ -300,26 +368,49 @@  discard block
 block discarded – undo
300 368
 	$aprs_connect = 0;
301 369
 	$aprs_keep = 120;
302 370
 	$aprs_last_tx = time();
303
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
304
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
305
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
306
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
307
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
308
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
309
-	if ($aprs_full) $aprs_filter = '';
310
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
311
-	else $aprs_pass = '-1';
371
+	if (isset($globalAPRSversion)) {
372
+		$aprs_version = $globalAPRSversion;
373
+	} else {
374
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
375
+	}
376
+	if (isset($globalAPRSssid)) {
377
+		$aprs_ssid = $globalAPRSssid;
378
+	} else {
379
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
380
+	}
381
+	if (isset($globalAPRSfilter)) {
382
+		$aprs_filter = $globalAPRSfilter;
383
+	} else {
384
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
385
+	}
386
+	if ($aprs_full) {
387
+		$aprs_filter = '';
388
+	}
389
+	if (isset($globalAPRSpass)) {
390
+		$aprs_pass = $globalAPRSpass;
391
+	} else {
392
+		$aprs_pass = '-1';
393
+	}
312 394
 
313
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
314
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
395
+	if ($aprs_filter != '') {
396
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
397
+	} else {
398
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
399
+	}
315 400
 	echo $aprs_login."\n";
316 401
 }
317 402
 
318 403
 // connected - lets do some work
319
-if ($globalDebug) echo "Connected!\n";
404
+if ($globalDebug) {
405
+	echo "Connected!\n";
406
+}
320 407
 sleep(1);
321
-if ($globalDebug) echo "SCAN MODE \n\n";
322
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
408
+if ($globalDebug) {
409
+	echo "SCAN MODE \n\n";
410
+}
411
+if (!isset($globalCronEnd)) {
412
+	$globalCronEnd = 60;
413
+}
323 414
 $endtime = time()+$globalCronEnd;
324 415
 $i = 1;
325 416
 $tt = array();
@@ -333,10 +424,14 @@  discard block
 block discarded – undo
333 424
 
334 425
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
335 426
 while ($i > 0) {
336
-    if (!$globalDaemon) $i = $endtime-time();
427
+    if (!$globalDaemon) {
428
+    	$i = $endtime-time();
429
+    }
337 430
     // Delete old ATC
338 431
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
339
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
432
+	if ($globalDebug) {
433
+		echo 'Delete old ATC...'."\n";
434
+	}
340 435
         $ATC->deleteOldATC();
341 436
     }
342 437
     
@@ -344,10 +439,14 @@  discard block
 block discarded – undo
344 439
     if (count($last_exec) == count($globalSources)) {
345 440
 	$max = $globalMinFetch;
346 441
 	foreach ($last_exec as $last) {
347
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
442
+	    if ((time() - $last['last']) < $max) {
443
+	    	$max = time() - $last['last'];
444
+	    }
348 445
 	}
349 446
 	if ($max != $globalMinFetch) {
350
-	    if ($globalDebug) echo 'Sleeping...'."\n";
447
+	    if ($globalDebug) {
448
+	    	echo 'Sleeping...'."\n";
449
+	    }
351 450
 	    sleep($globalMinFetch-$max+2);
352 451
 	}
353 452
     }
@@ -356,11 +455,15 @@  discard block
 block discarded – undo
356 455
     //foreach ($formats as $id => $value) {
357 456
     foreach ($globalSources as $id => $value) {
358 457
 	date_default_timezone_set('UTC');
359
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
458
+	if (!isset($last_exec[$id]['last'])) {
459
+		$last_exec[$id]['last'] = 0;
460
+	}
360 461
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
361 462
 	    //$buffer = $Common->getData($hosts[$id]);
362 463
 	    $buffer = $Common->getData($value['host']);
363
-	    if ($buffer != '') $reset = 0;
464
+	    if ($buffer != '') {
465
+	    	$reset = 0;
466
+	    }
364 467
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
365 468
 	    $buffer = explode('\n',$buffer);
366 469
 	    foreach ($buffer as $line) {
@@ -369,19 +472,38 @@  discard block
 block discarded – undo
369 472
 	            $data = array();
370 473
 	            $data['hex'] = $line[1]; // hex
371 474
 	            $data['ident'] = $line[2]; // ident
372
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
373
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
374
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
375
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
376
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
475
+	            if (isset($line[3])) {
476
+	            	$data['altitude'] = $line[3];
477
+	            }
478
+	            // altitude
479
+	            if (isset($line[4])) {
480
+	            	$data['speed'] = $line[4];
481
+	            }
482
+	            // speed
483
+	            if (isset($line[5])) {
484
+	            	$data['heading'] = $line[5];
485
+	            }
486
+	            // heading
487
+	            if (isset($line[6])) {
488
+	            	$data['latitude'] = $line[6];
489
+	            }
490
+	            // lat
491
+	            if (isset($line[7])) {
492
+	            	$data['longitude'] = $line[7];
493
+	            }
494
+	            // long
377 495
 	            $data['verticalrate'] = ''; // vertical rate
378 496
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
379 497
 	            $data['emergency'] = ''; // emergency
380 498
 		    $data['datetime'] = date('Y-m-d H:i:s');
381 499
 		    $data['format_source'] = 'deltadbtxt';
382 500
     		    $data['id_source'] = $id_source;
383
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
384
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
501
+		    if (isset($value['name']) && $value['name'] != '') {
502
+		    	$data['source_name'] = $value['name'];
503
+		    }
504
+		    if (isset($value['sourcestats'])) {
505
+		    	$data['sourcestats'] = $value['sourcestats'];
506
+		    }
385 507
     		    $SI->add($data);
386 508
 		    unset($data);
387 509
     		}
@@ -391,7 +513,9 @@  discard block
 block discarded – undo
391 513
 	    date_default_timezone_set('CET');
392 514
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
393 515
 	    date_default_timezone_set('UTC');
394
-	    if ($buffer != '') $reset = 0;
516
+	    if ($buffer != '') {
517
+	    	$reset = 0;
518
+	    }
395 519
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
396 520
 	    $buffer = explode('\n',$buffer);
397 521
 	    foreach ($buffer as $line) {
@@ -400,16 +524,36 @@  discard block
 block discarded – undo
400 524
 		    $add = false;
401 525
 		    $ais_data = $AIS->parse_line(trim($line));
402 526
 		    $data = array();
403
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
404
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
405
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
406
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
407
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
408
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
409
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
410
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
411
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
412
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
527
+		    if (isset($ais_data['ident'])) {
528
+		    	$data['ident'] = $ais_data['ident'];
529
+		    }
530
+		    if (isset($ais_data['mmsi'])) {
531
+		    	$data['mmsi'] = $ais_data['mmsi'];
532
+		    }
533
+		    if (isset($ais_data['speed'])) {
534
+		    	$data['speed'] = $ais_data['speed'];
535
+		    }
536
+		    if (isset($ais_data['heading'])) {
537
+		    	$data['heading'] = $ais_data['heading'];
538
+		    }
539
+		    if (isset($ais_data['latitude'])) {
540
+		    	$data['latitude'] = $ais_data['latitude'];
541
+		    }
542
+		    if (isset($ais_data['longitude'])) {
543
+		    	$data['longitude'] = $ais_data['longitude'];
544
+		    }
545
+		    if (isset($ais_data['status'])) {
546
+		    	$data['status'] = $ais_data['status'];
547
+		    }
548
+		    if (isset($ais_data['type'])) {
549
+		    	$data['type'] = $ais_data['type'];
550
+		    }
551
+		    if (isset($ais_data['imo'])) {
552
+		    	$data['imo'] = $ais_data['imo'];
553
+		    }
554
+		    if (isset($ais_data['callsign'])) {
555
+		    	$data['callsign'] = $ais_data['callsign'];
556
+		    }
413 557
 		    if (isset($ais_data['timestamp'])) {
414 558
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
415 559
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -424,7 +568,9 @@  discard block
 block discarded – undo
424 568
     		    $data['id_source'] = $id_source;
425 569
 		    print_r($data);
426 570
 		    echo 'Add...'."\n";
427
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
571
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
572
+		    	$MI->add($data);
573
+		    }
428 574
 		    unset($data);
429 575
 		}
430 576
     	    }
@@ -444,18 +590,42 @@  discard block
 block discarded – undo
444 590
 			if ($line != '') {
445 591
 			    $ais_data = $AIS->parse_line(trim($line));
446 592
 			    $data = array();
447
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
448
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
449
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
450
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
451
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
452
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
453
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
454
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
455
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
456
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
457
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
458
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
593
+			    if (isset($ais_data['ident'])) {
594
+			    	$data['ident'] = $ais_data['ident'];
595
+			    }
596
+			    if (isset($ais_data['mmsi'])) {
597
+			    	$data['mmsi'] = $ais_data['mmsi'];
598
+			    }
599
+			    if (isset($ais_data['speed'])) {
600
+			    	$data['speed'] = $ais_data['speed'];
601
+			    }
602
+			    if (isset($ais_data['heading'])) {
603
+			    	$data['heading'] = $ais_data['heading'];
604
+			    }
605
+			    if (isset($ais_data['latitude'])) {
606
+			    	$data['latitude'] = $ais_data['latitude'];
607
+			    }
608
+			    if (isset($ais_data['longitude'])) {
609
+			    	$data['longitude'] = $ais_data['longitude'];
610
+			    }
611
+			    if (isset($ais_data['status'])) {
612
+			    	$data['status'] = $ais_data['status'];
613
+			    }
614
+			    if (isset($ais_data['type'])) {
615
+			    	$data['type'] = $ais_data['type'];
616
+			    }
617
+			    if (isset($ais_data['imo'])) {
618
+			    	$data['imo'] = $ais_data['imo'];
619
+			    }
620
+			    if (isset($ais_data['callsign'])) {
621
+			    	$data['callsign'] = $ais_data['callsign'];
622
+			    }
623
+			    if (isset($ais_data['destination'])) {
624
+			    	$data['arrival_code'] = $ais_data['destination'];
625
+			    }
626
+			    if (isset($ais_data['eta_ts'])) {
627
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
628
+			    }
459 629
 			    if (isset($ais_data['timestamp'])) {
460 630
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
461 631
 			    } else {
@@ -463,7 +633,9 @@  discard block
 block discarded – undo
463 633
 			    }
464 634
 			    $data['format_source'] = 'aisnmeahttp';
465 635
 			    $data['id_source'] = $id_source;
466
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
636
+			    if ($ais_data['mmsi_type'] == 'Ship') {
637
+			    	$MI->add($data);
638
+			    }
467 639
 			    unset($data);
468 640
 			}
469 641
 		    }
@@ -512,7 +684,9 @@  discard block
 block discarded – undo
512 684
 			    $data['callsign'] = $line['callsign'];
513 685
 			    $data['mmsi'] = $line['mmsi'];
514 686
 			    $data['speed'] = $line['sog'];
515
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
687
+			    if ($line['heading'] != '511') {
688
+			    	$data['heading'] = $line['heading'];
689
+			    }
516 690
 			    $data['latitude'] = $line['latitude'];
517 691
 			    $data['longitude'] = $line['longitude'];
518 692
 			    $data['type_id'] = $line['shiptype'];
@@ -532,7 +706,9 @@  discard block
 block discarded – undo
532 706
 	    echo 'download...';
533 707
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534 708
 	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
709
+	    if ($buffer != '') {
710
+	    	$reset = 0;
711
+	    }
536 712
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537 713
 	    $buffer = explode('\n',$buffer);
538 714
 	    foreach ($buffer as $line) {
@@ -576,16 +752,28 @@  discard block
 block discarded – undo
576 752
     		    $line = explode(':', $line);
577 753
     		    if (count($line) > 30 && $line[0] != 'callsign') {
578 754
 			$data = array();
579
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
755
+			if (isset($line[37]) && $line[37] != '') {
756
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
757
+			} else {
758
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
759
+			}
581 760
 			$data['pilot_id'] = $line[1];
582 761
 			$data['pilot_name'] = $line[2];
583 762
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
584 763
 			$data['ident'] = $line[0]; // ident
585
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
764
+			if ($line[7] != '' && $line[7] != 0) {
765
+				$data['altitude'] = $line[7];
766
+			}
767
+			// altitude
586 768
 			$data['speed'] = $line[8]; // speed
587
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
769
+			if (isset($line[45])) {
770
+				$data['heading'] = $line[45];
771
+			}
772
+			// heading
773
+			elseif (isset($line[38])) {
774
+				$data['heading'] = $line[38];
775
+			}
776
+			// heading
589 777
 			$data['latitude'] = $line[5]; // lat
590 778
 	        	$data['longitude'] = $line[6]; // long
591 779
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -601,7 +789,9 @@  discard block
 block discarded – undo
601 789
 			$data['frequency'] = $line[4];
602 790
 			$data['type'] = $line[18];
603 791
 			$data['range'] = $line[19];
604
-			if (isset($line[35])) $data['info'] = $line[35];
792
+			if (isset($line[35])) {
793
+				$data['info'] = $line[35];
794
+			}
605 795
     			$data['id_source'] = $id_source;
606 796
 	    		//$data['arrival_airport_time'] = ;
607 797
 	    		if ($line[9] != '') {
@@ -615,24 +805,41 @@  discard block
 block discarded – undo
615 805
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 806
 	    		*/
617 807
 	    		$data['format_source'] = $value['format'];
618
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
620
-			elseif ($line[3] == 'ATC') {
808
+			if (isset($value['name']) && $value['name'] != '') {
809
+				$data['source_name'] = $value['name'];
810
+			}
811
+    			if ($line[3] == 'PILOT') {
812
+    				$SI->add($data);
813
+    			} elseif ($line[3] == 'ATC') {
621 814
 				//print_r($data);
622 815
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623 816
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624 817
 				$typec = substr($data['ident'],-3);
625
-				if ($typec == 'APP') $data['type'] = 'Approach';
626
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
628
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
629
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
630
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
631
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
632
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
634
-				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
818
+				if ($typec == 'APP') {
819
+					$data['type'] = 'Approach';
820
+				} elseif ($typec == 'TWR') {
821
+					$data['type'] = 'Tower';
822
+				} elseif ($typec == 'OBS') {
823
+					$data['type'] = 'Observer';
824
+				} elseif ($typec == 'GND') {
825
+					$data['type'] = 'Ground';
826
+				} elseif ($typec == 'DEL') {
827
+					$data['type'] = 'Delivery';
828
+				} elseif ($typec == 'DEP') {
829
+					$data['type'] = 'Departure';
830
+				} elseif ($typec == 'FSS') {
831
+					$data['type'] = 'Flight Service Station';
832
+				} elseif ($typec == 'CTR') {
833
+					$data['type'] = 'Control Radar or Centre';
834
+				} elseif ($data['type'] == '') {
835
+					$data['type'] = 'Observer';
836
+				}
837
+				if (!isset($data['source_name'])) {
838
+					$data['source_name'] = '';
839
+				}
840
+				if (isset($ATC)) {
841
+					echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
842
+				}
636 843
 			}
637 844
     			unset($data);
638 845
     		    }
@@ -651,26 +858,55 @@  discard block
 block discarded – undo
651 858
 		foreach ($all_data['acList'] as $line) {
652 859
 		    $data = array();
653 860
 		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
861
+		    if (isset($line['Call'])) {
862
+		    	$data['ident'] = $line['Call'];
863
+		    }
864
+		    // ident
865
+		    if (isset($line['Alt'])) {
866
+		    	$data['altitude'] = $line['Alt'];
867
+		    }
868
+		    // altitude
869
+		    if (isset($line['Spd'])) {
870
+		    	$data['speed'] = $line['Spd'];
871
+		    }
872
+		    // speed
873
+		    if (isset($line['Trak'])) {
874
+		    	$data['heading'] = $line['Trak'];
875
+		    }
876
+		    // heading
877
+		    if (isset($line['Lat'])) {
878
+		    	$data['latitude'] = $line['Lat'];
879
+		    }
880
+		    // lat
881
+		    if (isset($line['Long'])) {
882
+		    	$data['longitude'] = $line['Long'];
883
+		    }
884
+		    // long
660 885
 		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
886
+		    if (isset($line['Sqk'])) {
887
+		    	$data['squawk'] = $line['Sqk'];
888
+		    }
889
+		    // squawk
662 890
 		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
891
+		    if (isset($line['Reg'])) {
892
+		    	$data['registration'] = $line['Reg'];
893
+		    }
664 894
 		    /*
665 895
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 896
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 897
 		    */
668 898
 		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
899
+		    if (isset($line['Type'])) {
900
+		    	$data['aircraft_icao'] = $line['Type'];
901
+		    }
670 902
 	    	    $data['format_source'] = 'aircraftlistjson';
671 903
 		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['latitude'])) $SI->add($data);
904
+		    if (isset($value['name']) && $value['name'] != '') {
905
+		    	$data['source_name'] = $value['name'];
906
+		    }
907
+		    if (isset($data['latitude'])) {
908
+		    	$SI->add($data);
909
+		    }
674 910
 		    unset($data);
675 911
 		}
676 912
 	    } elseif (is_array($all_data)) {
@@ -690,7 +926,9 @@  discard block
 block discarded – undo
690 926
 		    $data['datetime'] = date('Y-m-d H:i:s');
691 927
 	    	    $data['format_source'] = 'aircraftlistjson';
692 928
     		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
929
+		    if (isset($value['name']) && $value['name'] != '') {
930
+		    	$data['source_name'] = $value['name'];
931
+		    }
694 932
 		    $SI->add($data);
695 933
 		    unset($data);
696 934
 		}
@@ -726,7 +964,9 @@  discard block
 block discarded – undo
726 964
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727 965
 	    	    $data['format_source'] = 'planeupdatefaa';
728 966
     		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
967
+		    if (isset($value['name']) && $value['name'] != '') {
968
+		    	$data['source_name'] = $value['name'];
969
+		    }
730 970
 		    $SI->add($data);
731 971
 		    unset($data);
732 972
 		}
@@ -766,7 +1006,9 @@  discard block
 block discarded – undo
766 1006
 	    //$buffer = $Common->getData($hosts[$id]);
767 1007
 	    $buffer = $Common->getData($value['host']);
768 1008
 	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
1009
+	    if (!empty($all_data)) {
1010
+	    	$reset = 0;
1011
+	    }
770 1012
 	    foreach ($all_data as $key => $line) {
771 1013
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772 1014
 		    $data = array();
@@ -787,7 +1029,9 @@  discard block
 block discarded – undo
787 1029
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788 1030
 	    	    $data['format_source'] = 'fr24json';
789 1031
     		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1032
+		    if (isset($value['name']) && $value['name'] != '') {
1033
+		    	$data['source_name'] = $value['name'];
1034
+		    }
791 1035
 		    $SI->add($data);
792 1036
 		    unset($data);
793 1037
 		}
@@ -811,23 +1055,39 @@  discard block
 block discarded – undo
811 1055
 		    if (isset($line['inf'])) {
812 1056
 			$data = array();
813 1057
 			$data['hex'] = $line['inf']['ia'];
814
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1058
+			if (isset($line['inf']['cs'])) {
1059
+				$data['ident'] = $line['inf']['cs'];
1060
+			}
1061
+			//$line[13]
815 1062
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1063
+	    		if (isset($line['inf']['gs'])) {
1064
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1065
+	    		}
1066
+	    		// speed
1067
+	    		if (isset($line['inf']['tr'])) {
1068
+	    			$data['heading'] = $line['inf']['tr'];
1069
+	    		}
1070
+	    		// heading
818 1071
 	    		$data['latitude'] = $line['pt'][0]; // lat
819 1072
 	    		$data['longitude'] = $line['pt'][1]; // long
820 1073
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1074
+	    		if (isset($line['inf']['sq'])) {
1075
+	    			$data['squawk'] = $line['inf']['sq'];
1076
+	    		}
1077
+	    		// squawk
822 1078
 	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1079
+	    		if (isset($line['inf']['rc'])) {
1080
+	    			$data['registration'] = $line['inf']['rc'];
1081
+	    		}
824 1082
 			//$data['departure_airport_iata'] = $line[11];
825 1083
 			//$data['arrival_airport_iata'] = $line[12];
826 1084
 	    		//$data['emergency'] = ''; // emergency
827 1085
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828 1086
 	    		$data['format_source'] = 'radarvirtueljson';
829 1087
     			$data['id_source'] = $id_source;
830
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1088
+			if (isset($value['name']) && $value['name'] != '') {
1089
+				$data['source_name'] = $value['name'];
1090
+			}
831 1091
 			$SI->add($data);
832 1092
 			unset($data);
833 1093
 		    }
@@ -848,29 +1108,62 @@  discard block
 block discarded – undo
848 1108
 		    $data['id'] = $line['id'];
849 1109
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850 1110
 		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1111
+		    if (isset($line['pilotid'])) {
1112
+		    	$data['pilot_id'] = $line['pilotid'];
1113
+		    }
1114
+		    // pilot id
1115
+		    if (isset($line['name'])) {
1116
+		    	$data['pilot_name'] = $line['name'];
1117
+		    }
1118
+		    // pilot name
1119
+		    if (isset($line['alt'])) {
1120
+		    	$data['altitude'] = $line['alt'];
1121
+		    }
1122
+		    // altitude
1123
+		    if (isset($line['gs'])) {
1124
+		    	$data['speed'] = $line['gs'];
1125
+		    }
1126
+		    // speed
1127
+		    if (isset($line['heading'])) {
1128
+		    	$data['heading'] = $line['heading'];
1129
+		    }
1130
+		    // heading
1131
+		    if (isset($line['route'])) {
1132
+		    	$data['waypoints'] = $line['route'];
1133
+		    }
1134
+		    // route
857 1135
 		    $data['latitude'] = $line['lat']; // lat
858 1136
 		    $data['longitude'] = $line['lon']; // long
859 1137
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860 1138
 		    //$data['squawk'] = $line['squawk']; // squawk
861 1139
 		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1140
+		    if (isset($line['depicao'])) {
1141
+		    	$data['departure_airport_icao'] = $line['depicao'];
1142
+		    }
1143
+		    if (isset($line['deptime'])) {
1144
+		    	$data['departure_airport_time'] = $line['deptime'];
1145
+		    }
1146
+		    if (isset($line['arricao'])) {
1147
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1148
+		    }
865 1149
 		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
1150
+		    if (isset($line['aircraft'])) {
1151
+		    	$data['aircraft_icao'] = $line['aircraft'];
1152
+		    }
1153
+		    if (isset($line['transponder'])) {
1154
+		    	$data['squawk'] = $line['transponder'];
1155
+		    }
1156
+		    if (isset($line['atis'])) {
1157
+		    	$data['info'] = $line['atis'];
1158
+		    } else {
1159
+		    	$data['info'] = '';
1160
+		    }
870 1161
 		    $data['format_source'] = 'pireps';
871 1162
     		    $data['id_source'] = $id_source;
872 1163
 		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1164
+		    if (isset($value['name']) && $value['name'] != '') {
1165
+		    	$data['source_name'] = $value['name'];
1166
+		    }
874 1167
 		    if ($line['icon'] == 'plane') {
875 1168
 			$SI->add($data);
876 1169
 		    //    print_r($data);
@@ -879,16 +1172,28 @@  discard block
 block discarded – undo
879 1172
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 1173
 			$typec = substr($data['ident'],-3);
881 1174
 			$data['type'] = '';
882
-			if ($typec == 'APP') $data['type'] = 'Approach';
883
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
884
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
885
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
886
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
887
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
888
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890
-			else $data['type'] = 'Observer';
891
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1175
+			if ($typec == 'APP') {
1176
+				$data['type'] = 'Approach';
1177
+			} elseif ($typec == 'TWR') {
1178
+				$data['type'] = 'Tower';
1179
+			} elseif ($typec == 'OBS') {
1180
+				$data['type'] = 'Observer';
1181
+			} elseif ($typec == 'GND') {
1182
+				$data['type'] = 'Ground';
1183
+			} elseif ($typec == 'DEL') {
1184
+				$data['type'] = 'Delivery';
1185
+			} elseif ($typec == 'DEP') {
1186
+				$data['type'] = 'Departure';
1187
+			} elseif ($typec == 'FSS') {
1188
+				$data['type'] = 'Flight Service Station';
1189
+			} elseif ($typec == 'CTR') {
1190
+				$data['type'] = 'Control Radar or Centre';
1191
+			} else {
1192
+				$data['type'] = 'Observer';
1193
+			}
1194
+			if (isset($ATC)) {
1195
+				echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1196
+			}
892 1197
 		    }
893 1198
 		    unset($data);
894 1199
 		}
@@ -898,7 +1203,9 @@  discard block
 block discarded – undo
898 1203
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899 1204
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900 1205
 	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
1206
+	    if ($globalDebug) {
1207
+	    	echo 'Get Data...'."\n";
1208
+	    }
902 1209
 	    $buffer = $Common->getData($value['host']);
903 1210
 	    $all_data = json_decode($buffer,true);
904 1211
 	    if ($buffer != '' && is_array($all_data)) {
@@ -906,10 +1213,16 @@  discard block
 block discarded – undo
906 1213
 		foreach ($all_data as $line) {
907 1214
 	    	    $data = array();
908 1215
 	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1216
+	    	    if (isset($line['pilotid'])) {
1217
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1218
+	    	    }
910 1219
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1220
+	    	    if (isset($line['pilotname'])) {
1221
+	    	    	$data['pilot_name'] = $line['pilotname'];
1222
+	    	    }
1223
+	    	    if (isset($line['pilotid'])) {
1224
+	    	    	$data['pilot_id'] = $line['pilotid'];
1225
+	    	    }
913 1226
 	    	    $data['ident'] = $line['flightnum']; // ident
914 1227
 	    	    $data['altitude'] = $line['alt']; // altitude
915 1228
 	    	    $data['speed'] = $line['gs']; // speed
@@ -927,27 +1240,41 @@  discard block
 block discarded – undo
927 1240
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
928 1241
     		    $data['arrival_airport_time'] = $line['arrtime'];
929 1242
     		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1243
+		    if (isset($line['route'])) {
1244
+		    	$data['waypoints'] = $line['route'];
1245
+		    }
1246
+		    // route
931 1247
 		    if (isset($line['aircraftname'])) {
932 1248
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 1249
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934 1250
 	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
1251
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1252
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1253
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1254
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1255
+	    		} else {
938 1256
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1257
+	    		    if (isset($aircraft_data[1])) {
1258
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1259
+	    		    } else {
1260
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1261
+	    		    }
941 1262
 	    		}
942 1263
 	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1264
+    		    if (isset($line['route'])) {
1265
+    		    	$data['waypoints'] = $line['route'];
1266
+    		    }
944 1267
     		    $data['id_source'] = $id_source;
945 1268
 	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1269
+		    if (isset($value['name']) && $value['name'] != '') {
1270
+		    	$data['source_name'] = $value['name'];
1271
+		    }
947 1272
 		    $SI->add($data);
948 1273
 		    unset($data);
949 1274
 		}
950
-		if ($globalDebug) echo 'No more data...'."\n";
1275
+		if ($globalDebug) {
1276
+			echo 'No more data...'."\n";
1277
+		}
951 1278
 		unset($buffer);
952 1279
 		unset($all_data);
953 1280
 	    }
@@ -955,7 +1282,9 @@  discard block
 block discarded – undo
955 1282
     	    $last_exec[$id]['last'] = time();
956 1283
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957 1284
 	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
1285
+	    if ($globalDebug) {
1286
+	    	echo 'Get Data...'."\n";
1287
+	    }
959 1288
 	    $buffer = $Common->getData($value['host']);
960 1289
 	    $all_data = json_decode($buffer,true);
961 1290
 	    if ($buffer != '' && is_array($all_data)) {
@@ -984,15 +1313,22 @@  discard block
 block discarded – undo
984 1313
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
985 1314
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
986 1315
     		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1316
+		    if (isset($line['route'])) {
1317
+		    	$data['waypoints'] = $line['route'];
1318
+		    }
1319
+		    // route
988 1320
 	    	    $data['aircraft_icao'] = $line['plane_type'];
989 1321
     		    $data['id_source'] = $id_source;
990 1322
 	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1323
+		    if (isset($value['name']) && $value['name'] != '') {
1324
+		    	$data['source_name'] = $value['name'];
1325
+		    }
992 1326
 		    $SI->add($data);
993 1327
 		    unset($data);
994 1328
 		}
995
-		if ($globalDebug) echo 'No more data...'."\n";
1329
+		if ($globalDebug) {
1330
+			echo 'No more data...'."\n";
1331
+		}
996 1332
 		unset($buffer);
997 1333
 		unset($all_data);
998 1334
 	    }
@@ -1000,7 +1336,9 @@  discard block
 block discarded – undo
1000 1336
     	    $last_exec[$id]['last'] = time();
1001 1337
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1338
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1339
+	    if (function_exists('pcntl_fork')) {
1340
+	    	pcntl_signal_dispatch();
1341
+	    }
1004 1342
     	    //$last_exec[$id]['last'] = time();
1005 1343
 
1006 1344
 	    //$read = array( $sockets[$id] );
@@ -1008,7 +1346,9 @@  discard block
 block discarded – undo
1008 1346
 	    $write = NULL;
1009 1347
 	    $e = NULL;
1010 1348
 	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1349
+	    if ($e != NULL) {
1350
+	    	var_dump($e);
1351
+	    }
1012 1352
 	    if ($n > 0) {
1013 1353
 		$reset = 0;
1014 1354
 		foreach ($read as $nb => $r) {
@@ -1027,12 +1367,16 @@  discard block
 block discarded – undo
1027 1367
 		    //$SI::del();
1028 1368
 		    if ($format == 'vrstcp') {
1029 1369
 			$buffer = explode('},{',$buffer);
1030
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1370
+		    } else {
1371
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1372
+		    }
1031 1373
 		    // SBS format is CSV format
1032 1374
 		    if ($buffer != '') {
1033 1375
 			$tt[$format] = 0;
1034 1376
 			if ($format == 'acarssbs3') {
1035
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1377
+                    	    if ($globalDebug) {
1378
+                    	    	echo 'ACARS : '.$buffer."\n";
1379
+                    	    }
1036 1380
 			    $ACARS->add(trim($buffer));
1037 1381
 			    $ACARS->deleteLiveAcarsData();
1038 1382
 			} elseif ($format == 'raw') {
@@ -1041,25 +1385,55 @@  discard block
 block discarded – undo
1041 1385
 			    if (is_array($data)) {
1042 1386
 				$data['datetime'] = date('Y-m-d H:i:s');
1043 1387
 				$data['format_source'] = 'raw';
1044
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1045
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1046
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1388
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1389
+					$data['source_name'] = $globalSources[$nb]['name'];
1390
+				}
1391
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1392
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1393
+    				}
1394
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1395
+                                	$SI->add($data);
1396
+                                }
1047 1397
                             }
1048 1398
                         } elseif ($format == 'ais') {
1049 1399
 			    $ais_data = $AIS->parse_line(trim($buffer));
1050 1400
 			    $data = array();
1051
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1052
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1053
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1054
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1055
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1056
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1057
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1058
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1059
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1060
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1061
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1062
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1401
+			    if (isset($ais_data['ident'])) {
1402
+			    	$data['ident'] = $ais_data['ident'];
1403
+			    }
1404
+			    if (isset($ais_data['mmsi'])) {
1405
+			    	$data['mmsi'] = $ais_data['mmsi'];
1406
+			    }
1407
+			    if (isset($ais_data['speed'])) {
1408
+			    	$data['speed'] = $ais_data['speed'];
1409
+			    }
1410
+			    if (isset($ais_data['heading'])) {
1411
+			    	$data['heading'] = $ais_data['heading'];
1412
+			    }
1413
+			    if (isset($ais_data['latitude'])) {
1414
+			    	$data['latitude'] = $ais_data['latitude'];
1415
+			    }
1416
+			    if (isset($ais_data['longitude'])) {
1417
+			    	$data['longitude'] = $ais_data['longitude'];
1418
+			    }
1419
+			    if (isset($ais_data['status'])) {
1420
+			    	$data['status'] = $ais_data['status'];
1421
+			    }
1422
+			    if (isset($ais_data['type'])) {
1423
+			    	$data['type'] = $ais_data['type'];
1424
+			    }
1425
+			    if (isset($ais_data['imo'])) {
1426
+			    	$data['imo'] = $ais_data['imo'];
1427
+			    }
1428
+			    if (isset($ais_data['callsign'])) {
1429
+			    	$data['callsign'] = $ais_data['callsign'];
1430
+			    }
1431
+			    if (isset($ais_data['destination'])) {
1432
+			    	$data['arrival_code'] = $ais_data['destination'];
1433
+			    }
1434
+			    if (isset($ais_data['eta_ts'])) {
1435
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1436
+			    }
1063 1437
 
1064 1438
 			    if (isset($ais_data['timestamp'])) {
1065 1439
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1068,7 +1442,9 @@  discard block
 block discarded – undo
1068 1442
 			    }
1069 1443
 			    $data['format_source'] = 'aisnmea';
1070 1444
     			    $data['id_source'] = $id_source;
1071
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1445
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1446
+			    	$MI->add($data);
1447
+			    }
1072 1448
 			    unset($data);
1073 1449
                         } elseif ($format == 'flightgearsp') {
1074 1450
                     	    //echo $buffer."\n";
@@ -1086,11 +1462,15 @@  discard block
 block discarded – undo
1086 1462
 				$data['speed'] = round($line[5]*1.94384);
1087 1463
 				$data['datetime'] = date('Y-m-d H:i:s');
1088 1464
 				$data['format_source'] = 'flightgearsp';
1089
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1465
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1466
+					$SI->add($data);
1467
+				}
1090 1468
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1091 1469
 			    }
1092 1470
                         } elseif ($format == 'acars') {
1093
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1471
+                    	    if ($globalDebug) {
1472
+                    	    	echo 'ACARS : '.$buffer."\n";
1473
+                    	    }
1094 1474
 			    $ACARS->add(trim($buffer));
1095 1475
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1096 1476
 			    $ACARS->deleteLiveAcarsData();
@@ -1111,7 +1491,9 @@  discard block
 block discarded – undo
1111 1491
 				    $aircraft_type = $line[10];
1112 1492
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1113 1493
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1114
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1494
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1495
+				    	$SI->add($data);
1496
+				    }
1115 1497
 				}
1116 1498
 			    }
1117 1499
 			} elseif ($format == 'beast') {
@@ -1121,27 +1503,59 @@  discard block
 block discarded – undo
1121 1503
 			    foreach($buffer as $all_data) {
1122 1504
 				$line = json_decode('{'.$all_data.'}',true);
1123 1505
 				$data = array();
1124
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1125
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1126
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1127
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1128
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1129
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1130
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1506
+				if (isset($line['Icao'])) {
1507
+					$data['hex'] = $line['Icao'];
1508
+				}
1509
+				// hex
1510
+				if (isset($line['Call'])) {
1511
+					$data['ident'] = $line['Call'];
1512
+				}
1513
+				// ident
1514
+				if (isset($line['Alt'])) {
1515
+					$data['altitude'] = $line['Alt'];
1516
+				}
1517
+				// altitude
1518
+				if (isset($line['Spd'])) {
1519
+					$data['speed'] = $line['Spd'];
1520
+				}
1521
+				// speed
1522
+				if (isset($line['Trak'])) {
1523
+					$data['heading'] = $line['Trak'];
1524
+				}
1525
+				// heading
1526
+				if (isset($line['Lat'])) {
1527
+					$data['latitude'] = $line['Lat'];
1528
+				}
1529
+				// lat
1530
+				if (isset($line['Long'])) {
1531
+					$data['longitude'] = $line['Long'];
1532
+				}
1533
+				// long
1131 1534
 				//$data['verticalrate'] = $line['']; // verticale rate
1132
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1535
+				if (isset($line['Sqk'])) {
1536
+					$data['squawk'] = $line['Sqk'];
1537
+				}
1538
+				// squawk
1133 1539
 				$data['emergency'] = ''; // emergency
1134
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1540
+				if (isset($line['Reg'])) {
1541
+					$data['registration'] = $line['Reg'];
1542
+				}
1135 1543
 				/*
1136 1544
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1137 1545
 				else $data['datetime'] = date('Y-m-d H:i:s');
1138 1546
 				*/
1139 1547
 				$data['datetime'] = date('Y-m-d H:i:s');
1140
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1548
+				if (isset($line['Type'])) {
1549
+					$data['aircraft_icao'] = $line['Type'];
1550
+				}
1141 1551
 		    		$data['format_source'] = 'vrstcp';
1142 1552
 				$data['id_source'] = $id_source;
1143
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1144
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1553
+				if (isset($value['name']) && $value['name'] != '') {
1554
+					$data['source_name'] = $value['name'];
1555
+				}
1556
+				if (isset($data['latitude']) && isset($data['hex'])) {
1557
+					$SI->add($data);
1558
+				}
1145 1559
 				unset($data);
1146 1560
 			    }
1147 1561
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1154,21 +1568,43 @@  discard block
 block discarded – undo
1154 1568
     				$data['hex'] = $lined['hexid'];
1155 1569
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1156 1570
     				$data['datetime'] = date('Y-m-d H:i:s');;
1157
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1158
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1159
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1160
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1161
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1162
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1163
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1571
+    				if (isset($lined['ident'])) {
1572
+    					$data['ident'] = $lined['ident'];
1573
+    				}
1574
+    				if (isset($lined['lat'])) {
1575
+    					$data['latitude'] = $lined['lat'];
1576
+    				}
1577
+    				if (isset($lined['lon'])) {
1578
+    					$data['longitude'] = $lined['lon'];
1579
+    				}
1580
+    				if (isset($lined['speed'])) {
1581
+    					$data['speed'] = $lined['speed'];
1582
+    				}
1583
+    				if (isset($lined['squawk'])) {
1584
+    					$data['squawk'] = $lined['squawk'];
1585
+    				}
1586
+    				if (isset($lined['alt'])) {
1587
+    					$data['altitude'] = $lined['alt'];
1588
+    				}
1589
+    				if (isset($lined['heading'])) {
1590
+    					$data['heading'] = $lined['heading'];
1591
+    				}
1164 1592
     				$data['id_source'] = $id_source;
1165 1593
     				$data['format_source'] = 'tsv';
1166
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1167
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1168
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1594
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1595
+    					$data['source_name'] = $globalSources[$nb]['name'];
1596
+    				}
1597
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1598
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1599
+    				}
1600
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1601
+    					$SI->add($data);
1602
+    				}
1169 1603
     				unset($lined);
1170 1604
     				unset($data);
1171
-    			    } else $error = true;
1605
+    			    } else {
1606
+    			    	$error = true;
1607
+    			    }
1172 1608
 			} elseif ($format == 'aprs' && $use_aprs) {
1173 1609
 			    if ($aprs_connect == 0) {
1174 1610
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1194,49 +1630,82 @@  discard block
 block discarded – undo
1194 1630
 				    $aprs_last_tx = time();
1195 1631
 				    $data = array();
1196 1632
 				    //print_r($line);
1197
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1198
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1199
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1633
+				    if (isset($line['address'])) {
1634
+				    	$data['hex'] = $line['address'];
1635
+				    }
1636
+				    if (isset($line['timestamp'])) {
1637
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1638
+				    } else {
1639
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1640
+				    }
1200 1641
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1201
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1642
+				    if (isset($line['ident'])) {
1643
+				    	$data['ident'] = $line['ident'];
1644
+				    }
1202 1645
 				    $data['latitude'] = $line['latitude'];
1203 1646
 				    $data['longitude'] = $line['longitude'];
1204 1647
 				    //$data['verticalrate'] = $line[16];
1205
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1206
-				    else $data['speed'] = 0;
1207
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1208
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1209
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1210
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1648
+				    if (isset($line['speed'])) {
1649
+				    	$data['speed'] = $line['speed'];
1650
+				    } else {
1651
+				    	$data['speed'] = 0;
1652
+				    }
1653
+				    if (isset($line['altitude'])) {
1654
+				    	$data['altitude'] = $line['altitude'];
1655
+				    }
1656
+				    if (isset($line['comment'])) {
1657
+				    	$data['comment'] = $line['comment'];
1658
+				    }
1659
+				    if (isset($line['symbol'])) {
1660
+				    	$data['type'] = $line['symbol'];
1661
+				    }
1662
+				    if (isset($line['heading'])) {
1663
+				    	$data['heading'] = $line['heading'];
1664
+				    }
1211 1665
 				    //else $data['heading'] = 0;
1212
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1213
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1666
+				    if (isset($line['stealth'])) {
1667
+				    	$data['aircraft_type'] = $line['stealth'];
1668
+				    }
1669
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1670
+				    	$data['noarchive'] = true;
1671
+				    }
1214 1672
     				    $data['id_source'] = $id_source;
1215
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1216
-				    else $data['format_source'] = 'aprs';
1673
+    				    if (isset($line['format_source'])) {
1674
+    				    	$data['format_source'] = $line['format_source'];
1675
+    				    } else {
1676
+				    	$data['format_source'] = 'aprs';
1677
+				    }
1217 1678
 				    $data['source_name'] = $line['source'];
1218
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1219
-				    else $data['source_type'] = 'flarm';
1220
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1679
+				    if (isset($line['source_type'])) {
1680
+				    	$data['source_type'] = $line['source_type'];
1681
+				    } else {
1682
+				    	$data['source_type'] = 'flarm';
1683
+				    }
1684
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1685
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1686
+    				    }
1221 1687
 				    $currentdate = date('Y-m-d H:i:s');
1222 1688
 				    $aprsdate = strtotime($data['datetime']);
1223 1689
 				    // Accept data if time <= system time + 20s
1224 1690
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1225 1691
 					$send = $SI->add($data);
1226 1692
 				    } elseif (isset($line['stealth'])) {
1227
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1228
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1693
+					if ($line['stealth'] != 0) {
1694
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1695
+					} else {
1696
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1697
+					}
1229 1698
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1230 1699
 				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1231 1700
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1232
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1701
+					if (isset($globalTracker) && $globalTracker) {
1702
+						$send = $TI->add($data);
1703
+					}
1233 1704
 				    }
1234 1705
 				    unset($data);
1235
-				} 
1236
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1706
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1237 1707
 					echo '!! Weather Station not yet supported'."\n";
1238
-				}
1239
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1708
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1240 1709
 					echo '!! Car & Trucks not yet supported'."\n";
1241 1710
 				}
1242 1711
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1269,25 +1738,42 @@  discard block
 block discarded – undo
1269 1738
     				$data['ground'] = $line[21];
1270 1739
     				$data['emergency'] = $line[19];
1271 1740
     				$data['format_source'] = 'sbs';
1272
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1273
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1741
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1742
+					$data['source_name'] = $globalSources[$nb]['name'];
1743
+				}
1744
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1745
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1746
+    				}
1274 1747
     				$data['id_source'] = $id_source;
1275
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1276
-    				else $error = true;
1748
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1749
+    					$send = $SI->add($data);
1750
+    				} else {
1751
+    					$error = true;
1752
+    				}
1277 1753
     				unset($data);
1278
-    			    } else $error = true;
1754
+    			    } else {
1755
+    			    	$error = true;
1756
+    			    }
1279 1757
 			    if ($error) {
1280 1758
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1281
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1759
+					if ($globalDebug) {
1760
+						echo "Not a message. Ignoring... \n";
1761
+					}
1282 1762
 				} else {
1283
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1763
+					if ($globalDebug) {
1764
+						echo "Wrong line format. Ignoring... \n";
1765
+					}
1284 1766
 					if ($globalDebug) {
1285 1767
 						echo $buffer;
1286 1768
 						print_r($line);
1287 1769
 					}
1288 1770
 					//socket_close($r);
1289
-					if ($globalDebug) echo "Reconnect after an error...\n";
1290
-					if ($format == 'aprs') $aprs_connect = 0;
1771
+					if ($globalDebug) {
1772
+						echo "Reconnect after an error...\n";
1773
+					}
1774
+					if ($format == 'aprs') {
1775
+						$aprs_connect = 0;
1776
+					}
1291 1777
 					$sourceer[$nb] = $globalSources[$nb];
1292 1778
 					connect_all($sourceer);
1293 1779
 					$sourceer = array();
@@ -1295,10 +1781,14 @@  discard block
 block discarded – undo
1295 1781
 			    }
1296 1782
 			}
1297 1783
 			// Sleep for xxx microseconds
1298
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1784
+			if (isset($globalSBSSleep)) {
1785
+				usleep($globalSBSSleep);
1786
+			}
1299 1787
 		    } else {
1300 1788
 			if ($format == 'flightgearmp') {
1301
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1789
+			    	if ($globalDebug) {
1790
+			    		echo "Reconnect FlightGear MP...";
1791
+			    	}
1302 1792
 				//@socket_close($r);
1303 1793
 				sleep($globalMinFetch);
1304 1794
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1307,10 +1797,15 @@  discard block
 block discarded – undo
1307 1797
 				break;
1308 1798
 				
1309 1799
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1310
-			    if (isset($tt[$format])) $tt[$format]++;
1311
-			    else $tt[$format] = 0;
1800
+			    if (isset($tt[$format])) {
1801
+			    	$tt[$format]++;
1802
+			    } else {
1803
+			    	$tt[$format] = 0;
1804
+			    }
1312 1805
 			    if ($tt[$format] > 30) {
1313
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1806
+				if ($globalDebug) {
1807
+					echo "ERROR : Reconnect ".$format."...";
1808
+				}
1314 1809
 				//@socket_close($r);
1315 1810
 				sleep(2);
1316 1811
 				$aprs_connect = 0;
@@ -1327,11 +1822,17 @@  discard block
 block discarded – undo
1327 1822
 	    } else {
1328 1823
 		$error = socket_strerror(socket_last_error());
1329 1824
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1330
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1331
-			if (isset($globalDebug)) echo "Restarting...\n";
1825
+			if ($globalDebug) {
1826
+				echo "ERROR : socket_select give this error ".$error . "\n";
1827
+			}
1828
+			if (isset($globalDebug)) {
1829
+				echo "Restarting...\n";
1830
+			}
1332 1831
 			// Restart the script if possible
1333 1832
 			if (is_array($sockets)) {
1334
-			    if ($globalDebug) echo "Shutdown all sockets...";
1833
+			    if ($globalDebug) {
1834
+			    	echo "Shutdown all sockets...";
1835
+			    }
1335 1836
 			    
1336 1837
 			    foreach ($sockets as $sock) {
1337 1838
 				@socket_shutdown($sock,2);
@@ -1339,18 +1840,24 @@  discard block
 block discarded – undo
1339 1840
 			    }
1340 1841
 			    
1341 1842
 			}
1342
-			if ($globalDebug) echo "Restart all connections...";
1843
+			if ($globalDebug) {
1844
+				echo "Restart all connections...";
1845
+			}
1343 1846
 			sleep(2);
1344 1847
 			$time = time();
1345 1848
 			//connect_all($hosts);
1346 1849
 			$aprs_connect = 0;
1347
-			if ($reset > 40) exit('Too many attempts...');
1850
+			if ($reset > 40) {
1851
+				exit('Too many attempts...');
1852
+			}
1348 1853
 			connect_all($globalSources);
1349 1854
 		}
1350 1855
 	    }
1351 1856
 	}
1352 1857
 	if ($globalDaemon === false) {
1353
-	    if ($globalDebug) echo 'Check all...'."\n";
1858
+	    if ($globalDebug) {
1859
+	    	echo 'Check all...'."\n";
1860
+	    }
1354 1861
 	    $SI->checkAll();
1355 1862
 	}
1356 1863
     }
Please login to merge, or discard this patch.
require/class.SpotterImport.php 3 patches
Indentation   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class SpotterImport {
13
-    private $all_flights = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
21
-
22
-    public function __construct($dbc = null) {
13
+	private $all_flights = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21
+
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta, $globalServerAPRS, $APRSSpotter;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
34
-	    	$type = $srcst['stats_type'];
33
+		foreach($sourcestat as $srcst) {
34
+			$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36
-		    $source = $srcst['source_name'];
37
-		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
-	        }
40
-	    }
36
+			$source = $srcst['source_name'];
37
+			$data = $srcst['source_data'];
38
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
+			}
40
+		}
41 41
 	}
42 42
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
43 43
 		$APRSSpotter = new APRSSpotter();
44 44
 		//$APRSSpotter->connect();
45 45
 	}
46 46
 
47
-    }
47
+	}
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+	public function get_Schedule($id,$ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -66,42 +66,42 @@  discard block
 block discarded – undo
66 66
 	$operator = $Spotter->getOperator($ident);
67 67
 	$scheduleexist = false;
68 68
 	if ($Schedule->checkSchedule($operator) == 0) {
69
-	    $operator = $Translation->checkTranslation($ident);
70
-	    if ($Schedule->checkSchedule($operator) == 0) {
69
+		$operator = $Translation->checkTranslation($ident);
70
+		if ($Schedule->checkSchedule($operator) == 0) {
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
-		    // Should also check if route schedule = route from DB
77
-		    if ($schedule['DepartureAirportIATA'] != '') {
73
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
+			// Should also check if route schedule = route from DB
77
+			if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
79
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
-			    if (trim($airport_icao) != '') {
79
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
+				if (trim($airport_icao) != '') {
81 81
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82 82
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
83
-			    }
83
+				}
84
+			}
84 85
 			}
85
-		    }
86
-		    if ($schedule['ArrivalAirportIATA'] != '') {
86
+			if ($schedule['ArrivalAirportIATA'] != '') {
87 87
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
88
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
-			    if (trim($airport_icao) != '') {
88
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
+				if (trim($airport_icao) != '') {
90 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91 91
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
92
-			    }
92
+				}
93
+			}
93 94
 			}
94
-		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 96
 		}
97
-	    } else $scheduleexist = true;
97
+		} else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
99 99
 	// close connection, at least one way will work ?
100
-       if ($scheduleexist) {
100
+	   if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102
-    		$sch = $Schedule->getSchedule($operator);
102
+			$sch = $Schedule->getSchedule($operator);
103 103
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104
-       }
104
+	   }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
107 107
 	$Translation->db = null;
@@ -116,96 +116,96 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 	  */
118 118
 	}
119
-    }
119
+	}
120 120
 
121
-    public function checkAll() {
121
+	public function checkAll() {
122 122
 	global $globalDebug, $globalNoImport;
123 123
 	if ($globalDebug) echo "Update last seen flights data...\n";
124 124
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125
-	    foreach ($this->all_flights as $key => $flight) {
125
+		foreach ($this->all_flights as $key => $flight) {
126 126
 		if (isset($this->all_flights[$key]['id'])) {
127
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
-    		    $Spotter = new Spotter($this->db);
129
-        	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
-        	}
132
-	    }
127
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
+				$Spotter = new Spotter($this->db);
129
+				$real_arrival = $this->arrival($key);
130
+				$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
+			}
132
+		}
133
+	}
133 134
 	}
134
-    }
135 135
 
136
-    public function arrival($key) {
136
+	public function arrival($key) {
137 137
 	global $globalClosestMinDist, $globalDebug;
138 138
 	if ($globalDebug) echo 'Update arrival...'."\n";
139 139
 	$Spotter = new Spotter($this->db);
140
-        $airport_icao = '';
141
-        $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
140
+		$airport_icao = '';
141
+		$airport_time = '';
142
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
-    	    if (isset($closestAirports[0])) {
146
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
-        	    $airport_icao = $closestAirports[0]['icao'];
148
-        	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
-        	    foreach ($closestAirports as $airport) {
152
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
-        		    $airport_icao = $airport['icao'];
154
-        		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
-        		    break;
157
-        		}
158
-        	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
-        		$airport_icao = $closestAirports[0]['icao'];
161
-        		$airport_time = $this->all_flights[$key]['datetime'];
162
-        	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
-        	}
165
-    	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
-    	    }
168
-
169
-        } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
-        }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
-    }
174
-
175
-
176
-
177
-    public function del() {
144
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
+			if (isset($closestAirports[0])) {
146
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
+				$airport_icao = $closestAirports[0]['icao'];
148
+				$airport_time = $this->all_flights[$key]['datetime'];
149
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
+				foreach ($closestAirports as $airport) {
152
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
+					$airport_icao = $airport['icao'];
154
+					$airport_time = $this->all_flights[$key]['datetime'];
155
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
+					break;
157
+				}
158
+				}
159
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
+				$airport_icao = $closestAirports[0]['icao'];
161
+				$airport_time = $this->all_flights[$key]['datetime'];
162
+			} else {
163
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
+			}
165
+			} else {
166
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
+			}
168
+
169
+		} else {
170
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
+		}
172
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
+	}
174
+
175
+
176
+
177
+	public function del() {
178 178
 	global $globalDebug, $globalNoImport;
179 179
 	// Delete old infos
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182
-    	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
184
-            	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
182
+			if (isset($flight['lastupdate'])) {
183
+			if ($flight['lastupdate'] < (time()-3000)) {
184
+					if (isset($this->all_flights[$key]['id'])) {
185
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
187 187
 			$SpotterLive = new SpotterLive();
188 188
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
189 189
 			$SpotterLive->db = null;
190 190
 			*/
191 191
 			if (!isset($globalNoImport) || $globalNoImport === FALSE) {
192
-            		    $real_arrival = $this->arrival($key);
193
-            		    $Spotter = new Spotter($this->db);
194
-            	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
192
+						$real_arrival = $this->arrival($key);
193
+						$Spotter = new Spotter($this->db);
194
+							if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 195
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197
-			    }
197
+				}
198 198
 			// Put in archive
199 199
 //				$Spotter->db = null;
200 200
 			}
201
-            	    }
202
-            	    unset($this->all_flights[$key]);
203
-    	        }
204
-	    }
205
-        }
206
-    }
201
+					}
202
+					unset($this->all_flights[$key]);
203
+				}
204
+		}
205
+		}
206
+	}
207 207
 
208
-    public function add($line) {
208
+	public function add($line) {
209 209
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 210
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211 211
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 	
231 231
 	// SBS format is CSV format
232 232
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233
-	    //print_r($line);
234
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
233
+		//print_r($line);
234
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
236 236
 		// Increment message number
237 237
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238
-		    $current_date = date('Y-m-d');
239
-		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
238
+			$current_date = date('Y-m-d');
239
+			$source = $line['source_name'];
240
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
242
+				$this->stats[$current_date][$source]['msg']['date'] = time();
243
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
245 245
 		}
246 246
 		
247 247
 		/*
@@ -257,34 +257,34 @@  discard block
 block discarded – undo
257 257
 		//$this->db = $dbc;
258 258
 
259 259
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
260
+			if (!isset($line['id'])) $id = trim($line['hex']);
261
+			else $id = trim($line['id']);
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264
-		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
-		    if (!isset($line['id'])) {
264
+			$this->all_flights[$id] = array();
265
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
+			if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272 272
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
273
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
273
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
+			if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
283
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
286
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 			$Spotter->db = null;
296 296
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297 297
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
298
-		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298
+			}
299
+			if ($globalAllFlights !== FALSE) $dataFound = true;
300
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 303
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323 323
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
324
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
324
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 325
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326
-		    } else {
326
+			} else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
329 329
 				/*
@@ -332,41 +332,41 @@  discard block
 block discarded – undo
332 332
 				print_r($line);
333 333
 				*/
334 334
 				return '';
335
-		    }
335
+			}
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338 338
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
355
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358
-            		$Spotter = new Spotter($this->db);
359
-            		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
358
+					$Spotter = new Spotter($this->db);
359
+					$fromsource = NULL;
360
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368 368
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
-		    }
369
+			}
370 370
 
371 371
 /*
372 372
 		    if (!isset($line['id'])) {
@@ -376,26 +376,26 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381
-		    //$putinarchive = true;
382
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
381
+			//$putinarchive = true;
382
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383 383
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
384
-		    }
385
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
384
+			}
385
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386 386
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
387
-		    }
388
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
387
+			}
388
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
395
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396 396
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397 397
 
398
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
398
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
400 400
 			$Spotter = new Spotter($this->db);
401 401
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -409,67 +409,67 @@  discard block
 block discarded – undo
409 409
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
412
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
-		    	    }
415
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
+					}
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420 420
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
421 421
 			}
422
-		    }
422
+			}
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
-		    //$dataFound = true;
427
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
+			//$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
-		    if ($distance > 1000 && $distance < 10000) {
433
-		    // use datetime
431
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
+			if ($distance > 1000 && $distance < 10000) {
433
+			// use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436 436
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438
-		    }
438
+			}
439 439
 		}
440 440
 
441 441
 
442 442
 
443
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
443
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
+				else unset($timediff);
446
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
452 452
 				$this->tmd = 0;
453 453
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
454
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455
-				    $timeelapsed = microtime(true);
456
-				    $Spotter = new Spotter($this->db);
457
-				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
-				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459
-				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
-				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
454
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455
+					$timeelapsed = microtime(true);
456
+					$Spotter = new Spotter($this->db);
457
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
+					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459
+					$Spotter->db = null;
460
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
+					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462
+				}
462 463
 				}
463
-			    }
464 464
 			}
465 465
 
466 466
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468 468
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
469 469
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471
-				    $dataFound = true;
472
-				    $this->all_flights[$id]['time_last_coord'] = time();
470
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471
+					$dataFound = true;
472
+					$this->all_flights[$id]['time_last_coord'] = time();
473 473
 				}
474 474
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
475 475
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
 				    //$putinarchive = true;
481 481
 				}
482 482
 				*/
483
-			    /*
483
+				/*
484 484
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
485 485
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
486 486
 			    }
487 487
 			    */
488 488
 			}
489 489
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
490
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
490
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492 492
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
493 493
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495
-				    $dataFound = true;
496
-				    $this->all_flights[$id]['time_last_coord'] = time();
494
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495
+					$dataFound = true;
496
+					$this->all_flights[$id]['time_last_coord'] = time();
497 497
 				}
498 498
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
499 499
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -511,54 +511,54 @@  discard block
 block discarded – undo
511 511
 			    */
512 512
 			}
513 513
 
514
-		    } else if ($globalDebug && $timediff > 20) {
514
+			} else if ($globalDebug && $timediff > 20) {
515 515
 			$this->tmd = $this->tmd + 1;
516 516
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
517 517
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
518 518
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
519 519
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
520
-		    }
520
+			}
521 521
 		}
522 522
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
523
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
525 525
 		}
526 526
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
527
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
528
-		    //$dataFound = true;
527
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
528
+			//$dataFound = true;
529 529
 		}
530 530
 		if (isset($line['format_source']) && $line['format_source'] != '') {
531
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
532 532
 		}
533 533
 		if (isset($line['source_name']) && $line['source_name'] != '') {
534
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
535 535
 		}
536 536
 		if (isset($line['emergency']) && $line['emergency'] != '') {
537
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
538
-		    //$dataFound = true;
537
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
538
+			//$dataFound = true;
539 539
 		}
540 540
 		if (isset($line['ground']) && $line['ground'] != '') {
541
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
541
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
542 542
 			// Here we force archive of flight because after ground it's a new one (or should be)
543 543
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544 544
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545 545
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547 547
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
548
-		    }
549
-		    if ($line['ground'] != 1) $line['ground'] = 0;
550
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551
-		    //$dataFound = true;
548
+			}
549
+			if ($line['ground'] != 1) $line['ground'] = 0;
550
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551
+			//$dataFound = true;
552 552
 		}
553 553
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557
-			    $highlight = '';
558
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
561
-			    if ($highlight != '') {
554
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557
+				$highlight = '';
558
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
561
+				if ($highlight != '') {
562 562
 				$timeelapsed = microtime(true);
563 563
 				$Spotter = new Spotter($this->db);
564 564
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -567,38 +567,38 @@  discard block
 block discarded – undo
567 567
 
568 568
 				//$putinarchive = true;
569 569
 				//$highlight = '';
570
-			    }
570
+				}
571 571
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
573
-		    //$dataFound = true;
572
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
573
+			//$dataFound = true;
574 574
 		}
575 575
 
576 576
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578 578
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579 579
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580 580
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
581 581
 			//$dataFound = true;
582
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
582
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
583 583
   		}
584 584
 
585 585
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
586
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
587 587
 		}
588 588
 		
589 589
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593
-		    //$dataFound = true;
590
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593
+			//$dataFound = true;
594 594
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
595
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
599 599
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600
-  		    // If not enough messages and ACARS set heading to 0
601
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
600
+  			// If not enough messages and ACARS set heading to 0
601
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
602 602
   		}
603 603
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604 604
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -609,121 +609,121 @@  discard block
 block discarded – undo
609 609
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
610 610
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
611 611
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
612
-		    $this->all_flights[$id]['lastupdate'] = time();
613
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615
-			    //print_r($this->all_flights);
616
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
612
+			$this->all_flights[$id]['lastupdate'] = time();
613
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615
+				//print_r($this->all_flights);
616
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
619 619
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
620 620
 				$timeelapsed = microtime(true);
621 621
 				$SpotterLive = new SpotterLive($this->db);
622 622
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
623
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
625 625
 				} elseif (isset($line['id'])) {
626
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
626
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
628 628
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
629
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
631 631
 				} else $recent_ident = '';
632 632
 				$SpotterLive->db=null;
633 633
 
634 634
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635 635
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
636
-			    } else {
636
+				} else {
637 637
 				$recent_ident = '';
638 638
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
639
-			    }
640
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
-			    if($recent_ident == "")
642
-			    {
639
+				}
640
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
+				if($recent_ident == "")
642
+				{
643 643
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
644 644
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 645
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 646
 				//adds the spotter data for the archive
647 647
 				$ignoreImport = false;
648 648
 				foreach($globalAirportIgnore as $airportIgnore) {
649
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
649
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
650 650
 					$ignoreImport = true;
651
-				    }
651
+					}
652 652
 				}
653 653
 				if (count($globalAirportAccept) > 0) {
654
-				    $ignoreImport = true;
655
-				    foreach($globalAirportIgnore as $airportIgnore) {
654
+					$ignoreImport = true;
655
+					foreach($globalAirportIgnore as $airportIgnore) {
656 656
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
657
-					    $ignoreImport = false;
657
+						$ignoreImport = false;
658
+					}
658 659
 					}
659
-				    }
660 660
 				}
661 661
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
662
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
662
+					foreach($globalAirlineIgnore as $airlineIgnore) {
663 663
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
664
-					    $ignoreImport = true;
664
+						$ignoreImport = true;
665
+					}
665 666
 					}
666
-				    }
667 667
 				}
668 668
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
669
-				    $ignoreImport = true;
670
-				    foreach($globalAirlineAccept as $airlineAccept) {
669
+					$ignoreImport = true;
670
+					foreach($globalAirlineAccept as $airlineAccept) {
671 671
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
672
-					    $ignoreImport = false;
672
+						$ignoreImport = false;
673
+					}
673 674
 					}
674
-				    }
675 675
 				}
676 676
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
677
-				    $ignoreImport = true;
678
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
677
+					$ignoreImport = true;
678
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
679 679
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
680
-					    $ignoreImport = false;
680
+						$ignoreImport = false;
681
+					}
681 682
 					}
682
-				    }
683 683
 				}
684 684
 				
685 685
 				if (!$ignoreImport) {
686
-				    $highlight = '';
687
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691
-				    $timeelapsed = microtime(true);
692
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
686
+					$highlight = '';
687
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691
+					$timeelapsed = microtime(true);
692
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 693
 					$Spotter = new Spotter($this->db);
694 694
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
695 695
 					$Spotter->db = null;
696 696
 					if ($globalDebug && isset($result)) echo $result."\n";
697
-				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697
+					}
698
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
699 699
 				    
700
-				    // Add source stat in DB
701
-				    $Stats = new Stats($this->db);
702
-				    if (!empty($this->stats)) {
700
+					// Add source stat in DB
701
+					$Stats = new Stats($this->db);
702
+					if (!empty($this->stats)) {
703 703
 					if ($globalDebug) echo 'Add source stats : ';
704
-				        foreach($this->stats as $date => $data) {
705
-					    foreach($data as $source => $sourced) {
706
-					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
709
-				    		if (isset($sourced['msg'])) {
710
-				    		    if (time() - $sourced['msg']['date'] > 10) {
711
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
713
-			    			        unset($this->stats[$date][$source]['msg']);
714
-			    			    }
715
-			    			}
716
-			    		    }
717
-			    		    if ($date != date('Y-m-d')) {
718
-			    			unset($this->stats[$date]);
719
-			    		    }
720
-				    	}
721
-				    	if ($globalDebug) echo 'Done'."\n";
722
-
723
-				    }
724
-				    $Stats->db = null;
704
+						foreach($this->stats as $date => $data) {
705
+						foreach($data as $source => $sourced) {
706
+							//print_r($sourced);
707
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
709
+							if (isset($sourced['msg'])) {
710
+								if (time() - $sourced['msg']['date'] > 10) {
711
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
713
+									unset($this->stats[$date][$source]['msg']);
714
+								}
715
+							}
716
+							}
717
+							if ($date != date('Y-m-d')) {
718
+							unset($this->stats[$date]);
719
+							}
720
+						}
721
+						if ($globalDebug) echo 'Done'."\n";
722
+
723
+					}
724
+					$Stats->db = null;
725 725
 				    
726
-				    $this->del();
726
+					$this->del();
727 727
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
728 728
 				//$ignoreImport = false;
729 729
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -741,37 +741,37 @@  discard block
 block discarded – undo
741 741
 			*/
742 742
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
743 743
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
744
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
745
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
746
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
744
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
745
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
746
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 747
 					$SpotterLive = new SpotterLive($this->db);
748 748
 					$SpotterLive->deleteLiveSpotterData();
749 749
 					$SpotterLive->db=null;
750
-				    }
751
-				    if ($globalDebug) echo " Done\n";
752
-				    $this->last_delete = time();
750
+					}
751
+					if ($globalDebug) echo " Done\n";
752
+					$this->last_delete = time();
753 753
 				}
754
-			    } else {
754
+				} else {
755 755
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
756
-				    $this->all_flights[$id]['id'] = $recent_ident;
757
-				    $this->all_flights[$id]['addedSpotter'] = 1;
756
+					$this->all_flights[$id]['id'] = $recent_ident;
757
+					$this->all_flights[$id]['addedSpotter'] = 1;
758 758
 				}
759 759
 				if (isset($globalDaemon) && !$globalDaemon) {
760
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
760
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
761 761
 					$Spotter = new Spotter($this->db);
762 762
 					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
763 763
 					$Spotter->db = null;
764
-				    }
764
+					}
765 765
 				}
766 766
 				
767
-			    }
767
+				}
768 768
 			}
769
-		    }
770
-		    //adds the spotter LIVE data
771
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
772
-		    //echo "\nAdd in Live !! \n";
773
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774
-		    if ($globalDebug) {
769
+			}
770
+			//adds the spotter LIVE data
771
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
772
+			//echo "\nAdd in Live !! \n";
773
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774
+			if ($globalDebug) {
775 775
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
776 776
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
777 777
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -779,49 +779,49 @@  discard block
 block discarded – undo
779 779
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
780 780
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
781 781
 			}
782
-		    }
783
-		    $ignoreImport = false;
784
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
782
+			}
783
+			$ignoreImport = false;
784
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
786 786
 
787
-		    foreach($globalAirportIgnore as $airportIgnore) {
788
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789
-			    $ignoreImport = true;
787
+			foreach($globalAirportIgnore as $airportIgnore) {
788
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789
+				$ignoreImport = true;
790
+			}
790 791
 			}
791
-		    }
792
-		    if (count($globalAirportAccept) > 0) {
793
-		        $ignoreImport = true;
794
-		        foreach($globalAirportIgnore as $airportIgnore) {
795
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
792
+			if (count($globalAirportAccept) > 0) {
793
+				$ignoreImport = true;
794
+				foreach($globalAirportIgnore as $airportIgnore) {
795
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
796 796
 				$ignoreImport = false;
797
-			    }
797
+				}
798 798
 			}
799
-		    }
800
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
799
+			}
800
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
801 801
 			foreach($globalAirlineIgnore as $airlineIgnore) {
802
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
802
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
803 803
 				$ignoreImport = true;
804
-			    }
804
+				}
805 805
 			}
806
-		    }
807
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
806
+			}
807
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
808 808
 			$ignoreImport = true;
809 809
 			foreach($globalAirlineAccept as $airlineAccept) {
810
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
810
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
811 811
 				$ignoreImport = false;
812
-			    }
812
+				}
813
+			}
813 814
 			}
814
-		    }
815
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
815
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
816 816
 			$ignoreImport = true;
817 817
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
818
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819
-			        $ignoreImport = false;
820
-			    }
818
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819
+					$ignoreImport = false;
820
+				}
821
+			}
821 822
 			}
822
-		    }
823 823
 
824
-		    if (!$ignoreImport) {
824
+			if (!$ignoreImport) {
825 825
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826 826
 				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
827 827
 				$timeelapsed = microtime(true);
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 					if ($stats_heading == 16) $stats_heading = 0;
868 868
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
869 869
 						for ($i=0;$i<=15;$i++) {
870
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
870
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
871 871
 						}
872 872
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
873 873
 					} else {
@@ -880,11 +880,11 @@  discard block
 block discarded – undo
880 880
 					//var_dump($this->stats);
881 881
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
882 882
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
883
-						    end($this->stats[$current_date][$source]['hist']);
884
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
883
+							end($this->stats[$current_date][$source]['hist']);
884
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
885 885
 						} else $mini = 0;
886 886
 						for ($i=$mini;$i<=$distance;$i+=10) {
887
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
887
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
888 888
 						}
889 889
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
890 890
 					} else {
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 			//$this->del();
900 900
 			
901 901
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
902
-			    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
902
+				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
903 903
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
904 904
 				$SpotterLive = new SpotterLive($this->db);
905 905
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -907,19 +907,19 @@  discard block
 block discarded – undo
907 907
 				//SpotterLive->deleteLiveSpotterData();
908 908
 				if ($globalDebug) echo " Done\n";
909 909
 				$this->last_delete_hourly = time();
910
-			    } else {
910
+				} else {
911 911
 				$this->del();
912 912
 				$this->last_delete_hourly = time();
913
-			    }
913
+				}
914 914
 			}
915 915
 			
916
-		    }
917
-		    //$ignoreImport = false;
916
+			}
917
+			//$ignoreImport = false;
918 918
 		}
919 919
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
920 920
 		if ($send) return $this->all_flights[$id];
921
-	    }
921
+		}
922
+	}
922 923
 	}
923
-    }
924 924
 }
925 925
 ?>
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
33
+	    foreach ($sourcestat as $srcst) {
34 34
 	    	$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36 36
 		    $source = $srcst['source_name'];
37 37
 		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
+		    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
39 39
 	        }
40 40
 	    }
41 41
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+    public function get_Schedule($id, $ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73 73
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
74
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
75
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
76 76
 		    // Should also check if route schedule = route from DB
77 77
 		    if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			    }
93 93
 			}
94 94
 		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
96 96
 		}
97 97
 	    } else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
        if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102 102
     		$sch = $Schedule->getSchedule($operator);
103
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
103
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
104 104
        }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128 128
     		    $Spotter = new Spotter($this->db);
129 129
         	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
130
+        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
131 131
         	}
132 132
 	    }
133 133
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $airport_time = '';
142 142
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
144
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
145 145
     	    if (isset($closestAirports[0])) {
146 146
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 147
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         		    break;
157 157
         		}
158 158
         	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
159
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
160 160
         		$airport_icao = $closestAirports[0]['icao'];
161 161
         		$airport_time = $this->all_flights[$key]['datetime'];
162 162
         	} else {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         } else {
170 170
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171 171
         }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
172
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
173 173
     }
174 174
 
175 175
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182 182
     	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
183
+        	if ($flight['lastupdate'] < (time() - 3000)) {
184 184
             	    if (isset($this->all_flights[$key]['id'])) {
185 185
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             		    $real_arrival = $this->arrival($key);
193 193
             		    $Spotter = new Spotter($this->db);
194 194
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
195
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197 197
 			    }
198 198
 			// Put in archive
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	$send = false;
230 230
 	
231 231
 	// SBS format is CSV format
232
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
232
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233 233
 	    //print_r($line);
234 234
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264 264
 		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
265
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
266
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => ''));
267
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
268 268
 		    if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
272
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
273 273
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
274
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
275 275
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
283
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
284 284
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286 286
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -288,41 +288,41 @@  discard block
 block discarded – undo
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
291
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
291
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
292 292
 			} else {
293 293
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 294
 			}
295 295
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
296
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
297
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
298 298
 		    }
299 299
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
300 300
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
303
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
304 304
 		}
305 305
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
306 306
 			// Get aircraft ICAO from aircraft name
307 307
 			$Spotter = new Spotter($this->db);
308 308
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 309
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
310
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
311 311
 		}
312 312
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313 313
 			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314 314
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315 315
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316 316
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
317
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
318 318
 		}
319 319
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
320
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
323
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) {
324 324
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
325
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
326 326
 		    } else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
 		    }
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
338
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
355
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
356 356
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358 358
             		$Spotter = new Spotter($this->db);
@@ -362,10 +362,10 @@  discard block
 block discarded – undo
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
368
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
369 369
 		    }
370 370
 
371 371
 /*
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381 381
 		    //$putinarchive = true;
382 382
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
383
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
384 384
 		    }
385 385
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
386
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
387 387
 		    }
388 388
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
389
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
390 390
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
395
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
396
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
397 397
 
398 398
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
@@ -406,34 +406,34 @@  discard block
 block discarded – undo
406 406
 				$Translation->db = null;
407 407
 			}
408 408
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
409
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 412
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413 413
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
415
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop']));
416 416
 		    	    }
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
420
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
421 421
 			}
422 422
 		    }
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
427
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
428
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
429 429
 		    //$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
431
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
432 432
 		    if ($distance > 1000 && $distance < 10000) {
433 433
 		    // use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
436
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438 438
 		    }
439 439
 		}
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 
442 442
 
443 443
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
444
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
445 445
 	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
446
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -454,10 +454,10 @@  discard block
 block discarded – undo
454 454
 				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455 455
 				    $timeelapsed = microtime(true);
456 456
 				    $Spotter = new Spotter($this->db);
457
-				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
457
+				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
458 458
 				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459 459
 				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
461 461
 				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462 462
 				}
463 463
 			    }
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467 467
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468 468
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
469
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470 470
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471 471
 				    $dataFound = true;
472 472
 				    $this->all_flights[$id]['time_last_coord'] = time();
473 473
 				}
474 474
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
475
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
475
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
476 476
 				/*
477 477
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
478 478
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491 491
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492 492
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
493
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494 494
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495 495
 				    $dataFound = true;
496 496
 				    $this->all_flights[$id]['time_last_coord'] = time();
497 497
 				}
498 498
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
499
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
499
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
500 500
 				/*
501 501
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
502 502
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -514,46 +514,46 @@  discard block
 block discarded – undo
514 514
 		    } else if ($globalDebug && $timediff > 20) {
515 515
 			$this->tmd = $this->tmd + 1;
516 516
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
517
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
518
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
517
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
518
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
519 519
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
520 520
 		    }
521 521
 		}
522 522
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523 523
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
525 525
 		}
526 526
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
527
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
528 528
 		    //$dataFound = true;
529 529
 		}
530 530
 		if (isset($line['format_source']) && $line['format_source'] != '') {
531
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
532 532
 		}
533 533
 		if (isset($line['source_name']) && $line['source_name'] != '') {
534
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
535 535
 		}
536 536
 		if (isset($line['emergency']) && $line['emergency'] != '') {
537
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
538 538
 		    //$dataFound = true;
539 539
 		}
540 540
 		if (isset($line['ground']) && $line['ground'] != '') {
541 541
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
542 542
 			// Here we force archive of flight because after ground it's a new one (or should be)
543
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
543
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
544
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
545
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
547
+			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
548 548
 		    }
549 549
 		    if ($line['ground'] != 1) $line['ground'] = 0;
550
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
551 551
 		    //$dataFound = true;
552 552
 		}
553 553
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554 554
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555 555
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
557 557
 			    $highlight = '';
558 558
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559 559
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -561,47 +561,47 @@  discard block
 block discarded – undo
561 561
 			    if ($highlight != '') {
562 562
 				$timeelapsed = microtime(true);
563 563
 				$Spotter = new Spotter($this->db);
564
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
564
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
565 565
 				$Spotter->db = null;
566
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
567 567
 
568 568
 				//$putinarchive = true;
569 569
 				//$highlight = '';
570 570
 			    }
571 571
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
573 573
 		    //$dataFound = true;
574 574
 		}
575 575
 
576 576
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577 577
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
578
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
580
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
581 581
 			//$dataFound = true;
582 582
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
583 583
   		}
584 584
 
585 585
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
586
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
587 587
 		}
588 588
 		
589 589
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
590
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
592
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
593 593
 		    //$dataFound = true;
594 594
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
595
+  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
596
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
597
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598 598
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
599 599
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600 600
   		    // If not enough messages and ACARS set heading to 0
601
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
602 602
   		}
603
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
603
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
605 605
 
606 606
 //		print_r($this->all_flights[$id]);
607 607
 		//gets the callsign from the last hour
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
612 612
 		    $this->all_flights[$id]['lastupdate'] = time();
613 613
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615 615
 			    //print_r($this->all_flights);
616 616
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617 617
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -621,61 +621,61 @@  discard block
 block discarded – undo
621 621
 				$SpotterLive = new SpotterLive($this->db);
622 622
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623 623
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
624
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
625 625
 				} elseif (isset($line['id'])) {
626 626
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
627
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
628 628
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629 629
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
631 631
 				} else $recent_ident = '';
632
-				$SpotterLive->db=null;
632
+				$SpotterLive->db = null;
633 633
 
634 634
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635 635
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
636 636
 			    } else {
637 637
 				$recent_ident = '';
638
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
638
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
639 639
 			    }
640 640
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
-			    if($recent_ident == "")
641
+			    if ($recent_ident == "")
642 642
 			    {
643 643
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
644 644
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 645
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 646
 				//adds the spotter data for the archive
647 647
 				$ignoreImport = false;
648
-				foreach($globalAirportIgnore as $airportIgnore) {
648
+				foreach ($globalAirportIgnore as $airportIgnore) {
649 649
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
650 650
 					$ignoreImport = true;
651 651
 				    }
652 652
 				}
653 653
 				if (count($globalAirportAccept) > 0) {
654 654
 				    $ignoreImport = true;
655
-				    foreach($globalAirportIgnore as $airportIgnore) {
655
+				    foreach ($globalAirportIgnore as $airportIgnore) {
656 656
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
657 657
 					    $ignoreImport = false;
658 658
 					}
659 659
 				    }
660 660
 				}
661 661
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
662
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
663
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
662
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
663
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
664 664
 					    $ignoreImport = true;
665 665
 					}
666 666
 				    }
667 667
 				}
668 668
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
669 669
 				    $ignoreImport = true;
670
-				    foreach($globalAirlineAccept as $airlineAccept) {
671
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
670
+				    foreach ($globalAirlineAccept as $airlineAccept) {
671
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
672 672
 					    $ignoreImport = false;
673 673
 					}
674 674
 				    }
675 675
 				}
676 676
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
677 677
 				    $ignoreImport = true;
678
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
678
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
679 679
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
680 680
 					    $ignoreImport = false;
681 681
 					}
@@ -687,29 +687,29 @@  discard block
 block discarded – undo
687 687
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688 688
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689 689
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
+				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691 691
 				    $timeelapsed = microtime(true);
692 692
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 693
 					$Spotter = new Spotter($this->db);
694
-					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694
+					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']);
695 695
 					$Spotter->db = null;
696 696
 					if ($globalDebug && isset($result)) echo $result."\n";
697 697
 				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
699 699
 				    
700 700
 				    // Add source stat in DB
701 701
 				    $Stats = new Stats($this->db);
702 702
 				    if (!empty($this->stats)) {
703 703
 					if ($globalDebug) echo 'Add source stats : ';
704
-				        foreach($this->stats as $date => $data) {
705
-					    foreach($data as $source => $sourced) {
704
+				        foreach ($this->stats as $date => $data) {
705
+					    foreach ($data as $source => $sourced) {
706 706
 					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
707
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
708
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
709 709
 				    		if (isset($sourced['msg'])) {
710 710
 				    		    if (time() - $sourced['msg']['date'] > 10) {
711 711
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
713 713
 			    			        unset($this->stats[$date][$source]['msg']);
714 714
 			    			    }
715 715
 			    			}
@@ -746,20 +746,20 @@  discard block
 block discarded – undo
746 746
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 747
 					$SpotterLive = new SpotterLive($this->db);
748 748
 					$SpotterLive->deleteLiveSpotterData();
749
-					$SpotterLive->db=null;
749
+					$SpotterLive->db = null;
750 750
 				    }
751 751
 				    if ($globalDebug) echo " Done\n";
752 752
 				    $this->last_delete = time();
753 753
 				}
754 754
 			    } else {
755
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
755
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
756 756
 				    $this->all_flights[$id]['id'] = $recent_ident;
757 757
 				    $this->all_flights[$id]['addedSpotter'] = 1;
758 758
 				}
759 759
 				if (isset($globalDaemon) && !$globalDaemon) {
760 760
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
761 761
 					$Spotter = new Spotter($this->db);
762
-					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
762
+					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
763 763
 					$Spotter->db = null;
764 764
 				    }
765 765
 				}
@@ -784,37 +784,37 @@  discard block
 block discarded – undo
784 784
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785 785
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
786 786
 
787
-		    foreach($globalAirportIgnore as $airportIgnore) {
787
+		    foreach ($globalAirportIgnore as $airportIgnore) {
788 788
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789 789
 			    $ignoreImport = true;
790 790
 			}
791 791
 		    }
792 792
 		    if (count($globalAirportAccept) > 0) {
793 793
 		        $ignoreImport = true;
794
-		        foreach($globalAirportIgnore as $airportIgnore) {
794
+		        foreach ($globalAirportIgnore as $airportIgnore) {
795 795
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
796 796
 				$ignoreImport = false;
797 797
 			    }
798 798
 			}
799 799
 		    }
800 800
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
801
-			foreach($globalAirlineIgnore as $airlineIgnore) {
802
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
801
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
802
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
803 803
 				$ignoreImport = true;
804 804
 			    }
805 805
 			}
806 806
 		    }
807 807
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
808 808
 			$ignoreImport = true;
809
-			foreach($globalAirlineAccept as $airlineAccept) {
810
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
809
+			foreach ($globalAirlineAccept as $airlineAccept) {
810
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
811 811
 				$ignoreImport = false;
812 812
 			    }
813 813
 			}
814 814
 		    }
815 815
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
816 816
 			$ignoreImport = true;
817
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
817
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
818 818
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819 819
 			        $ignoreImport = false;
820 820
 			    }
@@ -822,21 +822,21 @@  discard block
 block discarded – undo
822 822
 		    }
823 823
 
824 824
 		    if (!$ignoreImport) {
825
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826
-				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
825
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826
+				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
827 827
 				$timeelapsed = microtime(true);
828 828
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
829 829
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
830 830
 					$SpotterLive = new SpotterLive($this->db);
831
-					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
831
+					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
832 832
 					$SpotterLive->db = null;
833 833
 					if ($globalDebug) echo $result."\n";
834 834
 				}
835 835
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
836
-					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
836
+					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
837 837
 				}
838 838
 				$this->all_flights[$id]['putinarchive'] = false;
839
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
839
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
840 840
 
841 841
 				// Put statistics in $this->stats variable
842 842
 				//if ($line['format_source'] != 'aprs') {
@@ -854,19 +854,19 @@  discard block
 block discarded – undo
854 854
 							$latitude = $globalCenterLatitude;
855 855
 							$longitude = $globalCenterLongitude;
856 856
 						}
857
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
857
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
858 858
 					} else {
859 859
 						$latitude = $this->source_location[$source]['latitude'];
860 860
 						$longitude = $this->source_location[$source]['longitude'];
861 861
 					}
862
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
862
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
863 863
 					//$stats_heading = $stats_heading%22.5;
864 864
 					$stats_heading = round($stats_heading/22.5);
865
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
865
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
866 866
 					$current_date = date('Y-m-d');
867 867
 					if ($stats_heading == 16) $stats_heading = 0;
868 868
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
869
-						for ($i=0;$i<=15;$i++) {
869
+						for ($i = 0; $i <= 15; $i++) {
870 870
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
871 871
 						}
872 872
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -881,9 +881,9 @@  discard block
 block discarded – undo
881 881
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
882 882
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
883 883
 						    end($this->stats[$current_date][$source]['hist']);
884
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
884
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
885 885
 						} else $mini = 0;
886
-						for ($i=$mini;$i<=$distance;$i+=10) {
886
+						for ($i = $mini; $i <= $distance; $i += 10) {
887 887
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
888 888
 						}
889 889
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 				$this->all_flights[$id]['lastupdate'] = time();
896 896
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
897 897
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
898
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
898
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
899 899
 			//$this->del();
900 900
 			
901 901
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +334 added lines, -118 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
 	$dbc = $this->db;
60 60
 	$this->all_flights[$id]['schedule_check'] = true;
61 61
 	if ($globalSchedulesFetch) {
62
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Getting schedule info...'."\n";
64
+	}
63 65
 	$Spotter = new Spotter($dbc);
64 66
 	$Schedule = new Schedule($dbc);
65 67
 	$Translation = new Translation($dbc);
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
 	    if ($Schedule->checkSchedule($operator) == 0) {
71 73
 		$schedule = $Schedule->fetchSchedule($operator);
72 74
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
75
+		    if ($globalDebug) {
76
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
77
+		    }
74 78
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75 79
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76 80
 		    // Should also check if route schedule = route from DB
@@ -79,7 +83,9 @@  discard block
 block discarded – undo
79 83
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80 84
 			    if (trim($airport_icao) != '') {
81 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
86
+				if ($globalDebug) {
87
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
88
+				}
83 89
 			    }
84 90
 			}
85 91
 		    }
@@ -88,17 +94,25 @@  discard block
 block discarded – undo
88 94
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89 95
 			    if (trim($airport_icao) != '') {
90 96
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
97
+				if ($globalDebug) {
98
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
99
+				}
92 100
 			    }
93 101
 			}
94 102
 		    }
95 103
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 104
 		}
97
-	    } else $scheduleexist = true;
98
-	} else $scheduleexist = true;
105
+	    } else {
106
+	    	$scheduleexist = true;
107
+	    }
108
+	} else {
109
+		$scheduleexist = true;
110
+	}
99 111
 	// close connection, at least one way will work ?
100 112
        if ($scheduleexist) {
101
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
113
+		if ($globalDebug) {
114
+			echo "-> get arrival/departure airport info for ".$ident."\n";
115
+		}
102 116
     		$sch = $Schedule->getSchedule($operator);
103 117
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104 118
        }
@@ -120,7 +134,9 @@  discard block
 block discarded – undo
120 134
 
121 135
     public function checkAll() {
122 136
 	global $globalDebug, $globalNoImport;
123
-	if ($globalDebug) echo "Update last seen flights data...\n";
137
+	if ($globalDebug) {
138
+		echo "Update last seen flights data...\n";
139
+	}
124 140
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125 141
 	    foreach ($this->all_flights as $key => $flight) {
126 142
 		if (isset($this->all_flights[$key]['id'])) {
@@ -135,24 +151,32 @@  discard block
 block discarded – undo
135 151
 
136 152
     public function arrival($key) {
137 153
 	global $globalClosestMinDist, $globalDebug;
138
-	if ($globalDebug) echo 'Update arrival...'."\n";
154
+	if ($globalDebug) {
155
+		echo 'Update arrival...'."\n";
156
+	}
139 157
 	$Spotter = new Spotter($this->db);
140 158
         $airport_icao = '';
141 159
         $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
161
+        	$globalClosestMinDist = 50;
162
+        }
143 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144 164
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145 165
     	    if (isset($closestAirports[0])) {
146 166
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 167
         	    $airport_icao = $closestAirports[0]['icao'];
148 168
         	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        	    if ($globalDebug) {
170
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        	    }
150 172
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151 173
         	    foreach ($closestAirports as $airport) {
152 174
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153 175
         		    $airport_icao = $airport['icao'];
154 176
         		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        		    if ($globalDebug) {
178
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
179
+        		    }
156 180
         		    break;
157 181
         		}
158 182
         	    }
@@ -160,14 +184,20 @@  discard block
 block discarded – undo
160 184
         		$airport_icao = $closestAirports[0]['icao'];
161 185
         		$airport_time = $this->all_flights[$key]['datetime'];
162 186
         	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
187
+        		if ($globalDebug) {
188
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
189
+        		}
164 190
         	}
165 191
     	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
192
+    		    if ($globalDebug) {
193
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
194
+    		    }
167 195
     	    }
168 196
 
169 197
         } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
198
+        	if ($globalDebug) {
199
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
200
+        	}
171 201
         }
172 202
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173 203
     }
@@ -177,12 +207,16 @@  discard block
 block discarded – undo
177 207
     public function del() {
178 208
 	global $globalDebug, $globalNoImport;
179 209
 	// Delete old infos
180
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
210
+	if ($globalDebug) {
211
+		echo 'Delete old values and update latest data...'."\n";
212
+	}
181 213
 	foreach ($this->all_flights as $key => $flight) {
182 214
     	    if (isset($flight['lastupdate'])) {
183 215
         	if ($flight['lastupdate'] < (time()-3000)) {
184 216
             	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
217
+            		if ($globalDebug) {
218
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
219
+            		}
186 220
 			/*
187 221
 			$SpotterLive = new SpotterLive();
188 222
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -193,7 +227,9 @@  discard block
 block discarded – undo
193 227
             		    $Spotter = new Spotter($this->db);
194 228
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 229
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
230
+				if ($globalDebug && $result != 'success') {
231
+					echo '!!! ERROR : '.$result."\n";
232
+				}
197 233
 			    }
198 234
 			// Put in archive
199 235
 //				$Spotter->db = null;
@@ -208,8 +244,10 @@  discard block
 block discarded – undo
208 244
     public function add($line) {
209 245
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 246
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
212
-/*
247
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
248
+		$globalCoordMinChange = '0.02';
249
+	}
250
+	/*
213 251
 	$Spotter = new Spotter();
214 252
 	$dbc = $Spotter->db;
215 253
 	$SpotterLive = new SpotterLive($dbc);
@@ -237,11 +275,15 @@  discard block
 block discarded – undo
237 275
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238 276
 		    $current_date = date('Y-m-d');
239 277
 		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
278
+		    if ($source == '' || $line['format_source'] == 'aprs') {
279
+		    	$source = $line['format_source'];
280
+		    }
241 281
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242 282
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243 283
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
284
+		    } else {
285
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
286
+		    }
245 287
 		}
246 288
 		
247 289
 		/*
@@ -257,8 +299,11 @@  discard block
 block discarded – undo
257 299
 		//$this->db = $dbc;
258 300
 
259 301
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
302
+	        if (!isset($line['id'])) {
303
+	        	$id = trim($line['hex']);
304
+	        } else {
305
+	        	$id = trim($line['id']);
306
+	        }
262 307
 		
263 308
 		if (!isset($this->all_flights[$id])) {
264 309
 		    $this->all_flights[$id] = array();
@@ -266,13 +311,21 @@  discard block
 block discarded – undo
266 311
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267 312
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268 313
 		    if (!isset($line['id'])) {
269
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
314
+			if (!isset($globalDaemon)) {
315
+				$globalDaemon = TRUE;
316
+			}
317
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 318
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
319
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
320
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
321
+			}
273 322
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
323
+		     } else {
324
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
325
+		     }
326
+		    if ($globalAllFlights !== FALSE) {
327
+		    	$dataFound = true;
328
+		    }
276 329
 		}
277 330
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278 331
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -293,11 +346,19 @@  discard block
 block discarded – undo
293 346
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 347
 			}
295 348
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
349
+			if ($globalDebugTimeElapsed) {
350
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+			}
352
+			if ($aircraft_icao != '') {
353
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
354
+			}
355
+		    }
356
+		    if ($globalAllFlights !== FALSE) {
357
+		    	$dataFound = true;
358
+		    }
359
+		    if ($globalDebug) {
360
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298 361
 		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 362
 		}
302 363
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 364
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -307,14 +368,23 @@  discard block
 block discarded – undo
307 368
 			$Spotter = new Spotter($this->db);
308 369
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 370
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
371
+			if ($aircraft_icao != '') {
372
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
373
+			}
311 374
 		}
312 375
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
376
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
377
+				$aircraft_icao = 'GLID';
378
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
379
+				$aircraft_icao = 'UHEL';
380
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
381
+				$aircraft_icao = 'TOWPLANE';
382
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
383
+				$aircraft_icao = 'POWAIRC';
384
+			}
385
+			if (isset($aircraft_icao)) {
386
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
387
+			}
318 388
 		}
319 389
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320 390
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -324,8 +394,11 @@  discard block
 block discarded – undo
324 394
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326 396
 		    } else {
327
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
397
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
398
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
399
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
400
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
401
+				}
329 402
 				/*
330 403
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
331 404
 				print_r($this->all_flights[$id]);
@@ -357,15 +430,25 @@  discard block
 block discarded – undo
357 430
 			$timeelapsed = microtime(true);
358 431
             		$Spotter = new Spotter($this->db);
359 432
             		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
433
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
434
+            			$fromsource = $globalAirlinesSource;
435
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
436
+            			$fromsource = 'vatsim';
437
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
438
+				$fromsource = 'ivao';
439
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
440
+				$fromsource = 'vatsim';
441
+			} elseif (isset($globalIVAO) && $globalIVAO) {
442
+				$fromsource = 'ivao';
443
+			}
365 444
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
445
+			if ($globalDebug && $result != 'success') {
446
+				echo '!!! ERROR : '.$result."\n";
447
+			}
367 448
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
449
+			if ($globalDebugTimeElapsed) {
450
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+			}
369 452
 		    }
370 453
 
371 454
 /*
@@ -376,7 +459,9 @@  discard block
 block discarded – undo
376 459
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 460
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 461
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
462
+		    if (!isset($this->all_flights[$id]['id'])) {
463
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
464
+		    }
380 465
 
381 466
 		    //$putinarchive = true;
382 467
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -393,7 +478,9 @@  discard block
 block discarded – undo
393 478
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 479
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395 480
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481
+				if ($globalDebugTimeElapsed) {
482
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
483
+				}
397 484
 
398 485
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 486
 			$timeelapsed = microtime(true);
@@ -406,7 +493,9 @@  discard block
 block discarded – undo
406 493
 				$Translation->db = null;
407 494
 			}
408 495
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
496
+			if ($globalDebugTimeElapsed) {
497
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
498
+			}
410 499
 
411 500
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 501
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -415,9 +504,13 @@  discard block
 block discarded – undo
415 504
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416 505
 		    	    }
417 506
 			}
418
-			if (!isset($globalFork)) $globalFork = TRUE;
507
+			if (!isset($globalFork)) {
508
+				$globalFork = TRUE;
509
+			}
419 510
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
511
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
512
+					$this->get_Schedule($id,trim($line['ident']));
513
+				}
421 514
 			}
422 515
 		    }
423 516
 		}
@@ -433,16 +526,23 @@  discard block
 block discarded – undo
433 526
 		    // use datetime
434 527
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 528
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
529
+			if ($speed < 1000) {
530
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
531
+			}
532
+  			if ($globalDebug) {
533
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
534
+  			}
438 535
 		    }
439 536
 		}
440 537
 
441 538
 
442 539
 
443 540
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
541
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
542
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
543
+	    	    } else {
544
+	    	    	unset($timediff);
545
+	    	    }
446 546
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 547
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448 548
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -451,21 +551,31 @@  discard block
 block discarded – undo
451 551
 				$this->all_flights[$id]['putinarchive'] = true;
452 552
 				$this->tmd = 0;
453 553
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
454
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
554
+				    if ($globalDebug) {
555
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
556
+				    }
455 557
 				    $timeelapsed = microtime(true);
456 558
 				    $Spotter = new Spotter($this->db);
457 559
 				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
-				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
560
+				    if (!empty($all_country)) {
561
+				    	$this->all_flights[$id]['over_country'] = $all_country['iso2'];
562
+				    }
459 563
 				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
-				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
564
+				    if ($globalDebugTimeElapsed) {
565
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+				    }
567
+				    if ($globalDebug) {
568
+				    	echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
+				    }
462 570
 				}
463 571
 			    }
464 572
 			}
465 573
 
466 574
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467 575
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
576
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
577
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
578
+				}
469 579
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470 580
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471 581
 				    $dataFound = true;
@@ -487,9 +597,13 @@  discard block
 block discarded – undo
487 597
 			    */
488 598
 			}
489 599
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
490
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
600
+			    if ($line['longitude'] > 180) {
601
+			    	$line['longitude'] = $line['longitude'] - 360;
602
+			    }
491 603
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
604
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
605
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
606
+				}
493 607
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494 608
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495 609
 				    $dataFound = true;
@@ -520,7 +634,9 @@  discard block
 block discarded – undo
520 634
 		    }
521 635
 		}
522 636
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
637
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
638
+		    	$dataFound = true;
639
+		    }
524 640
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
525 641
 		}
526 642
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -542,40 +658,60 @@  discard block
 block discarded – undo
542 658
 			// Here we force archive of flight because after ground it's a new one (or should be)
543 659
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544 660
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
661
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
662
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
663
+			} elseif (isset($line['id'])) {
664
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
665
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
666
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
667
+			}
668
+		    }
669
+		    if ($line['ground'] != 1) {
670
+		    	$line['ground'] = 0;
548 671
 		    }
549
-		    if ($line['ground'] != 1) $line['ground'] = 0;
550 672
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551 673
 		    //$dataFound = true;
552 674
 		}
553 675
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554 676
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
677
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
678
+			    	$this->all_flights[$id]['putinarchive'] = true;
679
+			    }
556 680
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557 681
 			    $highlight = '';
558
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
682
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
683
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
684
+			    }
685
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
686
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
687
+			    }
688
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
689
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
690
+			    }
561 691
 			    if ($highlight != '') {
562 692
 				$timeelapsed = microtime(true);
563 693
 				$Spotter = new Spotter($this->db);
564 694
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
565 695
 				$Spotter->db = null;
566
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696
+				if ($globalDebugTimeElapsed) {
697
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698
+				}
567 699
 
568 700
 				//$putinarchive = true;
569 701
 				//$highlight = '';
570 702
 			    }
571 703
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
704
+		    } else {
705
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
706
+		    }
573 707
 		    //$dataFound = true;
574 708
 		}
575 709
 
576 710
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577 711
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
712
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
713
+				$this->all_flights[$id]['putinarchive'] = true;
714
+			}
579 715
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580 716
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
581 717
 			//$dataFound = true;
@@ -587,21 +723,30 @@  discard block
 block discarded – undo
587 723
 		}
588 724
 		
589 725
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
727
+		    	$this->all_flights[$id]['putinarchive'] = true;
728
+		    }
591 729
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592 730
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593 731
 		    //$dataFound = true;
594 732
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595 733
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596 734
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
735
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
736
+		    	$this->all_flights[$id]['putinarchive'] = true;
737
+		    }
738
+  		    if ($globalDebug) {
739
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
740
+  		    }
599 741
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600 742
   		    // If not enough messages and ACARS set heading to 0
601 743
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
602 744
   		}
603
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
745
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
746
+			$dataFound = false;
747
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
748
+			$dataFound = false;
749
+		}
605 750
 
606 751
 //		print_r($this->all_flights[$id]);
607 752
 		//gets the callsign from the last hour
@@ -616,23 +761,36 @@  discard block
 block discarded – undo
616 761
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617 762
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618 763
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
619
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
764
+				if ($globalDebug) {
765
+					echo "Check if aircraft is already in DB...";
766
+				}
620 767
 				$timeelapsed = microtime(true);
621 768
 				$SpotterLive = new SpotterLive($this->db);
622 769
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623 770
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
771
+				    if ($globalDebugTimeElapsed) {
772
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
773
+				    }
625 774
 				} elseif (isset($line['id'])) {
626 775
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
776
+				    if ($globalDebugTimeElapsed) {
777
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
778
+				    }
628 779
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629 780
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
631
-				} else $recent_ident = '';
781
+				    if ($globalDebugTimeElapsed) {
782
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
783
+				    }
784
+				} else {
785
+					$recent_ident = '';
786
+				}
632 787
 				$SpotterLive->db=null;
633 788
 
634
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
789
+				if ($globalDebug && $recent_ident == '') {
790
+					echo " Not in DB.\n";
791
+				} elseif ($globalDebug && $recent_ident != '') {
792
+					echo " Already in DB.\n";
793
+				}
636 794
 			    } else {
637 795
 				$recent_ident = '';
638 796
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -640,7 +798,9 @@  discard block
 block discarded – undo
640 798
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641 799
 			    if($recent_ident == "")
642 800
 			    {
643
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
801
+				if ($globalDebug) {
802
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
803
+				}
644 804
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 805
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 806
 				//adds the spotter data for the archive
@@ -684,28 +844,46 @@  discard block
 block discarded – undo
684 844
 				
685 845
 				if (!$ignoreImport) {
686 846
 				    $highlight = '';
687
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
847
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
848
+				    	$highlight = 'Squawk 7500 : Hijack';
849
+				    }
850
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
851
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
852
+				    }
853
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
854
+				    	$highlight = 'Squawk 7700 : Emergency';
855
+				    }
856
+				    if (!isset($this->all_flights[$id]['id'])) {
857
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
858
+				    }
691 859
 				    $timeelapsed = microtime(true);
692 860
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 861
 					$Spotter = new Spotter($this->db);
694 862
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
695 863
 					$Spotter->db = null;
696
-					if ($globalDebug && isset($result)) echo $result."\n";
864
+					if ($globalDebug && isset($result)) {
865
+						echo $result."\n";
866
+					}
867
+				    }
868
+				    if ($globalDebugTimeElapsed) {
869
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697 870
 				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
699 871
 				    
700 872
 				    // Add source stat in DB
701 873
 				    $Stats = new Stats($this->db);
702 874
 				    if (!empty($this->stats)) {
703
-					if ($globalDebug) echo 'Add source stats : ';
875
+					if ($globalDebug) {
876
+						echo 'Add source stats : ';
877
+					}
704 878
 				        foreach($this->stats as $date => $data) {
705 879
 					    foreach($data as $source => $sourced) {
706 880
 					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
881
+				    	        if (isset($sourced['polar'])) {
882
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
883
+				    	        }
884
+				    	        if (isset($sourced['hist'])) {
885
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
886
+				    	        }
709 887
 				    		if (isset($sourced['msg'])) {
710 888
 				    		    if (time() - $sourced['msg']['date'] > 10) {
711 889
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -718,13 +896,17 @@  discard block
 block discarded – undo
718 896
 			    			unset($this->stats[$date]);
719 897
 			    		    }
720 898
 				    	}
721
-				    	if ($globalDebug) echo 'Done'."\n";
899
+				    	if ($globalDebug) {
900
+				    		echo 'Done'."\n";
901
+				    	}
722 902
 
723 903
 				    }
724 904
 				    $Stats->db = null;
725 905
 				    
726 906
 				    $this->del();
727
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
907
+				} elseif ($globalDebug) {
908
+					echo 'Ignore data'."\n";
909
+				}
728 910
 				//$ignoreImport = false;
729 911
 				$this->all_flights[$id]['addedSpotter'] = 1;
730 912
 				//print_r($this->all_flights[$id]);
@@ -741,14 +923,18 @@  discard block
 block discarded – undo
741 923
 			*/
742 924
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
743 925
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
744
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
926
+				    if ($globalDebug) {
927
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
928
+				    }
745 929
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
746 930
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 931
 					$SpotterLive = new SpotterLive($this->db);
748 932
 					$SpotterLive->deleteLiveSpotterData();
749 933
 					$SpotterLive->db=null;
750 934
 				    }
751
-				    if ($globalDebug) echo " Done\n";
935
+				    if ($globalDebug) {
936
+				    	echo " Done\n";
937
+				    }
752 938
 				    $this->last_delete = time();
753 939
 				}
754 940
 			    } else {
@@ -773,11 +959,17 @@  discard block
 block discarded – undo
773 959
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774 960
 		    if ($globalDebug) {
775 961
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
776
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
777
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
962
+				if (isset($this->all_flights[$id]['source_name'])) {
963
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
964
+				} else {
965
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
966
+				}
778 967
 			} else {
779
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
780
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
968
+				if (isset($this->all_flights[$id]['source_name'])) {
969
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
970
+				} else {
971
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
972
+				}
781 973
 			}
782 974
 		    }
783 975
 		    $ignoreImport = false;
@@ -823,27 +1015,37 @@  discard block
 block discarded – undo
823 1015
 
824 1016
 		    if (!$ignoreImport) {
825 1017
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826
-				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1018
+				if (!isset($this->all_flights[$id]['id'])) {
1019
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1020
+				}
827 1021
 				$timeelapsed = microtime(true);
828 1022
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
829
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1023
+					if ($globalDebug) {
1024
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1025
+					}
830 1026
 					$SpotterLive = new SpotterLive($this->db);
831 1027
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
832 1028
 					$SpotterLive->db = null;
833
-					if ($globalDebug) echo $result."\n";
1029
+					if ($globalDebug) {
1030
+						echo $result."\n";
1031
+					}
834 1032
 				}
835 1033
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
836 1034
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
837 1035
 				}
838 1036
 				$this->all_flights[$id]['putinarchive'] = false;
839
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1037
+				if ($globalDebugTimeElapsed) {
1038
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1039
+				}
840 1040
 
841 1041
 				// Put statistics in $this->stats variable
842 1042
 				//if ($line['format_source'] != 'aprs') {
843 1043
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
844 1044
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
845 1045
 					$source = $this->all_flights[$id]['source_name'];
846
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1046
+					if ($source == '') {
1047
+						$source = $this->all_flights[$id]['format_source'];
1048
+					}
847 1049
 					if (!isset($this->source_location[$source])) {
848 1050
 						$Location = new Source();
849 1051
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -864,7 +1066,9 @@  discard block
 block discarded – undo
864 1066
 					$stats_heading = round($stats_heading/22.5);
865 1067
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
866 1068
 					$current_date = date('Y-m-d');
867
-					if ($stats_heading == 16) $stats_heading = 0;
1069
+					if ($stats_heading == 16) {
1070
+						$stats_heading = 0;
1071
+					}
868 1072
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
869 1073
 						for ($i=0;$i<=15;$i++) {
870 1074
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -882,7 +1086,9 @@  discard block
 block discarded – undo
882 1086
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
883 1087
 						    end($this->stats[$current_date][$source]['hist']);
884 1088
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
885
-						} else $mini = 0;
1089
+						} else {
1090
+							$mini = 0;
1091
+						}
886 1092
 						for ($i=$mini;$i<=$distance;$i+=10) {
887 1093
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
888 1094
 						}
@@ -893,19 +1099,27 @@  discard block
 block discarded – undo
893 1099
 				}
894 1100
 
895 1101
 				$this->all_flights[$id]['lastupdate'] = time();
896
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1102
+				if ($this->all_flights[$id]['putinarchive']) {
1103
+					$send = true;
1104
+				}
897 1105
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
898
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1106
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1107
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1108
+			}
899 1109
 			//$this->del();
900 1110
 			
901 1111
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
902 1112
 			    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
903
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1113
+				if ($globalDebug) {
1114
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1115
+				}
904 1116
 				$SpotterLive = new SpotterLive($this->db);
905 1117
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
906 1118
 				$SpotterLive->db = null;
907 1119
 				//SpotterLive->deleteLiveSpotterData();
908
-				if ($globalDebug) echo " Done\n";
1120
+				if ($globalDebug) {
1121
+					echo " Done\n";
1122
+				}
909 1123
 				$this->last_delete_hourly = time();
910 1124
 			    } else {
911 1125
 				$this->del();
@@ -917,7 +1131,9 @@  discard block
 block discarded – undo
917 1131
 		    //$ignoreImport = false;
918 1132
 		}
919 1133
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
920
-		if ($send) return $this->all_flights[$id];
1134
+		if ($send) {
1135
+			return $this->all_flights[$id];
1136
+		}
921 1137
 	    }
922 1138
 	}
923 1139
     }
Please login to merge, or discard this patch.
install/index.php 1 patch
Braces   +432 added lines, -114 removed lines patch added patch discarded remove patch
@@ -131,45 +131,72 @@  discard block
 block discarded – undo
131 131
 			</div>
132 132
 			<p>
133 133
 				<label for="dbhost">Database hostname</label>
134
-				<input type="text" name="dbhost" id="dbhost" value="<?php if (isset($globalDBhost)) print $globalDBhost; ?>" />
134
+				<input type="text" name="dbhost" id="dbhost" value="<?php if (isset($globalDBhost)) {
135
+	print $globalDBhost;
136
+}
137
+?>" />
135 138
 			</p>
136 139
 			<p>
137 140
 				<label for="dbport">Database port</label>
138
-				<input type="text" name="dbport" id="dbport" value="<?php if (isset($globalDBport)) print $globalDBport; ?>" />
141
+				<input type="text" name="dbport" id="dbport" value="<?php if (isset($globalDBport)) {
142
+	print $globalDBport;
143
+}
144
+?>" />
139 145
 				<p class="help-block">Default is 3306 for MariaDB/MySQL, 5432 for PostgreSQL</p>
140 146
 			</p>
141 147
 			<p>
142 148
 				<label for="dbname">Database name</label>
143
-				<input type="text" name="dbname" id="dbname" value="<?php if (isset($globalDBname)) print $globalDBname; ?>" />
149
+				<input type="text" name="dbname" id="dbname" value="<?php if (isset($globalDBname)) {
150
+	print $globalDBname;
151
+}
152
+?>" />
144 153
 			</p>
145 154
 			<p>
146 155
 				<label for="dbuser">Database user</label>
147
-				<input type="text" name="dbuser" id="dbuser" value="<?php if (isset($globalDBuser)) print $globalDBuser; ?>" />
156
+				<input type="text" name="dbuser" id="dbuser" value="<?php if (isset($globalDBuser)) {
157
+	print $globalDBuser;
158
+}
159
+?>" />
148 160
 			</p>
149 161
 			<p>
150 162
 				<label for="dbuserpass">Database user password</label>
151
-				<input type="password" name="dbuserpass" id="dbuserpass" value="<?php if (isset($globalDBpass)) print $globalDBpass; ?>" />
163
+				<input type="password" name="dbuserpass" id="dbuserpass" value="<?php if (isset($globalDBpass)) {
164
+	print $globalDBpass;
165
+}
166
+?>" />
152 167
 			</p>
153 168
 		</fieldset>
154 169
 		<fieldset id="site">
155 170
 			<legend>Site configuration</legend>
156 171
 			<p>
157 172
 				<label for="sitename">Site name</label>
158
-				<input type="text" name="sitename" id="sitename" value="<?php if (isset($globalName)) print $globalName; ?>" />
173
+				<input type="text" name="sitename" id="sitename" value="<?php if (isset($globalName)) {
174
+	print $globalName;
175
+}
176
+?>" />
159 177
 			</p>
160 178
 			<p>
161 179
 				<label for="siteurl">Site directory</label>
162
-				<input type="text" name="siteurl" id="siteurl" value="<?php if (isset($globalURL)) print $globalURL; ?>" />
180
+				<input type="text" name="siteurl" id="siteurl" value="<?php if (isset($globalURL)) {
181
+	print $globalURL;
182
+}
183
+?>" />
163 184
 				<p class="help-block">Can be null. ex : <i>flightairmap</i> if complete URL is <i>http://toto.com/flightairmap</i></p>
164 185
 			</p>
165 186
 			<p>
166 187
 				<label for="timezone">Timezone</label>
167
-				<input type="text" name="timezone" id="timezone" value="<?php if (isset($globalTimezone)) print $globalTimezone; ?>" />
188
+				<input type="text" name="timezone" id="timezone" value="<?php if (isset($globalTimezone)) {
189
+	print $globalTimezone;
190
+}
191
+?>" />
168 192
 				<p class="help-block">ex : UTC, Europe/Paris,...</p>
169 193
 			</p>
170 194
 			<p>
171 195
 				<label for="language">Language</label>
172
-				<input type="text" name="language" id="language" value="<?php if (isset($globalLanguage)) print $globalLanguage; ?>" />
196
+				<input type="text" name="language" id="language" value="<?php if (isset($globalLanguage)) {
197
+	print $globalLanguage;
198
+}
199
+?>" />
173 200
 				<p class="help-block">Used only when link to wikipedia for now. Can be EN,DE,FR,...</p>
174 201
 			</p>
175 202
 		</fieldset>
@@ -190,11 +217,17 @@  discard block
 block discarded – undo
190 217
 			<div id="mapbox_data">
191 218
 				<p>
192 219
 					<label for="mapboxid">Mapbox id</label>
193
-					<input type="text" name="mapboxid" id="mapboxid" value="<?php if (isset($globalMapboxId)) print $globalMapboxId; ?>" />
220
+					<input type="text" name="mapboxid" id="mapboxid" value="<?php if (isset($globalMapboxId)) {
221
+	print $globalMapboxId;
222
+}
223
+?>" />
194 224
 				</p>
195 225
 				<p>
196 226
 					<label for="mapboxtoken">Mapbox token</label>
197
-					<input type="text" name="mapboxtoken" id="mapboxtoken" value="<?php if (isset($globalMapboxToken)) print $globalMapboxToken; ?>" />
227
+					<input type="text" name="mapboxtoken" id="mapboxtoken" value="<?php if (isset($globalMapboxToken)) {
228
+	print $globalMapboxToken;
229
+}
230
+?>" />
198 231
 				</p>
199 232
 				<p class="help-block">Get a key <a href="https://www.mapbox.com/developers/">here</a></p>
200 233
 			</div>
@@ -202,7 +235,10 @@  discard block
 block discarded – undo
202 235
 			<div id="google_data">
203 236
 				<p>
204 237
 					<label for="googlekey">Google API key</label>
205
-					<input type="text" name="googlekey" id="googlekey" value="<?php if (isset($globalGoogleAPIKey)) print $globalGoogleAPIKey; ?>" />
238
+					<input type="text" name="googlekey" id="googlekey" value="<?php if (isset($globalGoogleAPIKey)) {
239
+	print $globalGoogleAPIKey;
240
+}
241
+?>" />
206 242
 					<p class="help-block">Get a key <a href="https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key">here</a></p>
207 243
 				</p>
208 244
 			</div>
@@ -210,7 +246,10 @@  discard block
 block discarded – undo
210 246
 			<div id="bing_data">
211 247
 				<p>
212 248
 					<label for="bingkey">Bing Map key</label>
213
-					<input type="text" name="bingkey" id="bingkey" value="<?php if (isset($globalBingMapKey)) print $globalBingMapKey; ?>" />
249
+					<input type="text" name="bingkey" id="bingkey" value="<?php if (isset($globalBingMapKey)) {
250
+	print $globalBingMapKey;
251
+}
252
+?>" />
214 253
 					<p class="help-block">Get a key <a href="https://www.bingmapsportal.com/">here</a></p>
215 254
 				</p>
216 255
 			</div>
@@ -218,7 +257,10 @@  discard block
 block discarded – undo
218 257
 			<div id="mapquest_data">
219 258
 				<p>
220 259
 					<label for="mapquestkey">MapQuest key</label>
221
-					<input type="text" name="mapquestkey" id="mapquestkey" value="<?php if (isset($globalMapQuestKey)) print $globalMapQuestKey; ?>" />
260
+					<input type="text" name="mapquestkey" id="mapquestkey" value="<?php if (isset($globalMapQuestKey)) {
261
+	print $globalMapQuestKey;
262
+}
263
+?>" />
222 264
 					<p class="help-block">Get a key <a href="https://developer.mapquest.com/user/me/apps">here</a></p>
223 265
 				</p>
224 266
 			</div>
@@ -226,11 +268,17 @@  discard block
 block discarded – undo
226 268
 			<div id="here_data">
227 269
 				<p>
228 270
 					<label for="hereappid">Here App_Id</label>
229
-					<input type="text" name="hereappid" id="hereappid" value="<?php if (isset($globalHereappId)) print $globalHereappId; ?>" />
271
+					<input type="text" name="hereappid" id="hereappid" value="<?php if (isset($globalHereappId)) {
272
+	print $globalHereappId;
273
+}
274
+?>" />
230 275
 				</p>
231 276
 				<p>
232 277
 					<label for="hereappcode">Here App_Code</label>
233
-					<input type="text" name="hereappcode" id="hereappcode" value="<?php if (isset($globalHereappCode)) print $globalHereappCode; ?>" />
278
+					<input type="text" name="hereappcode" id="hereappcode" value="<?php if (isset($globalHereappCode)) {
279
+	print $globalHereappCode;
280
+}
281
+?>" />
234 282
 				</p>
235 283
 				<p class="help-block">Get a key <a href="https://developer.here.com/rest-apis/documentation/enterprise-map-tile/topics/quick-start.html">here</a></p>
236 284
 			</div>
@@ -239,42 +287,86 @@  discard block
 block discarded – undo
239 287
 			<legend>Coverage area</legend>
240 288
 			<p>
241 289
 				<label for="latitudemax">The maximum latitude (north)</label>
242
-				<input type="text" name="latitudemax" id="latitudemax" value="<?php if (isset($globalLatitudeMax)) print $globalLatitudeMax; ?>" />
290
+				<input type="text" name="latitudemax" id="latitudemax" value="<?php if (isset($globalLatitudeMax)) {
291
+	print $globalLatitudeMax;
292
+}
293
+?>" />
243 294
 			</p>
244 295
 			<p>
245 296
 				<label for="latitudemin">The minimum latitude (south)</label>
246
-				<input type="text" name="latitudemin" id="latitudemin" value="<?php if (isset($globalLatitudeMin)) print $globalLatitudeMin; ?>" />
297
+				<input type="text" name="latitudemin" id="latitudemin" value="<?php if (isset($globalLatitudeMin)) {
298
+	print $globalLatitudeMin;
299
+}
300
+?>" />
247 301
 			</p>
248 302
 			<p>
249 303
 				<label for="longitudemax">The maximum longitude (west)</label>
250
-				<input type="text" name="longitudemax" id="longitudemax" value="<?php if (isset($globalLongitudeMax)) print $globalLongitudeMax; ?>" />
304
+				<input type="text" name="longitudemax" id="longitudemax" value="<?php if (isset($globalLongitudeMax)) {
305
+	print $globalLongitudeMax;
306
+}
307
+?>" />
251 308
 			</p>
252 309
 			<p>
253 310
 				<label for="longitudemin">The minimum longitude (east)</label>
254
-				<input type="text" name="longitudemin" id="longitudemin" value="<?php if (isset($globalLongitudeMin)) print $globalLongitudeMin; ?>" />
311
+				<input type="text" name="longitudemin" id="longitudemin" value="<?php if (isset($globalLongitudeMin)) {
312
+	print $globalLongitudeMin;
313
+}
314
+?>" />
255 315
 			</p>
256 316
 			<p>
257 317
 				<label for="latitudecenter">The latitude center</label>
258
-				<input type="text" name="latitudecenter" id="latitudecenter" value="<?php if (isset($globalCenterLatitude)) print $globalCenterLatitude; ?>" />
318
+				<input type="text" name="latitudecenter" id="latitudecenter" value="<?php if (isset($globalCenterLatitude)) {
319
+	print $globalCenterLatitude;
320
+}
321
+?>" />
259 322
 			</p>
260 323
 			<p>
261 324
 				<label for="longitudecenter">The longitude center</label>
262
-				<input type="text" name="longitudecenter" id="longitudecenter" value="<?php if (isset($globalCenterLongitude)) print $globalCenterLongitude; ?>" />
325
+				<input type="text" name="longitudecenter" id="longitudecenter" value="<?php if (isset($globalCenterLongitude)) {
326
+	print $globalCenterLongitude;
327
+}
328
+?>" />
263 329
 			</p>
264 330
 			<p>
265 331
 				<label for="livezoom">Default Zoom on live map</label>
266
-				<input type="number" name="livezoom" id="livezoom" value="<?php if (isset($globalLiveZoom)) print $globalLiveZoom; else print '9'; ?>" />
332
+				<input type="number" name="livezoom" id="livezoom" value="<?php if (isset($globalLiveZoom)) {
333
+	print $globalLiveZoom;
334
+} else {
335
+	print '9';
336
+}
337
+?>" />
267 338
 			</p>
268 339
 			<p>
269 340
 				<label for="squawk_country">Country for squawk usage</label>
270 341
 				<select name="squawk_country" id="squawk_country">
271
-					<option value="UK"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'UK') print ' selected '; ?>>UK</option>
272
-					<option value="NZ"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'NZ') print ' selected '; ?>>NZ</option>
273
-					<option value="US"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'US') print ' selected '; ?>>US</option>
274
-					<option value="AU"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'AU') print ' selected '; ?>>AU</option>
275
-					<option value="NL"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'NL') print ' selected '; ?>>NL</option>
276
-					<option value="FR"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'FR') print ' selected '; ?>>FR</option>
277
-					<option value="TR"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'TR') print ' selected '; ?>>TR</option>
342
+					<option value="UK"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'UK') {
343
+	print ' selected ';
344
+}
345
+?>>UK</option>
346
+					<option value="NZ"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'NZ') {
347
+	print ' selected ';
348
+}
349
+?>>NZ</option>
350
+					<option value="US"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'US') {
351
+	print ' selected ';
352
+}
353
+?>>US</option>
354
+					<option value="AU"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'AU') {
355
+	print ' selected ';
356
+}
357
+?>>AU</option>
358
+					<option value="NL"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'NL') {
359
+	print ' selected ';
360
+}
361
+?>>NL</option>
362
+					<option value="FR"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'FR') {
363
+	print ' selected ';
364
+}
365
+?>>FR</option>
366
+					<option value="TR"<?php if (isset($globalSquawkCountry) && $globalSquawkCountry == 'TR') {
367
+	print ' selected ';
368
+}
369
+?>>TR</option>
278 370
 				</select>
279 371
 			</p>
280 372
 		</fieldset>
@@ -283,15 +375,24 @@  discard block
 block discarded – undo
283 375
 			<p><i>Only put in DB flights that are inside a circle</i></p>
284 376
 			<p>
285 377
 				<label for="latitude">Center latitude</label>
286
-				<input type="text" name="zoilatitude" id="latitude" value="<?php if (isset($globalDistanceIgnore['latitude'])) echo $globalDistanceIgnore['latitude']; ?>" />
378
+				<input type="text" name="zoilatitude" id="latitude" value="<?php if (isset($globalDistanceIgnore['latitude'])) {
379
+	echo $globalDistanceIgnore['latitude'];
380
+}
381
+?>" />
287 382
 			</p>
288 383
 			<p>
289 384
 				<label for="longitude">Center longitude</label>
290
-				<input type="text" name="zoilongitude" id="longitude" value="<?php if (isset($globalDistanceIgnore['longitude'])) echo $globalDistanceIgnore['longitude']; ?>" />
385
+				<input type="text" name="zoilongitude" id="longitude" value="<?php if (isset($globalDistanceIgnore['longitude'])) {
386
+	echo $globalDistanceIgnore['longitude'];
387
+}
388
+?>" />
291 389
 			</p>
292 390
 			<p>
293 391
 				<label for="Distance">Distance (in km)</label>
294
-				<input type="text" name="zoidistance" id="distance" value="<?php if (isset($globalDistanceIgnore['distance'])) echo $globalDistanceIgnore['distance']; ?>" />
392
+				<input type="text" name="zoidistance" id="distance" value="<?php if (isset($globalDistanceIgnore['distance'])) {
393
+	echo $globalDistanceIgnore['distance'];
394
+}
395
+?>" />
295 396
 			</p>
296 397
 		</fieldset>
297 398
 		<fieldset id="sourceloc">
@@ -397,11 +498,17 @@  discard block
 block discarded – undo
397 498
 			<div id="flightaware_data">
398 499
 				<p>
399 500
 					<label for="flightawareusername">FlightAware username</label>
400
-					<input type="text" name="flightawareusername" id="flightawareusername" value="<?php if (isset($globalFlightAwareUsername)) print $globalFlightAwareUsername; ?>" />
501
+					<input type="text" name="flightawareusername" id="flightawareusername" value="<?php if (isset($globalFlightAwareUsername)) {
502
+	print $globalFlightAwareUsername;
503
+}
504
+?>" />
401 505
 				</p>
402 506
 				<p>
403 507
 					<label for="flightawarepassword">FlightAware password/API key</label>
404
-					<input type="text" name="flightawarepassword" id="flightawarepassword" value="<?php if (isset($globalFlightAwarePassword)) print $globalFlightAwarePassword; ?>" />
508
+					<input type="text" name="flightawarepassword" id="flightawarepassword" value="<?php if (isset($globalFlightAwarePassword)) {
509
+	print $globalFlightAwarePassword;
510
+}
511
+?>" />
405 512
 				</p>
406 513
 			</div>
407 514
 -->
@@ -460,27 +567,84 @@  discard block
 block discarded – undo
460 567
 								?>
461 568
 								<td>
462 569
 									<select name="format[]" id="format">
463
-										<option value="auto" <?php if (!isset($source['format'])) print 'selected'; ?>>Auto</option>
464
-										<option value="sbs" <?php if (isset($source['format']) && $source['format'] == 'sbs') print 'selected'; ?>>SBS</option>
465
-										<option value="tsv" <?php if (isset($source['format']) && $source['format'] == 'tsv') print 'selected'; ?>>TSV</option>
466
-										<option value="raw" <?php if (isset($source['format']) && $source['format'] == 'raw') print 'selected'; ?>>Raw</option>
467
-										<option value="aprs" <?php if (isset($source['format']) && $source['format'] == 'aprs') print 'selected'; ?>>APRS</option>
468
-										<option value="deltadbtxt" <?php if (isset($source['format']) && $source['format'] == 'deltadbtxt') print 'selected'; ?>>Radarcape deltadb.txt</option>
469
-										<option value="vatsimtxt" <?php if (isset($source['format']) && $source['format'] == 'vatsimtxt') print 'selected'; ?>>Vatsim</option>
470
-										<option value="aircraftlistjson" <?php if (isset($source['format']) && $source['format'] == 'aircraftlistjson') print 'selected'; ?>>Virtual Radar Server AircraftList.json</option>
471
-										<option value="vrstcp" <?php if (isset($source['format']) && $source['format'] == 'vrstcp') print 'selected'; ?>>Virtual Radar Server TCP</option>
472
-										<option value="phpvmacars" <?php if (isset($source['format']) && $source['format'] == 'phpvmacars') print 'selected'; ?>>phpVMS</option>
473
-										<option value="vam" <?php if (isset($source['format']) && $source['format'] == 'vam') print 'selected'; ?>>Virtual Airlines Manager</option>
474
-										<option value="whazzup" <?php if (isset($source['format']) && $source['format'] == 'whazzup') print 'selected'; ?>>IVAO</option>
475
-										<option value="flightgearmp" <?php if (isset($source['format']) && $source['format'] == 'flightgearmp') print 'selected'; ?>>FlightGear Multiplayer</option>
476
-										<option value="flightgearsp" <?php if (isset($source['format']) && $source['format'] == 'flightgearsp') print 'selected'; ?>>FlightGear Singleplayer</option>
477
-										<option value="acars" <?php if (isset($source['format']) && $source['format'] == 'acars') print 'selected'; ?>>ACARS from acarsdec/acarsdeco2 over UDP</option>
478
-										<option value="acarssbs3" <?php if (isset($source['format']) && $source['format'] == 'acarssbs3') print 'selected'; ?>>ACARS SBS-3 over TCP</option>
479
-										<option value="ais" <?php if (isset($source['format']) && $source['format'] == 'ais') print 'selected'; ?>>NMEA AIS over TCP</option>
570
+										<option value="auto" <?php if (!isset($source['format'])) {
571
+	print 'selected';
572
+}
573
+?>>Auto</option>
574
+										<option value="sbs" <?php if (isset($source['format']) && $source['format'] == 'sbs') {
575
+	print 'selected';
576
+}
577
+?>>SBS</option>
578
+										<option value="tsv" <?php if (isset($source['format']) && $source['format'] == 'tsv') {
579
+	print 'selected';
580
+}
581
+?>>TSV</option>
582
+										<option value="raw" <?php if (isset($source['format']) && $source['format'] == 'raw') {
583
+	print 'selected';
584
+}
585
+?>>Raw</option>
586
+										<option value="aprs" <?php if (isset($source['format']) && $source['format'] == 'aprs') {
587
+	print 'selected';
588
+}
589
+?>>APRS</option>
590
+										<option value="deltadbtxt" <?php if (isset($source['format']) && $source['format'] == 'deltadbtxt') {
591
+	print 'selected';
592
+}
593
+?>>Radarcape deltadb.txt</option>
594
+										<option value="vatsimtxt" <?php if (isset($source['format']) && $source['format'] == 'vatsimtxt') {
595
+	print 'selected';
596
+}
597
+?>>Vatsim</option>
598
+										<option value="aircraftlistjson" <?php if (isset($source['format']) && $source['format'] == 'aircraftlistjson') {
599
+	print 'selected';
600
+}
601
+?>>Virtual Radar Server AircraftList.json</option>
602
+										<option value="vrstcp" <?php if (isset($source['format']) && $source['format'] == 'vrstcp') {
603
+	print 'selected';
604
+}
605
+?>>Virtual Radar Server TCP</option>
606
+										<option value="phpvmacars" <?php if (isset($source['format']) && $source['format'] == 'phpvmacars') {
607
+	print 'selected';
608
+}
609
+?>>phpVMS</option>
610
+										<option value="vam" <?php if (isset($source['format']) && $source['format'] == 'vam') {
611
+	print 'selected';
612
+}
613
+?>>Virtual Airlines Manager</option>
614
+										<option value="whazzup" <?php if (isset($source['format']) && $source['format'] == 'whazzup') {
615
+	print 'selected';
616
+}
617
+?>>IVAO</option>
618
+										<option value="flightgearmp" <?php if (isset($source['format']) && $source['format'] == 'flightgearmp') {
619
+	print 'selected';
620
+}
621
+?>>FlightGear Multiplayer</option>
622
+										<option value="flightgearsp" <?php if (isset($source['format']) && $source['format'] == 'flightgearsp') {
623
+	print 'selected';
624
+}
625
+?>>FlightGear Singleplayer</option>
626
+										<option value="acars" <?php if (isset($source['format']) && $source['format'] == 'acars') {
627
+	print 'selected';
628
+}
629
+?>>ACARS from acarsdec/acarsdeco2 over UDP</option>
630
+										<option value="acarssbs3" <?php if (isset($source['format']) && $source['format'] == 'acarssbs3') {
631
+	print 'selected';
632
+}
633
+?>>ACARS SBS-3 over TCP</option>
634
+										<option value="ais" <?php if (isset($source['format']) && $source['format'] == 'ais') {
635
+	print 'selected';
636
+}
637
+?>>NMEA AIS over TCP</option>
480 638
 									</select>
481 639
 								</td>
482
-								<td><input type="text" name="name[]" id="name" value="<?php if (isset($source['name'])) print $source['name']; ?>" /></td>
483
-								<td><input type="checkbox" name="sourcestats[]" id="sourcestats" title="Create statistics for the source like number of messages, distance,..." value="1" <?php if (isset($source['sourcestats']) && $source['sourcestats']) print 'checked'; ?> /></td>
640
+								<td><input type="text" name="name[]" id="name" value="<?php if (isset($source['name'])) {
641
+	print $source['name'];
642
+}
643
+?>" /></td>
644
+								<td><input type="checkbox" name="sourcestats[]" id="sourcestats" title="Create statistics for the source like number of messages, distance,..." value="1" <?php if (isset($source['sourcestats']) && $source['sourcestats']) {
645
+	print 'checked';
646
+}
647
+?> /></td>
484 648
 								<td><input type="button" id="delhost" value="Delete" onclick="deleteRow(this)" /> <input type="button" id="addhost" value="Add" onclick="insRow()" /></td>
485 649
 							</tr>
486 650
 <?php
@@ -528,11 +692,17 @@  discard block
 block discarded – undo
528 692
 					<p>Listen UDP server for acarsdec/acarsdeco2/... with <i>daemon-acars.php</i> script</p>
529 693
 					<p>
530 694
 						<label for="acarshost">ACARS UDP host</label>
531
-						<input type="text" name="acarshost" id="acarshost" value="<?php if (isset($globalACARSHost)) print $globalACARSHost; ?>" />
695
+						<input type="text" name="acarshost" id="acarshost" value="<?php if (isset($globalACARSHost)) {
696
+	print $globalACARSHost;
697
+}
698
+?>" />
532 699
 					</p>
533 700
 					<p>
534 701
 						<label for="acarsport">ACARS UDP port</label>
535
-						<input type="number" name="acarsport" id="acarsport" value="<?php if (isset($globalACARSPort)) print $globalACARSPort; ?>" />
702
+						<input type="number" name="acarsport" id="acarsport" value="<?php if (isset($globalACARSPort)) {
703
+	print $globalACARSPort;
704
+}
705
+?>" />
536 706
 					</p>
537 707
 				</fieldset>
538 708
 			</div>
@@ -612,13 +782,19 @@  discard block
 block discarded – undo
612 782
 			<div id="schedules_options">
613 783
 				<p>
614 784
 					<label for="britishairways">British Airways API Key</label>
615
-					<input type="text" name="britishairways" id="britishairways" value="<?php if (isset($globalBritishAirwaysKey)) print $globalBritishAirwaysKey; ?>" />
785
+					<input type="text" name="britishairways" id="britishairways" value="<?php if (isset($globalBritishAirwaysKey)) {
786
+	print $globalBritishAirwaysKey;
787
+}
788
+?>" />
616 789
 					<p class="help-block">Register an account on <a href="https://developer.ba.com/">https://developer.ba.com/</a></p>
617 790
 				</p>
618 791
 				<!--
619 792
 				<p>
620 793
 					<label for="transavia">Transavia Test API Consumer Key</label>
621
-					<input type="text" name="transavia" id="transavia" value="<?php if (isset($globalTransaviaKey)) print $globalTransaviaKey; ?>" />
794
+					<input type="text" name="transavia" id="transavia" value="<?php if (isset($globalTransaviaKey)) {
795
+	print $globalTransaviaKey;
796
+}
797
+?>" />
622 798
 					<p class="help-block">Register an account on <a href="https://developer.transavia.com">https://developer.transavia.com</a></p>
623 799
 				</p>
624 800
 				-->
@@ -627,10 +803,16 @@  discard block
 block discarded – undo
627 803
 						<b>Lufthansa API Key</b>
628 804
 						<p>
629 805
 							<label for="lufthansakey">Key</label>
630
-							<input type="text" name="lufthansakey" id="lufthansakey" value="<?php if (isset($globalLufthansaKey['key'])) print $globalLufthansaKey['key']; ?>" />
806
+							<input type="text" name="lufthansakey" id="lufthansakey" value="<?php if (isset($globalLufthansaKey['key'])) {
807
+	print $globalLufthansaKey['key'];
808
+}
809
+?>" />
631 810
 						</p><p>
632 811
 							<label for="lufthansasecret">Secret</label>
633
-							<input type="text" name="lufthansasecret" id="lufthansasecret" value="<?php if (isset($globalLufthansaKey['secret'])) print $globalLufthansaKey['secret']; ?>" />
812
+							<input type="text" name="lufthansasecret" id="lufthansasecret" value="<?php if (isset($globalLufthansaKey['secret'])) {
813
+	print $globalLufthansaKey['secret'];
814
+}
815
+?>" />
634 816
 						</p>
635 817
 					</div>
636 818
 					<p class="help-block">Register an account on <a href="https://developer.lufthansa.com/page">https://developer.lufthansa.com/page</a></p>
@@ -650,7 +832,10 @@  discard block
 block discarded – undo
650 832
 			</p>
651 833
 			<p>
652 834
 				<label for="notamsource">URL of your feed from notaminfo.com</label>
653
-				<input type="text" name="notamsource" id="notamsource" value="<?php if (isset($globalNOTAMSource)) print $globalNOTAMSource; ?>" />
835
+				<input type="text" name="notamsource" id="notamsource" value="<?php if (isset($globalNOTAMSource)) {
836
+	print $globalNOTAMSource;
837
+}
838
+?>" />
654 839
 				<p class="help-block">If you want to use world NOTAM from FlightAirMap website, leave it blank</p>
655 840
 			</p>
656 841
 			<br />
@@ -666,14 +851,20 @@  discard block
 block discarded – undo
666 851
 			<div id="metarsrc">
667 852
 				<p>
668 853
 					<label for="metarsource">URL of your METAR source</label>
669
-					<input type="text" name="metarsource" id="metarsource" value="<?php if (isset($globalMETARurl)) print $globalMETARurl; ?>" />
854
+					<input type="text" name="metarsource" id="metarsource" value="<?php if (isset($globalMETARurl)) {
855
+	print $globalMETARurl;
856
+}
857
+?>" />
670 858
 					<p class="help-block">Use {icao} to specify where we replace by airport icao. ex : http://metar.vatsim.net/metar.php?id={icao}</p>
671 859
 				</p>
672 860
 			</div>
673 861
 			<br />
674 862
 			<p>
675 863
 				<label for="bitly">Bit.ly access token api (used in search page)</label>
676
-				<input type="text" name="bitly" id="bitly" value="<?php if (isset($globalBitlyAccessToken)) print $globalBitlyAccessToken; ?>" />
864
+				<input type="text" name="bitly" id="bitly" value="<?php if (isset($globalBitlyAccessToken)) {
865
+	print $globalBitlyAccessToken;
866
+}
867
+?>" />
677 868
 			</p>
678 869
 			<br />
679 870
 			<p>
@@ -693,7 +884,12 @@  discard block
 block discarded – undo
693 884
 			</p>
694 885
 			<p>
695 886
 				<label for="archivemonths">Generate statistics, delete or put in archive flights older than xx months</label>
696
-				<input type="number" name="archivemonths" id="archivemonths" value="<?php if (isset($globalArchiveMonths)) print $globalArchiveMonths; else echo '0'; ?>" />
887
+				<input type="number" name="archivemonths" id="archivemonths" value="<?php if (isset($globalArchiveMonths)) {
888
+	print $globalArchiveMonths;
889
+} else {
890
+	echo '0';
891
+}
892
+?>" />
697 893
 				<p class="help-block">0 to disable, delete old flight if <i>Archive all flights data</i> is disabled</p>
698 894
 			</p>
699 895
 			<p>
@@ -703,12 +899,22 @@  discard block
 block discarded – undo
703 899
 			</p>
704 900
 			<p>
705 901
 				<label for="archivekeepmonths">Keep flights data for xx months in archive</label>
706
-				<input type="number" name="archivekeepmonths" id="archivekeepmonths" value="<?php if (isset($globalArchiveKeepMonths)) print $globalArchiveKeepMonths; else echo '0'; ?>" />
902
+				<input type="number" name="archivekeepmonths" id="archivekeepmonths" value="<?php if (isset($globalArchiveKeepMonths)) {
903
+	print $globalArchiveKeepMonths;
904
+} else {
905
+	echo '0';
906
+}
907
+?>" />
707 908
 				<p class="help-block">0 to disable</p>
708 909
 			</p>
709 910
 			<p>
710 911
 				<label for="archivekeeptrackmonths">Keep flights track data for xx months in archive</label>
711
-				<input type="number" name="archivekeeptrackmonths" id="archivekeeptrackmonths" value="<?php if (isset($globalArchiveKeepTrackMonths)) print $globalArchiveKeepTrackMonths; else echo '0'; ?>" />
912
+				<input type="number" name="archivekeeptrackmonths" id="archivekeeptrackmonths" value="<?php if (isset($globalArchiveKeepTrackMonths)) {
913
+	print $globalArchiveKeepTrackMonths;
914
+} else {
915
+	echo '0';
916
+}
917
+?>" />
712 918
 				<p class="help-block">0 to disable, should be less or egal to <i>Keep flights data</i> value</p>
713 919
 			</p>
714 920
 			<br />
@@ -718,7 +924,12 @@  discard block
 block discarded – undo
718 924
 				<p class="help-block">Uncheck if the script is running as cron job</p>
719 925
 				<div id="cronends"> 
720 926
 					<label for="cronend">Run script for xx seconds</label>
721
-					<input type="number" name="cronend" id="cronend" value="<?php if (isset($globalCronEnd)) print $globalCronEnd; else print '0'; ?>" />
927
+					<input type="number" name="cronend" id="cronend" value="<?php if (isset($globalCronEnd)) {
928
+	print $globalCronEnd;
929
+} else {
930
+	print '0';
931
+}
932
+?>" />
722 933
 					<p class="help-block">Set to 0 to disable. Should be disabled if source is URL.</p>
723 934
 				</div>
724 935
 			</p>
@@ -763,26 +974,49 @@  discard block
 block discarded – undo
763 974
 			<br />
764 975
 			<p>
765 976
 				<label for="refresh">Show flights detected since xxx seconds</label>
766
-				<input type="number" name="refresh" id="refresh" value="<?php if (isset($globalLiveInterval)) echo $globalLiveInterval; else echo '200'; ?>" />
977
+				<input type="number" name="refresh" id="refresh" value="<?php if (isset($globalLiveInterval)) {
978
+	echo $globalLiveInterval;
979
+} else {
980
+	echo '200';
981
+}
982
+?>" />
767 983
 			</p>
768 984
 			<p>
769 985
 				<label for="maprefresh">Live map refresh (in seconds)</label>
770
-				<input type="number" name="maprefresh" id="maprefresh" value="<?php if (isset($globalMapRefresh)) echo $globalMapRefresh; else echo '30'; ?>" />
986
+				<input type="number" name="maprefresh" id="maprefresh" value="<?php if (isset($globalMapRefresh)) {
987
+	echo $globalMapRefresh;
988
+} else {
989
+	echo '30';
990
+}
991
+?>" />
771 992
 			</p>
772 993
 			<p>
773 994
 				<label for="mapidle">Map idle timeout (in minutes)</label>
774
-				<input type="number" name="mapidle" id="mapidle" value="<?php if (isset($globalMapIdleTimeout)) echo $globalMapIdleTimeout; else echo '30'; ?>" />
995
+				<input type="number" name="mapidle" id="mapidle" value="<?php if (isset($globalMapIdleTimeout)) {
996
+	echo $globalMapIdleTimeout;
997
+} else {
998
+	echo '30';
999
+}
1000
+?>" />
775 1001
 				<p class="help-block">0 to disable</p>
776 1002
 			</p>
777 1003
 			<br />
778 1004
 			<p>
779 1005
 				<label for="closestmindist">Distance to airport set as arrival (in km)</label>
780
-				<input type="number" name="closestmindist" id="closestmindist" value="<?php if (isset($globalClosestMinDist)) echo $globalClosestMinDist; else echo '50'; ?>" />
1006
+				<input type="number" name="closestmindist" id="closestmindist" value="<?php if (isset($globalClosestMinDist)) {
1007
+	echo $globalClosestMinDist;
1008
+} else {
1009
+	echo '50';
1010
+}
1011
+?>" />
781 1012
 			</p>
782 1013
 			<br />
783 1014
 			<p>
784 1015
 				<label for="aircraftsize">Size of aircraft icon on map (default to 30px if zoom > 7 else 15px), empty to default</label>
785
-				<input type="number" name="aircraftsize" id="aircraftsize" value="<?php if (isset($globalAircraftSize)) echo $globalAircraftSize;?>" />
1016
+				<input type="number" name="aircraftsize" id="aircraftsize" value="<?php if (isset($globalAircraftSize)) {
1017
+	echo $globalAircraftSize;
1018
+}
1019
+?>" />
786 1020
 			</p>
787 1021
 			<br />
788 1022
 			<p>
@@ -790,7 +1024,12 @@  discard block
 block discarded – undo
790 1024
 			    if (extension_loaded('gd') && function_exists('gd_info')) {
791 1025
 			?>
792 1026
 				<label for="aircrafticoncolor">Color of aircraft icon on map</label>
793
-				<input type="color" name="aircrafticoncolor" id="aircrafticoncolor" value="#<?php if (isset($globalAircraftIconColor)) echo $globalAircraftIconColor; else echo '1a3151'; ?>" />
1027
+				<input type="color" name="aircrafticoncolor" id="aircrafticoncolor" value="#<?php if (isset($globalAircraftIconColor)) {
1028
+	echo $globalAircraftIconColor;
1029
+} else {
1030
+	echo '1a3151';
1031
+}
1032
+?>" />
794 1033
 			<?php
795 1034
 				if (!is_writable('../cache')) {
796 1035
 			?>
@@ -808,8 +1047,18 @@  discard block
 block discarded – undo
808 1047
 			<p>
809 1048
 				<label for="airportzoom">Zoom level minimum to see airports icons</label>
810 1049
 				<div class="range">
811
-					<input type="range" name="airportzoom" id="airportzoom" value="<?php if (isset($globalAirportZoom)) echo $globalAirportZoom; else echo '7'; ?>" />
812
-					<output id="range"><?php if (isset($globalAirportZoom)) echo $globalAirportZoom; else echo '7'; ?></output>
1050
+					<input type="range" name="airportzoom" id="airportzoom" value="<?php if (isset($globalAirportZoom)) {
1051
+	echo $globalAirportZoom;
1052
+} else {
1053
+	echo '7';
1054
+}
1055
+?>" />
1056
+					<output id="range"><?php if (isset($globalAirportZoom)) {
1057
+	echo $globalAirportZoom;
1058
+} else {
1059
+	echo '7';
1060
+}
1061
+?></output>
813 1062
 				</div>
814 1063
 			</p>
815 1064
 		</fieldset>
@@ -837,8 +1086,12 @@  discard block
 block discarded – undo
837 1086
 	$dbhost = filter_input(INPUT_POST,'dbhost',FILTER_SANITIZE_STRING);
838 1087
 	$dbport = filter_input(INPUT_POST,'dbport',FILTER_SANITIZE_STRING);
839 1088
 
840
-	if ($dbtype == 'mysql' && !extension_loaded('pdo_mysql')) $error .= 'Mysql driver for PDO must be loaded';
841
-	if ($dbtype == 'pgsql' && !extension_loaded('pdo_pgsql')) $error .= 'PosgreSQL driver for PDO must be loaded';
1089
+	if ($dbtype == 'mysql' && !extension_loaded('pdo_mysql')) {
1090
+		$error .= 'Mysql driver for PDO must be loaded';
1091
+	}
1092
+	if ($dbtype == 'pgsql' && !extension_loaded('pdo_pgsql')) {
1093
+		$error .= 'PosgreSQL driver for PDO must be loaded';
1094
+	}
842 1095
 	
843 1096
 	$_SESSION['database_root'] = $dbroot;
844 1097
 	$_SESSION['database_rootpass'] = $dbrootpass;
@@ -905,15 +1158,23 @@  discard block
 block discarded – undo
905 1158
 	$source_city = $_POST['source_city'];
906 1159
 	$source_country = $_POST['source_country'];
907 1160
 	$source_ref = $_POST['source_ref'];
908
-	if (isset($source_id)) $source_id = $_POST['source_id'];
909
-	else $source_id = array();
1161
+	if (isset($source_id)) {
1162
+		$source_id = $_POST['source_id'];
1163
+	} else {
1164
+		$source_id = array();
1165
+	}
910 1166
 	
911 1167
 	$sources = array();
912 1168
 	foreach ($source_name as $keys => $name) {
913
-	    if (isset($source_id[$keys])) $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'id' => $source_id[$keys],'source' => $source_ref[$keys]);
914
-	    else $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'source' => $source_ref[$keys]);
1169
+	    if (isset($source_id[$keys])) {
1170
+	    	$sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'id' => $source_id[$keys],'source' => $source_ref[$keys]);
1171
+	    } else {
1172
+	    	$sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'source' => $source_ref[$keys]);
1173
+	    }
1174
+	}
1175
+	if (count($sources) > 0) {
1176
+		$_SESSION['sources'] = $sources;
915 1177
 	}
916
-	if (count($sources) > 0) $_SESSION['sources'] = $sources;
917 1178
 
918 1179
 	//$sbshost = filter_input(INPUT_POST,'sbshost',FILTER_SANITIZE_STRING);
919 1180
 	//$sbsport = filter_input(INPUT_POST,'sbsport',FILTER_SANITIZE_NUMBER_INT);
@@ -933,14 +1194,23 @@  discard block
 block discarded – undo
933 1194
 	$datasource = filter_input(INPUT_POST,'datasource',FILTER_SANITIZE_STRING);
934 1195
 
935 1196
 	$globalaircraft = filter_input(INPUT_POST,'globalaircraft',FILTER_SANITIZE_STRING);
936
-	if ($globalaircraft == 'aircraft') $settings = array_merge($settings,array('globalAircraft' => 'TRUE'));
937
-	else $settings = array_merge($settings,array('globalAircraft' => 'FALSE'));
1197
+	if ($globalaircraft == 'aircraft') {
1198
+		$settings = array_merge($settings,array('globalAircraft' => 'TRUE'));
1199
+	} else {
1200
+		$settings = array_merge($settings,array('globalAircraft' => 'FALSE'));
1201
+	}
938 1202
 	$globaltracker = filter_input(INPUT_POST,'globaltracker',FILTER_SANITIZE_STRING);
939
-	if ($globaltracker == 'tracker') $settings = array_merge($settings,array('globalTracker' => 'TRUE'));
940
-	else $settings = array_merge($settings,array('globalTracker' => 'FALSE'));
1203
+	if ($globaltracker == 'tracker') {
1204
+		$settings = array_merge($settings,array('globalTracker' => 'TRUE'));
1205
+	} else {
1206
+		$settings = array_merge($settings,array('globalTracker' => 'FALSE'));
1207
+	}
941 1208
 	$globalmarine = filter_input(INPUT_POST,'globalmarine',FILTER_SANITIZE_STRING);
942
-	if ($globalmarine == 'marine') $settings = array_merge($settings,array('globalMarine' => 'TRUE'));
943
-	else $settings = array_merge($settings,array('globalMarine' => 'FALSE'));
1209
+	if ($globalmarine == 'marine') {
1210
+		$settings = array_merge($settings,array('globalMarine' => 'TRUE'));
1211
+	} else {
1212
+		$settings = array_merge($settings,array('globalMarine' => 'FALSE'));
1213
+	}
944 1214
 
945 1215
 /*	
946 1216
 	$globalSBS1Hosts = array();
@@ -961,13 +1231,21 @@  discard block
 block discarded – undo
961 1231
 	$port = $_POST['port'];
962 1232
 	$name = $_POST['name'];
963 1233
 	$format = $_POST['format'];
964
-	if (isset($_POST['sourcestats'])) $sourcestats = $_POST['sourcestats'];
965
-	else $sourcestats = array();
1234
+	if (isset($_POST['sourcestats'])) {
1235
+		$sourcestats = $_POST['sourcestats'];
1236
+	} else {
1237
+		$sourcestats = array();
1238
+	}
966 1239
 	$gSources = array();
967 1240
 	foreach ($host as $key => $h) {
968
-		if (isset($sourcestats[$key]) && $sourcestats[$key] == 1) $cov = 'TRUE';
969
-		else $cov = 'FALSE';
970
-		if ($h != '') $gSources[] = array('host' => $h, 'port' => $port[$key],'name' => $name[$key],'format' => $format[$key],'sourcestats' => $cov);
1241
+		if (isset($sourcestats[$key]) && $sourcestats[$key] == 1) {
1242
+			$cov = 'TRUE';
1243
+		} else {
1244
+			$cov = 'FALSE';
1245
+		}
1246
+		if ($h != '') {
1247
+			$gSources[] = array('host' => $h, 'port' => $port[$key],'name' => $name[$key],'format' => $format[$key],'sourcestats' => $cov);
1248
+		}
971 1249
 	}
972 1250
 	$settings = array_merge($settings,array('globalSources' => $gSources));
973 1251
 
@@ -992,7 +1270,9 @@  discard block
 block discarded – undo
992 1270
 	$zoidistance = filter_input(INPUT_POST,'zoidistance',FILTER_SANITIZE_NUMBER_INT);
993 1271
 	if ($zoilatitude != '' && $zoilongitude != '' && $zoidistance != '') {
994 1272
 		$settings = array_merge($settings,array('globalDistanceIgnore' => array('latitude' => $zoilatitude,'longitude' => $zoilongitude,'distance' => $zoidistance)));
995
-	} else $settings = array_merge($settings,array('globalDistanceIgnore' => array()));
1273
+	} else {
1274
+		$settings = array_merge($settings,array('globalDistanceIgnore' => array()));
1275
+	}
996 1276
 
997 1277
 	$refresh = filter_input(INPUT_POST,'refresh',FILTER_SANITIZE_NUMBER_INT);
998 1278
 	$settings = array_merge($settings,array('globalLiveInterval' => $refresh));
@@ -1031,7 +1311,9 @@  discard block
 block discarded – undo
1031 1311
 
1032 1312
 	// Create in settings.php keys not yet configurable if not already here
1033 1313
 	//if (!isset($globalImageBingKey)) $settings = array_merge($settings,array('globalImageBingKey' => ''));
1034
-	if (!isset($globalDebug)) $settings = array_merge($settings,array('globalDebug' => 'TRUE'));
1314
+	if (!isset($globalDebug)) {
1315
+		$settings = array_merge($settings,array('globalDebug' => 'TRUE'));
1316
+	}
1035 1317
 
1036 1318
 	$resetyearstats = filter_input(INPUT_POST,'resetyearstats',FILTER_SANITIZE_STRING);
1037 1319
 	if ($resetyearstats == 'resetyearstats') {
@@ -1068,27 +1350,43 @@  discard block
 block discarded – undo
1068 1350
 	}
1069 1351
 */
1070 1352
 	$settings = array_merge($settings,array('globalFlightAware' => 'FALSE'));
1071
-	if ($globalsbs == 'sbs') $settings = array_merge($settings,array('globalSBS1' => 'TRUE'));
1072
-	else $settings = array_merge($settings,array('globalSBS1' => 'FALSE'));
1073
-	if ($globalaprs == 'aprs') $settings = array_merge($settings,array('globalAPRS' => 'TRUE'));
1074
-	else $settings = array_merge($settings,array('globalAPRS' => 'FALSE'));
1353
+	if ($globalsbs == 'sbs') {
1354
+		$settings = array_merge($settings,array('globalSBS1' => 'TRUE'));
1355
+	} else {
1356
+		$settings = array_merge($settings,array('globalSBS1' => 'FALSE'));
1357
+	}
1358
+	if ($globalaprs == 'aprs') {
1359
+		$settings = array_merge($settings,array('globalAPRS' => 'TRUE'));
1360
+	} else {
1361
+		$settings = array_merge($settings,array('globalAPRS' => 'FALSE'));
1362
+	}
1075 1363
 	if ($globalivao == 'ivao') {
1076 1364
 		//$settings = array_merge($settings,array('globalIVAO' => 'TRUE','globalVATSIM' => 'FALSE'));
1077 1365
 		$settings = array_merge($settings,array('globalIVAO' => 'TRUE'));
1078
-	} else $settings = array_merge($settings,array('globalIVAO' => 'FALSE'));
1366
+	} else {
1367
+		$settings = array_merge($settings,array('globalIVAO' => 'FALSE'));
1368
+	}
1079 1369
 	if ($globalvatsim == 'vatsim') {
1080 1370
 		//$settings = array_merge($settings,array('globalVATSIM' => 'TRUE','globalIVAO' => 'FALSE'));
1081 1371
 		$settings = array_merge($settings,array('globalVATSIM' => 'TRUE'));
1082
-	} else $settings = array_merge($settings,array('globalVATSIM' => 'FALSE'));
1372
+	} else {
1373
+		$settings = array_merge($settings,array('globalVATSIM' => 'FALSE'));
1374
+	}
1083 1375
 	if ($globalphpvms == 'phpvms') {
1084 1376
 		$settings = array_merge($settings,array('globalphpVMS' => 'TRUE'));
1085
-	} else $settings = array_merge($settings,array('globalphpVMS' => 'FALSE'));
1377
+	} else {
1378
+		$settings = array_merge($settings,array('globalphpVMS' => 'FALSE'));
1379
+	}
1086 1380
 	if ($globalvam == 'vam') {
1087 1381
 		$settings = array_merge($settings,array('globalVAM' => 'TRUE'));
1088
-	} else $settings = array_merge($settings,array('globalVAM' => 'FALSE'));
1382
+	} else {
1383
+		$settings = array_merge($settings,array('globalVAM' => 'FALSE'));
1384
+	}
1089 1385
 	if ($globalvatsim == 'vatsim' || $globalivao == 'ivao' || $globalphpvms == 'phpvms') {
1090 1386
 		$settings = array_merge($settings,array('globalSchedulesFetch' => 'FALSE','globalTranslationFetch' => 'FALSE'));
1091
-	} else $settings = array_merge($settings,array('globalSchedulesFetch' => 'TRUE','globalTranslationFetch' => 'TRUE'));
1387
+	} else {
1388
+		$settings = array_merge($settings,array('globalSchedulesFetch' => 'TRUE','globalTranslationFetch' => 'TRUE'));
1389
+	}
1092 1390
 	
1093 1391
 
1094 1392
 
@@ -1224,7 +1522,9 @@  discard block
 block discarded – undo
1224 1522
 		$settings = array_merge($settings,array('globalWaypoints' => 'FALSE'));
1225 1523
 	}
1226 1524
 
1227
-	if (!isset($globalTransaction)) $settings = array_merge($settings,array('globalTransaction' => 'TRUE'));
1525
+	if (!isset($globalTransaction)) {
1526
+		$settings = array_merge($settings,array('globalTransaction' => 'TRUE'));
1527
+	}
1228 1528
 
1229 1529
 	// Set some defaults values...
1230 1530
 	if (!isset($globalAircraftImageSources)) {
@@ -1239,15 +1539,23 @@  discard block
 block discarded – undo
1239 1539
 
1240 1540
 	$settings = array_merge($settings,array('globalInstalled' => 'TRUE'));
1241 1541
 
1242
-	if ($error == '') settings::modify_settings($settings);
1243
-	if ($error == '') settings::comment_settings($settings_comment);
1542
+	if ($error == '') {
1543
+		settings::modify_settings($settings);
1544
+	}
1545
+	if ($error == '') {
1546
+		settings::comment_settings($settings_comment);
1547
+	}
1244 1548
 	if ($error != '') {
1245 1549
 		print '<div class="info column">'.$error.'</div>';
1246 1550
 		require('../footer.php');
1247 1551
 		exit;
1248 1552
 	} else {
1249
-		if (isset($_POST['waypoints']) && $_POST['waypoints'] == 'waypoints') $_SESSION['waypoints'] = 1;
1250
-		if (isset($_POST['owner']) && $_POST['owner'] == 'owner') $_SESSION['owner'] = 1;
1553
+		if (isset($_POST['waypoints']) && $_POST['waypoints'] == 'waypoints') {
1554
+			$_SESSION['waypoints'] = 1;
1555
+		}
1556
+		if (isset($_POST['owner']) && $_POST['owner'] == 'owner') {
1557
+			$_SESSION['owner'] = 1;
1558
+		}
1251 1559
 		if (isset($_POST['createdb'])) {
1252 1560
 			$_SESSION['install'] = 'database_create';
1253 1561
 		} else {
@@ -1288,10 +1596,18 @@  discard block
 block discarded – undo
1288 1596
 	$popw = false;
1289 1597
 	foreach ($_SESSION['done'] as $done) {
1290 1598
 	    print '<li>'.$done.'....<strong>SUCCESS</strong></li>';
1291
-	    if ($done == 'Create database') $pop = true;
1292
-	    if ($_SESSION['install'] == 'database_create') $pop = true;
1293
-	    if ($_SESSION['install'] == 'database_import') $popi = true;
1294
-	    if ($_SESSION['install'] == 'waypoints') $popw = true;
1599
+	    if ($done == 'Create database') {
1600
+	    	$pop = true;
1601
+	    }
1602
+	    if ($_SESSION['install'] == 'database_create') {
1603
+	    	$pop = true;
1604
+	    }
1605
+	    if ($_SESSION['install'] == 'database_import') {
1606
+	    	$popi = true;
1607
+	    }
1608
+	    if ($_SESSION['install'] == 'waypoints') {
1609
+	    	$popw = true;
1610
+	    }
1295 1611
 	}
1296 1612
 	if ($pop) {
1297 1613
 	    sleep(5);
@@ -1302,7 +1618,9 @@  discard block
 block discarded – undo
1302 1618
 	} else if ($popw) {
1303 1619
 	    sleep(5);
1304 1620
 	    print '<li>Populate waypoints database....<img src="../images/loading.gif" /></li>';
1305
-	} else print '<li>Update schema if needed....<img src="../images/loading.gif" /></li>';
1621
+	} else {
1622
+		print '<li>Update schema if needed....<img src="../images/loading.gif" /></li>';
1623
+	}
1306 1624
 	print '</div></ul>';
1307 1625
 	print '<div id="error"></div>';
1308 1626
 /*	foreach ($_SESSION['done'] as $done) {
Please login to merge, or discard this patch.