Completed
Push — master ( c1d943...56b04e )
by Yannick
07:43
created
scripts/daemon-spotter.php 2 patches
Indentation   +695 added lines, -695 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 // Check if schema is at latest version
20 20
 $Connection = new Connection();
21 21
 if ($Connection->latest() === false) {
22
-    echo "You MUST update to latest schema. Run install/index.php";
23
-    exit();
22
+	echo "You MUST update to latest schema. Run install/index.php";
23
+	exit();
24 24
 }
25 25
 if (PHP_SAPI != 'cli') {
26
-    echo "This script MUST be called from console, not a web browser.";
26
+	echo "This script MUST be called from console, not a web browser.";
27 27
 //    exit();
28 28
 }
29 29
 
30 30
 // This is to be compatible with old version of settings.php
31 31
 if (!isset($globalSources)) {
32
-    if (isset($globalSBS1Hosts)) {
33
-        //$hosts = $globalSBS1Hosts;
34
-        foreach ($globalSBS1Hosts as $host) {
35
-	    $globalSources[] = array('host' => $host);
36
-    	}
37
-    } else {
38
-        if (!isset($globalSBS1Host)) {
39
-	    echo '$globalSources MUST be defined !';
40
-	    die;
32
+	if (isset($globalSBS1Hosts)) {
33
+		//$hosts = $globalSBS1Hosts;
34
+		foreach ($globalSBS1Hosts as $host) {
35
+		$globalSources[] = array('host' => $host);
36
+		}
37
+	} else {
38
+		if (!isset($globalSBS1Host)) {
39
+		echo '$globalSources MUST be defined !';
40
+		die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43 43
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
44
-    }
44
+	}
45 45
 }
46 46
 
47 47
 $options = getopt('s::',array('source::','server','idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
51
-    $globalSources = array();
52
-    $globalSources[] = array('host' => $options['s']);
51
+	$globalSources = array();
52
+	$globalSources[] = array('host' => $options['s']);
53 53
 } elseif (isset($options['source'])) {
54
-    $globalSources = array();
55
-    $globalSources[] = array('host' => $options['source']);
54
+	$globalSources = array();
55
+	$globalSources[] = array('host' => $options['source']);
56 56
 }
57 57
 if (isset($options['server'])) $globalServer = TRUE;
58 58
 if (isset($options['idsource'])) $id_source = $options['idsource'];
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
61
+	if ($globalDebug) echo "Using Server Mode\n";
62
+	$SI=new SpotterServer();
63 63
 } else $SI=new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65 65
 $SBS=new SBS();
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
73
-        global $sockets;
74
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
-        die("Bye!\n");
76
-    });
77
-    pcntl_signal_dispatch();
72
+	pcntl_signal(SIGINT,  function() {
73
+		global $sockets;
74
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
+		die("Bye!\n");
76
+	});
77
+	pcntl_signal_dispatch();
78 78
 }
79 79
 
80 80
 // let's try and connect
@@ -84,162 +84,162 @@  discard block
 block discarded – undo
84 84
 $reset = 0;
85 85
 
86 86
 function create_socket($host, $port, &$errno, &$errstr) {
87
-    $ip = gethostbyname($host);
88
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
89
-    $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
-        return $s;
93
-    }
94
-    $errno = socket_last_error($s);
95
-    $errstr = socket_strerror($errno);
96
-    socket_close($s);
97
-    return false;
87
+	$ip = gethostbyname($host);
88
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
89
+	$r = @socket_connect($s, $ip, $port);
90
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
+		return $s;
93
+	}
94
+	$errno = socket_last_error($s);
95
+	$errstr = socket_strerror($errno);
96
+	socket_close($s);
97
+	return false;
98 98
 }
99 99
 
100 100
 function create_socket_udp($host, $port, &$errno, &$errstr) {
101
-    echo "Create an UDP socket...\n";
102
-    $ip = gethostbyname($host);
103
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
-    $r = @socket_bind($s, $ip, $port);
105
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
-        return $s;
107
-    }
108
-    $errno = socket_last_error($s);
109
-    $errstr = socket_strerror($errno);
110
-    socket_close($s);
111
-    return false;
101
+	echo "Create an UDP socket...\n";
102
+	$ip = gethostbyname($host);
103
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
+	$r = @socket_bind($s, $ip, $port);
105
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
+		return $s;
107
+	}
108
+	$errno = socket_last_error($s);
109
+	$errstr = socket_strerror($errno);
110
+	socket_close($s);
111
+	return false;
112 112
 }
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
-        	//$formats[$id] = 'radarvirtueljson';
146
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
147
-        	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
-        	    exit(0);
152
-        	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
-        	//$formats[$id] = 'planeupdatefaa';
155
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
156
-        	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
-        	    exit(0);
161
-        	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
-        	//$formats[$id] = 'phpvmacars';
164
-        	$globalSources[$id]['format'] = 'phpvmacars';
165
-        	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
168
-        	//$formats[$id] = 'phpvmacars';
169
-        	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
172
-        	//$formats[$id] = 'whazzup';
173
-        	$globalSources[$id]['format'] = 'whazzup';
174
-        	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
177
-        	//$formats[$id] = 'pirepsjson';
178
-        	$globalSources[$id]['format'] = 'pirepsjson';
179
-        	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
-        	//$formats[$id] = 'fr24json';
183
-        	$globalSources[$id]['format'] = 'fr24json';
184
-        	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
-        	    exit(0);
189
-        	}
190
-            //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
-        	//$formats[$id] = 'tsv';
193
-        	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
-            }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
200
-	    if (isset($hostport[1])) {
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
+			//$formats[$id] = 'radarvirtueljson';
146
+			$globalSources[$id]['format'] = 'radarvirtueljson';
147
+			//$last_exec['radarvirtueljson'] = 0;
148
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
+				exit(0);
152
+			}
153
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
+			//$formats[$id] = 'planeupdatefaa';
155
+			$globalSources[$id]['format'] = 'planeupdatefaa';
156
+			//$last_exec['planeupdatefaa'] = 0;
157
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
+				exit(0);
161
+			}
162
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
+			//$formats[$id] = 'phpvmacars';
164
+			$globalSources[$id]['format'] = 'phpvmacars';
165
+			//$last_exec['phpvmacars'] = 0;
166
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
168
+			//$formats[$id] = 'phpvmacars';
169
+			$globalSources[$id]['format'] = 'vam';
170
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
+			} else if (preg_match('/whazzup/i',$host)) {
172
+			//$formats[$id] = 'whazzup';
173
+			$globalSources[$id]['format'] = 'whazzup';
174
+			//$last_exec['whazzup'] = 0;
175
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
+			} else if (preg_match('/recentpireps/i',$host)) {
177
+			//$formats[$id] = 'pirepsjson';
178
+			$globalSources[$id]['format'] = 'pirepsjson';
179
+			//$last_exec['pirepsjson'] = 0;
180
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
+			//$formats[$id] = 'fr24json';
183
+			$globalSources[$id]['format'] = 'fr24json';
184
+			//$last_exec['fr24json'] = 0;
185
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
+				exit(0);
189
+			}
190
+			//} else if (preg_match('/10001/',$host)) {
191
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
+			//$formats[$id] = 'tsv';
193
+			$globalSources[$id]['format'] = 'tsv';
194
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
+			}
196
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
+		$hostport = explode(':',$host);
200
+		if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
203
-	    } else {
203
+		} else {
204 204
 		$port = $globalSources[$id]['port'];
205 205
 		$hostn = $globalSources[$id]['host'];
206
-	    }
207
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
209
-    	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
-	    }
212
-	    if ($s) {
213
-    	        $sockets[$id] = $s;
214
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
206
+		}
207
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
+			$s = create_socket($hostn,$port, $errno, $errstr);
209
+			} else {
210
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
+		}
212
+		if ($s) {
213
+				$sockets[$id] = $s;
214
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
+			if (preg_match('/aprs/',$hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
219 219
 			//$use_aprs = true;
220
-    		    } elseif ($port == '10001') {
221
-        		//$formats[$id] = 'tsv';
222
-        		$globalSources[$id]['format'] = 'tsv';
223
-		    } elseif ($port == '30002') {
224
-        		//$formats[$id] = 'raw';
225
-        		$globalSources[$id]['format'] = 'raw';
226
-		    } elseif ($port == '5001') {
227
-        		//$formats[$id] = 'raw';
228
-        		$globalSources[$id]['format'] = 'flightgearmp';
229
-		    } elseif ($port == '30005') {
220
+				} elseif ($port == '10001') {
221
+				//$formats[$id] = 'tsv';
222
+				$globalSources[$id]['format'] = 'tsv';
223
+			} elseif ($port == '30002') {
224
+				//$formats[$id] = 'raw';
225
+				$globalSources[$id]['format'] = 'raw';
226
+			} elseif ($port == '5001') {
227
+				//$formats[$id] = 'raw';
228
+				$globalSources[$id]['format'] = 'flightgearmp';
229
+			} elseif ($port == '30005') {
230 230
 			// Not yet supported
231
-        		//$formats[$id] = 'beast';
232
-        		$globalSources[$id]['format'] = 'beast';
233
-		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
235
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
231
+				//$formats[$id] = 'beast';
232
+				$globalSources[$id]['format'] = 'beast';
233
+			//} else $formats[$id] = 'sbs';
234
+			} else $globalSources[$id]['format'] = 'sbs';
235
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 236
 		}
237 237
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
238
-            } else {
238
+			} else {
239 239
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
240
-    	    }
241
-        }
242
-    }
240
+			}
241
+		}
242
+	}
243 243
 }
244 244
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
245 245
 
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	die;
267 267
 }
268 268
 foreach ($globalSources as $key => $source) {
269
-    if (!isset($source['format'])) {
270
-        $globalSources[$key]['format'] = 'auto';
271
-    }
269
+	if (!isset($source['format'])) {
270
+		$globalSources[$key]['format'] = 'auto';
271
+	}
272 272
 }
273 273
 connect_all($globalSources);
274 274
 foreach ($globalSources as $key => $source) {
275
-    if (isset($source['format']) && $source['format'] == 'aprs') {
275
+	if (isset($source['format']) && $source['format'] == 'aprs') {
276 276
 	$aprs_connect = 0;
277 277
 	$use_aprs = true;
278 278
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
279 279
 	break;
280
-    }
280
+	}
281 281
 }
282 282
 
283 283
 if ($use_aprs) {
@@ -316,70 +316,70 @@  discard block
 block discarded – undo
316 316
 
317 317
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
318 318
 while ($i > 0) {
319
-    if (!$globalDaemon) $i = $endtime-time();
320
-    // Delete old ATC
321
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
319
+	if (!$globalDaemon) $i = $endtime-time();
320
+	// Delete old ATC
321
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
322 322
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
323
-        $ATC->deleteOldATC();
324
-    }
323
+		$ATC->deleteOldATC();
324
+	}
325 325
     
326
-    if (count($last_exec) > 0) {
326
+	if (count($last_exec) > 0) {
327 327
 	$max = $globalMinFetch;
328 328
 	foreach ($last_exec as $last) {
329
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
329
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
330 330
 	}
331 331
 	if ($max != $globalMinFetch) {
332
-	    if ($globalDebug) echo 'Sleeping...'."\n";
333
-	    sleep($globalMinFetch-$max+2);
332
+		if ($globalDebug) echo 'Sleeping...'."\n";
333
+		sleep($globalMinFetch-$max+2);
334
+	}
334 335
 	}
335
-    }
336 336
 
337 337
     
338
-    //foreach ($formats as $id => $value) {
339
-    foreach ($globalSources as $id => $value) {
338
+	//foreach ($formats as $id => $value) {
339
+	foreach ($globalSources as $id => $value) {
340 340
 	date_default_timezone_set('UTC');
341 341
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
342 342
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
343
-	    //$buffer = $Common->getData($hosts[$id]);
344
-	    $buffer = $Common->getData($value['host']);
345
-	    if ($buffer != '') $reset = 0;
346
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
-	    $buffer = explode('\n',$buffer);
348
-	    foreach ($buffer as $line) {
349
-    		if ($line != '' && count($line) > 7) {
350
-    		    $line = explode(',', $line);
351
-	            $data = array();
352
-	            $data['hex'] = $line[1]; // hex
353
-	            $data['ident'] = $line[2]; // ident
354
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
-	            $data['verticalrate'] = ''; // vertical rate
360
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
-	            $data['emergency'] = ''; // emergency
362
-		    $data['datetime'] = date('Y-m-d H:i:s');
363
-		    $data['format_source'] = 'deltadbtxt';
364
-    		    $data['id_source'] = $id_source;
365
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
-    		    $SI->add($data);
368
-		    unset($data);
369
-    		}
370
-    	    }
371
-    	    $last_exec[$id]['last'] = time();
343
+		//$buffer = $Common->getData($hosts[$id]);
344
+		$buffer = $Common->getData($value['host']);
345
+		if ($buffer != '') $reset = 0;
346
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
+		$buffer = explode('\n',$buffer);
348
+		foreach ($buffer as $line) {
349
+			if ($line != '' && count($line) > 7) {
350
+				$line = explode(',', $line);
351
+				$data = array();
352
+				$data['hex'] = $line[1]; // hex
353
+				$data['ident'] = $line[2]; // ident
354
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
+				$data['verticalrate'] = ''; // vertical rate
360
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
+				$data['emergency'] = ''; // emergency
362
+			$data['datetime'] = date('Y-m-d H:i:s');
363
+			$data['format_source'] = 'deltadbtxt';
364
+				$data['id_source'] = $id_source;
365
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
+				$SI->add($data);
368
+			unset($data);
369
+			}
370
+			}
371
+			$last_exec[$id]['last'] = time();
372 372
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
373 373
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
374
-	    //$buffer = $Common->getData($hosts[$id]);
375
-	    $buffer = $Common->getData($value['host']);
376
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
-	    $buffer = explode('\n',$buffer);
378
-	    $reset = 0;
379
-	    foreach ($buffer as $line) {
380
-    		if ($line != '') {
381
-    		    $line = explode(':', $line);
382
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
374
+		//$buffer = $Common->getData($hosts[$id]);
375
+		$buffer = $Common->getData($value['host']);
376
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
+		$buffer = explode('\n',$buffer);
378
+		$reset = 0;
379
+		foreach ($buffer as $line) {
380
+			if ($line != '') {
381
+				$line = explode(':', $line);
382
+				if (count($line) > 30 && $line[0] != 'callsign') {
383 383
 			$data = array();
384 384
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
385 385
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -392,36 +392,36 @@  discard block
 block discarded – undo
392 392
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
393 393
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
394 394
 			$data['latitude'] = $line[5]; // lat
395
-	        	$data['longitude'] = $line[6]; // long
396
-	        	$data['verticalrate'] = ''; // vertical rate
397
-	        	$data['squawk'] = ''; // squawk
398
-	        	$data['emergency'] = ''; // emergency
399
-	        	$data['waypoints'] = $line[30];
395
+				$data['longitude'] = $line[6]; // long
396
+				$data['verticalrate'] = ''; // vertical rate
397
+				$data['squawk'] = ''; // squawk
398
+				$data['emergency'] = ''; // emergency
399
+				$data['waypoints'] = $line[30];
400 400
 			$data['datetime'] = date('Y-m-d H:i:s');
401 401
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
402 402
 			//if (isset($line[37])) $data['last_update'] = $line[37];
403
-		        $data['departure_airport_icao'] = $line[11];
404
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
-		        $data['arrival_airport_icao'] = $line[13];
403
+				$data['departure_airport_icao'] = $line[11];
404
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
+				$data['arrival_airport_icao'] = $line[13];
406 406
 			$data['frequency'] = $line[4];
407 407
 			$data['type'] = $line[18];
408 408
 			$data['range'] = $line[19];
409 409
 			if (isset($line[35])) $data['info'] = $line[35];
410
-    			$data['id_source'] = $id_source;
411
-	    		//$data['arrival_airport_time'] = ;
412
-	    		if ($line[9] != '') {
413
-	    		    $aircraft_data = explode('/',$line[9]);
414
-	    		    if (isset($aircraft_data[1])) {
415
-	    			$data['aircraft_icao'] = $aircraft_data[1];
416
-	    		    }
417
-        		}
418
-	    		/*
410
+				$data['id_source'] = $id_source;
411
+				//$data['arrival_airport_time'] = ;
412
+				if ($line[9] != '') {
413
+					$aircraft_data = explode('/',$line[9]);
414
+					if (isset($aircraft_data[1])) {
415
+					$data['aircraft_icao'] = $aircraft_data[1];
416
+					}
417
+				}
418
+				/*
419 419
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
420 420
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
421 421
 	    		*/
422
-	    		$data['format_source'] = $value['format'];
422
+				$data['format_source'] = $value['format'];
423 423
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
424
-    			if ($line[3] == 'PILOT') $SI->add($data);
424
+				if ($line[3] == 'PILOT') $SI->add($data);
425 425
 			elseif ($line[3] == 'ATC') {
426 426
 				//print_r($data);
427 427
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -439,247 +439,247 @@  discard block
 block discarded – undo
439 439
 				if (!isset($data['source_name'])) $data['source_name'] = '';
440 440
 				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']);
441 441
 			}
442
-    			unset($data);
443
-    		    }
444
-    		}
445
-    	    }
446
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
447
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
448
-    	    $last_exec[$id]['last'] = time();
449
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
450
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
451
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
452
-	    if ($buffer != '') {
453
-	    $all_data = json_decode($buffer,true);
454
-	    if (isset($all_data['acList'])) {
442
+				unset($data);
443
+				}
444
+			}
445
+			}
446
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
447
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
448
+			$last_exec[$id]['last'] = time();
449
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
450
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
451
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
452
+		if ($buffer != '') {
453
+		$all_data = json_decode($buffer,true);
454
+		if (isset($all_data['acList'])) {
455 455
 		$reset = 0;
456 456
 		foreach ($all_data['acList'] as $line) {
457
-		    $data = array();
458
-		    $data['hex'] = $line['Icao']; // hex
459
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
460
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
461
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
462
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
463
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
464
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
465
-		    //$data['verticalrate'] = $line['']; // verticale rate
466
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
467
-		    $data['emergency'] = ''; // emergency
468
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
469
-		    /*
457
+			$data = array();
458
+			$data['hex'] = $line['Icao']; // hex
459
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
460
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
461
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
462
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
463
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
464
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
465
+			//$data['verticalrate'] = $line['']; // verticale rate
466
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
467
+			$data['emergency'] = ''; // emergency
468
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
469
+			/*
470 470
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
471 471
 		    else $data['datetime'] = date('Y-m-d H:i:s');
472 472
 		    */
473
-		    $data['datetime'] = date('Y-m-d H:i:s');
474
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
475
-	    	    $data['format_source'] = 'aircraftlistjson';
476
-		    $data['id_source'] = $id_source;
477
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
-		    if (isset($data['datetime'])) $SI->add($data);
479
-		    unset($data);
473
+			$data['datetime'] = date('Y-m-d H:i:s');
474
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
475
+				$data['format_source'] = 'aircraftlistjson';
476
+			$data['id_source'] = $id_source;
477
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
+			if (isset($data['datetime'])) $SI->add($data);
479
+			unset($data);
480 480
 		}
481
-	    } else {
481
+		} else {
482 482
 		$reset = 0;
483 483
 		foreach ($all_data as $line) {
484
-		    $data = array();
485
-		    $data['hex'] = $line['hex']; // hex
486
-		    $data['ident'] = $line['flight']; // ident
487
-		    $data['altitude'] = $line['altitude']; // altitude
488
-		    $data['speed'] = $line['speed']; // speed
489
-		    $data['heading'] = $line['track']; // heading
490
-		    $data['latitude'] = $line['lat']; // lat
491
-		    $data['longitude'] = $line['lon']; // long
492
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
493
-		    $data['squawk'] = $line['squawk']; // squawk
494
-		    $data['emergency'] = ''; // emergency
495
-		    $data['datetime'] = date('Y-m-d H:i:s');
496
-	    	    $data['format_source'] = 'aircraftlistjson';
497
-    		    $data['id_source'] = $id_source;
498
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
499
-		    $SI->add($data);
500
-		    unset($data);
484
+			$data = array();
485
+			$data['hex'] = $line['hex']; // hex
486
+			$data['ident'] = $line['flight']; // ident
487
+			$data['altitude'] = $line['altitude']; // altitude
488
+			$data['speed'] = $line['speed']; // speed
489
+			$data['heading'] = $line['track']; // heading
490
+			$data['latitude'] = $line['lat']; // lat
491
+			$data['longitude'] = $line['lon']; // long
492
+			$data['verticalrate'] = $line['vrt']; // verticale rate
493
+			$data['squawk'] = $line['squawk']; // squawk
494
+			$data['emergency'] = ''; // emergency
495
+			$data['datetime'] = date('Y-m-d H:i:s');
496
+				$data['format_source'] = 'aircraftlistjson';
497
+				$data['id_source'] = $id_source;
498
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
499
+			$SI->add($data);
500
+			unset($data);
501
+		}
501 502
 		}
502
-	    }
503
-	    }
504
-    	    //$last_exec['aircraftlistjson'] = time();
505
-    	    $last_exec[$id]['last'] = time();
506
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
507
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
508
-	    $buffer = $Common->getData($value['host']);
509
-	    $all_data = json_decode($buffer,true);
510
-	    if (isset($all_data['planes'])) {
503
+		}
504
+			//$last_exec['aircraftlistjson'] = time();
505
+			$last_exec[$id]['last'] = time();
506
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
507
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
508
+		$buffer = $Common->getData($value['host']);
509
+		$all_data = json_decode($buffer,true);
510
+		if (isset($all_data['planes'])) {
511 511
 		$reset = 0;
512 512
 		foreach ($all_data['planes'] as $key => $line) {
513
-		    $data = array();
514
-		    $data['hex'] = $key; // hex
515
-		    $data['ident'] = $line[3]; // ident
516
-		    $data['altitude'] = $line[6]; // altitude
517
-		    $data['speed'] = $line[8]; // speed
518
-		    $data['heading'] = $line[7]; // heading
519
-		    $data['latitude'] = $line[4]; // lat
520
-		    $data['longitude'] = $line[5]; // long
521
-		    //$data['verticalrate'] = $line[]; // verticale rate
522
-		    $data['squawk'] = $line[10]; // squawk
523
-		    $data['emergency'] = ''; // emergency
524
-		    $data['registration'] = $line[2];
525
-		    $data['aircraft_icao'] = $line[0];
526
-		    $deparr = explode('-',$line[1]);
527
-		    if (count($deparr) == 2) {
513
+			$data = array();
514
+			$data['hex'] = $key; // hex
515
+			$data['ident'] = $line[3]; // ident
516
+			$data['altitude'] = $line[6]; // altitude
517
+			$data['speed'] = $line[8]; // speed
518
+			$data['heading'] = $line[7]; // heading
519
+			$data['latitude'] = $line[4]; // lat
520
+			$data['longitude'] = $line[5]; // long
521
+			//$data['verticalrate'] = $line[]; // verticale rate
522
+			$data['squawk'] = $line[10]; // squawk
523
+			$data['emergency'] = ''; // emergency
524
+			$data['registration'] = $line[2];
525
+			$data['aircraft_icao'] = $line[0];
526
+			$deparr = explode('-',$line[1]);
527
+			if (count($deparr) == 2) {
528 528
 			$data['departure_airport_icao'] = $deparr[0];
529 529
 			$data['arrival_airport_icao'] = $deparr[1];
530
-		    }
531
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
-	    	    $data['format_source'] = 'planeupdatefaa';
533
-    		    $data['id_source'] = $id_source;
534
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
535
-		    $SI->add($data);
536
-		    unset($data);
530
+			}
531
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
+				$data['format_source'] = 'planeupdatefaa';
533
+				$data['id_source'] = $id_source;
534
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
535
+			$SI->add($data);
536
+			unset($data);
537
+		}
537 538
 		}
538
-	    }
539
-    	    //$last_exec['planeupdatefaa'] = time();
540
-    	    $last_exec[$id]['last'] = time();
541
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
542
-	    $buffer = $Common->getData($value['host']);
543
-	    $all_data = json_decode($buffer,true);
544
-	    if (isset($all_data['states'])) {
539
+			//$last_exec['planeupdatefaa'] = time();
540
+			$last_exec[$id]['last'] = time();
541
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
542
+		$buffer = $Common->getData($value['host']);
543
+		$all_data = json_decode($buffer,true);
544
+		if (isset($all_data['states'])) {
545 545
 		$reset = 0;
546 546
 		foreach ($all_data['states'] as $key => $line) {
547
-		    $data = array();
548
-		    $data['hex'] = $line[0]; // hex
549
-		    $data['ident'] = trim($line[1]); // ident
550
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
551
-		    $data['speed'] = round($line[9]*1.94384); // speed
552
-		    $data['heading'] = round($line[10]); // heading
553
-		    $data['latitude'] = $line[5]; // lat
554
-		    $data['longitude'] = $line[6]; // long
555
-		    $data['verticalrate'] = $line[11]; // verticale rate
556
-		    //$data['squawk'] = $line[10]; // squawk
557
-		    //$data['emergency'] = ''; // emergency
558
-		    //$data['registration'] = $line[2];
559
-		    //$data['aircraft_icao'] = $line[0];
560
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
-	    	    $data['format_source'] = 'opensky';
562
-    		    $data['id_source'] = $id_source;
563
-		    $SI->add($data);
564
-		    unset($data);
547
+			$data = array();
548
+			$data['hex'] = $line[0]; // hex
549
+			$data['ident'] = trim($line[1]); // ident
550
+			$data['altitude'] = round($line[7]*3.28084); // altitude
551
+			$data['speed'] = round($line[9]*1.94384); // speed
552
+			$data['heading'] = round($line[10]); // heading
553
+			$data['latitude'] = $line[5]; // lat
554
+			$data['longitude'] = $line[6]; // long
555
+			$data['verticalrate'] = $line[11]; // verticale rate
556
+			//$data['squawk'] = $line[10]; // squawk
557
+			//$data['emergency'] = ''; // emergency
558
+			//$data['registration'] = $line[2];
559
+			//$data['aircraft_icao'] = $line[0];
560
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
+				$data['format_source'] = 'opensky';
562
+				$data['id_source'] = $id_source;
563
+			$SI->add($data);
564
+			unset($data);
565
+		}
565 566
 		}
566
-	    }
567
-    	    //$last_exec['planeupdatefaa'] = time();
568
-    	    $last_exec[$id]['last'] = time();
569
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
570
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
571
-	    //$buffer = $Common->getData($hosts[$id]);
572
-	    $buffer = $Common->getData($value['host']);
573
-	    $all_data = json_decode($buffer,true);
574
-	    if (!empty($all_data)) $reset = 0;
575
-	    foreach ($all_data as $key => $line) {
567
+			//$last_exec['planeupdatefaa'] = time();
568
+			$last_exec[$id]['last'] = time();
569
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
570
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
571
+		//$buffer = $Common->getData($hosts[$id]);
572
+		$buffer = $Common->getData($value['host']);
573
+		$all_data = json_decode($buffer,true);
574
+		if (!empty($all_data)) $reset = 0;
575
+		foreach ($all_data as $key => $line) {
576 576
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
577
-		    $data = array();
578
-		    $data['hex'] = $line[0];
579
-		    $data['ident'] = $line[16]; //$line[13]
580
-	    	    $data['altitude'] = $line[4]; // altitude
581
-	    	    $data['speed'] = $line[5]; // speed
582
-	    	    $data['heading'] = $line[3]; // heading
583
-	    	    $data['latitude'] = $line[1]; // lat
584
-	    	    $data['longitude'] = $line[2]; // long
585
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
586
-	    	    $data['squawk'] = $line[6]; // squawk
587
-	    	    $data['aircraft_icao'] = $line[8];
588
-	    	    $data['registration'] = $line[9];
589
-		    $data['departure_airport_iata'] = $line[11];
590
-		    $data['arrival_airport_iata'] = $line[12];
591
-	    	    $data['emergency'] = ''; // emergency
592
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
593
-	    	    $data['format_source'] = 'fr24json';
594
-    		    $data['id_source'] = $id_source;
595
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
596
-		    $SI->add($data);
597
-		    unset($data);
577
+			$data = array();
578
+			$data['hex'] = $line[0];
579
+			$data['ident'] = $line[16]; //$line[13]
580
+				$data['altitude'] = $line[4]; // altitude
581
+				$data['speed'] = $line[5]; // speed
582
+				$data['heading'] = $line[3]; // heading
583
+				$data['latitude'] = $line[1]; // lat
584
+				$data['longitude'] = $line[2]; // long
585
+				$data['verticalrate'] = $line[15]; // verticale rate
586
+				$data['squawk'] = $line[6]; // squawk
587
+				$data['aircraft_icao'] = $line[8];
588
+				$data['registration'] = $line[9];
589
+			$data['departure_airport_iata'] = $line[11];
590
+			$data['arrival_airport_iata'] = $line[12];
591
+				$data['emergency'] = ''; // emergency
592
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
593
+				$data['format_source'] = 'fr24json';
594
+				$data['id_source'] = $id_source;
595
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
596
+			$SI->add($data);
597
+			unset($data);
598
+		}
598 599
 		}
599
-	    }
600
-    	    //$last_exec['fr24json'] = time();
601
-    	    $last_exec[$id]['last'] = time();
602
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
603
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
604
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
605
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
606
-	    //echo $buffer;
607
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
608
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
609
-	    $all_data = json_decode($buffer,true);
610
-	    if (json_last_error() != JSON_ERROR_NONE) {
600
+			//$last_exec['fr24json'] = time();
601
+			$last_exec[$id]['last'] = time();
602
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
603
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
604
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
605
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
606
+		//echo $buffer;
607
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
608
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
609
+		$all_data = json_decode($buffer,true);
610
+		if (json_last_error() != JSON_ERROR_NONE) {
611 611
 		die(json_last_error_msg());
612
-	    }
613
-	    if (isset($all_data['mrkrs'])) {
612
+		}
613
+		if (isset($all_data['mrkrs'])) {
614 614
 		$reset = 0;
615 615
 		foreach ($all_data['mrkrs'] as $key => $line) {
616
-		    if (isset($line['inf'])) {
616
+			if (isset($line['inf'])) {
617 617
 			$data = array();
618 618
 			$data['hex'] = $line['inf']['ia'];
619 619
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
620
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
621
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
622
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
623
-	    		$data['latitude'] = $line['pt'][0]; // lat
624
-	    		$data['longitude'] = $line['pt'][1]; // long
625
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
626
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
627
-	    		//$data['aircraft_icao'] = $line[8];
628
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
620
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
621
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
622
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
623
+				$data['latitude'] = $line['pt'][0]; // lat
624
+				$data['longitude'] = $line['pt'][1]; // long
625
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
626
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
627
+				//$data['aircraft_icao'] = $line[8];
628
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
629 629
 			//$data['departure_airport_iata'] = $line[11];
630 630
 			//$data['arrival_airport_iata'] = $line[12];
631
-	    		//$data['emergency'] = ''; // emergency
631
+				//$data['emergency'] = ''; // emergency
632 632
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
633
-	    		$data['format_source'] = 'radarvirtueljson';
634
-    			$data['id_source'] = $id_source;
633
+				$data['format_source'] = 'radarvirtueljson';
634
+				$data['id_source'] = $id_source;
635 635
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
636 636
 			$SI->add($data);
637 637
 			unset($data);
638
-		    }
638
+			}
639
+		}
639 640
 		}
640
-	    }
641
-    	    //$last_exec['radarvirtueljson'] = time();
642
-    	    $last_exec[$id]['last'] = time();
643
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
644
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
645
-	    //$buffer = $Common->getData($hosts[$id]);
646
-	    $buffer = $Common->getData($value['host'].'?'.time());
647
-	    $all_data = json_decode(utf8_encode($buffer),true);
641
+			//$last_exec['radarvirtueljson'] = time();
642
+			$last_exec[$id]['last'] = time();
643
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
644
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
645
+		//$buffer = $Common->getData($hosts[$id]);
646
+		$buffer = $Common->getData($value['host'].'?'.time());
647
+		$all_data = json_decode(utf8_encode($buffer),true);
648 648
 	    
649
-	    if (isset($all_data['pireps'])) {
649
+		if (isset($all_data['pireps'])) {
650 650
 		$reset = 0;
651
-	        foreach ($all_data['pireps'] as $line) {
652
-		    $data = array();
653
-		    $data['id'] = $line['id'];
654
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
-		    $data['ident'] = $line['callsign']; // ident
656
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
657
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
658
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
659
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
660
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
661
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
662
-		    $data['latitude'] = $line['lat']; // lat
663
-		    $data['longitude'] = $line['lon']; // long
664
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
665
-		    //$data['squawk'] = $line['squawk']; // squawk
666
-		    //$data['emergency'] = ''; // emergency
667
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
668
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
669
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
670
-		    //$data['arrival_airport_time'] = $line['arrtime'];
671
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
672
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
673
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
674
-		    else $data['info'] = '';
675
-		    $data['format_source'] = 'pireps';
676
-    		    $data['id_source'] = $id_source;
677
-		    $data['datetime'] = date('Y-m-d H:i:s');
678
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
-		    if ($line['icon'] == 'plane') {
651
+			foreach ($all_data['pireps'] as $line) {
652
+			$data = array();
653
+			$data['id'] = $line['id'];
654
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
+			$data['ident'] = $line['callsign']; // ident
656
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
657
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
658
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
659
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
660
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
661
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
662
+			$data['latitude'] = $line['lat']; // lat
663
+			$data['longitude'] = $line['lon']; // long
664
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
665
+			//$data['squawk'] = $line['squawk']; // squawk
666
+			//$data['emergency'] = ''; // emergency
667
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
668
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
669
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
670
+			//$data['arrival_airport_time'] = $line['arrtime'];
671
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
672
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
673
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
674
+			else $data['info'] = '';
675
+			$data['format_source'] = 'pireps';
676
+				$data['id_source'] = $id_source;
677
+			$data['datetime'] = date('Y-m-d H:i:s');
678
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
+			if ($line['icon'] == 'plane') {
680 680
 			$SI->add($data);
681
-		    //    print_r($data);
682
-    		    } elseif ($line['icon'] == 'ct') {
681
+			//    print_r($data);
682
+				} elseif ($line['icon'] == 'ct') {
683 683
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
684 684
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
685 685
 			$typec = substr($data['ident'],-3);
@@ -694,163 +694,163 @@  discard block
 block discarded – undo
694 694
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
695 695
 			else $data['type'] = 'Observer';
696 696
 			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']);
697
-		    }
698
-		    unset($data);
697
+			}
698
+			unset($data);
699
+		}
699 700
 		}
700
-	    }
701
-    	    //$last_exec['pirepsjson'] = time();
702
-    	    $last_exec[$id]['last'] = time();
703
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
704
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
-	    //$buffer = $Common->getData($hosts[$id]);
706
-	    if ($globalDebug) echo 'Get Data...'."\n";
707
-	    $buffer = $Common->getData($value['host']);
708
-	    $all_data = json_decode($buffer,true);
709
-	    if ($buffer != '' && is_array($all_data)) {
701
+			//$last_exec['pirepsjson'] = time();
702
+			$last_exec[$id]['last'] = time();
703
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
704
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
+		//$buffer = $Common->getData($hosts[$id]);
706
+		if ($globalDebug) echo 'Get Data...'."\n";
707
+		$buffer = $Common->getData($value['host']);
708
+		$all_data = json_decode($buffer,true);
709
+		if ($buffer != '' && is_array($all_data)) {
710 710
 		$reset = 0;
711 711
 		foreach ($all_data as $line) {
712
-	    	    $data = array();
713
-	    	    //$data['id'] = $line['id']; // id not usable
714
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
715
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
717
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
718
-	    	    $data['ident'] = $line['flightnum']; // ident
719
-	    	    $data['altitude'] = $line['alt']; // altitude
720
-	    	    $data['speed'] = $line['gs']; // speed
721
-	    	    $data['heading'] = $line['heading']; // heading
722
-	    	    $data['latitude'] = $line['lat']; // lat
723
-	    	    $data['longitude'] = $line['lng']; // long
724
-	    	    $data['verticalrate'] = ''; // verticale rate
725
-	    	    $data['squawk'] = ''; // squawk
726
-	    	    $data['emergency'] = ''; // emergency
727
-	    	    //$data['datetime'] = $line['lastupdate'];
728
-	    	    $data['last_update'] = $line['lastupdate'];
729
-		    $data['datetime'] = date('Y-m-d H:i:s');
730
-	    	    $data['departure_airport_icao'] = $line['depicao'];
731
-	    	    $data['departure_airport_time'] = $line['deptime'];
732
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
733
-    		    $data['arrival_airport_time'] = $line['arrtime'];
734
-    		    $data['registration'] = $line['aircraft'];
735
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
736
-		    if (isset($line['aircraftname'])) {
712
+				$data = array();
713
+				//$data['id'] = $line['id']; // id not usable
714
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
715
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
717
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
718
+				$data['ident'] = $line['flightnum']; // ident
719
+				$data['altitude'] = $line['alt']; // altitude
720
+				$data['speed'] = $line['gs']; // speed
721
+				$data['heading'] = $line['heading']; // heading
722
+				$data['latitude'] = $line['lat']; // lat
723
+				$data['longitude'] = $line['lng']; // long
724
+				$data['verticalrate'] = ''; // verticale rate
725
+				$data['squawk'] = ''; // squawk
726
+				$data['emergency'] = ''; // emergency
727
+				//$data['datetime'] = $line['lastupdate'];
728
+				$data['last_update'] = $line['lastupdate'];
729
+			$data['datetime'] = date('Y-m-d H:i:s');
730
+				$data['departure_airport_icao'] = $line['depicao'];
731
+				$data['departure_airport_time'] = $line['deptime'];
732
+				$data['arrival_airport_icao'] = $line['arricao'];
733
+				$data['arrival_airport_time'] = $line['arrtime'];
734
+				$data['registration'] = $line['aircraft'];
735
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
736
+			if (isset($line['aircraftname'])) {
737 737
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
738 738
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
739
-	    		$aircraft_data = explode('-',$line['aircraftname']);
740
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
741
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
742
-	    		else {
743
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
744
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
745
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
746
-	    		}
747
-	    	    }
748
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
749
-    		    $data['id_source'] = $id_source;
750
-	    	    $data['format_source'] = 'phpvmacars';
751
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
752
-		    $SI->add($data);
753
-		    unset($data);
739
+				$aircraft_data = explode('-',$line['aircraftname']);
740
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
741
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
742
+				else {
743
+					$aircraft_data = explode(' ',$line['aircraftname']);
744
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
745
+					else $data['aircraft_icao'] = $line['aircraftname'];
746
+				}
747
+				}
748
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
749
+				$data['id_source'] = $id_source;
750
+				$data['format_source'] = 'phpvmacars';
751
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
752
+			$SI->add($data);
753
+			unset($data);
754 754
 		}
755 755
 		if ($globalDebug) echo 'No more data...'."\n";
756 756
 		unset($buffer);
757 757
 		unset($all_data);
758
-	    }
759
-    	    //$last_exec['phpvmacars'] = time();
760
-    	    $last_exec[$id]['last'] = time();
761
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
762
-	    //$buffer = $Common->getData($hosts[$id]);
763
-	    if ($globalDebug) echo 'Get Data...'."\n";
764
-	    $buffer = $Common->getData($value['host']);
765
-	    $all_data = json_decode($buffer,true);
766
-	    if ($buffer != '' && is_array($all_data)) {
758
+		}
759
+			//$last_exec['phpvmacars'] = time();
760
+			$last_exec[$id]['last'] = time();
761
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
762
+		//$buffer = $Common->getData($hosts[$id]);
763
+		if ($globalDebug) echo 'Get Data...'."\n";
764
+		$buffer = $Common->getData($value['host']);
765
+		$all_data = json_decode($buffer,true);
766
+		if ($buffer != '' && is_array($all_data)) {
767 767
 		$reset = 0;
768 768
 		foreach ($all_data as $line) {
769
-	    	    $data = array();
770
-	    	    //$data['id'] = $line['id']; // id not usable
771
-	    	    $data['id'] = trim($line['flight_id']);
772
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
-	    	    $data['pilot_name'] = $line['pilot_name'];
774
-	    	    $data['pilot_id'] = $line['pilot_id'];
775
-	    	    $data['ident'] = trim($line['callsign']); // ident
776
-	    	    $data['altitude'] = $line['altitude']; // altitude
777
-	    	    $data['speed'] = $line['gs']; // speed
778
-	    	    $data['heading'] = $line['heading']; // heading
779
-	    	    $data['latitude'] = $line['latitude']; // lat
780
-	    	    $data['longitude'] = $line['longitude']; // long
781
-	    	    $data['verticalrate'] = ''; // verticale rate
782
-	    	    $data['squawk'] = ''; // squawk
783
-	    	    $data['emergency'] = ''; // emergency
784
-	    	    //$data['datetime'] = $line['lastupdate'];
785
-	    	    $data['last_update'] = $line['last_update'];
786
-		    $data['datetime'] = date('Y-m-d H:i:s');
787
-	    	    $data['departure_airport_icao'] = $line['departure'];
788
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
789
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
790
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
791
-    		    //$data['registration'] = $line['aircraft'];
792
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
793
-	    	    $data['aircraft_icao'] = $line['plane_type'];
794
-    		    $data['id_source'] = $id_source;
795
-	    	    $data['format_source'] = 'vam';
796
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
797
-		    $SI->add($data);
798
-		    unset($data);
769
+				$data = array();
770
+				//$data['id'] = $line['id']; // id not usable
771
+				$data['id'] = trim($line['flight_id']);
772
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
+				$data['pilot_name'] = $line['pilot_name'];
774
+				$data['pilot_id'] = $line['pilot_id'];
775
+				$data['ident'] = trim($line['callsign']); // ident
776
+				$data['altitude'] = $line['altitude']; // altitude
777
+				$data['speed'] = $line['gs']; // speed
778
+				$data['heading'] = $line['heading']; // heading
779
+				$data['latitude'] = $line['latitude']; // lat
780
+				$data['longitude'] = $line['longitude']; // long
781
+				$data['verticalrate'] = ''; // verticale rate
782
+				$data['squawk'] = ''; // squawk
783
+				$data['emergency'] = ''; // emergency
784
+				//$data['datetime'] = $line['lastupdate'];
785
+				$data['last_update'] = $line['last_update'];
786
+			$data['datetime'] = date('Y-m-d H:i:s');
787
+				$data['departure_airport_icao'] = $line['departure'];
788
+				//$data['departure_airport_time'] = $line['departure_time'];
789
+				$data['arrival_airport_icao'] = $line['arrival'];
790
+				//$data['arrival_airport_time'] = $line['arrival_time'];
791
+				//$data['registration'] = $line['aircraft'];
792
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
793
+				$data['aircraft_icao'] = $line['plane_type'];
794
+				$data['id_source'] = $id_source;
795
+				$data['format_source'] = 'vam';
796
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
797
+			$SI->add($data);
798
+			unset($data);
799 799
 		}
800 800
 		if ($globalDebug) echo 'No more data...'."\n";
801 801
 		unset($buffer);
802 802
 		unset($all_data);
803
-	    }
804
-    	    //$last_exec['phpvmacars'] = time();
805
-    	    $last_exec[$id]['last'] = time();
803
+		}
804
+			//$last_exec['phpvmacars'] = time();
805
+			$last_exec[$id]['last'] = time();
806 806
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
807 807
 	} 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') {
808
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
809
-    	    //$last_exec[$id]['last'] = time();
808
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
809
+			//$last_exec[$id]['last'] = time();
810 810
 
811
-	    //$read = array( $sockets[$id] );
812
-	    $read = $sockets;
813
-	    $write = NULL;
814
-	    $e = NULL;
815
-	    $n = socket_select($read, $write, $e, $timeout);
816
-	    if ($e != NULL) var_dump($e);
817
-	    if ($n > 0) {
811
+		//$read = array( $sockets[$id] );
812
+		$read = $sockets;
813
+		$write = NULL;
814
+		$e = NULL;
815
+		$n = socket_select($read, $write, $e, $timeout);
816
+		if ($e != NULL) var_dump($e);
817
+		if ($n > 0) {
818 818
 		$reset = 0;
819 819
 		foreach ($read as $nb => $r) {
820
-		    //$value = $formats[$nb];
821
-		    $format = $globalSources[$nb]['format'];
822
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
823
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
-        	    } else {
825
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
-	    	    }
827
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
828
-        	    //echo $buffer."\n";
829
-		    // lets play nice and handle signals such as ctrl-c/kill properly
830
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
831
-		    $error = false;
832
-		    //$SI::del();
833
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
-		    // SBS format is CSV format
835
-		    if ($buffer != '') {
820
+			//$value = $formats[$nb];
821
+			$format = $globalSources[$nb]['format'];
822
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
823
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
+				} else {
825
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
+				}
827
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
828
+				//echo $buffer."\n";
829
+			// lets play nice and handle signals such as ctrl-c/kill properly
830
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
831
+			$error = false;
832
+			//$SI::del();
833
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
+			// SBS format is CSV format
835
+			if ($buffer != '') {
836 836
 			$tt[$format] = 0;
837 837
 			if ($format == 'acarssbs3') {
838
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
839
-			    $ACARS->add(trim($buffer));
840
-			    $ACARS->deleteLiveAcarsData();
838
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
839
+				$ACARS->add(trim($buffer));
840
+				$ACARS->deleteLiveAcarsData();
841 841
 			} elseif ($format == 'raw') {
842
-			    // AVR format
843
-			    $data = $SBS->parse($buffer);
844
-			    if (is_array($data)) {
842
+				// AVR format
843
+				$data = $SBS->parse($buffer);
844
+				if (is_array($data)) {
845 845
 				$data['datetime'] = date('Y-m-d H:i:s');
846 846
 				$data['format_source'] = 'raw';
847 847
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
848
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
850
-                            }
851
-                        } elseif ($format == 'flightgearsp') {
852
-                    	    //echo $buffer."\n";
853
-                    	    if (strlen($buffer) > 5) {
848
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
850
+							}
851
+						} elseif ($format == 'flightgearsp') {
852
+							//echo $buffer."\n";
853
+							if (strlen($buffer) > 5) {
854 854
 				$line = explode(',',$buffer);
855 855
 				$data = array();
856 856
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -866,122 +866,122 @@  discard block
 block discarded – undo
866 866
 				$data['format_source'] = 'flightgearsp';
867 867
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
868 868
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
869
-			    }
870
-                        } elseif ($format == 'acars') {
871
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
872
-			    $ACARS->add(trim($buffer));
873
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
-			    $ACARS->deleteLiveAcarsData();
869
+				}
870
+						} elseif ($format == 'acars') {
871
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
872
+				$ACARS->add(trim($buffer));
873
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
+				$ACARS->deleteLiveAcarsData();
875 875
 			} elseif ($format == 'flightgearmp') {
876
-			    if (substr($buffer,0,1) != '#') {
876
+				if (substr($buffer,0,1) != '#') {
877 877
 				$data = array();
878 878
 				//echo $buffer."\n";
879 879
 				$line = explode(' ',$buffer);
880 880
 				if (count($line) == 11) {
881
-				    $userserver = explode('@',$line[0]);
882
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
883
-				    $data['ident'] = $userserver[0];
884
-				    $data['registration'] = $userserver[0];
885
-				    $data['latitude'] = $line[4];
886
-				    $data['longitude'] = $line[5];
887
-				    $data['altitude'] = $line[6];
888
-				    $data['datetime'] = date('Y-m-d H:i:s');
889
-				    $aircraft_type = $line[10];
890
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
891
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
892
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
881
+					$userserver = explode('@',$line[0]);
882
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
883
+					$data['ident'] = $userserver[0];
884
+					$data['registration'] = $userserver[0];
885
+					$data['latitude'] = $line[4];
886
+					$data['longitude'] = $line[5];
887
+					$data['altitude'] = $line[6];
888
+					$data['datetime'] = date('Y-m-d H:i:s');
889
+					$aircraft_type = $line[10];
890
+					$aircraft_type = preg_split(':/:',$aircraft_type);
891
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
892
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
893
+				}
893 894
 				}
894
-			    }
895 895
 			} elseif ($format == 'beast') {
896
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
897
-			    die;
896
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
897
+				die;
898 898
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
899
-			    $line = explode("\t", $buffer);
900
-			    for($k = 0; $k < count($line); $k=$k+2) {
899
+				$line = explode("\t", $buffer);
900
+				for($k = 0; $k < count($line); $k=$k+2) {
901 901
 				$key = $line[$k];
902
-			        $lined[$key] = $line[$k+1];
903
-			    }
904
-    			    if (count($lined) > 3) {
905
-    				$data['hex'] = $lined['hexid'];
906
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
907
-    				$data['datetime'] = date('Y-m-d H:i:s');;
908
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
909
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
910
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
911
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
912
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
913
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
914
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
915
-    				$data['id_source'] = $id_source;
916
-    				$data['format_source'] = 'tsv';
917
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
918
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
919
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
920
-    				unset($lined);
921
-    				unset($data);
922
-    			    } else $error = true;
902
+					$lined[$key] = $line[$k+1];
903
+				}
904
+					if (count($lined) > 3) {
905
+					$data['hex'] = $lined['hexid'];
906
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
907
+					$data['datetime'] = date('Y-m-d H:i:s');;
908
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
909
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
910
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
911
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
912
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
913
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
914
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
915
+					$data['id_source'] = $id_source;
916
+					$data['format_source'] = 'tsv';
917
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
918
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
919
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
920
+					unset($lined);
921
+					unset($data);
922
+					} else $error = true;
923 923
 			} elseif ($format == 'aprs' && $use_aprs) {
924
-			    if ($aprs_connect == 0) {
924
+				if ($aprs_connect == 0) {
925 925
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
926 926
 				$aprs_connect = 1;
927
-			    }
927
+				}
928 928
 			    
929
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
929
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
930 930
 				$aprs_last_tx = time();
931 931
 				$data_aprs = "# Keep alive";
932 932
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
933
-			    }
933
+				}
934 934
 			    
935
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
936
-			    $buffer = str_replace('APRS <- ','',$buffer);
937
-			    $buffer = str_replace('APRS -> ','',$buffer);
938
-			    //echo $buffer."\n";
939
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
935
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
936
+				$buffer = str_replace('APRS <- ','',$buffer);
937
+				$buffer = str_replace('APRS -> ','',$buffer);
938
+				//echo $buffer."\n";
939
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
940 940
 				$line = $APRS->parse($buffer);
941 941
 				//print_r($line);
942 942
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
943
-				    $aprs_last_tx = time();
944
-				    $data = array();
945
-				    //print_r($line);
946
-				    $data['hex'] = $line['address'];
947
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
948
-				    //$data['datetime'] = date('Y-m-d H:i:s');
949
-				    $data['ident'] = $line['ident'];
950
-				    $data['latitude'] = $line['latitude'];
951
-				    $data['longitude'] = $line['longitude'];
952
-				    //$data['verticalrate'] = $line[16];
953
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
954
-				    else $data['speed'] = 0;
955
-				    $data['altitude'] = $line['altitude'];
956
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
957
-				    //else $data['heading'] = 0;
958
-				    $data['aircraft_type'] = $line['stealth'];
959
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
960
-    				    $data['id_source'] = $id_source;
961
-				    $data['format_source'] = 'aprs';
962
-				    $data['source_name'] = $line['source'];
963
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
964
-				    $currentdate = date('Y-m-d H:i:s');
965
-				    $aprsdate = strtotime($data['datetime']);
966
-				    // Accept data if time <= system time + 20s
967
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
968
-				    else {
943
+					$aprs_last_tx = time();
944
+					$data = array();
945
+					//print_r($line);
946
+					$data['hex'] = $line['address'];
947
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
948
+					//$data['datetime'] = date('Y-m-d H:i:s');
949
+					$data['ident'] = $line['ident'];
950
+					$data['latitude'] = $line['latitude'];
951
+					$data['longitude'] = $line['longitude'];
952
+					//$data['verticalrate'] = $line[16];
953
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
954
+					else $data['speed'] = 0;
955
+					$data['altitude'] = $line['altitude'];
956
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
957
+					//else $data['heading'] = 0;
958
+					$data['aircraft_type'] = $line['stealth'];
959
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
960
+						$data['id_source'] = $id_source;
961
+					$data['format_source'] = 'aprs';
962
+					$data['source_name'] = $line['source'];
963
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
964
+					$currentdate = date('Y-m-d H:i:s');
965
+					$aprsdate = strtotime($data['datetime']);
966
+					// Accept data if time <= system time + 20s
967
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
968
+					else {
969 969
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
970 970
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
971
-				    }
972
-				    unset($data);
971
+					}
972
+					unset($data);
973 973
 				} 
974 974
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
975 975
 					echo '!! Weather Station not yet supported'."\n";
976 976
 				}
977 977
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
978 978
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
979
-			    }
979
+				}
980 980
 			} else {
981
-			    $line = explode(',', $buffer);
982
-    			    if (count($line) > 20) {
983
-    			    	$data['hex'] = $line[4];
984
-    				/*
981
+				$line = explode(',', $buffer);
982
+					if (count($line) > 20) {
983
+						$data['hex'] = $line[4];
984
+					/*
985 985
     				$data['datetime'] = $line[6].' '.$line[7];
986 986
     					date_default_timezone_set($globalTimezone);
987 987
     					$datetime = new DateTime($data['datetime']);
@@ -989,29 +989,29 @@  discard block
 block discarded – undo
989 989
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
990 990
     					date_default_timezone_set('UTC');
991 991
     				*/
992
-    				// Force datetime to current UTC datetime
993
-    				date_default_timezone_set('UTC');
994
-    				$data['datetime'] = date('Y-m-d H:i:s');
995
-    				$data['ident'] = trim($line[10]);
996
-    				$data['latitude'] = $line[14];
997
-    				$data['longitude'] = $line[15];
998
-    				$data['verticalrate'] = $line[16];
999
-    				$data['emergency'] = $line[20];
1000
-    				$data['speed'] = $line[12];
1001
-    				$data['squawk'] = $line[17];
1002
-    				$data['altitude'] = $line[11];
1003
-    				$data['heading'] = $line[13];
1004
-    				$data['ground'] = $line[21];
1005
-    				$data['emergency'] = $line[19];
1006
-    				$data['format_source'] = 'sbs';
992
+					// Force datetime to current UTC datetime
993
+					date_default_timezone_set('UTC');
994
+					$data['datetime'] = date('Y-m-d H:i:s');
995
+					$data['ident'] = trim($line[10]);
996
+					$data['latitude'] = $line[14];
997
+					$data['longitude'] = $line[15];
998
+					$data['verticalrate'] = $line[16];
999
+					$data['emergency'] = $line[20];
1000
+					$data['speed'] = $line[12];
1001
+					$data['squawk'] = $line[17];
1002
+					$data['altitude'] = $line[11];
1003
+					$data['heading'] = $line[13];
1004
+					$data['ground'] = $line[21];
1005
+					$data['emergency'] = $line[19];
1006
+					$data['format_source'] = 'sbs';
1007 1007
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1008
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1009
-    				$data['id_source'] = $id_source;
1010
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1011
-    				else $error = true;
1012
-    				unset($data);
1013
-    			    } else $error = true;
1014
-			    if ($error) {
1008
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1009
+					$data['id_source'] = $id_source;
1010
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1011
+					else $error = true;
1012
+					unset($data);
1013
+					} else $error = true;
1014
+				if ($error) {
1015 1015
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1016 1016
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1017 1017
 				} else {
@@ -1027,13 +1027,13 @@  discard block
 block discarded – undo
1027 1027
 					connect_all($sourceer);
1028 1028
 					$sourceer = array();
1029 1029
 				}
1030
-			    }
1030
+				}
1031 1031
 			}
1032 1032
 			// Sleep for xxx microseconds
1033 1033
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1034
-		    } else {
1034
+			} else {
1035 1035
 			if ($format == 'flightgearmp') {
1036
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1036
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1037 1037
 				//@socket_close($r);
1038 1038
 				sleep($globalMinFetch);
1039 1039
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1042,9 +1042,9 @@  discard block
 block discarded – undo
1042 1042
 				break;
1043 1043
 				
1044 1044
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1045
-			    if (isset($tt[$format])) $tt[$format]++;
1046
-			    else $tt[$format] = 0;
1047
-			    if ($tt[$format] > 30) {
1045
+				if (isset($tt[$format])) $tt[$format]++;
1046
+				else $tt[$format] = 0;
1047
+				if ($tt[$format] > 30) {
1048 1048
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1049 1049
 				//@socket_close($r);
1050 1050
 				sleep(2);
@@ -1055,23 +1055,23 @@  discard block
 block discarded – undo
1055 1055
 				//connect_all($globalSources);
1056 1056
 				$tt[$format]=0;
1057 1057
 				break;
1058
-			    }
1058
+				}
1059
+			}
1059 1060
 			}
1060
-		    }
1061 1061
 		}
1062
-	    } else {
1062
+		} else {
1063 1063
 		$error = socket_strerror(socket_last_error());
1064 1064
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1065 1065
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1066 1066
 			if (isset($globalDebug)) echo "Restarting...\n";
1067 1067
 			// Restart the script if possible
1068 1068
 			if (is_array($sockets)) {
1069
-			    if ($globalDebug) echo "Shutdown all sockets...";
1069
+				if ($globalDebug) echo "Shutdown all sockets...";
1070 1070
 			    
1071
-			    foreach ($sockets as $sock) {
1071
+				foreach ($sockets as $sock) {
1072 1072
 				@socket_shutdown($sock,2);
1073 1073
 				@socket_close($sock);
1074
-			    }
1074
+				}
1075 1075
 			    
1076 1076
 			}
1077 1077
 			if ($globalDebug) echo "Restart all connections...";
@@ -1082,13 +1082,13 @@  discard block
 block discarded – undo
1082 1082
 			if ($reset > 40) exit('Too many attempts...');
1083 1083
 			connect_all($globalSources);
1084 1084
 		}
1085
-	    }
1085
+		}
1086 1086
 	}
1087 1087
 	if ($globalDaemon === false) {
1088
-	    if ($globalDebug) echo 'Check all...'."\n";
1089
-	    $SI->checkAll();
1088
+		if ($globalDebug) echo 'Check all...'."\n";
1089
+		$SI->checkAll();
1090
+	}
1090 1091
 	}
1091
-    }
1092 1092
 }
1093 1093
 
1094 1094
 ?>
Please login to merge, or discard this patch.
Braces   +547 added lines, -189 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 
17
-if (!isset($globalDebug)) $globalDebug = FALSE;
17
+if (!isset($globalDebug)) {
18
+	$globalDebug = FALSE;
19
+}
18 20
 
19 21
 // Check if schema is at latest version
20 22
 $Connection = new Connection();
@@ -54,13 +56,22 @@  discard block
 block discarded – undo
54 56
     $globalSources = array();
55 57
     $globalSources[] = array('host' => $options['source']);
56 58
 }
57
-if (isset($options['server'])) $globalServer = TRUE;
58
-if (isset($options['idsource'])) $id_source = $options['idsource'];
59
-else $id_source = 1;
59
+if (isset($options['server'])) {
60
+	$globalServer = TRUE;
61
+}
62
+if (isset($options['idsource'])) {
63
+	$id_source = $options['idsource'];
64
+} else {
65
+	$id_source = 1;
66
+}
60 67
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
68
+    if ($globalDebug) {
69
+    	echo "Using Server Mode\n";
70
+    }
62 71
     $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
72
+} else {
73
+	$SI=new SpotterImport($Connection->db);
74
+}
64 75
 //$APRS=new APRS($Connection->db);
65 76
 $SBS=new SBS();
66 77
 $ACARS=new ACARS($Connection->db);
@@ -78,7 +89,9 @@  discard block
 block discarded – undo
78 89
 }
79 90
 
80 91
 // let's try and connect
81
-if ($globalDebug) echo "Connecting...\n";
92
+if ($globalDebug) {
93
+	echo "Connecting...\n";
94
+}
82 95
 $use_aprs = false;
83 96
 $aprs_full = false;
84 97
 $reset = 0;
@@ -87,7 +100,9 @@  discard block
 block discarded – undo
87 100
     $ip = gethostbyname($host);
88 101
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
89 102
     $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
103
+    if (!socket_set_nonblock($s)) {
104
+    	echo "Unable to set nonblock on socket\n";
105
+    }
91 106
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92 107
         return $s;
93 108
     }
@@ -115,7 +130,9 @@  discard block
 block discarded – undo
115 130
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116 131
     global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117 132
     $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
133
+    if ($globalDebug) {
134
+    	echo 'Connect to all...'."\n";
135
+    }
119 136
     foreach ($hosts as $id => $value) {
120 137
 	$host = $value['host'];
121 138
 	$globalSources[$id]['last_exec'] = 0;
@@ -125,27 +142,37 @@  discard block
 block discarded – undo
125 142
         	//$formats[$id] = 'deltadbtxt';
126 143
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 144
         	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
145
+        	if ($globalDebug) {
146
+        		echo "Connect to deltadb source (".$host.")...\n";
147
+        	}
129 148
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130 149
         	//$formats[$id] = 'vatsimtxt';
131 150
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 151
         	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
152
+        	if ($globalDebug) {
153
+        		echo "Connect to vatsim source (".$host.")...\n";
154
+        	}
134 155
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135 156
         	//$formats[$id] = 'aircraftlistjson';
136 157
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 158
         	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
161
+        	}
139 162
     	    } else if (preg_match('/opensky/i',$host)) {
140 163
         	//$formats[$id] = 'aircraftlistjson';
141 164
         	$globalSources[$id]['format'] = 'opensky';
142 165
         	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to opensky source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145 170
         	//$formats[$id] = 'radarvirtueljson';
146 171
         	$globalSources[$id]['format'] = 'radarvirtueljson';
147 172
         	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
175
+        	}
149 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151 178
         	    exit(0);
@@ -154,7 +181,9 @@  discard block
 block discarded – undo
154 181
         	//$formats[$id] = 'planeupdatefaa';
155 182
         	$globalSources[$id]['format'] = 'planeupdatefaa';
156 183
         	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
186
+        	}
158 187
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159 188
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160 189
         	    exit(0);
@@ -163,26 +192,36 @@  discard block
 block discarded – undo
163 192
         	//$formats[$id] = 'phpvmacars';
164 193
         	$globalSources[$id]['format'] = 'phpvmacars';
165 194
         	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
195
+        	if ($globalDebug) {
196
+        		echo "Connect to phpvmacars source (".$host.")...\n";
197
+        	}
167 198
             } else if (preg_match('/VAM-json.php$/i',$host)) {
168 199
         	//$formats[$id] = 'phpvmacars';
169 200
         	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
201
+        	if ($globalDebug) {
202
+        		echo "Connect to Vam source (".$host.")...\n";
203
+        	}
171 204
             } else if (preg_match('/whazzup/i',$host)) {
172 205
         	//$formats[$id] = 'whazzup';
173 206
         	$globalSources[$id]['format'] = 'whazzup';
174 207
         	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
208
+        	if ($globalDebug) {
209
+        		echo "Connect to whazzup source (".$host.")...\n";
210
+        	}
176 211
             } else if (preg_match('/recentpireps/i',$host)) {
177 212
         	//$formats[$id] = 'pirepsjson';
178 213
         	$globalSources[$id]['format'] = 'pirepsjson';
179 214
         	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to pirepsjson source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182 219
         	//$formats[$id] = 'fr24json';
183 220
         	$globalSources[$id]['format'] = 'fr24json';
184 221
         	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to fr24 source (".$host.")...\n";
224
+        	}
186 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188 227
         	    exit(0);
@@ -191,10 +230,14 @@  discard block
 block discarded – undo
191 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192 231
         	//$formats[$id] = 'tsv';
193 232
         	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
195 236
             }
196 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
240
+        	}
198 241
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199 242
 	    $hostport = explode(':',$host);
200 243
 	    if (isset($hostport[1])) {
@@ -231,17 +274,25 @@  discard block
 block discarded – undo
231 274
         		//$formats[$id] = 'beast';
232 275
         		$globalSources[$id]['format'] = 'beast';
233 276
 		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
277
+		    } else {
278
+		    	$globalSources[$id]['format'] = 'sbs';
279
+		    }
235 280
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 281
 		}
237
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
282
+		if ($globalDebug) {
283
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
284
+		}
238 285
             } else {
239
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
286
+		if ($globalDebug) {
287
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
288
+		}
240 289
     	    }
241 290
         }
242 291
     }
243 292
 }
244
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
293
+if (!isset($globalMinFetch)) {
294
+	$globalMinFetch = 15;
295
+}
245 296
 
246 297
 // Initialize all
247 298
 $status = array();
@@ -249,13 +300,19 @@  discard block
 block discarded – undo
249 300
 $formats = array();
250 301
 $last_exec = array();
251 302
 $time = time();
252
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
253
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
254
-else $timeout = 20;
303
+if (isset($globalSourcesTimeout)) {
304
+	$timeout = $globalSourcesTimeOut;
305
+} else if (isset($globalSBS1TimeOut)) {
306
+	$timeout = $globalSBS1TimeOut;
307
+} else {
308
+	$timeout = 20;
309
+}
255 310
 $errno = '';
256 311
 $errstr='';
257 312
 
258
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
313
+if (!isset($globalDaemon)) {
314
+	$globalDaemon = TRUE;
315
+}
259 316
 /* Initiate connections to all the hosts simultaneously */
260 317
 //connect_all($hosts);
261 318
 //connect_all($globalSources);
@@ -275,7 +332,9 @@  discard block
 block discarded – undo
275 332
     if (isset($source['format']) && $source['format'] == 'aprs') {
276 333
 	$aprs_connect = 0;
277 334
 	$use_aprs = true;
278
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
335
+	if (isset($source['port']) && $source['port'] == '10152') {
336
+		$aprs_full = true;
337
+	}
279 338
 	break;
280 339
     }
281 340
 }
@@ -286,23 +345,43 @@  discard block
 block discarded – undo
286 345
 	$aprs_connect = 0;
287 346
 	$aprs_keep = 120;
288 347
 	$aprs_last_tx = time();
289
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
290
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
291
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
292
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
293
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
294
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
295
-	if ($aprs_full) $aprs_filter = '';
348
+	if (isset($globalAPRSversion)) {
349
+		$aprs_version = $globalAPRSversion;
350
+	} else {
351
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
352
+	}
353
+	if (isset($globalAPRSssid)) {
354
+		$aprs_ssid = $globalAPRSssid;
355
+	} else {
356
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
357
+	}
358
+	if (isset($globalAPRSfilter)) {
359
+		$aprs_filter = $globalAPRSfilter;
360
+	} else {
361
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
362
+	}
363
+	if ($aprs_full) {
364
+		$aprs_filter = '';
365
+	}
296 366
 
297
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
298
-	else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
299
-}
367
+	if ($aprs_filter != '') {
368
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
369
+	} else {
370
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
371
+	}
372
+	}
300 373
 
301 374
 // connected - lets do some work
302
-if ($globalDebug) echo "Connected!\n";
375
+if ($globalDebug) {
376
+	echo "Connected!\n";
377
+}
303 378
 sleep(1);
304
-if ($globalDebug) echo "SCAN MODE \n\n";
305
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
379
+if ($globalDebug) {
380
+	echo "SCAN MODE \n\n";
381
+}
382
+if (!isset($globalCronEnd)) {
383
+	$globalCronEnd = 60;
384
+}
306 385
 $endtime = time()+$globalCronEnd;
307 386
 $i = 1;
308 387
 $tt = array();
@@ -316,20 +395,28 @@  discard block
 block discarded – undo
316 395
 
317 396
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
318 397
 while ($i > 0) {
319
-    if (!$globalDaemon) $i = $endtime-time();
398
+    if (!$globalDaemon) {
399
+    	$i = $endtime-time();
400
+    }
320 401
     // Delete old ATC
321 402
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
322
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
403
+	if ($globalDebug) {
404
+		echo 'Delete old ATC...'."\n";
405
+	}
323 406
         $ATC->deleteOldATC();
324 407
     }
325 408
     
326 409
     if (count($last_exec) > 0) {
327 410
 	$max = $globalMinFetch;
328 411
 	foreach ($last_exec as $last) {
329
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
412
+	    if ((time() - $last['last']) < $max) {
413
+	    	$max = time() - $last['last'];
414
+	    }
330 415
 	}
331 416
 	if ($max != $globalMinFetch) {
332
-	    if ($globalDebug) echo 'Sleeping...'."\n";
417
+	    if ($globalDebug) {
418
+	    	echo 'Sleeping...'."\n";
419
+	    }
333 420
 	    sleep($globalMinFetch-$max+2);
334 421
 	}
335 422
     }
@@ -338,11 +425,15 @@  discard block
 block discarded – undo
338 425
     //foreach ($formats as $id => $value) {
339 426
     foreach ($globalSources as $id => $value) {
340 427
 	date_default_timezone_set('UTC');
341
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
428
+	if (!isset($last_exec[$id]['last'])) {
429
+		$last_exec[$id]['last'] = 0;
430
+	}
342 431
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
343 432
 	    //$buffer = $Common->getData($hosts[$id]);
344 433
 	    $buffer = $Common->getData($value['host']);
345
-	    if ($buffer != '') $reset = 0;
434
+	    if ($buffer != '') {
435
+	    	$reset = 0;
436
+	    }
346 437
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347 438
 	    $buffer = explode('\n',$buffer);
348 439
 	    foreach ($buffer as $line) {
@@ -351,19 +442,38 @@  discard block
 block discarded – undo
351 442
 	            $data = array();
352 443
 	            $data['hex'] = $line[1]; // hex
353 444
 	            $data['ident'] = $line[2]; // ident
354
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
445
+	            if (isset($line[3])) {
446
+	            	$data['altitude'] = $line[3];
447
+	            }
448
+	            // altitude
449
+	            if (isset($line[4])) {
450
+	            	$data['speed'] = $line[4];
451
+	            }
452
+	            // speed
453
+	            if (isset($line[5])) {
454
+	            	$data['heading'] = $line[5];
455
+	            }
456
+	            // heading
457
+	            if (isset($line[6])) {
458
+	            	$data['latitude'] = $line[6];
459
+	            }
460
+	            // lat
461
+	            if (isset($line[7])) {
462
+	            	$data['longitude'] = $line[7];
463
+	            }
464
+	            // long
359 465
 	            $data['verticalrate'] = ''; // vertical rate
360 466
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361 467
 	            $data['emergency'] = ''; // emergency
362 468
 		    $data['datetime'] = date('Y-m-d H:i:s');
363 469
 		    $data['format_source'] = 'deltadbtxt';
364 470
     		    $data['id_source'] = $id_source;
365
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
471
+		    if (isset($value['name']) && $value['name'] != '') {
472
+		    	$data['source_name'] = $value['name'];
473
+		    }
474
+		    if (isset($value['sourcestats'])) {
475
+		    	$data['sourcestats'] = $value['sourcestats'];
476
+		    }
367 477
     		    $SI->add($data);
368 478
 		    unset($data);
369 479
     		}
@@ -381,16 +491,28 @@  discard block
 block discarded – undo
381 491
     		    $line = explode(':', $line);
382 492
     		    if (count($line) > 30 && $line[0] != 'callsign') {
383 493
 			$data = array();
384
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
385
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
494
+			if (isset($line[37]) && $line[37] != '') {
495
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
496
+			} else {
497
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
498
+			}
386 499
 			$data['pilot_id'] = $line[1];
387 500
 			$data['pilot_name'] = $line[2];
388 501
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
389 502
 			$data['ident'] = $line[0]; // ident
390
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
503
+			if ($line[7] != '' && $line[7] != 0) {
504
+				$data['altitude'] = $line[7];
505
+			}
506
+			// altitude
391 507
 			$data['speed'] = $line[8]; // speed
392
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
393
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
508
+			if (isset($line[45])) {
509
+				$data['heading'] = $line[45];
510
+			}
511
+			// heading
512
+			elseif (isset($line[38])) {
513
+				$data['heading'] = $line[38];
514
+			}
515
+			// heading
394 516
 			$data['latitude'] = $line[5]; // lat
395 517
 	        	$data['longitude'] = $line[6]; // long
396 518
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -406,7 +528,9 @@  discard block
 block discarded – undo
406 528
 			$data['frequency'] = $line[4];
407 529
 			$data['type'] = $line[18];
408 530
 			$data['range'] = $line[19];
409
-			if (isset($line[35])) $data['info'] = $line[35];
531
+			if (isset($line[35])) {
532
+				$data['info'] = $line[35];
533
+			}
410 534
     			$data['id_source'] = $id_source;
411 535
 	    		//$data['arrival_airport_time'] = ;
412 536
 	    		if ($line[9] != '') {
@@ -420,23 +544,38 @@  discard block
 block discarded – undo
420 544
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
421 545
 	    		*/
422 546
 	    		$data['format_source'] = $value['format'];
423
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
424
-    			if ($line[3] == 'PILOT') $SI->add($data);
425
-			elseif ($line[3] == 'ATC') {
547
+			if (isset($value['name']) && $value['name'] != '') {
548
+				$data['source_name'] = $value['name'];
549
+			}
550
+    			if ($line[3] == 'PILOT') {
551
+    				$SI->add($data);
552
+    			} elseif ($line[3] == 'ATC') {
426 553
 				//print_r($data);
427 554
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
428 555
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
429 556
 				$typec = substr($data['ident'],-3);
430
-				if ($typec == 'APP') $data['type'] = 'Approach';
431
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
432
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
433
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
434
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
435
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
436
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
437
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
438
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
439
-				if (!isset($data['source_name'])) $data['source_name'] = '';
557
+				if ($typec == 'APP') {
558
+					$data['type'] = 'Approach';
559
+				} elseif ($typec == 'TWR') {
560
+					$data['type'] = 'Tower';
561
+				} elseif ($typec == 'OBS') {
562
+					$data['type'] = 'Observer';
563
+				} elseif ($typec == 'GND') {
564
+					$data['type'] = 'Ground';
565
+				} elseif ($typec == 'DEL') {
566
+					$data['type'] = 'Delivery';
567
+				} elseif ($typec == 'DEP') {
568
+					$data['type'] = 'Departure';
569
+				} elseif ($typec == 'FSS') {
570
+					$data['type'] = 'Flight Service Station';
571
+				} elseif ($typec == 'CTR') {
572
+					$data['type'] = 'Control Radar or Centre';
573
+				} elseif ($data['type'] == '') {
574
+					$data['type'] = 'Observer';
575
+				}
576
+				if (!isset($data['source_name'])) {
577
+					$data['source_name'] = '';
578
+				}
440 579
 				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']);
441 580
 			}
442 581
     			unset($data);
@@ -456,26 +595,55 @@  discard block
 block discarded – undo
456 595
 		foreach ($all_data['acList'] as $line) {
457 596
 		    $data = array();
458 597
 		    $data['hex'] = $line['Icao']; // hex
459
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
460
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
461
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
462
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
463
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
464
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
598
+		    if (isset($line['Call'])) {
599
+		    	$data['ident'] = $line['Call'];
600
+		    }
601
+		    // ident
602
+		    if (isset($line['Alt'])) {
603
+		    	$data['altitude'] = $line['Alt'];
604
+		    }
605
+		    // altitude
606
+		    if (isset($line['Spd'])) {
607
+		    	$data['speed'] = $line['Spd'];
608
+		    }
609
+		    // speed
610
+		    if (isset($line['Trak'])) {
611
+		    	$data['heading'] = $line['Trak'];
612
+		    }
613
+		    // heading
614
+		    if (isset($line['Lat'])) {
615
+		    	$data['latitude'] = $line['Lat'];
616
+		    }
617
+		    // lat
618
+		    if (isset($line['Long'])) {
619
+		    	$data['longitude'] = $line['Long'];
620
+		    }
621
+		    // long
465 622
 		    //$data['verticalrate'] = $line['']; // verticale rate
466
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
623
+		    if (isset($line['Sqk'])) {
624
+		    	$data['squawk'] = $line['Sqk'];
625
+		    }
626
+		    // squawk
467 627
 		    $data['emergency'] = ''; // emergency
468
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
628
+		    if (isset($line['Reg'])) {
629
+		    	$data['registration'] = $line['Reg'];
630
+		    }
469 631
 		    /*
470 632
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
471 633
 		    else $data['datetime'] = date('Y-m-d H:i:s');
472 634
 		    */
473 635
 		    $data['datetime'] = date('Y-m-d H:i:s');
474
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
636
+		    if (isset($line['Type'])) {
637
+		    	$data['aircraft_icao'] = $line['Type'];
638
+		    }
475 639
 	    	    $data['format_source'] = 'aircraftlistjson';
476 640
 		    $data['id_source'] = $id_source;
477
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
-		    if (isset($data['datetime'])) $SI->add($data);
641
+		    if (isset($value['name']) && $value['name'] != '') {
642
+		    	$data['source_name'] = $value['name'];
643
+		    }
644
+		    if (isset($data['datetime'])) {
645
+		    	$SI->add($data);
646
+		    }
479 647
 		    unset($data);
480 648
 		}
481 649
 	    } else {
@@ -495,7 +663,9 @@  discard block
 block discarded – undo
495 663
 		    $data['datetime'] = date('Y-m-d H:i:s');
496 664
 	    	    $data['format_source'] = 'aircraftlistjson';
497 665
     		    $data['id_source'] = $id_source;
498
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
666
+		    if (isset($value['name']) && $value['name'] != '') {
667
+		    	$data['source_name'] = $value['name'];
668
+		    }
499 669
 		    $SI->add($data);
500 670
 		    unset($data);
501 671
 		}
@@ -531,7 +701,9 @@  discard block
 block discarded – undo
531 701
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532 702
 	    	    $data['format_source'] = 'planeupdatefaa';
533 703
     		    $data['id_source'] = $id_source;
534
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
704
+		    if (isset($value['name']) && $value['name'] != '') {
705
+		    	$data['source_name'] = $value['name'];
706
+		    }
535 707
 		    $SI->add($data);
536 708
 		    unset($data);
537 709
 		}
@@ -571,7 +743,9 @@  discard block
 block discarded – undo
571 743
 	    //$buffer = $Common->getData($hosts[$id]);
572 744
 	    $buffer = $Common->getData($value['host']);
573 745
 	    $all_data = json_decode($buffer,true);
574
-	    if (!empty($all_data)) $reset = 0;
746
+	    if (!empty($all_data)) {
747
+	    	$reset = 0;
748
+	    }
575 749
 	    foreach ($all_data as $key => $line) {
576 750
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
577 751
 		    $data = array();
@@ -592,7 +766,9 @@  discard block
 block discarded – undo
592 766
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
593 767
 	    	    $data['format_source'] = 'fr24json';
594 768
     		    $data['id_source'] = $id_source;
595
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
769
+		    if (isset($value['name']) && $value['name'] != '') {
770
+		    	$data['source_name'] = $value['name'];
771
+		    }
596 772
 		    $SI->add($data);
597 773
 		    unset($data);
598 774
 		}
@@ -616,23 +792,39 @@  discard block
 block discarded – undo
616 792
 		    if (isset($line['inf'])) {
617 793
 			$data = array();
618 794
 			$data['hex'] = $line['inf']['ia'];
619
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
795
+			if (isset($line['inf']['cs'])) {
796
+				$data['ident'] = $line['inf']['cs'];
797
+			}
798
+			//$line[13]
620 799
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
621
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
622
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
800
+	    		if (isset($line['inf']['gs'])) {
801
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
802
+	    		}
803
+	    		// speed
804
+	    		if (isset($line['inf']['tr'])) {
805
+	    			$data['heading'] = $line['inf']['tr'];
806
+	    		}
807
+	    		// heading
623 808
 	    		$data['latitude'] = $line['pt'][0]; // lat
624 809
 	    		$data['longitude'] = $line['pt'][1]; // long
625 810
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
626
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
811
+	    		if (isset($line['inf']['sq'])) {
812
+	    			$data['squawk'] = $line['inf']['sq'];
813
+	    		}
814
+	    		// squawk
627 815
 	    		//$data['aircraft_icao'] = $line[8];
628
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
816
+	    		if (isset($line['inf']['rc'])) {
817
+	    			$data['registration'] = $line['inf']['rc'];
818
+	    		}
629 819
 			//$data['departure_airport_iata'] = $line[11];
630 820
 			//$data['arrival_airport_iata'] = $line[12];
631 821
 	    		//$data['emergency'] = ''; // emergency
632 822
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
633 823
 	    		$data['format_source'] = 'radarvirtueljson';
634 824
     			$data['id_source'] = $id_source;
635
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
825
+			if (isset($value['name']) && $value['name'] != '') {
826
+				$data['source_name'] = $value['name'];
827
+			}
636 828
 			$SI->add($data);
637 829
 			unset($data);
638 830
 		    }
@@ -653,29 +845,62 @@  discard block
 block discarded – undo
653 845
 		    $data['id'] = $line['id'];
654 846
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655 847
 		    $data['ident'] = $line['callsign']; // ident
656
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
657
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
658
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
659
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
660
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
661
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
848
+		    if (isset($line['pilotid'])) {
849
+		    	$data['pilot_id'] = $line['pilotid'];
850
+		    }
851
+		    // pilot id
852
+		    if (isset($line['name'])) {
853
+		    	$data['pilot_name'] = $line['name'];
854
+		    }
855
+		    // pilot name
856
+		    if (isset($line['alt'])) {
857
+		    	$data['altitude'] = $line['alt'];
858
+		    }
859
+		    // altitude
860
+		    if (isset($line['gs'])) {
861
+		    	$data['speed'] = $line['gs'];
862
+		    }
863
+		    // speed
864
+		    if (isset($line['heading'])) {
865
+		    	$data['heading'] = $line['heading'];
866
+		    }
867
+		    // heading
868
+		    if (isset($line['route'])) {
869
+		    	$data['waypoints'] = $line['route'];
870
+		    }
871
+		    // route
662 872
 		    $data['latitude'] = $line['lat']; // lat
663 873
 		    $data['longitude'] = $line['lon']; // long
664 874
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
665 875
 		    //$data['squawk'] = $line['squawk']; // squawk
666 876
 		    //$data['emergency'] = ''; // emergency
667
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
668
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
669
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
877
+		    if (isset($line['depicao'])) {
878
+		    	$data['departure_airport_icao'] = $line['depicao'];
879
+		    }
880
+		    if (isset($line['deptime'])) {
881
+		    	$data['departure_airport_time'] = $line['deptime'];
882
+		    }
883
+		    if (isset($line['arricao'])) {
884
+		    	$data['arrival_airport_icao'] = $line['arricao'];
885
+		    }
670 886
 		    //$data['arrival_airport_time'] = $line['arrtime'];
671
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
672
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
673
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
674
-		    else $data['info'] = '';
887
+		    if (isset($line['aircraft'])) {
888
+		    	$data['aircraft_icao'] = $line['aircraft'];
889
+		    }
890
+		    if (isset($line['transponder'])) {
891
+		    	$data['squawk'] = $line['transponder'];
892
+		    }
893
+		    if (isset($line['atis'])) {
894
+		    	$data['info'] = $line['atis'];
895
+		    } else {
896
+		    	$data['info'] = '';
897
+		    }
675 898
 		    $data['format_source'] = 'pireps';
676 899
     		    $data['id_source'] = $id_source;
677 900
 		    $data['datetime'] = date('Y-m-d H:i:s');
678
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
901
+		    if (isset($value['name']) && $value['name'] != '') {
902
+		    	$data['source_name'] = $value['name'];
903
+		    }
679 904
 		    if ($line['icon'] == 'plane') {
680 905
 			$SI->add($data);
681 906
 		    //    print_r($data);
@@ -684,15 +909,25 @@  discard block
 block discarded – undo
684 909
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
685 910
 			$typec = substr($data['ident'],-3);
686 911
 			$data['type'] = '';
687
-			if ($typec == 'APP') $data['type'] = 'Approach';
688
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
689
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
690
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
691
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
692
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
693
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
694
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
695
-			else $data['type'] = 'Observer';
912
+			if ($typec == 'APP') {
913
+				$data['type'] = 'Approach';
914
+			} elseif ($typec == 'TWR') {
915
+				$data['type'] = 'Tower';
916
+			} elseif ($typec == 'OBS') {
917
+				$data['type'] = 'Observer';
918
+			} elseif ($typec == 'GND') {
919
+				$data['type'] = 'Ground';
920
+			} elseif ($typec == 'DEL') {
921
+				$data['type'] = 'Delivery';
922
+			} elseif ($typec == 'DEP') {
923
+				$data['type'] = 'Departure';
924
+			} elseif ($typec == 'FSS') {
925
+				$data['type'] = 'Flight Service Station';
926
+			} elseif ($typec == 'CTR') {
927
+				$data['type'] = 'Control Radar or Centre';
928
+			} else {
929
+				$data['type'] = 'Observer';
930
+			}
696 931
 			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']);
697 932
 		    }
698 933
 		    unset($data);
@@ -703,7 +938,9 @@  discard block
 block discarded – undo
703 938
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
704 939
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705 940
 	    //$buffer = $Common->getData($hosts[$id]);
706
-	    if ($globalDebug) echo 'Get Data...'."\n";
941
+	    if ($globalDebug) {
942
+	    	echo 'Get Data...'."\n";
943
+	    }
707 944
 	    $buffer = $Common->getData($value['host']);
708 945
 	    $all_data = json_decode($buffer,true);
709 946
 	    if ($buffer != '' && is_array($all_data)) {
@@ -711,10 +948,16 @@  discard block
 block discarded – undo
711 948
 		foreach ($all_data as $line) {
712 949
 	    	    $data = array();
713 950
 	    	    //$data['id'] = $line['id']; // id not usable
714
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
951
+	    	    if (isset($line['pilotid'])) {
952
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
953
+	    	    }
715 954
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
717
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
955
+	    	    if (isset($line['pilotname'])) {
956
+	    	    	$data['pilot_name'] = $line['pilotname'];
957
+	    	    }
958
+	    	    if (isset($line['pilotid'])) {
959
+	    	    	$data['pilot_id'] = $line['pilotid'];
960
+	    	    }
718 961
 	    	    $data['ident'] = $line['flightnum']; // ident
719 962
 	    	    $data['altitude'] = $line['alt']; // altitude
720 963
 	    	    $data['speed'] = $line['gs']; // speed
@@ -732,27 +975,41 @@  discard block
 block discarded – undo
732 975
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
733 976
     		    $data['arrival_airport_time'] = $line['arrtime'];
734 977
     		    $data['registration'] = $line['aircraft'];
735
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
978
+		    if (isset($line['route'])) {
979
+		    	$data['waypoints'] = $line['route'];
980
+		    }
981
+		    // route
736 982
 		    if (isset($line['aircraftname'])) {
737 983
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
738 984
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
739 985
 	    		$aircraft_data = explode('-',$line['aircraftname']);
740
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
741
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
742
-	    		else {
986
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
987
+	    			$data['aircraft_icao'] = $aircraft_data[0];
988
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
989
+	    			$data['aircraft_icao'] = $aircraft_data[1];
990
+	    		} else {
743 991
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
744
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
745
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
992
+	    		    if (isset($aircraft_data[1])) {
993
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
994
+	    		    } else {
995
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
996
+	    		    }
746 997
 	    		}
747 998
 	    	    }
748
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
999
+    		    if (isset($line['route'])) {
1000
+    		    	$data['waypoints'] = $line['route'];
1001
+    		    }
749 1002
     		    $data['id_source'] = $id_source;
750 1003
 	    	    $data['format_source'] = 'phpvmacars';
751
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1004
+		    if (isset($value['name']) && $value['name'] != '') {
1005
+		    	$data['source_name'] = $value['name'];
1006
+		    }
752 1007
 		    $SI->add($data);
753 1008
 		    unset($data);
754 1009
 		}
755
-		if ($globalDebug) echo 'No more data...'."\n";
1010
+		if ($globalDebug) {
1011
+			echo 'No more data...'."\n";
1012
+		}
756 1013
 		unset($buffer);
757 1014
 		unset($all_data);
758 1015
 	    }
@@ -760,7 +1017,9 @@  discard block
 block discarded – undo
760 1017
     	    $last_exec[$id]['last'] = time();
761 1018
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
762 1019
 	    //$buffer = $Common->getData($hosts[$id]);
763
-	    if ($globalDebug) echo 'Get Data...'."\n";
1020
+	    if ($globalDebug) {
1021
+	    	echo 'Get Data...'."\n";
1022
+	    }
764 1023
 	    $buffer = $Common->getData($value['host']);
765 1024
 	    $all_data = json_decode($buffer,true);
766 1025
 	    if ($buffer != '' && is_array($all_data)) {
@@ -789,15 +1048,22 @@  discard block
 block discarded – undo
789 1048
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
790 1049
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
791 1050
     		    //$data['registration'] = $line['aircraft'];
792
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1051
+		    if (isset($line['route'])) {
1052
+		    	$data['waypoints'] = $line['route'];
1053
+		    }
1054
+		    // route
793 1055
 	    	    $data['aircraft_icao'] = $line['plane_type'];
794 1056
     		    $data['id_source'] = $id_source;
795 1057
 	    	    $data['format_source'] = 'vam';
796
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1058
+		    if (isset($value['name']) && $value['name'] != '') {
1059
+		    	$data['source_name'] = $value['name'];
1060
+		    }
797 1061
 		    $SI->add($data);
798 1062
 		    unset($data);
799 1063
 		}
800
-		if ($globalDebug) echo 'No more data...'."\n";
1064
+		if ($globalDebug) {
1065
+			echo 'No more data...'."\n";
1066
+		}
801 1067
 		unset($buffer);
802 1068
 		unset($all_data);
803 1069
 	    }
@@ -805,7 +1071,9 @@  discard block
 block discarded – undo
805 1071
     	    $last_exec[$id]['last'] = time();
806 1072
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
807 1073
 	} 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') {
808
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1074
+	    if (function_exists('pcntl_fork')) {
1075
+	    	pcntl_signal_dispatch();
1076
+	    }
809 1077
     	    //$last_exec[$id]['last'] = time();
810 1078
 
811 1079
 	    //$read = array( $sockets[$id] );
@@ -813,7 +1081,9 @@  discard block
 block discarded – undo
813 1081
 	    $write = NULL;
814 1082
 	    $e = NULL;
815 1083
 	    $n = socket_select($read, $write, $e, $timeout);
816
-	    if ($e != NULL) var_dump($e);
1084
+	    if ($e != NULL) {
1085
+	    	var_dump($e);
1086
+	    }
817 1087
 	    if ($n > 0) {
818 1088
 		$reset = 0;
819 1089
 		foreach ($read as $nb => $r) {
@@ -835,7 +1105,9 @@  discard block
 block discarded – undo
835 1105
 		    if ($buffer != '') {
836 1106
 			$tt[$format] = 0;
837 1107
 			if ($format == 'acarssbs3') {
838
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1108
+                    	    if ($globalDebug) {
1109
+                    	    	echo 'ACARS : '.$buffer."\n";
1110
+                    	    }
839 1111
 			    $ACARS->add(trim($buffer));
840 1112
 			    $ACARS->deleteLiveAcarsData();
841 1113
 			} elseif ($format == 'raw') {
@@ -844,9 +1116,15 @@  discard block
 block discarded – undo
844 1116
 			    if (is_array($data)) {
845 1117
 				$data['datetime'] = date('Y-m-d H:i:s');
846 1118
 				$data['format_source'] = 'raw';
847
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
848
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1119
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1120
+					$data['source_name'] = $globalSources[$nb]['name'];
1121
+				}
1122
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1123
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1124
+    				}
1125
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1126
+                                	$SI->add($data);
1127
+                                }
850 1128
                             }
851 1129
                         } elseif ($format == 'flightgearsp') {
852 1130
                     	    //echo $buffer."\n";
@@ -864,11 +1142,15 @@  discard block
 block discarded – undo
864 1142
 				$data['speed'] = round($line[5]*1.94384);
865 1143
 				$data['datetime'] = date('Y-m-d H:i:s');
866 1144
 				$data['format_source'] = 'flightgearsp';
867
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1145
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1146
+					$SI->add($data);
1147
+				}
868 1148
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
869 1149
 			    }
870 1150
                         } elseif ($format == 'acars') {
871
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1151
+                    	    if ($globalDebug) {
1152
+                    	    	echo 'ACARS : '.$buffer."\n";
1153
+                    	    }
872 1154
 			    $ACARS->add(trim($buffer));
873 1155
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874 1156
 			    $ACARS->deleteLiveAcarsData();
@@ -889,7 +1171,9 @@  discard block
 block discarded – undo
889 1171
 				    $aircraft_type = $line[10];
890 1172
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
891 1173
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
892
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1174
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1175
+				    	$SI->add($data);
1176
+				    }
893 1177
 				}
894 1178
 			    }
895 1179
 			} elseif ($format == 'beast') {
@@ -905,21 +1189,43 @@  discard block
 block discarded – undo
905 1189
     				$data['hex'] = $lined['hexid'];
906 1190
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
907 1191
     				$data['datetime'] = date('Y-m-d H:i:s');;
908
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
909
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
910
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
911
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
912
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
913
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
914
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1192
+    				if (isset($lined['ident'])) {
1193
+    					$data['ident'] = $lined['ident'];
1194
+    				}
1195
+    				if (isset($lined['lat'])) {
1196
+    					$data['latitude'] = $lined['lat'];
1197
+    				}
1198
+    				if (isset($lined['lon'])) {
1199
+    					$data['longitude'] = $lined['lon'];
1200
+    				}
1201
+    				if (isset($lined['speed'])) {
1202
+    					$data['speed'] = $lined['speed'];
1203
+    				}
1204
+    				if (isset($lined['squawk'])) {
1205
+    					$data['squawk'] = $lined['squawk'];
1206
+    				}
1207
+    				if (isset($lined['alt'])) {
1208
+    					$data['altitude'] = $lined['alt'];
1209
+    				}
1210
+    				if (isset($lined['heading'])) {
1211
+    					$data['heading'] = $lined['heading'];
1212
+    				}
915 1213
     				$data['id_source'] = $id_source;
916 1214
     				$data['format_source'] = 'tsv';
917
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
918
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
919
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1215
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1216
+    					$data['source_name'] = $globalSources[$nb]['name'];
1217
+    				}
1218
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1219
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1220
+    				}
1221
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1222
+    					$SI->add($data);
1223
+    				}
920 1224
     				unset($lined);
921 1225
     				unset($data);
922
-    			    } else $error = true;
1226
+    			    } else {
1227
+    			    	$error = true;
1228
+    			    }
923 1229
 			} elseif ($format == 'aprs' && $use_aprs) {
924 1230
 			    if ($aprs_connect == 0) {
925 1231
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -950,32 +1256,46 @@  discard block
 block discarded – undo
950 1256
 				    $data['latitude'] = $line['latitude'];
951 1257
 				    $data['longitude'] = $line['longitude'];
952 1258
 				    //$data['verticalrate'] = $line[16];
953
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
954
-				    else $data['speed'] = 0;
1259
+				    if (isset($line['speed'])) {
1260
+				    	$data['speed'] = $line['speed'];
1261
+				    } else {
1262
+				    	$data['speed'] = 0;
1263
+				    }
955 1264
 				    $data['altitude'] = $line['altitude'];
956
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1265
+				    if (isset($line['heading'])) {
1266
+				    	$data['heading'] = $line['heading'];
1267
+				    }
957 1268
 				    //else $data['heading'] = 0;
958 1269
 				    $data['aircraft_type'] = $line['stealth'];
959
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1270
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1271
+				    	$data['noarchive'] = true;
1272
+				    }
960 1273
     				    $data['id_source'] = $id_source;
961 1274
 				    $data['format_source'] = 'aprs';
962 1275
 				    $data['source_name'] = $line['source'];
963
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1276
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1277
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1278
+    				    }
964 1279
 				    $currentdate = date('Y-m-d H:i:s');
965 1280
 				    $aprsdate = strtotime($data['datetime']);
966 1281
 				    // Accept data if time <= system time + 20s
967
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
968
-				    else {
969
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
970
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1282
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1283
+				    	$send = $SI->add($data);
1284
+				    } else {
1285
+					if ($line['stealth'] != 0) {
1286
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1287
+					} else {
1288
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1289
+					}
971 1290
 				    }
972 1291
 				    unset($data);
973
-				} 
974
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1292
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
975 1293
 					echo '!! Weather Station not yet supported'."\n";
976 1294
 				}
977 1295
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
978
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1296
+				elseif ($line == true && $globalDebug) {
1297
+					echo '!! Failed : '.$buffer."!!\n";
1298
+				}
979 1299
 			    }
980 1300
 			} else {
981 1301
 			    $line = explode(',', $buffer);
@@ -1004,25 +1324,42 @@  discard block
 block discarded – undo
1004 1324
     				$data['ground'] = $line[21];
1005 1325
     				$data['emergency'] = $line[19];
1006 1326
     				$data['format_source'] = 'sbs';
1007
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1008
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1327
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1328
+					$data['source_name'] = $globalSources[$nb]['name'];
1329
+				}
1330
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1331
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1332
+    				}
1009 1333
     				$data['id_source'] = $id_source;
1010
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1011
-    				else $error = true;
1334
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1335
+    					$send = $SI->add($data);
1336
+    				} else {
1337
+    					$error = true;
1338
+    				}
1012 1339
     				unset($data);
1013
-    			    } else $error = true;
1340
+    			    } else {
1341
+    			    	$error = true;
1342
+    			    }
1014 1343
 			    if ($error) {
1015 1344
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1016
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1345
+					if ($globalDebug) {
1346
+						echo "Not a message. Ignoring... \n";
1347
+					}
1017 1348
 				} else {
1018
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1349
+					if ($globalDebug) {
1350
+						echo "Wrong line format. Ignoring... \n";
1351
+					}
1019 1352
 					if ($globalDebug) {
1020 1353
 						echo $buffer;
1021 1354
 						print_r($line);
1022 1355
 					}
1023 1356
 					//socket_close($r);
1024
-					if ($globalDebug) echo "Reconnect after an error...\n";
1025
-					if ($format == 'aprs') $aprs_connect = 0;
1357
+					if ($globalDebug) {
1358
+						echo "Reconnect after an error...\n";
1359
+					}
1360
+					if ($format == 'aprs') {
1361
+						$aprs_connect = 0;
1362
+					}
1026 1363
 					$sourceer[$nb] = $globalSources[$nb];
1027 1364
 					connect_all($sourceer);
1028 1365
 					$sourceer = array();
@@ -1030,10 +1367,14 @@  discard block
 block discarded – undo
1030 1367
 			    }
1031 1368
 			}
1032 1369
 			// Sleep for xxx microseconds
1033
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1370
+			if (isset($globalSBSSleep)) {
1371
+				usleep($globalSBSSleep);
1372
+			}
1034 1373
 		    } else {
1035 1374
 			if ($format == 'flightgearmp') {
1036
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1375
+			    	if ($globalDebug) {
1376
+			    		echo "Reconnect FlightGear MP...";
1377
+			    	}
1037 1378
 				//@socket_close($r);
1038 1379
 				sleep($globalMinFetch);
1039 1380
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1042,10 +1383,15 @@  discard block
 block discarded – undo
1042 1383
 				break;
1043 1384
 				
1044 1385
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1045
-			    if (isset($tt[$format])) $tt[$format]++;
1046
-			    else $tt[$format] = 0;
1386
+			    if (isset($tt[$format])) {
1387
+			    	$tt[$format]++;
1388
+			    } else {
1389
+			    	$tt[$format] = 0;
1390
+			    }
1047 1391
 			    if ($tt[$format] > 30) {
1048
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1392
+				if ($globalDebug) {
1393
+					echo "ERROR : Reconnect ".$format."...";
1394
+				}
1049 1395
 				//@socket_close($r);
1050 1396
 				sleep(2);
1051 1397
 				$aprs_connect = 0;
@@ -1061,12 +1407,18 @@  discard block
 block discarded – undo
1061 1407
 		}
1062 1408
 	    } else {
1063 1409
 		$error = socket_strerror(socket_last_error());
1064
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1410
+		if ($globalDebug) {
1411
+			echo "ERROR : socket_select give this error ".$error . "\n";
1412
+		}
1065 1413
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1066
-			if (isset($globalDebug)) echo "Restarting...\n";
1414
+			if (isset($globalDebug)) {
1415
+				echo "Restarting...\n";
1416
+			}
1067 1417
 			// Restart the script if possible
1068 1418
 			if (is_array($sockets)) {
1069
-			    if ($globalDebug) echo "Shutdown all sockets...";
1419
+			    if ($globalDebug) {
1420
+			    	echo "Shutdown all sockets...";
1421
+			    }
1070 1422
 			    
1071 1423
 			    foreach ($sockets as $sock) {
1072 1424
 				@socket_shutdown($sock,2);
@@ -1074,18 +1426,24 @@  discard block
 block discarded – undo
1074 1426
 			    }
1075 1427
 			    
1076 1428
 			}
1077
-			if ($globalDebug) echo "Restart all connections...";
1429
+			if ($globalDebug) {
1430
+				echo "Restart all connections...";
1431
+			}
1078 1432
 			sleep(2);
1079 1433
 			$time = time();
1080 1434
 			//connect_all($hosts);
1081 1435
 			$aprs_connect = 0;
1082
-			if ($reset > 40) exit('Too many attempts...');
1436
+			if ($reset > 40) {
1437
+				exit('Too many attempts...');
1438
+			}
1083 1439
 			connect_all($globalSources);
1084 1440
 		}
1085 1441
 	    }
1086 1442
 	}
1087 1443
 	if ($globalDaemon === false) {
1088
-	    if ($globalDebug) echo 'Check all...'."\n";
1444
+	    if ($globalDebug) {
1445
+	    	echo 'Check all...'."\n";
1446
+	    }
1089 1447
 	    $SI->checkAll();
1090 1448
 	}
1091 1449
     }
Please login to merge, or discard this patch.
require/class.Stats.php 2 patches
Indentation   +788 added lines, -788 removed lines patch added patch discarded remove patch
@@ -15,33 +15,33 @@  discard block
 block discarded – undo
15 15
 		if (isset($globalFilterName)) $this->filter_name = $globalFilterName;
16 16
 		$Connection = new Connection($dbc);
17 17
 		$this->db = $Connection->db();
18
-        }
18
+		}
19 19
               
20 20
 	public function addLastStatsUpdate($type,$stats_date) {
21
-                $query = "DELETE FROM config WHERE name = :type;
21
+				$query = "DELETE FROM config WHERE name = :type;
22 22
             		INSERT INTO config (name,value) VALUES (:type,:stats_date);";
23
-                $query_values = array('type' => $type,':stats_date' => $stats_date);
24
-                 try {
25
-                        $sth = $this->db->prepare($query);
26
-                        $sth->execute($query_values);
27
-                } catch(PDOException $e) {
28
-                        return "error : ".$e->getMessage();
29
-                }
30
-        }
23
+				$query_values = array('type' => $type,':stats_date' => $stats_date);
24
+				 try {
25
+						$sth = $this->db->prepare($query);
26
+						$sth->execute($query_values);
27
+				} catch(PDOException $e) {
28
+						return "error : ".$e->getMessage();
29
+				}
30
+		}
31 31
 
32 32
 	public function getLastStatsUpdate($type = 'last_update_stats') {
33
-                $query = "SELECT value FROM config WHERE name = :type";
34
-                 try {
35
-                        $sth = $this->db->prepare($query);
36
-                        $sth->execute(array(':type' => $type));
37
-                } catch(PDOException $e) {
38
-                        echo "error : ".$e->getMessage();
39
-                }
40
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
41
-                return $all;
42
-        }
43
-        public function deleteStats($filter_name = '') {
44
-        	/*
33
+				$query = "SELECT value FROM config WHERE name = :type";
34
+				 try {
35
+						$sth = $this->db->prepare($query);
36
+						$sth->execute(array(':type' => $type));
37
+				} catch(PDOException $e) {
38
+						echo "error : ".$e->getMessage();
39
+				}
40
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
41
+				return $all;
42
+		}
43
+		public function deleteStats($filter_name = '') {
44
+			/*
45 45
         	$query = "DELETE FROM config WHERE name = 'last_update_stats'";
46 46
                  try {
47 47
                         $sth = $this->db->prepare($query);
@@ -50,109 +50,109 @@  discard block
 block discarded – undo
50 50
                         return "error : ".$e->getMessage();
51 51
                 }
52 52
                 */
53
-        	$query = "DELETE FROM stats WHERE filter_name = :filter_name;DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_airport WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_flight WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;";
54
-                 try {
55
-                        $sth = $this->db->prepare($query);
56
-                        $sth->execute(array(':filter_name' => $filter_name));
57
-                } catch(PDOException $e) {
58
-                        return "error : ".$e->getMessage();
59
-                }
60
-        }
61
-        public function deleteOldStats($filter_name = '') {
62
-        	if ($filter_name == '') {
63
-        		$query = "DELETE FROM config WHERE name = 'last_update_stats'";
64
-        	} else {
65
-        		$query = "DELETE FROM config WHERE name = 'last_update_stats_".$filter_name."'";
66
-        	}
67
-                 try {
68
-                        $sth = $this->db->prepare($query);
69
-                        $sth->execute();
70
-                } catch(PDOException $e) {
71
-                        return "error : ".$e->getMessage();
72
-                }
53
+			$query = "DELETE FROM stats WHERE filter_name = :filter_name;DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_airport WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_flight WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;";
54
+				 try {
55
+						$sth = $this->db->prepare($query);
56
+						$sth->execute(array(':filter_name' => $filter_name));
57
+				} catch(PDOException $e) {
58
+						return "error : ".$e->getMessage();
59
+				}
60
+		}
61
+		public function deleteOldStats($filter_name = '') {
62
+			if ($filter_name == '') {
63
+				$query = "DELETE FROM config WHERE name = 'last_update_stats'";
64
+			} else {
65
+				$query = "DELETE FROM config WHERE name = 'last_update_stats_".$filter_name."'";
66
+			}
67
+				 try {
68
+						$sth = $this->db->prepare($query);
69
+						$sth->execute();
70
+				} catch(PDOException $e) {
71
+						return "error : ".$e->getMessage();
72
+				}
73 73
                 
74
-        	$query = "DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;";
75
-                 try {
76
-                        $sth = $this->db->prepare($query);
77
-                        $sth->execute(array(':filter_name' => $filter_name));
78
-                } catch(PDOException $e) {
79
-                        return "error : ".$e->getMessage();
80
-                }
81
-        }
74
+			$query = "DELETE FROM stats_aircraft WHERE filter_name = :filter_name;DELETE FROM stats_airline WHERE filter_name = :filter_name;DELETE FROM stats_callsign WHERE filter_name = :filter_name;DELETE FROM stats_country WHERE filter_name = :filter_name;DELETE FROM stats_owner WHERE filter_name = :filter_name;DELETE FROM stats_pilot WHERE filter_name = :filter_name;DELETE FROM stats_registration WHERE filter_name = :filter_name;";
75
+				 try {
76
+						$sth = $this->db->prepare($query);
77
+						$sth->execute(array(':filter_name' => $filter_name));
78
+				} catch(PDOException $e) {
79
+						return "error : ".$e->getMessage();
80
+				}
81
+		}
82 82
 	public function getAllAirlineNames($filter_name = '') {
83 83
 		if ($filter_name == '') $filter_name = $this->filter_name;
84
-                $query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";
85
-                 try {
86
-                        $sth = $this->db->prepare($query);
87
-                        $sth->execute(array(':filter_name' => $filter_name));
88
-                } catch(PDOException $e) {
89
-                        echo "error : ".$e->getMessage();
90
-                }
91
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
92
-                return $all;
93
-        }
84
+				$query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";
85
+				 try {
86
+						$sth = $this->db->prepare($query);
87
+						$sth->execute(array(':filter_name' => $filter_name));
88
+				} catch(PDOException $e) {
89
+						echo "error : ".$e->getMessage();
90
+				}
91
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
92
+				return $all;
93
+		}
94 94
 	public function getAllAircraftTypes($stats_airline = '',$filter_name = '') {
95 95
 		if ($filter_name == '') $filter_name = $this->filter_name;
96
-                $query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";
97
-                 try {
98
-                        $sth = $this->db->prepare($query);
99
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
100
-                } catch(PDOException $e) {
101
-                        echo "error : ".$e->getMessage();
102
-                }
103
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
104
-                return $all;
105
-        }
96
+				$query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";
97
+				 try {
98
+						$sth = $this->db->prepare($query);
99
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
100
+				} catch(PDOException $e) {
101
+						echo "error : ".$e->getMessage();
102
+				}
103
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
104
+				return $all;
105
+		}
106 106
 	public function getAllManufacturers($stats_airline = '',$filter_name = '') {
107 107
 		if ($filter_name == '') $filter_name = $this->filter_name;
108
-                $query = "SELECT DISTINCT(aircraft_manufacturer) FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND aircraft_manufacturer <> '' ORDER BY aircraft_manufacturer ASC";
109
-                 try {
110
-                        $sth = $this->db->prepare($query);
111
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
112
-                } catch(PDOException $e) {
113
-                        echo "error : ".$e->getMessage();
114
-                }
115
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
116
-                return $all;
117
-        }
108
+				$query = "SELECT DISTINCT(aircraft_manufacturer) FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND aircraft_manufacturer <> '' ORDER BY aircraft_manufacturer ASC";
109
+				 try {
110
+						$sth = $this->db->prepare($query);
111
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
112
+				} catch(PDOException $e) {
113
+						echo "error : ".$e->getMessage();
114
+				}
115
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
116
+				return $all;
117
+		}
118 118
 	public function getAllAirportNames($stats_airline = '',$filter_name = '') {
119 119
 		if ($filter_name == '') $filter_name = $this->filter_name;
120
-                $query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND stats_type = 'daily' GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC";
121
-                 try {
122
-                        $sth = $this->db->prepare($query);
123
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
124
-                } catch(PDOException $e) {
125
-                        echo "error : ".$e->getMessage();
126
-                }
127
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
128
-                return $all;
129
-        }
120
+				$query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND stats_type = 'daily' GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC";
121
+				 try {
122
+						$sth = $this->db->prepare($query);
123
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
124
+				} catch(PDOException $e) {
125
+						echo "error : ".$e->getMessage();
126
+				}
127
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
128
+				return $all;
129
+		}
130 130
 
131 131
 	public function getAllOwnerNames($stats_airline = '',$filter_name = '') {
132 132
 		if ($filter_name == '') $filter_name = $this->filter_name;
133
-                $query = "SELECT owner_name FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_name ASC";
134
-                 try {
135
-                        $sth = $this->db->prepare($query);
136
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
137
-                } catch(PDOException $e) {
138
-                        echo "error : ".$e->getMessage();
139
-                }
140
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
141
-                return $all;
142
-        }
133
+				$query = "SELECT owner_name FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_name ASC";
134
+				 try {
135
+						$sth = $this->db->prepare($query);
136
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
137
+				} catch(PDOException $e) {
138
+						echo "error : ".$e->getMessage();
139
+				}
140
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
141
+				return $all;
142
+		}
143 143
 
144 144
 	public function getAllPilotNames($stats_airline = '',$filter_name = '') {
145 145
 		if ($filter_name == '') $filter_name = $this->filter_name;
146
-                $query = "SELECT pilot_id,pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_name ASC";
147
-                 try {
148
-                        $sth = $this->db->prepare($query);
149
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
150
-                } catch(PDOException $e) {
151
-                        echo "error : ".$e->getMessage();
152
-                }
153
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
154
-                return $all;
155
-        }
146
+				$query = "SELECT pilot_id,pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_name ASC";
147
+				 try {
148
+						$sth = $this->db->prepare($query);
149
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
150
+				} catch(PDOException $e) {
151
+						echo "error : ".$e->getMessage();
152
+				}
153
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
154
+				return $all;
155
+		}
156 156
 
157 157
 
158 158
 	public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') {
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
 			}
170 170
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
171 171
 		} else $all = array();
172
-                if (empty($all)) {
173
-            	    $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
174
-            	    if ($filter_name != '') {
175
-            		    $filters = array_merge($filters,$globalStatsFilters[$filter_name]);
176
-            	    }
177
-            	    $Spotter = new Spotter($this->db);
178
-            	    //$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters,$year,$month);
179
-            	    $all = $Spotter->countAllAircraftTypes($limit,0,'',$filters);
180
-                }
181
-                return $all;
172
+				if (empty($all)) {
173
+					$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
174
+					if ($filter_name != '') {
175
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
176
+					}
177
+					$Spotter = new Spotter($this->db);
178
+					//$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters,$year,$month);
179
+					$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters);
180
+				}
181
+				return $all;
182 182
 	}
183 183
 	public function countAllAirlineCountries($limit = true,$filter_name = '',$year = '',$month = '') {
184 184
 		global $globalStatsFilters;
@@ -194,17 +194,17 @@  discard block
 block discarded – undo
194 194
 			}
195 195
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
196 196
 		} else $all = array();
197
-                if (empty($all)) {
198
-            		$Spotter = new Spotter($this->db);
199
-            		$filters = array();
200
-            		$filters = array('year' => $year,'month' => $month);
201
-            		if ($filter_name != '') {
202
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
203
-			}
204
-            		//$all = $Spotter->countAllAirlineCountries($limit,$filters,$year,$month);
205
-            		$all = $Spotter->countAllAirlineCountries($limit,$filters);
206
-                }
207
-                return $all;
197
+				if (empty($all)) {
198
+					$Spotter = new Spotter($this->db);
199
+					$filters = array();
200
+					$filters = array('year' => $year,'month' => $month);
201
+					if ($filter_name != '') {
202
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
203
+			}
204
+					//$all = $Spotter->countAllAirlineCountries($limit,$filters,$year,$month);
205
+					$all = $Spotter->countAllAirlineCountries($limit,$filters);
206
+				}
207
+				return $all;
208 208
 	}
209 209
 	public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '',$year = '', $month = '') {
210 210
 		global $globalStatsFilters;
@@ -246,39 +246,39 @@  discard block
 block discarded – undo
246 246
 			}
247 247
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
248 248
 		} else $all = array();
249
-                if (empty($all)) {
249
+				if (empty($all)) {
250 250
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
251 251
 			if ($filter_name != '') {
252
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
252
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
253 253
 			}
254 254
 			$Spotter = new Spotter($this->db);
255 255
 			//$all = $Spotter->countAllArrivalCountries($limit,$filters,$year,$month);
256 256
 			$all = $Spotter->countAllArrivalCountries($limit,$filters);
257
-                }
258
-                return $all;
257
+				}
258
+				return $all;
259 259
 	}
260 260
 	public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '', $year = '', $month = '') {
261 261
 		global $globalStatsFilters;
262 262
 		if ($filter_name == '') $filter_name = $this->filter_name;
263 263
 		if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0";
264 264
 		else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC";
265
-                 try {
266
-                        $sth = $this->db->prepare($query);
267
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
268
-                } catch(PDOException $e) {
269
-                        echo "error : ".$e->getMessage();
270
-                }
271
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
272
-                if (empty($all)) {
265
+				 try {
266
+						$sth = $this->db->prepare($query);
267
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
268
+				} catch(PDOException $e) {
269
+						echo "error : ".$e->getMessage();
270
+				}
271
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
272
+				if (empty($all)) {
273 273
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
274 274
 			if ($filter_name != '') {
275
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
275
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
276 276
 			}
277 277
 			$Spotter = new Spotter($this->db);
278 278
 			//$all = $Spotter->countAllDepartureCountries($filters,$year,$month);
279 279
 			$all = $Spotter->countAllDepartureCountries($filters);
280
-                }
281
-                return $all;
280
+				}
281
+				return $all;
282 282
 	}
283 283
 
284 284
 	public function countAllAirlines($limit = true,$filter_name = '',$year = '',$month = '') {
@@ -304,17 +304,17 @@  discard block
 block discarded – undo
304 304
 			}
305 305
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
306 306
 		} else $all = array();
307
-                if (empty($all)) {
308
-	                $Spotter = new Spotter($this->db);
309
-            		$filters = array();
307
+				if (empty($all)) {
308
+					$Spotter = new Spotter($this->db);
309
+					$filters = array();
310 310
 			$filters = array('year' => $year,'month' => $month);
311
-            		if ($filter_name != '') {
312
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
311
+					if ($filter_name != '') {
312
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
313 313
 			}
314 314
 			//$all = $Spotter->countAllAirlines($limit,0,'',$filters,$year,$month);
315
-    		        $all = $Spotter->countAllAirlines($limit,0,'',$filters);
316
-                }
317
-                return $all;
315
+					$all = $Spotter->countAllAirlines($limit,0,'',$filters);
316
+				}
317
+				return $all;
318 318
 	}
319 319
 	public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
320 320
 		global $globalStatsFilters;
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
 			}
331 331
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
332 332
 		} else $all = array();
333
-                if (empty($all)) {
333
+				if (empty($all)) {
334 334
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
335 335
 			if ($filter_name != '') {
336 336
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
337 337
 			}
338
-	                $Spotter = new Spotter($this->db);
339
-    		        //$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters,$year,$month);
340
-    		        $all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters);
341
-                }
342
-                return $all;
338
+					$Spotter = new Spotter($this->db);
339
+					//$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters,$year,$month);
340
+					$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters);
341
+				}
342
+				return $all;
343 343
 	}
344 344
 	public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
345 345
 		global $globalStatsFilters;
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 					echo "error : ".$e->getMessage();
381 381
 				}
382 382
 				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
383
-                /*
383
+				/*
384 384
                 if (empty($all)) {
385 385
 	                $Spotter = new Spotter($this->db);
386 386
     		        $all = $Spotter->countAllFlightOverCountries($limit);
@@ -432,16 +432,16 @@  discard block
 block discarded – undo
432 432
 			}
433 433
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
434 434
 		} else $all = array();
435
-                if (empty($all)) {
435
+				if (empty($all)) {
436 436
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
437 437
 			if ($filter_name != '') {
438 438
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
439 439
 			}
440
-            		$Spotter = new Spotter($this->db);
441
-            		//$all = $Spotter->countAllOwners($limit,0,'',$filters,$year,$month);
442
-            		$all = $Spotter->countAllOwners($limit,0,'',$filters);
443
-                }
444
-                return $all;
440
+					$Spotter = new Spotter($this->db);
441
+					//$all = $Spotter->countAllOwners($limit,0,'',$filters,$year,$month);
442
+					$all = $Spotter->countAllOwners($limit,0,'',$filters);
443
+				}
444
+				return $all;
445 445
 	}
446 446
 	public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
447 447
 		global $globalStatsFilters;
@@ -457,35 +457,35 @@  discard block
 block discarded – undo
457 457
 			}
458 458
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
459 459
 		} else $all = array();
460
-                if (empty($all)) {
460
+				if (empty($all)) {
461 461
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
462
-            		if ($filter_name != '') {
463
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
462
+					if ($filter_name != '') {
463
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
464 464
 			}
465
-            		$Spotter = new Spotter($this->db);
465
+					$Spotter = new Spotter($this->db);
466 466
 //            		$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters,$year,$month);
467 467
   //      		$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters,$year,$month);
468
-            		$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters);
469
-        		$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters);
470
-        		$all = array();
471
-        		foreach ($pall as $value) {
472
-        			$icao = $value['airport_departure_icao'];
473
-        			$all[$icao] = $value;
474
-        		}
468
+					$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters);
469
+				$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters);
470
+				$all = array();
471
+				foreach ($pall as $value) {
472
+					$icao = $value['airport_departure_icao'];
473
+					$all[$icao] = $value;
474
+				}
475 475
         		
476
-        		foreach ($dall as $value) {
477
-        			$icao = $value['airport_departure_icao'];
478
-        			if (isset($all[$icao])) {
479
-        				$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
480
-        			} else $all[$icao] = $value;
481
-        		}
482
-        		$count = array();
483
-        		foreach ($all as $key => $row) {
484
-        			$count[$key] = $row['airport_departure_icao_count'];
485
-        		}
486
-        		array_multisort($count,SORT_DESC,$all);
487
-                }
488
-                return $all;
476
+				foreach ($dall as $value) {
477
+					$icao = $value['airport_departure_icao'];
478
+					if (isset($all[$icao])) {
479
+						$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
480
+					} else $all[$icao] = $value;
481
+				}
482
+				$count = array();
483
+				foreach ($all as $key => $row) {
484
+					$count[$key] = $row['airport_departure_icao_count'];
485
+				}
486
+				array_multisort($count,SORT_DESC,$all);
487
+				}
488
+				return $all;
489 489
 	}
490 490
 	public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
491 491
 		global $globalStatsFilters;
@@ -511,26 +511,26 @@  discard block
 block discarded – undo
511 511
 //			$dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters,$year,$month);
512 512
 			$pall = $Spotter->countAllArrivalAirports($limit,0,'',false,$filters);
513 513
 			$dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters);
514
-        		$all = array();
515
-        		foreach ($pall as $value) {
516
-        			$icao = $value['airport_arrival_icao'];
517
-        			$all[$icao] = $value;
518
-        		}
514
+				$all = array();
515
+				foreach ($pall as $value) {
516
+					$icao = $value['airport_arrival_icao'];
517
+					$all[$icao] = $value;
518
+				}
519 519
         		
520
-        		foreach ($dall as $value) {
521
-        			$icao = $value['airport_arrival_icao'];
522
-        			if (isset($all[$icao])) {
523
-        				$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
524
-        			} else $all[$icao] = $value;
525
-        		}
526
-        		$count = array();
527
-        		foreach ($all as $key => $row) {
528
-        			$count[$key] = $row['airport_arrival_icao_count'];
529
-        		}
530
-        		array_multisort($count,SORT_DESC,$all);
531
-                }
520
+				foreach ($dall as $value) {
521
+					$icao = $value['airport_arrival_icao'];
522
+					if (isset($all[$icao])) {
523
+						$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
524
+					} else $all[$icao] = $value;
525
+				}
526
+				$count = array();
527
+				foreach ($all as $key => $row) {
528
+					$count[$key] = $row['airport_arrival_icao_count'];
529
+				}
530
+				array_multisort($count,SORT_DESC,$all);
531
+				}
532 532
  
533
-                return $all;
533
+				return $all;
534 534
 	}
535 535
 	public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') {
536 536
 		global $globalDBdriver, $globalStatsFilters;
@@ -543,23 +543,23 @@  discard block
 block discarded – undo
543 543
 			else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
544 544
 		}
545 545
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
546
-                 try {
547
-                        $sth = $this->db->prepare($query);
548
-                        $sth->execute($query_data);
549
-                } catch(PDOException $e) {
550
-                        echo "error : ".$e->getMessage();
551
-                }
552
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
553
-                if (empty($all)) {
546
+				 try {
547
+						$sth = $this->db->prepare($query);
548
+						$sth->execute($query_data);
549
+				} catch(PDOException $e) {
550
+						echo "error : ".$e->getMessage();
551
+				}
552
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
553
+				if (empty($all)) {
554 554
 			$filters = array('airlines' => array($stats_airline));
555 555
 			if ($filter_name != '') {
556 556
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
557 557
 			}
558
-            		$Spotter = new Spotter($this->db);
559
-            		$all = $Spotter->countAllMonthsLastYear($filters);
560
-                }
558
+					$Spotter = new Spotter($this->db);
559
+					$all = $Spotter->countAllMonthsLastYear($filters);
560
+				}
561 561
                 
562
-                return $all;
562
+				return $all;
563 563
 	}
564 564
 	
565 565
 	public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') {
@@ -567,22 +567,22 @@  discard block
 block discarded – undo
567 567
 		if ($filter_name == '') $filter_name = $this->filter_name;
568 568
 		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline = :stats_airline AND filter_name = :filter_name";
569 569
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
570
-                 try {
571
-                        $sth = $this->db->prepare($query);
572
-                        $sth->execute($query_data);
573
-                } catch(PDOException $e) {
574
-                        echo "error : ".$e->getMessage();
575
-                }
576
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
577
-                if (empty($all)) {
570
+				 try {
571
+						$sth = $this->db->prepare($query);
572
+						$sth->execute($query_data);
573
+				} catch(PDOException $e) {
574
+						echo "error : ".$e->getMessage();
575
+				}
576
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
577
+				if (empty($all)) {
578 578
 			$filters = array('airlines' => array($stats_airline));
579 579
 			if ($filter_name != '') {
580 580
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
581 581
 			}
582
-            		$Spotter = new Spotter($this->db);
583
-            		$all = $Spotter->countAllDatesLastMonth($filters);
584
-                }
585
-                return $all;
582
+					$Spotter = new Spotter($this->db);
583
+					$all = $Spotter->countAllDatesLastMonth($filters);
584
+				}
585
+				return $all;
586 586
 	}
587 587
 	public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') {
588 588
 		global $globalDBdriver, $globalStatsFilters;
@@ -593,110 +593,110 @@  discard block
 block discarded – undo
593 593
 			$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND stats_airline = :stats_airline AND filter_name = :filter_name";
594 594
 		}
595 595
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
596
-                 try {
597
-                        $sth = $this->db->prepare($query);
598
-                        $sth->execute($query_data);
599
-                } catch(PDOException $e) {
600
-                        echo "error : ".$e->getMessage();
601
-                }
602
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
603
-                if (empty($all)) {
596
+				 try {
597
+						$sth = $this->db->prepare($query);
598
+						$sth->execute($query_data);
599
+				} catch(PDOException $e) {
600
+						echo "error : ".$e->getMessage();
601
+				}
602
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
603
+				if (empty($all)) {
604 604
 			$filters = array('airlines' => array($stats_airline));
605 605
 			if ($filter_name != '') {
606 606
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
607 607
 			}
608
-            		$Spotter = new Spotter($this->db);
609
-            		$all = $Spotter->countAllDatesLast7Days($filters);
610
-                }
611
-                return $all;
608
+					$Spotter = new Spotter($this->db);
609
+					$all = $Spotter->countAllDatesLast7Days($filters);
610
+				}
611
+				return $all;
612 612
 	}
613 613
 	public function countAllDates($stats_airline = '',$filter_name = '') {
614 614
 		global $globalStatsFilters;
615 615
 		if ($filter_name == '') $filter_name = $this->filter_name;
616 616
 		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline = :stats_airline AND filter_name = :filter_name";
617 617
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
618
-                 try {
619
-                        $sth = $this->db->prepare($query);
620
-                        $sth->execute($query_data);
621
-                } catch(PDOException $e) {
622
-                        echo "error : ".$e->getMessage();
623
-                }
624
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
625
-                if (empty($all)) {
618
+				 try {
619
+						$sth = $this->db->prepare($query);
620
+						$sth->execute($query_data);
621
+				} catch(PDOException $e) {
622
+						echo "error : ".$e->getMessage();
623
+				}
624
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
625
+				if (empty($all)) {
626 626
 			$filters = array('airlines' => array($stats_airline));
627 627
 			if ($filter_name != '') {
628
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
628
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
629 629
 			}
630
-            		$Spotter = new Spotter($this->db);
631
-            		$all = $Spotter->countAllDates($filters);
632
-                }
633
-                return $all;
630
+					$Spotter = new Spotter($this->db);
631
+					$all = $Spotter->countAllDates($filters);
632
+				}
633
+				return $all;
634 634
 	}
635 635
 	public function countAllDatesByAirlines($filter_name = '') {
636 636
 		global $globalStatsFilters;
637 637
 		if ($filter_name == '') $filter_name = $this->filter_name;
638 638
 		$query = "SELECT stats_airline as airline_icao, flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND filter_name = :filter_name";
639 639
 		$query_data = array('filter_name' => $filter_name);
640
-                 try {
641
-                        $sth = $this->db->prepare($query);
642
-                        $sth->execute($query_data);
643
-                } catch(PDOException $e) {
644
-                        echo "error : ".$e->getMessage();
645
-                }
646
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
647
-                if (empty($all)) {
648
-            		$filters = array();
649
-            		if ($filter_name != '') {
650
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
640
+				 try {
641
+						$sth = $this->db->prepare($query);
642
+						$sth->execute($query_data);
643
+				} catch(PDOException $e) {
644
+						echo "error : ".$e->getMessage();
645
+				}
646
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
647
+				if (empty($all)) {
648
+					$filters = array();
649
+					if ($filter_name != '') {
650
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
651 651
 			}
652
-            		$Spotter = new Spotter($this->db);
653
-            		$all = $Spotter->countAllDatesByAirlines($filters);
654
-                }
655
-                return $all;
652
+					$Spotter = new Spotter($this->db);
653
+					$all = $Spotter->countAllDatesByAirlines($filters);
654
+				}
655
+				return $all;
656 656
 	}
657 657
 	public function countAllMonths($stats_airline = '',$filter_name = '') {
658 658
 		global $globalStatsFilters;
659 659
 		if ($filter_name == '') $filter_name = $this->filter_name;
660
-	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
661
-                 try {
662
-                        $sth = $this->db->prepare($query);
663
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
664
-                } catch(PDOException $e) {
665
-                        echo "error : ".$e->getMessage();
666
-                }
667
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
660
+			$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
661
+				 try {
662
+						$sth = $this->db->prepare($query);
663
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
664
+				} catch(PDOException $e) {
665
+						echo "error : ".$e->getMessage();
666
+				}
667
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
668 668
                 
669
-                if (empty($all)) {
669
+				if (empty($all)) {
670 670
 			$filters = array('airlines' => array($stats_airline));
671 671
 			if ($filter_name != '') {
672 672
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
673 673
 			}
674
-            		$Spotter = new Spotter($this->db);
675
-            		$all = $Spotter->countAllMonths($filters);
676
-                }
674
+					$Spotter = new Spotter($this->db);
675
+					$all = $Spotter->countAllMonths($filters);
676
+				}
677 677
                 
678
-                return $all;
678
+				return $all;
679 679
 	}
680 680
 	public function countAllMilitaryMonths($filter_name = '') {
681 681
 		global $globalStatsFilters;
682 682
 		if ($filter_name == '') $filter_name = $this->filter_name;
683
-	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name";
684
-                 try {
685
-                        $sth = $this->db->prepare($query);
686
-                        $sth->execute(array(':filter_name' => $filter_name));
687
-                } catch(PDOException $e) {
688
-                        echo "error : ".$e->getMessage();
689
-                }
690
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
691
-                if (empty($all)) {
692
-            		$filters = array();
693
-            		if ($filter_name != '') {
694
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
683
+			$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name";
684
+				 try {
685
+						$sth = $this->db->prepare($query);
686
+						$sth->execute(array(':filter_name' => $filter_name));
687
+				} catch(PDOException $e) {
688
+						echo "error : ".$e->getMessage();
689
+				}
690
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
691
+				if (empty($all)) {
692
+					$filters = array();
693
+					if ($filter_name != '') {
694
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
695 695
 			}
696
-            		$Spotter = new Spotter($this->db);
697
-            		$all = $Spotter->countAllMilitaryMonths($filters);
698
-                }
699
-                return $all;
696
+					$Spotter = new Spotter($this->db);
697
+					$all = $Spotter->countAllMilitaryMonths($filters);
698
+				}
699
+				return $all;
700 700
 	}
701 701
 	public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') {
702 702
 		global $globalTimezone, $globalDBdriver, $globalStatsFilters;
@@ -712,22 +712,22 @@  discard block
 block discarded – undo
712 712
 			$query .= " ORDER BY CAST(flight_date AS integer) ASC";
713 713
 		}
714 714
 		if ($orderby == 'count') $query .= " ORDER BY hour_count DESC";
715
-                 try {
716
-                        $sth = $this->db->prepare($query);
717
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
718
-                } catch(PDOException $e) {
719
-                        echo "error : ".$e->getMessage();
720
-                }
721
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
722
-                if (empty($all)) {
715
+				 try {
716
+						$sth = $this->db->prepare($query);
717
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
718
+				} catch(PDOException $e) {
719
+						echo "error : ".$e->getMessage();
720
+				}
721
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
722
+				if (empty($all)) {
723 723
 			$filters = array('airlines' => array($stats_airline));
724 724
 			if ($filter_name != '') {
725
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
725
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
726 726
 			}
727
-            		$Spotter = new Spotter($this->db);
728
-            		$all = $Spotter->countAllHours($orderby,$filters);
729
-                }
730
-                return $all;
727
+					$Spotter = new Spotter($this->db);
728
+					$all = $Spotter->countAllHours($orderby,$filters);
729
+				}
730
+				return $all;
731 731
 	}
732 732
 	
733 733
 	public function countOverallFlights($stats_airline = '', $filter_name = '',$year = '',$month = '') {
@@ -752,10 +752,10 @@  discard block
 block discarded – undo
752 752
 		if ($year == '') $year = date('Y');
753 753
 		$all = $this->getSumStats('military_flights_bymonth',$year,'',$filter_name,$month);
754 754
 		if (empty($all)) {
755
-		        $filters = array();
755
+				$filters = array();
756 756
 			$filters = array('year' => $year,'month' => $month);
757
-            		if ($filter_name != '') {
758
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
757
+					if ($filter_name != '') {
758
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
759 759
 			}
760 760
 			$Spotter = new Spotter($this->db);
761 761
 			//$all = $Spotter->countOverallMilitaryFlights($filters,$year,$month);
@@ -819,10 +819,10 @@  discard block
 block discarded – undo
819 819
 			$all = $result[0]['nb_airline'];
820 820
 		} else $all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month);
821 821
 		if (empty($all)) {
822
-            		$filters = array();
822
+					$filters = array();
823 823
 			$filters = array('year' => $year,'month' => $month);
824
-            		if ($filter_name != '') {
825
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
824
+					if ($filter_name != '') {
825
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
826 826
 			}
827 827
 			$Spotter = new Spotter($this->db);
828 828
 			//$all = $Spotter->countOverallAirlines($filters,$year,$month);
@@ -892,33 +892,33 @@  discard block
 block discarded – undo
892 892
 		if ($filter_name == '') $filter_name = $this->filter_name;
893 893
 		$query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date";
894 894
 		$query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
895
-                 try {
896
-                        $sth = $this->db->prepare($query);
897
-                        $sth->execute($query_values);
898
-                } catch(PDOException $e) {
899
-                        echo "error : ".$e->getMessage();
900
-                }
901
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
902
-                return $all;
895
+				 try {
896
+						$sth = $this->db->prepare($query);
897
+						$sth->execute($query_values);
898
+				} catch(PDOException $e) {
899
+						echo "error : ".$e->getMessage();
900
+				}
901
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
902
+				return $all;
903 903
 	}
904 904
 	public function getStats($type,$stats_airline = '', $filter_name = '') {
905 905
 		if ($filter_name == '') $filter_name = $this->filter_name;
906
-                $query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";
907
-                $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
908
-                 try {
909
-                        $sth = $this->db->prepare($query);
910
-                        $sth->execute($query_values);
911
-                } catch(PDOException $e) {
912
-                        echo "error : ".$e->getMessage();
913
-                }
914
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
915
-                return $all;
916
-        }
906
+				$query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";
907
+				$query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
908
+				 try {
909
+						$sth = $this->db->prepare($query);
910
+						$sth->execute($query_values);
911
+				} catch(PDOException $e) {
912
+						echo "error : ".$e->getMessage();
913
+				}
914
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
915
+				return $all;
916
+		}
917 917
 	public function getSumStats($type,$year,$stats_airline = '',$filter_name = '',$month = '') {
918 918
 		if ($filter_name == '') $filter_name = $this->filter_name;
919
-    		global $globalArchiveMonths, $globalDBdriver;
920
-    		if ($globalDBdriver == 'mysql') {
921
-    			if ($month == '') {
919
+			global $globalArchiveMonths, $globalDBdriver;
920
+			if ($globalDBdriver == 'mysql') {
921
+				if ($month == '') {
922 922
 				$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name";
923 923
 				$query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
924 924
 			} else {
@@ -933,165 +933,165 @@  discard block
 block discarded – undo
933 933
 				$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND EXTRACT(MONTH FROM stats_date) = :month AND stats_airline = :stats_airline AND filter_name = :filter_name";
934 934
 				$query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name,':month' => $month);
935 935
 			}
936
-                }
937
-                 try {
938
-                        $sth = $this->db->prepare($query);
939
-                        $sth->execute($query_values);
940
-                } catch(PDOException $e) {
941
-                        echo "error : ".$e->getMessage();
942
-                }
943
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
944
-                return $all[0]['total'];
945
-        }
936
+				}
937
+				 try {
938
+						$sth = $this->db->prepare($query);
939
+						$sth->execute($query_values);
940
+				} catch(PDOException $e) {
941
+						echo "error : ".$e->getMessage();
942
+				}
943
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
944
+				return $all[0]['total'];
945
+		}
946 946
 	public function getStatsTotal($type, $stats_airline = '', $filter_name = '') {
947
-    		global $globalArchiveMonths, $globalDBdriver;
947
+			global $globalArchiveMonths, $globalDBdriver;
948 948
 		if ($filter_name == '') $filter_name = $this->filter_name;
949
-    		if ($globalDBdriver == 'mysql') {
949
+			if ($globalDBdriver == 'mysql') {
950 950
 			$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";
951 951
 		} else {
952 952
 			$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name";
953
-                }
954
-                $query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
955
-                 try {
956
-                        $sth = $this->db->prepare($query);
957
-                        $sth->execute($query_values);
958
-                } catch(PDOException $e) {
959
-                        echo "error : ".$e->getMessage();
960
-                }
961
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
962
-                return $all[0]['total'];
963
-        }
953
+				}
954
+				$query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
955
+				 try {
956
+						$sth = $this->db->prepare($query);
957
+						$sth->execute($query_values);
958
+				} catch(PDOException $e) {
959
+						echo "error : ".$e->getMessage();
960
+				}
961
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
962
+				return $all[0]['total'];
963
+		}
964 964
 	public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') {
965
-    		global $globalArchiveMonths, $globalDBdriver;
965
+			global $globalArchiveMonths, $globalDBdriver;
966 966
 		if ($filter_name == '') $filter_name = $this->filter_name;
967
-    		if ($globalDBdriver == 'mysql') {
967
+			if ($globalDBdriver == 'mysql') {
968 968
 			$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
969
-                } else {
969
+				} else {
970 970
 			$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
971
-                }
972
-                 try {
973
-                        $sth = $this->db->prepare($query);
974
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
975
-                } catch(PDOException $e) {
976
-                        echo "error : ".$e->getMessage();
977
-                }
978
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
979
-                return $all[0]['total'];
980
-        }
971
+				}
972
+				 try {
973
+						$sth = $this->db->prepare($query);
974
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
975
+				} catch(PDOException $e) {
976
+						echo "error : ".$e->getMessage();
977
+				}
978
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
979
+				return $all[0]['total'];
980
+		}
981 981
 	public function getStatsAirlineTotal($filter_name = '') {
982
-    		global $globalArchiveMonths, $globalDBdriver;
982
+			global $globalArchiveMonths, $globalDBdriver;
983 983
 		if ($filter_name == '') $filter_name = $this->filter_name;
984
-    		if ($globalDBdriver == 'mysql') {
984
+			if ($globalDBdriver == 'mysql') {
985 985
 			$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";
986
-                } else {
986
+				} else {
987 987
 			$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";
988
-                }
989
-                 try {
990
-                        $sth = $this->db->prepare($query);
991
-                        $sth->execute(array(':filter_name' => $filter_name));
992
-                } catch(PDOException $e) {
993
-                        echo "error : ".$e->getMessage();
994
-                }
995
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
996
-                return $all[0]['total'];
997
-        }
988
+				}
989
+				 try {
990
+						$sth = $this->db->prepare($query);
991
+						$sth->execute(array(':filter_name' => $filter_name));
992
+				} catch(PDOException $e) {
993
+						echo "error : ".$e->getMessage();
994
+				}
995
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
996
+				return $all[0]['total'];
997
+		}
998 998
 	public function getStatsOwnerTotal($filter_name = '') {
999
-    		global $globalArchiveMonths, $globalDBdriver;
999
+			global $globalArchiveMonths, $globalDBdriver;
1000 1000
 		if ($filter_name == '') $filter_name = $this->filter_name;
1001
-    		if ($globalDBdriver == 'mysql') {
1001
+			if ($globalDBdriver == 'mysql') {
1002 1002
 			$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";
1003 1003
 		} else {
1004 1004
 			$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";
1005
-                }
1006
-                 try {
1007
-                        $sth = $this->db->prepare($query);
1008
-                        $sth->execute(array(':filter_name' => $filter_name));
1009
-                } catch(PDOException $e) {
1010
-                        echo "error : ".$e->getMessage();
1011
-                }
1012
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1013
-                return $all[0]['total'];
1014
-        }
1005
+				}
1006
+				 try {
1007
+						$sth = $this->db->prepare($query);
1008
+						$sth->execute(array(':filter_name' => $filter_name));
1009
+				} catch(PDOException $e) {
1010
+						echo "error : ".$e->getMessage();
1011
+				}
1012
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1013
+				return $all[0]['total'];
1014
+		}
1015 1015
 	public function getStatsOwner($owner_name,$filter_name = '') {
1016
-    		global $globalArchiveMonths, $globalDBdriver;
1016
+			global $globalArchiveMonths, $globalDBdriver;
1017 1017
 		if ($filter_name == '') $filter_name = $this->filter_name;
1018 1018
 		$query = "SELECT cnt FROM stats_owner WHERE filter_name = :filter_name AND owner_name = :owner_name";
1019
-                 try {
1020
-                        $sth = $this->db->prepare($query);
1021
-                        $sth->execute(array(':filter_name' => $filter_name,':owner_name' => $owner_name));
1022
-                } catch(PDOException $e) {
1023
-                        echo "error : ".$e->getMessage();
1024
-                }
1025
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1026
-                if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1027
-                else return 0;
1028
-        }
1019
+				 try {
1020
+						$sth = $this->db->prepare($query);
1021
+						$sth->execute(array(':filter_name' => $filter_name,':owner_name' => $owner_name));
1022
+				} catch(PDOException $e) {
1023
+						echo "error : ".$e->getMessage();
1024
+				}
1025
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1026
+				if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1027
+				else return 0;
1028
+		}
1029 1029
 	public function getStatsPilotTotal($filter_name = '') {
1030
-    		global $globalArchiveMonths, $globalDBdriver;
1030
+			global $globalArchiveMonths, $globalDBdriver;
1031 1031
 		if ($filter_name == '') $filter_name = $this->filter_name;
1032
-    		if ($globalDBdriver == 'mysql') {
1033
-            		$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
1034
-            	} else {
1035
-            		$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
1036
-            	}
1037
-                 try {
1038
-                        $sth = $this->db->prepare($query);
1039
-                        $sth->execute(array(':filter_name' => $filter_name));
1040
-                } catch(PDOException $e) {
1041
-                        echo "error : ".$e->getMessage();
1042
-                }
1043
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1044
-                return $all[0]['total'];
1045
-        }
1032
+			if ($globalDBdriver == 'mysql') {
1033
+					$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
1034
+				} else {
1035
+					$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
1036
+				}
1037
+				 try {
1038
+						$sth = $this->db->prepare($query);
1039
+						$sth->execute(array(':filter_name' => $filter_name));
1040
+				} catch(PDOException $e) {
1041
+						echo "error : ".$e->getMessage();
1042
+				}
1043
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1044
+				return $all[0]['total'];
1045
+		}
1046 1046
 	public function getStatsPilot($pilot,$filter_name = '') {
1047
-    		global $globalArchiveMonths, $globalDBdriver;
1047
+			global $globalArchiveMonths, $globalDBdriver;
1048 1048
 		if ($filter_name == '') $filter_name = $this->filter_name;
1049 1049
 		$query = "SELECT cnt FROM stats_pilot WHERE filter_name = :filter_name AND (pilot_name = :pilot OR pilot_id = :pilot)";
1050
-                 try {
1051
-                        $sth = $this->db->prepare($query);
1052
-                        $sth->execute(array(':filter_name' => $filter_name,':pilot' => $pilot));
1053
-                } catch(PDOException $e) {
1054
-                        echo "error : ".$e->getMessage();
1055
-                }
1056
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1057
-                if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1058
-                else return 0;
1059
-        }
1050
+				 try {
1051
+						$sth = $this->db->prepare($query);
1052
+						$sth->execute(array(':filter_name' => $filter_name,':pilot' => $pilot));
1053
+				} catch(PDOException $e) {
1054
+						echo "error : ".$e->getMessage();
1055
+				}
1056
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1057
+				if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1058
+				else return 0;
1059
+		}
1060 1060
 
1061 1061
 	public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
1062 1062
 		global $globalDBdriver;
1063 1063
 		if ($filter_name == '') $filter_name = $this->filter_name;
1064 1064
 		if ($globalDBdriver == 'mysql') {
1065 1065
 			$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt";
1066
-                } else {
1066
+				} else {
1067 1067
 			$query = "UPDATE stats SET cnt = :cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1068 1068
 		}
1069
-                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1070
-                 try {
1071
-                        $sth = $this->db->prepare($query);
1072
-                        $sth->execute($query_values);
1073
-                } catch(PDOException $e) {
1074
-                        return "error : ".$e->getMessage();
1075
-                }
1076
-        }
1069
+				$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1070
+				 try {
1071
+						$sth = $this->db->prepare($query);
1072
+						$sth->execute($query_values);
1073
+				} catch(PDOException $e) {
1074
+						return "error : ".$e->getMessage();
1075
+				}
1076
+		}
1077 1077
 	public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
1078 1078
 		global $globalDBdriver;
1079 1079
 		if ($filter_name == '') $filter_name = $this->filter_name;
1080 1080
 		if ($globalDBdriver == 'mysql') {
1081 1081
 			$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
1082 1082
 		} else {
1083
-            		//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
1083
+					//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
1084 1084
 			$query = "UPDATE stats SET cnt = cnt+:cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1085
-                }
1086
-                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1087
-                 try {
1088
-                        $sth = $this->db->prepare($query);
1089
-                        $sth->execute($query_values);
1090
-                } catch(PDOException $e) {
1091
-                        return "error : ".$e->getMessage();
1092
-                }
1093
-        }
1094
-        /*
1085
+				}
1086
+				$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1087
+				 try {
1088
+						$sth = $this->db->prepare($query);
1089
+						$sth->execute($query_values);
1090
+				} catch(PDOException $e) {
1091
+						return "error : ".$e->getMessage();
1092
+				}
1093
+		}
1094
+		/*
1095 1095
 	public function getStatsSource($date,$stats_type = '') {
1096 1096
 		if ($stats_type == '') {
1097 1097
 			$query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name";
@@ -1160,25 +1160,25 @@  discard block
 block discarded – undo
1160 1160
 			$query = "INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) VALUES (:data,:source_name,:stats_type,:stats_date) ON DUPLICATE KEY UPDATE source_data = :data";
1161 1161
 		} else {
1162 1162
 			$query = "UPDATE stats_source SET source_data = :data WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type; INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) SELECT :data,:source_name,:stats_type,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats_source WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type);"; 
1163
-                }
1164
-                $query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
1165
-                 try {
1166
-                        $sth = $this->db->prepare($query);
1167
-                        $sth->execute($query_values);
1168
-                } catch(PDOException $e) {
1169
-                        return "error : ".$e->getMessage();
1170
-                }
1171
-        }
1172
-	public function addStatFlight($type,$date_name,$cnt,$stats_airline = '',$filter_name = '') {
1173
-                $query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)";
1174
-                $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1175
-                 try {
1176
-                        $sth = $this->db->prepare($query);
1177
-                        $sth->execute($query_values);
1178
-                } catch(PDOException $e) {
1179
-                        return "error : ".$e->getMessage();
1180
-                }
1181
-        }
1163
+				}
1164
+				$query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
1165
+				 try {
1166
+						$sth = $this->db->prepare($query);
1167
+						$sth->execute($query_values);
1168
+				} catch(PDOException $e) {
1169
+						return "error : ".$e->getMessage();
1170
+				}
1171
+		}
1172
+	public function addStatFlight($type,$date_name,$cnt,$stats_airline = '',$filter_name = '') {
1173
+				$query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)";
1174
+				$query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1175
+				 try {
1176
+						$sth = $this->db->prepare($query);
1177
+						$sth->execute($query_values);
1178
+				} catch(PDOException $e) {
1179
+						return "error : ".$e->getMessage();
1180
+				}
1181
+		}
1182 1182
 	public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '',$airline_icao = '',$filter_name = '',$reset = false) {
1183 1183
 		global $globalDBdriver;
1184 1184
 		if ($globalDBdriver == 'mysql') {
@@ -1194,14 +1194,14 @@  discard block
 block discarded – undo
1194 1194
 				$query = "UPDATE stats_registration SET cnt = cnt+:cnt WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:registration,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1195 1195
 			}
1196 1196
 		}
1197
-                $query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
1198
-                 try {
1199
-                        $sth = $this->db->prepare($query);
1200
-                        $sth->execute($query_values);
1201
-                } catch(PDOException $e) {
1202
-                        return "error : ".$e->getMessage();
1203
-                }
1204
-        }
1197
+				$query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
1198
+				 try {
1199
+						$sth = $this->db->prepare($query);
1200
+						$sth->execute($query_values);
1201
+				} catch(PDOException $e) {
1202
+						return "error : ".$e->getMessage();
1203
+				}
1204
+		}
1205 1205
 	public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '', $filter_name = '', $reset = false) {
1206 1206
 		global $globalDBdriver;
1207 1207
 		if ($globalDBdriver == 'mysql') {
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
 				$query = "UPDATE stats_callsign SET cnt = cnt+:cnt WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) SELECT :callsign_icao,:airline_icao,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name);"; 
1218 1218
 			}
1219 1219
 		}
1220
-                $query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name);
1221
-                 try {
1222
-                        $sth = $this->db->prepare($query);
1223
-                        $sth->execute($query_values);
1224
-                } catch(PDOException $e) {
1225
-                        return "error : ".$e->getMessage();
1226
-                }
1227
-        }
1220
+				$query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name);
1221
+				 try {
1222
+						$sth = $this->db->prepare($query);
1223
+						$sth->execute($query_values);
1224
+				} catch(PDOException $e) {
1225
+						return "error : ".$e->getMessage();
1226
+				}
1227
+		}
1228 1228
 	public function addStatCountry($iso2,$iso3,$name,$cnt,$airline_icao = '',$filter_name = '',$reset = false) {
1229 1229
 		global $globalDBdriver;
1230 1230
 		if ($globalDBdriver == 'mysql') {
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
 				$query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline; INSERT INTO stats_country (iso2,iso3,name,cnt,stats_airline,filter_name) SELECT :iso2,:iso3,:name,:cnt,:airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2 AND filter_name = :filter_name AND stats_airline = :airline);"; 
1241 1241
 			}
1242 1242
 		}
1243
-                $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name,':airline' => $airline_icao);
1244
-                 try {
1245
-                        $sth = $this->db->prepare($query);
1246
-                        $sth->execute($query_values);
1247
-                } catch(PDOException $e) {
1248
-                        return "error : ".$e->getMessage();
1249
-                }
1250
-        }
1243
+				$query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name,':airline' => $airline_icao);
1244
+				 try {
1245
+						$sth = $this->db->prepare($query);
1246
+						$sth->execute($query_values);
1247
+				} catch(PDOException $e) {
1248
+						return "error : ".$e->getMessage();
1249
+				}
1250
+		}
1251 1251
 	public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '',$aircraft_manufacturer = '', $airline_icao = '', $filter_name = '', $reset = false) {
1252 1252
 		global $globalDBdriver;
1253 1253
 		if ($globalDBdriver == 'mysql') {
@@ -1263,14 +1263,14 @@  discard block
 block discarded – undo
1263 1263
 				$query = "UPDATE stats_aircraft SET cnt = cnt+:cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, filter_name = :filter_name WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1264 1264
 			}
1265 1265
 		}
1266
-                $query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt, ':aircraft_manufacturer' => $aircraft_manufacturer,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
1267
-                 try {
1268
-                        $sth = $this->db->prepare($query);
1269
-                        $sth->execute($query_values);
1270
-                } catch(PDOException $e) {
1271
-                        return "error : ".$e->getMessage();
1272
-                }
1273
-        }
1266
+				$query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt, ':aircraft_manufacturer' => $aircraft_manufacturer,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
1267
+				 try {
1268
+						$sth = $this->db->prepare($query);
1269
+						$sth->execute($query_values);
1270
+				} catch(PDOException $e) {
1271
+						return "error : ".$e->getMessage();
1272
+				}
1273
+		}
1274 1274
 	public function addStatAirline($airline_icao,$cnt,$airline_name = '',$filter_name = '', $reset = false) {
1275 1275
 		global $globalDBdriver;
1276 1276
 		if ($globalDBdriver == 'mysql') {
@@ -1286,14 +1286,14 @@  discard block
 block discarded – undo
1286 1286
 				$query = "UPDATE stats_airline SET cnt = cnt+:cnt WHERE airline_icao = :airline_icao AND filter_name = :filter_name; INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) SELECT :airline_icao,:airline_name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao AND filter_name = :filter_name);"; 
1287 1287
 			}
1288 1288
 		}
1289
-                $query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name);
1290
-                 try {
1291
-                        $sth = $this->db->prepare($query);
1292
-                        $sth->execute($query_values);
1293
-                } catch(PDOException $e) {
1294
-                        return "error : ".$e->getMessage();
1295
-                }
1296
-        }
1289
+				$query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name);
1290
+				 try {
1291
+						$sth = $this->db->prepare($query);
1292
+						$sth->execute($query_values);
1293
+				} catch(PDOException $e) {
1294
+						return "error : ".$e->getMessage();
1295
+				}
1296
+		}
1297 1297
 	public function addStatOwner($owner_name,$cnt,$stats_airline = '', $filter_name = '', $reset = false) {
1298 1298
 		global $globalDBdriver;
1299 1299
 		if ($globalDBdriver == 'mysql') {
@@ -1309,14 +1309,14 @@  discard block
 block discarded – undo
1309 1309
 				$query = "UPDATE stats_owner SET cnt = cnt+:cnt WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) SELECT :owner_name,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1310 1310
 			}
1311 1311
 		}
1312
-                $query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1313
-                 try {
1314
-                        $sth = $this->db->prepare($query);
1315
-                        $sth->execute($query_values);
1316
-                } catch(PDOException $e) {
1317
-                        return "error : ".$e->getMessage();
1318
-                }
1319
-        }
1312
+				$query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1313
+				 try {
1314
+						$sth = $this->db->prepare($query);
1315
+						$sth->execute($query_values);
1316
+				} catch(PDOException $e) {
1317
+						return "error : ".$e->getMessage();
1318
+				}
1319
+		}
1320 1320
 	public function addStatPilot($pilot_id,$cnt,$pilot_name,$stats_airline = '',$filter_name = '',$format_source = '',$reset = false) {
1321 1321
 		global $globalDBdriver;
1322 1322
 		if ($globalDBdriver == 'mysql') {
@@ -1332,14 +1332,14 @@  discard block
 block discarded – undo
1332 1332
 				$query = "UPDATE stats_pilot SET cnt = cnt+:cnt, pilot_name = :pilot_name WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source; INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name,format_source) SELECT :pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name,:format_source WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name AND format_source = :format_source);"; 
1333 1333
 			}
1334 1334
 		}
1335
-                $query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name,':format_source' => $format_source);
1336
-                 try {
1337
-                        $sth = $this->db->prepare($query);
1338
-                        $sth->execute($query_values);
1339
-                } catch(PDOException $e) {
1340
-                        return "error : ".$e->getMessage();
1341
-                }
1342
-        }
1335
+				$query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name,':format_source' => $format_source);
1336
+				 try {
1337
+						$sth = $this->db->prepare($query);
1338
+						$sth->execute($query_values);
1339
+				} catch(PDOException $e) {
1340
+						return "error : ".$e->getMessage();
1341
+				}
1342
+		}
1343 1343
 	public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '',$reset = false) {
1344 1344
 		global $globalDBdriver;
1345 1345
 		if ($airport_icao != '') {
@@ -1363,8 +1363,8 @@  discard block
 block discarded – undo
1363 1363
 			} catch(PDOException $e) {
1364 1364
 				return "error : ".$e->getMessage();
1365 1365
 			}
1366
-                }
1367
-        }
1366
+				}
1367
+		}
1368 1368
 	public function addStatDepartureAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') {
1369 1369
 		global $globalDBdriver;
1370 1370
 		if ($airport_icao != '') {
@@ -1380,8 +1380,8 @@  discard block
 block discarded – undo
1380 1380
 			} catch(PDOException $e) {
1381 1381
 				return "error : ".$e->getMessage();
1382 1382
 			}
1383
-                }
1384
-        }
1383
+				}
1384
+		}
1385 1385
 	public function addStatArrivalAirports($airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '',$reset = false) {
1386 1386
 		global $globalDBdriver;
1387 1387
 		if ($airport_icao != '') {
@@ -1398,15 +1398,15 @@  discard block
 block discarded – undo
1398 1398
 					$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; 
1399 1399
 				}
1400 1400
 			}
1401
-	                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival,':date' => date('Y').'-01-01 00:00:00',':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1401
+					$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival,':date' => date('Y').'-01-01 00:00:00',':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1402 1402
 			 try {
1403
-                    		$sth = $this->db->prepare($query);
1404
-	                        $sth->execute($query_values);
1405
-    		        } catch(PDOException $e) {
1406
-            		        return "error : ".$e->getMessage();
1407
-	                }
1408
-	        }
1409
-        }
1403
+							$sth = $this->db->prepare($query);
1404
+							$sth->execute($query_values);
1405
+					} catch(PDOException $e) {
1406
+							return "error : ".$e->getMessage();
1407
+					}
1408
+			}
1409
+		}
1410 1410
 	public function addStatArrivalAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') {
1411 1411
 		global $globalDBdriver;
1412 1412
 		if ($airport_icao != '') {
@@ -1422,46 +1422,46 @@  discard block
 block discarded – undo
1422 1422
 			} catch(PDOException $e) {
1423 1423
 				return "error : ".$e->getMessage();
1424 1424
 			}
1425
-                }
1426
-        }
1425
+				}
1426
+		}
1427 1427
 
1428 1428
 	public function deleteStat($id) {
1429
-                $query = "DELETE FROM stats WHERE stats_id = :id";
1430
-                $query_values = array(':id' => $id);
1431
-                 try {
1432
-                        $sth = $this->db->prepare($query);
1433
-                        $sth->execute($query_values);
1434
-                } catch(PDOException $e) {
1435
-                        return "error : ".$e->getMessage();
1436
-                }
1437
-        }
1429
+				$query = "DELETE FROM stats WHERE stats_id = :id";
1430
+				$query_values = array(':id' => $id);
1431
+				 try {
1432
+						$sth = $this->db->prepare($query);
1433
+						$sth->execute($query_values);
1434
+				} catch(PDOException $e) {
1435
+						return "error : ".$e->getMessage();
1436
+				}
1437
+		}
1438 1438
 	public function deleteStatFlight($type) {
1439
-                $query = "DELETE FROM stats_flight WHERE stats_type = :type";
1440
-                $query_values = array(':type' => $type);
1441
-                 try {
1442
-                        $sth = $this->db->prepare($query);
1443
-                        $sth->execute($query_values);
1444
-                } catch(PDOException $e) {
1445
-                        return "error : ".$e->getMessage();
1446
-                }
1447
-        }
1439
+				$query = "DELETE FROM stats_flight WHERE stats_type = :type";
1440
+				$query_values = array(':type' => $type);
1441
+				 try {
1442
+						$sth = $this->db->prepare($query);
1443
+						$sth->execute($query_values);
1444
+				} catch(PDOException $e) {
1445
+						return "error : ".$e->getMessage();
1446
+				}
1447
+		}
1448 1448
 	public function deleteStatAirport($type) {
1449
-                $query = "DELETE FROM stats_airport WHERE stats_type = :type";
1450
-                $query_values = array(':type' => $type);
1451
-                 try {
1452
-                        $sth = $this->db->prepare($query);
1453
-                        $sth->execute($query_values);
1454
-                } catch(PDOException $e) {
1455
-                        return "error : ".$e->getMessage();
1456
-                }
1457
-        }
1449
+				$query = "DELETE FROM stats_airport WHERE stats_type = :type";
1450
+				$query_values = array(':type' => $type);
1451
+				 try {
1452
+						$sth = $this->db->prepare($query);
1453
+						$sth->execute($query_values);
1454
+				} catch(PDOException $e) {
1455
+						return "error : ".$e->getMessage();
1456
+				}
1457
+		}
1458 1458
         
1459
-        public function addOldStats() {
1460
-    		global $globalDebug, $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters,$globalDeleteLastYearStats,$globalStatsReset,$globalStatsResetYear;
1461
-    		$Common = new Common();
1462
-    		$Connection = new Connection();
1463
-    		date_default_timezone_set('UTC');
1464
-    		$last_update = $this->getLastStatsUpdate('last_update_stats');
1459
+		public function addOldStats() {
1460
+			global $globalDebug, $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters,$globalDeleteLastYearStats,$globalStatsReset,$globalStatsResetYear;
1461
+			$Common = new Common();
1462
+			$Connection = new Connection();
1463
+			date_default_timezone_set('UTC');
1464
+			$last_update = $this->getLastStatsUpdate('last_update_stats');
1465 1465
 			if ($globalDebug) echo 'Update stats !'."\n";
1466 1466
 			if (isset($last_update[0]['value'])) {
1467 1467
 				$last_update_day = $last_update[0]['value'];
@@ -1508,24 +1508,24 @@  discard block
 block discarded – undo
1508 1508
 			if ($globalDebug) echo 'Count all departure airports...'."\n";
1509 1509
 			$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day);
1510 1510
 			if ($globalDebug) echo 'Count all detected departure airports...'."\n";
1511
-        		$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1511
+				$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1512 1512
 			if ($globalDebug) echo 'Order departure airports...'."\n";
1513
-	        	$alldata = array();
1513
+				$alldata = array();
1514 1514
 	        	
1515
-    			foreach ($pall as $value) {
1516
-	        		$icao = $value['airport_departure_icao'];
1517
-    				$alldata[$icao] = $value;
1518
-	        	}
1519
-	        	foreach ($dall as $value) {
1520
-    				$icao = $value['airport_departure_icao'];
1521
-        			if (isset($alldata[$icao])) {
1522
-    					$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1523
-        			} else $alldata[$icao] = $value;
1524
-			}
1525
-    			$count = array();
1526
-    			foreach ($alldata as $key => $row) {
1527
-    				$count[$key] = $row['airport_departure_icao_count'];
1528
-        		}
1515
+				foreach ($pall as $value) {
1516
+					$icao = $value['airport_departure_icao'];
1517
+					$alldata[$icao] = $value;
1518
+				}
1519
+				foreach ($dall as $value) {
1520
+					$icao = $value['airport_departure_icao'];
1521
+					if (isset($alldata[$icao])) {
1522
+						$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1523
+					} else $alldata[$icao] = $value;
1524
+			}
1525
+				$count = array();
1526
+				foreach ($alldata as $key => $row) {
1527
+					$count[$key] = $row['airport_departure_icao_count'];
1528
+				}
1529 1529
 			array_multisort($count,SORT_DESC,$alldata);
1530 1530
 			foreach ($alldata as $number) {
1531 1531
 				echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'','',$reset);
@@ -1533,25 +1533,25 @@  discard block
 block discarded – undo
1533 1533
 			if ($globalDebug) echo 'Count all arrival airports...'."\n";
1534 1534
 			$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day);
1535 1535
 			if ($globalDebug) echo 'Count all detected arrival airports...'."\n";
1536
-        		$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1536
+				$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1537 1537
 			if ($globalDebug) echo 'Order arrival airports...'."\n";
1538
-	        	$alldata = array();
1539
-    			foreach ($pall as $value) {
1540
-	        		$icao = $value['airport_arrival_icao'];
1541
-    				$alldata[$icao] = $value;
1542
-	        	}
1543
-	        	foreach ($dall as $value) {
1544
-    				$icao = $value['airport_arrival_icao'];
1545
-        			if (isset($alldata[$icao])) {
1546
-        				$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1547
-	        		} else $alldata[$icao] = $value;
1548
-    			}
1549
-        		$count = array();
1550
-        		foreach ($alldata as $key => $row) {
1551
-        			$count[$key] = $row['airport_arrival_icao_count'];
1552
-	        	}
1553
-    			array_multisort($count,SORT_DESC,$alldata);
1554
-                        foreach ($alldata as $number) {
1538
+				$alldata = array();
1539
+				foreach ($pall as $value) {
1540
+					$icao = $value['airport_arrival_icao'];
1541
+					$alldata[$icao] = $value;
1542
+				}
1543
+				foreach ($dall as $value) {
1544
+					$icao = $value['airport_arrival_icao'];
1545
+					if (isset($alldata[$icao])) {
1546
+						$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1547
+					} else $alldata[$icao] = $value;
1548
+				}
1549
+				$count = array();
1550
+				foreach ($alldata as $key => $row) {
1551
+					$count[$key] = $row['airport_arrival_icao_count'];
1552
+				}
1553
+				array_multisort($count,SORT_DESC,$alldata);
1554
+						foreach ($alldata as $number) {
1555 1555
 				echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'','',$reset);
1556 1556
 			}
1557 1557
 			if ($Connection->tableExists('countries')) {
@@ -1611,8 +1611,8 @@  discard block
 block discarded – undo
1611 1611
 //			$pall = $Spotter->getLast7DaysAirportsDeparture();
1612 1612
   //      		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1613 1613
 			$pall = $Spotter->getLast7DaysAirportsDeparture();
1614
-        		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1615
-        		/*
1614
+				$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1615
+				/*
1616 1616
 	        	$alldata = array();
1617 1617
     			foreach ($pall as $value) {
1618 1618
 	        		$icao = $value['departure_airport_icao'];
@@ -1631,29 +1631,29 @@  discard block
 block discarded – undo
1631 1631
 	        	}
1632 1632
     			array_multisort($count,SORT_DESC,$alldata);
1633 1633
     			*/
1634
-    			foreach ($dall as $value) {
1635
-    				$icao = $value['departure_airport_icao'];
1636
-    				$ddate = $value['date'];
1637
-    				$find = false;
1638
-    				foreach ($pall as $pvalue) {
1639
-    					if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1640
-    						$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1641
-    						$find = true;
1642
-    						break;
1643
-    					}
1644
-    				}
1645
-    				if ($find === false) {
1646
-    					$pall[] = $value;
1647
-    				}
1648
-    			}
1649
-    			$alldata = $pall;
1634
+				foreach ($dall as $value) {
1635
+					$icao = $value['departure_airport_icao'];
1636
+					$ddate = $value['date'];
1637
+					$find = false;
1638
+					foreach ($pall as $pvalue) {
1639
+						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1640
+							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1641
+							$find = true;
1642
+							break;
1643
+						}
1644
+					}
1645
+					if ($find === false) {
1646
+						$pall[] = $value;
1647
+					}
1648
+				}
1649
+				$alldata = $pall;
1650 1650
 			foreach ($alldata as $number) {
1651 1651
 				$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']);
1652 1652
 			}
1653 1653
 			echo '...Arrival'."\n";
1654 1654
 			$pall = $Spotter->getLast7DaysAirportsArrival();
1655
-        		$dall = $Spotter->getLast7DaysDetectedAirportsArrival();
1656
-        		/*
1655
+				$dall = $Spotter->getLast7DaysDetectedAirportsArrival();
1656
+				/*
1657 1657
 	        	$alldata = array();
1658 1658
     			foreach ($pall as $value) {
1659 1659
 	        		$icao = $value['arrival_airport_icao'];
@@ -1673,22 +1673,22 @@  discard block
 block discarded – undo
1673 1673
     			*/
1674 1674
 
1675 1675
 
1676
-    			foreach ($dall as $value) {
1677
-    				$icao = $value['arrival_airport_icao'];
1678
-    				$ddate = $value['date'];
1679
-    				$find = false;
1680
-    				foreach ($pall as $pvalue) {
1681
-    					if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1682
-    						$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1683
-    						$find = true;
1684
-    						break;
1685
-    					}
1686
-    				}
1687
-    				if ($find === false) {
1688
-    					$pall[] = $value;
1689
-    				}
1690
-    			}
1691
-    			$alldata = $pall;
1676
+				foreach ($dall as $value) {
1677
+					$icao = $value['arrival_airport_icao'];
1678
+					$ddate = $value['date'];
1679
+					$find = false;
1680
+					foreach ($pall as $pvalue) {
1681
+						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1682
+							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1683
+							$find = true;
1684
+							break;
1685
+						}
1686
+					}
1687
+					if ($find === false) {
1688
+						$pall[] = $value;
1689
+					}
1690
+				}
1691
+				$alldata = $pall;
1692 1692
 			foreach ($alldata as $number) {
1693 1693
 				$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']);
1694 1694
 			}
@@ -1763,51 +1763,51 @@  discard block
 block discarded – undo
1763 1763
 			if ($globalDebug) echo 'Count all departure airports by airlines...'."\n";
1764 1764
 			$pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day);
1765 1765
 			if ($globalDebug) echo 'Count all detected departure airports by airlines...'."\n";
1766
-       			$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);
1766
+	   			$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);
1767 1767
 			if ($globalDebug) echo 'Order detected departure airports by airlines...'."\n";
1768
-	        	//$alldata = array();
1769
-    			foreach ($dall as $value) {
1770
-    				$icao = $value['airport_departure_icao'];
1771
-    				$dicao = $value['airline_icao'];
1772
-    				$find = false;
1773
-    				foreach ($pall as $pvalue) {
1774
-    					if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1775
-    						$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1776
-    						$find = true;
1777
-    						break;
1778
-    					}
1779
-    				}
1780
-    				if ($find === false) {
1781
-    					$pall[] = $value;
1782
-    				}
1783
-    			}
1784
-    			$alldata = $pall;
1768
+				//$alldata = array();
1769
+				foreach ($dall as $value) {
1770
+					$icao = $value['airport_departure_icao'];
1771
+					$dicao = $value['airline_icao'];
1772
+					$find = false;
1773
+					foreach ($pall as $pvalue) {
1774
+						if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1775
+							$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1776
+							$find = true;
1777
+							break;
1778
+						}
1779
+					}
1780
+					if ($find === false) {
1781
+						$pall[] = $value;
1782
+					}
1783
+				}
1784
+				$alldata = $pall;
1785 1785
 			foreach ($alldata as $number) {
1786 1786
 				echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],$number['airline_icao'],'',$reset);
1787 1787
 			}
1788 1788
 			if ($globalDebug) echo 'Count all arrival airports by airlines...'."\n";
1789 1789
 			$pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day);
1790 1790
 			if ($globalDebug) echo 'Count all detected arrival airports by airlines...'."\n";
1791
-        		$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);
1791
+				$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);
1792 1792
 			if ($globalDebug) echo 'Order arrival airports by airlines...'."\n";
1793
-	        	//$alldata = array();
1794
-    			foreach ($dall as $value) {
1795
-    				$icao = $value['airport_arrival_icao'];
1796
-    				$dicao = $value['airline_icao'];
1797
-    				$find = false;
1798
-    				foreach ($pall as $pvalue) {
1799
-    					if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1800
-    						$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1801
-    						$find = true;
1802
-    						break;
1803
-    					}
1804
-    				}
1805
-    				if ($find === false) {
1806
-    					$pall[] = $value;
1807
-    				}
1808
-    			}
1809
-    			$alldata = $pall;
1810
-                        foreach ($alldata as $number) {
1793
+				//$alldata = array();
1794
+				foreach ($dall as $value) {
1795
+					$icao = $value['airport_arrival_icao'];
1796
+					$dicao = $value['airline_icao'];
1797
+					$find = false;
1798
+					foreach ($pall as $pvalue) {
1799
+						if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1800
+							$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1801
+							$find = true;
1802
+							break;
1803
+						}
1804
+					}
1805
+					if ($find === false) {
1806
+						$pall[] = $value;
1807
+					}
1808
+				}
1809
+				$alldata = $pall;
1810
+						foreach ($alldata as $number) {
1811 1811
 				if ($number['airline_icao'] != '') echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset);
1812 1812
 			}
1813 1813
 			if ($globalDebug) echo 'Count all flights by months by airlines...'."\n";
@@ -1840,47 +1840,47 @@  discard block
 block discarded – undo
1840 1840
 			}
1841 1841
 			if ($globalDebug) echo '...Departure'."\n";
1842 1842
 			$pall = $Spotter->getLast7DaysAirportsDepartureByAirlines();
1843
-        		$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();
1844
-    			foreach ($dall as $value) {
1845
-    				$icao = $value['departure_airport_icao'];
1846
-    				$airline = $value['airline_icao'];
1847
-    				$ddate = $value['date'];
1848
-    				$find = false;
1849
-    				foreach ($pall as $pvalue) {
1850
-    					if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) {
1851
-    						$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1852
-    						$find = true;
1853
-    						break;
1854
-    					}
1855
-    				}
1856
-    				if ($find === false) {
1857
-    					$pall[] = $value;
1858
-    				}
1859
-    			}
1860
-    			$alldata = $pall;
1843
+				$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();
1844
+				foreach ($dall as $value) {
1845
+					$icao = $value['departure_airport_icao'];
1846
+					$airline = $value['airline_icao'];
1847
+					$ddate = $value['date'];
1848
+					$find = false;
1849
+					foreach ($pall as $pvalue) {
1850
+						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) {
1851
+							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1852
+							$find = true;
1853
+							break;
1854
+						}
1855
+					}
1856
+					if ($find === false) {
1857
+						$pall[] = $value;
1858
+					}
1859
+				}
1860
+				$alldata = $pall;
1861 1861
 			foreach ($alldata as $number) {
1862 1862
 				$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],$number['airline_icao']);
1863 1863
 			}
1864 1864
 			if ($globalDebug) echo '...Arrival'."\n";
1865 1865
 			$pall = $Spotter->getLast7DaysAirportsArrivalByAirlines();
1866
-        		$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();
1867
-    			foreach ($dall as $value) {
1868
-    				$icao = $value['arrival_airport_icao'];
1869
-    				$airline = $value['airline_icao'];
1870
-    				$ddate = $value['date'];
1871
-    				$find = false;
1872
-    				foreach ($pall as $pvalue) {
1873
-    					if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) {
1874
-    						$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1875
-    						$find = true;
1876
-    						break;
1877
-    					}
1878
-    				}
1879
-    				if ($find === false) {
1880
-    					$pall[] = $value;
1881
-    				}
1882
-    			}
1883
-    			$alldata = $pall;
1866
+				$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();
1867
+				foreach ($dall as $value) {
1868
+					$icao = $value['arrival_airport_icao'];
1869
+					$airline = $value['airline_icao'];
1870
+					$ddate = $value['date'];
1871
+					$find = false;
1872
+					foreach ($pall as $pvalue) {
1873
+						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) {
1874
+							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1875
+							$find = true;
1876
+							break;
1877
+						}
1878
+					}
1879
+					if ($find === false) {
1880
+						$pall[] = $value;
1881
+					}
1882
+				}
1883
+				$alldata = $pall;
1884 1884
 			foreach ($alldata as $number) {
1885 1885
 				$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],$number['airline_icao']);
1886 1886
 			}
@@ -1963,44 +1963,44 @@  discard block
 block discarded – undo
1963 1963
 					$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'',$filter_name,$number['format_source'],$reset);
1964 1964
 				}
1965 1965
 				$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day,$filter);
1966
-	       			$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter);
1967
-		        	$alldata = array();
1968
-	    			foreach ($pall as $value) {
1969
-		        		$icao = $value['airport_departure_icao'];
1970
-    					$alldata[$icao] = $value;
1971
-	    			}
1972
-		        	foreach ($dall as $value) {
1973
-	    				$icao = $value['airport_departure_icao'];
1974
-        				if (isset($alldata[$icao])) {
1975
-    						$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1976
-        				} else $alldata[$icao] = $value;
1977
-				}
1978
-	    			$count = array();
1979
-    				foreach ($alldata as $key => $row) {
1980
-    					$count[$key] = $row['airport_departure_icao_count'];
1981
-    				}
1966
+		   			$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter);
1967
+					$alldata = array();
1968
+					foreach ($pall as $value) {
1969
+						$icao = $value['airport_departure_icao'];
1970
+						$alldata[$icao] = $value;
1971
+					}
1972
+					foreach ($dall as $value) {
1973
+						$icao = $value['airport_departure_icao'];
1974
+						if (isset($alldata[$icao])) {
1975
+							$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1976
+						} else $alldata[$icao] = $value;
1977
+				}
1978
+					$count = array();
1979
+					foreach ($alldata as $key => $row) {
1980
+						$count[$key] = $row['airport_departure_icao_count'];
1981
+					}
1982 1982
 				array_multisort($count,SORT_DESC,$alldata);
1983 1983
 				foreach ($alldata as $number) {
1984
-    					echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'',$filter_name,$reset);
1984
+						echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'',$filter_name,$reset);
1985 1985
 				}
1986 1986
 				$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day,false,$filter);
1987
-    				$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,false,$filter);
1987
+					$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,false,$filter);
1988 1988
 				$alldata = array();
1989
-    				foreach ($pall as $value) {
1990
-		        		$icao = $value['airport_arrival_icao'];
1991
-    					$alldata[$icao] = $value;
1992
-	    			}
1993
-		        	foreach ($dall as $value) {
1994
-	    				$icao = $value['airport_arrival_icao'];
1995
-        				if (isset($alldata[$icao])) {
1996
-        					$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1997
-		        		} else $alldata[$icao] = $value;
1998
-	    			}
1999
-        			$count = array();
2000
-        			foreach ($alldata as $key => $row) {
2001
-    					$count[$key] = $row['airport_arrival_icao_count'];
2002
-		        	}
2003
-        			array_multisort($count,SORT_DESC,$alldata);
1989
+					foreach ($pall as $value) {
1990
+						$icao = $value['airport_arrival_icao'];
1991
+						$alldata[$icao] = $value;
1992
+					}
1993
+					foreach ($dall as $value) {
1994
+						$icao = $value['airport_arrival_icao'];
1995
+						if (isset($alldata[$icao])) {
1996
+							$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1997
+						} else $alldata[$icao] = $value;
1998
+					}
1999
+					$count = array();
2000
+					foreach ($alldata as $key => $row) {
2001
+						$count[$key] = $row['airport_arrival_icao_count'];
2002
+					}
2003
+					array_multisort($count,SORT_DESC,$alldata);
2004 2004
 				foreach ($alldata as $number) {
2005 2005
 					echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'',$filter_name,$reset);
2006 2006
 				}
@@ -2033,45 +2033,45 @@  discard block
 block discarded – undo
2033 2033
 				}
2034 2034
 				echo '...Departure'."\n";
2035 2035
 				$pall = $Spotter->getLast7DaysAirportsDeparture('',$filter);
2036
-        			$dall = $Spotter->getLast7DaysDetectedAirportsDeparture('',$filter);
2036
+					$dall = $Spotter->getLast7DaysDetectedAirportsDeparture('',$filter);
2037 2037
 				foreach ($dall as $value) {
2038
-    					$icao = $value['departure_airport_icao'];
2039
-    					$ddate = $value['date'];
2040
-    					$find = false;
2041
-    					foreach ($pall as $pvalue) {
2042
-    						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
2043
-    							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
2044
-	    						$find = true;
2045
-    							break;
2046
-    						}
2047
-    					}
2048
-    					if ($find === false) {
2049
-    						$pall[] = $value;
2050
-	    				}
2051
-    				}
2052
-	    			$alldata = $pall;
2038
+						$icao = $value['departure_airport_icao'];
2039
+						$ddate = $value['date'];
2040
+						$find = false;
2041
+						foreach ($pall as $pvalue) {
2042
+							if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
2043
+								$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
2044
+								$find = true;
2045
+								break;
2046
+							}
2047
+						}
2048
+						if ($find === false) {
2049
+							$pall[] = $value;
2050
+						}
2051
+					}
2052
+					$alldata = $pall;
2053 2053
 				foreach ($alldata as $number) {
2054 2054
 					$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],'',$filter_name);
2055 2055
 				}
2056 2056
 				echo '...Arrival'."\n";
2057 2057
 				$pall = $Spotter->getLast7DaysAirportsArrival('',$filter);
2058
-    				$dall = $Spotter->getLast7DaysDetectedAirportsArrival('',$filter);
2058
+					$dall = $Spotter->getLast7DaysDetectedAirportsArrival('',$filter);
2059 2059
 				foreach ($dall as $value) {
2060 2060
 					$icao = $value['arrival_airport_icao'];
2061 2061
 					$ddate = $value['date'];
2062
-    					$find = false;
2062
+						$find = false;
2063 2063
 					foreach ($pall as $pvalue) {
2064
-    						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
2065
-    							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
2066
-    							$find = true;
2067
-    							break;
2068
-	    					}
2069
-    					}
2070
-    					if ($find === false) {
2071
-    						$pall[] = $value;
2072
-	    				}
2073
-    				}
2074
-    				$alldata = $pall;
2064
+							if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
2065
+								$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
2066
+								$find = true;
2067
+								break;
2068
+							}
2069
+						}
2070
+						if ($find === false) {
2071
+							$pall[] = $value;
2072
+						}
2073
+					}
2074
+					$alldata = $pall;
2075 2075
 				foreach ($alldata as $number) {
2076 2076
 					$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],'',$filter_name);
2077 2077
 				}
Please login to merge, or discard this patch.
Braces   +473 added lines, -164 removed lines patch added patch discarded remove patch
@@ -12,7 +12,9 @@  discard block
 block discarded – undo
12 12
 	
13 13
 	public function __construct($dbc = null) {
14 14
 		global $globalFilterName;
15
-		if (isset($globalFilterName)) $this->filter_name = $globalFilterName;
15
+		if (isset($globalFilterName)) {
16
+			$this->filter_name = $globalFilterName;
17
+		}
16 18
 		$Connection = new Connection($dbc);
17 19
 		$this->db = $Connection->db();
18 20
         }
@@ -80,7 +82,9 @@  discard block
 block discarded – undo
80 82
                 }
81 83
         }
82 84
 	public function getAllAirlineNames($filter_name = '') {
83
-		if ($filter_name == '') $filter_name = $this->filter_name;
85
+		if ($filter_name == '') {
86
+			$filter_name = $this->filter_name;
87
+		}
84 88
                 $query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";
85 89
                  try {
86 90
                         $sth = $this->db->prepare($query);
@@ -92,7 +96,9 @@  discard block
 block discarded – undo
92 96
                 return $all;
93 97
         }
94 98
 	public function getAllAircraftTypes($stats_airline = '',$filter_name = '') {
95
-		if ($filter_name == '') $filter_name = $this->filter_name;
99
+		if ($filter_name == '') {
100
+			$filter_name = $this->filter_name;
101
+		}
96 102
                 $query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";
97 103
                  try {
98 104
                         $sth = $this->db->prepare($query);
@@ -104,7 +110,9 @@  discard block
 block discarded – undo
104 110
                 return $all;
105 111
         }
106 112
 	public function getAllManufacturers($stats_airline = '',$filter_name = '') {
107
-		if ($filter_name == '') $filter_name = $this->filter_name;
113
+		if ($filter_name == '') {
114
+			$filter_name = $this->filter_name;
115
+		}
108 116
                 $query = "SELECT DISTINCT(aircraft_manufacturer) FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND aircraft_manufacturer <> '' ORDER BY aircraft_manufacturer ASC";
109 117
                  try {
110 118
                         $sth = $this->db->prepare($query);
@@ -116,7 +124,9 @@  discard block
 block discarded – undo
116 124
                 return $all;
117 125
         }
118 126
 	public function getAllAirportNames($stats_airline = '',$filter_name = '') {
119
-		if ($filter_name == '') $filter_name = $this->filter_name;
127
+		if ($filter_name == '') {
128
+			$filter_name = $this->filter_name;
129
+		}
120 130
                 $query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND stats_type = 'daily' GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC";
121 131
                  try {
122 132
                         $sth = $this->db->prepare($query);
@@ -129,7 +139,9 @@  discard block
 block discarded – undo
129 139
         }
130 140
 
131 141
 	public function getAllOwnerNames($stats_airline = '',$filter_name = '') {
132
-		if ($filter_name == '') $filter_name = $this->filter_name;
142
+		if ($filter_name == '') {
143
+			$filter_name = $this->filter_name;
144
+		}
133 145
                 $query = "SELECT owner_name FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_name ASC";
134 146
                  try {
135 147
                         $sth = $this->db->prepare($query);
@@ -142,7 +154,9 @@  discard block
 block discarded – undo
142 154
         }
143 155
 
144 156
 	public function getAllPilotNames($stats_airline = '',$filter_name = '') {
145
-		if ($filter_name == '') $filter_name = $this->filter_name;
157
+		if ($filter_name == '') {
158
+			$filter_name = $this->filter_name;
159
+		}
146 160
                 $query = "SELECT pilot_id,pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_name ASC";
147 161
                  try {
148 162
                         $sth = $this->db->prepare($query);
@@ -157,10 +171,15 @@  discard block
 block discarded – undo
157 171
 
158 172
 	public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') {
159 173
 		global $globalStatsFilters;
160
-		if ($filter_name == '') $filter_name = $this->filter_name;
174
+		if ($filter_name == '') {
175
+			$filter_name = $this->filter_name;
176
+		}
161 177
 		if ($year == '' && $month == '') {
162
-			if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0";
163
-			else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC";
178
+			if ($limit) {
179
+				$query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0";
180
+			} else {
181
+				$query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC";
182
+			}
164 183
 			try {
165 184
 				$sth = $this->db->prepare($query);
166 185
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -168,7 +187,9 @@  discard block
 block discarded – undo
168 187
 				echo "error : ".$e->getMessage();
169 188
 			}
170 189
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
171
-		} else $all = array();
190
+		} else {
191
+			$all = array();
192
+		}
172 193
                 if (empty($all)) {
173 194
             	    $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
174 195
             	    if ($filter_name != '') {
@@ -182,10 +203,15 @@  discard block
 block discarded – undo
182 203
 	}
183 204
 	public function countAllAirlineCountries($limit = true,$filter_name = '',$year = '',$month = '') {
184 205
 		global $globalStatsFilters;
185
-		if ($filter_name == '') $filter_name = $this->filter_name;
206
+		if ($filter_name == '') {
207
+			$filter_name = $this->filter_name;
208
+		}
186 209
 		if ($year == '' && $month == '') {
187
-			if ($limit) $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0";
188
-			else $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC";
210
+			if ($limit) {
211
+				$query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0";
212
+			} else {
213
+				$query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC";
214
+			}
189 215
 			try {
190 216
 				$sth = $this->db->prepare($query);
191 217
 				$sth->execute(array(':filter_name' => $filter_name));
@@ -193,7 +219,9 @@  discard block
 block discarded – undo
193 219
 				echo "error : ".$e->getMessage();
194 220
 			}
195 221
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
196
-		} else $all = array();
222
+		} else {
223
+			$all = array();
224
+		}
197 225
                 if (empty($all)) {
198 226
             		$Spotter = new Spotter($this->db);
199 227
             		$filters = array();
@@ -208,10 +236,15 @@  discard block
 block discarded – undo
208 236
 	}
209 237
 	public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '',$year = '', $month = '') {
210 238
 		global $globalStatsFilters;
211
-		if ($filter_name == '') $filter_name = $this->filter_name;
239
+		if ($filter_name == '') {
240
+			$filter_name = $this->filter_name;
241
+		}
212 242
 		if ($year == '' && $month == '') {
213
-			if ($limit) $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0";
214
-			else $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC";
243
+			if ($limit) {
244
+				$query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0";
245
+			} else {
246
+				$query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC";
247
+			}
215 248
 			try {
216 249
 				$sth = $this->db->prepare($query);
217 250
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -219,7 +252,9 @@  discard block
 block discarded – undo
219 252
 				echo "error : ".$e->getMessage();
220 253
 			}
221 254
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
222
-		} else $all = array();
255
+		} else {
256
+			$all = array();
257
+		}
223 258
 		if (empty($all)) {
224 259
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
225 260
 			if ($filter_name != '') {
@@ -234,10 +269,15 @@  discard block
 block discarded – undo
234 269
 
235 270
 	public function countAllArrivalCountries($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') {
236 271
 		global $globalStatsFilters;
237
-		if ($filter_name == '') $filter_name = $this->filter_name;
272
+		if ($filter_name == '') {
273
+			$filter_name = $this->filter_name;
274
+		}
238 275
 		if ($year == '' && $month == '') {
239
-			if ($limit) $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0";
240
-			else $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC";
276
+			if ($limit) {
277
+				$query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0";
278
+			} else {
279
+				$query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC";
280
+			}
241 281
 			try {
242 282
 				$sth = $this->db->prepare($query);
243 283
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -245,7 +285,9 @@  discard block
 block discarded – undo
245 285
 				echo "error : ".$e->getMessage();
246 286
 			}
247 287
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
248
-		} else $all = array();
288
+		} else {
289
+			$all = array();
290
+		}
249 291
                 if (empty($all)) {
250 292
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
251 293
 			if ($filter_name != '') {
@@ -259,9 +301,14 @@  discard block
 block discarded – undo
259 301
 	}
260 302
 	public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '', $year = '', $month = '') {
261 303
 		global $globalStatsFilters;
262
-		if ($filter_name == '') $filter_name = $this->filter_name;
263
-		if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0";
264
-		else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC";
304
+		if ($filter_name == '') {
305
+			$filter_name = $this->filter_name;
306
+		}
307
+		if ($limit) {
308
+			$query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0";
309
+		} else {
310
+			$query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC";
311
+		}
265 312
                  try {
266 313
                         $sth = $this->db->prepare($query);
267 314
                         $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -283,17 +330,29 @@  discard block
 block discarded – undo
283 330
 
284 331
 	public function countAllAirlines($limit = true,$filter_name = '',$year = '',$month = '') {
285 332
 		global $globalStatsFilters, $globalVATSIM, $globalIVAO;
286
-		if ($filter_name == '') $filter_name = $this->filter_name;
333
+		if ($filter_name == '') {
334
+			$filter_name = $this->filter_name;
335
+		}
287 336
 		if ($year == '' && $month == '') {
288
-			if ($globalVATSIM) $forsource = 'vatsim';
289
-			if ($globalIVAO) $forsource = 'ivao';
337
+			if ($globalVATSIM) {
338
+				$forsource = 'vatsim';
339
+			}
340
+			if ($globalIVAO) {
341
+				$forsource = 'ivao';
342
+			}
290 343
 			if (isset($forsource)) {
291
-				if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
292
-				else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC";
344
+				if ($limit) {
345
+					$query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
346
+				} else {
347
+					$query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC";
348
+				}
293 349
 				$query_values = array(':filter_name' => $filter_name,':forsource' => $forsource);
294 350
 			} else {
295
-				if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
296
-				else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC";
351
+				if ($limit) {
352
+					$query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
353
+				} else {
354
+					$query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC";
355
+				}
297 356
 				$query_values = array(':filter_name' => $filter_name);
298 357
 			}
299 358
 			try {
@@ -303,7 +362,9 @@  discard block
 block discarded – undo
303 362
 				echo "error : ".$e->getMessage();
304 363
 			}
305 364
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
306
-		} else $all = array();
365
+		} else {
366
+			$all = array();
367
+		}
307 368
                 if (empty($all)) {
308 369
 	                $Spotter = new Spotter($this->db);
309 370
             		$filters = array();
@@ -318,10 +379,15 @@  discard block
 block discarded – undo
318 379
 	}
319 380
 	public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
320 381
 		global $globalStatsFilters;
321
-		if ($filter_name == '') $filter_name = $this->filter_name;
382
+		if ($filter_name == '') {
383
+			$filter_name = $this->filter_name;
384
+		}
322 385
 		if ($year == '' && $month == '') {
323
-			if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0";
324
-			else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC";
386
+			if ($limit) {
387
+				$query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0";
388
+			} else {
389
+				$query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC";
390
+			}
325 391
 			try {
326 392
 				$sth = $this->db->prepare($query);
327 393
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -329,7 +395,9 @@  discard block
 block discarded – undo
329 395
 				echo "error : ".$e->getMessage();
330 396
 			}
331 397
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
332
-		} else $all = array();
398
+		} else {
399
+			$all = array();
400
+		}
333 401
                 if (empty($all)) {
334 402
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
335 403
 			if ($filter_name != '') {
@@ -343,10 +411,15 @@  discard block
 block discarded – undo
343 411
 	}
344 412
 	public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
345 413
 		global $globalStatsFilters;
346
-		if ($filter_name == '') $filter_name = $this->filter_name;
414
+		if ($filter_name == '') {
415
+			$filter_name = $this->filter_name;
416
+		}
347 417
 		if ($year == '' && $month == '') {
348
-			if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0";
349
-			else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC";
418
+			if ($limit) {
419
+				$query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0";
420
+			} else {
421
+				$query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC";
422
+			}
350 423
 			 try {
351 424
 				$sth = $this->db->prepare($query);
352 425
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -354,7 +427,9 @@  discard block
 block discarded – undo
354 427
 				echo "error : ".$e->getMessage();
355 428
 			}
356 429
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
357
-		} else $all = array();
430
+		} else {
431
+			$all = array();
432
+		}
358 433
 		if (empty($all)) {
359 434
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
360 435
 			if ($filter_name != '') {
@@ -368,11 +443,16 @@  discard block
 block discarded – undo
368 443
 	}
369 444
 	public function countAllFlightOverCountries($limit = true, $stats_airline = '',$filter_name = '',$year = '',$month = '') {
370 445
 		$Connection = new Connection();
371
-		if ($filter_name == '') $filter_name = $this->filter_name;
446
+		if ($filter_name == '') {
447
+			$filter_name = $this->filter_name;
448
+		}
372 449
 		if ($Connection->tableExists('countries')) {
373 450
 			if ($year == '' && $month == '') {
374
-				if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0";
375
-				else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC";
451
+				if ($limit) {
452
+					$query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0";
453
+				} else {
454
+					$query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC";
455
+				}
376 456
 				 try {
377 457
 					$sth = $this->db->prepare($query);
378 458
 					$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -387,17 +467,24 @@  discard block
 block discarded – undo
387 467
                 }
388 468
                 */
389 469
 				return $all;
390
-			} else return array();
470
+			} else {
471
+				return array();
472
+			}
391 473
 		} else {
392 474
 			return array();
393 475
 		}
394 476
 	}
395 477
 	public function countAllPilots($limit = true,$stats_airline = '',$filter_name = '', $year = '',$month = '') {
396 478
 		global $globalStatsFilters;
397
-		if ($filter_name == '') $filter_name = $this->filter_name;
479
+		if ($filter_name == '') {
480
+			$filter_name = $this->filter_name;
481
+		}
398 482
 		if ($year == '' && $month == '') {
399
-			if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";
400
-			else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC";
483
+			if ($limit) {
484
+				$query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";
485
+			} else {
486
+				$query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC";
487
+			}
401 488
 			try {
402 489
 				$sth = $this->db->prepare($query);
403 490
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -405,7 +492,9 @@  discard block
 block discarded – undo
405 492
 				echo "error : ".$e->getMessage();
406 493
 			}
407 494
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
408
-		} else $all = array();
495
+		} else {
496
+			$all = array();
497
+		}
409 498
 		if (empty($all)) {
410 499
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
411 500
 			if ($filter_name != '') {
@@ -420,10 +509,15 @@  discard block
 block discarded – undo
420 509
 
421 510
 	public function countAllOwners($limit = true,$stats_airline = '', $filter_name = '',$year = '',$month = '') {
422 511
 		global $globalStatsFilters;
423
-		if ($filter_name == '') $filter_name = $this->filter_name;
512
+		if ($filter_name == '') {
513
+			$filter_name = $this->filter_name;
514
+		}
424 515
 		if ($year == '' && $month == '') {
425
-			if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0";
426
-			else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC";
516
+			if ($limit) {
517
+				$query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0";
518
+			} else {
519
+				$query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC";
520
+			}
427 521
 			try {
428 522
 				$sth = $this->db->prepare($query);
429 523
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -431,7 +525,9 @@  discard block
 block discarded – undo
431 525
 				echo "error : ".$e->getMessage();
432 526
 			}
433 527
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
434
-		} else $all = array();
528
+		} else {
529
+			$all = array();
530
+		}
435 531
                 if (empty($all)) {
436 532
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
437 533
 			if ($filter_name != '') {
@@ -445,10 +541,15 @@  discard block
 block discarded – undo
445 541
 	}
446 542
 	public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
447 543
 		global $globalStatsFilters;
448
-		if ($filter_name == '') $filter_name = $this->filter_name;
544
+		if ($filter_name == '') {
545
+			$filter_name = $this->filter_name;
546
+		}
449 547
 		if ($year == '' && $month == '') {
450
-			if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0";
451
-			else $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC";
548
+			if ($limit) {
549
+				$query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0";
550
+			} else {
551
+				$query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC";
552
+			}
452 553
 			try {
453 554
 				$sth = $this->db->prepare($query);
454 555
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -456,7 +557,9 @@  discard block
 block discarded – undo
456 557
 				echo "error : ".$e->getMessage();
457 558
 			}
458 559
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
459
-		} else $all = array();
560
+		} else {
561
+			$all = array();
562
+		}
460 563
                 if (empty($all)) {
461 564
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
462 565
             		if ($filter_name != '') {
@@ -477,7 +580,9 @@  discard block
 block discarded – undo
477 580
         			$icao = $value['airport_departure_icao'];
478 581
         			if (isset($all[$icao])) {
479 582
         				$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
480
-        			} else $all[$icao] = $value;
583
+        			} else {
584
+        				$all[$icao] = $value;
585
+        			}
481 586
         		}
482 587
         		$count = array();
483 588
         		foreach ($all as $key => $row) {
@@ -489,10 +594,15 @@  discard block
 block discarded – undo
489 594
 	}
490 595
 	public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') {
491 596
 		global $globalStatsFilters;
492
-		if ($filter_name == '') $filter_name = $this->filter_name;
597
+		if ($filter_name == '') {
598
+			$filter_name = $this->filter_name;
599
+		}
493 600
 		if ($year == '' && $month == '') {
494
-			if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0";
495
-			else $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC";
601
+			if ($limit) {
602
+				$query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0";
603
+			} else {
604
+				$query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC";
605
+			}
496 606
 			try {
497 607
 				$sth = $this->db->prepare($query);
498 608
 				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
@@ -500,7 +610,9 @@  discard block
 block discarded – undo
500 610
 				echo "error : ".$e->getMessage();
501 611
 			}
502 612
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
503
-		} else $all = array();
613
+		} else {
614
+			$all = array();
615
+		}
504 616
 		if (empty($all)) {
505 617
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
506 618
 			if ($filter_name != '') {
@@ -521,7 +633,9 @@  discard block
 block discarded – undo
521 633
         			$icao = $value['airport_arrival_icao'];
522 634
         			if (isset($all[$icao])) {
523 635
         				$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
524
-        			} else $all[$icao] = $value;
636
+        			} else {
637
+        				$all[$icao] = $value;
638
+        			}
525 639
         		}
526 640
         		$count = array();
527 641
         		foreach ($all as $key => $row) {
@@ -534,13 +648,21 @@  discard block
 block discarded – undo
534 648
 	}
535 649
 	public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') {
536 650
 		global $globalDBdriver, $globalStatsFilters;
537
-		if ($filter_name == '') $filter_name = $this->filter_name;
651
+		if ($filter_name == '') {
652
+			$filter_name = $this->filter_name;
653
+		}
538 654
 		if ($globalDBdriver == 'mysql') {
539
-			if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";
540
-			else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
655
+			if ($limit) {
656
+				$query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";
657
+			} else {
658
+				$query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
659
+			}
541 660
 		} else {
542
-			if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name";
543
-			else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
661
+			if ($limit) {
662
+				$query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name";
663
+			} else {
664
+				$query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
665
+			}
544 666
 		}
545 667
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
546 668
                  try {
@@ -564,7 +686,9 @@  discard block
 block discarded – undo
564 686
 	
565 687
 	public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') {
566 688
 		global $globalStatsFilters;
567
-		if ($filter_name == '') $filter_name = $this->filter_name;
689
+		if ($filter_name == '') {
690
+			$filter_name = $this->filter_name;
691
+		}
568 692
 		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline = :stats_airline AND filter_name = :filter_name";
569 693
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
570 694
                  try {
@@ -586,7 +710,9 @@  discard block
 block discarded – undo
586 710
 	}
587 711
 	public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') {
588 712
 		global $globalDBdriver, $globalStatsFilters;
589
-		if ($filter_name == '') $filter_name = $this->filter_name;
713
+		if ($filter_name == '') {
714
+			$filter_name = $this->filter_name;
715
+		}
590 716
 		if ($globalDBdriver == 'mysql') {
591 717
 			$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND stats_airline = :stats_airline AND filter_name = :filter_name";
592 718
 		} else {
@@ -612,7 +738,9 @@  discard block
 block discarded – undo
612 738
 	}
613 739
 	public function countAllDates($stats_airline = '',$filter_name = '') {
614 740
 		global $globalStatsFilters;
615
-		if ($filter_name == '') $filter_name = $this->filter_name;
741
+		if ($filter_name == '') {
742
+			$filter_name = $this->filter_name;
743
+		}
616 744
 		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline = :stats_airline AND filter_name = :filter_name";
617 745
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
618 746
                  try {
@@ -634,7 +762,9 @@  discard block
 block discarded – undo
634 762
 	}
635 763
 	public function countAllDatesByAirlines($filter_name = '') {
636 764
 		global $globalStatsFilters;
637
-		if ($filter_name == '') $filter_name = $this->filter_name;
765
+		if ($filter_name == '') {
766
+			$filter_name = $this->filter_name;
767
+		}
638 768
 		$query = "SELECT stats_airline as airline_icao, flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND filter_name = :filter_name";
639 769
 		$query_data = array('filter_name' => $filter_name);
640 770
                  try {
@@ -656,7 +786,9 @@  discard block
 block discarded – undo
656 786
 	}
657 787
 	public function countAllMonths($stats_airline = '',$filter_name = '') {
658 788
 		global $globalStatsFilters;
659
-		if ($filter_name == '') $filter_name = $this->filter_name;
789
+		if ($filter_name == '') {
790
+			$filter_name = $this->filter_name;
791
+		}
660 792
 	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";
661 793
                  try {
662 794
                         $sth = $this->db->prepare($query);
@@ -679,7 +811,9 @@  discard block
 block discarded – undo
679 811
 	}
680 812
 	public function countAllMilitaryMonths($filter_name = '') {
681 813
 		global $globalStatsFilters;
682
-		if ($filter_name == '') $filter_name = $this->filter_name;
814
+		if ($filter_name == '') {
815
+			$filter_name = $this->filter_name;
816
+		}
683 817
 	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name";
684 818
                  try {
685 819
                         $sth = $this->db->prepare($query);
@@ -700,9 +834,14 @@  discard block
 block discarded – undo
700 834
 	}
701 835
 	public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') {
702 836
 		global $globalTimezone, $globalDBdriver, $globalStatsFilters;
703
-		if ($filter_name == '') $filter_name = $this->filter_name;
704
-		if ($limit) $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";
705
-		else $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";
837
+		if ($filter_name == '') {
838
+			$filter_name = $this->filter_name;
839
+		}
840
+		if ($limit) {
841
+			$query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";
842
+		} else {
843
+			$query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";
844
+		}
706 845
 		if ($orderby == 'hour') {
707 846
 			/*
708 847
 			if ($globalDBdriver == 'mysql') {
@@ -711,7 +850,9 @@  discard block
 block discarded – undo
711 850
 			*/
712 851
 			$query .= " ORDER BY CAST(flight_date AS integer) ASC";
713 852
 		}
714
-		if ($orderby == 'count') $query .= " ORDER BY hour_count DESC";
853
+		if ($orderby == 'count') {
854
+			$query .= " ORDER BY hour_count DESC";
855
+		}
715 856
                  try {
716 857
                         $sth = $this->db->prepare($query);
717 858
                         $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
@@ -732,8 +873,12 @@  discard block
 block discarded – undo
732 873
 	
733 874
 	public function countOverallFlights($stats_airline = '', $filter_name = '',$year = '',$month = '') {
734 875
 		global $globalStatsFilters;
735
-		if ($filter_name == '') $filter_name = $this->filter_name;
736
-		if ($year == '') $year = date('Y');
876
+		if ($filter_name == '') {
877
+			$filter_name = $this->filter_name;
878
+		}
879
+		if ($year == '') {
880
+			$year = date('Y');
881
+		}
737 882
 		$all = $this->getSumStats('flights_bymonth',$year,$stats_airline,$filter_name,$month);
738 883
 		if (empty($all)) {
739 884
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
@@ -748,8 +893,12 @@  discard block
 block discarded – undo
748 893
 	}
749 894
 	public function countOverallMilitaryFlights($filter_name = '',$year = '', $month = '') {
750 895
 		global $globalStatsFilters;
751
-		if ($filter_name == '') $filter_name = $this->filter_name;
752
-		if ($year == '') $year = date('Y');
896
+		if ($filter_name == '') {
897
+			$filter_name = $this->filter_name;
898
+		}
899
+		if ($year == '') {
900
+			$year = date('Y');
901
+		}
753 902
 		$all = $this->getSumStats('military_flights_bymonth',$year,'',$filter_name,$month);
754 903
 		if (empty($all)) {
755 904
 		        $filters = array();
@@ -765,8 +914,12 @@  discard block
 block discarded – undo
765 914
 	}
766 915
 	public function countOverallArrival($stats_airline = '',$filter_name = '', $year = '', $month = '') {
767 916
 		global $globalStatsFilters;
768
-		if ($filter_name == '') $filter_name = $this->filter_name;
769
-		if ($year == '') $year = date('Y');
917
+		if ($filter_name == '') {
918
+			$filter_name = $this->filter_name;
919
+		}
920
+		if ($year == '') {
921
+			$year = date('Y');
922
+		}
770 923
 		$all = $this->getSumStats('realarrivals_bymonth',$year,$stats_airline,$filter_name,$month);
771 924
 		if (empty($all)) {
772 925
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
@@ -781,7 +934,9 @@  discard block
 block discarded – undo
781 934
 	}
782 935
 	public function countOverallAircrafts($stats_airline = '',$filter_name = '',$year = '', $month = '') {
783 936
 		global $globalStatsFilters;
784
-		if ($filter_name == '') $filter_name = $this->filter_name;
937
+		if ($filter_name == '') {
938
+			$filter_name = $this->filter_name;
939
+		}
785 940
 		if ($year == '' && $month == '') {
786 941
 			$query = "SELECT COUNT(*) AS nb FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
787 942
 			try {
@@ -792,7 +947,9 @@  discard block
 block discarded – undo
792 947
 			}
793 948
 			$result = $sth->fetchAll(PDO::FETCH_ASSOC);
794 949
 			$all = $result[0]['nb'];
795
-		} else $all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month);
950
+		} else {
951
+			$all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month);
952
+		}
796 953
 		if (empty($all)) {
797 954
 			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month);
798 955
 			if ($filter_name != '') {
@@ -806,7 +963,9 @@  discard block
 block discarded – undo
806 963
 	}
807 964
 	public function countOverallAirlines($filter_name = '',$year = '',$month = '') {
808 965
 		global $globalStatsFilters;
809
-		if ($filter_name == '') $filter_name = $this->filter_name;
966
+		if ($filter_name == '') {
967
+			$filter_name = $this->filter_name;
968
+		}
810 969
 		if ($year == '' && $month == '') {
811 970
 			$query = "SELECT COUNT(*) AS nb_airline FROM stats_airline WHERE filter_name = :filter_name";
812 971
 			try {
@@ -817,7 +976,9 @@  discard block
 block discarded – undo
817 976
 			}
818 977
 			$result = $sth->fetchAll(PDO::FETCH_ASSOC);
819 978
 			$all = $result[0]['nb_airline'];
820
-		} else $all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month);
979
+		} else {
980
+			$all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month);
981
+		}
821 982
 		if (empty($all)) {
822 983
             		$filters = array();
823 984
 			$filters = array('year' => $year,'month' => $month);
@@ -832,7 +993,9 @@  discard block
 block discarded – undo
832 993
 	}
833 994
 	public function countOverallOwners($stats_airline = '',$filter_name = '',$year = '', $month = '') {
834 995
 		global $globalStatsFilters;
835
-		if ($filter_name == '') $filter_name = $this->filter_name;
996
+		if ($filter_name == '') {
997
+			$filter_name = $this->filter_name;
998
+		}
836 999
 		if ($year == '' && $month == '') {
837 1000
 			$query = "SELECT count(*) as nb FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
838 1001
 			$query_values = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
@@ -860,7 +1023,9 @@  discard block
 block discarded – undo
860 1023
 	}
861 1024
 	public function countOverallPilots($stats_airline = '',$filter_name = '',$year = '',$month = '') {
862 1025
 		global $globalStatsFilters;
863
-		if ($filter_name == '') $filter_name = $this->filter_name;
1026
+		if ($filter_name == '') {
1027
+			$filter_name = $this->filter_name;
1028
+		}
864 1029
 		//if ($year == '') $year = date('Y');
865 1030
 		if ($year == '' && $month == '') {
866 1031
 			$query = "SELECT count(*) as nb FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
@@ -889,7 +1054,9 @@  discard block
 block discarded – undo
889 1054
 	}
890 1055
 
891 1056
 	public function getLast7DaysAirports($airport_icao = '', $stats_airline = '',$filter_name = '') {
892
-		if ($filter_name == '') $filter_name = $this->filter_name;
1057
+		if ($filter_name == '') {
1058
+			$filter_name = $this->filter_name;
1059
+		}
893 1060
 		$query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date";
894 1061
 		$query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
895 1062
                  try {
@@ -902,7 +1069,9 @@  discard block
 block discarded – undo
902 1069
                 return $all;
903 1070
 	}
904 1071
 	public function getStats($type,$stats_airline = '', $filter_name = '') {
905
-		if ($filter_name == '') $filter_name = $this->filter_name;
1072
+		if ($filter_name == '') {
1073
+			$filter_name = $this->filter_name;
1074
+		}
906 1075
                 $query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";
907 1076
                 $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
908 1077
                  try {
@@ -915,7 +1084,9 @@  discard block
 block discarded – undo
915 1084
                 return $all;
916 1085
         }
917 1086
 	public function getSumStats($type,$year,$stats_airline = '',$filter_name = '',$month = '') {
918
-		if ($filter_name == '') $filter_name = $this->filter_name;
1087
+		if ($filter_name == '') {
1088
+			$filter_name = $this->filter_name;
1089
+		}
919 1090
     		global $globalArchiveMonths, $globalDBdriver;
920 1091
     		if ($globalDBdriver == 'mysql') {
921 1092
     			if ($month == '') {
@@ -945,7 +1116,9 @@  discard block
 block discarded – undo
945 1116
         }
946 1117
 	public function getStatsTotal($type, $stats_airline = '', $filter_name = '') {
947 1118
     		global $globalArchiveMonths, $globalDBdriver;
948
-		if ($filter_name == '') $filter_name = $this->filter_name;
1119
+		if ($filter_name == '') {
1120
+			$filter_name = $this->filter_name;
1121
+		}
949 1122
     		if ($globalDBdriver == 'mysql') {
950 1123
 			$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";
951 1124
 		} else {
@@ -963,7 +1136,9 @@  discard block
 block discarded – undo
963 1136
         }
964 1137
 	public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') {
965 1138
     		global $globalArchiveMonths, $globalDBdriver;
966
-		if ($filter_name == '') $filter_name = $this->filter_name;
1139
+		if ($filter_name == '') {
1140
+			$filter_name = $this->filter_name;
1141
+		}
967 1142
     		if ($globalDBdriver == 'mysql') {
968 1143
 			$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
969 1144
                 } else {
@@ -980,7 +1155,9 @@  discard block
 block discarded – undo
980 1155
         }
981 1156
 	public function getStatsAirlineTotal($filter_name = '') {
982 1157
     		global $globalArchiveMonths, $globalDBdriver;
983
-		if ($filter_name == '') $filter_name = $this->filter_name;
1158
+		if ($filter_name == '') {
1159
+			$filter_name = $this->filter_name;
1160
+		}
984 1161
     		if ($globalDBdriver == 'mysql') {
985 1162
 			$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";
986 1163
                 } else {
@@ -997,7 +1174,9 @@  discard block
 block discarded – undo
997 1174
         }
998 1175
 	public function getStatsOwnerTotal($filter_name = '') {
999 1176
     		global $globalArchiveMonths, $globalDBdriver;
1000
-		if ($filter_name == '') $filter_name = $this->filter_name;
1177
+		if ($filter_name == '') {
1178
+			$filter_name = $this->filter_name;
1179
+		}
1001 1180
     		if ($globalDBdriver == 'mysql') {
1002 1181
 			$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";
1003 1182
 		} else {
@@ -1014,7 +1193,9 @@  discard block
 block discarded – undo
1014 1193
         }
1015 1194
 	public function getStatsOwner($owner_name,$filter_name = '') {
1016 1195
     		global $globalArchiveMonths, $globalDBdriver;
1017
-		if ($filter_name == '') $filter_name = $this->filter_name;
1196
+		if ($filter_name == '') {
1197
+			$filter_name = $this->filter_name;
1198
+		}
1018 1199
 		$query = "SELECT cnt FROM stats_owner WHERE filter_name = :filter_name AND owner_name = :owner_name";
1019 1200
                  try {
1020 1201
                         $sth = $this->db->prepare($query);
@@ -1023,12 +1204,17 @@  discard block
 block discarded – undo
1023 1204
                         echo "error : ".$e->getMessage();
1024 1205
                 }
1025 1206
                 $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1026
-                if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1027
-                else return 0;
1207
+                if (isset($all[0]['cnt'])) {
1208
+                	return $all[0]['cnt'];
1209
+                } else {
1210
+                	return 0;
1211
+                }
1028 1212
         }
1029 1213
 	public function getStatsPilotTotal($filter_name = '') {
1030 1214
     		global $globalArchiveMonths, $globalDBdriver;
1031
-		if ($filter_name == '') $filter_name = $this->filter_name;
1215
+		if ($filter_name == '') {
1216
+			$filter_name = $this->filter_name;
1217
+		}
1032 1218
     		if ($globalDBdriver == 'mysql') {
1033 1219
             		$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
1034 1220
             	} else {
@@ -1045,7 +1231,9 @@  discard block
 block discarded – undo
1045 1231
         }
1046 1232
 	public function getStatsPilot($pilot,$filter_name = '') {
1047 1233
     		global $globalArchiveMonths, $globalDBdriver;
1048
-		if ($filter_name == '') $filter_name = $this->filter_name;
1234
+		if ($filter_name == '') {
1235
+			$filter_name = $this->filter_name;
1236
+		}
1049 1237
 		$query = "SELECT cnt FROM stats_pilot WHERE filter_name = :filter_name AND (pilot_name = :pilot OR pilot_id = :pilot)";
1050 1238
                  try {
1051 1239
                         $sth = $this->db->prepare($query);
@@ -1054,13 +1242,18 @@  discard block
 block discarded – undo
1054 1242
                         echo "error : ".$e->getMessage();
1055 1243
                 }
1056 1244
                 $all = $sth->fetchAll(PDO::FETCH_ASSOC);
1057
-                if (isset($all[0]['cnt'])) return $all[0]['cnt'];
1058
-                else return 0;
1245
+                if (isset($all[0]['cnt'])) {
1246
+                	return $all[0]['cnt'];
1247
+                } else {
1248
+                	return 0;
1249
+                }
1059 1250
         }
1060 1251
 
1061 1252
 	public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
1062 1253
 		global $globalDBdriver;
1063
-		if ($filter_name == '') $filter_name = $this->filter_name;
1254
+		if ($filter_name == '') {
1255
+			$filter_name = $this->filter_name;
1256
+		}
1064 1257
 		if ($globalDBdriver == 'mysql') {
1065 1258
 			$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt";
1066 1259
                 } else {
@@ -1076,7 +1269,9 @@  discard block
 block discarded – undo
1076 1269
         }
1077 1270
 	public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
1078 1271
 		global $globalDBdriver;
1079
-		if ($filter_name == '') $filter_name = $this->filter_name;
1272
+		if ($filter_name == '') {
1273
+			$filter_name = $this->filter_name;
1274
+		}
1080 1275
 		if ($globalDBdriver == 'mysql') {
1081 1276
 			$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
1082 1277
 		} else {
@@ -1462,10 +1657,14 @@  discard block
 block discarded – undo
1462 1657
     		$Connection = new Connection();
1463 1658
     		date_default_timezone_set('UTC');
1464 1659
     		$last_update = $this->getLastStatsUpdate('last_update_stats');
1465
-			if ($globalDebug) echo 'Update stats !'."\n";
1660
+			if ($globalDebug) {
1661
+				echo 'Update stats !'."\n";
1662
+			}
1466 1663
 			if (isset($last_update[0]['value'])) {
1467 1664
 				$last_update_day = $last_update[0]['value'];
1468
-			} else $last_update_day = '2012-12-12 12:12:12';
1665
+			} else {
1666
+				$last_update_day = '2012-12-12 12:12:12';
1667
+			}
1469 1668
 			$reset = false;
1470 1669
 			//if ($globalStatsResetYear && date('Y',strtotime($last_update_day)) != date('Y')) {
1471 1670
 			if ($globalStatsResetYear) {
@@ -1474,42 +1673,60 @@  discard block
 block discarded – undo
1474 1673
 			}
1475 1674
 			$Spotter = new Spotter($this->db);
1476 1675
 
1477
-			if ($globalDebug) echo 'Count all aircraft types...'."\n";
1676
+			if ($globalDebug) {
1677
+				echo 'Count all aircraft types...'."\n";
1678
+			}
1478 1679
 			$alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day);
1479 1680
 			foreach ($alldata as $number) {
1480 1681
 				$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],'','',$reset);
1481 1682
 			}
1482
-			if ($globalDebug) echo 'Count all airlines...'."\n";
1683
+			if ($globalDebug) {
1684
+				echo 'Count all airlines...'."\n";
1685
+			}
1483 1686
 			$alldata = $Spotter->countAllAirlines(false,0,$last_update_day);
1484 1687
 			foreach ($alldata as $number) {
1485 1688
 				$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name'],'',$reset);
1486 1689
 			}
1487
-			if ($globalDebug) echo 'Count all registrations...'."\n";
1690
+			if ($globalDebug) {
1691
+				echo 'Count all registrations...'."\n";
1692
+			}
1488 1693
 			$alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day);
1489 1694
 			foreach ($alldata as $number) {
1490 1695
 				$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],'','',$reset);
1491 1696
 			}
1492
-			if ($globalDebug) echo 'Count all callsigns...'."\n";
1697
+			if ($globalDebug) {
1698
+				echo 'Count all callsigns...'."\n";
1699
+			}
1493 1700
 			$alldata = $Spotter->countAllCallsigns(false,0,$last_update_day);
1494 1701
 			foreach ($alldata as $number) {
1495 1702
 				$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset);
1496 1703
 			}
1497
-			if ($globalDebug) echo 'Count all owners...'."\n";
1704
+			if ($globalDebug) {
1705
+				echo 'Count all owners...'."\n";
1706
+			}
1498 1707
 			$alldata = $Spotter->countAllOwners(false,0,$last_update_day);
1499 1708
 			foreach ($alldata as $number) {
1500 1709
 				$this->addStatOwner($number['owner_name'],$number['owner_count'],'','',$reset);
1501 1710
 			}
1502
-			if ($globalDebug) echo 'Count all pilots...'."\n";
1711
+			if ($globalDebug) {
1712
+				echo 'Count all pilots...'."\n";
1713
+			}
1503 1714
 			$alldata = $Spotter->countAllPilots(false,0,$last_update_day);
1504 1715
 			foreach ($alldata as $number) {
1505 1716
 				$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'','',$number['format_source'],$reset);
1506 1717
 			}
1507 1718
 			
1508
-			if ($globalDebug) echo 'Count all departure airports...'."\n";
1719
+			if ($globalDebug) {
1720
+				echo 'Count all departure airports...'."\n";
1721
+			}
1509 1722
 			$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day);
1510
-			if ($globalDebug) echo 'Count all detected departure airports...'."\n";
1723
+			if ($globalDebug) {
1724
+				echo 'Count all detected departure airports...'."\n";
1725
+			}
1511 1726
         		$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1512
-			if ($globalDebug) echo 'Order departure airports...'."\n";
1727
+			if ($globalDebug) {
1728
+				echo 'Order departure airports...'."\n";
1729
+			}
1513 1730
 	        	$alldata = array();
1514 1731
 	        	
1515 1732
     			foreach ($pall as $value) {
@@ -1520,7 +1737,9 @@  discard block
 block discarded – undo
1520 1737
     				$icao = $value['airport_departure_icao'];
1521 1738
         			if (isset($alldata[$icao])) {
1522 1739
     					$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1523
-        			} else $alldata[$icao] = $value;
1740
+        			} else {
1741
+        				$alldata[$icao] = $value;
1742
+        			}
1524 1743
 			}
1525 1744
     			$count = array();
1526 1745
     			foreach ($alldata as $key => $row) {
@@ -1530,11 +1749,17 @@  discard block
 block discarded – undo
1530 1749
 			foreach ($alldata as $number) {
1531 1750
 				echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'','',$reset);
1532 1751
 			}
1533
-			if ($globalDebug) echo 'Count all arrival airports...'."\n";
1752
+			if ($globalDebug) {
1753
+				echo 'Count all arrival airports...'."\n";
1754
+			}
1534 1755
 			$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day);
1535
-			if ($globalDebug) echo 'Count all detected arrival airports...'."\n";
1756
+			if ($globalDebug) {
1757
+				echo 'Count all detected arrival airports...'."\n";
1758
+			}
1536 1759
         		$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1537
-			if ($globalDebug) echo 'Order arrival airports...'."\n";
1760
+			if ($globalDebug) {
1761
+				echo 'Order arrival airports...'."\n";
1762
+			}
1538 1763
 	        	$alldata = array();
1539 1764
     			foreach ($pall as $value) {
1540 1765
 	        		$icao = $value['airport_arrival_icao'];
@@ -1544,7 +1769,9 @@  discard block
 block discarded – undo
1544 1769
     				$icao = $value['airport_arrival_icao'];
1545 1770
         			if (isset($alldata[$icao])) {
1546 1771
         				$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1547
-	        		} else $alldata[$icao] = $value;
1772
+	        		} else {
1773
+	        			$alldata[$icao] = $value;
1774
+	        		}
1548 1775
     			}
1549 1776
         		$count = array();
1550 1777
         		foreach ($alldata as $key => $row) {
@@ -1555,7 +1782,9 @@  discard block
 block discarded – undo
1555 1782
 				echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'','',$reset);
1556 1783
 			}
1557 1784
 			if ($Connection->tableExists('countries')) {
1558
-				if ($globalDebug) echo 'Count all flights by countries...'."\n";
1785
+				if ($globalDebug) {
1786
+					echo 'Count all flights by countries...'."\n";
1787
+				}
1559 1788
 				$SpotterArchive = new SpotterArchive();
1560 1789
 				$alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day);
1561 1790
 				foreach ($alldata as $number) {
@@ -1567,46 +1796,66 @@  discard block
 block discarded – undo
1567 1796
 			// Add by month using getstat if month finish...
1568 1797
 
1569 1798
 			//if (date('m',strtotime($last_update_day)) != date('m')) {
1570
-			if ($globalDebug) echo 'Count all flights by months...'."\n";
1799
+			if ($globalDebug) {
1800
+				echo 'Count all flights by months...'."\n";
1801
+			}
1571 1802
 			$Spotter = new Spotter($this->db);
1572 1803
 			$alldata = $Spotter->countAllMonths();
1573 1804
 			$lastyear = false;
1574 1805
 			foreach ($alldata as $number) {
1575
-				if ($number['year_name'] != date('Y')) $lastyear = true;
1806
+				if ($number['year_name'] != date('Y')) {
1807
+					$lastyear = true;
1808
+				}
1576 1809
 				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1577 1810
 			}
1578
-			if ($globalDebug) echo 'Count all military flights by months...'."\n";
1811
+			if ($globalDebug) {
1812
+				echo 'Count all military flights by months...'."\n";
1813
+			}
1579 1814
 			$alldata = $Spotter->countAllMilitaryMonths();
1580 1815
 			foreach ($alldata as $number) {
1581 1816
 				$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1582 1817
 			}
1583
-			if ($globalDebug) echo 'Count all owners by months...'."\n";
1818
+			if ($globalDebug) {
1819
+				echo 'Count all owners by months...'."\n";
1820
+			}
1584 1821
 			$alldata = $Spotter->countAllMonthsOwners();
1585 1822
 			foreach ($alldata as $number) {
1586 1823
 				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1587 1824
 			}
1588
-			if ($globalDebug) echo 'Count all pilots by months...'."\n";
1825
+			if ($globalDebug) {
1826
+				echo 'Count all pilots by months...'."\n";
1827
+			}
1589 1828
 			$alldata = $Spotter->countAllMonthsPilots();
1590 1829
 			foreach ($alldata as $number) {
1591 1830
 				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1592 1831
 			}
1593
-			if ($globalDebug) echo 'Count all airlines by months...'."\n";
1832
+			if ($globalDebug) {
1833
+				echo 'Count all airlines by months...'."\n";
1834
+			}
1594 1835
 			$alldata = $Spotter->countAllMonthsAirlines();
1595 1836
 			foreach ($alldata as $number) {
1596 1837
 				$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1597 1838
 			}
1598
-			if ($globalDebug) echo 'Count all aircrafts by months...'."\n";
1839
+			if ($globalDebug) {
1840
+				echo 'Count all aircrafts by months...'."\n";
1841
+			}
1599 1842
 			$alldata = $Spotter->countAllMonthsAircrafts();
1600 1843
 			foreach ($alldata as $number) {
1601 1844
 				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1602 1845
 			}
1603
-			if ($globalDebug) echo 'Count all real arrivals by months...'."\n";
1846
+			if ($globalDebug) {
1847
+				echo 'Count all real arrivals by months...'."\n";
1848
+			}
1604 1849
 			$alldata = $Spotter->countAllMonthsRealArrivals();
1605 1850
 			foreach ($alldata as $number) {
1606 1851
 				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1607 1852
 			}
1608
-			if ($globalDebug) echo 'Airports data...'."\n";
1609
-			if ($globalDebug) echo '...Departure'."\n";
1853
+			if ($globalDebug) {
1854
+				echo 'Airports data...'."\n";
1855
+			}
1856
+			if ($globalDebug) {
1857
+				echo '...Departure'."\n";
1858
+			}
1610 1859
 			$this->deleteStatAirport('daily');
1611 1860
 //			$pall = $Spotter->getLast7DaysAirportsDeparture();
1612 1861
   //      		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
@@ -1727,44 +1976,62 @@  discard block
 block discarded – undo
1727 1976
 			// Count by airlines
1728 1977
 			echo '--- Stats by airlines ---'."\n";
1729 1978
 			if ($Connection->tableExists('countries')) {
1730
-				if ($globalDebug) echo 'Count all flights by countries by airlines...'."\n";
1979
+				if ($globalDebug) {
1980
+					echo 'Count all flights by countries by airlines...'."\n";
1981
+				}
1731 1982
 				$SpotterArchive = new SpotterArchive();
1732 1983
 				$alldata = $SpotterArchive->countAllFlightOverCountriesByAirlines(false,0,$last_update_day);
1733 1984
 				foreach ($alldata as $number) {
1734 1985
 					$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count'],$number['airline_icao'],'',$reset);
1735 1986
 				}
1736 1987
 			}
1737
-			if ($globalDebug) echo 'Count all aircraft types by airlines...'."\n";
1988
+			if ($globalDebug) {
1989
+				echo 'Count all aircraft types by airlines...'."\n";
1990
+			}
1738 1991
 			$Spotter = new Spotter($this->db);
1739 1992
 			$alldata = $Spotter->countAllAircraftTypesByAirlines(false,0,$last_update_day);
1740 1993
 			foreach ($alldata as $number) {
1741 1994
 				$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],$number['airline_icao'],'',$reset);
1742 1995
 			}
1743
-			if ($globalDebug) echo 'Count all aircraft registrations by airlines...'."\n";
1996
+			if ($globalDebug) {
1997
+				echo 'Count all aircraft registrations by airlines...'."\n";
1998
+			}
1744 1999
 			$alldata = $Spotter->countAllAircraftRegistrationsByAirlines(false,0,$last_update_day);
1745 2000
 			foreach ($alldata as $number) {
1746 2001
 				$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],$number['airline_icao'],'',$reset);
1747 2002
 			}
1748
-			if ($globalDebug) echo 'Count all callsigns by airlines...'."\n";
2003
+			if ($globalDebug) {
2004
+				echo 'Count all callsigns by airlines...'."\n";
2005
+			}
1749 2006
 			$alldata = $Spotter->countAllCallsignsByAirlines(false,0,$last_update_day);
1750 2007
 			foreach ($alldata as $number) {
1751 2008
 				$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset);
1752 2009
 			}
1753
-			if ($globalDebug) echo 'Count all owners by airlines...'."\n";
2010
+			if ($globalDebug) {
2011
+				echo 'Count all owners by airlines...'."\n";
2012
+			}
1754 2013
 			$alldata = $Spotter->countAllOwnersByAirlines(false,0,$last_update_day);
1755 2014
 			foreach ($alldata as $number) {
1756 2015
 				$this->addStatOwner($number['owner_name'],$number['owner_count'],$number['airline_icao'],'',$reset);
1757 2016
 			}
1758
-			if ($globalDebug) echo 'Count all pilots by airlines...'."\n";
2017
+			if ($globalDebug) {
2018
+				echo 'Count all pilots by airlines...'."\n";
2019
+			}
1759 2020
 			$alldata = $Spotter->countAllPilotsByAirlines(false,0,$last_update_day);
1760 2021
 			foreach ($alldata as $number) {
1761 2022
 				$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],$number['airline_icao'],'',$number['format_source'],$reset);
1762 2023
 			}
1763
-			if ($globalDebug) echo 'Count all departure airports by airlines...'."\n";
2024
+			if ($globalDebug) {
2025
+				echo 'Count all departure airports by airlines...'."\n";
2026
+			}
1764 2027
 			$pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day);
1765
-			if ($globalDebug) echo 'Count all detected departure airports by airlines...'."\n";
2028
+			if ($globalDebug) {
2029
+				echo 'Count all detected departure airports by airlines...'."\n";
2030
+			}
1766 2031
        			$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);
1767
-			if ($globalDebug) echo 'Order detected departure airports by airlines...'."\n";
2032
+			if ($globalDebug) {
2033
+				echo 'Order detected departure airports by airlines...'."\n";
2034
+			}
1768 2035
 	        	//$alldata = array();
1769 2036
     			foreach ($dall as $value) {
1770 2037
     				$icao = $value['airport_departure_icao'];
@@ -1785,11 +2052,17 @@  discard block
 block discarded – undo
1785 2052
 			foreach ($alldata as $number) {
1786 2053
 				echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],$number['airline_icao'],'',$reset);
1787 2054
 			}
1788
-			if ($globalDebug) echo 'Count all arrival airports by airlines...'."\n";
2055
+			if ($globalDebug) {
2056
+				echo 'Count all arrival airports by airlines...'."\n";
2057
+			}
1789 2058
 			$pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day);
1790
-			if ($globalDebug) echo 'Count all detected arrival airports by airlines...'."\n";
2059
+			if ($globalDebug) {
2060
+				echo 'Count all detected arrival airports by airlines...'."\n";
2061
+			}
1791 2062
         		$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);
1792
-			if ($globalDebug) echo 'Order arrival airports by airlines...'."\n";
2063
+			if ($globalDebug) {
2064
+				echo 'Order arrival airports by airlines...'."\n";
2065
+			}
1793 2066
 	        	//$alldata = array();
1794 2067
     			foreach ($dall as $value) {
1795 2068
     				$icao = $value['airport_arrival_icao'];
@@ -1808,37 +2081,53 @@  discard block
 block discarded – undo
1808 2081
     			}
1809 2082
     			$alldata = $pall;
1810 2083
                         foreach ($alldata as $number) {
1811
-				if ($number['airline_icao'] != '') echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset);
2084
+				if ($number['airline_icao'] != '') {
2085
+					echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset);
2086
+				}
2087
+			}
2088
+			if ($globalDebug) {
2089
+				echo 'Count all flights by months by airlines...'."\n";
1812 2090
 			}
1813
-			if ($globalDebug) echo 'Count all flights by months by airlines...'."\n";
1814 2091
 			$Spotter = new Spotter($this->db);
1815 2092
 			$alldata = $Spotter->countAllMonthsByAirlines();
1816 2093
 			$lastyear = false;
1817 2094
 			foreach ($alldata as $number) {
1818
-				if ($number['year_name'] != date('Y')) $lastyear = true;
2095
+				if ($number['year_name'] != date('Y')) {
2096
+					$lastyear = true;
2097
+				}
1819 2098
 				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']);
1820 2099
 			}
1821
-			if ($globalDebug) echo 'Count all owners by months by airlines...'."\n";
2100
+			if ($globalDebug) {
2101
+				echo 'Count all owners by months by airlines...'."\n";
2102
+			}
1822 2103
 			$alldata = $Spotter->countAllMonthsOwnersByAirlines();
1823 2104
 			foreach ($alldata as $number) {
1824 2105
 				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']);
1825 2106
 			}
1826
-			if ($globalDebug) echo 'Count all pilots by months by airlines...'."\n";
2107
+			if ($globalDebug) {
2108
+				echo 'Count all pilots by months by airlines...'."\n";
2109
+			}
1827 2110
 			$alldata = $Spotter->countAllMonthsPilotsByAirlines();
1828 2111
 			foreach ($alldata as $number) {
1829 2112
 				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']);
1830 2113
 			}
1831
-			if ($globalDebug) echo 'Count all aircrafts by months by airlines...'."\n";
2114
+			if ($globalDebug) {
2115
+				echo 'Count all aircrafts by months by airlines...'."\n";
2116
+			}
1832 2117
 			$alldata = $Spotter->countAllMonthsAircraftsByAirlines();
1833 2118
 			foreach ($alldata as $number) {
1834 2119
 				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']);
1835 2120
 			}
1836
-			if ($globalDebug) echo 'Count all real arrivals by months by airlines...'."\n";
2121
+			if ($globalDebug) {
2122
+				echo 'Count all real arrivals by months by airlines...'."\n";
2123
+			}
1837 2124
 			$alldata = $Spotter->countAllMonthsRealArrivalsByAirlines();
1838 2125
 			foreach ($alldata as $number) {
1839 2126
 				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']);
1840 2127
 			}
1841
-			if ($globalDebug) echo '...Departure'."\n";
2128
+			if ($globalDebug) {
2129
+				echo '...Departure'."\n";
2130
+			}
1842 2131
 			$pall = $Spotter->getLast7DaysAirportsDepartureByAirlines();
1843 2132
         		$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();
1844 2133
     			foreach ($dall as $value) {
@@ -1861,7 +2150,9 @@  discard block
 block discarded – undo
1861 2150
 			foreach ($alldata as $number) {
1862 2151
 				$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],$number['airline_icao']);
1863 2152
 			}
1864
-			if ($globalDebug) echo '...Arrival'."\n";
2153
+			if ($globalDebug) {
2154
+				echo '...Arrival'."\n";
2155
+			}
1865 2156
 			$pall = $Spotter->getLast7DaysAirportsArrivalByAirlines();
1866 2157
         		$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();
1867 2158
     			foreach ($dall as $value) {
@@ -1885,13 +2176,19 @@  discard block
 block discarded – undo
1885 2176
 				$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],$number['airline_icao']);
1886 2177
 			}
1887 2178
 
1888
-			if ($globalDebug) echo 'Flights data...'."\n";
1889
-			if ($globalDebug) echo '-> countAllDatesLastMonth...'."\n";
2179
+			if ($globalDebug) {
2180
+				echo 'Flights data...'."\n";
2181
+			}
2182
+			if ($globalDebug) {
2183
+				echo '-> countAllDatesLastMonth...'."\n";
2184
+			}
1890 2185
 			$alldata = $Spotter->countAllDatesLastMonthByAirlines();
1891 2186
 			foreach ($alldata as $number) {
1892 2187
 				$this->addStatFlight('month',$number['date_name'],$number['date_count'], $number['airline_icao']);
1893 2188
 			}
1894
-			if ($globalDebug) echo '-> countAllDates...'."\n";
2189
+			if ($globalDebug) {
2190
+				echo '-> countAllDates...'."\n";
2191
+			}
1895 2192
 			//$previousdata = $this->countAllDatesByAirlines();
1896 2193
 			$alldata = $Common->array_merge_noappend($previousdatabyairlines,$Spotter->countAllDatesByAirlines());
1897 2194
 			$values = array();
@@ -1904,7 +2201,9 @@  discard block
 block discarded – undo
1904 2201
 				$this->addStatFlight('date',$number['date_name'],$number['date_count'],$number['airline_icao']);
1905 2202
 			}
1906 2203
 			
1907
-			if ($globalDebug) echo '-> countAllHours...'."\n";
2204
+			if ($globalDebug) {
2205
+				echo '-> countAllHours...'."\n";
2206
+			}
1908 2207
 			$alldata = $Spotter->countAllHoursByAirlines('hour');
1909 2208
 			foreach ($alldata as $number) {
1910 2209
 				$this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],$number['airline_icao']);
@@ -1912,7 +2211,9 @@  discard block
 block discarded – undo
1912 2211
 			
1913 2212
 
1914 2213
 			// Stats by filters
1915
-			if (!isset($globalStatsFilters) || $globalStatsFilters == '') $globalStatsFilters = array();
2214
+			if (!isset($globalStatsFilters) || $globalStatsFilters == '') {
2215
+				$globalStatsFilters = array();
2216
+			}
1916 2217
 			foreach ($globalStatsFilters as $name => $filter) {
1917 2218
 				//$filter_name = $filter['name'];
1918 2219
 				$filter_name = $name;
@@ -1936,7 +2237,9 @@  discard block
 block discarded – undo
1936 2237
 				
1937 2238
 
1938 2239
 				// Count by filter
1939
-				if ($globalDebug) echo '--- Stats for filter '.$filter_name.' ---'."\n";
2240
+				if ($globalDebug) {
2241
+					echo '--- Stats for filter '.$filter_name.' ---'."\n";
2242
+				}
1940 2243
 				$Spotter = new Spotter($this->db);
1941 2244
 				$alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day,$filter);
1942 2245
 				foreach ($alldata as $number) {
@@ -1973,7 +2276,9 @@  discard block
 block discarded – undo
1973 2276
 	    				$icao = $value['airport_departure_icao'];
1974 2277
         				if (isset($alldata[$icao])) {
1975 2278
     						$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1976
-        				} else $alldata[$icao] = $value;
2279
+        				} else {
2280
+        					$alldata[$icao] = $value;
2281
+        				}
1977 2282
 				}
1978 2283
 	    			$count = array();
1979 2284
     				foreach ($alldata as $key => $row) {
@@ -1994,7 +2299,9 @@  discard block
 block discarded – undo
1994 2299
 	    				$icao = $value['airport_arrival_icao'];
1995 2300
         				if (isset($alldata[$icao])) {
1996 2301
         					$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1997
-		        		} else $alldata[$icao] = $value;
2302
+		        		} else {
2303
+		        			$alldata[$icao] = $value;
2304
+		        		}
1998 2305
 	    			}
1999 2306
         			$count = array();
2000 2307
         			foreach ($alldata as $key => $row) {
@@ -2008,7 +2315,9 @@  discard block
 block discarded – undo
2008 2315
 				$alldata = $Spotter->countAllMonths($filter);
2009 2316
 				$lastyear = false;
2010 2317
 				foreach ($alldata as $number) {
2011
-					if ($number['year_name'] != date('Y')) $lastyear = true;
2318
+					if ($number['year_name'] != date('Y')) {
2319
+						$lastyear = true;
2320
+					}
2012 2321
 					$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name);
2013 2322
 				}
2014 2323
 				$alldata = $Spotter->countAllMonthsOwners($filter);
Please login to merge, or discard this patch.
require/class.APRS.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class aprs {
3
-    protected $symbols = array('!' => 'Police',
3
+	protected $symbols = array('!' => 'Police',
4 4
 	'#' => 'DIGI',
5 5
 	'$' => 'Phone',
6 6
 	'%' => 'DX Cluster',
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	'y' => 'Yagi At QTH');
85 85
 	
86 86
 
87
-    private function urshift($n, $s) {
87
+	private function urshift($n, $s) {
88 88
 	return ($n >= 0) ? ($n >> $s) :
89
-    	    (($n & 0x7fffffff) >> $s) | 
90
-        	(0x40000000 >> ($s - 1));
91
-    }
89
+			(($n & 0x7fffffff) >> $s) | 
90
+			(0x40000000 >> ($s - 1));
91
+	}
92 92
 
93
-    public function parse($input) {
93
+	public function parse($input) {
94 94
 	global $globalDebug;
95 95
 	$debug = false;
96 96
 	$result = array();
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 	
103 103
 	/* Check that end was found and body has at least one byte. */
104 104
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
105
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
106
-	    return false;
105
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
106
+		return false;
107 107
 	}
108 108
 	
109 109
 	/* Save header and body. */
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
 	/* Parse source, target and path. */
117 117
 	//FLRDF0A52>APRS,qAS,LSTB
118 118
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
119
-	    $ident = $matches[1];
120
-	    $all_elements = $matches[2];
121
-	    if ($debug) echo 'ident : '.$ident."\n";
122
-	    $result['ident'] = $ident;
119
+		$ident = $matches[1];
120
+		$all_elements = $matches[2];
121
+		if ($debug) echo 'ident : '.$ident."\n";
122
+		$result['ident'] = $ident;
123 123
 	} else return false;
124 124
 	$elements = explode(',',$all_elements);
125 125
 	$source = end($elements);
126 126
 	$result['source'] = $source;
127 127
 	foreach ($elements as $element) {
128
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
129
-	        //echo "ok";
130
-	        if ($element == 'TCPIP*') return false;
131
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
128
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
129
+			//echo "ok";
130
+			if ($element == 'TCPIP*') return false;
131
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
132 132
 		return false;
133
-	    }
134
-	    /*
133
+		}
134
+		/*
135 135
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
136 136
 		//echo "ok";
137 137
 	    } else {
@@ -144,42 +144,42 @@  discard block
 block discarded – undo
144 144
 	$body_parse = substr($body,1);
145 145
 	//echo 'Body : '.$body."\n";
146 146
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
147
-	    $body_parse = substr($body_parse,10);
148
-	    $find = true;
149
-	    //echo $body_parse."\n";
147
+		$body_parse = substr($body_parse,10);
148
+		$find = true;
149
+		//echo $body_parse."\n";
150 150
 	}
151 151
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
152
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
153
-	    $find = true;
154
-	    //echo $body_parse."\n";
152
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
153
+		$find = true;
154
+		//echo $body_parse."\n";
155 155
 	}
156 156
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
157
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
158
-	    $find = true;
159
-	    //echo $body_parse."\n";
157
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
158
+		$find = true;
159
+		//echo $body_parse."\n";
160 160
 	}
161 161
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
162
-	    $find = true;
163
-	    //print_r($matches);
164
-	    $timestamp = $matches[0];
165
-	    if ($matches[4] == 'h') {
162
+		$find = true;
163
+		//print_r($matches);
164
+		$timestamp = $matches[0];
165
+		if ($matches[4] == 'h') {
166 166
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
167 167
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
168 168
 		/*
169 169
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
170 170
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
171 171
 		*/
172
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
172
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
173 173
 		// This work or not ?
174 174
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
175
-	    }
176
-	    $body_parse = substr($body_parse,7);
177
-	    $result['timestamp'] = $timestamp;
178
-	    //echo date('Ymd H:i:s',$timestamp);
175
+		}
176
+		$body_parse = substr($body_parse,7);
177
+		$result['timestamp'] = $timestamp;
178
+		//echo date('Ymd H:i:s',$timestamp);
179 179
 	}
180 180
 	//if (strlen($body_parse) > 19) {
181
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
182
-	    $find = true;
181
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
182
+		$find = true;
183 183
 		// 4658.70N/00707.78Ez
184 184
 		//print_r(str_split($body_parse));
185 185
 		
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		$lon = intval($lon_deg);
197 197
 		if ($lat > 89 || $lon > 179) return false;
198 198
 	    
199
-	    /*
199
+		/*
200 200
 	    $tmp_5b = str_replace('.','',$lat_min);
201 201
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
202 202
 	        print_r($matches);
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 		$result['longitude'] = $longitude;
211 211
 		$body_parse = substr($body_parse,18);
212 212
 		$body_parse_len = strlen($body_parse);
213
-	    }
214
-	    if ($body_len > 0) {
213
+		}
214
+		if ($body_len > 0) {
215 215
 		/*
216 216
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
217 217
 			$body_split = str_split($body);
@@ -237,60 +237,60 @@  discard block
 block discarded – undo
237 237
 		$result['symbol_code'] = $symbol_code;
238 238
 		if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
239 239
 		if ($symbol_code != '_') {
240
-		    //$body_parse = substr($body_parse,1);
241
-		    //$body_parse = trim($body_parse);
242
-		    //$body_parse_len = strlen($body_parse);
243
-		    if ($body_parse_len >= 7) {
240
+			//$body_parse = substr($body_parse,1);
241
+			//$body_parse = trim($body_parse);
242
+			//$body_parse_len = strlen($body_parse);
243
+			if ($body_parse_len >= 7) {
244 244
 			
245
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
246
-		    	    $course = substr($body_parse,0,3);
247
-		    	    $tmp_s = intval($course);
248
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
249
-		    	    $speed = substr($body_parse,4,3);
250
-		    	    $result['speed'] = round($speed*1.852);
251
-		    	    $body_parse = substr($body_parse,7);
252
-		        }
253
-		        // Check PHGR, PHG, RNG
254
-		    } 
255
-		    /*
245
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
246
+					$course = substr($body_parse,0,3);
247
+					$tmp_s = intval($course);
248
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
249
+					$speed = substr($body_parse,4,3);
250
+					$result['speed'] = round($speed*1.852);
251
+					$body_parse = substr($body_parse,7);
252
+				}
253
+				// Check PHGR, PHG, RNG
254
+			} 
255
+			/*
256 256
 		    else if ($body_parse_len > 0) {
257 257
 			$rest = $body_parse;
258 258
 		    }
259 259
 		    */
260
-		    if (strlen($body_parse) > 0) {
261
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
262
-		            $altitude = intval($matches[1]);
263
-		            //$result['altitude'] = round($altitude*0.3048);
264
-		            $result['altitude'] = $altitude;
265
-		            $body_parse = trim(substr($body_parse,strlen($matches[0])));
266
-		        }
267
-		    }
260
+			if (strlen($body_parse) > 0) {
261
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
262
+					$altitude = intval($matches[1]);
263
+					//$result['altitude'] = round($altitude*0.3048);
264
+					$result['altitude'] = $altitude;
265
+					$body_parse = trim(substr($body_parse,strlen($matches[0])));
266
+				}
267
+			}
268 268
 		    
269
-		    // Telemetry
270
-		    /*
269
+			// Telemetry
270
+			/*
271 271
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
272 272
 		        // Nothing yet...
273 273
 		    }
274 274
 		    */
275
-		    // DAO
276
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
277
-			    $dao = $matches[1];
278
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
275
+			// DAO
276
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
277
+				$dao = $matches[1];
278
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
279 279
 				$dao_split = str_split($dao);
280
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
281
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
280
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
281
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
282 282
 			    
283 283
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
284 284
 				else $result['latitude'] += $lat_off;
285 285
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
286 286
 				else $result['longitude'] += $lon_off;
287
-			    }
288
-		            $body_parse = substr($body_parse,6);
289
-		    }
287
+				}
288
+					$body_parse = substr($body_parse,6);
289
+			}
290 290
 		    
291
-		    // OGN comment
291
+			// OGN comment
292 292
 		   // echo "Before OGN : ".$body_parse."\n";
293
-		    if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
293
+			if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
294 294
 			$id = $matches[1];
295 295
 			//$mode = substr($id,0,2);
296 296
 			$address = substr($id,2);
@@ -320,49 +320,49 @@  discard block
 block discarded – undo
320 320
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
321 321
 			$result['stealth'] = $stealth;
322 322
 			$result['address'] = $address;
323
-		    }
323
+			}
324 324
 		    
325
-		    //Comment
326
-		    $result['comment'] = trim($body_parse);
325
+			//Comment
326
+			$result['comment'] = trim($body_parse);
327 327
 		} else {
328
-		    // parse weather
329
-		    //$body_parse = substr($body_parse,1);
330
-		    //$body_parse_len = strlen($body_parse);
328
+			// parse weather
329
+			//$body_parse = substr($body_parse,1);
330
+			//$body_parse_len = strlen($body_parse);
331 331
 
332
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
333
-			    $result['wind_dir'] = intval($matches[1]);
334
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
335
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
336
-			    $result['temp'] = round(5/9*(($matches[4])-32),1);
337
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
338
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
332
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
333
+				$result['wind_dir'] = intval($matches[1]);
334
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
335
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
336
+				$result['temp'] = round(5/9*(($matches[4])-32),1);
337
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
338
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
339 339
 			$result['wind_dir'] = intval($matches[1]);
340 340
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
341 341
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
342 342
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
343
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
344
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
343
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
344
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
345 345
 			$result['wind_dir'] = intval($matches[1]);
346 346
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
347 347
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
348
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
349
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
348
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
349
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
350 350
 			$result['wind_dir'] = intval($matches[1]);
351 351
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
352 352
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
353
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
354
-		    }
355
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
353
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
354
+			}
355
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
356 356
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
357
-		    }
357
+			}
358
+		}
358 359
 		}
359
-	    }
360 360
 	//}
361 361
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
362 362
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
363 363
 	//print_r($result);
364 364
 	return $result;
365
-    }
365
+	}
366 366
 }
367 367
 /*
368 368
 $aprs = new aprs();
Please login to merge, or discard this patch.
Braces   +86 added lines, -35 removed lines patch added patch discarded remove patch
@@ -102,7 +102,9 @@  discard block
 block discarded – undo
102 102
 	
103 103
 	/* Check that end was found and body has at least one byte. */
104 104
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
105
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
105
+	    if ($globalDebug) {
106
+	    	echo '!!! APRS invalid : '.$input."\n";
107
+	    }
106 108
 	    return false;
107 109
 	}
108 110
 	
@@ -111,23 +113,31 @@  discard block
 block discarded – undo
111 113
 	$body_len = strlen($body);
112 114
 	$header = substr($input,0,$splitpos);
113 115
 	//$header_len = strlen($header);
114
-	if ($debug) echo 'header : '.$header."\n";
116
+	if ($debug) {
117
+		echo 'header : '.$header."\n";
118
+	}
115 119
 	
116 120
 	/* Parse source, target and path. */
117 121
 	//FLRDF0A52>APRS,qAS,LSTB
118 122
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
119 123
 	    $ident = $matches[1];
120 124
 	    $all_elements = $matches[2];
121
-	    if ($debug) echo 'ident : '.$ident."\n";
125
+	    if ($debug) {
126
+	    	echo 'ident : '.$ident."\n";
127
+	    }
122 128
 	    $result['ident'] = $ident;
123
-	} else return false;
129
+	} else {
130
+		return false;
131
+	}
124 132
 	$elements = explode(',',$all_elements);
125 133
 	$source = end($elements);
126 134
 	$result['source'] = $source;
127 135
 	foreach ($elements as $element) {
128 136
 	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
129 137
 	        //echo "ok";
130
-	        if ($element == 'TCPIP*') return false;
138
+	        if ($element == 'TCPIP*') {
139
+	        	return false;
140
+	        }
131 141
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
132 142
 		return false;
133 143
 	    }
@@ -194,7 +204,9 @@  discard block
 block discarded – undo
194 204
 		//$symbol_table = $matches[4];
195 205
 		$lat = intval($lat_deg);
196 206
 		$lon = intval($lon_deg);
197
-		if ($lat > 89 || $lon > 179) return false;
207
+		if ($lat > 89 || $lon > 179) {
208
+			return false;
209
+		}
198 210
 	    
199 211
 	    /*
200 212
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -204,8 +216,12 @@  discard block
 block discarded – undo
204 216
 	    */
205 217
 		$latitude = $lat + floatval($lat_min)/60;
206 218
 		$longitude = $lon + floatval($lon_min)/60;
207
-		if ($sind == 'S') $latitude = 0-$latitude;
208
-		if ($wind == 'W') $longitude = 0-$longitude;
219
+		if ($sind == 'S') {
220
+			$latitude = 0-$latitude;
221
+		}
222
+		if ($wind == 'W') {
223
+			$longitude = 0-$longitude;
224
+		}
209 225
 		$result['latitude'] = $latitude;
210 226
 		$result['longitude'] = $longitude;
211 227
 		$body_parse = substr($body_parse,18);
@@ -235,7 +251,9 @@  discard block
 block discarded – undo
235 251
 		//}
236 252
 		//echo $body_parse;
237 253
 		$result['symbol_code'] = $symbol_code;
238
-		if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
254
+		if (isset($this->symbols[$symbol_code])) {
255
+			$result['symbol'] = $this->symbols[$symbol_code];
256
+		}
239 257
 		if ($symbol_code != '_') {
240 258
 		    //$body_parse = substr($body_parse,1);
241 259
 		    //$body_parse = trim($body_parse);
@@ -245,7 +263,9 @@  discard block
 block discarded – undo
245 263
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
246 264
 		    	    $course = substr($body_parse,0,3);
247 265
 		    	    $tmp_s = intval($course);
248
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
266
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
267
+		    	    	$result['heading'] = intval($course);
268
+		    	    }
249 269
 		    	    $speed = substr($body_parse,4,3);
250 270
 		    	    $result['speed'] = round($speed*1.852);
251 271
 		    	    $body_parse = substr($body_parse,7);
@@ -280,10 +300,16 @@  discard block
 block discarded – undo
280 300
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
281 301
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
282 302
 			    
283
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
284
-				else $result['latitude'] += $lat_off;
285
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
286
-				else $result['longitude'] += $lon_off;
303
+				if ($result['latitude'] < 0) {
304
+					$result['latitude'] -= $lat_off;
305
+				} else {
306
+					$result['latitude'] += $lat_off;
307
+				}
308
+				if ($result['longitude'] < 0) {
309
+					$result['longitude'] -= $lon_off;
310
+				} else {
311
+					$result['longitude'] += $lon_off;
312
+				}
287 313
 			    }
288 314
 		            $body_parse = substr($body_parse,6);
289 315
 		    }
@@ -296,27 +322,48 @@  discard block
 block discarded – undo
296 322
 			$address = substr($id,2);
297 323
 			//print_r($matches);
298 324
 			$addressType = (intval(substr($id,0,2),16))&3;
299
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
300
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
301
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
302
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
325
+			if ($addressType == 0) {
326
+				$result['addresstype'] = "RANDOM";
327
+			} elseif ($addressType == 1) {
328
+				$result['addresstype'] = "ICAO";
329
+			} elseif ($addressType == 2) {
330
+				$result['addresstype'] = "FLARM";
331
+			} elseif ($addressType == 3) {
332
+				$result['addresstype'] = "OGN";
333
+			}
303 334
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
304 335
 			$result['aircrafttype_code'] = $aircraftType;
305
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
306
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
307
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
308
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
309
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
310
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
311
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
312
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
313
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
314
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
315
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
316
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
317
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
318
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
319
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
336
+			if ($aircraftType == 0) {
337
+				$result['aircrafttype'] = "UNKNOWN";
338
+			} elseif ($aircraftType == 1) {
339
+				$result['aircrafttype'] = "GLIDER";
340
+			} elseif ($aircraftType == 2) {
341
+				$result['aircrafttype'] = "TOW_PLANE";
342
+			} elseif ($aircraftType == 3) {
343
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
344
+			} elseif ($aircraftType == 4) {
345
+				$result['aircrafttype'] = "PARACHUTE";
346
+			} elseif ($aircraftType == 5) {
347
+				$result['aircrafttype'] = "DROP_PLANE";
348
+			} elseif ($aircraftType == 6) {
349
+				$result['aircrafttype'] = "HANG_GLIDER";
350
+			} elseif ($aircraftType == 7) {
351
+				$result['aircrafttype'] = "PARA_GLIDER";
352
+			} elseif ($aircraftType == 8) {
353
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
354
+			} elseif ($aircraftType == 9) {
355
+				$result['aircrafttype'] = "JET_AIRCRAFT";
356
+			} elseif ($aircraftType == 10) {
357
+				$result['aircrafttype'] = "UFO";
358
+			} elseif ($aircraftType == 11) {
359
+				$result['aircrafttype'] = "BALLOON";
360
+			} elseif ($aircraftType == 12) {
361
+				$result['aircrafttype'] = "AIRSHIP";
362
+			} elseif ($aircraftType == 13) {
363
+				$result['aircrafttype'] = "UAV";
364
+			} elseif ($aircraftType == 15) {
365
+				$result['aircrafttype'] = "STATIC_OBJECT";
366
+			}
320 367
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
321 368
 			$result['stealth'] = $stealth;
322 369
 			$result['address'] = $address;
@@ -358,8 +405,12 @@  discard block
 block discarded – undo
358 405
 		}
359 406
 	    }
360 407
 	//}
361
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
362
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
408
+	if (isset($result['latitude'])) {
409
+		$result['latitude'] = round($result['latitude'],4);
410
+	}
411
+	if (isset($result['longitude'])) {
412
+		$result['longitude'] = round($result['longitude'],4);
413
+	}
363 414
 	//print_r($result);
364 415
 	return $result;
365 416
     }
Please login to merge, or discard this patch.