Completed
Push — master ( 54c225...de7e29 )
by Yannick
06:07
created
scripts/daemon-spotter.php 1 patch
Indentation   +694 added lines, -694 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
@@ -83,161 +83,161 @@  discard block
 block discarded – undo
83 83
 $aprs_full = false;
84 84
 
85 85
 function create_socket($host, $port, &$errno, &$errstr) {
86
-    $ip = gethostbyname($host);
87
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
88
-    $r = @socket_connect($s, $ip, $port);
89
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
90
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
91
-        return $s;
92
-    }
93
-    $errno = socket_last_error($s);
94
-    $errstr = socket_strerror($errno);
95
-    socket_close($s);
96
-    return false;
86
+	$ip = gethostbyname($host);
87
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
88
+	$r = @socket_connect($s, $ip, $port);
89
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
90
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
91
+		return $s;
92
+	}
93
+	$errno = socket_last_error($s);
94
+	$errstr = socket_strerror($errno);
95
+	socket_close($s);
96
+	return false;
97 97
 }
98 98
 
99 99
 function create_socket_udp($host, $port, &$errno, &$errstr) {
100
-    echo "UDP !!";
101
-    $ip = gethostbyname($host);
102
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
103
-    $r = @socket_bind($s, $ip, $port);
104
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
105
-        return $s;
106
-    }
107
-    $errno = socket_last_error($s);
108
-    $errstr = socket_strerror($errno);
109
-    socket_close($s);
110
-    return false;
100
+	echo "UDP !!";
101
+	$ip = gethostbyname($host);
102
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
103
+	$r = @socket_bind($s, $ip, $port);
104
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
105
+		return $s;
106
+	}
107
+	$errno = socket_last_error($s);
108
+	$errstr = socket_strerror($errno);
109
+	socket_close($s);
110
+	return false;
111 111
 }
112 112
 
113 113
 function connect_all($hosts) {
114
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
115
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
117
-    foreach ($hosts as $id => $value) {
114
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
115
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	if ($globalDebug) echo 'Connect to all...'."\n";
117
+	foreach ($hosts as $id => $value) {
118 118
 	$host = $value['host'];
119 119
 	$globalSources[$id]['last_exec'] = 0;
120 120
 	// Here we check type of source(s)
121 121
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
122
-            if (preg_match('/deltadb.txt$/i',$host)) {
123
-        	//$formats[$id] = 'deltadbtxt';
124
-        	$globalSources[$id]['format'] = 'deltadbtxt';
125
-        	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
-        	//$formats[$id] = 'vatsimtxt';
129
-        	$globalSources[$id]['format'] = 'vatsimtxt';
130
-        	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133
-        	//$formats[$id] = 'aircraftlistjson';
134
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
135
-        	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
-    	    } else if (preg_match('/opensky/i',$host)) {
138
-        	//$formats[$id] = 'aircraftlistjson';
139
-        	$globalSources[$id]['format'] = 'opensky';
140
-        	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
-        	//$formats[$id] = 'radarvirtueljson';
144
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
145
-        	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
-        	    exit(0);
150
-        	}
151
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
-        	//$formats[$id] = 'planeupdatefaa';
153
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
154
-        	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
-        	    exit(0);
159
-        	}
160
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
-        	//$formats[$id] = 'phpvmacars';
162
-        	$globalSources[$id]['format'] = 'phpvmacars';
163
-        	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
166
-        	//$formats[$id] = 'phpvmacars';
167
-        	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
-            } else if (preg_match('/whazzup/i',$host)) {
170
-        	//$formats[$id] = 'whazzup';
171
-        	$globalSources[$id]['format'] = 'whazzup';
172
-        	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
-            } else if (preg_match('/recentpireps/i',$host)) {
175
-        	//$formats[$id] = 'pirepsjson';
176
-        	$globalSources[$id]['format'] = 'pirepsjson';
177
-        	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
-        	//$formats[$id] = 'fr24json';
181
-        	$globalSources[$id]['format'] = 'fr24json';
182
-        	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
-        	    exit(0);
187
-        	}
188
-            //} else if (preg_match('/10001/',$host)) {
189
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
190
-        	//$formats[$id] = 'tsv';
191
-        	$globalSources[$id]['format'] = 'tsv';
192
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
193
-            }
194
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
195
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
196
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
197
-	    $hostport = explode(':',$host);
198
-	    if (isset($hostport[1])) {
122
+			if (preg_match('/deltadb.txt$/i',$host)) {
123
+			//$formats[$id] = 'deltadbtxt';
124
+			$globalSources[$id]['format'] = 'deltadbtxt';
125
+			//$last_exec['deltadbtxt'] = 0;
126
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
127
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
128
+			//$formats[$id] = 'vatsimtxt';
129
+			$globalSources[$id]['format'] = 'vatsimtxt';
130
+			//$last_exec['vatsimtxt'] = 0;
131
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
132
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
133
+			//$formats[$id] = 'aircraftlistjson';
134
+			$globalSources[$id]['format'] = 'aircraftlistjson';
135
+			//$last_exec['aircraftlistjson'] = 0;
136
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
137
+			} else if (preg_match('/opensky/i',$host)) {
138
+			//$formats[$id] = 'aircraftlistjson';
139
+			$globalSources[$id]['format'] = 'opensky';
140
+			//$last_exec['aircraftlistjson'] = 0;
141
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
142
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143
+			//$formats[$id] = 'radarvirtueljson';
144
+			$globalSources[$id]['format'] = 'radarvirtueljson';
145
+			//$last_exec['radarvirtueljson'] = 0;
146
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
147
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149
+				exit(0);
150
+			}
151
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
152
+			//$formats[$id] = 'planeupdatefaa';
153
+			$globalSources[$id]['format'] = 'planeupdatefaa';
154
+			//$last_exec['planeupdatefaa'] = 0;
155
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
156
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158
+				exit(0);
159
+			}
160
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
161
+			//$formats[$id] = 'phpvmacars';
162
+			$globalSources[$id]['format'] = 'phpvmacars';
163
+			//$last_exec['phpvmacars'] = 0;
164
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
165
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
166
+			//$formats[$id] = 'phpvmacars';
167
+			$globalSources[$id]['format'] = 'vam';
168
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
169
+			} else if (preg_match('/whazzup/i',$host)) {
170
+			//$formats[$id] = 'whazzup';
171
+			$globalSources[$id]['format'] = 'whazzup';
172
+			//$last_exec['whazzup'] = 0;
173
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
174
+			} else if (preg_match('/recentpireps/i',$host)) {
175
+			//$formats[$id] = 'pirepsjson';
176
+			$globalSources[$id]['format'] = 'pirepsjson';
177
+			//$last_exec['pirepsjson'] = 0;
178
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
179
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180
+			//$formats[$id] = 'fr24json';
181
+			$globalSources[$id]['format'] = 'fr24json';
182
+			//$last_exec['fr24json'] = 0;
183
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
184
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186
+				exit(0);
187
+			}
188
+			//} else if (preg_match('/10001/',$host)) {
189
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
190
+			//$formats[$id] = 'tsv';
191
+			$globalSources[$id]['format'] = 'tsv';
192
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
193
+			}
194
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
195
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
196
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
197
+		$hostport = explode(':',$host);
198
+		if (isset($hostport[1])) {
199 199
 		$port = $hostport[1];
200 200
 		$hostn = $hostport[0];
201
-	    } else {
201
+		} else {
202 202
 		$port = $globalSources[$id]['port'];
203 203
 		$hostn = $globalSources[$id]['host'];
204
-	    }
205
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
206
-        	$s = create_socket($hostn,$port, $errno, $errstr);
207
-    	    } else {
208
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
209
-	    }
210
-	    if ($s) {
211
-    	        $sockets[$id] = $s;
212
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
213
-		    if (preg_match('/aprs/',$hostn)) {
204
+		}
205
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
206
+			$s = create_socket($hostn,$port, $errno, $errstr);
207
+			} else {
208
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
209
+		}
210
+		if ($s) {
211
+				$sockets[$id] = $s;
212
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
213
+			if (preg_match('/aprs/',$hostn)) {
214 214
 			//$formats[$id] = 'aprs';
215 215
 			$globalSources[$id]['format'] = 'aprs';
216 216
 			//$aprs_connect = 0;
217 217
 			//$use_aprs = true;
218
-    		    } elseif ($port == '10001') {
219
-        		//$formats[$id] = 'tsv';
220
-        		$globalSources[$id]['format'] = 'tsv';
221
-		    } elseif ($port == '30002') {
222
-        		//$formats[$id] = 'raw';
223
-        		$globalSources[$id]['format'] = 'raw';
224
-		    } elseif ($port == '5001') {
225
-        		//$formats[$id] = 'raw';
226
-        		$globalSources[$id]['format'] = 'flightgearmp';
227
-		    } elseif ($port == '30005') {
218
+				} elseif ($port == '10001') {
219
+				//$formats[$id] = 'tsv';
220
+				$globalSources[$id]['format'] = 'tsv';
221
+			} elseif ($port == '30002') {
222
+				//$formats[$id] = 'raw';
223
+				$globalSources[$id]['format'] = 'raw';
224
+			} elseif ($port == '5001') {
225
+				//$formats[$id] = 'raw';
226
+				$globalSources[$id]['format'] = 'flightgearmp';
227
+			} elseif ($port == '30005') {
228 228
 			// Not yet supported
229
-        		//$formats[$id] = 'beast';
230
-        		$globalSources[$id]['format'] = 'beast';
231
-		    //} else $formats[$id] = 'sbs';
232
-		    } else $globalSources[$id]['format'] = 'sbs';
233
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
229
+				//$formats[$id] = 'beast';
230
+				$globalSources[$id]['format'] = 'beast';
231
+			//} else $formats[$id] = 'sbs';
232
+			} else $globalSources[$id]['format'] = 'sbs';
233
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
234 234
 		}
235 235
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
236
-            } else {
236
+			} else {
237 237
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
238
-    	    }
239
-        }
240
-    }
238
+			}
239
+		}
240
+	}
241 241
 }
242 242
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
243 243
 
@@ -264,18 +264,18 @@  discard block
 block discarded – undo
264 264
 	die;
265 265
 }
266 266
 foreach ($globalSources as $key => $source) {
267
-    if (!isset($source['format'])) {
268
-        $globalSources[$key]['format'] = 'auto';
269
-    }
267
+	if (!isset($source['format'])) {
268
+		$globalSources[$key]['format'] = 'auto';
269
+	}
270 270
 }
271 271
 connect_all($globalSources);
272 272
 foreach ($globalSources as $key => $source) {
273
-    if (isset($source['format']) && $source['format'] == 'aprs') {
273
+	if (isset($source['format']) && $source['format'] == 'aprs') {
274 274
 	$aprs_connect = 0;
275 275
 	$use_aprs = true;
276 276
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
277 277
 	break;
278
-    }
278
+	}
279 279
 }
280 280
 
281 281
 if ($use_aprs) {
@@ -315,67 +315,67 @@  discard block
 block discarded – undo
315 315
 
316 316
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
317 317
 while ($i > 0) {
318
-    if (!$globalDaemon) $i = $endtime-time();
319
-    // Delete old ATC
320
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
318
+	if (!$globalDaemon) $i = $endtime-time();
319
+	// Delete old ATC
320
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
321 321
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
322
-        $ATC->deleteOldATC();
323
-    }
322
+		$ATC->deleteOldATC();
323
+	}
324 324
     
325
-    if (count($last_exec) > 0) {
325
+	if (count($last_exec) > 0) {
326 326
 	$max = $globalMinFetch;
327 327
 	foreach ($last_exec as $last) {
328
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
328
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
329 329
 	}
330 330
 	if ($max != $globalMinFetch) {
331
-	    if ($globalDebug) echo 'Sleeping...'."\n";
332
-	    sleep($globalMinFetch-$max+2);
331
+		if ($globalDebug) echo 'Sleeping...'."\n";
332
+		sleep($globalMinFetch-$max+2);
333
+	}
333 334
 	}
334
-    }
335 335
 
336 336
     
337
-    //foreach ($formats as $id => $value) {
338
-    foreach ($globalSources as $id => $value) {
337
+	//foreach ($formats as $id => $value) {
338
+	foreach ($globalSources as $id => $value) {
339 339
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
340 340
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
341
-	    //$buffer = $Common->getData($hosts[$id]);
342
-	    $buffer = $Common->getData($value['host']);
343
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
344
-	    $buffer = explode('\n',$buffer);
345
-	    foreach ($buffer as $line) {
346
-    		if ($line != '' && count($line) > 7) {
347
-    		    $line = explode(',', $line);
348
-	            $data = array();
349
-	            $data['hex'] = $line[1]; // hex
350
-	            $data['ident'] = $line[2]; // ident
351
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
352
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
353
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
354
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
355
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
356
-	            $data['verticalrate'] = ''; // vertical rate
357
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
358
-	            $data['emergency'] = ''; // emergency
359
-		    $data['datetime'] = date('Y-m-d H:i:s');
360
-		    $data['format_source'] = 'deltadbtxt';
361
-    		    $data['id_source'] = $id_source;
362
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
363
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
364
-    		    $SI->add($data);
365
-		    unset($data);
366
-    		}
367
-    	    }
368
-    	    $last_exec[$id]['last'] = time();
341
+		//$buffer = $Common->getData($hosts[$id]);
342
+		$buffer = $Common->getData($value['host']);
343
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
344
+		$buffer = explode('\n',$buffer);
345
+		foreach ($buffer as $line) {
346
+			if ($line != '' && count($line) > 7) {
347
+				$line = explode(',', $line);
348
+				$data = array();
349
+				$data['hex'] = $line[1]; // hex
350
+				$data['ident'] = $line[2]; // ident
351
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
352
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
353
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
354
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
355
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
356
+				$data['verticalrate'] = ''; // vertical rate
357
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
358
+				$data['emergency'] = ''; // emergency
359
+			$data['datetime'] = date('Y-m-d H:i:s');
360
+			$data['format_source'] = 'deltadbtxt';
361
+				$data['id_source'] = $id_source;
362
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
363
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
364
+				$SI->add($data);
365
+			unset($data);
366
+			}
367
+			}
368
+			$last_exec[$id]['last'] = time();
369 369
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
370 370
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
371
-	    //$buffer = $Common->getData($hosts[$id]);
372
-	    $buffer = $Common->getData($value['host']);
373
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
-	    $buffer = explode('\n',$buffer);
375
-	    foreach ($buffer as $line) {
376
-    		if ($line != '') {
377
-    		    $line = explode(':', $line);
378
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
371
+		//$buffer = $Common->getData($hosts[$id]);
372
+		$buffer = $Common->getData($value['host']);
373
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374
+		$buffer = explode('\n',$buffer);
375
+		foreach ($buffer as $line) {
376
+			if ($line != '') {
377
+				$line = explode(':', $line);
378
+				if (count($line) > 30 && $line[0] != 'callsign') {
379 379
 			$data = array();
380 380
 			$data['id'] = $line[1].'-'.$line[0];
381 381
 			$data['pilot_id'] = $line[1];
@@ -387,36 +387,36 @@  discard block
 block discarded – undo
387 387
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
388 388
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
389 389
 			$data['latitude'] = $line[5]; // lat
390
-	        	$data['longitude'] = $line[6]; // long
391
-	        	$data['verticalrate'] = ''; // vertical rate
392
-	        	$data['squawk'] = ''; // squawk
393
-	        	$data['emergency'] = ''; // emergency
394
-	        	$data['waypoints'] = $line[30];
390
+				$data['longitude'] = $line[6]; // long
391
+				$data['verticalrate'] = ''; // vertical rate
392
+				$data['squawk'] = ''; // squawk
393
+				$data['emergency'] = ''; // emergency
394
+				$data['waypoints'] = $line[30];
395 395
 			$data['datetime'] = date('Y-m-d H:i:s');
396 396
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
397 397
 			if (isset($line[37])) $data['last_update'] = $line[37];
398
-		        $data['departure_airport_icao'] = $line[11];
399
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
400
-		        $data['arrival_airport_icao'] = $line[13];
398
+				$data['departure_airport_icao'] = $line[11];
399
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
400
+				$data['arrival_airport_icao'] = $line[13];
401 401
 			$data['frequency'] = $line[4];
402 402
 			$data['type'] = $line[18];
403 403
 			$data['range'] = $line[19];
404 404
 			if (isset($line[35])) $data['info'] = $line[35];
405
-    			$data['id_source'] = $id_source;
406
-	    		//$data['arrival_airport_time'] = ;
407
-	    		if ($line[9] != '') {
408
-	    		    $aircraft_data = explode('/',$line[9]);
409
-	    		    if (isset($aircraft_data[1])) {
410
-	    			$data['aircraft_icao'] = $aircraft_data[1];
411
-	    		    }
412
-        		}
413
-	    		/*
405
+				$data['id_source'] = $id_source;
406
+				//$data['arrival_airport_time'] = ;
407
+				if ($line[9] != '') {
408
+					$aircraft_data = explode('/',$line[9]);
409
+					if (isset($aircraft_data[1])) {
410
+					$data['aircraft_icao'] = $aircraft_data[1];
411
+					}
412
+				}
413
+				/*
414 414
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
415 415
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
416 416
 	    		*/
417
-	    		$data['format_source'] = $value['format'];
417
+				$data['format_source'] = $value['format'];
418 418
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
419
-    			if ($line[3] == 'PILOT') $SI->add($data);
419
+				if ($line[3] == 'PILOT') $SI->add($data);
420 420
 			elseif ($line[3] == 'ATC') {
421 421
 				//print_r($data);
422 422
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -434,240 +434,240 @@  discard block
 block discarded – undo
434 434
 				if (!isset($data['source_name'])) $data['source_name'] = '';
435 435
 				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']);
436 436
 			}
437
-    			unset($data);
438
-    		    }
439
-    		}
440
-    	    }
441
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
442
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
443
-    	    $last_exec[$id]['last'] = time();
444
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
445
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
446
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
447
-	    if ($buffer != '') {
448
-	    $all_data = json_decode($buffer,true);
449
-	    if (isset($all_data['acList'])) {
437
+				unset($data);
438
+				}
439
+			}
440
+			}
441
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
442
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
443
+			$last_exec[$id]['last'] = time();
444
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
445
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
446
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
447
+		if ($buffer != '') {
448
+		$all_data = json_decode($buffer,true);
449
+		if (isset($all_data['acList'])) {
450 450
 		foreach ($all_data['acList'] as $line) {
451
-		    $data = array();
452
-		    $data['hex'] = $line['Icao']; // hex
453
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
454
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
455
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
456
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
457
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
458
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
459
-		    //$data['verticalrate'] = $line['']; // verticale rate
460
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
461
-		    $data['emergency'] = ''; // emergency
462
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
463
-		    /*
451
+			$data = array();
452
+			$data['hex'] = $line['Icao']; // hex
453
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
454
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
455
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
456
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
457
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
458
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
459
+			//$data['verticalrate'] = $line['']; // verticale rate
460
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
461
+			$data['emergency'] = ''; // emergency
462
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
463
+			/*
464 464
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
465 465
 		    else $data['datetime'] = date('Y-m-d H:i:s');
466 466
 		    */
467
-		    $data['datetime'] = date('Y-m-d H:i:s');
468
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
469
-	    	    $data['format_source'] = 'aircraftlistjson';
470
-		    $data['id_source'] = $id_source;
471
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
472
-		    if (isset($data['datetime'])) $SI->add($data);
473
-		    unset($data);
467
+			$data['datetime'] = date('Y-m-d H:i:s');
468
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
469
+				$data['format_source'] = 'aircraftlistjson';
470
+			$data['id_source'] = $id_source;
471
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
472
+			if (isset($data['datetime'])) $SI->add($data);
473
+			unset($data);
474 474
 		}
475
-	    } else {
475
+		} else {
476 476
 		foreach ($all_data as $line) {
477
-		    $data = array();
478
-		    $data['hex'] = $line['hex']; // hex
479
-		    $data['ident'] = $line['flight']; // ident
480
-		    $data['altitude'] = $line['altitude']; // altitude
481
-		    $data['speed'] = $line['speed']; // speed
482
-		    $data['heading'] = $line['track']; // heading
483
-		    $data['latitude'] = $line['lat']; // lat
484
-		    $data['longitude'] = $line['lon']; // long
485
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
486
-		    $data['squawk'] = $line['squawk']; // squawk
487
-		    $data['emergency'] = ''; // emergency
488
-		    $data['datetime'] = date('Y-m-d H:i:s');
489
-	    	    $data['format_source'] = 'aircraftlistjson';
490
-    		    $data['id_source'] = $id_source;
491
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
492
-		    $SI->add($data);
493
-		    unset($data);
477
+			$data = array();
478
+			$data['hex'] = $line['hex']; // hex
479
+			$data['ident'] = $line['flight']; // ident
480
+			$data['altitude'] = $line['altitude']; // altitude
481
+			$data['speed'] = $line['speed']; // speed
482
+			$data['heading'] = $line['track']; // heading
483
+			$data['latitude'] = $line['lat']; // lat
484
+			$data['longitude'] = $line['lon']; // long
485
+			$data['verticalrate'] = $line['vrt']; // verticale rate
486
+			$data['squawk'] = $line['squawk']; // squawk
487
+			$data['emergency'] = ''; // emergency
488
+			$data['datetime'] = date('Y-m-d H:i:s');
489
+				$data['format_source'] = 'aircraftlistjson';
490
+				$data['id_source'] = $id_source;
491
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
492
+			$SI->add($data);
493
+			unset($data);
494
+		}
495
+		}
494 496
 		}
495
-	    }
496
-	    }
497
-    	    //$last_exec['aircraftlistjson'] = time();
498
-    	    $last_exec[$id]['last'] = time();
499
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
500
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
501
-	    $buffer = $Common->getData($value['host']);
502
-	    $all_data = json_decode($buffer,true);
503
-	    if (isset($all_data['planes'])) {
497
+			//$last_exec['aircraftlistjson'] = time();
498
+			$last_exec[$id]['last'] = time();
499
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
500
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
501
+		$buffer = $Common->getData($value['host']);
502
+		$all_data = json_decode($buffer,true);
503
+		if (isset($all_data['planes'])) {
504 504
 		foreach ($all_data['planes'] as $key => $line) {
505
-		    $data = array();
506
-		    $data['hex'] = $key; // hex
507
-		    $data['ident'] = $line[3]; // ident
508
-		    $data['altitude'] = $line[6]; // altitude
509
-		    $data['speed'] = $line[8]; // speed
510
-		    $data['heading'] = $line[7]; // heading
511
-		    $data['latitude'] = $line[4]; // lat
512
-		    $data['longitude'] = $line[5]; // long
513
-		    //$data['verticalrate'] = $line[]; // verticale rate
514
-		    $data['squawk'] = $line[10]; // squawk
515
-		    $data['emergency'] = ''; // emergency
516
-		    $data['registration'] = $line[2];
517
-		    $data['aircraft_icao'] = $line[0];
518
-		    $deparr = explode('-',$line[1]);
519
-		    if (count($deparr) == 2) {
505
+			$data = array();
506
+			$data['hex'] = $key; // hex
507
+			$data['ident'] = $line[3]; // ident
508
+			$data['altitude'] = $line[6]; // altitude
509
+			$data['speed'] = $line[8]; // speed
510
+			$data['heading'] = $line[7]; // heading
511
+			$data['latitude'] = $line[4]; // lat
512
+			$data['longitude'] = $line[5]; // long
513
+			//$data['verticalrate'] = $line[]; // verticale rate
514
+			$data['squawk'] = $line[10]; // squawk
515
+			$data['emergency'] = ''; // emergency
516
+			$data['registration'] = $line[2];
517
+			$data['aircraft_icao'] = $line[0];
518
+			$deparr = explode('-',$line[1]);
519
+			if (count($deparr) == 2) {
520 520
 			$data['departure_airport_icao'] = $deparr[0];
521 521
 			$data['arrival_airport_icao'] = $deparr[1];
522
-		    }
523
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
524
-	    	    $data['format_source'] = 'planeupdatefaa';
525
-    		    $data['id_source'] = $id_source;
526
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
527
-		    $SI->add($data);
528
-		    unset($data);
522
+			}
523
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
524
+				$data['format_source'] = 'planeupdatefaa';
525
+				$data['id_source'] = $id_source;
526
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
527
+			$SI->add($data);
528
+			unset($data);
529 529
 		}
530
-	    }
531
-    	    //$last_exec['planeupdatefaa'] = time();
532
-    	    $last_exec[$id]['last'] = time();
533
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
534
-	    $buffer = $Common->getData($value['host']);
535
-	    $all_data = json_decode($buffer,true);
536
-	    if (isset($all_data['states'])) {
530
+		}
531
+			//$last_exec['planeupdatefaa'] = time();
532
+			$last_exec[$id]['last'] = time();
533
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
534
+		$buffer = $Common->getData($value['host']);
535
+		$all_data = json_decode($buffer,true);
536
+		if (isset($all_data['states'])) {
537 537
 		foreach ($all_data['states'] as $key => $line) {
538
-		    $data = array();
539
-		    $data['hex'] = $line[0]; // hex
540
-		    $data['ident'] = trim($line[1]); // ident
541
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
542
-		    $data['speed'] = round($line[9]*1.94384); // speed
543
-		    $data['heading'] = round($line[10]); // heading
544
-		    $data['latitude'] = $line[5]; // lat
545
-		    $data['longitude'] = $line[6]; // long
546
-		    $data['verticalrate'] = $line[11]; // verticale rate
547
-		    //$data['squawk'] = $line[10]; // squawk
548
-		    //$data['emergency'] = ''; // emergency
549
-		    //$data['registration'] = $line[2];
550
-		    //$data['aircraft_icao'] = $line[0];
551
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
552
-	    	    $data['format_source'] = 'opensky';
553
-    		    $data['id_source'] = $id_source;
554
-		    $SI->add($data);
555
-		    unset($data);
538
+			$data = array();
539
+			$data['hex'] = $line[0]; // hex
540
+			$data['ident'] = trim($line[1]); // ident
541
+			$data['altitude'] = round($line[7]*3.28084); // altitude
542
+			$data['speed'] = round($line[9]*1.94384); // speed
543
+			$data['heading'] = round($line[10]); // heading
544
+			$data['latitude'] = $line[5]; // lat
545
+			$data['longitude'] = $line[6]; // long
546
+			$data['verticalrate'] = $line[11]; // verticale rate
547
+			//$data['squawk'] = $line[10]; // squawk
548
+			//$data['emergency'] = ''; // emergency
549
+			//$data['registration'] = $line[2];
550
+			//$data['aircraft_icao'] = $line[0];
551
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
552
+				$data['format_source'] = 'opensky';
553
+				$data['id_source'] = $id_source;
554
+			$SI->add($data);
555
+			unset($data);
556 556
 		}
557
-	    }
558
-    	    //$last_exec['planeupdatefaa'] = time();
559
-    	    $last_exec[$id]['last'] = time();
560
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
561
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
562
-	    //$buffer = $Common->getData($hosts[$id]);
563
-	    $buffer = $Common->getData($value['host']);
564
-	    $all_data = json_decode($buffer,true);
565
-	    foreach ($all_data as $key => $line) {
557
+		}
558
+			//$last_exec['planeupdatefaa'] = time();
559
+			$last_exec[$id]['last'] = time();
560
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
561
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
562
+		//$buffer = $Common->getData($hosts[$id]);
563
+		$buffer = $Common->getData($value['host']);
564
+		$all_data = json_decode($buffer,true);
565
+		foreach ($all_data as $key => $line) {
566 566
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
567
-		    $data = array();
568
-		    $data['hex'] = $line[0];
569
-		    $data['ident'] = $line[16]; //$line[13]
570
-	    	    $data['altitude'] = $line[4]; // altitude
571
-	    	    $data['speed'] = $line[5]; // speed
572
-	    	    $data['heading'] = $line[3]; // heading
573
-	    	    $data['latitude'] = $line[1]; // lat
574
-	    	    $data['longitude'] = $line[2]; // long
575
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
576
-	    	    $data['squawk'] = $line[6]; // squawk
577
-	    	    $data['aircraft_icao'] = $line[8];
578
-	    	    $data['registration'] = $line[9];
579
-		    $data['departure_airport_iata'] = $line[11];
580
-		    $data['arrival_airport_iata'] = $line[12];
581
-	    	    $data['emergency'] = ''; // emergency
582
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
583
-	    	    $data['format_source'] = 'fr24json';
584
-    		    $data['id_source'] = $id_source;
585
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
586
-		    $SI->add($data);
587
-		    unset($data);
567
+			$data = array();
568
+			$data['hex'] = $line[0];
569
+			$data['ident'] = $line[16]; //$line[13]
570
+				$data['altitude'] = $line[4]; // altitude
571
+				$data['speed'] = $line[5]; // speed
572
+				$data['heading'] = $line[3]; // heading
573
+				$data['latitude'] = $line[1]; // lat
574
+				$data['longitude'] = $line[2]; // long
575
+				$data['verticalrate'] = $line[15]; // verticale rate
576
+				$data['squawk'] = $line[6]; // squawk
577
+				$data['aircraft_icao'] = $line[8];
578
+				$data['registration'] = $line[9];
579
+			$data['departure_airport_iata'] = $line[11];
580
+			$data['arrival_airport_iata'] = $line[12];
581
+				$data['emergency'] = ''; // emergency
582
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
583
+				$data['format_source'] = 'fr24json';
584
+				$data['id_source'] = $id_source;
585
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
586
+			$SI->add($data);
587
+			unset($data);
588 588
 		}
589
-	    }
590
-    	    //$last_exec['fr24json'] = time();
591
-    	    $last_exec[$id]['last'] = time();
592
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
593
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
594
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
595
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
596
-	    //echo $buffer;
597
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
598
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
599
-	    $all_data = json_decode($buffer,true);
600
-	    if (json_last_error() != JSON_ERROR_NONE) {
589
+		}
590
+			//$last_exec['fr24json'] = time();
591
+			$last_exec[$id]['last'] = time();
592
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
593
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
594
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
595
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
596
+		//echo $buffer;
597
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
598
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
599
+		$all_data = json_decode($buffer,true);
600
+		if (json_last_error() != JSON_ERROR_NONE) {
601 601
 		die(json_last_error_msg());
602
-	    }
603
-	    if (isset($all_data['mrkrs'])) {
602
+		}
603
+		if (isset($all_data['mrkrs'])) {
604 604
 		foreach ($all_data['mrkrs'] as $key => $line) {
605
-		    if (isset($line['inf'])) {
605
+			if (isset($line['inf'])) {
606 606
 			$data = array();
607 607
 			$data['hex'] = $line['inf']['ia'];
608 608
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
609
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
610
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
611
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
612
-	    		$data['latitude'] = $line['pt'][0]; // lat
613
-	    		$data['longitude'] = $line['pt'][1]; // long
614
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
615
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
616
-	    		//$data['aircraft_icao'] = $line[8];
617
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
609
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
610
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
611
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
612
+				$data['latitude'] = $line['pt'][0]; // lat
613
+				$data['longitude'] = $line['pt'][1]; // long
614
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
615
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
616
+				//$data['aircraft_icao'] = $line[8];
617
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
618 618
 			//$data['departure_airport_iata'] = $line[11];
619 619
 			//$data['arrival_airport_iata'] = $line[12];
620
-	    		//$data['emergency'] = ''; // emergency
620
+				//$data['emergency'] = ''; // emergency
621 621
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
622
-	    		$data['format_source'] = 'radarvirtueljson';
623
-    			$data['id_source'] = $id_source;
622
+				$data['format_source'] = 'radarvirtueljson';
623
+				$data['id_source'] = $id_source;
624 624
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
625 625
 			$SI->add($data);
626 626
 			unset($data);
627
-		    }
627
+			}
628 628
 		}
629
-	    }
630
-    	    //$last_exec['radarvirtueljson'] = time();
631
-    	    $last_exec[$id]['last'] = time();
632
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
633
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
634
-	    //$buffer = $Common->getData($hosts[$id]);
635
-	    $buffer = $Common->getData($value['host'].'?'.time());
636
-	    $all_data = json_decode(utf8_encode($buffer),true);
629
+		}
630
+			//$last_exec['radarvirtueljson'] = time();
631
+			$last_exec[$id]['last'] = time();
632
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
633
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
634
+		//$buffer = $Common->getData($hosts[$id]);
635
+		$buffer = $Common->getData($value['host'].'?'.time());
636
+		$all_data = json_decode(utf8_encode($buffer),true);
637 637
 	    
638
-	    if (isset($all_data['pireps'])) {
639
-	        foreach ($all_data['pireps'] as $line) {
640
-		    $data = array();
641
-		    $data['id'] = $line['id'];
642
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
643
-		    $data['ident'] = $line['callsign']; // ident
644
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
645
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
646
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
647
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
648
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
649
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
650
-		    $data['latitude'] = $line['lat']; // lat
651
-		    $data['longitude'] = $line['lon']; // long
652
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
653
-		    //$data['squawk'] = $line['squawk']; // squawk
654
-		    //$data['emergency'] = ''; // emergency
655
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
656
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
657
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
658
-		    //$data['arrival_airport_time'] = $line['arrtime'];
659
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
660
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
661
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
662
-		    else $data['info'] = '';
663
-		    $data['format_source'] = 'pireps';
664
-    		    $data['id_source'] = $id_source;
665
-		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
667
-		    if ($line['icon'] == 'plane') {
638
+		if (isset($all_data['pireps'])) {
639
+			foreach ($all_data['pireps'] as $line) {
640
+			$data = array();
641
+			$data['id'] = $line['id'];
642
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
643
+			$data['ident'] = $line['callsign']; // ident
644
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
645
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
646
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
647
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
648
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
649
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
650
+			$data['latitude'] = $line['lat']; // lat
651
+			$data['longitude'] = $line['lon']; // long
652
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
653
+			//$data['squawk'] = $line['squawk']; // squawk
654
+			//$data['emergency'] = ''; // emergency
655
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
656
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
657
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
658
+			//$data['arrival_airport_time'] = $line['arrtime'];
659
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
660
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
661
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
662
+			else $data['info'] = '';
663
+			$data['format_source'] = 'pireps';
664
+				$data['id_source'] = $id_source;
665
+			$data['datetime'] = date('Y-m-d H:i:s');
666
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
667
+			if ($line['icon'] == 'plane') {
668 668
 			$SI->add($data);
669
-		    //    print_r($data);
670
-    		    } elseif ($line['icon'] == 'ct') {
669
+			//    print_r($data);
670
+				} elseif ($line['icon'] == 'ct') {
671 671
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
672 672
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
673 673
 			$typec = substr($data['ident'],-3);
@@ -682,160 +682,160 @@  discard block
 block discarded – undo
682 682
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
683 683
 			else $data['type'] = 'Observer';
684 684
 			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']);
685
-		    }
686
-		    unset($data);
685
+			}
686
+			unset($data);
687 687
 		}
688
-	    }
689
-    	    //$last_exec['pirepsjson'] = time();
690
-    	    $last_exec[$id]['last'] = time();
691
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
692
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
693
-	    //$buffer = $Common->getData($hosts[$id]);
694
-	    if ($globalDebug) echo 'Get Data...'."\n";
695
-	    $buffer = $Common->getData($value['host']);
696
-	    $all_data = json_decode($buffer,true);
697
-	    if ($buffer != '' && is_array($all_data)) {
688
+		}
689
+			//$last_exec['pirepsjson'] = time();
690
+			$last_exec[$id]['last'] = time();
691
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
692
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
693
+		//$buffer = $Common->getData($hosts[$id]);
694
+		if ($globalDebug) echo 'Get Data...'."\n";
695
+		$buffer = $Common->getData($value['host']);
696
+		$all_data = json_decode($buffer,true);
697
+		if ($buffer != '' && is_array($all_data)) {
698 698
 		foreach ($all_data as $line) {
699
-	    	    $data = array();
700
-	    	    //$data['id'] = $line['id']; // id not usable
701
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
702
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
703
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
704
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
705
-	    	    $data['ident'] = $line['flightnum']; // ident
706
-	    	    $data['altitude'] = $line['alt']; // altitude
707
-	    	    $data['speed'] = $line['gs']; // speed
708
-	    	    $data['heading'] = $line['heading']; // heading
709
-	    	    $data['latitude'] = $line['lat']; // lat
710
-	    	    $data['longitude'] = $line['lng']; // long
711
-	    	    $data['verticalrate'] = ''; // verticale rate
712
-	    	    $data['squawk'] = ''; // squawk
713
-	    	    $data['emergency'] = ''; // emergency
714
-	    	    //$data['datetime'] = $line['lastupdate'];
715
-	    	    $data['last_update'] = $line['lastupdate'];
716
-		    $data['datetime'] = date('Y-m-d H:i:s');
717
-	    	    $data['departure_airport_icao'] = $line['depicao'];
718
-	    	    $data['departure_airport_time'] = $line['deptime'];
719
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
720
-    		    $data['arrival_airport_time'] = $line['arrtime'];
721
-    		    $data['registration'] = $line['aircraft'];
722
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
723
-		    if (isset($line['aircraftname'])) {
699
+				$data = array();
700
+				//$data['id'] = $line['id']; // id not usable
701
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
702
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
703
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
704
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
705
+				$data['ident'] = $line['flightnum']; // ident
706
+				$data['altitude'] = $line['alt']; // altitude
707
+				$data['speed'] = $line['gs']; // speed
708
+				$data['heading'] = $line['heading']; // heading
709
+				$data['latitude'] = $line['lat']; // lat
710
+				$data['longitude'] = $line['lng']; // long
711
+				$data['verticalrate'] = ''; // verticale rate
712
+				$data['squawk'] = ''; // squawk
713
+				$data['emergency'] = ''; // emergency
714
+				//$data['datetime'] = $line['lastupdate'];
715
+				$data['last_update'] = $line['lastupdate'];
716
+			$data['datetime'] = date('Y-m-d H:i:s');
717
+				$data['departure_airport_icao'] = $line['depicao'];
718
+				$data['departure_airport_time'] = $line['deptime'];
719
+				$data['arrival_airport_icao'] = $line['arricao'];
720
+				$data['arrival_airport_time'] = $line['arrtime'];
721
+				$data['registration'] = $line['aircraft'];
722
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
723
+			if (isset($line['aircraftname'])) {
724 724
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
725 725
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
726
-	    		$aircraft_data = explode('-',$line['aircraftname']);
727
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
728
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
729
-	    		else {
730
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
731
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
732
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
733
-	    		}
734
-	    	    }
735
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
736
-    		    $data['id_source'] = $id_source;
737
-	    	    $data['format_source'] = 'phpvmacars';
738
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
739
-		    $SI->add($data);
740
-		    unset($data);
726
+				$aircraft_data = explode('-',$line['aircraftname']);
727
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
728
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
729
+				else {
730
+					$aircraft_data = explode(' ',$line['aircraftname']);
731
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
732
+					else $data['aircraft_icao'] = $line['aircraftname'];
733
+				}
734
+				}
735
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
736
+				$data['id_source'] = $id_source;
737
+				$data['format_source'] = 'phpvmacars';
738
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
739
+			$SI->add($data);
740
+			unset($data);
741 741
 		}
742 742
 		if ($globalDebug) echo 'No more data...'."\n";
743 743
 		unset($buffer);
744 744
 		unset($all_data);
745
-	    }
746
-    	    //$last_exec['phpvmacars'] = time();
747
-    	    $last_exec[$id]['last'] = time();
748
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
749
-	    //$buffer = $Common->getData($hosts[$id]);
750
-	    if ($globalDebug) echo 'Get Data...'."\n";
751
-	    $buffer = $Common->getData($value['host']);
752
-	    $all_data = json_decode($buffer,true);
753
-	    if ($buffer != '' && is_array($all_data)) {
745
+		}
746
+			//$last_exec['phpvmacars'] = time();
747
+			$last_exec[$id]['last'] = time();
748
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
749
+		//$buffer = $Common->getData($hosts[$id]);
750
+		if ($globalDebug) echo 'Get Data...'."\n";
751
+		$buffer = $Common->getData($value['host']);
752
+		$all_data = json_decode($buffer,true);
753
+		if ($buffer != '' && is_array($all_data)) {
754 754
 		foreach ($all_data as $line) {
755
-	    	    $data = array();
756
-	    	    //$data['id'] = $line['id']; // id not usable
757
-	    	    $data['id'] = trim($line['flight_id']);
758
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
759
-	    	    $data['pilot_name'] = $line['pilot_name'];
760
-	    	    $data['pilot_id'] = $line['pilot_id'];
761
-	    	    $data['ident'] = trim($line['callsign']); // ident
762
-	    	    $data['altitude'] = $line['altitude']; // altitude
763
-	    	    $data['speed'] = $line['gs']; // speed
764
-	    	    $data['heading'] = $line['heading']; // heading
765
-	    	    $data['latitude'] = $line['latitude']; // lat
766
-	    	    $data['longitude'] = $line['longitude']; // long
767
-	    	    $data['verticalrate'] = ''; // verticale rate
768
-	    	    $data['squawk'] = ''; // squawk
769
-	    	    $data['emergency'] = ''; // emergency
770
-	    	    //$data['datetime'] = $line['lastupdate'];
771
-	    	    $data['last_update'] = $line['last_update'];
772
-		    $data['datetime'] = date('Y-m-d H:i:s');
773
-	    	    $data['departure_airport_icao'] = $line['departure'];
774
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
775
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
776
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
777
-    		    //$data['registration'] = $line['aircraft'];
778
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
779
-	    	    $data['aircraft_icao'] = $line['plane_type'];
780
-    		    $data['id_source'] = $id_source;
781
-	    	    $data['format_source'] = 'vam';
782
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
783
-		    $SI->add($data);
784
-		    unset($data);
755
+				$data = array();
756
+				//$data['id'] = $line['id']; // id not usable
757
+				$data['id'] = trim($line['flight_id']);
758
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
759
+				$data['pilot_name'] = $line['pilot_name'];
760
+				$data['pilot_id'] = $line['pilot_id'];
761
+				$data['ident'] = trim($line['callsign']); // ident
762
+				$data['altitude'] = $line['altitude']; // altitude
763
+				$data['speed'] = $line['gs']; // speed
764
+				$data['heading'] = $line['heading']; // heading
765
+				$data['latitude'] = $line['latitude']; // lat
766
+				$data['longitude'] = $line['longitude']; // long
767
+				$data['verticalrate'] = ''; // verticale rate
768
+				$data['squawk'] = ''; // squawk
769
+				$data['emergency'] = ''; // emergency
770
+				//$data['datetime'] = $line['lastupdate'];
771
+				$data['last_update'] = $line['last_update'];
772
+			$data['datetime'] = date('Y-m-d H:i:s');
773
+				$data['departure_airport_icao'] = $line['departure'];
774
+				//$data['departure_airport_time'] = $line['departure_time'];
775
+				$data['arrival_airport_icao'] = $line['arrival'];
776
+				//$data['arrival_airport_time'] = $line['arrival_time'];
777
+				//$data['registration'] = $line['aircraft'];
778
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
779
+				$data['aircraft_icao'] = $line['plane_type'];
780
+				$data['id_source'] = $id_source;
781
+				$data['format_source'] = 'vam';
782
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
783
+			$SI->add($data);
784
+			unset($data);
785 785
 		}
786 786
 		if ($globalDebug) echo 'No more data...'."\n";
787 787
 		unset($buffer);
788 788
 		unset($all_data);
789
-	    }
790
-    	    //$last_exec['phpvmacars'] = time();
791
-    	    $last_exec[$id]['last'] = time();
789
+		}
790
+			//$last_exec['phpvmacars'] = time();
791
+			$last_exec[$id]['last'] = time();
792 792
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
793 793
 	} 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') {
794
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
795
-    	    //$last_exec[$id]['last'] = time();
794
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
795
+			//$last_exec[$id]['last'] = time();
796 796
 
797
-	    //$read = array( $sockets[$id] );
798
-	    $read = $sockets;
799
-	    $write = NULL;
800
-	    $e = NULL;
801
-	    $n = socket_select($read, $write, $e, $timeout);
802
-	    if ($e != NULL) var_dump($e);
803
-	    if ($n > 0) {
797
+		//$read = array( $sockets[$id] );
798
+		$read = $sockets;
799
+		$write = NULL;
800
+		$e = NULL;
801
+		$n = socket_select($read, $write, $e, $timeout);
802
+		if ($e != NULL) var_dump($e);
803
+		if ($n > 0) {
804 804
 		foreach ($read as $nb => $r) {
805
-		    //$value = $formats[$nb];
806
-		    $format = $globalSources[$nb]['format'];
807
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
808
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
809
-        	    } else {
810
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
811
-	    	    }
812
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
813
-        	    //echo $buffer."\n";
814
-		    // lets play nice and handle signals such as ctrl-c/kill properly
815
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
816
-		    $error = false;
817
-		    //$SI::del();
818
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
819
-		    // SBS format is CSV format
820
-		    if ($buffer != '') {
805
+			//$value = $formats[$nb];
806
+			$format = $globalSources[$nb]['format'];
807
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
808
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
809
+				} else {
810
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
811
+				}
812
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
813
+				//echo $buffer."\n";
814
+			// lets play nice and handle signals such as ctrl-c/kill properly
815
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
816
+			$error = false;
817
+			//$SI::del();
818
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
819
+			// SBS format is CSV format
820
+			if ($buffer != '') {
821 821
 			$tt[$format] = 0;
822 822
 			if ($format == 'acarssbs3') {
823
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
824
-			    $ACARS->add(trim($buffer));
825
-			    $ACARS->deleteLiveAcarsData();
823
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
824
+				$ACARS->add(trim($buffer));
825
+				$ACARS->deleteLiveAcarsData();
826 826
 			} elseif ($format == 'raw') {
827
-			    // AVR format
828
-			    $data = $SBS->parse($buffer);
829
-			    if (is_array($data)) {
827
+				// AVR format
828
+				$data = $SBS->parse($buffer);
829
+				if (is_array($data)) {
830 830
 				$data['datetime'] = date('Y-m-d H:i:s');
831 831
 				$data['format_source'] = 'raw';
832 832
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
833
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
834
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
835
-                            }
836
-                        } elseif ($format == 'flightgearsp') {
837
-                    	    //echo $buffer."\n";
838
-                    	    if (strlen($buffer) > 5) {
833
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
834
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
835
+							}
836
+						} elseif ($format == 'flightgearsp') {
837
+							//echo $buffer."\n";
838
+							if (strlen($buffer) > 5) {
839 839
 				$line = explode(',',$buffer);
840 840
 				$data = array();
841 841
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -851,114 +851,114 @@  discard block
 block discarded – undo
851 851
 				$data['format_source'] = 'flightgearsp';
852 852
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
853 853
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
854
-			    }
855
-                        } elseif ($format == 'acars') {
856
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
857
-			    $ACARS->add(trim($buffer));
858
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
859
-			    $ACARS->deleteLiveAcarsData();
854
+				}
855
+						} elseif ($format == 'acars') {
856
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
857
+				$ACARS->add(trim($buffer));
858
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
859
+				$ACARS->deleteLiveAcarsData();
860 860
 			} elseif ($format == 'flightgearmp') {
861
-			    if (substr($buffer,0,1) != '#') {
861
+				if (substr($buffer,0,1) != '#') {
862 862
 				$data = array();
863 863
 				//echo $buffer."\n";
864 864
 				$line = explode(' ',$buffer);
865 865
 				if (count($line) == 11) {
866
-				    $userserver = explode('@',$line[0]);
867
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
868
-				    $data['ident'] = $userserver[0];
869
-				    $data['registration'] = $userserver[0];
870
-				    $data['latitude'] = $line[4];
871
-				    $data['longitude'] = $line[5];
872
-				    $data['altitude'] = $line[6];
873
-				    $data['datetime'] = date('Y-m-d H:i:s');
874
-				    $aircraft_type = $line[10];
875
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
876
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
877
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
866
+					$userserver = explode('@',$line[0]);
867
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
868
+					$data['ident'] = $userserver[0];
869
+					$data['registration'] = $userserver[0];
870
+					$data['latitude'] = $line[4];
871
+					$data['longitude'] = $line[5];
872
+					$data['altitude'] = $line[6];
873
+					$data['datetime'] = date('Y-m-d H:i:s');
874
+					$aircraft_type = $line[10];
875
+					$aircraft_type = preg_split(':/:',$aircraft_type);
876
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
877
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
878
+				}
878 879
 				}
879
-			    }
880 880
 			} elseif ($format == 'beast') {
881
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
882
-			    die;
881
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
882
+				die;
883 883
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
884
-			    $line = explode("\t", $buffer);
885
-			    for($k = 0; $k < count($line); $k=$k+2) {
884
+				$line = explode("\t", $buffer);
885
+				for($k = 0; $k < count($line); $k=$k+2) {
886 886
 				$key = $line[$k];
887
-			        $lined[$key] = $line[$k+1];
888
-			    }
889
-    			    if (count($lined) > 3) {
890
-    				$data['hex'] = $lined['hexid'];
891
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
892
-    				$data['datetime'] = date('Y-m-d H:i:s');;
893
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
894
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
895
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
896
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
897
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
898
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
899
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
900
-    				$data['id_source'] = $id_source;
901
-    				$data['format_source'] = 'tsv';
902
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
903
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
904
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
905
-    				unset($lined);
906
-    				unset($data);
907
-    			    } else $error = true;
887
+					$lined[$key] = $line[$k+1];
888
+				}
889
+					if (count($lined) > 3) {
890
+					$data['hex'] = $lined['hexid'];
891
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
892
+					$data['datetime'] = date('Y-m-d H:i:s');;
893
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
894
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
895
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
896
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
897
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
898
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
899
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
900
+					$data['id_source'] = $id_source;
901
+					$data['format_source'] = 'tsv';
902
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
903
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
904
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
905
+					unset($lined);
906
+					unset($data);
907
+					} else $error = true;
908 908
 			} elseif ($format == 'aprs' && $use_aprs) {
909
-			    if ($aprs_connect == 0) {
909
+				if ($aprs_connect == 0) {
910 910
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
911 911
 				$aprs_connect = 1;
912
-			    }
913
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
912
+				}
913
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
914 914
 				$aprs_last_tx = time();
915 915
 				$data_aprs = "# Keep alive";
916 916
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
917
-			    }
918
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
919
-			    $buffer = str_replace('APRS <- ','',$buffer);
920
-			    $buffer = str_replace('APRS -> ','',$buffer);
921
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
917
+				}
918
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
919
+				$buffer = str_replace('APRS <- ','',$buffer);
920
+				$buffer = str_replace('APRS -> ','',$buffer);
921
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
922 922
 				$line = $APRS->parse($buffer);
923 923
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
924
-				    $data = array();
925
-				    //print_r($line);
926
-				    $data['hex'] = $line['address'];
927
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
928
-				    //$data['datetime'] = date('Y-m-d H:i:s');
929
-				    $data['ident'] = $line['ident'];
930
-				    $data['latitude'] = $line['latitude'];
931
-				    $data['longitude'] = $line['longitude'];
932
-				    //$data['verticalrate'] = $line[16];
933
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
934
-				    else $data['speed'] = 0;
935
-				    $data['altitude'] = $line['altitude'];
936
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
937
-				    //else $data['heading'] = 0;
938
-				    $data['aircraft_type'] = $line['stealth'];
939
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
940
-    				    $data['id_source'] = $id_source;
941
-				    $data['format_source'] = 'aprs';
942
-				    $data['source_name'] = $line['source'];
943
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
944
-				    $currentdate = date('Y-m-d H:i:s');
945
-				    $aprsdate = strtotime($data['datetime']);
946
-				    // Accept data if time <= system time + 20s
947
-				    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);
948
-				    else {
924
+					$data = array();
925
+					//print_r($line);
926
+					$data['hex'] = $line['address'];
927
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
928
+					//$data['datetime'] = date('Y-m-d H:i:s');
929
+					$data['ident'] = $line['ident'];
930
+					$data['latitude'] = $line['latitude'];
931
+					$data['longitude'] = $line['longitude'];
932
+					//$data['verticalrate'] = $line[16];
933
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
934
+					else $data['speed'] = 0;
935
+					$data['altitude'] = $line['altitude'];
936
+					if (isset($line['course'])) $data['heading'] = $line['course'];
937
+					//else $data['heading'] = 0;
938
+					$data['aircraft_type'] = $line['stealth'];
939
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
940
+						$data['id_source'] = $id_source;
941
+					$data['format_source'] = 'aprs';
942
+					$data['source_name'] = $line['source'];
943
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
944
+					$currentdate = date('Y-m-d H:i:s');
945
+					$aprsdate = strtotime($data['datetime']);
946
+					// Accept data if time <= system time + 20s
947
+					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);
948
+					else {
949 949
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
950 950
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
951
-				    }
952
-				    unset($data);
951
+					}
952
+					unset($data);
953 953
 				} 
954 954
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
955 955
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
956
-			    }
956
+				}
957 957
 			} else {
958
-			    $line = explode(',', $buffer);
959
-    			    if (count($line) > 20) {
960
-    			    	$data['hex'] = $line[4];
961
-    				/*
958
+				$line = explode(',', $buffer);
959
+					if (count($line) > 20) {
960
+						$data['hex'] = $line[4];
961
+					/*
962 962
     				$data['datetime'] = $line[6].' '.$line[7];
963 963
     					date_default_timezone_set($globalTimezone);
964 964
     					$datetime = new DateTime($data['datetime']);
@@ -966,28 +966,28 @@  discard block
 block discarded – undo
966 966
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
967 967
     					date_default_timezone_set('UTC');
968 968
     				*/
969
-    				// Force datetime to current UTC datetime
970
-    				$data['datetime'] = date('Y-m-d H:i:s');
971
-    				$data['ident'] = trim($line[10]);
972
-    				$data['latitude'] = $line[14];
973
-    				$data['longitude'] = $line[15];
974
-    				$data['verticalrate'] = $line[16];
975
-    				$data['emergency'] = $line[20];
976
-    				$data['speed'] = $line[12];
977
-    				$data['squawk'] = $line[17];
978
-    				$data['altitude'] = $line[11];
979
-    				$data['heading'] = $line[13];
980
-    				$data['ground'] = $line[21];
981
-    				$data['emergency'] = $line[19];
982
-    				$data['format_source'] = 'sbs';
969
+					// Force datetime to current UTC datetime
970
+					$data['datetime'] = date('Y-m-d H:i:s');
971
+					$data['ident'] = trim($line[10]);
972
+					$data['latitude'] = $line[14];
973
+					$data['longitude'] = $line[15];
974
+					$data['verticalrate'] = $line[16];
975
+					$data['emergency'] = $line[20];
976
+					$data['speed'] = $line[12];
977
+					$data['squawk'] = $line[17];
978
+					$data['altitude'] = $line[11];
979
+					$data['heading'] = $line[13];
980
+					$data['ground'] = $line[21];
981
+					$data['emergency'] = $line[19];
982
+					$data['format_source'] = 'sbs';
983 983
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
984
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
985
-    				$data['id_source'] = $id_source;
986
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
987
-    				else $error = true;
988
-    				unset($data);
989
-    			    } else $error = true;
990
-			    if ($error) {
984
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
985
+					$data['id_source'] = $id_source;
986
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
987
+					else $error = true;
988
+					unset($data);
989
+					} else $error = true;
990
+				if ($error) {
991 991
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
992 992
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
993 993
 				} else {
@@ -1003,13 +1003,13 @@  discard block
 block discarded – undo
1003 1003
 					connect_all($sourceer);
1004 1004
 					$sourceer = array();
1005 1005
 				}
1006
-			    }
1006
+				}
1007 1007
 			}
1008 1008
 			// Sleep for xxx microseconds
1009 1009
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1010
-		    } else {
1010
+			} else {
1011 1011
 			if ($format == 'flightgearmp') {
1012
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1012
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1013 1013
 				//@socket_close($r);
1014 1014
 				sleep($globalMinFetch);
1015 1015
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1018,9 +1018,9 @@  discard block
 block discarded – undo
1018 1018
 				break;
1019 1019
 				
1020 1020
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1021
-			    if (isset($tt[$format])) $tt[$format]++;
1022
-			    else $tt[$format] = 0;
1023
-			    if ($tt[$format] > 30) {
1021
+				if (isset($tt[$format])) $tt[$format]++;
1022
+				else $tt[$format] = 0;
1023
+				if ($tt[$format] > 30) {
1024 1024
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1025 1025
 				//@socket_close($r);
1026 1026
 				sleep(2);
@@ -1031,40 +1031,40 @@  discard block
 block discarded – undo
1031 1031
 				//connect_all($globalSources);
1032 1032
 				$tt[$format]=0;
1033 1033
 				break;
1034
-			    }
1034
+				}
1035
+			}
1035 1036
 			}
1036
-		    }
1037 1037
 		}
1038
-	    } else {
1038
+		} else {
1039 1039
 		$error = socket_strerror(socket_last_error());
1040 1040
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1041 1041
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1042 1042
 			if (isset($globalDebug)) echo "Restarting...\n";
1043 1043
 			// Restart the script if possible
1044 1044
 			if (is_array($sockets)) {
1045
-			    if ($globalDebug) echo "Shutdown all sockets...";
1045
+				if ($globalDebug) echo "Shutdown all sockets...";
1046 1046
 			    
1047
-			    foreach ($sockets as $sock) {
1047
+				foreach ($sockets as $sock) {
1048 1048
 				@socket_shutdown($sock,2);
1049 1049
 				@socket_close($sock);
1050
-			    }
1050
+				}
1051 1051
 			    
1052 1052
 			}
1053
-			    if ($globalDebug) echo "Restart all connections...";
1054
-			    sleep(2);
1055
-			    $time = time();
1056
-			    //connect_all($hosts);
1057
-			    $aprs_connect = 0;
1058
-			    connect_all($globalSources);
1053
+				if ($globalDebug) echo "Restart all connections...";
1054
+				sleep(2);
1055
+				$time = time();
1056
+				//connect_all($hosts);
1057
+				$aprs_connect = 0;
1058
+				connect_all($globalSources);
1059 1059
 
1060 1060
 		}
1061
-	    }
1061
+		}
1062 1062
 	}
1063 1063
 	if ($globalDaemon === false) {
1064
-	    if ($globalDebug) echo 'Check all...'."\n";
1065
-	    $SI->checkAll();
1064
+		if ($globalDebug) echo 'Check all...'."\n";
1065
+		$SI->checkAll();
1066
+	}
1066 1067
 	}
1067
-    }
1068 1068
 }
1069 1069
 
1070 1070
 ?>
Please login to merge, or discard this patch.
require/class.Stats.php 1 patch
Indentation   +825 added lines, -825 removed lines patch added patch discarded remove patch
@@ -15,79 +15,79 @@  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
-        }
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 43
 	public function getAllAirlineNames($filter_name = '') {
44 44
 		if ($filter_name == '') $filter_name = $this->filter_name;
45
-                $query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";
46
-                 try {
47
-                        $sth = $this->db->prepare($query);
48
-                        $sth->execute(array(':filter_name' => $filter_name));
49
-                } catch(PDOException $e) {
50
-                        echo "error : ".$e->getMessage();
51
-                }
52
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
53
-                return $all;
54
-        }
45
+				$query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";
46
+				 try {
47
+						$sth = $this->db->prepare($query);
48
+						$sth->execute(array(':filter_name' => $filter_name));
49
+				} catch(PDOException $e) {
50
+						echo "error : ".$e->getMessage();
51
+				}
52
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
53
+				return $all;
54
+		}
55 55
 	public function getAllAircraftTypes($stats_airline = '',$filter_name = '') {
56 56
 		if ($filter_name == '') $filter_name = $this->filter_name;
57
-                $query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";
58
-                 try {
59
-                        $sth = $this->db->prepare($query);
60
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
61
-                } catch(PDOException $e) {
62
-                        echo "error : ".$e->getMessage();
63
-                }
64
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
65
-                return $all;
66
-        }
57
+				$query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";
58
+				 try {
59
+						$sth = $this->db->prepare($query);
60
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
61
+				} catch(PDOException $e) {
62
+						echo "error : ".$e->getMessage();
63
+				}
64
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
65
+				return $all;
66
+		}
67 67
 	public function getAllManufacturers($stats_airline = '',$filter_name = '') {
68 68
 		if ($filter_name == '') $filter_name = $this->filter_name;
69
-                $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";
70
-                 try {
71
-                        $sth = $this->db->prepare($query);
72
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
73
-                } catch(PDOException $e) {
74
-                        echo "error : ".$e->getMessage();
75
-                }
76
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
77
-                return $all;
78
-        }
69
+				$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";
70
+				 try {
71
+						$sth = $this->db->prepare($query);
72
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
73
+				} catch(PDOException $e) {
74
+						echo "error : ".$e->getMessage();
75
+				}
76
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
77
+				return $all;
78
+		}
79 79
 	public function getAllAirportNames($stats_airline = '',$filter_name = '') {
80 80
 		if ($filter_name == '') $filter_name = $this->filter_name;
81
-                $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";
82
-                 try {
83
-                        $sth = $this->db->prepare($query);
84
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
85
-                } catch(PDOException $e) {
86
-                        echo "error : ".$e->getMessage();
87
-                }
88
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
89
-                return $all;
90
-        }
81
+				$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";
82
+				 try {
83
+						$sth = $this->db->prepare($query);
84
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
85
+				} catch(PDOException $e) {
86
+						echo "error : ".$e->getMessage();
87
+				}
88
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
89
+				return $all;
90
+		}
91 91
 
92 92
 
93 93
 	public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '') {
@@ -95,66 +95,66 @@  discard block
 block discarded – undo
95 95
 		if ($filter_name == '') $filter_name = $this->filter_name;
96 96
 		if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name 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";
97 97
 		else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name 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";
98
-                 try {
99
-                        $sth = $this->db->prepare($query);
100
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
101
-                } catch(PDOException $e) {
102
-                        echo "error : ".$e->getMessage();
103
-                }
104
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
105
-                if (empty($all)) {
106
-            	    $filters = array('airlines' => array($stats_airline));
107
-            	    if ($filter_name != '') {
108
-            		    $filters = array_merge($filters,$globalStatsFilters[$filter_name]);
109
-            	    }
110
-            	    $Spotter = new Spotter($this->db);
111
-            	    $all = $Spotter->countAllAircraftTypes($limit,0,'',$filters);
112
-                }
113
-                return $all;
98
+				 try {
99
+						$sth = $this->db->prepare($query);
100
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
101
+				} catch(PDOException $e) {
102
+						echo "error : ".$e->getMessage();
103
+				}
104
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
105
+				if (empty($all)) {
106
+					$filters = array('airlines' => array($stats_airline));
107
+					if ($filter_name != '') {
108
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
109
+					}
110
+					$Spotter = new Spotter($this->db);
111
+					$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters);
112
+				}
113
+				return $all;
114 114
 	}
115 115
 	public function countAllAirlineCountries($limit = true,$filter_name = '') {
116 116
 		global $globalStatsFilters;
117 117
 		if ($filter_name == '') $filter_name = $this->filter_name;
118 118
 		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";
119 119
 		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";
120
-                 try {
121
-                        $sth = $this->db->prepare($query);
122
-                        $sth->execute(array(':filter_name' => $filter_name));
123
-                } catch(PDOException $e) {
124
-                        echo "error : ".$e->getMessage();
125
-                }
126
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
127
-                if (empty($all)) {
128
-            		$Spotter = new Spotter($this->db);
129
-            		$filters = array();
130
-            		if ($filter_name != '') {
131
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
132
-			}
133
-            		$all = $Spotter->countAllAirlineCountries($limit,$filters);
134
-                }
135
-                return $all;
120
+				 try {
121
+						$sth = $this->db->prepare($query);
122
+						$sth->execute(array(':filter_name' => $filter_name));
123
+				} catch(PDOException $e) {
124
+						echo "error : ".$e->getMessage();
125
+				}
126
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
127
+				if (empty($all)) {
128
+					$Spotter = new Spotter($this->db);
129
+					$filters = array();
130
+					if ($filter_name != '') {
131
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
132
+			}
133
+					$all = $Spotter->countAllAirlineCountries($limit,$filters);
134
+				}
135
+				return $all;
136 136
 	}
137 137
 	public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '') {
138 138
 		global $globalStatsFilters;
139 139
 		if ($filter_name == '') $filter_name = $this->filter_name;
140 140
 		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";
141 141
 		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";
142
-                 try {
143
-                        $sth = $this->db->prepare($query);
144
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
145
-                } catch(PDOException $e) {
146
-                        echo "error : ".$e->getMessage();
147
-                }
148
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
149
-                if (empty($all)) {
150
-            		$filters = array('airlines' => array($stats_airline));
151
-            		if ($filter_name != '') {
152
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
142
+				 try {
143
+						$sth = $this->db->prepare($query);
144
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
145
+				} catch(PDOException $e) {
146
+						echo "error : ".$e->getMessage();
147
+				}
148
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
149
+				if (empty($all)) {
150
+					$filters = array('airlines' => array($stats_airline));
151
+					if ($filter_name != '') {
152
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
153 153
 			}
154
-            		$Spotter = new Spotter($this->db);
154
+					$Spotter = new Spotter($this->db);
155 155
 			$all = $Spotter->countAllAircraftManufacturers($filters);
156
-                }
157
-                return $all;
156
+				}
157
+				return $all;
158 158
 	}
159 159
 
160 160
 	public function countAllArrivalCountries($limit = true, $stats_airline = '', $filter_name = '') {
@@ -162,44 +162,44 @@  discard block
 block discarded – undo
162 162
 		if ($filter_name == '') $filter_name = $this->filter_name;
163 163
 		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";
164 164
 		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";
165
-                 try {
166
-                        $sth = $this->db->prepare($query);
167
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
168
-                } catch(PDOException $e) {
169
-                        echo "error : ".$e->getMessage();
170
-                }
171
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
172
-                if (empty($all)) {
165
+				 try {
166
+						$sth = $this->db->prepare($query);
167
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
168
+				} catch(PDOException $e) {
169
+						echo "error : ".$e->getMessage();
170
+				}
171
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
172
+				if (empty($all)) {
173 173
 			$filters = array('airlines' => array($stats_airline));
174 174
 			if ($filter_name != '') {
175
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
175
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
176 176
 			}
177 177
 			$Spotter = new Spotter($this->db);
178 178
 			$all = $Spotter->countAllArrivalCountries($limit,$filters);
179
-                }
180
-                return $all;
179
+				}
180
+				return $all;
181 181
 	}
182 182
 	public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '') {
183 183
 		global $globalStatsFilters;
184 184
 		if ($filter_name == '') $filter_name = $this->filter_name;
185 185
 		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";
186 186
 		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";
187
-                 try {
188
-                        $sth = $this->db->prepare($query);
189
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
190
-                } catch(PDOException $e) {
191
-                        echo "error : ".$e->getMessage();
192
-                }
193
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
194
-                if (empty($all)) {
187
+				 try {
188
+						$sth = $this->db->prepare($query);
189
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
190
+				} catch(PDOException $e) {
191
+						echo "error : ".$e->getMessage();
192
+				}
193
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
194
+				if (empty($all)) {
195 195
 			$filters = array('airlines' => array($stats_airline));
196 196
 			if ($filter_name != '') {
197
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
197
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
198 198
 			}
199 199
 			$Spotter = new Spotter($this->db);
200 200
 			$all = $Spotter->countAllDepartureCountries($filters);
201
-                }
202
-                return $all;
201
+				}
202
+				return $all;
203 203
 	}
204 204
 
205 205
 	public function countAllAirlines($limit = true,$filter_name = '') {
@@ -207,45 +207,45 @@  discard block
 block discarded – undo
207 207
 		if ($filter_name == '') $filter_name = $this->filter_name;
208 208
 		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 ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
209 209
 		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 ORDER BY airline_count DESC";
210
-                 try {
211
-                        $sth = $this->db->prepare($query);
212
-                        $sth->execute(array(':filter_name' => $filter_name));
213
-                } catch(PDOException $e) {
214
-                        echo "error : ".$e->getMessage();
215
-                }
216
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
217
-                if (empty($all)) {
218
-	                $Spotter = new Spotter($this->db);
219
-            		$filters = array();
220
-            		if ($filter_name != '') {
221
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
210
+				 try {
211
+						$sth = $this->db->prepare($query);
212
+						$sth->execute(array(':filter_name' => $filter_name));
213
+				} catch(PDOException $e) {
214
+						echo "error : ".$e->getMessage();
215
+				}
216
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
217
+				if (empty($all)) {
218
+					$Spotter = new Spotter($this->db);
219
+					$filters = array();
220
+					if ($filter_name != '') {
221
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
222 222
 			}
223 223
 
224
-    		        $all = $Spotter->countAllAirlines($limit,0,'',$filters);
225
-                }
226
-                return $all;
224
+					$all = $Spotter->countAllAirlines($limit,0,'',$filters);
225
+				}
226
+				return $all;
227 227
 	}
228 228
 	public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '') {
229 229
 		global $globalStatsFilters;
230 230
 		if ($filter_name == '') $filter_name = $this->filter_name;
231 231
 		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";
232 232
 		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";
233
-                 try {
234
-                        $sth = $this->db->prepare($query);
235
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
236
-                } catch(PDOException $e) {
237
-                        echo "error : ".$e->getMessage();
238
-                }
239
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
240
-                if (empty($all)) {
233
+				 try {
234
+						$sth = $this->db->prepare($query);
235
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
236
+				} catch(PDOException $e) {
237
+						echo "error : ".$e->getMessage();
238
+				}
239
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
240
+				if (empty($all)) {
241 241
 			$filters = array('airlines' => array($stats_airline));
242 242
 			if ($filter_name != '') {
243 243
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
244 244
 			}
245
-	                $Spotter = new Spotter($this->db);
246
-    		        $all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters);
247
-                }
248
-                return $all;
245
+					$Spotter = new Spotter($this->db);
246
+					$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters);
247
+				}
248
+				return $all;
249 249
 	}
250 250
 	public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '') {
251 251
 		global $globalStatsFilters;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 				echo "error : ".$e->getMessage();
283 283
 			}
284 284
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
285
-                /*
285
+				/*
286 286
                 if (empty($all)) {
287 287
 	                $Spotter = new Spotter($this->db);
288 288
     		        $all = $Spotter->countAllFlightOverCountries($limit);
@@ -298,84 +298,84 @@  discard block
 block discarded – undo
298 298
 		if ($filter_name == '') $filter_name = $this->filter_name;
299 299
 		if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";
300 300
 		else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC";
301
-                 try {
302
-                        $sth = $this->db->prepare($query);
303
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
304
-                } catch(PDOException $e) {
305
-                        echo "error : ".$e->getMessage();
306
-                }
307
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
308
-                if (empty($all)) {
301
+				 try {
302
+						$sth = $this->db->prepare($query);
303
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
304
+				} catch(PDOException $e) {
305
+						echo "error : ".$e->getMessage();
306
+				}
307
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
308
+				if (empty($all)) {
309 309
 			$filters = array('airlines' => array($stats_airline));
310 310
 			if ($filter_name != '') {
311 311
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
312 312
 			}
313
-            		$Spotter = new Spotter($this->db);
314
-            		$all = $Spotter->countAllPilots($limit,0,'',$filters);
315
-                }
316
-                return $all;
313
+					$Spotter = new Spotter($this->db);
314
+					$all = $Spotter->countAllPilots($limit,0,'',$filters);
315
+				}
316
+				return $all;
317 317
 	}
318 318
 	public function countAllOwners($limit = true,$stats_airline = '', $filter_name = '') {
319 319
 		global $globalStatsFilters;
320 320
 		if ($filter_name == '') $filter_name = $this->filter_name;
321 321
 		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";
322 322
 		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";
323
-                 try {
324
-                        $sth = $this->db->prepare($query);
325
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
326
-                } catch(PDOException $e) {
327
-                        echo "error : ".$e->getMessage();
328
-                }
329
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
330
-                if (empty($all)) {
323
+				 try {
324
+						$sth = $this->db->prepare($query);
325
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
326
+				} catch(PDOException $e) {
327
+						echo "error : ".$e->getMessage();
328
+				}
329
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
330
+				if (empty($all)) {
331 331
 			$filters = array('airlines' => array($stats_airline));
332 332
 			if ($filter_name != '') {
333 333
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
334 334
 			}
335
-            		$Spotter = new Spotter($this->db);
336
-            		$all = $Spotter->countAllOwners($limit,0,'',$filters);
337
-                }
338
-                return $all;
335
+					$Spotter = new Spotter($this->db);
336
+					$all = $Spotter->countAllOwners($limit,0,'',$filters);
337
+				}
338
+				return $all;
339 339
 	}
340 340
 	public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '') {
341 341
 		global $globalStatsFilters;
342 342
 		if ($filter_name == '') $filter_name = $this->filter_name;
343 343
 		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";
344 344
 		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";
345
-                 try {
346
-                        $sth = $this->db->prepare($query);
347
-                        $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
348
-                } catch(PDOException $e) {
349
-                        echo "error : ".$e->getMessage();
350
-                }
351
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
352
-                if (empty($all)) {
345
+				 try {
346
+						$sth = $this->db->prepare($query);
347
+						$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name));
348
+				} catch(PDOException $e) {
349
+						echo "error : ".$e->getMessage();
350
+				}
351
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
352
+				if (empty($all)) {
353 353
 			$filters = array('airlines' => array($stats_airline));
354
-            		if ($filter_name != '') {
355
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
356
-			}
357
-            		$Spotter = new Spotter($this->db);
358
-            		$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters);
359
-        		$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters);
360
-        		$all = array();
361
-        		foreach ($pall as $value) {
362
-        			$icao = $value['airport_departure_icao'];
363
-        			$all[$icao] = $value;
364
-        		}
354
+					if ($filter_name != '') {
355
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
356
+			}
357
+					$Spotter = new Spotter($this->db);
358
+					$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters);
359
+				$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters);
360
+				$all = array();
361
+				foreach ($pall as $value) {
362
+					$icao = $value['airport_departure_icao'];
363
+					$all[$icao] = $value;
364
+				}
365 365
         		
366
-        		foreach ($dall as $value) {
367
-        			$icao = $value['airport_departure_icao'];
368
-        			if (isset($all[$icao])) {
369
-        				$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
370
-        			} else $all[$icao] = $value;
371
-        		}
372
-        		$count = array();
373
-        		foreach ($all as $key => $row) {
374
-        			$count[$key] = $row['airport_departure_icao_count'];
375
-        		}
376
-        		array_multisort($count,SORT_DESC,$all);
377
-                }
378
-                return $all;
366
+				foreach ($dall as $value) {
367
+					$icao = $value['airport_departure_icao'];
368
+					if (isset($all[$icao])) {
369
+						$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
370
+					} else $all[$icao] = $value;
371
+				}
372
+				$count = array();
373
+				foreach ($all as $key => $row) {
374
+					$count[$key] = $row['airport_departure_icao_count'];
375
+				}
376
+				array_multisort($count,SORT_DESC,$all);
377
+				}
378
+				return $all;
379 379
 	}
380 380
 	public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '') {
381 381
 		global $globalStatsFilters;
@@ -397,26 +397,26 @@  discard block
 block discarded – undo
397 397
 			$Spotter = new Spotter($this->db);
398 398
 			$pall = $Spotter->countAllArrivalAirports($limit,0,'',false,$filters);
399 399
 			$dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters);
400
-        		$all = array();
401
-        		foreach ($pall as $value) {
402
-        			$icao = $value['airport_arrival_icao'];
403
-        			$all[$icao] = $value;
404
-        		}
400
+				$all = array();
401
+				foreach ($pall as $value) {
402
+					$icao = $value['airport_arrival_icao'];
403
+					$all[$icao] = $value;
404
+				}
405 405
         		
406
-        		foreach ($dall as $value) {
407
-        			$icao = $value['airport_arrival_icao'];
408
-        			if (isset($all[$icao])) {
409
-        				$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
410
-        			} else $all[$icao] = $value;
411
-        		}
412
-        		$count = array();
413
-        		foreach ($all as $key => $row) {
414
-        			$count[$key] = $row['airport_arrival_icao_count'];
415
-        		}
416
-        		array_multisort($count,SORT_DESC,$all);
417
-                }
406
+				foreach ($dall as $value) {
407
+					$icao = $value['airport_arrival_icao'];
408
+					if (isset($all[$icao])) {
409
+						$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
410
+					} else $all[$icao] = $value;
411
+				}
412
+				$count = array();
413
+				foreach ($all as $key => $row) {
414
+					$count[$key] = $row['airport_arrival_icao_count'];
415
+				}
416
+				array_multisort($count,SORT_DESC,$all);
417
+				}
418 418
  
419
-                return $all;
419
+				return $all;
420 420
 	}
421 421
 	public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') {
422 422
 		global $globalDBdriver, $globalStatsFilters;
@@ -429,23 +429,23 @@  discard block
 block discarded – undo
429 429
 			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";
430 430
 		}
431 431
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
432
-                 try {
433
-                        $sth = $this->db->prepare($query);
434
-                        $sth->execute($query_data);
435
-                } catch(PDOException $e) {
436
-                        echo "error : ".$e->getMessage();
437
-                }
438
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
439
-                if (empty($all)) {
432
+				 try {
433
+						$sth = $this->db->prepare($query);
434
+						$sth->execute($query_data);
435
+				} catch(PDOException $e) {
436
+						echo "error : ".$e->getMessage();
437
+				}
438
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
439
+				if (empty($all)) {
440 440
 			$filters = array('airlines' => array($stats_airline));
441 441
 			if ($filter_name != '') {
442 442
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
443 443
 			}
444
-            		$Spotter = new Spotter($this->db);
445
-            		$all = $Spotter->countAllMonthsLastYear($filters);
446
-                }
444
+					$Spotter = new Spotter($this->db);
445
+					$all = $Spotter->countAllMonthsLastYear($filters);
446
+				}
447 447
                 
448
-                return $all;
448
+				return $all;
449 449
 	}
450 450
 	
451 451
 	public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') {
@@ -453,22 +453,22 @@  discard block
 block discarded – undo
453 453
 		if ($filter_name == '') $filter_name = $this->filter_name;
454 454
 		$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";
455 455
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
456
-                 try {
457
-                        $sth = $this->db->prepare($query);
458
-                        $sth->execute($query_data);
459
-                } catch(PDOException $e) {
460
-                        echo "error : ".$e->getMessage();
461
-                }
462
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
463
-                if (empty($all)) {
456
+				 try {
457
+						$sth = $this->db->prepare($query);
458
+						$sth->execute($query_data);
459
+				} catch(PDOException $e) {
460
+						echo "error : ".$e->getMessage();
461
+				}
462
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
463
+				if (empty($all)) {
464 464
 			$filters = array('airlines' => array($stats_airline));
465 465
 			if ($filter_name != '') {
466 466
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
467 467
 			}
468
-            		$Spotter = new Spotter($this->db);
469
-            		$all = $Spotter->countAllDatesLastMonth($filters);
470
-                }
471
-                return $all;
468
+					$Spotter = new Spotter($this->db);
469
+					$all = $Spotter->countAllDatesLastMonth($filters);
470
+				}
471
+				return $all;
472 472
 	}
473 473
 	public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') {
474 474
 		global $globalDBdriver, $globalStatsFilters;
@@ -479,108 +479,108 @@  discard block
 block discarded – undo
479 479
 			$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";
480 480
 		}
481 481
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
482
-                 try {
483
-                        $sth = $this->db->prepare($query);
484
-                        $sth->execute($query_data);
485
-                } catch(PDOException $e) {
486
-                        echo "error : ".$e->getMessage();
487
-                }
488
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
489
-                if (empty($all)) {
482
+				 try {
483
+						$sth = $this->db->prepare($query);
484
+						$sth->execute($query_data);
485
+				} catch(PDOException $e) {
486
+						echo "error : ".$e->getMessage();
487
+				}
488
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
489
+				if (empty($all)) {
490 490
 			$filters = array('airlines' => array($stats_airline));
491 491
 			if ($filter_name != '') {
492 492
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
493 493
 			}
494
-            		$Spotter = new Spotter($this->db);
495
-            		$all = $Spotter->countAllDatesLast7Days($filters);
496
-                }
497
-                return $all;
494
+					$Spotter = new Spotter($this->db);
495
+					$all = $Spotter->countAllDatesLast7Days($filters);
496
+				}
497
+				return $all;
498 498
 	}
499 499
 	public function countAllDates($stats_airline = '',$filter_name = '') {
500 500
 		global $globalStatsFilters;
501 501
 		if ($filter_name == '') $filter_name = $this->filter_name;
502 502
 		$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";
503 503
 		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name);
504
-                 try {
505
-                        $sth = $this->db->prepare($query);
506
-                        $sth->execute($query_data);
507
-                } catch(PDOException $e) {
508
-                        echo "error : ".$e->getMessage();
509
-                }
510
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
511
-                if (empty($all)) {
504
+				 try {
505
+						$sth = $this->db->prepare($query);
506
+						$sth->execute($query_data);
507
+				} catch(PDOException $e) {
508
+						echo "error : ".$e->getMessage();
509
+				}
510
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
511
+				if (empty($all)) {
512 512
 			$filters = array('airlines' => array($stats_airline));
513 513
 			if ($filter_name != '') {
514
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
514
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
515 515
 			}
516
-            		$Spotter = new Spotter($this->db);
517
-            		$all = $Spotter->countAllDates($filters);
518
-                }
519
-                return $all;
516
+					$Spotter = new Spotter($this->db);
517
+					$all = $Spotter->countAllDates($filters);
518
+				}
519
+				return $all;
520 520
 	}
521 521
 	public function countAllDatesByAirlines($filter_name = '') {
522 522
 		global $globalStatsFilters;
523 523
 		if ($filter_name == '') $filter_name = $this->filter_name;
524 524
 		$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";
525 525
 		$query_data = array('filter_name' => $filter_name);
526
-                 try {
527
-                        $sth = $this->db->prepare($query);
528
-                        $sth->execute($query_data);
529
-                } catch(PDOException $e) {
530
-                        echo "error : ".$e->getMessage();
531
-                }
532
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
533
-                if (empty($all)) {
534
-            		$filters = array();
535
-            		if ($filter_name != '') {
536
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
537
-			}
538
-            		$Spotter = new Spotter($this->db);
539
-            		$all = $Spotter->countAllDatesByAirlines($filters);
540
-                }
541
-                return $all;
526
+				 try {
527
+						$sth = $this->db->prepare($query);
528
+						$sth->execute($query_data);
529
+				} catch(PDOException $e) {
530
+						echo "error : ".$e->getMessage();
531
+				}
532
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
533
+				if (empty($all)) {
534
+					$filters = array();
535
+					if ($filter_name != '') {
536
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
537
+			}
538
+					$Spotter = new Spotter($this->db);
539
+					$all = $Spotter->countAllDatesByAirlines($filters);
540
+				}
541
+				return $all;
542 542
 	}
543 543
 	public function countAllMonths($stats_airline = '',$filter_name = '') {
544 544
 		global $globalStatsFilters;
545 545
 		if ($filter_name == '') $filter_name = $this->filter_name;
546
-	    	$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";
547
-                 try {
548
-                        $sth = $this->db->prepare($query);
549
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
550
-                } catch(PDOException $e) {
551
-                        echo "error : ".$e->getMessage();
552
-                }
553
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
554
-                if (empty($all)) {
546
+			$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";
547
+				 try {
548
+						$sth = $this->db->prepare($query);
549
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
550
+				} catch(PDOException $e) {
551
+						echo "error : ".$e->getMessage();
552
+				}
553
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
554
+				if (empty($all)) {
555 555
 			$filters = array('airlines' => array($stats_airline));
556 556
 			if ($filter_name != '') {
557 557
 				$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
558 558
 			}
559
-            		$Spotter = new Spotter($this->db);
560
-            		$all = $Spotter->countAllMonths($filters);
561
-                }
562
-                return $all;
559
+					$Spotter = new Spotter($this->db);
560
+					$all = $Spotter->countAllMonths($filters);
561
+				}
562
+				return $all;
563 563
 	}
564 564
 	public function countAllMilitaryMonths($filter_name = '') {
565 565
 		global $globalStatsFilters;
566 566
 		if ($filter_name == '') $filter_name = $this->filter_name;
567
-	    	$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";
568
-                 try {
569
-                        $sth = $this->db->prepare($query);
570
-                        $sth->execute(array(':filter_name' => $filter_name));
571
-                } catch(PDOException $e) {
572
-                        echo "error : ".$e->getMessage();
573
-                }
574
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
575
-                if (empty($all)) {
576
-            		$filters = array();
577
-            		if ($filter_name != '') {
578
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
579
-			}
580
-            		$Spotter = new Spotter($this->db);
581
-            		$all = $Spotter->countAllMilitaryMonths($filters);
582
-                }
583
-                return $all;
567
+			$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";
568
+				 try {
569
+						$sth = $this->db->prepare($query);
570
+						$sth->execute(array(':filter_name' => $filter_name));
571
+				} catch(PDOException $e) {
572
+						echo "error : ".$e->getMessage();
573
+				}
574
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
575
+				if (empty($all)) {
576
+					$filters = array();
577
+					if ($filter_name != '') {
578
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
579
+			}
580
+					$Spotter = new Spotter($this->db);
581
+					$all = $Spotter->countAllMilitaryMonths($filters);
582
+				}
583
+				return $all;
584 584
 	}
585 585
 	public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') {
586 586
 		global $globalTimezone, $globalDBdriver, $globalStatsFilters;
@@ -596,22 +596,22 @@  discard block
 block discarded – undo
596 596
 			$query .= " ORDER BY CAST(flight_date AS integer) ASC";
597 597
 		}
598 598
 		if ($orderby == 'count') $query .= " ORDER BY hour_count DESC";
599
-                 try {
600
-                        $sth = $this->db->prepare($query);
601
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
602
-                } catch(PDOException $e) {
603
-                        echo "error : ".$e->getMessage();
604
-                }
605
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
606
-                if (empty($all)) {
599
+				 try {
600
+						$sth = $this->db->prepare($query);
601
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
602
+				} catch(PDOException $e) {
603
+						echo "error : ".$e->getMessage();
604
+				}
605
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
606
+				if (empty($all)) {
607 607
 			$filters = array('airlines' => array($stats_airline));
608 608
 			if ($filter_name != '') {
609
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
609
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
610 610
 			}
611
-            		$Spotter = new Spotter($this->db);
612
-            		$all = $Spotter->countAllHours($orderby,$filters);
613
-                }
614
-                return $all;
611
+					$Spotter = new Spotter($this->db);
612
+					$all = $Spotter->countAllHours($orderby,$filters);
613
+				}
614
+				return $all;
615 615
 	}
616 616
 	
617 617
 	public function countOverallFlights($stats_airline = '', $filter_name = '') {
@@ -633,9 +633,9 @@  discard block
 block discarded – undo
633 633
 		if ($filter_name == '') $filter_name = $this->filter_name;
634 634
 		$all = $this->getSumStats('military_flights_bymonth',date('Y'),'',$filter_name);
635 635
 		if (empty($all)) {
636
-		        $filters = array();
637
-            		if ($filter_name != '') {
638
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
636
+				$filters = array();
637
+					if ($filter_name != '') {
638
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
639 639
 			}
640 640
 			$Spotter = new Spotter($this->db);
641 641
 			$all = $Spotter->countOverallMilitaryFlights($filters);
@@ -674,19 +674,19 @@  discard block
 block discarded – undo
674 674
 		global $globalStatsFilters;
675 675
 		if ($filter_name == '') $filter_name = $this->filter_name;
676 676
 		$query = "SELECT COUNT(*) AS nb_airline FROM stats_airline WHERE filter_name = :filter_name";
677
-                 try {
678
-                        $sth = $this->db->prepare($query);
679
-                        $sth->execute(array(':filter_name' => $filter_name));
680
-                } catch(PDOException $e) {
681
-                        echo "error : ".$e->getMessage();
682
-                }
683
-                $result = $sth->fetchAll(PDO::FETCH_ASSOC);
684
-                $all = $result[0]['nb_airline'];
677
+				 try {
678
+						$sth = $this->db->prepare($query);
679
+						$sth->execute(array(':filter_name' => $filter_name));
680
+				} catch(PDOException $e) {
681
+						echo "error : ".$e->getMessage();
682
+				}
683
+				$result = $sth->fetchAll(PDO::FETCH_ASSOC);
684
+				$all = $result[0]['nb_airline'];
685 685
 		//$all = $this->getSumStats('airlines_bymonth',date('Y'));
686 686
 		if (empty($all)) {
687
-            		$filters = array();
688
-            		if ($filter_name != '') {
689
-            			$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
687
+					$filters = array();
688
+					if ($filter_name != '') {
689
+						$filters = array_merge($filters,$globalStatsFilters[$filter_name]);
690 690
 			}
691 691
 			$Spotter = new Spotter($this->db);
692 692
 			$all = $Spotter->countOverallAirlines($filters);
@@ -737,166 +737,166 @@  discard block
 block discarded – undo
737 737
 		if ($filter_name == '') $filter_name = $this->filter_name;
738 738
 		$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";
739 739
 		$query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
740
-                 try {
741
-                        $sth = $this->db->prepare($query);
742
-                        $sth->execute($query_values);
743
-                } catch(PDOException $e) {
744
-                        echo "error : ".$e->getMessage();
745
-                }
746
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
747
-                return $all;
740
+				 try {
741
+						$sth = $this->db->prepare($query);
742
+						$sth->execute($query_values);
743
+				} catch(PDOException $e) {
744
+						echo "error : ".$e->getMessage();
745
+				}
746
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
747
+				return $all;
748 748
 	}
749 749
 	public function getStats($type,$stats_airline = '', $filter_name = '') {
750 750
 		if ($filter_name == '') $filter_name = $this->filter_name;
751
-                $query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";
752
-                $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
753
-                 try {
754
-                        $sth = $this->db->prepare($query);
755
-                        $sth->execute($query_values);
756
-                } catch(PDOException $e) {
757
-                        echo "error : ".$e->getMessage();
758
-                }
759
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
760
-                return $all;
761
-        }
751
+				$query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";
752
+				$query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
753
+				 try {
754
+						$sth = $this->db->prepare($query);
755
+						$sth->execute($query_values);
756
+				} catch(PDOException $e) {
757
+						echo "error : ".$e->getMessage();
758
+				}
759
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
760
+				return $all;
761
+		}
762 762
 	public function getSumStats($type,$year,$stats_airline = '',$filter_name = '') {
763 763
 		if ($filter_name == '') $filter_name = $this->filter_name;
764
-    		global $globalArchiveMonths, $globalDBdriver;
765
-    		if ($globalDBdriver == 'mysql') {
766
-	                $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";
767
-	        } else {
768
-            		$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name";
769
-                }
770
-                $query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
771
-                 try {
772
-                        $sth = $this->db->prepare($query);
773
-                        $sth->execute($query_values);
774
-                } catch(PDOException $e) {
775
-                        echo "error : ".$e->getMessage();
776
-                }
777
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
778
-                return $all[0]['total'];
779
-        }
764
+			global $globalArchiveMonths, $globalDBdriver;
765
+			if ($globalDBdriver == 'mysql') {
766
+					$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";
767
+			} else {
768
+					$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name";
769
+				}
770
+				$query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
771
+				 try {
772
+						$sth = $this->db->prepare($query);
773
+						$sth->execute($query_values);
774
+				} catch(PDOException $e) {
775
+						echo "error : ".$e->getMessage();
776
+				}
777
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
778
+				return $all[0]['total'];
779
+		}
780 780
 	public function getStatsTotal($type, $stats_airline = '', $filter_name = '') {
781
-    		global $globalArchiveMonths, $globalDBdriver;
781
+			global $globalArchiveMonths, $globalDBdriver;
782 782
 		if ($filter_name == '') $filter_name = $this->filter_name;
783
-    		if ($globalDBdriver == 'mysql') {
783
+			if ($globalDBdriver == 'mysql') {
784 784
 			$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";
785 785
 		} else {
786 786
 			$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";
787
-                }
788
-                $query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
789
-                 try {
790
-                        $sth = $this->db->prepare($query);
791
-                        $sth->execute($query_values);
792
-                } catch(PDOException $e) {
793
-                        echo "error : ".$e->getMessage();
794
-                }
795
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
796
-                return $all[0]['total'];
797
-        }
787
+				}
788
+				$query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name);
789
+				 try {
790
+						$sth = $this->db->prepare($query);
791
+						$sth->execute($query_values);
792
+				} catch(PDOException $e) {
793
+						echo "error : ".$e->getMessage();
794
+				}
795
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
796
+				return $all[0]['total'];
797
+		}
798 798
 	public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') {
799
-    		global $globalArchiveMonths, $globalDBdriver;
799
+			global $globalArchiveMonths, $globalDBdriver;
800 800
 		if ($filter_name == '') $filter_name = $this->filter_name;
801
-    		if ($globalDBdriver == 'mysql') {
801
+			if ($globalDBdriver == 'mysql') {
802 802
 			$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
803
-                } else {
803
+				} else {
804 804
 			$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";
805
-                }
806
-                 try {
807
-                        $sth = $this->db->prepare($query);
808
-                        $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
809
-                } catch(PDOException $e) {
810
-                        echo "error : ".$e->getMessage();
811
-                }
812
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
813
-                return $all[0]['total'];
814
-        }
805
+				}
806
+				 try {
807
+						$sth = $this->db->prepare($query);
808
+						$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name));
809
+				} catch(PDOException $e) {
810
+						echo "error : ".$e->getMessage();
811
+				}
812
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
813
+				return $all[0]['total'];
814
+		}
815 815
 	public function getStatsAirlineTotal($filter_name = '') {
816
-    		global $globalArchiveMonths, $globalDBdriver;
816
+			global $globalArchiveMonths, $globalDBdriver;
817 817
 		if ($filter_name == '') $filter_name = $this->filter_name;
818
-    		if ($globalDBdriver == 'mysql') {
818
+			if ($globalDBdriver == 'mysql') {
819 819
 			$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";
820
-                } else {
820
+				} else {
821 821
 			$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";
822
-                }
823
-                 try {
824
-                        $sth = $this->db->prepare($query);
825
-                        $sth->execute(array(':filter_name' => $filter_name));
826
-                } catch(PDOException $e) {
827
-                        echo "error : ".$e->getMessage();
828
-                }
829
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
830
-                return $all[0]['total'];
831
-        }
822
+				}
823
+				 try {
824
+						$sth = $this->db->prepare($query);
825
+						$sth->execute(array(':filter_name' => $filter_name));
826
+				} catch(PDOException $e) {
827
+						echo "error : ".$e->getMessage();
828
+				}
829
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
830
+				return $all[0]['total'];
831
+		}
832 832
 	public function getStatsOwnerTotal($filter_name = '') {
833
-    		global $globalArchiveMonths, $globalDBdriver;
833
+			global $globalArchiveMonths, $globalDBdriver;
834 834
 		if ($filter_name == '') $filter_name = $this->filter_name;
835
-    		if ($globalDBdriver == 'mysql') {
835
+			if ($globalDBdriver == 'mysql') {
836 836
 			$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";
837 837
 		} else {
838 838
 			$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";
839
-                }
840
-                 try {
841
-                        $sth = $this->db->prepare($query);
842
-                        $sth->execute(array(':filter_name' => $filter_name));
843
-                } catch(PDOException $e) {
844
-                        echo "error : ".$e->getMessage();
845
-                }
846
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
847
-                return $all[0]['total'];
848
-        }
839
+				}
840
+				 try {
841
+						$sth = $this->db->prepare($query);
842
+						$sth->execute(array(':filter_name' => $filter_name));
843
+				} catch(PDOException $e) {
844
+						echo "error : ".$e->getMessage();
845
+				}
846
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
847
+				return $all[0]['total'];
848
+		}
849 849
 	public function getStatsPilotTotal($filter_name = '') {
850
-    		global $globalArchiveMonths, $globalDBdriver;
850
+			global $globalArchiveMonths, $globalDBdriver;
851 851
 		if ($filter_name == '') $filter_name = $this->filter_name;
852
-    		if ($globalDBdriver == 'mysql') {
853
-            		$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
854
-            	} else {
855
-            		$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
856
-            	}
857
-                 try {
858
-                        $sth = $this->db->prepare($query);
859
-                        $sth->execute(array(':filter_name' => $filter_name));
860
-                } catch(PDOException $e) {
861
-                        echo "error : ".$e->getMessage();
862
-                }
863
-                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
864
-                return $all[0]['total'];
865
-        }
852
+			if ($globalDBdriver == 'mysql') {
853
+					$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
854
+				} else {
855
+					$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";
856
+				}
857
+				 try {
858
+						$sth = $this->db->prepare($query);
859
+						$sth->execute(array(':filter_name' => $filter_name));
860
+				} catch(PDOException $e) {
861
+						echo "error : ".$e->getMessage();
862
+				}
863
+				$all = $sth->fetchAll(PDO::FETCH_ASSOC);
864
+				return $all[0]['total'];
865
+		}
866 866
 
867 867
 	public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
868 868
 		global $globalDBdriver;
869 869
 		if ($filter_name == '') $filter_name = $this->filter_name;
870 870
 		if ($globalDBdriver == 'mysql') {
871 871
 			$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";
872
-                } else {
872
+				} else {
873 873
 			$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);"; 
874 874
 		}
875
-                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
876
-                 try {
877
-                        $sth = $this->db->prepare($query);
878
-                        $sth->execute($query_values);
879
-                } catch(PDOException $e) {
880
-                        return "error : ".$e->getMessage();
881
-                }
882
-        }
875
+				$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
876
+				 try {
877
+						$sth = $this->db->prepare($query);
878
+						$sth->execute($query_values);
879
+				} catch(PDOException $e) {
880
+						return "error : ".$e->getMessage();
881
+				}
882
+		}
883 883
 	public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') {
884 884
 		global $globalDBdriver;
885 885
 		if ($filter_name == '') $filter_name = $this->filter_name;
886 886
 		if ($globalDBdriver == 'mysql') {
887 887
 			$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";
888 888
 		} else {
889
-            		//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
889
+					//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
890 890
 			$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);"; 
891
-                }
892
-                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
893
-                 try {
894
-                        $sth = $this->db->prepare($query);
895
-                        $sth->execute($query_values);
896
-                } catch(PDOException $e) {
897
-                        return "error : ".$e->getMessage();
898
-                }
899
-        }
891
+				}
892
+				$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
893
+				 try {
894
+						$sth = $this->db->prepare($query);
895
+						$sth->execute($query_values);
896
+				} catch(PDOException $e) {
897
+						return "error : ".$e->getMessage();
898
+				}
899
+		}
900 900
 	public function getStatsSource($date,$stats_type = '') {
901 901
 		if ($stats_type == '') {
902 902
 			$query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name";
@@ -905,15 +905,15 @@  discard block
 block discarded – undo
905 905
 			$query = "SELECT * FROM stats_source WHERE stats_date = :date AND stats_type = :stats_type ORDER BY source_name";
906 906
 			$query_values = array(':date' => $date,':stats_type' => $stats_type);
907 907
 		}
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
-        }
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
 
918 918
 	public function addStatSource($data,$source_name,$stats_type,$date) {
919 919
 		global $globalDBdriver;
@@ -921,25 +921,25 @@  discard block
 block discarded – undo
921 921
 			$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";
922 922
 		} else {
923 923
 			$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);"; 
924
-                }
925
-                $query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
926
-                 try {
927
-                        $sth = $this->db->prepare($query);
928
-                        $sth->execute($query_values);
929
-                } catch(PDOException $e) {
930
-                        return "error : ".$e->getMessage();
931
-                }
932
-        }
924
+				}
925
+				$query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
926
+				 try {
927
+						$sth = $this->db->prepare($query);
928
+						$sth->execute($query_values);
929
+				} catch(PDOException $e) {
930
+						return "error : ".$e->getMessage();
931
+				}
932
+		}
933 933
 	public function addStatFlight($type,$date_name,$cnt,$stats_airline = '',$filter_name = '') {
934
-                $query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)";
935
-                $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
936
-                 try {
937
-                        $sth = $this->db->prepare($query);
938
-                        $sth->execute($query_values);
939
-                } catch(PDOException $e) {
940
-                        return "error : ".$e->getMessage();
941
-                }
942
-        }
934
+				$query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)";
935
+				$query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name);
936
+				 try {
937
+						$sth = $this->db->prepare($query);
938
+						$sth->execute($query_values);
939
+				} catch(PDOException $e) {
940
+						return "error : ".$e->getMessage();
941
+				}
942
+		}
943 943
 	public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '',$airline_icao = '',$filter_name = '') {
944 944
 		global $globalDBdriver;
945 945
 		if ($globalDBdriver == 'mysql') {
@@ -947,14 +947,14 @@  discard block
 block discarded – undo
947 947
 		} else {
948 948
 			$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);"; 
949 949
 		}
950
-                $query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
951
-                 try {
952
-                        $sth = $this->db->prepare($query);
953
-                        $sth->execute($query_values);
954
-                } catch(PDOException $e) {
955
-                        return "error : ".$e->getMessage();
956
-                }
957
-        }
950
+				$query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name);
951
+				 try {
952
+						$sth = $this->db->prepare($query);
953
+						$sth->execute($query_values);
954
+				} catch(PDOException $e) {
955
+						return "error : ".$e->getMessage();
956
+				}
957
+		}
958 958
 	public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '', $filter_name = '') {
959 959
 		global $globalDBdriver;
960 960
 		if ($globalDBdriver == 'mysql') {
@@ -962,14 +962,14 @@  discard block
 block discarded – undo
962 962
 		} else {
963 963
 			$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);"; 
964 964
 		}
965
-                $query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name);
966
-                 try {
967
-                        $sth = $this->db->prepare($query);
968
-                        $sth->execute($query_values);
969
-                } catch(PDOException $e) {
970
-                        return "error : ".$e->getMessage();
971
-                }
972
-        }
965
+				$query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name);
966
+				 try {
967
+						$sth = $this->db->prepare($query);
968
+						$sth->execute($query_values);
969
+				} catch(PDOException $e) {
970
+						return "error : ".$e->getMessage();
971
+				}
972
+		}
973 973
 	public function addStatCountry($iso2,$iso3,$name,$cnt,$filter_name = '') {
974 974
 		global $globalDBdriver;
975 975
 		if ($globalDBdriver == 'mysql') {
@@ -977,14 +977,14 @@  discard block
 block discarded – undo
977 977
 		} else {
978 978
 			$query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; 
979 979
 		}
980
-                $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name);
981
-                 try {
982
-                        $sth = $this->db->prepare($query);
983
-                        $sth->execute($query_values);
984
-                } catch(PDOException $e) {
985
-                        return "error : ".$e->getMessage();
986
-                }
987
-        }
980
+				$query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name);
981
+				 try {
982
+						$sth = $this->db->prepare($query);
983
+						$sth->execute($query_values);
984
+				} catch(PDOException $e) {
985
+						return "error : ".$e->getMessage();
986
+				}
987
+		}
988 988
 	public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '',$aircraft_manufacturer = '', $airline_icao = '', $filter_name = '') {
989 989
 		global $globalDBdriver;
990 990
 		if ($globalDBdriver == 'mysql') {
@@ -992,14 +992,14 @@  discard block
 block discarded – undo
992 992
 		} else {
993 993
 			$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);"; 
994 994
 		}
995
-                $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);
996
-                 try {
997
-                        $sth = $this->db->prepare($query);
998
-                        $sth->execute($query_values);
999
-                } catch(PDOException $e) {
1000
-                        return "error : ".$e->getMessage();
1001
-                }
1002
-        }
995
+				$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);
996
+				 try {
997
+						$sth = $this->db->prepare($query);
998
+						$sth->execute($query_values);
999
+				} catch(PDOException $e) {
1000
+						return "error : ".$e->getMessage();
1001
+				}
1002
+		}
1003 1003
 	public function addStatAirline($airline_icao,$cnt,$airline_name = '',$filter_name = '') {
1004 1004
 		global $globalDBdriver;
1005 1005
 		if ($globalDBdriver == 'mysql') {
@@ -1007,14 +1007,14 @@  discard block
 block discarded – undo
1007 1007
 		} else {
1008 1008
 			$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);"; 
1009 1009
 		}
1010
-                $query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name);
1011
-                 try {
1012
-                        $sth = $this->db->prepare($query);
1013
-                        $sth->execute($query_values);
1014
-                } catch(PDOException $e) {
1015
-                        return "error : ".$e->getMessage();
1016
-                }
1017
-        }
1010
+				$query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name);
1011
+				 try {
1012
+						$sth = $this->db->prepare($query);
1013
+						$sth->execute($query_values);
1014
+				} catch(PDOException $e) {
1015
+						return "error : ".$e->getMessage();
1016
+				}
1017
+		}
1018 1018
 	public function addStatOwner($owner_name,$cnt,$stats_airline = '', $filter_name = '') {
1019 1019
 		global $globalDBdriver;
1020 1020
 		if ($globalDBdriver == 'mysql') {
@@ -1022,14 +1022,14 @@  discard block
 block discarded – undo
1022 1022
 		} else {
1023 1023
 			$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);"; 
1024 1024
 		}
1025
-                $query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1026
-                 try {
1027
-                        $sth = $this->db->prepare($query);
1028
-                        $sth->execute($query_values);
1029
-                } catch(PDOException $e) {
1030
-                        return "error : ".$e->getMessage();
1031
-                }
1032
-        }
1025
+				$query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1026
+				 try {
1027
+						$sth = $this->db->prepare($query);
1028
+						$sth->execute($query_values);
1029
+				} catch(PDOException $e) {
1030
+						return "error : ".$e->getMessage();
1031
+				}
1032
+		}
1033 1033
 	public function addStatPilot($pilot_id,$cnt,$pilot_name,$stats_airline = '',$filter_name = '') {
1034 1034
 		global $globalDBdriver;
1035 1035
 		if ($globalDBdriver == 'mysql') {
@@ -1037,14 +1037,14 @@  discard block
 block discarded – undo
1037 1037
 		} else {
1038 1038
 			$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; INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name) SELECT :pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1039 1039
 		}
1040
-                $query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1041
-                 try {
1042
-                        $sth = $this->db->prepare($query);
1043
-                        $sth->execute($query_values);
1044
-                } catch(PDOException $e) {
1045
-                        return "error : ".$e->getMessage();
1046
-                }
1047
-        }
1040
+				$query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name);
1041
+				 try {
1042
+						$sth = $this->db->prepare($query);
1043
+						$sth->execute($query_values);
1044
+				} catch(PDOException $e) {
1045
+						return "error : ".$e->getMessage();
1046
+				}
1047
+		}
1048 1048
 	public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') {
1049 1049
 		global $globalDBdriver;
1050 1050
 		if ($globalDBdriver == 'mysql') {
@@ -1052,14 +1052,14 @@  discard block
 block discarded – undo
1052 1052
 		} else {
1053 1053
 			$query = "UPDATE stats_airport SET departure = departure+:departure 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,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'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);"; 
1054 1054
 		}
1055
-                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => date('Y').'-01-01 00:00:00', ':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1056
-                 try {
1057
-                        $sth = $this->db->prepare($query);
1058
-                        $sth->execute($query_values);
1059
-                } catch(PDOException $e) {
1060
-                        return "error : ".$e->getMessage();
1061
-                }
1062
-        }
1055
+				$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => date('Y').'-01-01 00:00:00', ':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1056
+				 try {
1057
+						$sth = $this->db->prepare($query);
1058
+						$sth->execute($query_values);
1059
+				} catch(PDOException $e) {
1060
+						return "error : ".$e->getMessage();
1061
+				}
1062
+		}
1063 1063
 	public function addStatDepartureAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') {
1064 1064
 		global $globalDBdriver;
1065 1065
 		if ($globalDBdriver == 'mysql') {
@@ -1067,14 +1067,14 @@  discard block
 block discarded – undo
1067 1067
 		} else {
1068 1068
 			$query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1069 1069
 		}
1070
-                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1071
-                 try {
1072
-                        $sth = $this->db->prepare($query);
1073
-                        $sth->execute($query_values);
1074
-                } catch(PDOException $e) {
1075
-                        return "error : ".$e->getMessage();
1076
-                }
1077
-        }
1070
+				$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1071
+				 try {
1072
+						$sth = $this->db->prepare($query);
1073
+						$sth->execute($query_values);
1074
+				} catch(PDOException $e) {
1075
+						return "error : ".$e->getMessage();
1076
+				}
1077
+		}
1078 1078
 	public function addStatArrivalAirports($airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') {
1079 1079
 		global $globalDBdriver;
1080 1080
 		if ($globalDBdriver == 'mysql') {
@@ -1082,14 +1082,14 @@  discard block
 block discarded – undo
1082 1082
 		} else {
1083 1083
 			$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);"; 
1084 1084
 		}
1085
-                $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);
1086
-                 try {
1087
-                        $sth = $this->db->prepare($query);
1088
-                        $sth->execute($query_values);
1089
-                } catch(PDOException $e) {
1090
-                        return "error : ".$e->getMessage();
1091
-                }
1092
-        }
1085
+				$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);
1086
+				 try {
1087
+						$sth = $this->db->prepare($query);
1088
+						$sth->execute($query_values);
1089
+				} catch(PDOException $e) {
1090
+						return "error : ".$e->getMessage();
1091
+				}
1092
+		}
1093 1093
 	public function addStatArrivalAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') {
1094 1094
 		global $globalDBdriver;
1095 1095
 		if ($globalDBdriver == 'mysql') {
@@ -1097,52 +1097,52 @@  discard block
 block discarded – undo
1097 1097
 		} else {
1098 1098
 			$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline 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,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; 
1099 1099
 		}
1100
-                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival, ':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1101
-                 try {
1102
-                        $sth = $this->db->prepare($query);
1103
-                        $sth->execute($query_values);
1104
-                } catch(PDOException $e) {
1105
-                        return "error : ".$e->getMessage();
1106
-                }
1107
-        }
1100
+				$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival, ':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name);
1101
+				 try {
1102
+						$sth = $this->db->prepare($query);
1103
+						$sth->execute($query_values);
1104
+				} catch(PDOException $e) {
1105
+						return "error : ".$e->getMessage();
1106
+				}
1107
+		}
1108 1108
 
1109 1109
 	public function deleteStat($id) {
1110
-                $query = "DELETE FROM stats WHERE stats_id = :id";
1111
-                $query_values = array(':id' => $id);
1112
-                 try {
1113
-                        $sth = $this->db->prepare($query);
1114
-                        $sth->execute($query_values);
1115
-                } catch(PDOException $e) {
1116
-                        return "error : ".$e->getMessage();
1117
-                }
1118
-        }
1110
+				$query = "DELETE FROM stats WHERE stats_id = :id";
1111
+				$query_values = array(':id' => $id);
1112
+				 try {
1113
+						$sth = $this->db->prepare($query);
1114
+						$sth->execute($query_values);
1115
+				} catch(PDOException $e) {
1116
+						return "error : ".$e->getMessage();
1117
+				}
1118
+		}
1119 1119
 	public function deleteStatFlight($type) {
1120
-                $query = "DELETE FROM stats_flight WHERE stats_type = :type";
1121
-                $query_values = array(':type' => $type);
1122
-                 try {
1123
-                        $sth = $this->db->prepare($query);
1124
-                        $sth->execute($query_values);
1125
-                } catch(PDOException $e) {
1126
-                        return "error : ".$e->getMessage();
1127
-                }
1128
-        }
1120
+				$query = "DELETE FROM stats_flight WHERE stats_type = :type";
1121
+				$query_values = array(':type' => $type);
1122
+				 try {
1123
+						$sth = $this->db->prepare($query);
1124
+						$sth->execute($query_values);
1125
+				} catch(PDOException $e) {
1126
+						return "error : ".$e->getMessage();
1127
+				}
1128
+		}
1129 1129
 	public function deleteStatAirport($type) {
1130
-                $query = "DELETE FROM stats_airport WHERE stats_type = :type";
1131
-                $query_values = array(':type' => $type);
1132
-                 try {
1133
-                        $sth = $this->db->prepare($query);
1134
-                        $sth->execute($query_values);
1135
-                } catch(PDOException $e) {
1136
-                        return "error : ".$e->getMessage();
1137
-                }
1138
-        }
1130
+				$query = "DELETE FROM stats_airport WHERE stats_type = :type";
1131
+				$query_values = array(':type' => $type);
1132
+				 try {
1133
+						$sth = $this->db->prepare($query);
1134
+						$sth->execute($query_values);
1135
+				} catch(PDOException $e) {
1136
+						return "error : ".$e->getMessage();
1137
+				}
1138
+		}
1139 1139
         
1140
-        public function addOldStats() {
1141
-    		global $globalDebug, $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters;
1142
-    		$Common = new Common();
1143
-    		$Connection = new Connection();
1144
-    		date_default_timezone_set('UTC');
1145
-    		$last_update = $this->getLastStatsUpdate('last_update_stats');
1140
+		public function addOldStats() {
1141
+			global $globalDebug, $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters;
1142
+			$Common = new Common();
1143
+			$Connection = new Connection();
1144
+			date_default_timezone_set('UTC');
1145
+			$last_update = $this->getLastStatsUpdate('last_update_stats');
1146 1146
 		//print_r($last_update);
1147 1147
 		/*
1148 1148
 		$flightsbymonth = $this->getStats('flights_by_month');
@@ -1404,24 +1404,24 @@  discard block
 block discarded – undo
1404 1404
 			if ($globalDebug) echo 'Count all departure airports...'."\n";
1405 1405
 			$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day);
1406 1406
 			if ($globalDebug) echo 'Count all detected departure airports...'."\n";
1407
-        		$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1407
+				$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1408 1408
 			if ($globalDebug) echo 'Order departure airports...'."\n";
1409
-	        	$alldata = array();
1409
+				$alldata = array();
1410 1410
 	        	
1411
-    			foreach ($pall as $value) {
1412
-	        		$icao = $value['airport_departure_icao'];
1413
-    				$alldata[$icao] = $value;
1414
-	        	}
1415
-	        	foreach ($dall as $value) {
1416
-    				$icao = $value['airport_departure_icao'];
1417
-        			if (isset($alldata[$icao])) {
1418
-    					$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1419
-        			} else $alldata[$icao] = $value;
1420
-			}
1421
-    			$count = array();
1422
-    			foreach ($alldata as $key => $row) {
1423
-    				$count[$key] = $row['airport_departure_icao_count'];
1424
-        		}
1411
+				foreach ($pall as $value) {
1412
+					$icao = $value['airport_departure_icao'];
1413
+					$alldata[$icao] = $value;
1414
+				}
1415
+				foreach ($dall as $value) {
1416
+					$icao = $value['airport_departure_icao'];
1417
+					if (isset($alldata[$icao])) {
1418
+						$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1419
+					} else $alldata[$icao] = $value;
1420
+			}
1421
+				$count = array();
1422
+				foreach ($alldata as $key => $row) {
1423
+					$count[$key] = $row['airport_departure_icao_count'];
1424
+				}
1425 1425
 			array_multisort($count,SORT_DESC,$alldata);
1426 1426
 			foreach ($alldata as $number) {
1427 1427
 				echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']);
@@ -1429,25 +1429,25 @@  discard block
 block discarded – undo
1429 1429
 			if ($globalDebug) echo 'Count all arrival airports...'."\n";
1430 1430
 			$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day);
1431 1431
 			if ($globalDebug) echo 'Count all detected arrival airports...'."\n";
1432
-        		$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1432
+				$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1433 1433
 			if ($globalDebug) echo 'Order arrival airports...'."\n";
1434
-	        	$alldata = array();
1435
-    			foreach ($pall as $value) {
1436
-	        		$icao = $value['airport_arrival_icao'];
1437
-    				$alldata[$icao] = $value;
1438
-	        	}
1439
-	        	foreach ($dall as $value) {
1440
-    				$icao = $value['airport_arrival_icao'];
1441
-        			if (isset($alldata[$icao])) {
1442
-        				$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1443
-	        		} else $alldata[$icao] = $value;
1444
-    			}
1445
-        		$count = array();
1446
-        		foreach ($alldata as $key => $row) {
1447
-        			$count[$key] = $row['airport_arrival_icao_count'];
1448
-	        	}
1449
-    			array_multisort($count,SORT_DESC,$alldata);
1450
-                        foreach ($alldata as $number) {
1434
+				$alldata = array();
1435
+				foreach ($pall as $value) {
1436
+					$icao = $value['airport_arrival_icao'];
1437
+					$alldata[$icao] = $value;
1438
+				}
1439
+				foreach ($dall as $value) {
1440
+					$icao = $value['airport_arrival_icao'];
1441
+					if (isset($alldata[$icao])) {
1442
+						$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1443
+					} else $alldata[$icao] = $value;
1444
+				}
1445
+				$count = array();
1446
+				foreach ($alldata as $key => $row) {
1447
+					$count[$key] = $row['airport_arrival_icao_count'];
1448
+				}
1449
+				array_multisort($count,SORT_DESC,$alldata);
1450
+						foreach ($alldata as $number) {
1451 1451
 				echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']);
1452 1452
 			}
1453 1453
 			if ($Connection->tableExists('countries')) {
@@ -1507,8 +1507,8 @@  discard block
 block discarded – undo
1507 1507
 //			$pall = $Spotter->getLast7DaysAirportsDeparture();
1508 1508
   //      		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1509 1509
 			$pall = $Spotter->getLast7DaysAirportsDeparture();
1510
-        		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1511
-        		/*
1510
+				$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1511
+				/*
1512 1512
 	        	$alldata = array();
1513 1513
     			foreach ($pall as $value) {
1514 1514
 	        		$icao = $value['departure_airport_icao'];
@@ -1527,29 +1527,29 @@  discard block
 block discarded – undo
1527 1527
 	        	}
1528 1528
     			array_multisort($count,SORT_DESC,$alldata);
1529 1529
     			*/
1530
-    			foreach ($dall as $value) {
1531
-    				$icao = $value['departure_airport_icao'];
1532
-    				$ddate = $value['date'];
1533
-    				$find = false;
1534
-    				foreach ($pall as $pvalue) {
1535
-    					if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1536
-    						$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1537
-    						$find = true;
1538
-    						break;
1539
-    					}
1540
-    				}
1541
-    				if ($find === false) {
1542
-    					$pall[] = $value;
1543
-    				}
1544
-    			}
1545
-    			$alldata = $pall;
1530
+				foreach ($dall as $value) {
1531
+					$icao = $value['departure_airport_icao'];
1532
+					$ddate = $value['date'];
1533
+					$find = false;
1534
+					foreach ($pall as $pvalue) {
1535
+						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1536
+							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1537
+							$find = true;
1538
+							break;
1539
+						}
1540
+					}
1541
+					if ($find === false) {
1542
+						$pall[] = $value;
1543
+					}
1544
+				}
1545
+				$alldata = $pall;
1546 1546
 			foreach ($alldata as $number) {
1547 1547
 				$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']);
1548 1548
 			}
1549 1549
 			echo '...Arrival'."\n";
1550 1550
 			$pall = $Spotter->getLast7DaysAirportsArrival();
1551
-        		$dall = $Spotter->getLast7DaysDetectedAirportsArrival();
1552
-        		/*
1551
+				$dall = $Spotter->getLast7DaysDetectedAirportsArrival();
1552
+				/*
1553 1553
 	        	$alldata = array();
1554 1554
     			foreach ($pall as $value) {
1555 1555
 	        		$icao = $value['arrival_airport_icao'];
@@ -1569,22 +1569,22 @@  discard block
 block discarded – undo
1569 1569
     			*/
1570 1570
 
1571 1571
 
1572
-    			foreach ($dall as $value) {
1573
-    				$icao = $value['arrival_airport_icao'];
1574
-    				$ddate = $value['date'];
1575
-    				$find = false;
1576
-    				foreach ($pall as $pvalue) {
1577
-    					if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1578
-    						$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1579
-    						$find = true;
1580
-    						break;
1581
-    					}
1582
-    				}
1583
-    				if ($find === false) {
1584
-    					$pall[] = $value;
1585
-    				}
1586
-    			}
1587
-    			$alldata = $pall;
1572
+				foreach ($dall as $value) {
1573
+					$icao = $value['arrival_airport_icao'];
1574
+					$ddate = $value['date'];
1575
+					$find = false;
1576
+					foreach ($pall as $pvalue) {
1577
+						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1578
+							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1579
+							$find = true;
1580
+							break;
1581
+						}
1582
+					}
1583
+					if ($find === false) {
1584
+						$pall[] = $value;
1585
+					}
1586
+				}
1587
+				$alldata = $pall;
1588 1588
 			foreach ($alldata as $number) {
1589 1589
 				$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']);
1590 1590
 			}
@@ -1651,51 +1651,51 @@  discard block
 block discarded – undo
1651 1651
 			if ($globalDebug) echo 'Count all departure airports by airlines...'."\n";
1652 1652
 			$pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day);
1653 1653
 			if ($globalDebug) echo 'Count all detected departure airports by airlines...'."\n";
1654
-       			$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);
1654
+	   			$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);
1655 1655
 			if ($globalDebug) echo 'Order detected departure airports by airlines...'."\n";
1656
-	        	//$alldata = array();
1657
-    			foreach ($dall as $value) {
1658
-    				$icao = $value['airport_departure_icao'];
1659
-    				$dicao = $value['airline_icao'];
1660
-    				$find = false;
1661
-    				foreach ($pall as $pvalue) {
1662
-    					if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1663
-    						$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1664
-    						$find = true;
1665
-    						break;
1666
-    					}
1667
-    				}
1668
-    				if ($find === false) {
1669
-    					$pall[] = $value;
1670
-    				}
1671
-    			}
1672
-    			$alldata = $pall;
1656
+				//$alldata = array();
1657
+				foreach ($dall as $value) {
1658
+					$icao = $value['airport_departure_icao'];
1659
+					$dicao = $value['airline_icao'];
1660
+					$find = false;
1661
+					foreach ($pall as $pvalue) {
1662
+						if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1663
+							$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1664
+							$find = true;
1665
+							break;
1666
+						}
1667
+					}
1668
+					if ($find === false) {
1669
+						$pall[] = $value;
1670
+					}
1671
+				}
1672
+				$alldata = $pall;
1673 1673
 			foreach ($alldata as $number) {
1674 1674
 				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']);
1675 1675
 			}
1676 1676
 			if ($globalDebug) echo 'Count all arrival airports by airlines...'."\n";
1677 1677
 			$pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day);
1678 1678
 			if ($globalDebug) echo 'Count all detected arrival airports by airlines...'."\n";
1679
-        		$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);
1679
+				$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);
1680 1680
 			if ($globalDebug) echo 'Order arrival airports by airlines...'."\n";
1681
-	        	//$alldata = array();
1682
-    			foreach ($dall as $value) {
1683
-    				$icao = $value['airport_arrival_icao'];
1684
-    				$dicao = $value['airline_icao'];
1685
-    				$find = false;
1686
-    				foreach ($pall as $pvalue) {
1687
-    					if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1688
-    						$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1689
-    						$find = true;
1690
-    						break;
1691
-    					}
1692
-    				}
1693
-    				if ($find === false) {
1694
-    					$pall[] = $value;
1695
-    				}
1696
-    			}
1697
-    			$alldata = $pall;
1698
-                        foreach ($alldata as $number) {
1681
+				//$alldata = array();
1682
+				foreach ($dall as $value) {
1683
+					$icao = $value['airport_arrival_icao'];
1684
+					$dicao = $value['airline_icao'];
1685
+					$find = false;
1686
+					foreach ($pall as $pvalue) {
1687
+						if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) {
1688
+							$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1689
+							$find = true;
1690
+							break;
1691
+						}
1692
+					}
1693
+					if ($find === false) {
1694
+						$pall[] = $value;
1695
+					}
1696
+				}
1697
+				$alldata = $pall;
1698
+						foreach ($alldata as $number) {
1699 1699
 				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']);
1700 1700
 			}
1701 1701
 			if ($globalDebug) echo 'Count all flights by months by airlines...'."\n";
@@ -1728,47 +1728,47 @@  discard block
 block discarded – undo
1728 1728
 			}
1729 1729
 			if ($globalDebug) echo '...Departure'."\n";
1730 1730
 			$pall = $Spotter->getLast7DaysAirportsDepartureByAirlines();
1731
-        		$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();
1732
-    			foreach ($dall as $value) {
1733
-    				$icao = $value['departure_airport_icao'];
1734
-    				$airline = $value['airline_icao'];
1735
-    				$ddate = $value['date'];
1736
-    				$find = false;
1737
-    				foreach ($pall as $pvalue) {
1738
-    					if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) {
1739
-    						$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1740
-    						$find = true;
1741
-    						break;
1742
-    					}
1743
-    				}
1744
-    				if ($find === false) {
1745
-    					$pall[] = $value;
1746
-    				}
1747
-    			}
1748
-    			$alldata = $pall;
1731
+				$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();
1732
+				foreach ($dall as $value) {
1733
+					$icao = $value['departure_airport_icao'];
1734
+					$airline = $value['airline_icao'];
1735
+					$ddate = $value['date'];
1736
+					$find = false;
1737
+					foreach ($pall as $pvalue) {
1738
+						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) {
1739
+							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1740
+							$find = true;
1741
+							break;
1742
+						}
1743
+					}
1744
+					if ($find === false) {
1745
+						$pall[] = $value;
1746
+					}
1747
+				}
1748
+				$alldata = $pall;
1749 1749
 			foreach ($alldata as $number) {
1750 1750
 				$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']);
1751 1751
 			}
1752 1752
 			if ($globalDebug) echo '...Arrival'."\n";
1753 1753
 			$pall = $Spotter->getLast7DaysAirportsArrivalByAirlines();
1754
-        		$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();
1755
-    			foreach ($dall as $value) {
1756
-    				$icao = $value['arrival_airport_icao'];
1757
-    				$airline = $value['airline_icao'];
1758
-    				$ddate = $value['date'];
1759
-    				$find = false;
1760
-    				foreach ($pall as $pvalue) {
1761
-    					if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) {
1762
-    						$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1763
-    						$find = true;
1764
-    						break;
1765
-    					}
1766
-    				}
1767
-    				if ($find === false) {
1768
-    					$pall[] = $value;
1769
-    				}
1770
-    			}
1771
-    			$alldata = $pall;
1754
+				$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();
1755
+				foreach ($dall as $value) {
1756
+					$icao = $value['arrival_airport_icao'];
1757
+					$airline = $value['airline_icao'];
1758
+					$ddate = $value['date'];
1759
+					$find = false;
1760
+					foreach ($pall as $pvalue) {
1761
+						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) {
1762
+							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1763
+							$find = true;
1764
+							break;
1765
+						}
1766
+					}
1767
+					if ($find === false) {
1768
+						$pall[] = $value;
1769
+					}
1770
+				}
1771
+				$alldata = $pall;
1772 1772
 			foreach ($alldata as $number) {
1773 1773
 				$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']);
1774 1774
 			}
@@ -1832,44 +1832,44 @@  discard block
 block discarded – undo
1832 1832
 				}
1833 1833
     			
1834 1834
 				$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day,$filter);
1835
-	       			$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter);
1836
-		        	$alldata = array();
1837
-	    			foreach ($pall as $value) {
1838
-		        		$icao = $value['airport_departure_icao'];
1839
-    					$alldata[$icao] = $value;
1840
-	    			}
1841
-		        	foreach ($dall as $value) {
1842
-	    				$icao = $value['airport_departure_icao'];
1843
-        				if (isset($alldata[$icao])) {
1844
-    						$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1845
-        				} else $alldata[$icao] = $value;
1846
-				}
1847
-	    			$count = array();
1848
-    				foreach ($alldata as $key => $row) {
1849
-    					$count[$key] = $row['airport_departure_icao_count'];
1850
-    				}
1835
+		   			$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter);
1836
+					$alldata = array();
1837
+					foreach ($pall as $value) {
1838
+						$icao = $value['airport_departure_icao'];
1839
+						$alldata[$icao] = $value;
1840
+					}
1841
+					foreach ($dall as $value) {
1842
+						$icao = $value['airport_departure_icao'];
1843
+						if (isset($alldata[$icao])) {
1844
+							$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1845
+						} else $alldata[$icao] = $value;
1846
+				}
1847
+					$count = array();
1848
+					foreach ($alldata as $key => $row) {
1849
+						$count[$key] = $row['airport_departure_icao_count'];
1850
+					}
1851 1851
 				array_multisort($count,SORT_DESC,$alldata);
1852 1852
 				foreach ($alldata as $number) {
1853
-    					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);
1853
+						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);
1854 1854
 				}
1855 1855
 				$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day,$filter);
1856
-    				$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,$filter);
1856
+					$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,$filter);
1857 1857
 				$alldata = array();
1858
-    				foreach ($pall as $value) {
1859
-		        		$icao = $value['airport_arrival_icao'];
1860
-    					$alldata[$icao] = $value;
1861
-	    			}
1862
-		        	foreach ($dall as $value) {
1863
-	    				$icao = $value['airport_arrival_icao'];
1864
-        				if (isset($alldata[$icao])) {
1865
-        					$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1866
-		        		} else $alldata[$icao] = $value;
1867
-	    			}
1868
-        			$count = array();
1869
-        			foreach ($alldata as $key => $row) {
1870
-    					$count[$key] = $row['airport_arrival_icao_count'];
1871
-		        	}
1872
-        			array_multisort($count,SORT_DESC,$alldata);
1858
+					foreach ($pall as $value) {
1859
+						$icao = $value['airport_arrival_icao'];
1860
+						$alldata[$icao] = $value;
1861
+					}
1862
+					foreach ($dall as $value) {
1863
+						$icao = $value['airport_arrival_icao'];
1864
+						if (isset($alldata[$icao])) {
1865
+							$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1866
+						} else $alldata[$icao] = $value;
1867
+					}
1868
+					$count = array();
1869
+					foreach ($alldata as $key => $row) {
1870
+						$count[$key] = $row['airport_arrival_icao_count'];
1871
+					}
1872
+					array_multisort($count,SORT_DESC,$alldata);
1873 1873
 				foreach ($alldata as $number) {
1874 1874
 					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);
1875 1875
 				}
@@ -1898,45 +1898,45 @@  discard block
 block discarded – undo
1898 1898
 				}
1899 1899
 				echo '...Departure'."\n";
1900 1900
 				$pall = $Spotter->getLast7DaysAirportsDeparture('',$filter);
1901
-        			$dall = $Spotter->getLast7DaysDetectedAirportsDeparture('',$filter);
1901
+					$dall = $Spotter->getLast7DaysDetectedAirportsDeparture('',$filter);
1902 1902
 				foreach ($dall as $value) {
1903
-    					$icao = $value['departure_airport_icao'];
1904
-    					$ddate = $value['date'];
1905
-    					$find = false;
1906
-    					foreach ($pall as $pvalue) {
1907
-    						if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1908
-    							$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1909
-	    						$find = true;
1910
-    							break;
1911
-    						}
1912
-    					}
1913
-    					if ($find === false) {
1914
-    						$pall[] = $value;
1915
-	    				}
1916
-    				}
1917
-	    			$alldata = $pall;
1903
+						$icao = $value['departure_airport_icao'];
1904
+						$ddate = $value['date'];
1905
+						$find = false;
1906
+						foreach ($pall as $pvalue) {
1907
+							if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1908
+								$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count'];
1909
+								$find = true;
1910
+								break;
1911
+							}
1912
+						}
1913
+						if ($find === false) {
1914
+							$pall[] = $value;
1915
+						}
1916
+					}
1917
+					$alldata = $pall;
1918 1918
 				foreach ($alldata as $number) {
1919 1919
 					$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);
1920 1920
 				}
1921 1921
 				echo '...Arrival'."\n";
1922 1922
 				$pall = $Spotter->getLast7DaysAirportsArrival('',$filter);
1923
-    				$dall = $Spotter->getLast7DaysDetectedAirportsArrival('',$filter);
1923
+					$dall = $Spotter->getLast7DaysDetectedAirportsArrival('',$filter);
1924 1924
 				foreach ($dall as $value) {
1925 1925
 					$icao = $value['arrival_airport_icao'];
1926 1926
 					$ddate = $value['date'];
1927
-    					$find = false;
1927
+						$find = false;
1928 1928
 					foreach ($pall as $pvalue) {
1929
-    						if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1930
-    							$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1931
-    							$find = true;
1932
-    							break;
1933
-	    					}
1934
-    					}
1935
-    					if ($find === false) {
1936
-    						$pall[] = $value;
1937
-	    				}
1938
-    				}
1939
-    				$alldata = $pall;
1929
+							if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) {
1930
+								$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count'];
1931
+								$find = true;
1932
+								break;
1933
+							}
1934
+						}
1935
+						if ($find === false) {
1936
+							$pall[] = $value;
1937
+						}
1938
+					}
1939
+					$alldata = $pall;
1940 1940
 				foreach ($alldata as $number) {
1941 1941
 					$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);
1942 1942
 				}
Please login to merge, or discard this patch.