Completed
Push — master ( b8bc3a...1cdde9 )
by Yannick
13:28
created
scripts/daemon-spotter.php 1 patch
Indentation   +695 added lines, -695 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 // Check if schema is at latest version
20 20
 $Connection = new Connection();
21 21
 if ($Connection->latest() === false) {
22
-    echo "You MUST update to latest schema. Run install/index.php";
23
-    exit();
22
+	echo "You MUST update to latest schema. Run install/index.php";
23
+	exit();
24 24
 }
25 25
 if (PHP_SAPI != 'cli') {
26
-    echo "This script MUST be called from console, not a web browser.";
26
+	echo "This script MUST be called from console, not a web browser.";
27 27
 //    exit();
28 28
 }
29 29
 
30 30
 // This is to be compatible with old version of settings.php
31 31
 if (!isset($globalSources)) {
32
-    if (isset($globalSBS1Hosts)) {
33
-        //$hosts = $globalSBS1Hosts;
34
-        foreach ($globalSBS1Hosts as $host) {
35
-	    $globalSources[] = array('host' => $host);
36
-    	}
37
-    } else {
38
-        if (!isset($globalSBS1Host)) {
39
-	    echo '$globalSources MUST be defined !';
40
-	    die;
32
+	if (isset($globalSBS1Hosts)) {
33
+		//$hosts = $globalSBS1Hosts;
34
+		foreach ($globalSBS1Hosts as $host) {
35
+		$globalSources[] = array('host' => $host);
36
+		}
37
+	} else {
38
+		if (!isset($globalSBS1Host)) {
39
+		echo '$globalSources MUST be defined !';
40
+		die;
41 41
 	}
42 42
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
43 43
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
44
-    }
44
+	}
45 45
 }
46 46
 
47 47
 $options = getopt('s::',array('source::','server','idsource::'));
48 48
 //if (isset($options['s'])) $hosts = array($options['s']);
49 49
 //elseif (isset($options['source'])) $hosts = array($options['source']);
50 50
 if (isset($options['s'])) {
51
-    $globalSources = array();
52
-    $globalSources[] = array('host' => $options['s']);
51
+	$globalSources = array();
52
+	$globalSources[] = array('host' => $options['s']);
53 53
 } elseif (isset($options['source'])) {
54
-    $globalSources = array();
55
-    $globalSources[] = array('host' => $options['source']);
54
+	$globalSources = array();
55
+	$globalSources[] = array('host' => $options['source']);
56 56
 }
57 57
 if (isset($options['server'])) $globalServer = TRUE;
58 58
 if (isset($options['idsource'])) $id_source = $options['idsource'];
59 59
 else $id_source = 1;
60 60
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
62
-    $SI=new SpotterServer();
61
+	if ($globalDebug) echo "Using Server Mode\n";
62
+	$SI=new SpotterServer();
63 63
 } else $SI=new SpotterImport($Connection->db);
64 64
 //$APRS=new APRS($Connection->db);
65 65
 $SBS=new SBS();
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 //$servertz = system('date +%Z');
70 70
 // signal handler - playing nice with sockets and dump1090
71 71
 if (function_exists('pcntl_fork')) {
72
-    pcntl_signal(SIGINT,  function() {
73
-        global $sockets;
74
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
-        die("Bye!\n");
76
-    });
77
-    pcntl_signal_dispatch();
72
+	pcntl_signal(SIGINT,  function() {
73
+		global $sockets;
74
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
75
+		die("Bye!\n");
76
+	});
77
+	pcntl_signal_dispatch();
78 78
 }
79 79
 
80 80
 // let's try and connect
@@ -84,162 +84,162 @@  discard block
 block discarded – undo
84 84
 $reset = 0;
85 85
 
86 86
 function create_socket($host, $port, &$errno, &$errstr) {
87
-    $ip = gethostbyname($host);
88
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
89
-    $r = @socket_connect($s, $ip, $port);
90
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
-        return $s;
93
-    }
94
-    $errno = socket_last_error($s);
95
-    $errstr = socket_strerror($errno);
96
-    socket_close($s);
97
-    return false;
87
+	$ip = gethostbyname($host);
88
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
89
+	$r = @socket_connect($s, $ip, $port);
90
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
91
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
92
+		return $s;
93
+	}
94
+	$errno = socket_last_error($s);
95
+	$errstr = socket_strerror($errno);
96
+	socket_close($s);
97
+	return false;
98 98
 }
99 99
 
100 100
 function create_socket_udp($host, $port, &$errno, &$errstr) {
101
-    echo "Create an UDP socket...\n";
102
-    $ip = gethostbyname($host);
103
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
-    $r = @socket_bind($s, $ip, $port);
105
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
-        return $s;
107
-    }
108
-    $errno = socket_last_error($s);
109
-    $errstr = socket_strerror($errno);
110
-    socket_close($s);
111
-    return false;
101
+	echo "Create an UDP socket...\n";
102
+	$ip = gethostbyname($host);
103
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
104
+	$r = @socket_bind($s, $ip, $port);
105
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
106
+		return $s;
107
+	}
108
+	$errno = socket_last_error($s);
109
+	$errstr = socket_strerror($errno);
110
+	socket_close($s);
111
+	return false;
112 112
 }
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
-        	//$formats[$id] = 'radarvirtueljson';
146
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
147
-        	//$last_exec['radarvirtueljson'] = 0;
148
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
-        	    exit(0);
152
-        	}
153
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
-        	//$formats[$id] = 'planeupdatefaa';
155
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
156
-        	//$last_exec['planeupdatefaa'] = 0;
157
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
-        	    exit(0);
161
-        	}
162
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
-        	//$formats[$id] = 'phpvmacars';
164
-        	$globalSources[$id]['format'] = 'phpvmacars';
165
-        	//$last_exec['phpvmacars'] = 0;
166
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
168
-        	//$formats[$id] = 'phpvmacars';
169
-        	$globalSources[$id]['format'] = 'vam';
170
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
-            } else if (preg_match('/whazzup/i',$host)) {
172
-        	//$formats[$id] = 'whazzup';
173
-        	$globalSources[$id]['format'] = 'whazzup';
174
-        	//$last_exec['whazzup'] = 0;
175
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
-            } else if (preg_match('/recentpireps/i',$host)) {
177
-        	//$formats[$id] = 'pirepsjson';
178
-        	$globalSources[$id]['format'] = 'pirepsjson';
179
-        	//$last_exec['pirepsjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
-        	//$formats[$id] = 'fr24json';
183
-        	$globalSources[$id]['format'] = 'fr24json';
184
-        	//$last_exec['fr24json'] = 0;
185
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
-        	    exit(0);
189
-        	}
190
-            //} else if (preg_match('/10001/',$host)) {
191
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
-        	//$formats[$id] = 'tsv';
193
-        	$globalSources[$id]['format'] = 'tsv';
194
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
-            }
196
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
-	    $hostport = explode(':',$host);
200
-	    if (isset($hostport[1])) {
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
145
+			//$formats[$id] = 'radarvirtueljson';
146
+			$globalSources[$id]['format'] = 'radarvirtueljson';
147
+			//$last_exec['radarvirtueljson'] = 0;
148
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
149
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
150
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
151
+				exit(0);
152
+			}
153
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
154
+			//$formats[$id] = 'planeupdatefaa';
155
+			$globalSources[$id]['format'] = 'planeupdatefaa';
156
+			//$last_exec['planeupdatefaa'] = 0;
157
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
158
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
159
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
160
+				exit(0);
161
+			}
162
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
163
+			//$formats[$id] = 'phpvmacars';
164
+			$globalSources[$id]['format'] = 'phpvmacars';
165
+			//$last_exec['phpvmacars'] = 0;
166
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
167
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
168
+			//$formats[$id] = 'phpvmacars';
169
+			$globalSources[$id]['format'] = 'vam';
170
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
171
+			} else if (preg_match('/whazzup/i',$host)) {
172
+			//$formats[$id] = 'whazzup';
173
+			$globalSources[$id]['format'] = 'whazzup';
174
+			//$last_exec['whazzup'] = 0;
175
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
176
+			} else if (preg_match('/recentpireps/i',$host)) {
177
+			//$formats[$id] = 'pirepsjson';
178
+			$globalSources[$id]['format'] = 'pirepsjson';
179
+			//$last_exec['pirepsjson'] = 0;
180
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
181
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
182
+			//$formats[$id] = 'fr24json';
183
+			$globalSources[$id]['format'] = 'fr24json';
184
+			//$last_exec['fr24json'] = 0;
185
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
186
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
187
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
188
+				exit(0);
189
+			}
190
+			//} else if (preg_match('/10001/',$host)) {
191
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
192
+			//$formats[$id] = 'tsv';
193
+			$globalSources[$id]['format'] = 'tsv';
194
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
195
+			}
196
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
197
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
199
+		$hostport = explode(':',$host);
200
+		if (isset($hostport[1])) {
201 201
 		$port = $hostport[1];
202 202
 		$hostn = $hostport[0];
203
-	    } else {
203
+		} else {
204 204
 		$port = $globalSources[$id]['port'];
205 205
 		$hostn = $globalSources[$id]['host'];
206
-	    }
207
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
-        	$s = create_socket($hostn,$port, $errno, $errstr);
209
-    	    } else {
210
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
-	    }
212
-	    if ($s) {
213
-    	        $sockets[$id] = $s;
214
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
-		    if (preg_match('/aprs/',$hostn)) {
206
+		}
207
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
208
+			$s = create_socket($hostn,$port, $errno, $errstr);
209
+			} else {
210
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
211
+		}
212
+		if ($s) {
213
+				$sockets[$id] = $s;
214
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
215
+			if (preg_match('/aprs/',$hostn)) {
216 216
 			//$formats[$id] = 'aprs';
217 217
 			$globalSources[$id]['format'] = 'aprs';
218 218
 			//$aprs_connect = 0;
219 219
 			//$use_aprs = true;
220
-    		    } elseif ($port == '10001') {
221
-        		//$formats[$id] = 'tsv';
222
-        		$globalSources[$id]['format'] = 'tsv';
223
-		    } elseif ($port == '30002') {
224
-        		//$formats[$id] = 'raw';
225
-        		$globalSources[$id]['format'] = 'raw';
226
-		    } elseif ($port == '5001') {
227
-        		//$formats[$id] = 'raw';
228
-        		$globalSources[$id]['format'] = 'flightgearmp';
229
-		    } elseif ($port == '30005') {
220
+				} elseif ($port == '10001') {
221
+				//$formats[$id] = 'tsv';
222
+				$globalSources[$id]['format'] = 'tsv';
223
+			} elseif ($port == '30002') {
224
+				//$formats[$id] = 'raw';
225
+				$globalSources[$id]['format'] = 'raw';
226
+			} elseif ($port == '5001') {
227
+				//$formats[$id] = 'raw';
228
+				$globalSources[$id]['format'] = 'flightgearmp';
229
+			} elseif ($port == '30005') {
230 230
 			// Not yet supported
231
-        		//$formats[$id] = 'beast';
232
-        		$globalSources[$id]['format'] = 'beast';
233
-		    //} else $formats[$id] = 'sbs';
234
-		    } else $globalSources[$id]['format'] = 'sbs';
235
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
231
+				//$formats[$id] = 'beast';
232
+				$globalSources[$id]['format'] = 'beast';
233
+			//} else $formats[$id] = 'sbs';
234
+			} else $globalSources[$id]['format'] = 'sbs';
235
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
236 236
 		}
237 237
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
238
-            } else {
238
+			} else {
239 239
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
240
-    	    }
241
-        }
242
-    }
240
+			}
241
+		}
242
+	}
243 243
 }
244 244
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
245 245
 
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	die;
267 267
 }
268 268
 foreach ($globalSources as $key => $source) {
269
-    if (!isset($source['format'])) {
270
-        $globalSources[$key]['format'] = 'auto';
271
-    }
269
+	if (!isset($source['format'])) {
270
+		$globalSources[$key]['format'] = 'auto';
271
+	}
272 272
 }
273 273
 connect_all($globalSources);
274 274
 foreach ($globalSources as $key => $source) {
275
-    if (isset($source['format']) && $source['format'] == 'aprs') {
275
+	if (isset($source['format']) && $source['format'] == 'aprs') {
276 276
 	$aprs_connect = 0;
277 277
 	$use_aprs = true;
278 278
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
279 279
 	break;
280
-    }
280
+	}
281 281
 }
282 282
 
283 283
 if ($use_aprs) {
@@ -316,70 +316,70 @@  discard block
 block discarded – undo
316 316
 
317 317
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
318 318
 while ($i > 0) {
319
-    if (!$globalDaemon) $i = $endtime-time();
320
-    // Delete old ATC
321
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
319
+	if (!$globalDaemon) $i = $endtime-time();
320
+	// Delete old ATC
321
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
322 322
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
323
-        $ATC->deleteOldATC();
324
-    }
323
+		$ATC->deleteOldATC();
324
+	}
325 325
     
326
-    if (count($last_exec) > 0) {
326
+	if (count($last_exec) > 0) {
327 327
 	$max = $globalMinFetch;
328 328
 	foreach ($last_exec as $last) {
329
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
329
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
330 330
 	}
331 331
 	if ($max != $globalMinFetch) {
332
-	    if ($globalDebug) echo 'Sleeping...'."\n";
333
-	    sleep($globalMinFetch-$max+2);
332
+		if ($globalDebug) echo 'Sleeping...'."\n";
333
+		sleep($globalMinFetch-$max+2);
334
+	}
334 335
 	}
335
-    }
336 336
 
337 337
     
338
-    //foreach ($formats as $id => $value) {
339
-    foreach ($globalSources as $id => $value) {
338
+	//foreach ($formats as $id => $value) {
339
+	foreach ($globalSources as $id => $value) {
340 340
 	date_default_timezone_set('UTC');
341 341
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
342 342
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
343
-	    //$buffer = $Common->getData($hosts[$id]);
344
-	    $buffer = $Common->getData($value['host']);
345
-	    if ($buffer != '') $reset = 0;
346
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
-	    $buffer = explode('\n',$buffer);
348
-	    foreach ($buffer as $line) {
349
-    		if ($line != '' && count($line) > 7) {
350
-    		    $line = explode(',', $line);
351
-	            $data = array();
352
-	            $data['hex'] = $line[1]; // hex
353
-	            $data['ident'] = $line[2]; // ident
354
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
-	            $data['verticalrate'] = ''; // vertical rate
360
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
-	            $data['emergency'] = ''; // emergency
362
-		    $data['datetime'] = date('Y-m-d H:i:s');
363
-		    $data['format_source'] = 'deltadbtxt';
364
-    		    $data['id_source'] = $id_source;
365
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
-    		    $SI->add($data);
368
-		    unset($data);
369
-    		}
370
-    	    }
371
-    	    $last_exec[$id]['last'] = time();
343
+		//$buffer = $Common->getData($hosts[$id]);
344
+		$buffer = $Common->getData($value['host']);
345
+		if ($buffer != '') $reset = 0;
346
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
347
+		$buffer = explode('\n',$buffer);
348
+		foreach ($buffer as $line) {
349
+			if ($line != '' && count($line) > 7) {
350
+				$line = explode(',', $line);
351
+				$data = array();
352
+				$data['hex'] = $line[1]; // hex
353
+				$data['ident'] = $line[2]; // ident
354
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
355
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
356
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
357
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
358
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
359
+				$data['verticalrate'] = ''; // vertical rate
360
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
361
+				$data['emergency'] = ''; // emergency
362
+			$data['datetime'] = date('Y-m-d H:i:s');
363
+			$data['format_source'] = 'deltadbtxt';
364
+				$data['id_source'] = $id_source;
365
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
366
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
367
+				$SI->add($data);
368
+			unset($data);
369
+			}
370
+			}
371
+			$last_exec[$id]['last'] = time();
372 372
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
373 373
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
374
-	    //$buffer = $Common->getData($hosts[$id]);
375
-	    $buffer = $Common->getData($value['host']);
376
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
-	    $buffer = explode('\n',$buffer);
378
-	    $reset = 0;
379
-	    foreach ($buffer as $line) {
380
-    		if ($line != '') {
381
-    		    $line = explode(':', $line);
382
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
374
+		//$buffer = $Common->getData($hosts[$id]);
375
+		$buffer = $Common->getData($value['host']);
376
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
377
+		$buffer = explode('\n',$buffer);
378
+		$reset = 0;
379
+		foreach ($buffer as $line) {
380
+			if ($line != '') {
381
+				$line = explode(':', $line);
382
+				if (count($line) > 30 && $line[0] != 'callsign') {
383 383
 			$data = array();
384 384
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
385 385
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -392,36 +392,36 @@  discard block
 block discarded – undo
392 392
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
393 393
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
394 394
 			$data['latitude'] = $line[5]; // lat
395
-	        	$data['longitude'] = $line[6]; // long
396
-	        	$data['verticalrate'] = ''; // vertical rate
397
-	        	$data['squawk'] = ''; // squawk
398
-	        	$data['emergency'] = ''; // emergency
399
-	        	$data['waypoints'] = $line[30];
395
+				$data['longitude'] = $line[6]; // long
396
+				$data['verticalrate'] = ''; // vertical rate
397
+				$data['squawk'] = ''; // squawk
398
+				$data['emergency'] = ''; // emergency
399
+				$data['waypoints'] = $line[30];
400 400
 			$data['datetime'] = date('Y-m-d H:i:s');
401 401
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
402 402
 			//if (isset($line[37])) $data['last_update'] = $line[37];
403
-		        $data['departure_airport_icao'] = $line[11];
404
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
-		        $data['arrival_airport_icao'] = $line[13];
403
+				$data['departure_airport_icao'] = $line[11];
404
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
405
+				$data['arrival_airport_icao'] = $line[13];
406 406
 			$data['frequency'] = $line[4];
407 407
 			$data['type'] = $line[18];
408 408
 			$data['range'] = $line[19];
409 409
 			if (isset($line[35])) $data['info'] = $line[35];
410
-    			$data['id_source'] = $id_source;
411
-	    		//$data['arrival_airport_time'] = ;
412
-	    		if ($line[9] != '') {
413
-	    		    $aircraft_data = explode('/',$line[9]);
414
-	    		    if (isset($aircraft_data[1])) {
415
-	    			$data['aircraft_icao'] = $aircraft_data[1];
416
-	    		    }
417
-        		}
418
-	    		/*
410
+				$data['id_source'] = $id_source;
411
+				//$data['arrival_airport_time'] = ;
412
+				if ($line[9] != '') {
413
+					$aircraft_data = explode('/',$line[9]);
414
+					if (isset($aircraft_data[1])) {
415
+					$data['aircraft_icao'] = $aircraft_data[1];
416
+					}
417
+				}
418
+				/*
419 419
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
420 420
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
421 421
 	    		*/
422
-	    		$data['format_source'] = $value['format'];
422
+				$data['format_source'] = $value['format'];
423 423
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
424
-    			if ($line[3] == 'PILOT') $SI->add($data);
424
+				if ($line[3] == 'PILOT') $SI->add($data);
425 425
 			elseif ($line[3] == 'ATC') {
426 426
 				//print_r($data);
427 427
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -439,247 +439,247 @@  discard block
 block discarded – undo
439 439
 				if (!isset($data['source_name'])) $data['source_name'] = '';
440 440
 				echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
441 441
 			}
442
-    			unset($data);
443
-    		    }
444
-    		}
445
-    	    }
446
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
447
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
448
-    	    $last_exec[$id]['last'] = time();
449
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
450
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
451
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
452
-	    if ($buffer != '') {
453
-	    $all_data = json_decode($buffer,true);
454
-	    if (isset($all_data['acList'])) {
442
+				unset($data);
443
+				}
444
+			}
445
+			}
446
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
447
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
448
+			$last_exec[$id]['last'] = time();
449
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
450
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
451
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
452
+		if ($buffer != '') {
453
+		$all_data = json_decode($buffer,true);
454
+		if (isset($all_data['acList'])) {
455 455
 		$reset = 0;
456 456
 		foreach ($all_data['acList'] as $line) {
457
-		    $data = array();
458
-		    $data['hex'] = $line['Icao']; // hex
459
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
460
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
461
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
462
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
463
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
464
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
465
-		    //$data['verticalrate'] = $line['']; // verticale rate
466
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
467
-		    $data['emergency'] = ''; // emergency
468
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
469
-		    /*
457
+			$data = array();
458
+			$data['hex'] = $line['Icao']; // hex
459
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
460
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
461
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
462
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
463
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
464
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
465
+			//$data['verticalrate'] = $line['']; // verticale rate
466
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
467
+			$data['emergency'] = ''; // emergency
468
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
469
+			/*
470 470
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
471 471
 		    else $data['datetime'] = date('Y-m-d H:i:s');
472 472
 		    */
473
-		    $data['datetime'] = date('Y-m-d H:i:s');
474
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
475
-	    	    $data['format_source'] = 'aircraftlistjson';
476
-		    $data['id_source'] = $id_source;
477
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
-		    if (isset($data['datetime'])) $SI->add($data);
479
-		    unset($data);
473
+			$data['datetime'] = date('Y-m-d H:i:s');
474
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
475
+				$data['format_source'] = 'aircraftlistjson';
476
+			$data['id_source'] = $id_source;
477
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
478
+			if (isset($data['datetime'])) $SI->add($data);
479
+			unset($data);
480 480
 		}
481
-	    } else {
481
+		} else {
482 482
 		$reset = 0;
483 483
 		foreach ($all_data as $line) {
484
-		    $data = array();
485
-		    $data['hex'] = $line['hex']; // hex
486
-		    $data['ident'] = $line['flight']; // ident
487
-		    $data['altitude'] = $line['altitude']; // altitude
488
-		    $data['speed'] = $line['speed']; // speed
489
-		    $data['heading'] = $line['track']; // heading
490
-		    $data['latitude'] = $line['lat']; // lat
491
-		    $data['longitude'] = $line['lon']; // long
492
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
493
-		    $data['squawk'] = $line['squawk']; // squawk
494
-		    $data['emergency'] = ''; // emergency
495
-		    $data['datetime'] = date('Y-m-d H:i:s');
496
-	    	    $data['format_source'] = 'aircraftlistjson';
497
-    		    $data['id_source'] = $id_source;
498
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
499
-		    $SI->add($data);
500
-		    unset($data);
484
+			$data = array();
485
+			$data['hex'] = $line['hex']; // hex
486
+			$data['ident'] = $line['flight']; // ident
487
+			$data['altitude'] = $line['altitude']; // altitude
488
+			$data['speed'] = $line['speed']; // speed
489
+			$data['heading'] = $line['track']; // heading
490
+			$data['latitude'] = $line['lat']; // lat
491
+			$data['longitude'] = $line['lon']; // long
492
+			$data['verticalrate'] = $line['vrt']; // verticale rate
493
+			$data['squawk'] = $line['squawk']; // squawk
494
+			$data['emergency'] = ''; // emergency
495
+			$data['datetime'] = date('Y-m-d H:i:s');
496
+				$data['format_source'] = 'aircraftlistjson';
497
+				$data['id_source'] = $id_source;
498
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
499
+			$SI->add($data);
500
+			unset($data);
501
+		}
501 502
 		}
502
-	    }
503
-	    }
504
-    	    //$last_exec['aircraftlistjson'] = time();
505
-    	    $last_exec[$id]['last'] = time();
506
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
507
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
508
-	    $buffer = $Common->getData($value['host']);
509
-	    $all_data = json_decode($buffer,true);
510
-	    if (isset($all_data['planes'])) {
503
+		}
504
+			//$last_exec['aircraftlistjson'] = time();
505
+			$last_exec[$id]['last'] = time();
506
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
507
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
508
+		$buffer = $Common->getData($value['host']);
509
+		$all_data = json_decode($buffer,true);
510
+		if (isset($all_data['planes'])) {
511 511
 		$reset = 0;
512 512
 		foreach ($all_data['planes'] as $key => $line) {
513
-		    $data = array();
514
-		    $data['hex'] = $key; // hex
515
-		    $data['ident'] = $line[3]; // ident
516
-		    $data['altitude'] = $line[6]; // altitude
517
-		    $data['speed'] = $line[8]; // speed
518
-		    $data['heading'] = $line[7]; // heading
519
-		    $data['latitude'] = $line[4]; // lat
520
-		    $data['longitude'] = $line[5]; // long
521
-		    //$data['verticalrate'] = $line[]; // verticale rate
522
-		    $data['squawk'] = $line[10]; // squawk
523
-		    $data['emergency'] = ''; // emergency
524
-		    $data['registration'] = $line[2];
525
-		    $data['aircraft_icao'] = $line[0];
526
-		    $deparr = explode('-',$line[1]);
527
-		    if (count($deparr) == 2) {
513
+			$data = array();
514
+			$data['hex'] = $key; // hex
515
+			$data['ident'] = $line[3]; // ident
516
+			$data['altitude'] = $line[6]; // altitude
517
+			$data['speed'] = $line[8]; // speed
518
+			$data['heading'] = $line[7]; // heading
519
+			$data['latitude'] = $line[4]; // lat
520
+			$data['longitude'] = $line[5]; // long
521
+			//$data['verticalrate'] = $line[]; // verticale rate
522
+			$data['squawk'] = $line[10]; // squawk
523
+			$data['emergency'] = ''; // emergency
524
+			$data['registration'] = $line[2];
525
+			$data['aircraft_icao'] = $line[0];
526
+			$deparr = explode('-',$line[1]);
527
+			if (count($deparr) == 2) {
528 528
 			$data['departure_airport_icao'] = $deparr[0];
529 529
 			$data['arrival_airport_icao'] = $deparr[1];
530
-		    }
531
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
-	    	    $data['format_source'] = 'planeupdatefaa';
533
-    		    $data['id_source'] = $id_source;
534
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
535
-		    $SI->add($data);
536
-		    unset($data);
530
+			}
531
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
532
+				$data['format_source'] = 'planeupdatefaa';
533
+				$data['id_source'] = $id_source;
534
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
535
+			$SI->add($data);
536
+			unset($data);
537
+		}
537 538
 		}
538
-	    }
539
-    	    //$last_exec['planeupdatefaa'] = time();
540
-    	    $last_exec[$id]['last'] = time();
541
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
542
-	    $buffer = $Common->getData($value['host']);
543
-	    $all_data = json_decode($buffer,true);
544
-	    if (isset($all_data['states'])) {
539
+			//$last_exec['planeupdatefaa'] = time();
540
+			$last_exec[$id]['last'] = time();
541
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
542
+		$buffer = $Common->getData($value['host']);
543
+		$all_data = json_decode($buffer,true);
544
+		if (isset($all_data['states'])) {
545 545
 		$reset = 0;
546 546
 		foreach ($all_data['states'] as $key => $line) {
547
-		    $data = array();
548
-		    $data['hex'] = $line[0]; // hex
549
-		    $data['ident'] = trim($line[1]); // ident
550
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
551
-		    $data['speed'] = round($line[9]*1.94384); // speed
552
-		    $data['heading'] = round($line[10]); // heading
553
-		    $data['latitude'] = $line[5]; // lat
554
-		    $data['longitude'] = $line[6]; // long
555
-		    $data['verticalrate'] = $line[11]; // verticale rate
556
-		    //$data['squawk'] = $line[10]; // squawk
557
-		    //$data['emergency'] = ''; // emergency
558
-		    //$data['registration'] = $line[2];
559
-		    //$data['aircraft_icao'] = $line[0];
560
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
-	    	    $data['format_source'] = 'opensky';
562
-    		    $data['id_source'] = $id_source;
563
-		    $SI->add($data);
564
-		    unset($data);
547
+			$data = array();
548
+			$data['hex'] = $line[0]; // hex
549
+			$data['ident'] = trim($line[1]); // ident
550
+			$data['altitude'] = round($line[7]*3.28084); // altitude
551
+			$data['speed'] = round($line[9]*1.94384); // speed
552
+			$data['heading'] = round($line[10]); // heading
553
+			$data['latitude'] = $line[5]; // lat
554
+			$data['longitude'] = $line[6]; // long
555
+			$data['verticalrate'] = $line[11]; // verticale rate
556
+			//$data['squawk'] = $line[10]; // squawk
557
+			//$data['emergency'] = ''; // emergency
558
+			//$data['registration'] = $line[2];
559
+			//$data['aircraft_icao'] = $line[0];
560
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
561
+				$data['format_source'] = 'opensky';
562
+				$data['id_source'] = $id_source;
563
+			$SI->add($data);
564
+			unset($data);
565
+		}
565 566
 		}
566
-	    }
567
-    	    //$last_exec['planeupdatefaa'] = time();
568
-    	    $last_exec[$id]['last'] = time();
569
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
570
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
571
-	    //$buffer = $Common->getData($hosts[$id]);
572
-	    $buffer = $Common->getData($value['host']);
573
-	    $all_data = json_decode($buffer,true);
574
-	    if (!empty($all_data)) $reset = 0;
575
-	    foreach ($all_data as $key => $line) {
567
+			//$last_exec['planeupdatefaa'] = time();
568
+			$last_exec[$id]['last'] = time();
569
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
570
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
571
+		//$buffer = $Common->getData($hosts[$id]);
572
+		$buffer = $Common->getData($value['host']);
573
+		$all_data = json_decode($buffer,true);
574
+		if (!empty($all_data)) $reset = 0;
575
+		foreach ($all_data as $key => $line) {
576 576
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
577
-		    $data = array();
578
-		    $data['hex'] = $line[0];
579
-		    $data['ident'] = $line[16]; //$line[13]
580
-	    	    $data['altitude'] = $line[4]; // altitude
581
-	    	    $data['speed'] = $line[5]; // speed
582
-	    	    $data['heading'] = $line[3]; // heading
583
-	    	    $data['latitude'] = $line[1]; // lat
584
-	    	    $data['longitude'] = $line[2]; // long
585
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
586
-	    	    $data['squawk'] = $line[6]; // squawk
587
-	    	    $data['aircraft_icao'] = $line[8];
588
-	    	    $data['registration'] = $line[9];
589
-		    $data['departure_airport_iata'] = $line[11];
590
-		    $data['arrival_airport_iata'] = $line[12];
591
-	    	    $data['emergency'] = ''; // emergency
592
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
593
-	    	    $data['format_source'] = 'fr24json';
594
-    		    $data['id_source'] = $id_source;
595
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
596
-		    $SI->add($data);
597
-		    unset($data);
577
+			$data = array();
578
+			$data['hex'] = $line[0];
579
+			$data['ident'] = $line[16]; //$line[13]
580
+				$data['altitude'] = $line[4]; // altitude
581
+				$data['speed'] = $line[5]; // speed
582
+				$data['heading'] = $line[3]; // heading
583
+				$data['latitude'] = $line[1]; // lat
584
+				$data['longitude'] = $line[2]; // long
585
+				$data['verticalrate'] = $line[15]; // verticale rate
586
+				$data['squawk'] = $line[6]; // squawk
587
+				$data['aircraft_icao'] = $line[8];
588
+				$data['registration'] = $line[9];
589
+			$data['departure_airport_iata'] = $line[11];
590
+			$data['arrival_airport_iata'] = $line[12];
591
+				$data['emergency'] = ''; // emergency
592
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
593
+				$data['format_source'] = 'fr24json';
594
+				$data['id_source'] = $id_source;
595
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
596
+			$SI->add($data);
597
+			unset($data);
598
+		}
598 599
 		}
599
-	    }
600
-    	    //$last_exec['fr24json'] = time();
601
-    	    $last_exec[$id]['last'] = time();
602
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
603
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
604
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
605
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
606
-	    //echo $buffer;
607
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
608
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
609
-	    $all_data = json_decode($buffer,true);
610
-	    if (json_last_error() != JSON_ERROR_NONE) {
600
+			//$last_exec['fr24json'] = time();
601
+			$last_exec[$id]['last'] = time();
602
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
603
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
604
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
605
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
606
+		//echo $buffer;
607
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
608
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
609
+		$all_data = json_decode($buffer,true);
610
+		if (json_last_error() != JSON_ERROR_NONE) {
611 611
 		die(json_last_error_msg());
612
-	    }
613
-	    if (isset($all_data['mrkrs'])) {
612
+		}
613
+		if (isset($all_data['mrkrs'])) {
614 614
 		$reset = 0;
615 615
 		foreach ($all_data['mrkrs'] as $key => $line) {
616
-		    if (isset($line['inf'])) {
616
+			if (isset($line['inf'])) {
617 617
 			$data = array();
618 618
 			$data['hex'] = $line['inf']['ia'];
619 619
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
620
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
621
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
622
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
623
-	    		$data['latitude'] = $line['pt'][0]; // lat
624
-	    		$data['longitude'] = $line['pt'][1]; // long
625
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
626
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
627
-	    		//$data['aircraft_icao'] = $line[8];
628
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
620
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
621
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
622
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
623
+				$data['latitude'] = $line['pt'][0]; // lat
624
+				$data['longitude'] = $line['pt'][1]; // long
625
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
626
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
627
+				//$data['aircraft_icao'] = $line[8];
628
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
629 629
 			//$data['departure_airport_iata'] = $line[11];
630 630
 			//$data['arrival_airport_iata'] = $line[12];
631
-	    		//$data['emergency'] = ''; // emergency
631
+				//$data['emergency'] = ''; // emergency
632 632
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
633
-	    		$data['format_source'] = 'radarvirtueljson';
634
-    			$data['id_source'] = $id_source;
633
+				$data['format_source'] = 'radarvirtueljson';
634
+				$data['id_source'] = $id_source;
635 635
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
636 636
 			$SI->add($data);
637 637
 			unset($data);
638
-		    }
638
+			}
639
+		}
639 640
 		}
640
-	    }
641
-    	    //$last_exec['radarvirtueljson'] = time();
642
-    	    $last_exec[$id]['last'] = time();
643
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
644
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
645
-	    //$buffer = $Common->getData($hosts[$id]);
646
-	    $buffer = $Common->getData($value['host'].'?'.time());
647
-	    $all_data = json_decode(utf8_encode($buffer),true);
641
+			//$last_exec['radarvirtueljson'] = time();
642
+			$last_exec[$id]['last'] = time();
643
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
644
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
645
+		//$buffer = $Common->getData($hosts[$id]);
646
+		$buffer = $Common->getData($value['host'].'?'.time());
647
+		$all_data = json_decode(utf8_encode($buffer),true);
648 648
 	    
649
-	    if (isset($all_data['pireps'])) {
649
+		if (isset($all_data['pireps'])) {
650 650
 		$reset = 0;
651
-	        foreach ($all_data['pireps'] as $line) {
652
-		    $data = array();
653
-		    $data['id'] = $line['id'];
654
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
-		    $data['ident'] = $line['callsign']; // ident
656
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
657
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
658
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
659
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
660
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
661
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
662
-		    $data['latitude'] = $line['lat']; // lat
663
-		    $data['longitude'] = $line['lon']; // long
664
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
665
-		    //$data['squawk'] = $line['squawk']; // squawk
666
-		    //$data['emergency'] = ''; // emergency
667
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
668
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
669
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
670
-		    //$data['arrival_airport_time'] = $line['arrtime'];
671
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
672
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
673
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
674
-		    else $data['info'] = '';
675
-		    $data['format_source'] = 'pireps';
676
-    		    $data['id_source'] = $id_source;
677
-		    $data['datetime'] = date('Y-m-d H:i:s');
678
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
-		    if ($line['icon'] == 'plane') {
651
+			foreach ($all_data['pireps'] as $line) {
652
+			$data = array();
653
+			$data['id'] = $line['id'];
654
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
655
+			$data['ident'] = $line['callsign']; // ident
656
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
657
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
658
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
659
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
660
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
661
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
662
+			$data['latitude'] = $line['lat']; // lat
663
+			$data['longitude'] = $line['lon']; // long
664
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
665
+			//$data['squawk'] = $line['squawk']; // squawk
666
+			//$data['emergency'] = ''; // emergency
667
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
668
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
669
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
670
+			//$data['arrival_airport_time'] = $line['arrtime'];
671
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
672
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
673
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
674
+			else $data['info'] = '';
675
+			$data['format_source'] = 'pireps';
676
+				$data['id_source'] = $id_source;
677
+			$data['datetime'] = date('Y-m-d H:i:s');
678
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
+			if ($line['icon'] == 'plane') {
680 680
 			$SI->add($data);
681
-		    //    print_r($data);
682
-    		    } elseif ($line['icon'] == 'ct') {
681
+			//    print_r($data);
682
+				} elseif ($line['icon'] == 'ct') {
683 683
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
684 684
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
685 685
 			$typec = substr($data['ident'],-3);
@@ -694,163 +694,163 @@  discard block
 block discarded – undo
694 694
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
695 695
 			else $data['type'] = 'Observer';
696 696
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
697
-		    }
698
-		    unset($data);
697
+			}
698
+			unset($data);
699
+		}
699 700
 		}
700
-	    }
701
-    	    //$last_exec['pirepsjson'] = time();
702
-    	    $last_exec[$id]['last'] = time();
703
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
704
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
-	    //$buffer = $Common->getData($hosts[$id]);
706
-	    if ($globalDebug) echo 'Get Data...'."\n";
707
-	    $buffer = $Common->getData($value['host']);
708
-	    $all_data = json_decode($buffer,true);
709
-	    if ($buffer != '' && is_array($all_data)) {
701
+			//$last_exec['pirepsjson'] = time();
702
+			$last_exec[$id]['last'] = time();
703
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
704
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
705
+		//$buffer = $Common->getData($hosts[$id]);
706
+		if ($globalDebug) echo 'Get Data...'."\n";
707
+		$buffer = $Common->getData($value['host']);
708
+		$all_data = json_decode($buffer,true);
709
+		if ($buffer != '' && is_array($all_data)) {
710 710
 		$reset = 0;
711 711
 		foreach ($all_data as $line) {
712
-	    	    $data = array();
713
-	    	    //$data['id'] = $line['id']; // id not usable
714
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
715
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
717
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
718
-	    	    $data['ident'] = $line['flightnum']; // ident
719
-	    	    $data['altitude'] = $line['alt']; // altitude
720
-	    	    $data['speed'] = $line['gs']; // speed
721
-	    	    $data['heading'] = $line['heading']; // heading
722
-	    	    $data['latitude'] = $line['lat']; // lat
723
-	    	    $data['longitude'] = $line['lng']; // long
724
-	    	    $data['verticalrate'] = ''; // verticale rate
725
-	    	    $data['squawk'] = ''; // squawk
726
-	    	    $data['emergency'] = ''; // emergency
727
-	    	    //$data['datetime'] = $line['lastupdate'];
728
-	    	    $data['last_update'] = $line['lastupdate'];
729
-		    $data['datetime'] = date('Y-m-d H:i:s');
730
-	    	    $data['departure_airport_icao'] = $line['depicao'];
731
-	    	    $data['departure_airport_time'] = $line['deptime'];
732
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
733
-    		    $data['arrival_airport_time'] = $line['arrtime'];
734
-    		    $data['registration'] = $line['aircraft'];
735
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
736
-		    if (isset($line['aircraftname'])) {
712
+				$data = array();
713
+				//$data['id'] = $line['id']; // id not usable
714
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
715
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
716
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
717
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
718
+				$data['ident'] = $line['flightnum']; // ident
719
+				$data['altitude'] = $line['alt']; // altitude
720
+				$data['speed'] = $line['gs']; // speed
721
+				$data['heading'] = $line['heading']; // heading
722
+				$data['latitude'] = $line['lat']; // lat
723
+				$data['longitude'] = $line['lng']; // long
724
+				$data['verticalrate'] = ''; // verticale rate
725
+				$data['squawk'] = ''; // squawk
726
+				$data['emergency'] = ''; // emergency
727
+				//$data['datetime'] = $line['lastupdate'];
728
+				$data['last_update'] = $line['lastupdate'];
729
+			$data['datetime'] = date('Y-m-d H:i:s');
730
+				$data['departure_airport_icao'] = $line['depicao'];
731
+				$data['departure_airport_time'] = $line['deptime'];
732
+				$data['arrival_airport_icao'] = $line['arricao'];
733
+				$data['arrival_airport_time'] = $line['arrtime'];
734
+				$data['registration'] = $line['aircraft'];
735
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
736
+			if (isset($line['aircraftname'])) {
737 737
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
738 738
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
739
-	    		$aircraft_data = explode('-',$line['aircraftname']);
740
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
741
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
742
-	    		else {
743
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
744
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
745
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
746
-	    		}
747
-	    	    }
748
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
749
-    		    $data['id_source'] = $id_source;
750
-	    	    $data['format_source'] = 'phpvmacars';
751
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
752
-		    $SI->add($data);
753
-		    unset($data);
739
+				$aircraft_data = explode('-',$line['aircraftname']);
740
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
741
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
742
+				else {
743
+					$aircraft_data = explode(' ',$line['aircraftname']);
744
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
745
+					else $data['aircraft_icao'] = $line['aircraftname'];
746
+				}
747
+				}
748
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
749
+				$data['id_source'] = $id_source;
750
+				$data['format_source'] = 'phpvmacars';
751
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
752
+			$SI->add($data);
753
+			unset($data);
754 754
 		}
755 755
 		if ($globalDebug) echo 'No more data...'."\n";
756 756
 		unset($buffer);
757 757
 		unset($all_data);
758
-	    }
759
-    	    //$last_exec['phpvmacars'] = time();
760
-    	    $last_exec[$id]['last'] = time();
761
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
762
-	    //$buffer = $Common->getData($hosts[$id]);
763
-	    if ($globalDebug) echo 'Get Data...'."\n";
764
-	    $buffer = $Common->getData($value['host']);
765
-	    $all_data = json_decode($buffer,true);
766
-	    if ($buffer != '' && is_array($all_data)) {
758
+		}
759
+			//$last_exec['phpvmacars'] = time();
760
+			$last_exec[$id]['last'] = time();
761
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
762
+		//$buffer = $Common->getData($hosts[$id]);
763
+		if ($globalDebug) echo 'Get Data...'."\n";
764
+		$buffer = $Common->getData($value['host']);
765
+		$all_data = json_decode($buffer,true);
766
+		if ($buffer != '' && is_array($all_data)) {
767 767
 		$reset = 0;
768 768
 		foreach ($all_data as $line) {
769
-	    	    $data = array();
770
-	    	    //$data['id'] = $line['id']; // id not usable
771
-	    	    $data['id'] = trim($line['flight_id']);
772
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
-	    	    $data['pilot_name'] = $line['pilot_name'];
774
-	    	    $data['pilot_id'] = $line['pilot_id'];
775
-	    	    $data['ident'] = trim($line['callsign']); // ident
776
-	    	    $data['altitude'] = $line['altitude']; // altitude
777
-	    	    $data['speed'] = $line['gs']; // speed
778
-	    	    $data['heading'] = $line['heading']; // heading
779
-	    	    $data['latitude'] = $line['latitude']; // lat
780
-	    	    $data['longitude'] = $line['longitude']; // long
781
-	    	    $data['verticalrate'] = ''; // verticale rate
782
-	    	    $data['squawk'] = ''; // squawk
783
-	    	    $data['emergency'] = ''; // emergency
784
-	    	    //$data['datetime'] = $line['lastupdate'];
785
-	    	    $data['last_update'] = $line['last_update'];
786
-		    $data['datetime'] = date('Y-m-d H:i:s');
787
-	    	    $data['departure_airport_icao'] = $line['departure'];
788
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
789
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
790
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
791
-    		    //$data['registration'] = $line['aircraft'];
792
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
793
-	    	    $data['aircraft_icao'] = $line['plane_type'];
794
-    		    $data['id_source'] = $id_source;
795
-	    	    $data['format_source'] = 'vam';
796
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
797
-		    $SI->add($data);
798
-		    unset($data);
769
+				$data = array();
770
+				//$data['id'] = $line['id']; // id not usable
771
+				$data['id'] = trim($line['flight_id']);
772
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
773
+				$data['pilot_name'] = $line['pilot_name'];
774
+				$data['pilot_id'] = $line['pilot_id'];
775
+				$data['ident'] = trim($line['callsign']); // ident
776
+				$data['altitude'] = $line['altitude']; // altitude
777
+				$data['speed'] = $line['gs']; // speed
778
+				$data['heading'] = $line['heading']; // heading
779
+				$data['latitude'] = $line['latitude']; // lat
780
+				$data['longitude'] = $line['longitude']; // long
781
+				$data['verticalrate'] = ''; // verticale rate
782
+				$data['squawk'] = ''; // squawk
783
+				$data['emergency'] = ''; // emergency
784
+				//$data['datetime'] = $line['lastupdate'];
785
+				$data['last_update'] = $line['last_update'];
786
+			$data['datetime'] = date('Y-m-d H:i:s');
787
+				$data['departure_airport_icao'] = $line['departure'];
788
+				//$data['departure_airport_time'] = $line['departure_time'];
789
+				$data['arrival_airport_icao'] = $line['arrival'];
790
+				//$data['arrival_airport_time'] = $line['arrival_time'];
791
+				//$data['registration'] = $line['aircraft'];
792
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
793
+				$data['aircraft_icao'] = $line['plane_type'];
794
+				$data['id_source'] = $id_source;
795
+				$data['format_source'] = 'vam';
796
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
797
+			$SI->add($data);
798
+			unset($data);
799 799
 		}
800 800
 		if ($globalDebug) echo 'No more data...'."\n";
801 801
 		unset($buffer);
802 802
 		unset($all_data);
803
-	    }
804
-    	    //$last_exec['phpvmacars'] = time();
805
-    	    $last_exec[$id]['last'] = time();
803
+		}
804
+			//$last_exec['phpvmacars'] = time();
805
+			$last_exec[$id]['last'] = time();
806 806
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
807 807
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') {
808
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
809
-    	    //$last_exec[$id]['last'] = time();
808
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
809
+			//$last_exec[$id]['last'] = time();
810 810
 
811
-	    //$read = array( $sockets[$id] );
812
-	    $read = $sockets;
813
-	    $write = NULL;
814
-	    $e = NULL;
815
-	    $n = socket_select($read, $write, $e, $timeout);
816
-	    if ($e != NULL) var_dump($e);
817
-	    if ($n > 0) {
811
+		//$read = array( $sockets[$id] );
812
+		$read = $sockets;
813
+		$write = NULL;
814
+		$e = NULL;
815
+		$n = socket_select($read, $write, $e, $timeout);
816
+		if ($e != NULL) var_dump($e);
817
+		if ($n > 0) {
818 818
 		$reset = 0;
819 819
 		foreach ($read as $nb => $r) {
820
-		    //$value = $formats[$nb];
821
-		    $format = $globalSources[$nb]['format'];
822
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
823
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
-        	    } else {
825
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
-	    	    }
827
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
828
-        	    //echo $buffer."\n";
829
-		    // lets play nice and handle signals such as ctrl-c/kill properly
830
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
831
-		    $error = false;
832
-		    //$SI::del();
833
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
-		    // SBS format is CSV format
835
-		    if ($buffer != '') {
820
+			//$value = $formats[$nb];
821
+			$format = $globalSources[$nb]['format'];
822
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
823
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
824
+				} else {
825
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
826
+				}
827
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
828
+				//echo $buffer."\n";
829
+			// lets play nice and handle signals such as ctrl-c/kill properly
830
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
831
+			$error = false;
832
+			//$SI::del();
833
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
834
+			// SBS format is CSV format
835
+			if ($buffer != '') {
836 836
 			$tt[$format] = 0;
837 837
 			if ($format == 'acarssbs3') {
838
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
839
-			    $ACARS->add(trim($buffer));
840
-			    $ACARS->deleteLiveAcarsData();
838
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
839
+				$ACARS->add(trim($buffer));
840
+				$ACARS->deleteLiveAcarsData();
841 841
 			} elseif ($format == 'raw') {
842
-			    // AVR format
843
-			    $data = $SBS->parse($buffer);
844
-			    if (is_array($data)) {
842
+				// AVR format
843
+				$data = $SBS->parse($buffer);
844
+				if (is_array($data)) {
845 845
 				$data['datetime'] = date('Y-m-d H:i:s');
846 846
 				$data['format_source'] = 'raw';
847 847
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
848
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
850
-                            }
851
-                        } elseif ($format == 'flightgearsp') {
852
-                    	    //echo $buffer."\n";
853
-                    	    if (strlen($buffer) > 5) {
848
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
849
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
850
+							}
851
+						} elseif ($format == 'flightgearsp') {
852
+							//echo $buffer."\n";
853
+							if (strlen($buffer) > 5) {
854 854
 				$line = explode(',',$buffer);
855 855
 				$data = array();
856 856
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -866,123 +866,123 @@  discard block
 block discarded – undo
866 866
 				$data['format_source'] = 'flightgearsp';
867 867
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
868 868
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
869
-			    }
870
-                        } elseif ($format == 'acars') {
871
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
872
-			    $ACARS->add(trim($buffer));
873
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
-			    $ACARS->deleteLiveAcarsData();
869
+				}
870
+						} elseif ($format == 'acars') {
871
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
872
+				$ACARS->add(trim($buffer));
873
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
874
+				$ACARS->deleteLiveAcarsData();
875 875
 			} elseif ($format == 'flightgearmp') {
876
-			    if (substr($buffer,0,1) != '#') {
876
+				if (substr($buffer,0,1) != '#') {
877 877
 				$data = array();
878 878
 				//echo $buffer."\n";
879 879
 				$line = explode(' ',$buffer);
880 880
 				if (count($line) == 11) {
881
-				    $userserver = explode('@',$line[0]);
882
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
883
-				    $data['ident'] = $userserver[0];
884
-				    $data['registration'] = $userserver[0];
885
-				    $data['latitude'] = $line[4];
886
-				    $data['longitude'] = $line[5];
887
-				    $data['altitude'] = $line[6];
888
-				    $data['datetime'] = date('Y-m-d H:i:s');
889
-				    $aircraft_type = $line[10];
890
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
891
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
892
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
881
+					$userserver = explode('@',$line[0]);
882
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
883
+					$data['ident'] = $userserver[0];
884
+					$data['registration'] = $userserver[0];
885
+					$data['latitude'] = $line[4];
886
+					$data['longitude'] = $line[5];
887
+					$data['altitude'] = $line[6];
888
+					$data['datetime'] = date('Y-m-d H:i:s');
889
+					$aircraft_type = $line[10];
890
+					$aircraft_type = preg_split(':/:',$aircraft_type);
891
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
892
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
893
+				}
893 894
 				}
894
-			    }
895 895
 			} elseif ($format == 'beast') {
896
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
897
-			    die;
896
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
897
+				die;
898 898
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
899
-			    $line = explode("\t", $buffer);
900
-			    for($k = 0; $k < count($line); $k=$k+2) {
899
+				$line = explode("\t", $buffer);
900
+				for($k = 0; $k < count($line); $k=$k+2) {
901 901
 				$key = $line[$k];
902
-			        $lined[$key] = $line[$k+1];
903
-			    }
904
-    			    if (count($lined) > 3) {
905
-    				$data['hex'] = $lined['hexid'];
906
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
907
-    				$data['datetime'] = date('Y-m-d H:i:s');;
908
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
909
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
910
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
911
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
912
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
913
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
914
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
915
-    				$data['id_source'] = $id_source;
916
-    				$data['format_source'] = 'tsv';
917
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
918
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
919
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
920
-    				unset($lined);
921
-    				unset($data);
922
-    			    } else $error = true;
902
+					$lined[$key] = $line[$k+1];
903
+				}
904
+					if (count($lined) > 3) {
905
+					$data['hex'] = $lined['hexid'];
906
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
907
+					$data['datetime'] = date('Y-m-d H:i:s');;
908
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
909
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
910
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
911
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
912
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
913
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
914
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
915
+					$data['id_source'] = $id_source;
916
+					$data['format_source'] = 'tsv';
917
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
918
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
919
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
920
+					unset($lined);
921
+					unset($data);
922
+					} else $error = true;
923 923
 			} elseif ($format == 'aprs' && $use_aprs) {
924
-			    if ($aprs_connect == 0) {
924
+				if ($aprs_connect == 0) {
925 925
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
926 926
 				$aprs_connect = 1;
927
-			    }
927
+				}
928 928
 			    
929
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
929
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
930 930
 				$aprs_last_tx = time();
931 931
 				$data_aprs = "# Keep alive";
932 932
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
933
-			    }
933
+				}
934 934
 			    
935
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
936
-			    $buffer = str_replace('APRS <- ','',$buffer);
937
-			    $buffer = str_replace('APRS -> ','',$buffer);
938
-			    //echo $buffer."\n";
939
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
935
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
936
+				$buffer = str_replace('APRS <- ','',$buffer);
937
+				$buffer = str_replace('APRS -> ','',$buffer);
938
+				//echo $buffer."\n";
939
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
940 940
 				$line = $APRS->parse($buffer);
941 941
 				//print_r($line);
942 942
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
943
-				    $aprs_last_tx = time();
944
-				    $data = array();
945
-				    //print_r($line);
946
-				    $data['hex'] = $line['address'];
947
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
948
-				    //$data['datetime'] = date('Y-m-d H:i:s');
949
-				    $data['ident'] = $line['ident'];
950
-				    $data['latitude'] = $line['latitude'];
951
-				    $data['longitude'] = $line['longitude'];
952
-				    //$data['verticalrate'] = $line[16];
953
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
954
-				    else $data['speed'] = 0;
955
-				    $data['altitude'] = $line['altitude'];
956
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
957
-				    //else $data['heading'] = 0;
958
-				    $data['aircraft_type'] = $line['stealth'];
959
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
960
-    				    $data['id_source'] = $id_source;
961
-				    $data['format_source'] = 'aprs';
962
-				    $data['source_name'] = $line['source'];
963
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
964
-				    $currentdate = date('Y-m-d H:i:s');
965
-				    $aprsdate = strtotime($data['datetime']);
966
-				    // Accept data if time <= system time + 20s
967
-				    if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
943
+					$aprs_last_tx = time();
944
+					$data = array();
945
+					//print_r($line);
946
+					$data['hex'] = $line['address'];
947
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
948
+					//$data['datetime'] = date('Y-m-d H:i:s');
949
+					$data['ident'] = $line['ident'];
950
+					$data['latitude'] = $line['latitude'];
951
+					$data['longitude'] = $line['longitude'];
952
+					//$data['verticalrate'] = $line[16];
953
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
954
+					else $data['speed'] = 0;
955
+					$data['altitude'] = $line['altitude'];
956
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
957
+					//else $data['heading'] = 0;
958
+					$data['aircraft_type'] = $line['stealth'];
959
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
960
+						$data['id_source'] = $id_source;
961
+					$data['format_source'] = 'aprs';
962
+					$data['source_name'] = $line['source'];
963
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
964
+					$currentdate = date('Y-m-d H:i:s');
965
+					$aprsdate = strtotime($data['datetime']);
966
+					// Accept data if time <= system time + 20s
967
+					if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
968 968
 					$send = $SI->add($data);
969
-				    } else {
969
+					} else {
970 970
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
971 971
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
972
-				    }
973
-				    unset($data);
972
+					}
973
+					unset($data);
974 974
 				} 
975 975
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
976 976
 					echo '!! Weather Station not yet supported'."\n";
977 977
 				}
978 978
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
979 979
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
980
-			    }
980
+				}
981 981
 			} else {
982
-			    $line = explode(',', $buffer);
983
-    			    if (count($line) > 20) {
984
-    			    	$data['hex'] = $line[4];
985
-    				/*
982
+				$line = explode(',', $buffer);
983
+					if (count($line) > 20) {
984
+						$data['hex'] = $line[4];
985
+					/*
986 986
     				$data['datetime'] = $line[6].' '.$line[7];
987 987
     					date_default_timezone_set($globalTimezone);
988 988
     					$datetime = new DateTime($data['datetime']);
@@ -990,29 +990,29 @@  discard block
 block discarded – undo
990 990
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
991 991
     					date_default_timezone_set('UTC');
992 992
     				*/
993
-    				// Force datetime to current UTC datetime
994
-    				date_default_timezone_set('UTC');
995
-    				$data['datetime'] = date('Y-m-d H:i:s');
996
-    				$data['ident'] = trim($line[10]);
997
-    				$data['latitude'] = $line[14];
998
-    				$data['longitude'] = $line[15];
999
-    				$data['verticalrate'] = $line[16];
1000
-    				$data['emergency'] = $line[20];
1001
-    				$data['speed'] = $line[12];
1002
-    				$data['squawk'] = $line[17];
1003
-    				$data['altitude'] = $line[11];
1004
-    				$data['heading'] = $line[13];
1005
-    				$data['ground'] = $line[21];
1006
-    				$data['emergency'] = $line[19];
1007
-    				$data['format_source'] = 'sbs';
993
+					// Force datetime to current UTC datetime
994
+					date_default_timezone_set('UTC');
995
+					$data['datetime'] = date('Y-m-d H:i:s');
996
+					$data['ident'] = trim($line[10]);
997
+					$data['latitude'] = $line[14];
998
+					$data['longitude'] = $line[15];
999
+					$data['verticalrate'] = $line[16];
1000
+					$data['emergency'] = $line[20];
1001
+					$data['speed'] = $line[12];
1002
+					$data['squawk'] = $line[17];
1003
+					$data['altitude'] = $line[11];
1004
+					$data['heading'] = $line[13];
1005
+					$data['ground'] = $line[21];
1006
+					$data['emergency'] = $line[19];
1007
+					$data['format_source'] = 'sbs';
1008 1008
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1009
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1010
-    				$data['id_source'] = $id_source;
1011
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1012
-    				else $error = true;
1013
-    				unset($data);
1014
-    			    } else $error = true;
1015
-			    if ($error) {
1009
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1010
+					$data['id_source'] = $id_source;
1011
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1012
+					else $error = true;
1013
+					unset($data);
1014
+					} else $error = true;
1015
+				if ($error) {
1016 1016
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1017 1017
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1018 1018
 				} else {
@@ -1028,13 +1028,13 @@  discard block
 block discarded – undo
1028 1028
 					connect_all($sourceer);
1029 1029
 					$sourceer = array();
1030 1030
 				}
1031
-			    }
1031
+				}
1032 1032
 			}
1033 1033
 			// Sleep for xxx microseconds
1034 1034
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1035
-		    } else {
1035
+			} else {
1036 1036
 			if ($format == 'flightgearmp') {
1037
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1037
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1038 1038
 				//@socket_close($r);
1039 1039
 				sleep($globalMinFetch);
1040 1040
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1043,9 +1043,9 @@  discard block
 block discarded – undo
1043 1043
 				break;
1044 1044
 				
1045 1045
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1046
-			    if (isset($tt[$format])) $tt[$format]++;
1047
-			    else $tt[$format] = 0;
1048
-			    if ($tt[$format] > 30) {
1046
+				if (isset($tt[$format])) $tt[$format]++;
1047
+				else $tt[$format] = 0;
1048
+				if ($tt[$format] > 30) {
1049 1049
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1050 1050
 				//@socket_close($r);
1051 1051
 				sleep(2);
@@ -1056,23 +1056,23 @@  discard block
 block discarded – undo
1056 1056
 				//connect_all($globalSources);
1057 1057
 				$tt[$format]=0;
1058 1058
 				break;
1059
-			    }
1059
+				}
1060
+			}
1060 1061
 			}
1061
-		    }
1062 1062
 		}
1063
-	    } else {
1063
+		} else {
1064 1064
 		$error = socket_strerror(socket_last_error());
1065 1065
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1066 1066
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1067 1067
 			if (isset($globalDebug)) echo "Restarting...\n";
1068 1068
 			// Restart the script if possible
1069 1069
 			if (is_array($sockets)) {
1070
-			    if ($globalDebug) echo "Shutdown all sockets...";
1070
+				if ($globalDebug) echo "Shutdown all sockets...";
1071 1071
 			    
1072
-			    foreach ($sockets as $sock) {
1072
+				foreach ($sockets as $sock) {
1073 1073
 				@socket_shutdown($sock,2);
1074 1074
 				@socket_close($sock);
1075
-			    }
1075
+				}
1076 1076
 			    
1077 1077
 			}
1078 1078
 			if ($globalDebug) echo "Restart all connections...";
@@ -1083,13 +1083,13 @@  discard block
 block discarded – undo
1083 1083
 			if ($reset > 40) exit('Too many attempts...');
1084 1084
 			connect_all($globalSources);
1085 1085
 		}
1086
-	    }
1086
+		}
1087 1087
 	}
1088 1088
 	if ($globalDaemon === false) {
1089
-	    if ($globalDebug) echo 'Check all...'."\n";
1090
-	    $SI->checkAll();
1089
+		if ($globalDebug) echo 'Check all...'."\n";
1090
+		$SI->checkAll();
1091
+	}
1091 1092
 	}
1092
-    }
1093 1093
 }
1094 1094
 
1095 1095
 ?>
Please login to merge, or discard this patch.
require/class.APRS.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class aprs {
3
-    protected $symbols = array('!' => 'Police',
3
+	protected $symbols = array('!' => 'Police',
4 4
 	'#' => 'DIGI',
5 5
 	'$' => 'Phone',
6 6
 	'%' => 'DX Cluster',
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	'y' => 'Yagi At QTH');
85 85
 	
86 86
 
87
-    private function urshift($n, $s) {
87
+	private function urshift($n, $s) {
88 88
 	return ($n >= 0) ? ($n >> $s) :
89
-    	    (($n & 0x7fffffff) >> $s) | 
90
-        	(0x40000000 >> ($s - 1));
91
-    }
89
+			(($n & 0x7fffffff) >> $s) | 
90
+			(0x40000000 >> ($s - 1));
91
+	}
92 92
 
93
-    public function parse($input) {
93
+	public function parse($input) {
94 94
 	global $globalDebug;
95 95
 	$debug = false;
96 96
 	$result = array();
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 	
103 103
 	/* Check that end was found and body has at least one byte. */
104 104
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
105
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
106
-	    return false;
105
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
106
+		return false;
107 107
 	}
108 108
 	
109 109
 	/* Save header and body. */
@@ -116,23 +116,23 @@  discard block
 block discarded – undo
116 116
 	/* Parse source, target and path. */
117 117
 	//FLRDF0A52>APRS,qAS,LSTB
118 118
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
119
-	    $ident = $matches[1];
120
-	    $all_elements = $matches[2];
121
-	    if ($debug) echo 'ident : '.$ident."\n";
122
-	    $result['ident'] = $ident;
119
+		$ident = $matches[1];
120
+		$all_elements = $matches[2];
121
+		if ($debug) echo 'ident : '.$ident."\n";
122
+		$result['ident'] = $ident;
123 123
 	} else return false;
124 124
 	$elements = explode(',',$all_elements);
125 125
 	$source = end($elements);
126 126
 	$result['source'] = $source;
127 127
 	foreach ($elements as $element) {
128
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
129
-	        //echo "ok";
130
-	        //if ($element == 'TCPIP*') return false;
131
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
128
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
129
+			//echo "ok";
130
+			//if ($element == 'TCPIP*') return false;
131
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
132 132
 		echo 'element : '.$element."\n";
133 133
 		return false;
134
-	    }
135
-	    /*
134
+		}
135
+		/*
136 136
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
137 137
 		//echo "ok";
138 138
 	    } else {
@@ -145,49 +145,49 @@  discard block
 block discarded – undo
145 145
 	$body_parse = substr($body,1);
146 146
 	//echo 'Body : '.$body."\n";
147 147
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
148
-	    $body_parse = substr($body_parse,10);
149
-	    $find = true;
150
-	    //echo $body_parse."\n";
148
+		$body_parse = substr($body_parse,10);
149
+		$find = true;
150
+		//echo $body_parse."\n";
151 151
 	}
152 152
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
153
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
154
-	    $find = true;
155
-	    //echo $body_parse."\n";
153
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
154
+		$find = true;
155
+		//echo $body_parse."\n";
156 156
 	}
157 157
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
158
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
159
-	    $find = true;
160
-	    //echo $body_parse."\n";
158
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
159
+		$find = true;
160
+		//echo $body_parse."\n";
161 161
 	}
162 162
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
163
-	    $find = true;
164
-	    //print_r($matches);
165
-	    $timestamp = $matches[0];
166
-	    if ($matches[4] == 'h') {
163
+		$find = true;
164
+		//print_r($matches);
165
+		$timestamp = $matches[0];
166
+		if ($matches[4] == 'h') {
167 167
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
168 168
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
169 169
 		/*
170 170
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
171 171
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
172 172
 		*/
173
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
173
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
174 174
 		// This work or not ?
175 175
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
176
-	    }
177
-	    $body_parse = substr($body_parse,7);
178
-	    $result['timestamp'] = $timestamp;
179
-	    //echo date('Ymd H:i:s',$timestamp);
176
+		}
177
+		$body_parse = substr($body_parse,7);
178
+		$result['timestamp'] = $timestamp;
179
+		//echo date('Ymd H:i:s',$timestamp);
180 180
 	}
181 181
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
182
-	    $find = true;
183
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
184
-	    $body_parse = substr($body_parse,8);
185
-	    $result['timestamp'] = $timestamp;
186
-	    //echo date('Ymd H:i:s',$timestamp);
182
+		$find = true;
183
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
184
+		$body_parse = substr($body_parse,8);
185
+		$result['timestamp'] = $timestamp;
186
+		//echo date('Ymd H:i:s',$timestamp);
187 187
 	}
188 188
 	//if (strlen($body_parse) > 19) {
189
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
190
-	    $find = true;
189
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
190
+		$find = true;
191 191
 		// 4658.70N/00707.78Ez
192 192
 		//print_r(str_split($body_parse));
193 193
 		
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		$lon = intval($lon_deg);
205 205
 		if ($lat > 89 || $lon > 179) return false;
206 206
 	    
207
-	    /*
207
+		/*
208 208
 	    $tmp_5b = str_replace('.','',$lat_min);
209 209
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
210 210
 	        print_r($matches);
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 		$result['longitude'] = $longitude;
219 219
 		$body_parse = substr($body_parse,18);
220 220
 		$body_parse_len = strlen($body_parse);
221
-	    }
222
-	    $body_parse_len = strlen($body_parse);
223
-	    if ($body_parse_len > 0) {
221
+		}
222
+		$body_parse_len = strlen($body_parse);
223
+		if ($body_parse_len > 0) {
224 224
 		/*
225 225
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
226 226
 			$body_split = str_split($body);
@@ -247,61 +247,61 @@  discard block
 block discarded – undo
247 247
 			$result['symbol_code'] = $symbol_code;
248 248
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
249 249
 			if ($symbol_code != '_') {
250
-		    //$body_parse = substr($body_parse,1);
251
-		    //$body_parse = trim($body_parse);
252
-		    //$body_parse_len = strlen($body_parse);
253
-		    if ($body_parse_len >= 7) {
250
+			//$body_parse = substr($body_parse,1);
251
+			//$body_parse = trim($body_parse);
252
+			//$body_parse_len = strlen($body_parse);
253
+			if ($body_parse_len >= 7) {
254 254
 			
255
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
256
-		    	    $course = substr($body_parse,0,3);
257
-		    	    $tmp_s = intval($course);
258
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
259
-		    	    $speed = substr($body_parse,4,3);
260
-		    	    $result['speed'] = round($speed*1.852);
261
-		    	    $body_parse = substr($body_parse,7);
262
-		        }
263
-		        // Check PHGR, PHG, RNG
264
-		    } 
265
-		    /*
255
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
256
+					$course = substr($body_parse,0,3);
257
+					$tmp_s = intval($course);
258
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
259
+					$speed = substr($body_parse,4,3);
260
+					$result['speed'] = round($speed*1.852);
261
+					$body_parse = substr($body_parse,7);
262
+				}
263
+				// Check PHGR, PHG, RNG
264
+			} 
265
+			/*
266 266
 		    else if ($body_parse_len > 0) {
267 267
 			$rest = $body_parse;
268 268
 		    }
269 269
 		    */
270
-		    if (strlen($body_parse) > 0) {
271
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
272
-		            $altitude = intval($matches[1]);
273
-		            //$result['altitude'] = round($altitude*0.3048);
274
-		            $result['altitude'] = $altitude;
275
-		            $body_parse = trim(substr($body_parse,strlen($matches[0])));
276
-		        }
277
-		    }
270
+			if (strlen($body_parse) > 0) {
271
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
272
+					$altitude = intval($matches[1]);
273
+					//$result['altitude'] = round($altitude*0.3048);
274
+					$result['altitude'] = $altitude;
275
+					$body_parse = trim(substr($body_parse,strlen($matches[0])));
276
+				}
277
+			}
278 278
 		    
279
-		    // Telemetry
280
-		    /*
279
+			// Telemetry
280
+			/*
281 281
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
282 282
 		        // Nothing yet...
283 283
 		    }
284 284
 		    */
285
-		    // DAO
286
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
287
-			    $dao = $matches[1];
288
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
285
+			// DAO
286
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
287
+				$dao = $matches[1];
288
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
289 289
 				$dao_split = str_split($dao);
290
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
291
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
290
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
291
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
292 292
 			    
293 293
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
294 294
 				else $result['latitude'] += $lat_off;
295 295
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
296 296
 				else $result['longitude'] += $lon_off;
297
-			    }
298
-		            $body_parse = substr($body_parse,6);
299
-		    }
297
+				}
298
+					$body_parse = substr($body_parse,6);
299
+			}
300 300
 		    
301
-		    // OGN comment
301
+			// OGN comment
302 302
 		   // echo "Before OGN : ".$body_parse."\n";
303
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
304
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
303
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
304
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
305 305
 			$id = $matches[1];
306 306
 			//$mode = substr($id,0,2);
307 307
 			$address = substr($id,2);
@@ -331,51 +331,51 @@  discard block
 block discarded – undo
331 331
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
332 332
 			$result['stealth'] = $stealth;
333 333
 			$result['address'] = $address;
334
-		    }
334
+			}
335 335
 		    
336
-		    //Comment
337
-		    $result['comment'] = trim($body_parse);
336
+			//Comment
337
+			$result['comment'] = trim($body_parse);
338 338
 		} else {
339
-		    // parse weather
340
-		    //$body_parse = substr($body_parse,1);
341
-		    //$body_parse_len = strlen($body_parse);
339
+			// parse weather
340
+			//$body_parse = substr($body_parse,1);
341
+			//$body_parse_len = strlen($body_parse);
342 342
 
343
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
344
-			    $result['wind_dir'] = intval($matches[1]);
345
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
346
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
347
-			    $result['temp'] = round(5/9*(($matches[4])-32),1);
348
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
349
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
343
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
344
+				$result['wind_dir'] = intval($matches[1]);
345
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
346
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
347
+				$result['temp'] = round(5/9*(($matches[4])-32),1);
348
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
349
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
350 350
 			$result['wind_dir'] = intval($matches[1]);
351 351
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
352 352
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
353 353
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
354
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
355
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
354
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
355
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
356 356
 			$result['wind_dir'] = intval($matches[1]);
357 357
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
358 358
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
359
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
360
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
359
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
360
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
361 361
 			$result['wind_dir'] = intval($matches[1]);
362 362
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
363 363
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
364
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
365
-		    }
366
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
364
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
365
+			}
366
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
367 367
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
368
-		    }
368
+			}
369 369
 		}
370 370
 		} else $result['comment'] = trim($body_parse);
371 371
 
372
-	    }
372
+		}
373 373
 	//}
374 374
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
375 375
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
376 376
 	//print_r($result);
377 377
 	return $result;
378
-    }
378
+	}
379 379
 }
380 380
 /*
381 381
 $aprs = new aprs();
Please login to merge, or discard this patch.
require/class.Connection.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 36;
8 8
 	
9 9
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10
-	    global $globalDBdriver;
11
-	    if ($dbc === null) {
10
+		global $globalDBdriver;
11
+		if ($dbc === null) {
12 12
 		if ($this->db === null && $dbname === null) {
13
-		    if ($user === null && $pass === null) {
13
+			if ($user === null && $pass === null) {
14 14
 			$this->createDBConnection();
15
-		    } else {
15
+			} else {
16 16
 			$this->createDBConnection(null,$user,$pass);
17
-		    }
17
+			}
18 18
 		} else {
19
-		    $this->createDBConnection($dbname);
19
+			$this->createDBConnection($dbname);
20 20
 		}
21
-	    } elseif ($dbname === null || $dbname === 'default') {
21
+		} elseif ($dbname === null || $dbname === 'default') {
22 22
 		$this->db = $dbc;
23 23
 		if ($this->connectionExists() === false) {
24 24
 			/*
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 			*/
29 29
 			$this->createDBConnection();
30 30
 		}
31
-	    } else {
31
+		} else {
32 32
 		//$this->connectionExists();
33 33
 		$this->dbs[$dbname] = $dbc;
34
-	    }
34
+		}
35 35
 	}
36 36
 
37 37
 	public function db() {
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
 	}
48 48
 
49 49
 	/**
50
-	* Creates the database connection
51
-	*
52
-	* @return Boolean of the database connection
53
-	*
54
-	*/
50
+	 * Creates the database connection
51
+	 *
52
+	 * @return Boolean of the database connection
53
+	 *
54
+	 */
55 55
 
56 56
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
57 57
 	{
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 			return false;
149 149
 		}
150 150
 		if($results->rowCount()>0) {
151
-		    return true; 
151
+			return true; 
152 152
 		}
153 153
 		else return false;
154 154
 	}
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 				$sum = $sum->fetchColumn(0);
166 166
 			} else $sum = 0;
167 167
 			if (intval($sum) !== 2) {
168
-			     return false;
168
+				 return false;
169 169
 			}
170 170
 			
171 171
 		} catch(PDOException $e) {
172 172
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
173
-            			throw $e;
174
-	                }
175
-	                //echo 'error ! '.$e->getMessage();
173
+						throw $e;
174
+					}
175
+					//echo 'error ! '.$e->getMessage();
176 176
 			return false;
177 177
 		}
178 178
 		return true; 
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 		$version = 0;
277 277
 		if ($this->tableExists('aircraft')) {
278 278
 			if (!$this->tableExists('config')) {
279
-	    			$version = '1';
280
-	    			return $version;
279
+					$version = '1';
280
+					return $version;
281 281
 			} else {
282 282
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
283 283
 				try {
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 	* @return Boolean if latest version or not
299 299
 	*/
300 300
 	public function latest() {
301
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
302
-	    else return false;
301
+		if ($this->check_schema_version() == $this->latest_schema) return true;
302
+		else return false;
303 303
 	}
304 304
 
305 305
 }
Please login to merge, or discard this patch.
install/class.update_schema.php 1 patch
Indentation   +603 added lines, -603 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
 class update_schema {
9 9
 
10 10
 	public static function update_schedule() {
11
-	    $Connection = new Connection();
12
-	    $Schedule = new Schedule();
13
-	    $query = "SELECT * FROM schedule";
14
-            try {
15
-            	$sth = $Connection->db->prepare($query);
11
+		$Connection = new Connection();
12
+		$Schedule = new Schedule();
13
+		$query = "SELECT * FROM schedule";
14
+			try {
15
+				$sth = $Connection->db->prepare($query);
16 16
 		$sth->execute();
17
-    	    } catch(PDOException $e) {
17
+			} catch(PDOException $e) {
18 18
 		return "error : ".$e->getMessage()."\n";
19
-    	    }
20
-    	    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
-    		$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
-    	    }
19
+			}
20
+			while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
+			$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
+			}
23 23
 	
24 24
 	}
25 25
 /*
@@ -43,198 +43,198 @@  discard block
 block discarded – undo
43 43
     	}
44 44
 */	
45 45
 	private static function update_from_1() {
46
-    		$Connection = new Connection();
47
-    		// Add new column to routes table
48
-    		//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
46
+			$Connection = new Connection();
47
+			// Add new column to routes table
48
+			//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
49 49
 		$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10) NULL , ADD `ToAirport_Time` VARCHAR(10) NULL , ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP, ADD `date_modified` timestamp NULL, ADD `date_lastseen` timestamp NULL";
50
-        	try {
51
-            	    $sth = $Connection->db->prepare($query);
52
-		    $sth->execute();
53
-    		} catch(PDOException $e) {
54
-		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
-    		}
56
-    		// Copy schedules data to routes table
57
-    		self::update_schedule();
58
-    		// Delete schedule table
50
+			try {
51
+					$sth = $Connection->db->prepare($query);
52
+			$sth->execute();
53
+			} catch(PDOException $e) {
54
+			return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
+			}
56
+			// Copy schedules data to routes table
57
+			self::update_schedule();
58
+			// Delete schedule table
59 59
 		$query = "DROP TABLE `schedule`";
60
-        	try {
61
-            	    $sth = $Connection->db->prepare($query);
62
-		    $sth->execute();
63
-    		} catch(PDOException $e) {
64
-		    return "error (delete schedule table) : ".$e->getMessage()."\n";
65
-    		}
66
-    		// Add source column
67
-    		$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
-    		try {
69
-            	    $sth = $Connection->db->prepare($query);
70
-		    $sth->execute();
71
-    		} catch(PDOException $e) {
72
-		    return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
-    		}
60
+			try {
61
+					$sth = $Connection->db->prepare($query);
62
+			$sth->execute();
63
+			} catch(PDOException $e) {
64
+			return "error (delete schedule table) : ".$e->getMessage()."\n";
65
+			}
66
+			// Add source column
67
+			$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
+			try {
69
+					$sth = $Connection->db->prepare($query);
70
+			$sth->execute();
71
+			} catch(PDOException $e) {
72
+			return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
+			}
74 74
 		// Delete unused column
75 75
 		$query = "ALTER TABLE `aircraft_modes`  DROP `SerialNo`,  DROP `OperatorFlagCode`,  DROP `Manufacturer`,  DROP `Type`,  DROP `FirstRegDate`,  DROP `CurrentRegDate`,  DROP `Country`,  DROP `PreviousID`,  DROP `DeRegDate`,  DROP `Status`,  DROP `PopularName`,  DROP `GenericName`,  DROP `AircraftClass`,  DROP `Engines`,  DROP `OwnershipStatus`,  DROP `RegisteredOwners`,  DROP `MTOW`,  DROP `TotalHours`,  DROP `YearBuilt`,  DROP `CofACategory`,  DROP `CofAExpiry`,  DROP `UserNotes`,  DROP `Interested`,  DROP `UserTag`,  DROP `InfoUrl`,  DROP `PictureUrl1`,  DROP `PictureUrl2`,  DROP `PictureUrl3`,  DROP `UserBool1`,  DROP `UserBool2`,  DROP `UserBool3`,  DROP `UserBool4`,  DROP `UserBool5`,  DROP `UserString1`,  DROP `UserString2`,  DROP `UserString3`,  DROP `UserString4`,  DROP `UserString5`,  DROP `UserInt1`,  DROP `UserInt2`,  DROP `UserInt3`,  DROP `UserInt4`,  DROP `UserInt5`";
76
-    		try {
77
-            	    $sth = $Connection->db->prepare($query);
78
-		    $sth->execute();
79
-    		} catch(PDOException $e) {
80
-		    return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
-    		}
76
+			try {
77
+					$sth = $Connection->db->prepare($query);
78
+			$sth->execute();
79
+			} catch(PDOException $e) {
80
+			return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
+			}
82 82
 		// Add ModeS column
83 83
 		$query = "ALTER TABLE `spotter_output`  ADD `ModeS` VARCHAR(255) NULL";
84
-    		try {
85
-            	    $sth = $Connection->db->prepare($query);
86
-		    $sth->execute();
87
-    		} catch(PDOException $e) {
88
-		    return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
-    		}
84
+			try {
85
+					$sth = $Connection->db->prepare($query);
86
+			$sth->execute();
87
+			} catch(PDOException $e) {
88
+			return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
+			}
90 90
 		$query = "ALTER TABLE `spotter_live`  ADD `ModeS` VARCHAR(255)";
91
-    		try {
92
-            	    $sth = $Connection->db->prepare($query);
93
-		    $sth->execute();
94
-    		} catch(PDOException $e) {
95
-		    return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
-    		}
97
-    		// Add auto_increment for aircraft_modes
98
-    		$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
-    		try {
100
-            	    $sth = $Connection->db->prepare($query);
101
-		    $sth->execute();
102
-    		} catch(PDOException $e) {
103
-		    return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
-    		}
105
-    		$error = '';
91
+			try {
92
+					$sth = $Connection->db->prepare($query);
93
+			$sth->execute();
94
+			} catch(PDOException $e) {
95
+			return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
+			}
97
+			// Add auto_increment for aircraft_modes
98
+			$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
+			try {
100
+					$sth = $Connection->db->prepare($query);
101
+			$sth->execute();
102
+			} catch(PDOException $e) {
103
+			return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
+			}
105
+			$error = '';
106 106
 		$error .= create_db::import_file('../db/acars_live.sql');
107 107
 		$error .= create_db::import_file('../db/config.sql');
108 108
 		// Update schema_version to 2
109 109
 		$query = "UPDATE `config` SET `value` = '2' WHERE `name` = 'schema_version'";
110
-        	try {
111
-            	    $sth = $Connection->db->prepare($query);
112
-		    $sth->execute();
113
-    		} catch(PDOException $e) {
114
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
115
-    		}
110
+			try {
111
+					$sth = $Connection->db->prepare($query);
112
+			$sth->execute();
113
+			} catch(PDOException $e) {
114
+			return "error (update schema_version) : ".$e->getMessage()."\n";
115
+			}
116 116
 		return $error;
117
-        }
117
+		}
118 118
 
119 119
 	private static function update_from_2() {
120
-    		$Connection = new Connection();
121
-    		// Add new column decode to acars_live table
120
+			$Connection = new Connection();
121
+			// Add new column decode to acars_live table
122 122
 		$query = "ALTER TABLE `acars_live` ADD `decode` TEXT";
123
-        	try {
124
-            	    $sth = $Connection->db->prepare($query);
125
-		    $sth->execute();
126
-    		} catch(PDOException $e) {
127
-		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
-    		}
129
-    		$error = '';
130
-    		// Create table acars_archive
123
+			try {
124
+					$sth = $Connection->db->prepare($query);
125
+			$sth->execute();
126
+			} catch(PDOException $e) {
127
+			return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
+			}
129
+			$error = '';
130
+			// Create table acars_archive
131 131
 		$error .= create_db::import_file('../db/acars_archive.sql');
132 132
 		// Update schema_version to 3
133 133
 		$query = "UPDATE `config` SET `value` = '3' WHERE `name` = 'schema_version'";
134
-        	try {
135
-            	    $sth = $Connection->db->prepare($query);
136
-		    $sth->execute();
137
-    		} catch(PDOException $e) {
138
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
139
-    		}
134
+			try {
135
+					$sth = $Connection->db->prepare($query);
136
+			$sth->execute();
137
+			} catch(PDOException $e) {
138
+			return "error (update schema_version) : ".$e->getMessage()."\n";
139
+			}
140 140
 		return $error;
141 141
 	}
142 142
 
143 143
 	private static function update_from_3() {
144
-    		$Connection = new Connection();
145
-    		// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
144
+			$Connection = new Connection();
145
+			// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
146 146
 		$query = "ALTER TABLE `aircraft_modes` CHANGE `FirstCreated` `FirstCreated` timestamp DEFAULT CURRENT_TIMESTAMP";
147
-        	try {
148
-            	    $sth = $Connection->db->prepare($query);
149
-		    $sth->execute();
150
-    		} catch(PDOException $e) {
151
-		    return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
-    		}
153
-    		// Add image_source_website column to spotter_image
147
+			try {
148
+					$sth = $Connection->db->prepare($query);
149
+			$sth->execute();
150
+			} catch(PDOException $e) {
151
+			return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
+			}
153
+			// Add image_source_website column to spotter_image
154 154
 		$query = "ALTER TABLE `spotter_image` ADD `image_source_website` VARCHAR(999) NULL";
155
-        	try {
156
-            	    $sth = $Connection->db->prepare($query);
157
-		    $sth->execute();
158
-    		} catch(PDOException $e) {
159
-		    return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
-    		}
161
-    		$error = '';
155
+			try {
156
+					$sth = $Connection->db->prepare($query);
157
+			$sth->execute();
158
+			} catch(PDOException $e) {
159
+			return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
+			}
161
+			$error = '';
162 162
 		// Update schema_version to 4
163 163
 		$query = "UPDATE `config` SET `value` = '4' WHERE `name` = 'schema_version'";
164
-        	try {
165
-            	    $sth = $Connection->db->prepare($query);
166
-		    $sth->execute();
167
-    		} catch(PDOException $e) {
168
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
169
-    		}
164
+			try {
165
+					$sth = $Connection->db->prepare($query);
166
+			$sth->execute();
167
+			} catch(PDOException $e) {
168
+			return "error (update schema_version) : ".$e->getMessage()."\n";
169
+			}
170 170
 		return $error;
171 171
 	}
172 172
 	
173 173
 	private static function update_from_4() {
174
-    		$Connection = new Connection();
174
+			$Connection = new Connection();
175 175
 	
176
-    		$error = '';
177
-    		// Create table acars_label
176
+			$error = '';
177
+			// Create table acars_label
178 178
 		$error .= create_db::import_file('../db/acars_label.sql');
179 179
 		if ($error == '') {
180
-		    // Update schema_version to 5
181
-		    $query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
-        	    try {
183
-            		$sth = $Connection->db->prepare($query);
180
+			// Update schema_version to 5
181
+			$query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
+				try {
183
+					$sth = $Connection->db->prepare($query);
184 184
 			$sth->execute();
185
-    		    } catch(PDOException $e) {
185
+				} catch(PDOException $e) {
186 186
 			return "error (update schema_version) : ".$e->getMessage()."\n";
187
-    		    }
188
-    		}
187
+				}
188
+			}
189 189
 		return $error;
190 190
 	}
191 191
 
192 192
 	private static function update_from_5() {
193
-    		$Connection = new Connection();
194
-    		// Add columns to translation
193
+			$Connection = new Connection();
194
+			// Add columns to translation
195 195
 		$query = "ALTER TABLE `translation` ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP , ADD `date_modified` timestamp DEFAULT CURRENT_TIMESTAMP ;";
196
-        	try {
197
-            	    $sth = $Connection->db->prepare($query);
198
-		    $sth->execute();
199
-    		} catch(PDOException $e) {
200
-		    return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
-    		}
202
-    		// Add aircraft_shadow column to aircraft
203
-    		$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
-        	try {
205
-            	    $sth = $Connection->db->prepare($query);
206
-		    $sth->execute();
207
-    		} catch(PDOException $e) {
208
-		    return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
-    		}
210
-    		// Add aircraft_shadow column to spotter_live
211
-    		$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
-        	try {
213
-            	    $sth = $Connection->db->prepare($query);
214
-		    $sth->execute();
215
-    		} catch(PDOException $e) {
216
-		    return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
-    		}
218
-    		$error = '';
219
-    		// Update table aircraft
196
+			try {
197
+					$sth = $Connection->db->prepare($query);
198
+			$sth->execute();
199
+			} catch(PDOException $e) {
200
+			return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
+			}
202
+			// Add aircraft_shadow column to aircraft
203
+			$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
+			try {
205
+					$sth = $Connection->db->prepare($query);
206
+			$sth->execute();
207
+			} catch(PDOException $e) {
208
+			return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
+			}
210
+			// Add aircraft_shadow column to spotter_live
211
+			$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
+			try {
213
+					$sth = $Connection->db->prepare($query);
214
+			$sth->execute();
215
+			} catch(PDOException $e) {
216
+			return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
+			}
218
+			$error = '';
219
+			// Update table aircraft
220 220
 		$error .= create_db::import_file('../db/aircraft.sql');
221 221
 		$error .= create_db::import_file('../db/spotter_archive.sql');
222 222
 
223 223
 		// Update schema_version to 6
224 224
 		$query = "UPDATE `config` SET `value` = '6' WHERE `name` = 'schema_version'";
225
-        	try {
226
-            	    $sth = $Connection->db->prepare($query);
227
-		    $sth->execute();
228
-    		} catch(PDOException $e) {
229
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
230
-    		}
225
+			try {
226
+					$sth = $Connection->db->prepare($query);
227
+			$sth->execute();
228
+			} catch(PDOException $e) {
229
+			return "error (update schema_version) : ".$e->getMessage()."\n";
230
+			}
231 231
 		return $error;
232 232
 	}
233 233
 
234 234
 	private static function update_from_6() {
235
-    		$Connection = new Connection();
236
-    		if (!$Connection->indexExists('spotter_output','flightaware_id')) {
237
-    		    $query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
235
+			$Connection = new Connection();
236
+			if (!$Connection->indexExists('spotter_output','flightaware_id')) {
237
+				$query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
238 238
 			ALTER TABLE spotter_output ADD INDEX(date);
239 239
 			ALTER TABLE spotter_output ADD INDEX(ident);
240 240
 			ALTER TABLE spotter_live ADD INDEX(flightaware_id);
@@ -247,147 +247,147 @@  discard block
 block discarded – undo
247 247
 			ALTER TABLE aircraft ADD INDEX(icao);
248 248
 			ALTER TABLE airport ADD INDEX(icao);
249 249
 			ALTER TABLE translation ADD INDEX(Operator);";
250
-        	    try {
251
-            		$sth = $Connection->db->prepare($query);
250
+				try {
251
+					$sth = $Connection->db->prepare($query);
252 252
 			$sth->execute();
253
-    		    } catch(PDOException $e) {
253
+				} catch(PDOException $e) {
254 254
 			return "error (add some indexes) : ".$e->getMessage()."\n";
255
-    		    }
256
-    		}
257
-    		$error = '';
258
-    		// Update table countries
259
-    		if ($Connection->tableExists('airspace')) {
260
-    		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
255
+				}
256
+			}
257
+			$error = '';
258
+			// Update table countries
259
+			if ($Connection->tableExists('airspace')) {
260
+				$error .= update_db::update_countries();
261
+			if ($error != '') return $error;
262 262
 		}
263 263
 		// Update schema_version to 7
264 264
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
265
-        	try {
266
-            	    $sth = $Connection->db->prepare($query);
267
-		    $sth->execute();
268
-    		} catch(PDOException $e) {
269
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
270
-    		}
265
+			try {
266
+					$sth = $Connection->db->prepare($query);
267
+			$sth->execute();
268
+			} catch(PDOException $e) {
269
+			return "error (update schema_version) : ".$e->getMessage()."\n";
270
+			}
271 271
 		return $error;
272
-    	}
272
+		}
273 273
 
274 274
 	private static function update_from_7() {
275 275
 		global $globalDBname, $globalDBdriver;
276
-    		$Connection = new Connection();
277
-    		$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
276
+			$Connection = new Connection();
277
+			$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
278 278
     			ALTER TABLE spotter_output ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;";
279
-        	try {
280
-            	    $sth = $Connection->db->prepare($query);
281
-		    $sth->execute();
282
-    		} catch(PDOException $e) {
283
-		    return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
-    		}
285
-    		if ($globalDBdriver == 'mysql') {
286
-    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
-		    try {
288
-            		$sth = $Connection->db->prepare($query);
279
+			try {
280
+					$sth = $Connection->db->prepare($query);
281
+			$sth->execute();
282
+			} catch(PDOException $e) {
283
+			return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
+			}
285
+			if ($globalDBdriver == 'mysql') {
286
+				$query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
+			try {
288
+					$sth = $Connection->db->prepare($query);
289 289
 			$sth->execute();
290
-    		    } catch(PDOException $e) {
290
+				} catch(PDOException $e) {
291 291
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
292
-    		    }
293
-    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
294
-    		    if ($row['engine'] == 'ARCHIVE') {
292
+				}
293
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
294
+				if ($row['engine'] == 'ARCHIVE') {
295 295
 			$query = "CREATE TABLE copy LIKE spotter_archive; 
296 296
 				ALTER TABLE copy ENGINE=ARCHIVE;
297 297
 				ALTER TABLE copy ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
298 298
 				INSERT INTO copy SELECT *, '' as pilot_name, '' as pilot_id FROM spotter_archive ORDER BY `spotter_archive_id`;
299 299
 				DROP TABLE spotter_archive;
300 300
 				RENAME TABLE copy TO spotter_archive;";
301
-            	    } else {
302
-    			$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
-            	    }
304
-                } else {
305
-    		    $query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
-                }
307
-        	try {
308
-            	    $sth = $Connection->db->prepare($query);
309
-		    $sth->execute();
310
-    		} catch(PDOException $e) {
311
-		    return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
-    		}
301
+					} else {
302
+				$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
+					}
304
+				} else {
305
+				$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
+				}
307
+			try {
308
+					$sth = $Connection->db->prepare($query);
309
+			$sth->execute();
310
+			} catch(PDOException $e) {
311
+			return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
+			}
313 313
 
314
-    		$error = '';
315
-    		// Update table aircraft
314
+			$error = '';
315
+			// Update table aircraft
316 316
 		$error .= create_db::import_file('../db/source_location.sql');
317 317
 		if ($error != '') return $error;
318 318
 		// Update schema_version to 6
319 319
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320
-        	try {
321
-            	    $sth = $Connection->db->prepare($query);
322
-		    $sth->execute();
323
-    		} catch(PDOException $e) {
324
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
325
-    		}
320
+			try {
321
+					$sth = $Connection->db->prepare($query);
322
+			$sth->execute();
323
+			} catch(PDOException $e) {
324
+			return "error (update schema_version) : ".$e->getMessage()."\n";
325
+			}
326 326
 		return $error;
327 327
 	}
328 328
 
329 329
 	private static function update_from_8() {
330
-    		$Connection = new Connection();
331
-    		$error = '';
332
-    		// Update table aircraft
330
+			$Connection = new Connection();
331
+			$error = '';
332
+			// Update table aircraft
333 333
 		$error .= create_db::import_file('../db/notam.sql');
334 334
 		if ($error != '') return $error;
335 335
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 336
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 337
                         DELETE FROM config WHERE name = 'last_update_notam_db';
338 338
                         INSERT INTO config (name,value) VALUES ('last_update_notam_db',NOW());";
339
-        	try {
340
-            	    $sth = $Connection->db->prepare($query);
341
-		    $sth->execute();
342
-    		} catch(PDOException $e) {
343
-		    return "error (insert last_update values) : ".$e->getMessage()."\n";
344
-    		}
339
+			try {
340
+					$sth = $Connection->db->prepare($query);
341
+			$sth->execute();
342
+			} catch(PDOException $e) {
343
+			return "error (insert last_update values) : ".$e->getMessage()."\n";
344
+			}
345 345
 		$query = "UPDATE `config` SET `value` = '9' WHERE `name` = 'schema_version'";
346
-        	try {
347
-            	    $sth = $Connection->db->prepare($query);
348
-		    $sth->execute();
349
-    		} catch(PDOException $e) {
350
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
351
-    		}
346
+			try {
347
+					$sth = $Connection->db->prepare($query);
348
+			$sth->execute();
349
+			} catch(PDOException $e) {
350
+			return "error (update schema_version) : ".$e->getMessage()."\n";
351
+			}
352 352
 		return $error;
353 353
 	}
354 354
 
355 355
 	private static function update_from_9() {
356
-    		$Connection = new Connection();
357
-    		$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
356
+			$Connection = new Connection();
357
+			$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
358 358
     			ALTER TABLE spotter_output ADD verticalrate INT(11) NULL;";
359
-        	try {
360
-            	    $sth = $Connection->db->prepare($query);
361
-		    $sth->execute();
362
-    		} catch(PDOException $e) {
363
-		    return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
-    		}
359
+			try {
360
+					$sth = $Connection->db->prepare($query);
361
+			$sth->execute();
362
+			} catch(PDOException $e) {
363
+			return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
+			}
365 365
 		$error = '';
366
-    		// Update table atc
366
+			// Update table atc
367 367
 		$error .= create_db::import_file('../db/atc.sql');
368 368
 		if ($error != '') return $error;
369 369
 		
370 370
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371
-        	try {
372
-            	    $sth = $Connection->db->prepare($query);
373
-		    $sth->execute();
374
-    		} catch(PDOException $e) {
375
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
376
-    		}
371
+			try {
372
+					$sth = $Connection->db->prepare($query);
373
+			$sth->execute();
374
+			} catch(PDOException $e) {
375
+			return "error (update schema_version) : ".$e->getMessage()."\n";
376
+			}
377 377
 		return $error;
378 378
 	}
379 379
 
380 380
 	private static function update_from_10() {
381
-    		$Connection = new Connection();
382
-    		$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
-        	try {
384
-            	    $sth = $Connection->db->prepare($query);
385
-		    $sth->execute();
386
-    		} catch(PDOException $e) {
387
-		    return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
-    		}
381
+			$Connection = new Connection();
382
+			$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
+			try {
384
+					$sth = $Connection->db->prepare($query);
385
+			$sth->execute();
386
+			} catch(PDOException $e) {
387
+			return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
+			}
389 389
 		$error = '';
390
-    		// Add tables
390
+			// Add tables
391 391
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392 392
 		if ($error != '') return $error;
393 393
 		$error .= create_db::import_file('../db/metar.sql');
@@ -398,76 +398,76 @@  discard block
 block discarded – undo
398 398
 		if ($error != '') return $error;
399 399
 		
400 400
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401
-        	try {
402
-            	    $sth = $Connection->db->prepare($query);
403
-		    $sth->execute();
404
-    		} catch(PDOException $e) {
405
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
406
-    		}
401
+			try {
402
+					$sth = $Connection->db->prepare($query);
403
+			$sth->execute();
404
+			} catch(PDOException $e) {
405
+			return "error (update schema_version) : ".$e->getMessage()."\n";
406
+			}
407 407
 		return $error;
408 408
 	}
409 409
 
410 410
 	private static function update_from_11() {
411 411
 		global $globalDBdriver, $globalDBname;
412
-    		$Connection = new Connection();
413
-    		$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414
-        	try {
415
-            	    $sth = $Connection->db->prepare($query);
416
-		    $sth->execute();
417
-    		} catch(PDOException $e) {
418
-		    return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419
-    		}
420
-    		$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421
-        	try {
422
-            	    $sth = $Connection->db->prepare($query);
423
-		    $sth->execute();
424
-    		} catch(PDOException $e) {
425
-		    return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426
-    		}
427
-    		if ($globalDBdriver == 'mysql') {
428
-    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
429
-		    try {
430
-            		$sth = $Connection->db->prepare($query);
412
+			$Connection = new Connection();
413
+			$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414
+			try {
415
+					$sth = $Connection->db->prepare($query);
416
+			$sth->execute();
417
+			} catch(PDOException $e) {
418
+			return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419
+			}
420
+			$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421
+			try {
422
+					$sth = $Connection->db->prepare($query);
423
+			$sth->execute();
424
+			} catch(PDOException $e) {
425
+			return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426
+			}
427
+			if ($globalDBdriver == 'mysql') {
428
+				$query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
429
+			try {
430
+					$sth = $Connection->db->prepare($query);
431 431
 			$sth->execute();
432
-    		    } catch(PDOException $e) {
432
+				} catch(PDOException $e) {
433 433
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
434
-    		    }
435
-    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
436
-    		    if ($row['engine'] == 'ARCHIVE') {
434
+				}
435
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
436
+				if ($row['engine'] == 'ARCHIVE') {
437 437
 			$query = "CREATE TABLE copy LIKE spotter_archive; 
438 438
 				ALTER TABLE copy ENGINE=ARCHIVE;
439 439
 				ALTER TABLE copy ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE;
440 440
 				INSERT INTO copy SELECT *, '' as verticalrate, '' as format_source, '0' as ground FROM spotter_archive ORDER BY `spotter_archive_id`;
441 441
 				DROP TABLE spotter_archive;
442 442
 				RENAME TABLE copy TO spotter_archive;";
443
-            	    } else {
444
-    			$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445
-            	    }
446
-                } else {
447
-    		    $query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448
-                }
449
-        	try {
450
-            	    $sth = $Connection->db->prepare($query);
451
-		    $sth->execute();
452
-    		} catch(PDOException $e) {
453
-		    return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454
-    		}
443
+					} else {
444
+				$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445
+					}
446
+				} else {
447
+				$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448
+				}
449
+			try {
450
+					$sth = $Connection->db->prepare($query);
451
+			$sth->execute();
452
+			} catch(PDOException $e) {
453
+			return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454
+			}
455 455
 
456 456
 		$error = '';
457 457
 		
458 458
 		$query = "UPDATE `config` SET `value` = '12' WHERE `name` = 'schema_version'";
459
-        	try {
460
-            	    $sth = $Connection->db->prepare($query);
461
-		    $sth->execute();
462
-    		} catch(PDOException $e) {
463
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
464
-    		}
459
+			try {
460
+					$sth = $Connection->db->prepare($query);
461
+			$sth->execute();
462
+			} catch(PDOException $e) {
463
+			return "error (update schema_version) : ".$e->getMessage()."\n";
464
+			}
465 465
 		return $error;
466 466
 	}
467 467
 	private static function update_from_12() {
468
-    		$Connection = new Connection();
468
+			$Connection = new Connection();
469 469
 		$error = '';
470
-    		// Add tables
470
+			// Add tables
471 471
 		$error .= create_db::import_file('../db/stats.sql');
472 472
 		if ($error != '') return $error;
473 473
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
@@ -484,166 +484,166 @@  discard block
 block discarded – undo
484 484
 		if ($error != '') return $error;
485 485
 		
486 486
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487
-        	try {
488
-            	    $sth = $Connection->db->prepare($query);
489
-		    $sth->execute();
490
-    		} catch(PDOException $e) {
491
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
492
-    		}
487
+			try {
488
+					$sth = $Connection->db->prepare($query);
489
+			$sth->execute();
490
+			} catch(PDOException $e) {
491
+			return "error (update schema_version) : ".$e->getMessage()."\n";
492
+			}
493 493
 		return $error;
494 494
 	}
495 495
 
496 496
 	private static function update_from_13() {
497
-    		$Connection = new Connection();
498
-    		if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
-    			$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
497
+			$Connection = new Connection();
498
+			if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
+				$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
500 500
 			try {
501 501
 				$sth = $Connection->db->prepare($query);
502 502
 				$sth->execute();
503
-	    		} catch(PDOException $e) {
503
+				} catch(PDOException $e) {
504 504
 				return "error (update spotter_archive_output) : ".$e->getMessage()."\n";
505
-    			}
505
+				}
506 506
 		}
507
-    		$error = '';
507
+			$error = '';
508 508
 		$query = "UPDATE `config` SET `value` = '14' WHERE `name` = 'schema_version'";
509
-        	try {
510
-            	    $sth = $Connection->db->prepare($query);
511
-		    $sth->execute();
512
-    		} catch(PDOException $e) {
513
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
514
-    		}
509
+			try {
510
+					$sth = $Connection->db->prepare($query);
511
+			$sth->execute();
512
+			} catch(PDOException $e) {
513
+			return "error (update schema_version) : ".$e->getMessage()."\n";
514
+			}
515 515
 		return $error;
516 516
 	}
517 517
 
518 518
 	private static function update_from_14() {
519
-    		$Connection = new Connection();
519
+			$Connection = new Connection();
520 520
 		$error = '';
521
-    		// Add tables
522
-    		if (!$Connection->tableExists('stats_flight')) {
521
+			// Add tables
522
+			if (!$Connection->tableExists('stats_flight')) {
523 523
 			$error .= create_db::import_file('../db/stats_flight.sql');
524 524
 			if ($error != '') return $error;
525 525
 		}
526 526
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527
-        	try {
528
-            	    $sth = $Connection->db->prepare($query);
529
-		    $sth->execute();
530
-    		} catch(PDOException $e) {
531
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
532
-    		}
527
+			try {
528
+					$sth = $Connection->db->prepare($query);
529
+			$sth->execute();
530
+			} catch(PDOException $e) {
531
+			return "error (update schema_version) : ".$e->getMessage()."\n";
532
+			}
533 533
 		return $error;
534 534
 	}
535 535
 
536 536
 
537 537
 	private static function update_from_15() {
538
-    		$Connection = new Connection();
538
+			$Connection = new Connection();
539 539
 		$error = '';
540
-    		// Add tables
541
-    		$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542
-        	try {
543
-            	    $sth = $Connection->db->prepare($query);
544
-		    $sth->execute();
545
-    		} catch(PDOException $e) {
546
-		    return "error (update stats) : ".$e->getMessage()."\n";
547
-    		}
540
+			// Add tables
541
+			$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542
+			try {
543
+					$sth = $Connection->db->prepare($query);
544
+			$sth->execute();
545
+			} catch(PDOException $e) {
546
+			return "error (update stats) : ".$e->getMessage()."\n";
547
+			}
548 548
 		if ($error != '') return $error;
549 549
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550
-        	try {
551
-            	    $sth = $Connection->db->prepare($query);
552
-		    $sth->execute();
553
-    		} catch(PDOException $e) {
554
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
555
-    		}
550
+			try {
551
+					$sth = $Connection->db->prepare($query);
552
+			$sth->execute();
553
+			} catch(PDOException $e) {
554
+			return "error (update schema_version) : ".$e->getMessage()."\n";
555
+			}
556 556
 		return $error;
557 557
 	}
558 558
 
559 559
 	private static function update_from_16() {
560
-    		$Connection = new Connection();
560
+			$Connection = new Connection();
561 561
 		$error = '';
562
-    		// Add tables
563
-    		if (!$Connection->tableExists('stats_registration')) {
562
+			// Add tables
563
+			if (!$Connection->tableExists('stats_registration')) {
564 564
 			$error .= create_db::import_file('../db/stats_registration.sql');
565 565
 		}
566
-    		if (!$Connection->tableExists('stats_callsign')) {
566
+			if (!$Connection->tableExists('stats_callsign')) {
567 567
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 568
 		}
569 569
 		if ($error != '') return $error;
570 570
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571
-        	try {
572
-            	    $sth = $Connection->db->prepare($query);
573
-		    $sth->execute();
574
-    		} catch(PDOException $e) {
575
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
576
-    		}
571
+			try {
572
+					$sth = $Connection->db->prepare($query);
573
+			$sth->execute();
574
+			} catch(PDOException $e) {
575
+			return "error (update schema_version) : ".$e->getMessage()."\n";
576
+			}
577 577
 		return $error;
578 578
 	}
579 579
 
580 580
 	private static function update_from_17() {
581
-    		$Connection = new Connection();
581
+			$Connection = new Connection();
582 582
 		$error = '';
583
-    		// Add tables
584
-    		if (!$Connection->tableExists('stats_country')) {
583
+			// Add tables
584
+			if (!$Connection->tableExists('stats_country')) {
585 585
 			$error .= create_db::import_file('../db/stats_country.sql');
586 586
 		}
587 587
 		if ($error != '') return $error;
588 588
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589
-        	try {
590
-            	    $sth = $Connection->db->prepare($query);
591
-		    $sth->execute();
592
-    		} catch(PDOException $e) {
593
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
594
-    		}
589
+			try {
590
+					$sth = $Connection->db->prepare($query);
591
+			$sth->execute();
592
+			} catch(PDOException $e) {
593
+			return "error (update schema_version) : ".$e->getMessage()."\n";
594
+			}
595 595
 		return $error;
596 596
 	}
597 597
 	private static function update_from_18() {
598
-    		$Connection = new Connection();
598
+			$Connection = new Connection();
599 599
 		$error = '';
600
-    		// Modify stats_airport table
601
-    		if (!$Connection->checkColumnName('stats_airport','airport_name')) {
602
-    			$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603
-    	        	try {
604
-	            	    $sth = $Connection->db->prepare($query);
605
-			    $sth->execute();
606
-    			} catch(PDOException $e) {
607
-			    return "error (update stats) : ".$e->getMessage()."\n";
608
-    			}
609
-    		}
600
+			// Modify stats_airport table
601
+			if (!$Connection->checkColumnName('stats_airport','airport_name')) {
602
+				$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603
+					try {
604
+						$sth = $Connection->db->prepare($query);
605
+				$sth->execute();
606
+				} catch(PDOException $e) {
607
+				return "error (update stats) : ".$e->getMessage()."\n";
608
+				}
609
+			}
610 610
 		if ($error != '') return $error;
611 611
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612
-        	try {
613
-            	    $sth = $Connection->db->prepare($query);
614
-		    $sth->execute();
615
-    		} catch(PDOException $e) {
616
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
617
-    		}
612
+			try {
613
+					$sth = $Connection->db->prepare($query);
614
+			$sth->execute();
615
+			} catch(PDOException $e) {
616
+			return "error (update schema_version) : ".$e->getMessage()."\n";
617
+			}
618 618
 		return $error;
619 619
 	}
620 620
 
621 621
 	private static function update_from_19() {
622
-    		$Connection = new Connection();
622
+			$Connection = new Connection();
623 623
 		$error = '';
624
-    		// Update airport table
624
+			// Update airport table
625 625
 		$error .= create_db::import_file('../db/airport.sql');
626 626
 		if ($error != '') return 'Import airport.sql : '.$error;
627 627
 		// Remove primary key on Spotter_Archive
628 628
 		$query = "alter table spotter_archive drop spotter_archive_id";
629
-        	try {
630
-            	    $sth = $Connection->db->prepare($query);
631
-		    $sth->execute();
632
-    		} catch(PDOException $e) {
633
-		    return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634
-    		}
629
+			try {
630
+					$sth = $Connection->db->prepare($query);
631
+			$sth->execute();
632
+			} catch(PDOException $e) {
633
+			return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634
+			}
635 635
 		$query = "alter table spotter_archive add spotter_archive_id INT(11)";
636
-        	try {
637
-            	    $sth = $Connection->db->prepare($query);
638
-		    $sth->execute();
639
-    		} catch(PDOException $e) {
640
-		    return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641
-    		}
636
+			try {
637
+					$sth = $Connection->db->prepare($query);
638
+			$sth->execute();
639
+			} catch(PDOException $e) {
640
+			return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641
+			}
642 642
 		if (!$Connection->checkColumnName('spotter_archive','over_country')) {
643 643
 			// Add column over_country
644
-    			$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
644
+				$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
645 645
 			try {
646
-            			$sth = $Connection->db->prepare($query);
646
+						$sth = $Connection->db->prepare($query);
647 647
 				$sth->execute();
648 648
 			} catch(PDOException $e) {
649 649
 				return "error (add over_country) : ".$e->getMessage()."\n";
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 		}
652 652
 		if (!$Connection->checkColumnName('spotter_live','over_country')) {
653 653
 			// Add column over_country
654
-    			$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
654
+				$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
655 655
 			try {
656
-            			$sth = $Connection->db->prepare($query);
656
+						$sth = $Connection->db->prepare($query);
657 657
 				$sth->execute();
658 658
 			} catch(PDOException $e) {
659 659
 				return "error (add over_country) : ".$e->getMessage()."\n";
@@ -661,74 +661,74 @@  discard block
 block discarded – undo
661 661
 		}
662 662
 		if (!$Connection->checkColumnName('spotter_output','source_name')) {
663 663
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
664
-    			$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
664
+				$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
665 665
 			try {
666 666
 				$sth = $Connection->db->prepare($query);
667 667
 				$sth->execute();
668 668
 			} catch(PDOException $e) {
669 669
 				return "error (add source_name column) : ".$e->getMessage()."\n";
670
-    			}
671
-    		}
670
+				}
671
+			}
672 672
 		if (!$Connection->checkColumnName('spotter_live','source_name')) {
673 673
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
674
-    			$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
674
+				$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
675 675
 			try {
676 676
 				$sth = $Connection->db->prepare($query);
677 677
 				$sth->execute();
678 678
 			} catch(PDOException $e) {
679 679
 				return "error (add source_name column) : ".$e->getMessage()."\n";
680
-    			}
681
-    		}
680
+				}
681
+			}
682 682
 		if (!$Connection->checkColumnName('spotter_archive_output','source_name')) {
683 683
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
684
-    			$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
684
+				$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
685 685
 			try {
686 686
 				$sth = $Connection->db->prepare($query);
687 687
 				$sth->execute();
688 688
 			} catch(PDOException $e) {
689 689
 				return "error (add source_name column) : ".$e->getMessage()."\n";
690
-    			}
691
-    		}
690
+				}
691
+			}
692 692
 		if (!$Connection->checkColumnName('spotter_archive','source_name')) {
693 693
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
694
-    			$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
694
+				$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
695 695
 			try {
696 696
 				$sth = $Connection->db->prepare($query);
697 697
 				$sth->execute();
698 698
 			} catch(PDOException $e) {
699 699
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700
-    			}
701
-    		}
700
+				}
701
+			}
702 702
 		if ($error != '') return $error;
703 703
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704
-        	try {
705
-            	    $sth = $Connection->db->prepare($query);
706
-		    $sth->execute();
707
-    		} catch(PDOException $e) {
708
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
709
-    		}
704
+			try {
705
+					$sth = $Connection->db->prepare($query);
706
+			$sth->execute();
707
+			} catch(PDOException $e) {
708
+			return "error (update schema_version) : ".$e->getMessage()."\n";
709
+			}
710 710
 		return $error;
711 711
 	}
712 712
 
713 713
 	private static function update_from_20() {
714 714
 		global $globalIVAO, $globalVATSIM, $globalphpVMS;
715
-    		$Connection = new Connection();
715
+			$Connection = new Connection();
716 716
 		$error = '';
717
-    		// Update airline table
718
-    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
717
+			// Update airline table
718
+			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 719
 			$error .= create_db::import_file('../db/airlines.sql');
720 720
 			if ($error != '') return 'Import airlines.sql : '.$error;
721 721
 		}
722 722
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 723
 			// Add column over_country
724
-    			$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725
-        		try {
724
+				$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725
+				try {
726 726
 				$sth = $Connection->db->prepare($query);
727 727
 				$sth->execute();
728 728
 			} catch(PDOException $e) {
729 729
 				return "error (add over_country) : ".$e->getMessage()."\n";
730
-    			}
731
-    		}
730
+				}
731
+			}
732 732
 		if ($error != '') return $error;
733 733
 		/*
734 734
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 		}
739 739
 		*/
740 740
 		$query = "UPDATE `config` SET `value` = '21' WHERE `name` = 'schema_version'";
741
-        	try {
742
-            	    $sth = $Connection->db->prepare($query);
743
-		    $sth->execute();
744
-    		} catch(PDOException $e) {
745
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
746
-    		}
741
+			try {
742
+					$sth = $Connection->db->prepare($query);
743
+			$sth->execute();
744
+			} catch(PDOException $e) {
745
+			return "error (update schema_version) : ".$e->getMessage()."\n";
746
+			}
747 747
 		return $error;
748 748
 	}
749 749
 
@@ -762,35 +762,35 @@  discard block
 block discarded – undo
762 762
 			if ($error != '') return $error;
763 763
 		}
764 764
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765
-        	try {
766
-            	    $sth = $Connection->db->prepare($query);
767
-		    $sth->execute();
768
-    		} catch(PDOException $e) {
769
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
770
-    		}
765
+			try {
766
+					$sth = $Connection->db->prepare($query);
767
+			$sth->execute();
768
+			} catch(PDOException $e) {
769
+			return "error (update schema_version) : ".$e->getMessage()."\n";
770
+			}
771 771
 		return $error;
772 772
 	}
773 773
 
774 774
 	private static function update_from_22() {
775 775
 		global $globalDBdriver;
776
-    		$Connection = new Connection();
776
+			$Connection = new Connection();
777 777
 		$error = '';
778 778
 		// Add table stats polar
779
-    		if (!$Connection->tableExists('stats_source')) {
779
+			if (!$Connection->tableExists('stats_source')) {
780 780
 			if ($globalDBdriver == 'mysql') {
781
-    				$error .= create_db::import_file('../db/stats_source.sql');
781
+					$error .= create_db::import_file('../db/stats_source.sql');
782 782
 			} else {
783 783
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 784
 			}
785 785
 			if ($error != '') return $error;
786 786
 		}
787 787
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788
-        	try {
789
-            	    $sth = $Connection->db->prepare($query);
790
-		    $sth->execute();
791
-    		} catch(PDOException $e) {
792
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
793
-    		}
788
+			try {
789
+					$sth = $Connection->db->prepare($query);
790
+			$sth->execute();
791
+			} catch(PDOException $e) {
792
+			return "error (update schema_version) : ".$e->getMessage()."\n";
793
+			}
794 794
 		return $error;
795 795
 	}
796 796
 
@@ -821,14 +821,14 @@  discard block
 block discarded – undo
821 821
 		}
822 822
 		if (!$Connection->checkColumnName('stats_aircraft','aircraft_manufacturer')) {
823 823
 			// Add aircraft_manufacturer to stats_aircraft
824
-    			$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
824
+				$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
825 825
 			try {
826 826
 				$sth = $Connection->db->prepare($query);
827 827
 				$sth->execute();
828 828
 			} catch(PDOException $e) {
829 829
 				return "error (add aircraft_manufacturer column) : ".$e->getMessage()."\n";
830
-    			}
831
-    		}
830
+				}
831
+			}
832 832
 		
833 833
 		$query = "UPDATE config SET value = '24' WHERE name = 'schema_version'";
834 834
 		try {
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 			} catch(PDOException $e) {
1177 1177
 				return "error (add index latitude,longitude on spotter_live) : ".$e->getMessage()."\n";
1178 1178
 			}
1179
-                }
1179
+				}
1180 1180
 		if (!$Connection->checkColumnName('aircraft','mfr')) {
1181 1181
 			// Add mfr to aircraft
1182 1182
 			$query = "ALTER TABLE aircraft ADD mfr VARCHAR(255) NULL";
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 			} catch(PDOException $e) {
1251 1251
 				return "error (add index ref on notam) : ".$e->getMessage()."\n";
1252 1252
 			}
1253
-                }
1253
+				}
1254 1254
 		if (!$Connection->indexExists('accidents','registration_idx')) {
1255 1255
 			// Add index key
1256 1256
 			$query = "create index registration_idx on accidents (registration)";
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 			} catch(PDOException $e) {
1261 1261
 				return "error (add index registration on accidents) : ".$e->getMessage()."\n";
1262 1262
 			}
1263
-                }
1263
+				}
1264 1264
 		if (!$Connection->indexExists('accidents','rdts')) {
1265 1265
 			// Add index key
1266 1266
 			$query = "create index rdts on accidents (registration,date,type,source)";
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
 			} catch(PDOException $e) {
1271 1271
 				return "error (add index registration, date, type & source on accidents) : ".$e->getMessage()."\n";
1272 1272
 			}
1273
-                }
1273
+				}
1274 1274
 
1275 1275
 		$query = "UPDATE config SET value = '31' WHERE name = 'schema_version'";
1276 1276
 		try {
@@ -1562,7 +1562,7 @@  discard block
 block discarded – undo
1562 1562
 			} catch(PDOException $e) {
1563 1563
 				return "error (add index type on accidents) : ".$e->getMessage()."\n";
1564 1564
 			}
1565
-                }
1565
+				}
1566 1566
 		$query = "UPDATE config SET value = '36' WHERE name = 'schema_version'";
1567 1567
 		try {
1568 1568
 			$sth = $Connection->db->prepare($query);
@@ -1574,169 +1574,169 @@  discard block
 block discarded – undo
1574 1574
 	}
1575 1575
 
1576 1576
 
1577
-    	public static function check_version($update = false) {
1578
-    	    global $globalDBname;
1579
-    	    $version = 0;
1580
-    	    $Connection = new Connection();
1581
-    	    if ($Connection->tableExists('aircraft')) {
1582
-    		if (!$Connection->tableExists('config')) {
1583
-    		    $version = '1';
1584
-    		    if ($update) return self::update_from_1();
1585
-    		    else return $version;
1577
+		public static function check_version($update = false) {
1578
+			global $globalDBname;
1579
+			$version = 0;
1580
+			$Connection = new Connection();
1581
+			if ($Connection->tableExists('aircraft')) {
1582
+			if (!$Connection->tableExists('config')) {
1583
+				$version = '1';
1584
+				if ($update) return self::update_from_1();
1585
+				else return $version;
1586 1586
 		} else {
1587
-    		    $Connection = new Connection();
1588
-		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
1589
-		    try {
1590
-            		$sth = $Connection->db->prepare($query);
1591
-		        $sth->execute();
1592
-		    } catch(PDOException $e) {
1587
+				$Connection = new Connection();
1588
+			$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
1589
+			try {
1590
+					$sth = $Connection->db->prepare($query);
1591
+				$sth->execute();
1592
+			} catch(PDOException $e) {
1593 1593
 			return "error : ".$e->getMessage()."\n";
1594
-    		    }
1595
-    		    $result = $sth->fetch(PDO::FETCH_ASSOC);
1596
-    		    if ($update) {
1597
-    			if ($result['value'] == '2') {
1598
-    			    $error = self::update_from_2();
1599
-    			    if ($error != '') return $error;
1600
-    			    else return self::check_version(true);
1601
-    			} elseif ($result['value'] == '3') {
1602
-    			    $error = self::update_from_3();
1603
-    			    if ($error != '') return $error;
1604
-    			    else return self::check_version(true);
1605
-    			} elseif ($result['value'] == '4') {
1606
-    			    $error = self::update_from_4();
1607
-    			    if ($error != '') return $error;
1608
-    			    else return self::check_version(true);
1609
-    			} elseif ($result['value'] == '5') {
1610
-    			    $error = self::update_from_5();
1611
-    			    if ($error != '') return $error;
1612
-    			    else return self::check_version(true);
1613
-    			} elseif ($result['value'] == '6') {
1614
-    			    $error = self::update_from_6();
1615
-    			    if ($error != '') return $error;
1616
-    			    else return self::check_version(true);
1617
-    			} elseif ($result['value'] == '7') {
1618
-    			    $error = self::update_from_7();
1619
-    			    if ($error != '') return $error;
1620
-    			    else return self::check_version(true);
1621
-    			} elseif ($result['value'] == '8') {
1622
-    			    $error = self::update_from_8();
1623
-    			    if ($error != '') return $error;
1624
-    			    else return self::check_version(true);
1625
-    			} elseif ($result['value'] == '9') {
1626
-    			    $error = self::update_from_9();
1627
-    			    if ($error != '') return $error;
1628
-    			    else return self::check_version(true);
1629
-    			} elseif ($result['value'] == '10') {
1630
-    			    $error = self::update_from_10();
1631
-    			    if ($error != '') return $error;
1632
-    			    else return self::check_version(true);
1633
-    			} elseif ($result['value'] == '11') {
1634
-    			    $error = self::update_from_11();
1635
-    			    if ($error != '') return $error;
1636
-    			    else return self::check_version(true);
1637
-    			} elseif ($result['value'] == '12') {
1638
-    			    $error = self::update_from_12();
1639
-    			    if ($error != '') return $error;
1640
-    			    else return self::check_version(true);
1641
-    			} elseif ($result['value'] == '13') {
1642
-    			    $error = self::update_from_13();
1643
-    			    if ($error != '') return $error;
1644
-    			    else return self::check_version(true);
1645
-    			} elseif ($result['value'] == '14') {
1646
-    			    $error = self::update_from_14();
1647
-    			    if ($error != '') return $error;
1648
-    			    else return self::check_version(true);
1649
-    			} elseif ($result['value'] == '15') {
1650
-    			    $error = self::update_from_15();
1651
-    			    if ($error != '') return $error;
1652
-    			    else return self::check_version(true);
1653
-    			} elseif ($result['value'] == '16') {
1654
-    			    $error = self::update_from_16();
1655
-    			    if ($error != '') return $error;
1656
-    			    else return self::check_version(true);
1657
-    			} elseif ($result['value'] == '17') {
1658
-    			    $error = self::update_from_17();
1659
-    			    if ($error != '') return $error;
1660
-    			    else return self::check_version(true);
1661
-    			} elseif ($result['value'] == '18') {
1662
-    			    $error = self::update_from_18();
1663
-    			    if ($error != '') return $error;
1664
-    			    else return self::check_version(true);
1665
-    			} elseif ($result['value'] == '19') {
1666
-    			    $error = self::update_from_19();
1667
-    			    if ($error != '') return $error;
1668
-    			    else return self::check_version(true);
1669
-    			} elseif ($result['value'] == '20') {
1670
-    			    $error = self::update_from_20();
1671
-    			    if ($error != '') return $error;
1672
-    			    else return self::check_version(true);
1673
-    			} elseif ($result['value'] == '21') {
1674
-    			    $error = self::update_from_21();
1675
-    			    if ($error != '') return $error;
1676
-    			    else return self::check_version(true);
1677
-    			} elseif ($result['value'] == '22') {
1678
-    			    $error = self::update_from_22();
1679
-    			    if ($error != '') return $error;
1680
-    			    else return self::check_version(true);
1681
-    			} elseif ($result['value'] == '23') {
1682
-    			    $error = self::update_from_23();
1683
-    			    if ($error != '') return $error;
1684
-    			    else return self::check_version(true);
1685
-    			} elseif ($result['value'] == '24') {
1686
-    			    $error = self::update_from_24();
1687
-    			    if ($error != '') return $error;
1688
-    			    else return self::check_version(true);
1689
-    			} elseif ($result['value'] == '25') {
1690
-    			    $error = self::update_from_25();
1691
-    			    if ($error != '') return $error;
1692
-    			    else return self::check_version(true);
1693
-    			} elseif ($result['value'] == '26') {
1694
-    			    $error = self::update_from_26();
1695
-    			    if ($error != '') return $error;
1696
-    			    else return self::check_version(true);
1697
-    			} elseif ($result['value'] == '27') {
1698
-    			    $error = self::update_from_27();
1699
-    			    if ($error != '') return $error;
1700
-    			    else return self::check_version(true);
1701
-    			} elseif ($result['value'] == '28') {
1702
-    			    $error = self::update_from_28();
1703
-    			    if ($error != '') return $error;
1704
-    			    else return self::check_version(true);
1705
-    			} elseif ($result['value'] == '29') {
1706
-    			    $error = self::update_from_29();
1707
-    			    if ($error != '') return $error;
1708
-    			    else return self::check_version(true);
1709
-    			} elseif ($result['value'] == '30') {
1710
-    			    $error = self::update_from_30();
1711
-    			    if ($error != '') return $error;
1712
-    			    else return self::check_version(true);
1713
-    			} elseif ($result['value'] == '31') {
1714
-    			    $error = self::update_from_31();
1715
-    			    if ($error != '') return $error;
1716
-    			    else return self::check_version(true);
1717
-    			} elseif ($result['value'] == '32') {
1718
-    			    $error = self::update_from_32();
1719
-    			    if ($error != '') return $error;
1720
-    			    else return self::check_version(true);
1721
-    			} elseif ($result['value'] == '33') {
1722
-    			    $error = self::update_from_33();
1723
-    			    if ($error != '') return $error;
1724
-    			    else return self::check_version(true);
1725
-    			} elseif ($result['value'] == '34') {
1726
-    			    $error = self::update_from_34();
1727
-    			    if ($error != '') return $error;
1728
-    			    else return self::check_version(true);
1729
-    			} elseif ($result['value'] == '35') {
1730
-    			    $error = self::update_from_35();
1731
-    			    if ($error != '') return $error;
1732
-    			    else return self::check_version(true);
1733
-    			} else return '';
1734
-    		    }
1735
-    		    else return $result['value'];
1594
+				}
1595
+				$result = $sth->fetch(PDO::FETCH_ASSOC);
1596
+				if ($update) {
1597
+				if ($result['value'] == '2') {
1598
+					$error = self::update_from_2();
1599
+					if ($error != '') return $error;
1600
+					else return self::check_version(true);
1601
+				} elseif ($result['value'] == '3') {
1602
+					$error = self::update_from_3();
1603
+					if ($error != '') return $error;
1604
+					else return self::check_version(true);
1605
+				} elseif ($result['value'] == '4') {
1606
+					$error = self::update_from_4();
1607
+					if ($error != '') return $error;
1608
+					else return self::check_version(true);
1609
+				} elseif ($result['value'] == '5') {
1610
+					$error = self::update_from_5();
1611
+					if ($error != '') return $error;
1612
+					else return self::check_version(true);
1613
+				} elseif ($result['value'] == '6') {
1614
+					$error = self::update_from_6();
1615
+					if ($error != '') return $error;
1616
+					else return self::check_version(true);
1617
+				} elseif ($result['value'] == '7') {
1618
+					$error = self::update_from_7();
1619
+					if ($error != '') return $error;
1620
+					else return self::check_version(true);
1621
+				} elseif ($result['value'] == '8') {
1622
+					$error = self::update_from_8();
1623
+					if ($error != '') return $error;
1624
+					else return self::check_version(true);
1625
+				} elseif ($result['value'] == '9') {
1626
+					$error = self::update_from_9();
1627
+					if ($error != '') return $error;
1628
+					else return self::check_version(true);
1629
+				} elseif ($result['value'] == '10') {
1630
+					$error = self::update_from_10();
1631
+					if ($error != '') return $error;
1632
+					else return self::check_version(true);
1633
+				} elseif ($result['value'] == '11') {
1634
+					$error = self::update_from_11();
1635
+					if ($error != '') return $error;
1636
+					else return self::check_version(true);
1637
+				} elseif ($result['value'] == '12') {
1638
+					$error = self::update_from_12();
1639
+					if ($error != '') return $error;
1640
+					else return self::check_version(true);
1641
+				} elseif ($result['value'] == '13') {
1642
+					$error = self::update_from_13();
1643
+					if ($error != '') return $error;
1644
+					else return self::check_version(true);
1645
+				} elseif ($result['value'] == '14') {
1646
+					$error = self::update_from_14();
1647
+					if ($error != '') return $error;
1648
+					else return self::check_version(true);
1649
+				} elseif ($result['value'] == '15') {
1650
+					$error = self::update_from_15();
1651
+					if ($error != '') return $error;
1652
+					else return self::check_version(true);
1653
+				} elseif ($result['value'] == '16') {
1654
+					$error = self::update_from_16();
1655
+					if ($error != '') return $error;
1656
+					else return self::check_version(true);
1657
+				} elseif ($result['value'] == '17') {
1658
+					$error = self::update_from_17();
1659
+					if ($error != '') return $error;
1660
+					else return self::check_version(true);
1661
+				} elseif ($result['value'] == '18') {
1662
+					$error = self::update_from_18();
1663
+					if ($error != '') return $error;
1664
+					else return self::check_version(true);
1665
+				} elseif ($result['value'] == '19') {
1666
+					$error = self::update_from_19();
1667
+					if ($error != '') return $error;
1668
+					else return self::check_version(true);
1669
+				} elseif ($result['value'] == '20') {
1670
+					$error = self::update_from_20();
1671
+					if ($error != '') return $error;
1672
+					else return self::check_version(true);
1673
+				} elseif ($result['value'] == '21') {
1674
+					$error = self::update_from_21();
1675
+					if ($error != '') return $error;
1676
+					else return self::check_version(true);
1677
+				} elseif ($result['value'] == '22') {
1678
+					$error = self::update_from_22();
1679
+					if ($error != '') return $error;
1680
+					else return self::check_version(true);
1681
+				} elseif ($result['value'] == '23') {
1682
+					$error = self::update_from_23();
1683
+					if ($error != '') return $error;
1684
+					else return self::check_version(true);
1685
+				} elseif ($result['value'] == '24') {
1686
+					$error = self::update_from_24();
1687
+					if ($error != '') return $error;
1688
+					else return self::check_version(true);
1689
+				} elseif ($result['value'] == '25') {
1690
+					$error = self::update_from_25();
1691
+					if ($error != '') return $error;
1692
+					else return self::check_version(true);
1693
+				} elseif ($result['value'] == '26') {
1694
+					$error = self::update_from_26();
1695
+					if ($error != '') return $error;
1696
+					else return self::check_version(true);
1697
+				} elseif ($result['value'] == '27') {
1698
+					$error = self::update_from_27();
1699
+					if ($error != '') return $error;
1700
+					else return self::check_version(true);
1701
+				} elseif ($result['value'] == '28') {
1702
+					$error = self::update_from_28();
1703
+					if ($error != '') return $error;
1704
+					else return self::check_version(true);
1705
+				} elseif ($result['value'] == '29') {
1706
+					$error = self::update_from_29();
1707
+					if ($error != '') return $error;
1708
+					else return self::check_version(true);
1709
+				} elseif ($result['value'] == '30') {
1710
+					$error = self::update_from_30();
1711
+					if ($error != '') return $error;
1712
+					else return self::check_version(true);
1713
+				} elseif ($result['value'] == '31') {
1714
+					$error = self::update_from_31();
1715
+					if ($error != '') return $error;
1716
+					else return self::check_version(true);
1717
+				} elseif ($result['value'] == '32') {
1718
+					$error = self::update_from_32();
1719
+					if ($error != '') return $error;
1720
+					else return self::check_version(true);
1721
+				} elseif ($result['value'] == '33') {
1722
+					$error = self::update_from_33();
1723
+					if ($error != '') return $error;
1724
+					else return self::check_version(true);
1725
+				} elseif ($result['value'] == '34') {
1726
+					$error = self::update_from_34();
1727
+					if ($error != '') return $error;
1728
+					else return self::check_version(true);
1729
+				} elseif ($result['value'] == '35') {
1730
+					$error = self::update_from_35();
1731
+					if ($error != '') return $error;
1732
+					else return self::check_version(true);
1733
+				} else return '';
1734
+				}
1735
+				else return $result['value'];
1736 1736
 		}
1737 1737
 		
1738
-	    } else return $version;
1739
-    	}
1738
+		} else return $version;
1739
+		}
1740 1740
     	
1741 1741
 }
1742 1742
 //echo update_schema::check_version();
Please login to merge, or discard this patch.