Completed
Push — master ( d8c574...a11679 )
by Yannick
07:12
created
scripts/daemon-spotter.php 1 patch
Indentation   +551 added lines, -551 removed lines patch added patch discarded remove patch
@@ -18,26 +18,26 @@  discard block
 block discarded – undo
18 18
 // Check if schema is at latest version
19 19
 $Connection = new Connection();
20 20
 if ($Connection->latest() === false) {
21
-    echo "You MUST update to latest schema. Run install/index.php";
22
-    exit();
21
+	echo "You MUST update to latest schema. Run install/index.php";
22
+	exit();
23 23
 }
24 24
 
25 25
 
26 26
 // This is to be compatible with old version of settings.php
27 27
 if (!isset($globalSources)) {
28
-    if (isset($globalSBS1Hosts)) {
29
-        //$hosts = $globalSBS1Hosts;
30
-        foreach ($globalSBS1Hosts as $host) {
31
-	    $globalSources[] = array('host' => $host);
32
-    	}
33
-    } else {
34
-        if (!isset($globalSBS1Host)) {
35
-	    echo '$globalSBS1Host MUST be defined !';
36
-	    die;
28
+	if (isset($globalSBS1Hosts)) {
29
+		//$hosts = $globalSBS1Hosts;
30
+		foreach ($globalSBS1Hosts as $host) {
31
+		$globalSources[] = array('host' => $host);
32
+		}
33
+	} else {
34
+		if (!isset($globalSBS1Host)) {
35
+		echo '$globalSBS1Host MUST be defined !';
36
+		die;
37 37
 	}
38 38
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
39 39
 	$globalSources[] = array('host' => $globalSBS1Host.':'.$globalSBS1Port);
40
-    }
40
+	}
41 41
 }
42 42
 
43 43
 $options = getopt('s::',array('source::','server','idsource::'));
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 if (isset($options['idsource'])) $id_source = $options['idsource'];
50 50
 else $id_source = 1;
51 51
 if (isset($globalServer) && $globalServer) {
52
-    if ($globalDebug) echo "Using Server Mode\n";
53
-    $SI=new SpotterServer();
52
+	if ($globalDebug) echo "Using Server Mode\n";
53
+	$SI=new SpotterServer();
54 54
 } else $SI=new SpotterImport($Connection->db);
55 55
 //$APRS=new APRS($Connection->db);
56 56
 $SBS=new SBS($Connection->db);
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 //$servertz = system('date +%Z');
60 60
 // signal handler - playing nice with sockets and dump1090
61 61
 if (function_exists('pcntl_fork')) {
62
-    pcntl_signal(SIGINT,  function($signo) {
63
-        global $sockets;
64
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
65
-        die("Bye!\n");
66
-    });
67
-    pcntl_signal_dispatch();
62
+	pcntl_signal(SIGINT,  function($signo) {
63
+		global $sockets;
64
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
65
+		die("Bye!\n");
66
+	});
67
+	pcntl_signal_dispatch();
68 68
 }
69 69
 
70 70
 // let's try and connect
@@ -72,125 +72,125 @@  discard block
 block discarded – undo
72 72
 $use_aprs = false;
73 73
 
74 74
 function create_socket($host, $port, &$errno, &$errstr) {
75
-    $ip = gethostbyname($host);
76
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
77
-    $r = @socket_connect($s, $ip, $port);
78
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
79
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
80
-        return $s;
81
-    }
82
-    $errno = socket_last_error($s);
83
-    $errstr = socket_strerror($errno);
84
-    socket_close($s);
85
-    return false;
75
+	$ip = gethostbyname($host);
76
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
77
+	$r = @socket_connect($s, $ip, $port);
78
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
79
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
80
+		return $s;
81
+	}
82
+	$errno = socket_last_error($s);
83
+	$errstr = socket_strerror($errno);
84
+	socket_close($s);
85
+	return false;
86 86
 }
87 87
 
88 88
 function connect_all($hosts) {
89
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
-    global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
91
-    foreach ($hosts as $id => $value) {
89
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
90
+	global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
91
+	foreach ($hosts as $id => $value) {
92 92
 	$host = $value['host'];
93 93
 	$globalSources[$id]['last_exec'] = 0;
94 94
 	// Here we check type of source(s)
95 95
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
96
-            if (preg_match('/deltadb.txt$/i',$host)) {
97
-        	//$formats[$id] = 'deltadbtxt';
98
-        	$globalSources[$id]['format'] = 'deltadbtxt';
99
-        	//$last_exec['deltadbtxt'] = 0;
100
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
101
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
102
-        	//$formats[$id] = 'vatsimtxt';
103
-        	$globalSources[$id]['format'] = 'vatsimtxt';
104
-        	//$last_exec['vatsimtxt'] = 0;
105
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
106
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
107
-        	//$formats[$id] = 'aircraftlistjson';
108
-        	$$globalSources[$id]['format'] = 'aircraftlistjson';
109
-        	//$last_exec['aircraftlistjson'] = 0;
110
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
111
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
112
-        	//$formats[$id] = 'radarvirtueljson';
113
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
114
-        	//$last_exec['radarvirtueljson'] = 0;
115
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
116
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
117
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118
-        	    exit(0);
119
-        	}
120
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
121
-        	//$formats[$id] = 'planeupdatefaa';
122
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
123
-        	//$last_exec['planeupdatefaa'] = 0;
124
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
125
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
126
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127
-        	    exit(0);
128
-        	}
129
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
130
-        	//$formats[$id] = 'phpvmacars';
131
-        	$globalSources[$id]['format'] = 'phpvmacars';
132
-        	//$last_exec['phpvmacars'] = 0;
133
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
134
-            } else if (preg_match('/whazzup/i',$host)) {
135
-        	//$formats[$id] = 'whazzup';
136
-        	$globalSources[$id]['format'] = 'whazzup';
137
-        	//$last_exec['whazzup'] = 0;
138
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
139
-            } else if (preg_match('/recentpireps/i',$host)) {
140
-        	//$formats[$id] = 'pirepsjson';
141
-        	$globalSources[$id]['format'] = 'pirepsjson';
142
-        	//$last_exec['pirepsjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
144
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
145
-        	//$formats[$id] = 'fr24json';
146
-        	$globalSources[$id]['format'] = 'fr24json';
147
-        	//$last_exec['fr24json'] = 0;
148
-        	if ($globalDebug) echo "Connect to fr24 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('/10001/',$host)) {
154
-            } else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
155
-        	//$formats[$id] = 'tsv';
156
-        	$globalSources[$id]['format'] = 'tsv';
157
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
158
-            }
159
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
160
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
161
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162
-	    $hostport = explode(':',$host);
163
-	    if (isset($hostport[1])) $port = $hostport[1];
164
-	    else $port = $globalSources[$id]['port'];
165
-    	    $s = create_socket($host,$port, $errno, $errstr);
166
-	    if ($s) {
167
-    	        $sockets[$id] = $s;
168
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
169
-		    if (preg_match('/aprs/',$host)) {
96
+			if (preg_match('/deltadb.txt$/i',$host)) {
97
+			//$formats[$id] = 'deltadbtxt';
98
+			$globalSources[$id]['format'] = 'deltadbtxt';
99
+			//$last_exec['deltadbtxt'] = 0;
100
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
101
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
102
+			//$formats[$id] = 'vatsimtxt';
103
+			$globalSources[$id]['format'] = 'vatsimtxt';
104
+			//$last_exec['vatsimtxt'] = 0;
105
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
106
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
107
+			//$formats[$id] = 'aircraftlistjson';
108
+			$$globalSources[$id]['format'] = 'aircraftlistjson';
109
+			//$last_exec['aircraftlistjson'] = 0;
110
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
111
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
112
+			//$formats[$id] = 'radarvirtueljson';
113
+			$globalSources[$id]['format'] = 'radarvirtueljson';
114
+			//$last_exec['radarvirtueljson'] = 0;
115
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
116
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
117
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
118
+				exit(0);
119
+			}
120
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
121
+			//$formats[$id] = 'planeupdatefaa';
122
+			$globalSources[$id]['format'] = 'planeupdatefaa';
123
+			//$last_exec['planeupdatefaa'] = 0;
124
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
125
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
126
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
127
+				exit(0);
128
+			}
129
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
130
+			//$formats[$id] = 'phpvmacars';
131
+			$globalSources[$id]['format'] = 'phpvmacars';
132
+			//$last_exec['phpvmacars'] = 0;
133
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
134
+			} else if (preg_match('/whazzup/i',$host)) {
135
+			//$formats[$id] = 'whazzup';
136
+			$globalSources[$id]['format'] = 'whazzup';
137
+			//$last_exec['whazzup'] = 0;
138
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
139
+			} else if (preg_match('/recentpireps/i',$host)) {
140
+			//$formats[$id] = 'pirepsjson';
141
+			$globalSources[$id]['format'] = 'pirepsjson';
142
+			//$last_exec['pirepsjson'] = 0;
143
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
144
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
145
+			//$formats[$id] = 'fr24json';
146
+			$globalSources[$id]['format'] = 'fr24json';
147
+			//$last_exec['fr24json'] = 0;
148
+			if ($globalDebug) echo "Connect to fr24 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('/10001/',$host)) {
154
+			} else if (preg_match('/10001/',$host) || $globalSources[$id]['port'] == '10001') {
155
+			//$formats[$id] = 'tsv';
156
+			$globalSources[$id]['format'] = 'tsv';
157
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
158
+			}
159
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
160
+			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
161
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
162
+		$hostport = explode(':',$host);
163
+		if (isset($hostport[1])) $port = $hostport[1];
164
+		else $port = $globalSources[$id]['port'];
165
+			$s = create_socket($host,$port, $errno, $errstr);
166
+		if ($s) {
167
+				$sockets[$id] = $s;
168
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
169
+			if (preg_match('/aprs/',$host)) {
170 170
 			//$formats[$id] = 'aprs';
171 171
 			$globalSources[$id]['format'] = 'aprs';
172 172
 			//$aprs_connect = 0;
173 173
 			//$use_aprs = true;
174
-    		    } elseif ($port == '10001') {
175
-        		//$formats[$id] = 'tsv';
176
-        		$globalSources[$id]['format'] = 'tsv';
177
-		    } elseif ($port == '30002') {
178
-        		//$formats[$id] = 'raw';
179
-        		$globalSources[$id]['format'] = 'raw';
180
-		    } elseif ($port == '30005') {
174
+				} elseif ($port == '10001') {
175
+				//$formats[$id] = 'tsv';
176
+				$globalSources[$id]['format'] = 'tsv';
177
+			} elseif ($port == '30002') {
178
+				//$formats[$id] = 'raw';
179
+				$globalSources[$id]['format'] = 'raw';
180
+			} elseif ($port == '30005') {
181 181
 			// Not yet supported
182
-        		//$formats[$id] = 'beast';
183
-        		$globalSources[$id]['format'] = 'beast';
184
-		    //} else $formats[$id] = 'sbs';
185
-		    } else $globalSources[$id]['format'] = 'sbs';
186
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
182
+				//$formats[$id] = 'beast';
183
+				$globalSources[$id]['format'] = 'beast';
184
+			//} else $formats[$id] = 'sbs';
185
+			} else $globalSources[$id]['format'] = 'sbs';
186
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
187 187
 		}
188 188
 		if ($globalDebug) echo 'Connection in progress to '.$host.'('.$globalSources[$id]['format'].')....'."\n";
189
-            } else {
189
+			} else {
190 190
 		if ($globalDebug) echo 'Connection failed to '.$host.':'.$port.' : '.$errno.' '.$errstr."\n";
191
-    	    }
192
-        }
193
-    }
191
+			}
192
+		}
193
+	}
194 194
 }
195 195
 if (!isset($globalMinFetch)) $globalMinFetch = 0;
196 196
 
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 
214 214
 // APRS Configuration
215 215
 foreach ($globalSources as $key => $source) {
216
-    if (isset($source['format']) && $source['format'] == 'aprs') {
216
+	if (isset($source['format']) && $source['format'] == 'aprs') {
217 217
 	$aprs_connect = 0;
218 218
 	$use_aprs = true;
219 219
 	break;
220
-    } elseif (!isset($source['format'])) {
221
-        $globalSources[$key]['format'] = 'auto';
222
-    }
220
+	} elseif (!isset($source['format'])) {
221
+		$globalSources[$key]['format'] = 'auto';
222
+	}
223 223
 }
224 224
 
225 225
 if ($use_aprs) {
@@ -259,53 +259,53 @@  discard block
 block discarded – undo
259 259
 
260 260
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
261 261
 while ($i > 0) {
262
-    if (!$globalDaemon) $i = $endtime-time();
263
-    // Delete old ATC
264
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265
-        $ATC->deleteOldATC();
266
-    }
267
-    //foreach ($formats as $id => $value) {
268
-    foreach ($globalSources as $id => $value) {
262
+	if (!$globalDaemon) $i = $endtime-time();
263
+	// Delete old ATC
264
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
265
+		$ATC->deleteOldATC();
266
+	}
267
+	//foreach ($formats as $id => $value) {
268
+	foreach ($globalSources as $id => $value) {
269 269
 	//if ($value == 'deltadbtxt' && (time() - $last_exec['deltadbtxt'] > $globalMinFetch)) {
270 270
 	if ($value['format'] == 'deltadbtxt' && (time() - $value['last_exec'] > $globalMinFetch)) {
271
-	    //$buffer = $Common->getData($hosts[$id]);
272
-	    $buffer = $Common->getData($value['host']);
273
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
274
-	    $buffer = explode('\n',$buffer);
275
-	    foreach ($buffer as $line) {
276
-    		if ($line != '') {
277
-    		    $line = explode(',', $line);
278
-	            $data = array();
279
-	            $data['hex'] = $line[1]; // hex
280
-	            $data['ident'] = $line[2]; // ident
281
-	            $data['altitude'] = $line[3]; // altitude
282
-	            $data['speed'] = $line[4]; // speed
283
-	            $data['heading'] = $line[5]; // heading
284
-	            $data['latitude'] = $line[6]; // lat
285
-	            $data['longitude'] = $line[7]; // long
286
-	            $data['verticalrate'] = ''; // vertical rate
287
-	            $data['squawk'] = ''; // squawk
288
-	            $data['emergency'] = ''; // emergency
289
-		    $data['datetime'] = date('Y-m-d H:i:s');
290
-		    $data['format_source'] = 'deltadbtxt';
291
-    		    $data['id_source'] = $id_source;
292
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
293
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
294
-    		    $SI->add($data);
295
-		    unset($data);
296
-    		}
297
-    	    }
298
-    	    $value['last_exec'] = time();
271
+		//$buffer = $Common->getData($hosts[$id]);
272
+		$buffer = $Common->getData($value['host']);
273
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
274
+		$buffer = explode('\n',$buffer);
275
+		foreach ($buffer as $line) {
276
+			if ($line != '') {
277
+				$line = explode(',', $line);
278
+				$data = array();
279
+				$data['hex'] = $line[1]; // hex
280
+				$data['ident'] = $line[2]; // ident
281
+				$data['altitude'] = $line[3]; // altitude
282
+				$data['speed'] = $line[4]; // speed
283
+				$data['heading'] = $line[5]; // heading
284
+				$data['latitude'] = $line[6]; // lat
285
+				$data['longitude'] = $line[7]; // long
286
+				$data['verticalrate'] = ''; // vertical rate
287
+				$data['squawk'] = ''; // squawk
288
+				$data['emergency'] = ''; // emergency
289
+			$data['datetime'] = date('Y-m-d H:i:s');
290
+			$data['format_source'] = 'deltadbtxt';
291
+				$data['id_source'] = $id_source;
292
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
293
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
294
+				$SI->add($data);
295
+			unset($data);
296
+			}
297
+			}
298
+			$value['last_exec'] = time();
299 299
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
300 300
 	} elseif (($value['format'] == 'whazzup' && (time() - $value['last_exec'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $value['last_exec'] > $globalMinFetch))) {
301
-	    //$buffer = $Common->getData($hosts[$id]);
302
-	    $buffer = $Common->getData($value['host']);
303
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
304
-	    $buffer = explode('\n',$buffer);
305
-	    foreach ($buffer as $line) {
306
-    		if ($line != '') {
307
-    		    $line = explode(':', $line);
308
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
301
+		//$buffer = $Common->getData($hosts[$id]);
302
+		$buffer = $Common->getData($value['host']);
303
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
304
+		$buffer = explode('\n',$buffer);
305
+		foreach ($buffer as $line) {
306
+			if ($line != '') {
307
+				$line = explode(':', $line);
308
+				if (count($line) > 30 && $line[0] != 'callsign') {
309 309
 			$data = array();
310 310
 			$data['id'] = $line[1].'-'.$line[0];
311 311
 			$data['pilot_id'] = $line[1];
@@ -317,35 +317,35 @@  discard block
 block discarded – undo
317 317
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
318 318
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
319 319
 			$data['latitude'] = $line[5]; // lat
320
-	        	$data['longitude'] = $line[6]; // long
321
-	        	$data['verticalrate'] = ''; // vertical rate
322
-	        	$data['squawk'] = ''; // squawk
323
-	        	$data['emergency'] = ''; // emergency
324
-	        	$data['waypoints'] = $line[30];
320
+				$data['longitude'] = $line[6]; // long
321
+				$data['verticalrate'] = ''; // vertical rate
322
+				$data['squawk'] = ''; // squawk
323
+				$data['emergency'] = ''; // emergency
324
+				$data['waypoints'] = $line[30];
325 325
 			$data['datetime'] = date('Y-m-d H:i:s');
326 326
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
327
-		        $data['departure_airport_icao'] = $line[11];
328
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
329
-		        $data['arrival_airport_icao'] = $line[13];
327
+				$data['departure_airport_icao'] = $line[11];
328
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
329
+				$data['arrival_airport_icao'] = $line[13];
330 330
 			$data['frequency'] = $line[4];
331 331
 			$data['type'] = $line[18];
332 332
 			$data['range'] = $line[19];
333 333
 			if (isset($line[35])) $data['info'] = $line[35];
334
-    			$data['id_source'] = $id_source;
335
-	    		//$data['arrival_airport_time'] = ;
336
-	    		if ($line[9] != '') {
337
-	    		    $aircraft_data = explode('/',$line[9]);
338
-	    		    if (isset($aircraft_data[1])) {
339
-	    			$data['aircraft_icao'] = $aircraft_data[1];
340
-	    		    }
341
-        		}
342
-	    		/*
334
+				$data['id_source'] = $id_source;
335
+				//$data['arrival_airport_time'] = ;
336
+				if ($line[9] != '') {
337
+					$aircraft_data = explode('/',$line[9]);
338
+					if (isset($aircraft_data[1])) {
339
+					$data['aircraft_icao'] = $aircraft_data[1];
340
+					}
341
+				}
342
+				/*
343 343
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
344 344
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
345 345
 	    		*/
346
-	    		$data['format_source'] = $value['format'];
346
+				$data['format_source'] = $value['format'];
347 347
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
348
-    			if ($line[3] == 'PILOT') $SI->add($data);
348
+				if ($line[3] == 'PILOT') $SI->add($data);
349 349
 			elseif ($line[3] == 'ATC') {
350 350
 				//print_r($data);
351 351
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -363,212 +363,212 @@  discard block
 block discarded – undo
363 363
 				
364 364
 				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']);
365 365
 			}
366
-    			unset($data);
367
-    		    }
368
-    		}
369
-    	    }
370
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
371
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
372
-    	    $value['last_exec'] = time();
373
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
374
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
375
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
376
-	    if ($buffer != '') {
377
-	    $all_data = json_decode($buffer,true);
378
-	    if (isset($all_data['acList'])) {
366
+				unset($data);
367
+				}
368
+			}
369
+			}
370
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
371
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
372
+			$value['last_exec'] = time();
373
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
374
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
375
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
376
+		if ($buffer != '') {
377
+		$all_data = json_decode($buffer,true);
378
+		if (isset($all_data['acList'])) {
379 379
 		foreach ($all_data['acList'] as $line) {
380
-		    $data = array();
381
-		    $data['hex'] = $line['Icao']; // hex
382
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
383
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
384
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
385
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
386
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
387
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
388
-		    //$data['verticalrate'] = $line['']; // verticale rate
389
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
390
-		    $data['emergency'] = ''; // emergency
391
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
392
-		    /*
380
+			$data = array();
381
+			$data['hex'] = $line['Icao']; // hex
382
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
383
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
384
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
385
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
386
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
387
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
388
+			//$data['verticalrate'] = $line['']; // verticale rate
389
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
390
+			$data['emergency'] = ''; // emergency
391
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
392
+			/*
393 393
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
394 394
 		    else $data['datetime'] = date('Y-m-d H:i:s');
395 395
 		    */
396
-		    $data['datetime'] = date('Y-m-d H:i:s');
397
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
398
-	    	    $data['format_source'] = 'aircraftlistjson';
399
-		    $data['id_source'] = $id_source;
400
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
401
-		    if (isset($data['datetime'])) $SI->add($data);
402
-		    unset($data);
396
+			$data['datetime'] = date('Y-m-d H:i:s');
397
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
398
+				$data['format_source'] = 'aircraftlistjson';
399
+			$data['id_source'] = $id_source;
400
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
401
+			if (isset($data['datetime'])) $SI->add($data);
402
+			unset($data);
403 403
 		}
404
-	    } else {
404
+		} else {
405 405
 		foreach ($all_data as $line) {
406
-		    $data = array();
407
-		    $data['hex'] = $line['hex']; // hex
408
-		    $data['ident'] = $line['flight']; // ident
409
-		    $data['altitude'] = $line['altitude']; // altitude
410
-		    $data['speed'] = $line['speed']; // speed
411
-		    $data['heading'] = $line['track']; // heading
412
-		    $data['latitude'] = $line['lat']; // lat
413
-		    $data['longitude'] = $line['lon']; // long
414
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
415
-		    $data['squawk'] = $line['squawk']; // squawk
416
-		    $data['emergency'] = ''; // emergency
417
-		    $data['datetime'] = date('Y-m-d H:i:s');
418
-	    	    $data['format_source'] = 'aircraftlistjson';
419
-    		    $data['id_source'] = $id_source;
420
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
421
-		    $SI->add($data);
422
-		    unset($data);
406
+			$data = array();
407
+			$data['hex'] = $line['hex']; // hex
408
+			$data['ident'] = $line['flight']; // ident
409
+			$data['altitude'] = $line['altitude']; // altitude
410
+			$data['speed'] = $line['speed']; // speed
411
+			$data['heading'] = $line['track']; // heading
412
+			$data['latitude'] = $line['lat']; // lat
413
+			$data['longitude'] = $line['lon']; // long
414
+			$data['verticalrate'] = $line['vrt']; // verticale rate
415
+			$data['squawk'] = $line['squawk']; // squawk
416
+			$data['emergency'] = ''; // emergency
417
+			$data['datetime'] = date('Y-m-d H:i:s');
418
+				$data['format_source'] = 'aircraftlistjson';
419
+				$data['id_source'] = $id_source;
420
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
421
+			$SI->add($data);
422
+			unset($data);
423
+		}
423 424
 		}
424
-	    }
425
-	    }
426
-    	    //$last_exec['aircraftlistjson'] = time();
427
-    	    $value['last_exec'] = time();
428
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
429
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
430
-	    $buffer = $Common->getData($value['host']);
431
-	    $all_data = json_decode($buffer,true);
432
-	    if (isset($all_data['planes'])) {
425
+		}
426
+			//$last_exec['aircraftlistjson'] = time();
427
+			$value['last_exec'] = time();
428
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
429
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $value['last_exec'] > $globalMinFetch)) {
430
+		$buffer = $Common->getData($value['host']);
431
+		$all_data = json_decode($buffer,true);
432
+		if (isset($all_data['planes'])) {
433 433
 		foreach ($all_data['planes'] as $key => $line) {
434
-		    $data = array();
435
-		    $data['hex'] = $key; // hex
436
-		    $data['ident'] = $line[3]; // ident
437
-		    $data['altitude'] = $line[6]; // altitude
438
-		    $data['speed'] = $line[8]; // speed
439
-		    $data['heading'] = $line[7]; // heading
440
-		    $data['latitude'] = $line[4]; // lat
441
-		    $data['longitude'] = $line[5]; // long
442
-		    //$data['verticalrate'] = $line[]; // verticale rate
443
-		    $data['squawk'] = $line[10]; // squawk
444
-		    $data['emergency'] = ''; // emergency
445
-		    $data['registration'] = $line[2];
446
-		    $data['aircraft_icao'] = $line[0];
447
-		    $deparr = explode('-',$line[1]);
448
-		    if (count($deparr) == 2) {
434
+			$data = array();
435
+			$data['hex'] = $key; // hex
436
+			$data['ident'] = $line[3]; // ident
437
+			$data['altitude'] = $line[6]; // altitude
438
+			$data['speed'] = $line[8]; // speed
439
+			$data['heading'] = $line[7]; // heading
440
+			$data['latitude'] = $line[4]; // lat
441
+			$data['longitude'] = $line[5]; // long
442
+			//$data['verticalrate'] = $line[]; // verticale rate
443
+			$data['squawk'] = $line[10]; // squawk
444
+			$data['emergency'] = ''; // emergency
445
+			$data['registration'] = $line[2];
446
+			$data['aircraft_icao'] = $line[0];
447
+			$deparr = explode('-',$line[1]);
448
+			if (count($deparr) == 2) {
449 449
 			$data['departure_airport_icao'] = $deparr[0];
450 450
 			$data['arrival_airport_icao'] = $deparr[1];
451
-		    }
452
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
453
-	    	    $data['format_source'] = 'planeupdatefaa';
454
-    		    $data['id_source'] = $id_source;
455
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
456
-		    $SI->add($data);
457
-		    unset($data);
451
+			}
452
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
453
+				$data['format_source'] = 'planeupdatefaa';
454
+				$data['id_source'] = $id_source;
455
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
456
+			$SI->add($data);
457
+			unset($data);
458 458
 		}
459
-	    }
460
-    	    //$last_exec['planeupdatefaa'] = time();
461
-    	    $value['last_exec'] = time();
462
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
463
-    	} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
464
-	    //$buffer = $Common->getData($hosts[$id]);
465
-	    $buffer = $Common->getData($value['host']);
466
-	    $all_data = json_decode($buffer,true);
467
-	    foreach ($all_data as $key => $line) {
459
+		}
460
+			//$last_exec['planeupdatefaa'] = time();
461
+			$value['last_exec'] = time();
462
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
463
+		} elseif ($value['format'] == 'fr24json' && (time() - $value['last_exec'] > $globalMinFetch)) {
464
+		//$buffer = $Common->getData($hosts[$id]);
465
+		$buffer = $Common->getData($value['host']);
466
+		$all_data = json_decode($buffer,true);
467
+		foreach ($all_data as $key => $line) {
468 468
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
469
-		    $data = array();
470
-		    $data['hex'] = $line[0];
471
-		    $data['ident'] = $line[16]; //$line[13]
472
-	    	    $data['altitude'] = $line[4]; // altitude
473
-	    	    $data['speed'] = $line[5]; // speed
474
-	    	    $data['heading'] = $line[3]; // heading
475
-	    	    $data['latitude'] = $line[1]; // lat
476
-	    	    $data['longitude'] = $line[2]; // long
477
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
478
-	    	    $data['squawk'] = $line[6]; // squawk
479
-	    	    $data['aircraft_icao'] = $line[8];
480
-	    	    $data['registration'] = $line[9];
481
-		    $data['departure_airport_iata'] = $line[11];
482
-		    $data['arrival_airport_iata'] = $line[12];
483
-	    	    $data['emergency'] = ''; // emergency
484
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
485
-	    	    $data['format_source'] = 'fr24json';
486
-    		    $data['id_source'] = $id_source;
487
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
488
-		    $SI->add($data);
489
-		    unset($data);
469
+			$data = array();
470
+			$data['hex'] = $line[0];
471
+			$data['ident'] = $line[16]; //$line[13]
472
+				$data['altitude'] = $line[4]; // altitude
473
+				$data['speed'] = $line[5]; // speed
474
+				$data['heading'] = $line[3]; // heading
475
+				$data['latitude'] = $line[1]; // lat
476
+				$data['longitude'] = $line[2]; // long
477
+				$data['verticalrate'] = $line[15]; // verticale rate
478
+				$data['squawk'] = $line[6]; // squawk
479
+				$data['aircraft_icao'] = $line[8];
480
+				$data['registration'] = $line[9];
481
+			$data['departure_airport_iata'] = $line[11];
482
+			$data['arrival_airport_iata'] = $line[12];
483
+				$data['emergency'] = ''; // emergency
484
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
485
+				$data['format_source'] = 'fr24json';
486
+				$data['id_source'] = $id_source;
487
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
488
+			$SI->add($data);
489
+			unset($data);
490
+		}
490 491
 		}
491
-	    }
492
-    	    //$last_exec['fr24json'] = time();
493
-    	    $value['last_exec'] = time();
494
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
495
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
496
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
497
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
498
-	    //echo $buffer;
499
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
500
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
501
-	    $all_data = json_decode($buffer,true);
502
-	    if (json_last_error() != JSON_ERROR_NONE) {
492
+			//$last_exec['fr24json'] = time();
493
+			$value['last_exec'] = time();
494
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
495
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $value['last_exec'] > $globalMinFetch)) {
496
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
497
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
498
+		//echo $buffer;
499
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
500
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
501
+		$all_data = json_decode($buffer,true);
502
+		if (json_last_error() != JSON_ERROR_NONE) {
503 503
 		die(json_last_error_msg());
504
-	    }
505
-	    if (isset($all_data['mrkrs'])) {
504
+		}
505
+		if (isset($all_data['mrkrs'])) {
506 506
 		foreach ($all_data['mrkrs'] as $key => $line) {
507
-		    if (isset($line['inf'])) {
507
+			if (isset($line['inf'])) {
508 508
 			$data = array();
509 509
 			$data['hex'] = $line['inf']['ia'];
510 510
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
511
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
512
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
513
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
514
-	    		$data['latitude'] = $line['pt'][0]; // lat
515
-	    		$data['longitude'] = $line['pt'][1]; // long
516
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
517
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
518
-	    		//$data['aircraft_icao'] = $line[8];
519
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
511
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
512
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
513
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
514
+				$data['latitude'] = $line['pt'][0]; // lat
515
+				$data['longitude'] = $line['pt'][1]; // long
516
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
517
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
518
+				//$data['aircraft_icao'] = $line[8];
519
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
520 520
 			//$data['departure_airport_iata'] = $line[11];
521 521
 			//$data['arrival_airport_iata'] = $line[12];
522
-	    		//$data['emergency'] = ''; // emergency
522
+				//$data['emergency'] = ''; // emergency
523 523
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
524
-	    		$data['format_source'] = 'radarvirtueljson';
525
-    			$data['id_source'] = $id_source;
524
+				$data['format_source'] = 'radarvirtueljson';
525
+				$data['id_source'] = $id_source;
526 526
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
527 527
 			$SI->add($data);
528 528
 			unset($data);
529
-		    }
529
+			}
530
+		}
530 531
 		}
531
-	    }
532
-    	    //$last_exec['radarvirtueljson'] = time();
533
-    	    $value['last_exec'] = time();
534
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
535
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
536
-	    //$buffer = $Common->getData($hosts[$id]);
537
-	    $buffer = $Common->getData($value['host']);
538
-	    $all_data = json_decode(utf8_encode($buffer),true);
532
+			//$last_exec['radarvirtueljson'] = time();
533
+			$value['last_exec'] = time();
534
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
535
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $value['last_exec'] > $globalMinFetch)) {
536
+		//$buffer = $Common->getData($hosts[$id]);
537
+		$buffer = $Common->getData($value['host']);
538
+		$all_data = json_decode(utf8_encode($buffer),true);
539 539
 	    
540
-	    if (isset($all_data['pireps'])) {
541
-	        foreach ($all_data['pireps'] as $line) {
542
-		    $data = array();
543
-		    $data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
544
-		    $data['ident'] = $line['callsign']; // ident
545
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
547
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
548
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
549
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
550
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
551
-		    $data['latitude'] = $line['lat']; // lat
552
-		    $data['longitude'] = $line['lon']; // long
553
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
554
-		    //$data['squawk'] = $line['squawk']; // squawk
555
-		    //$data['emergency'] = ''; // emergency
556
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
557
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
558
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
559
-		    //$data['arrival_airport_time'] = $line['arrtime'];
560
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
561
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
562
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
563
-		    else $data['info'] = '';
564
-		    $data['format_source'] = 'pireps';
565
-    		    $data['id_source'] = $id_source;
566
-		    $data['datetime'] = date('Y-m-d H:i:s');
567
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
-		    if ($line['icon'] == 'plane') {
540
+		if (isset($all_data['pireps'])) {
541
+			foreach ($all_data['pireps'] as $line) {
542
+			$data = array();
543
+			$data['hex'] = str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT);
544
+			$data['ident'] = $line['callsign']; // ident
545
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
546
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
547
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
548
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
549
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
550
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
551
+			$data['latitude'] = $line['lat']; // lat
552
+			$data['longitude'] = $line['lon']; // long
553
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
554
+			//$data['squawk'] = $line['squawk']; // squawk
555
+			//$data['emergency'] = ''; // emergency
556
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
557
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
558
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
559
+			//$data['arrival_airport_time'] = $line['arrtime'];
560
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
561
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
562
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
563
+			else $data['info'] = '';
564
+			$data['format_source'] = 'pireps';
565
+				$data['id_source'] = $id_source;
566
+			$data['datetime'] = date('Y-m-d H:i:s');
567
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
+			if ($line['icon'] == 'plane') {
569 569
 			$SI->add($data);
570
-		    //    print_r($data);
571
-    		    } elseif ($line['icon'] == 'ct') {
570
+			//    print_r($data);
571
+				} elseif ($line['icon'] == 'ct') {
572 572
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
573 573
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
574 574
 			$typec = substr($data['ident'],-3);
@@ -583,178 +583,178 @@  discard block
 block discarded – undo
583 583
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
584 584
 			else $data['type'] = 'Observer';
585 585
 			echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name']);
586
-		    }
587
-		    unset($data);
586
+			}
587
+			unset($data);
588
+		}
588 589
 		}
589
-	    }
590
-    	    //$last_exec['pirepsjson'] = time();
591
-    	    $value['last_exec'] = time();
592
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
593
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
594
-	    //$buffer = $Common->getData($hosts[$id]);
595
-	    $buffer = $Common->getData($value['host']);
596
-	    $all_data = json_decode($buffer,true);
597
-	    if ($buffer != '' && is_array($all_data)) {
590
+			//$last_exec['pirepsjson'] = time();
591
+			$value['last_exec'] = time();
592
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
593
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $value['last_exec'] > $globalMinFetch)) {
594
+		//$buffer = $Common->getData($hosts[$id]);
595
+		$buffer = $Common->getData($value['host']);
596
+		$all_data = json_decode($buffer,true);
597
+		if ($buffer != '' && is_array($all_data)) {
598 598
 		foreach ($all_data as $line) {
599
-	    	    $data = array();
600
-	    	    //$data['id'] = $line['id']; // id not usable
601
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
602
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
604
-	    	    $data['ident'] = $line['flightnum']; // ident
605
-	    	    $data['altitude'] = $line['alt']; // altitude
606
-	    	    $data['speed'] = $line['gs']; // speed
607
-	    	    $data['heading'] = $line['heading']; // heading
608
-	    	    $data['latitude'] = $line['lat']; // lat
609
-	    	    $data['longitude'] = $line['lng']; // long
610
-	    	    $data['verticalrate'] = ''; // verticale rate
611
-	    	    $data['squawk'] = ''; // squawk
612
-	    	    $data['emergency'] = ''; // emergency
613
-	    	    //$data['datetime'] = $line['lastupdate'];
614
-		    $data['datetime'] = date('Y-m-d H:i:s');
615
-	    	    $data['departure_airport_icao'] = $line['depicao'];
616
-	    	    $data['departure_airport_time'] = $line['deptime'];
617
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
618
-    		    $data['arrival_airport_time'] = $line['arrtime'];
619
-    		    $data['registration'] = $line['aircraft'];
620
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
621
-		    if (isset($line['aircraftname'])) {
599
+				$data = array();
600
+				//$data['id'] = $line['id']; // id not usable
601
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
602
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
603
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
604
+				$data['ident'] = $line['flightnum']; // ident
605
+				$data['altitude'] = $line['alt']; // altitude
606
+				$data['speed'] = $line['gs']; // speed
607
+				$data['heading'] = $line['heading']; // heading
608
+				$data['latitude'] = $line['lat']; // lat
609
+				$data['longitude'] = $line['lng']; // long
610
+				$data['verticalrate'] = ''; // verticale rate
611
+				$data['squawk'] = ''; // squawk
612
+				$data['emergency'] = ''; // emergency
613
+				//$data['datetime'] = $line['lastupdate'];
614
+			$data['datetime'] = date('Y-m-d H:i:s');
615
+				$data['departure_airport_icao'] = $line['depicao'];
616
+				$data['departure_airport_time'] = $line['deptime'];
617
+				$data['arrival_airport_icao'] = $line['arricao'];
618
+				$data['arrival_airport_time'] = $line['arrtime'];
619
+				$data['registration'] = $line['aircraft'];
620
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
621
+			if (isset($line['aircraftname'])) {
622 622
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
623 623
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
624
-	    		$aircraft_data = explode('-',$line['aircraftname']);
625
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627
-	    		else {
628
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
629
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
631
-	    		}
632
-	    	    }
633
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
634
-    		    $data['id_source'] = $id_source;
635
-	    	    $data['format_source'] = 'phpvmacars';
636
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
637
-		    $SI->add($data);
638
-		    unset($data);
624
+				$aircraft_data = explode('-',$line['aircraftname']);
625
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
626
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
627
+				else {
628
+					$aircraft_data = explode(' ',$line['aircraftname']);
629
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
630
+					else $data['aircraft_icao'] = $line['aircraftname'];
631
+				}
632
+				}
633
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
634
+				$data['id_source'] = $id_source;
635
+				$data['format_source'] = 'phpvmacars';
636
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
637
+			$SI->add($data);
638
+			unset($data);
639
+		}
639 640
 		}
640
-	    }
641
-    	    //$last_exec['phpvmacars'] = time();
642
-    	    $value['last_exec'] = time();
641
+			//$last_exec['phpvmacars'] = time();
642
+			$value['last_exec'] = time();
643 643
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
644 644
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast') {
645
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
645
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
646 646
 
647
-	    //$read = array( $sockets[$id] );
648
-	    $read = $sockets;
649
-	    $write = NULL;
650
-	    $e = NULL;
651
-	    $n = socket_select($read, $write, $e, $timeout);
652
-	    if ($e != NULL) var_dump($e);
653
-	    if ($n > 0) {
647
+		//$read = array( $sockets[$id] );
648
+		$read = $sockets;
649
+		$write = NULL;
650
+		$e = NULL;
651
+		$n = socket_select($read, $write, $e, $timeout);
652
+		if ($e != NULL) var_dump($e);
653
+		if ($n > 0) {
654 654
 		foreach ($read as $nb => $r) {
655
-		    //$value = $formats[$nb];
656
-		    $format = $globalSources[$nb]['format'];
657
-        	    $buffer = socket_read($r, 6000,PHP_NORMAL_READ);
658
-        	    //echo $buffer."\n";
659
-		    // lets play nice and handle signals such as ctrl-c/kill properly
660
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
661
-		    $dataFound = false;
662
-		    $error = false;
663
-		    //$SI::del();
664
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
665
-		    // SBS format is CSV format
666
-		    if ($buffer != '') {
655
+			//$value = $formats[$nb];
656
+			$format = $globalSources[$nb]['format'];
657
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
658
+				//echo $buffer."\n";
659
+			// lets play nice and handle signals such as ctrl-c/kill properly
660
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
661
+			$dataFound = false;
662
+			$error = false;
663
+			//$SI::del();
664
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
665
+			// SBS format is CSV format
666
+			if ($buffer != '') {
667 667
 			$tt = 0;
668 668
 			if ($format == 'raw') {
669
-			    // AVR format
670
-			    $data = $SBS->parse($buffer);
671
-			    if (is_array($data)) {
669
+				// AVR format
670
+				$data = $SBS->parse($buffer);
671
+				if (is_array($data)) {
672 672
 				$data['datetime'] = date('Y-m-d H:i:s');
673 673
 				$data['format_source'] = 'raw';
674 674
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
675
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
676
-                                $SI->add($data);
677
-                            }
675
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
676
+								$SI->add($data);
677
+							}
678 678
 			} elseif ($format == 'beast') {
679
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
680
-			    die;
679
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
680
+				die;
681 681
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
682
-			    $line = explode("\t", $buffer);
683
-			    for($k = 0; $k < count($line); $k=$k+2) {
682
+				$line = explode("\t", $buffer);
683
+				for($k = 0; $k < count($line); $k=$k+2) {
684 684
 				$key = $line[$k];
685
-			        $lined[$key] = $line[$k+1];
686
-			    }
687
-    			    if (count($lined) > 3) {
688
-    				$data['hex'] = $lined['hexid'];
689
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690
-    				$data['datetime'] = date('Y-m-d H:i:s');;
691
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
694
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
695
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
696
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
697
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
698
-    				$data['id_source'] = $id_source;
699
-    				$data['format_source'] = 'tsv';
700
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
701
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
702
-    				$SI->add($data);
703
-    				unset($lined);
704
-    				unset($data);
705
-    			    } else $error = true;
685
+					$lined[$key] = $line[$k+1];
686
+				}
687
+					if (count($lined) > 3) {
688
+					$data['hex'] = $lined['hexid'];
689
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
690
+					$data['datetime'] = date('Y-m-d H:i:s');;
691
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
692
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
693
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
694
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
695
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
696
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
697
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
698
+					$data['id_source'] = $id_source;
699
+					$data['format_source'] = 'tsv';
700
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
701
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
702
+					$SI->add($data);
703
+					unset($lined);
704
+					unset($data);
705
+					} else $error = true;
706 706
 			} elseif ($format == 'aprs' && $use_aprs) {
707
-			    if ($aprs_connect == 0) {
707
+				if ($aprs_connect == 0) {
708 708
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
709 709
 				$aprs_connect = 1;
710
-			    }
711
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
710
+				}
711
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
712 712
 				$aprs_last_tx = time();
713 713
 				$data_aprs = "# Keep alive";
714 714
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
715
-			    }
716
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
717
-			    if (substr($buffer,0,1) != '#') {
715
+				}
716
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
717
+				if (substr($buffer,0,1) != '#') {
718 718
 				$line = $APRS->parse($buffer);
719 719
 				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
720
-				    $data = array();
721
-				    //print_r($line);
722
-				    $data['hex'] = $line['address'];
723
-				    $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
724
-				    //$data['datetime'] = date('Y-m-d H:i:s');
725
-				    $data['ident'] = $line['ident'];
726
-				    $data['latitude'] = $line['latitude'];
727
-				    $data['longitude'] = $line['longitude'];
728
-				    //$data['verticalrate'] = $line[16];
729
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
730
-				    else $data['speed'] = 0;
731
-				    $data['altitude'] = $line['altitude'];
732
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
733
-				    //else $data['heading'] = 0;
734
-				    $data['aircraft_type'] = $line['stealth'];
735
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
736
-    				    $data['id_source'] = $id_source;
737
-				    $data['format_source'] = 'aprs';
738
-				    $data['source_name'] = $line['source'];
739
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
740
-				    $currentdate = date('Y-m-d H:i:s');
741
-				    $aprsdate = strtotime($data['datetime']);
742
-				    // Accept data if time <= system time + 20s
743
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
744
-				    else {
720
+					$data = array();
721
+					//print_r($line);
722
+					$data['hex'] = $line['address'];
723
+					$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
724
+					//$data['datetime'] = date('Y-m-d H:i:s');
725
+					$data['ident'] = $line['ident'];
726
+					$data['latitude'] = $line['latitude'];
727
+					$data['longitude'] = $line['longitude'];
728
+					//$data['verticalrate'] = $line[16];
729
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
730
+					else $data['speed'] = 0;
731
+					$data['altitude'] = $line['altitude'];
732
+					if (isset($line['course'])) $data['heading'] = $line['course'];
733
+					//else $data['heading'] = 0;
734
+					$data['aircraft_type'] = $line['stealth'];
735
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
736
+						$data['id_source'] = $id_source;
737
+					$data['format_source'] = 'aprs';
738
+					$data['source_name'] = $line['source'];
739
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
740
+					$currentdate = date('Y-m-d H:i:s');
741
+					$aprsdate = strtotime($data['datetime']);
742
+					// Accept data if time <= system time + 20s
743
+					if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20)) $send = $SI->add($data);
744
+					else {
745 745
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
746 746
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
747
-				    }
748
-				    unset($data);
747
+					}
748
+					unset($data);
749 749
 				} 
750 750
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
751 751
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
752
-			    }
752
+				}
753 753
 			} else {
754
-			    $line = explode(',', $buffer);
755
-    			    if (count($line) > 20) {
756
-    			    	$data['hex'] = $line[4];
757
-    				/*
754
+				$line = explode(',', $buffer);
755
+					if (count($line) > 20) {
756
+						$data['hex'] = $line[4];
757
+					/*
758 758
     				$data['datetime'] = $line[6].' '.$line[7];
759 759
     					date_default_timezone_set($globalTimezone);
760 760
     					$datetime = new DateTime($data['datetime']);
@@ -762,27 +762,27 @@  discard block
 block discarded – undo
762 762
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
763 763
     					date_default_timezone_set('UTC');
764 764
     				*/
765
-    				// Force datetime to current UTC datetime
766
-    				$data['datetime'] = date('Y-m-d H:i:s');
767
-    				$data['ident'] = trim($line[10]);
768
-    				$data['latitude'] = $line[14];
769
-    				$data['longitude'] = $line[15];
770
-    				$data['verticalrate'] = $line[16];
771
-    				$data['emergency'] = $line[20];
772
-    				$data['speed'] = $line[12];
773
-    				$data['squawk'] = $line[17];
774
-    				$data['altitude'] = $line[11];
775
-    				$data['heading'] = $line[13];
776
-    				$data['ground'] = $line[21];
777
-    				$data['emergency'] = $line[19];
778
-    				$data['format_source'] = 'sbs';
765
+					// Force datetime to current UTC datetime
766
+					$data['datetime'] = date('Y-m-d H:i:s');
767
+					$data['ident'] = trim($line[10]);
768
+					$data['latitude'] = $line[14];
769
+					$data['longitude'] = $line[15];
770
+					$data['verticalrate'] = $line[16];
771
+					$data['emergency'] = $line[20];
772
+					$data['speed'] = $line[12];
773
+					$data['squawk'] = $line[17];
774
+					$data['altitude'] = $line[11];
775
+					$data['heading'] = $line[13];
776
+					$data['ground'] = $line[21];
777
+					$data['emergency'] = $line[19];
778
+					$data['format_source'] = 'sbs';
779 779
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
780
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
781
-    				$data['id_source'] = $id_source;
782
-    				$send = $SI->add($data);
783
-    				unset($data);
784
-    			    } else $error = true;
785
-			    if ($error) {
780
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
781
+					$data['id_source'] = $id_source;
782
+					$send = $SI->add($data);
783
+					unset($data);
784
+					} else $error = true;
785
+				if ($error) {
786 786
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
787 787
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
788 788
 				} else {
@@ -795,50 +795,50 @@  discard block
 block discarded – undo
795 795
 					if ($globalDebug) echo "Reconnect after an error...\n";
796 796
 					connect_all($globalSources);
797 797
 				}
798
-			    }
798
+				}
799 799
 			}
800 800
 			// Sleep for xxx microseconds
801 801
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
802
-		    } else {
802
+			} else {
803 803
 			$tt++;
804 804
 			if ($tt > 30) {
805
-			    if ($globalDebug)echo "ERROR : Reconnect...";
806
-			    //@socket_close($r);
807
-			    sleep(2);
808
-			    connect_all($globalSources);
809
-			    break;
810
-			    $tt = 0;
805
+				if ($globalDebug)echo "ERROR : Reconnect...";
806
+				//@socket_close($r);
807
+				sleep(2);
808
+				connect_all($globalSources);
809
+				break;
810
+				$tt = 0;
811
+			}
811 812
 			}
812
-		    }
813 813
 		}
814
-	    } else {
814
+		} else {
815 815
 		$error = socket_strerror(socket_last_error());
816 816
 		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
817 817
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) || time() - $time >= $timeout) {
818 818
 			if (isset($globalDebug)) echo "Restarting...\n";
819 819
 			// Restart the script if possible
820 820
 			if (is_array($sockets)) {
821
-			    if ($globalDebug) echo "Shutdown all sockets...";
821
+				if ($globalDebug) echo "Shutdown all sockets...";
822 822
 			    
823
-			    foreach ($sockets as $sock) {
823
+				foreach ($sockets as $sock) {
824 824
 				@socket_shutdown($sock,2);
825 825
 				@socket_close($sock);
826
-			    }
826
+				}
827 827
 			    
828 828
 			}
829
-			    if ($globalDebug) echo "Restart all connections...";
830
-			    sleep(2);
831
-			    $time = time();
832
-			    //connect_all($hosts);
833
-			    connect_all($globalSources);
829
+				if ($globalDebug) echo "Restart all connections...";
830
+				sleep(2);
831
+				$time = time();
832
+				//connect_all($hosts);
833
+				connect_all($globalSources);
834 834
 
835 835
 		}
836
-	    }
836
+		}
837 837
 	}
838 838
 	if ($globalDaemon == false) {
839
-	    $SI->checkAll();
839
+		$SI->checkAll();
840
+	}
840 841
 	}
841
-    }
842 842
 }
843 843
 
844 844
 ?>
Please login to merge, or discard this patch.
install/class.update_db.php 1 patch
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -70,38 +70,38 @@  discard block
 block discarded – undo
70 70
 		try {
71 71
 			//$Connection = new Connection();
72 72
 			$sth = $Connection->db->prepare($query);
73
-                        $sth->execute(array(':source' => $database_file));
74
-                } catch(PDOException $e) {
75
-                        return "error : ".$e->getMessage();
76
-                }
73
+						$sth->execute(array(':source' => $database_file));
74
+				} catch(PDOException $e) {
75
+						return "error : ".$e->getMessage();
76
+				}
77 77
 
78
-    		if ($globalDebug) echo " - Add routes to DB -";
79
-    		update_db::connect_sqlite($database_file);
78
+			if ($globalDebug) echo " - Add routes to DB -";
79
+			update_db::connect_sqlite($database_file);
80 80
 		//$query = 'select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID';
81 81
 		$query = "select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao, rstp.allstop AS AllStop from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID LEFT JOIN (select RouteId,GROUP_CONCAT(icao,' ') as allstop from routestop left join Airport as air ON routestop.AirportId = air.AirportID group by RouteID) AS rstp ON Route.RouteID = rstp.RouteID";
82 82
 		try {
83
-                        $sth = update_db::$db_sqlite->prepare($query);
84
-                        $sth->execute();
85
-                } catch(PDOException $e) {
86
-                        return "error : ".$e->getMessage();
87
-                }
83
+						$sth = update_db::$db_sqlite->prepare($query);
84
+						$sth->execute();
85
+				} catch(PDOException $e) {
86
+						return "error : ".$e->getMessage();
87
+				}
88 88
 		//$query_dest = 'INSERT INTO routes (`RouteID`,`CallSign`,`Operator_ICAO`,`FromAirport_ICAO`,`ToAirport_ICAO`,`RouteStop`,`Source`) VALUES (:RouteID, :CallSign, :Operator_ICAO, :FromAirport_ICAO, :ToAirport_ICAO, :routestop, :source)';
89 89
 		$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,ToAirport_ICAO,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO, :ToAirport_ICAO, :routestop, :source)';
90 90
 		$Connection = new Connection();
91 91
 		$sth_dest = $Connection->db->prepare($query_dest);
92 92
 		try {
93 93
 			if ($globalTransaction) $Connection->db->beginTransaction();
94
-            		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
94
+					while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
95 95
 				//$query_dest_values = array(':RouteID' => $values['RouteId'],':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file);
96 96
 				$query_dest_values = array(':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file);
97 97
 				$sth_dest->execute($query_dest_values);
98
-            		}
98
+					}
99 99
 			if ($globalTransaction) $Connection->db->commit();
100 100
 		} catch(PDOException $e) {
101 101
 			if ($globalTransaction) $Connection->db->rollBack(); 
102 102
 			return "error : ".$e->getMessage();
103 103
 		}
104
-                return '';
104
+				return '';
105 105
 	}
106 106
 	public static function retrieve_modes_sqlite_to_dest($database_file) {
107 107
 		global $globalTransaction;
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
 		try {
111 111
 			$Connection = new Connection();
112 112
 			$sth = $Connection->db->prepare($query);
113
-                        $sth->execute(array(':source' => $database_file));
114
-                } catch(PDOException $e) {
115
-                        return "error : ".$e->getMessage();
116
-                }
113
+						$sth->execute(array(':source' => $database_file));
114
+				} catch(PDOException $e) {
115
+						return "error : ".$e->getMessage();
116
+				}
117 117
 		$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source";
118 118
 		try {
119 119
 			$Connection = new Connection();
120 120
 			$sth = $Connection->db->prepare($query);
121
-                        $sth->execute(array(':source' => $database_file));
122
-                } catch(PDOException $e) {
123
-                        return "error : ".$e->getMessage();
124
-                }
121
+						$sth->execute(array(':source' => $database_file));
122
+				} catch(PDOException $e) {
123
+						return "error : ".$e->getMessage();
124
+				}
125 125
 
126
-    		update_db::connect_sqlite($database_file);
126
+			update_db::connect_sqlite($database_file);
127 127
 		$query = 'select * from Aircraft';
128 128
 		try {
129
-                        $sth = update_db::$db_sqlite->prepare($query);
130
-                        $sth->execute();
131
-                } catch(PDOException $e) {
132
-                        return "error : ".$e->getMessage();
133
-                }
129
+						$sth = update_db::$db_sqlite->prepare($query);
130
+						$sth->execute();
131
+				} catch(PDOException $e) {
132
+						return "error : ".$e->getMessage();
133
+				}
134 134
 		//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)';
135 135
 		$query_dest = 'INSERT INTO aircraft_modes (LastModified, ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type,:source)';
136 136
 		
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
 		$sth_dest_owner = $Connection->db->prepare($query_dest_owner);
142 142
 		try {
143 143
 			if ($globalTransaction) $Connection->db->beginTransaction();
144
-            		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
144
+					while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
145 145
 			//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']);
146 146
 				if ($values['UserString4'] == 'M') $type = 'military';
147 147
 				else $type = null;
148 148
 				$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type);
149 149
 				$sth_dest->execute($query_dest_values);
150 150
 				if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') {
151
-				    $query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']);
152
-				    $sth_dest_owner->execute($query_dest_owner_values);
151
+					$query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']);
152
+					$sth_dest_owner->execute($query_dest_owner_values);
153 153
 				}
154
-            		}
154
+					}
155 155
 			if ($globalTransaction) $Connection->db->commit();
156 156
 		} catch(PDOException $e) {
157 157
 			return "error : ".$e->getMessage();
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 		try {
162 162
 			$Connection = new Connection();
163 163
 			$sth = $Connection->db->prepare($query);
164
-                        $sth->execute(array(':source' => $database_file));
165
-                } catch(PDOException $e) {
166
-                        return "error : ".$e->getMessage();
167
-                }
164
+						$sth->execute(array(':source' => $database_file));
165
+				} catch(PDOException $e) {
166
+						return "error : ".$e->getMessage();
167
+				}
168 168
 		return '';
169 169
 	}
170 170
 
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 		try {
177 177
 			$Connection = new Connection();
178 178
 			$sth = $Connection->db->prepare($query);
179
-                        $sth->execute(array(':source' => $database_file));
180
-                } catch(PDOException $e) {
181
-                        return "error : ".$e->getMessage();
182
-                }
179
+						$sth->execute(array(':source' => $database_file));
180
+				} catch(PDOException $e) {
181
+						return "error : ".$e->getMessage();
182
+				}
183 183
 		
184 184
 		if ($fh = fopen($database_file,"r")) {
185 185
 			//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)';
@@ -189,25 +189,25 @@  discard block
 block discarded – undo
189 189
 			$sth_dest = $Connection->db->prepare($query_dest);
190 190
 			try {
191 191
 				if ($globalTransaction) $Connection->db->beginTransaction();
192
-            			while (!feof($fh)) {
193
-            				$line = $Common->hex2str(fgets($fh,9999));
192
+						while (!feof($fh)) {
193
+							$line = $Common->hex2str(fgets($fh,9999));
194 194
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
195
-            				$values['ModeS'] = substr($line,0,6);
196
-            				$values['Registration'] = trim(substr($line,69,6));
197
-            				$aircraft_name = trim(substr($line,48,6));
198
-            				// Check if we can find ICAO, else set it to GLID
199
-            				$aircraft_name_split = explode(' ',$aircraft_name);
200
-            				$search_more = '';
201
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
202
-            				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
203
-            				$sth_search = $Connection->db->prepare($query_search);
195
+							$values['ModeS'] = substr($line,0,6);
196
+							$values['Registration'] = trim(substr($line,69,6));
197
+							$aircraft_name = trim(substr($line,48,6));
198
+							// Check if we can find ICAO, else set it to GLID
199
+							$aircraft_name_split = explode(' ',$aircraft_name);
200
+							$search_more = '';
201
+							if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
202
+							$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
203
+							$sth_search = $Connection->db->prepare($query_search);
204 204
 					try {
205
-                                    		$sth_search->execute();
206
-	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
207
-	            				//if (count($result) > 0) {
208
-	            				if (isset($result['icao']) && $result['icao'] != '') {
209
-	            				    $values['ICAOTypeCode'] = $result['icao'];
210
-	            				} 
205
+											$sth_search->execute();
206
+								$result = $sth_search->fetch(PDO::FETCH_ASSOC);
207
+								//if (count($result) > 0) {
208
+								if (isset($result['icao']) && $result['icao'] != '') {
209
+									$values['ICAOTypeCode'] = $result['icao'];
210
+								} 
211 211
 					} catch(PDOException $e) {
212 212
 						return "error : ".$e->getMessage();
213 213
 					}
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
 		try {
231 231
 			$Connection = new Connection();
232 232
 			$sth = $Connection->db->prepare($query);
233
-                        $sth->execute(array(':source' => $database_file));
234
-                } catch(PDOException $e) {
235
-                        return "error : ".$e->getMessage();
236
-                }
233
+						$sth->execute(array(':source' => $database_file));
234
+				} catch(PDOException $e) {
235
+						return "error : ".$e->getMessage();
236
+				}
237 237
 		return '';
238 238
 	}
239 239
 
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 		try {
245 245
 			$Connection = new Connection();
246 246
 			$sth = $Connection->db->prepare($query);
247
-                        $sth->execute(array(':source' => $database_file));
248
-                } catch(PDOException $e) {
249
-                        return "error : ".$e->getMessage();
250
-                }
247
+						$sth->execute(array(':source' => $database_file));
248
+				} catch(PDOException $e) {
249
+						return "error : ".$e->getMessage();
250
+				}
251 251
 		
252 252
 		if ($fh = fopen($database_file,"r")) {
253 253
 			//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)';
@@ -258,24 +258,24 @@  discard block
 block discarded – undo
258 258
 			try {
259 259
 				if ($globalTransaction) $Connection->db->beginTransaction();
260 260
 				$tmp = fgetcsv($fh,9999,',',"'");
261
-            			while (!feof($fh)) {
262
-            				$line = fgetcsv($fh,9999,',',"'");
261
+						while (!feof($fh)) {
262
+							$line = fgetcsv($fh,9999,',',"'");
263 263
             				
264 264
 					//FFFFFF                     RIDEAU VALLEY SOARINGASW-20               C-FBKN MZ 123.400
265 265
 					//print_r($line);
266
-            				$values['ModeS'] = $line[1];
267
-            				$values['Registration'] = $line[3];
268
-            				$aircraft_name = $line[2];
269
-            				// Check if we can find ICAO, else set it to GLID
270
-            				$aircraft_name_split = explode(' ',$aircraft_name);
271
-            				$search_more = '';
272
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
273
-            				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
274
-            				$sth_search = $Connection->db->prepare($query_search);
266
+							$values['ModeS'] = $line[1];
267
+							$values['Registration'] = $line[3];
268
+							$aircraft_name = $line[2];
269
+							// Check if we can find ICAO, else set it to GLID
270
+							$aircraft_name_split = explode(' ',$aircraft_name);
271
+							$search_more = '';
272
+							if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
273
+							$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
274
+							$sth_search = $Connection->db->prepare($query_search);
275 275
 					try {
276
-                                    		$sth_search->execute();
277
-	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
278
-	            				if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
276
+											$sth_search->execute();
277
+								$result = $sth_search->fetch(PDO::FETCH_ASSOC);
278
+								if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
279 279
 					} catch(PDOException $e) {
280 280
 						return "error : ".$e->getMessage();
281 281
 					}
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 		try {
299 299
 			$Connection = new Connection();
300 300
 			$sth = $Connection->db->prepare($query);
301
-                        $sth->execute(array(':source' => $database_file));
302
-                } catch(PDOException $e) {
303
-                        return "error : ".$e->getMessage();
304
-                }
301
+						$sth->execute(array(':source' => $database_file));
302
+				} catch(PDOException $e) {
303
+						return "error : ".$e->getMessage();
304
+				}
305 305
 		return '';
306 306
 	}
307 307
 
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 		try {
313 313
 			$Connection = new Connection();
314 314
 			$sth = $Connection->db->prepare($query);
315
-                        $sth->execute(array(':source' => $database_file));
316
-                } catch(PDOException $e) {
317
-                        return "error : ".$e->getMessage();
318
-                }
315
+						$sth->execute(array(':source' => $database_file));
316
+				} catch(PDOException $e) {
317
+						return "error : ".$e->getMessage();
318
+				}
319 319
 		
320 320
 		if ($fh = fopen($database_file,"r")) {
321 321
 			//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)';
@@ -326,94 +326,94 @@  discard block
 block discarded – undo
326 326
 			try {
327 327
 				if ($globalTransaction) $Connection->db->beginTransaction();
328 328
 				$tmp = fgetcsv($fh,9999,',','"');
329
-            			while (!feof($fh)) {
330
-            				$line = fgetcsv($fh,9999,',','"');
331
-            				//print_r($line);
332
-            				if ($country == 'F') {
333
-            				    $values['registration'] = $line[0];
334
-            				    $values['base'] = $line[4];
335
-            				    $values['owner'] = $line[5];
336
-            				    if ($line[6] == '') $values['date_first_reg'] = '';
337
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
338
-					    $values['cancel'] = $line[7];
329
+						while (!feof($fh)) {
330
+							$line = fgetcsv($fh,9999,',','"');
331
+							//print_r($line);
332
+							if ($country == 'F') {
333
+								$values['registration'] = $line[0];
334
+								$values['base'] = $line[4];
335
+								$values['owner'] = $line[5];
336
+								if ($line[6] == '') $values['date_first_reg'] = '';
337
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
338
+						$values['cancel'] = $line[7];
339 339
 					} elseif ($country == 'EI') {
340
-					    // TODO : add modeS & reg to aircraft_modes
341
-            				    $values['registration'] = $line[0];
342
-            				    $values['base'] = $line[3];
343
-            				    $values['owner'] = $line[2];
344
-            				    if ($line[1] == '') $values['date_first_reg'] = '';
345
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
346
-					    $values['cancel'] = '';
340
+						// TODO : add modeS & reg to aircraft_modes
341
+								$values['registration'] = $line[0];
342
+								$values['base'] = $line[3];
343
+								$values['owner'] = $line[2];
344
+								if ($line[1] == '') $values['date_first_reg'] = '';
345
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
346
+						$values['cancel'] = '';
347 347
 					} elseif ($country == 'HB') {
348
-					    // TODO : add modeS & reg to aircraft_modes
349
-            				    $values['registration'] = $line[0];
350
-            				    $values['base'] = null;
351
-            				    $values['owner'] = $line[5];
352
-            				    $values['date_first_reg'] = '';
353
-					    $values['cancel'] = '';
348
+						// TODO : add modeS & reg to aircraft_modes
349
+								$values['registration'] = $line[0];
350
+								$values['base'] = null;
351
+								$values['owner'] = $line[5];
352
+								$values['date_first_reg'] = '';
353
+						$values['cancel'] = '';
354 354
 					} elseif ($country == 'OK') {
355
-					    // TODO : add modeS & reg to aircraft_modes
356
-            				    $values['registration'] = $line[3];
357
-            				    $values['base'] = null;
358
-            				    $values['owner'] = $line[5];
359
-            				    if ($line[18] == '') $values['date_first_reg'] = '';
360
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
361
-					    $values['cancel'] = '';
355
+						// TODO : add modeS & reg to aircraft_modes
356
+								$values['registration'] = $line[3];
357
+								$values['base'] = null;
358
+								$values['owner'] = $line[5];
359
+								if ($line[18] == '') $values['date_first_reg'] = '';
360
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
361
+						$values['cancel'] = '';
362 362
 					} elseif ($country == 'VH') {
363
-					    // TODO : add modeS & reg to aircraft_modes
364
-            				    $values['registration'] = $line[0];
365
-            				    $values['base'] = null;
366
-            				    $values['owner'] = $line[12];
367
-            				    if ($line[28] == '') $values['date_first_reg'] = '';
368
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
369
-
370
-					    $values['cancel'] = $line[39];
363
+						// TODO : add modeS & reg to aircraft_modes
364
+								$values['registration'] = $line[0];
365
+								$values['base'] = null;
366
+								$values['owner'] = $line[12];
367
+								if ($line[28] == '') $values['date_first_reg'] = '';
368
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
369
+
370
+						$values['cancel'] = $line[39];
371 371
 					} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') {
372
-            				    $values['registration'] = $line[0];
373
-            				    $values['base'] = null;
374
-            				    $values['owner'] = $line[4];
375
-            				    $values['date_first_reg'] = null;
376
-					    $values['cancel'] = '';
372
+								$values['registration'] = $line[0];
373
+								$values['base'] = null;
374
+								$values['owner'] = $line[4];
375
+								$values['date_first_reg'] = null;
376
+						$values['cancel'] = '';
377 377
 					} elseif ($country == 'CC') {
378
-            				    $values['registration'] = $line[0];
379
-            				    $values['base'] = null;
380
-            				    $values['owner'] = $line[6];
381
-            				    $values['date_first_reg'] = null;
382
-					    $values['cancel'] = '';
378
+								$values['registration'] = $line[0];
379
+								$values['base'] = null;
380
+								$values['owner'] = $line[6];
381
+								$values['date_first_reg'] = null;
382
+						$values['cancel'] = '';
383 383
 					} elseif ($country == 'HJ') {
384
-            				    $values['registration'] = $line[0];
385
-            				    $values['base'] = null;
386
-            				    $values['owner'] = $line[8];
387
-            				    if ($line[7] == '') $values['date_first_reg'] = '';
388
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
389
-					    $values['cancel'] = '';
384
+								$values['registration'] = $line[0];
385
+								$values['base'] = null;
386
+								$values['owner'] = $line[8];
387
+								if ($line[7] == '') $values['date_first_reg'] = '';
388
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
389
+						$values['cancel'] = '';
390 390
 					} elseif ($country == 'PP') {
391
-            				    $values['registration'] = $line[0];
392
-            				    $values['base'] = null;
393
-            				    $values['owner'] = $line[4];
394
-            				    if ($line[6] == '') $values['date_first_reg'] = '';
395
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
396
-					    $values['cancel'] = $line[7];
391
+								$values['registration'] = $line[0];
392
+								$values['base'] = null;
393
+								$values['owner'] = $line[4];
394
+								if ($line[6] == '') $values['date_first_reg'] = '';
395
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
396
+						$values['cancel'] = $line[7];
397 397
 					} elseif ($country == 'E7') {
398
-            				    $values['registration'] = $line[0];
399
-            				    $values['base'] = null;
400
-            				    $values['owner'] = $line[4];
401
-            				    if ($line[5] == '') $values['date_first_reg'] = '';
402
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
403
-					    $values['cancel'] = '';
398
+								$values['registration'] = $line[0];
399
+								$values['base'] = null;
400
+								$values['owner'] = $line[4];
401
+								if ($line[5] == '') $values['date_first_reg'] = '';
402
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
403
+						$values['cancel'] = '';
404 404
 					} elseif ($country == '8Q') {
405
-            				    $values['registration'] = $line[0];
406
-            				    $values['base'] = null;
407
-            				    $values['owner'] = $line[3];
408
-            				    if ($line[7] == '') $values['date_first_reg'] = '';
409
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
410
-					    $values['cancel'] = '';
405
+								$values['registration'] = $line[0];
406
+								$values['base'] = null;
407
+								$values['owner'] = $line[3];
408
+								if ($line[7] == '') $values['date_first_reg'] = '';
409
+						else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
410
+						$values['cancel'] = '';
411 411
 					} elseif ($country == 'ZK' || $country == 'OM' || $country == 'TF') {
412
-            				    $values['registration'] = $line[0];
413
-            				    $values['base'] = null;
414
-            				    $values['owner'] = $line[3];
415
-            				    $values['date_first_reg'] = '';
416
-					    $values['cancel'] = '';
412
+								$values['registration'] = $line[0];
413
+								$values['base'] = null;
414
+								$values['owner'] = $line[3];
415
+								$values['date_first_reg'] = '';
416
+						$values['cancel'] = '';
417 417
 					}
418 418
 					if ($values['cancel'] == '' && $values['registration'] != null) {
419 419
 						$query_dest_values = array(':registration' => $values['registration'],':base' => $values['base'],':date_first_reg' => $values['date_first_reg'],':owner' => $values['owner'],':source' => $database_file);
@@ -535,20 +535,20 @@  discard block
 block discarded – undo
535 535
 		try {
536 536
 			$Connection = new Connection();
537 537
 			$sth = $Connection->db->prepare($query);
538
-                        $sth->execute();
539
-                } catch(PDOException $e) {
540
-                        return "error : ".$e->getMessage();
541
-                }
538
+						$sth->execute();
539
+				} catch(PDOException $e) {
540
+						return "error : ".$e->getMessage();
541
+				}
542 542
 
543 543
 
544 544
 		$query = 'ALTER TABLE airport DROP INDEX icaoidx';
545 545
 		try {
546 546
 			$Connection = new Connection();
547 547
 			$sth = $Connection->db->prepare($query);
548
-                        $sth->execute();
549
-                } catch(PDOException $e) {
550
-                        return "error : ".$e->getMessage();
551
-                }
548
+						$sth->execute();
549
+				} catch(PDOException $e) {
550
+						return "error : ".$e->getMessage();
551
+				}
552 552
 
553 553
 		$query_dest = "INSERT INTO airport (`airport_id`,`name`,`city`,`country`,`iata`,`icao`,`latitude`,`longitude`,`altitude`,`type`,`home_link`,`wikipedia_link`,`image_thumb`,`image`)
554 554
 		    VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image_thumb, :image)";
@@ -614,10 +614,10 @@  discard block
 block discarded – undo
614 614
 		try {
615 615
 			$Connection = new Connection();
616 616
 			$sth = $Connection->db->prepare($query);
617
-                        $sth->execute();
618
-                } catch(PDOException $e) {
619
-                        return "error : ".$e->getMessage();
620
-                }
617
+						$sth->execute();
618
+				} catch(PDOException $e) {
619
+						return "error : ".$e->getMessage();
620
+				}
621 621
 
622 622
 
623 623
 		if ($globalDebug) echo "Insert Not available Airport...\n";
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 		try {
628 628
 			$Connection = new Connection();
629 629
 			$sth = $Connection->db->prepare($query);
630
-                        $sth->execute($query_values);
631
-                } catch(PDOException $e) {
632
-                        return "error : ".$e->getMessage();
633
-                }
630
+						$sth->execute($query_values);
631
+				} catch(PDOException $e) {
632
+						return "error : ".$e->getMessage();
633
+				}
634 634
 		$i++;
635 635
 /*
636 636
 		$query = 'DELETE FROM airport WHERE airport_id IN (SELECT * FROM (SELECT min(a.airport_id) FROM airport a GROUP BY a.icao) x)';
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 
745 745
 
746 746
 
747
-                return "success";
747
+				return "success";
748 748
 	}
749 749
 	
750 750
 	public static function translation() {
@@ -760,10 +760,10 @@  discard block
 block discarded – undo
760 760
 		try {
761 761
 			$Connection = new Connection();
762 762
 			$sth = $Connection->db->prepare($query);
763
-                        $sth->execute(array(':source' => 'translation.csv'));
764
-                } catch(PDOException $e) {
765
-                        return "error : ".$e->getMessage();
766
-                }
763
+						$sth->execute(array(':source' => 'translation.csv'));
764
+				} catch(PDOException $e) {
765
+						return "error : ".$e->getMessage();
766
+				}
767 767
 
768 768
 		
769 769
 		//update_db::unzip($out_file);
@@ -782,21 +782,21 @@  discard block
 block discarded – undo
782 782
 					$data = $row;
783 783
 					$operator = $data[2];
784 784
 					if ($operator != '' && is_numeric(substr(substr($operator, 0, 3), -1, 1))) {
785
-                                                $airline_array = $Spotter->getAllAirlineInfo(substr($operator, 0, 2));
786
-                                                //echo substr($operator, 0, 2)."\n";;
787
-                                                if (count($airline_array) > 0) {
785
+												$airline_array = $Spotter->getAllAirlineInfo(substr($operator, 0, 2));
786
+												//echo substr($operator, 0, 2)."\n";;
787
+												if (count($airline_array) > 0) {
788 788
 							//print_r($airline_array);
789 789
 							$operator = $airline_array[0]['icao'].substr($operator,2);
790
-                                                }
791
-                                        }
790
+												}
791
+										}
792 792
 					
793 793
 					$operator_correct = $data[3];
794 794
 					if ($operator_correct != '' && is_numeric(substr(substr($operator_correct, 0, 3), -1, 1))) {
795
-                                                $airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2));
796
-                                                if (count($airline_array) > 0) {
797
-                                            		$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2);
798
-                                            	}
799
-                                        }
795
+												$airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2));
796
+												if (count($airline_array) > 0) {
797
+													$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2);
798
+												}
799
+										}
800 800
 					$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)';
801 801
 					try {
802 802
 						$sth = $Connection->db->prepare($query);
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 			//$Connection->db->commit();
811 811
 		}
812 812
 		return '';
813
-        }
813
+		}
814 814
 	
815 815
 	public static function translation_fam() {
816 816
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
@@ -820,10 +820,10 @@  discard block
 block discarded – undo
820 820
 		try {
821 821
 			$Connection = new Connection();
822 822
 			$sth = $Connection->db->prepare($query);
823
-                        $sth->execute(array(':source' => 'website_fam'));
824
-                } catch(PDOException $e) {
825
-                        return "error : ".$e->getMessage();
826
-                }
823
+						$sth->execute(array(':source' => 'website_fam'));
824
+				} catch(PDOException $e) {
825
+						return "error : ".$e->getMessage();
826
+				}
827 827
 
828 828
 		
829 829
 		//update_db::unzip($out_file);
@@ -852,54 +852,54 @@  discard block
 block discarded – undo
852 852
 			//$Connection->db->commit();
853 853
 		}
854 854
 		return '';
855
-        }
855
+		}
856 856
 
857 857
 	/**
858
-        * Convert a HTML table to an array
859
-        * @param String $data HTML page
860
-        * @return Array array of the tables in HTML page
861
-        */
862
-        private static function table2array($data) {
863
-                $html = str_get_html($data);
864
-                $tabledata=array();
865
-                foreach($html->find('tr') as $element)
866
-                {
867
-                        $td = array();
868
-                        foreach( $element->find('th') as $row)
869
-                        {
870
-                                $td [] = trim($row->plaintext);
871
-                        }
872
-                        $td=array_filter($td);
873
-                        $tabledata[] = $td;
874
-
875
-                        $td = array();
876
-                        $tdi = array();
877
-                        foreach( $element->find('td') as $row)
878
-                        {
879
-                                $td [] = trim($row->plaintext);
880
-                                $tdi [] = trim($row->innertext);
881
-                        }
882
-                        $td=array_filter($td);
883
-                        $tdi=array_filter($tdi);
884
-                    //    $tabledata[]=array_merge($td,$tdi);
885
-                        $tabledata[]=$td;
886
-                }
887
-                return(array_filter($tabledata));
888
-        }
889
-
890
-       /**
891
-        * Get data from form result
892
-        * @param String $url form URL
893
-        * @return String the result
894
-        */
895
-        private static function getData($url) {
896
-                $ch = curl_init();
897
-                curl_setopt($ch, CURLOPT_URL, $url);
898
-                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
899
-                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
900
-                curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
901
-                return curl_exec($ch);
902
-        }
858
+	 * Convert a HTML table to an array
859
+	 * @param String $data HTML page
860
+	 * @return Array array of the tables in HTML page
861
+	 */
862
+		private static function table2array($data) {
863
+				$html = str_get_html($data);
864
+				$tabledata=array();
865
+				foreach($html->find('tr') as $element)
866
+				{
867
+						$td = array();
868
+						foreach( $element->find('th') as $row)
869
+						{
870
+								$td [] = trim($row->plaintext);
871
+						}
872
+						$td=array_filter($td);
873
+						$tabledata[] = $td;
874
+
875
+						$td = array();
876
+						$tdi = array();
877
+						foreach( $element->find('td') as $row)
878
+						{
879
+								$td [] = trim($row->plaintext);
880
+								$tdi [] = trim($row->innertext);
881
+						}
882
+						$td=array_filter($td);
883
+						$tdi=array_filter($tdi);
884
+					//    $tabledata[]=array_merge($td,$tdi);
885
+						$tabledata[]=$td;
886
+				}
887
+				return(array_filter($tabledata));
888
+		}
889
+
890
+	   /**
891
+	    * Get data from form result
892
+	    * @param String $url form URL
893
+	    * @return String the result
894
+	    */
895
+		private static function getData($url) {
896
+				$ch = curl_init();
897
+				curl_setopt($ch, CURLOPT_URL, $url);
898
+				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
899
+				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
900
+				curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
901
+				return curl_exec($ch);
902
+		}
903 903
 /*
904 904
 	public static function waypoints() {
905 905
 		$data = update_db::getData('http://www.fallingrain.com/world/FR/waypoints.html');
@@ -949,10 +949,10 @@  discard block
 block discarded – undo
949 949
 		try {
950 950
 			$Connection = new Connection();
951 951
 			$sth = $Connection->db->prepare($query);
952
-                        $sth->execute();
953
-                } catch(PDOException $e) {
954
-                        return "error : ".$e->getMessage();
955
-                }
952
+						$sth->execute();
953
+				} catch(PDOException $e) {
954
+						return "error : ".$e->getMessage();
955
+				}
956 956
 
957 957
 		
958 958
 		//update_db::unzip($out_file);
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 			if ($globalTransaction) $Connection->db->commit();
994 994
 		}
995 995
 		return '';
996
-        }
996
+		}
997 997
 
998 998
 	public static function ivao_airlines($filename) {
999 999
 		//require_once(dirname(__FILE__).'/../require/class.Spotter.php');
@@ -1002,10 +1002,10 @@  discard block
 block discarded – undo
1002 1002
 		try {
1003 1003
 			$Connection = new Connection();
1004 1004
 			$sth = $Connection->db->prepare($query);
1005
-                        $sth->execute();
1006
-                } catch(PDOException $e) {
1007
-                        return "error : ".$e->getMessage();
1008
-                }
1005
+						$sth->execute();
1006
+				} catch(PDOException $e) {
1007
+						return "error : ".$e->getMessage();
1008
+				}
1009 1009
 
1010 1010
 		$header = NULL;
1011 1011
 		$delimiter = ':';
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 			if ($globalTransaction) $Connection->db->commit();
1030 1030
 		}
1031 1031
 		return '';
1032
-        }
1032
+		}
1033 1033
 	
1034 1034
 	public static function update_airspace() {
1035 1035
 		global $tmp_dir, $globalDBdriver;
@@ -1064,10 +1064,10 @@  discard block
 block discarded – undo
1064 1064
 			$query = 'DROP TABLE countries';
1065 1065
 			try {
1066 1066
 				$sth = $Connection->db->prepare($query);
1067
-            	        	$sth->execute();
1068
-	                } catch(PDOException $e) {
1069
-    	                	echo "error : ".$e->getMessage();
1070
-	                }
1067
+							$sth->execute();
1068
+					} catch(PDOException $e) {
1069
+							echo "error : ".$e->getMessage();
1070
+					}
1071 1071
 		}
1072 1072
 		if ($globalDBdriver == 'mysql') {
1073 1073
 			update_db::gunzip('../db/countries.sql.gz',$tmp_dir.'countries.sql');
@@ -1412,12 +1412,12 @@  discard block
 block discarded – undo
1412 1412
 		echo $data;
1413 1413
 		*/
1414 1414
 		if (file_exists($tmp_dir.'aircrafts.html')) {
1415
-		    //var_dump(file_get_html($tmp_dir.'aircrafts.html'));
1416
-		    $fh = fopen($tmp_dir.'aircrafts.html',"r");
1417
-		    $result = fread($fh,100000000);
1418
-		    //echo $result;
1419
-		    //var_dump(str_get_html($result));
1420
-		    //print_r(self::table2array($result));
1415
+			//var_dump(file_get_html($tmp_dir.'aircrafts.html'));
1416
+			$fh = fopen($tmp_dir.'aircrafts.html',"r");
1417
+			$result = fread($fh,100000000);
1418
+			//echo $result;
1419
+			//var_dump(str_get_html($result));
1420
+			//print_r(self::table2array($result));
1421 1421
 		}
1422 1422
 
1423 1423
 	}
@@ -1431,10 +1431,10 @@  discard block
 block discarded – undo
1431 1431
 		try {
1432 1432
 			$Connection = new Connection();
1433 1433
 			$sth = $Connection->db->prepare($query);
1434
-                        $sth->execute();
1435
-                } catch(PDOException $e) {
1436
-                        return "error : ".$e->getMessage();
1437
-                }
1434
+						$sth->execute();
1435
+				} catch(PDOException $e) {
1436
+						return "error : ".$e->getMessage();
1437
+				}
1438 1438
 
1439 1439
 		$error = '';
1440 1440
 		if ($globalDebug) echo "Notam : Download...";
@@ -1490,8 +1490,8 @@  discard block
 block discarded – undo
1490 1490
 					$data['date_end'] = date("Y-m-d H:i:s",strtotime($to));
1491 1491
 					$data['permanent'] = 0;
1492 1492
 				} else {
1493
-				    $data['date_end'] = NULL;
1494
-				    $data['permanent'] = 1;
1493
+					$data['date_end'] = NULL;
1494
+					$data['permanent'] = 1;
1495 1495
 				}
1496 1496
 				$data['full_notam'] = $notam['title'].'<br>'.$notam['description'];
1497 1497
 				$NOTAM = new NOTAM();
@@ -1515,13 +1515,13 @@  discard block
 block discarded – undo
1515 1515
 		try {
1516 1516
 			$Connection = new Connection();
1517 1517
 			$sth = $Connection->db->prepare($query);
1518
-                        $sth->execute();
1519
-                } catch(PDOException $e) {
1520
-                        return "error : ".$e->getMessage();
1521
-                }
1522
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
1523
-                if ($row['nb'] > 0) return false;
1524
-                else return true;
1518
+						$sth->execute();
1519
+				} catch(PDOException $e) {
1520
+						return "error : ".$e->getMessage();
1521
+				}
1522
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
1523
+				if ($row['nb'] > 0) return false;
1524
+				else return true;
1525 1525
 	}
1526 1526
 
1527 1527
 	public static function insert_last_update() {
@@ -1530,10 +1530,10 @@  discard block
 block discarded – undo
1530 1530
 		try {
1531 1531
 			$Connection = new Connection();
1532 1532
 			$sth = $Connection->db->prepare($query);
1533
-                        $sth->execute();
1534
-                } catch(PDOException $e) {
1535
-                        return "error : ".$e->getMessage();
1536
-                }
1533
+						$sth->execute();
1534
+				} catch(PDOException $e) {
1535
+						return "error : ".$e->getMessage();
1536
+				}
1537 1537
 	}
1538 1538
 
1539 1539
 	public static function check_last_notam_update() {
@@ -1546,13 +1546,13 @@  discard block
 block discarded – undo
1546 1546
 		try {
1547 1547
 			$Connection = new Connection();
1548 1548
 			$sth = $Connection->db->prepare($query);
1549
-                        $sth->execute();
1550
-                } catch(PDOException $e) {
1551
-                        return "error : ".$e->getMessage();
1552
-                }
1553
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
1554
-                if ($row['nb'] > 0) return false;
1555
-                else return true;
1549
+						$sth->execute();
1550
+				} catch(PDOException $e) {
1551
+						return "error : ".$e->getMessage();
1552
+				}
1553
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
1554
+				if ($row['nb'] > 0) return false;
1555
+				else return true;
1556 1556
 	}
1557 1557
 
1558 1558
 	public static function insert_last_notam_update() {
@@ -1561,10 +1561,10 @@  discard block
 block discarded – undo
1561 1561
 		try {
1562 1562
 			$Connection = new Connection();
1563 1563
 			$sth = $Connection->db->prepare($query);
1564
-                        $sth->execute();
1565
-                } catch(PDOException $e) {
1566
-                        return "error : ".$e->getMessage();
1567
-                }
1564
+						$sth->execute();
1565
+				} catch(PDOException $e) {
1566
+						return "error : ".$e->getMessage();
1567
+				}
1568 1568
 	}
1569 1569
 
1570 1570
 	public static function check_last_owner_update() {
@@ -1577,13 +1577,13 @@  discard block
 block discarded – undo
1577 1577
 		try {
1578 1578
 			$Connection = new Connection();
1579 1579
 			$sth = $Connection->db->prepare($query);
1580
-                        $sth->execute();
1581
-                } catch(PDOException $e) {
1582
-                        return "error : ".$e->getMessage();
1583
-                }
1584
-                $row = $sth->fetch(PDO::FETCH_ASSOC);
1585
-                if ($row['nb'] > 0) return false;
1586
-                else return true;
1580
+						$sth->execute();
1581
+				} catch(PDOException $e) {
1582
+						return "error : ".$e->getMessage();
1583
+				}
1584
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
1585
+				if ($row['nb'] > 0) return false;
1586
+				else return true;
1587 1587
 	}
1588 1588
 
1589 1589
 	public static function insert_last_owner_update() {
@@ -1592,10 +1592,10 @@  discard block
 block discarded – undo
1592 1592
 		try {
1593 1593
 			$Connection = new Connection();
1594 1594
 			$sth = $Connection->db->prepare($query);
1595
-                        $sth->execute();
1596
-                } catch(PDOException $e) {
1597
-                        return "error : ".$e->getMessage();
1598
-                }
1595
+						$sth->execute();
1596
+				} catch(PDOException $e) {
1597
+						return "error : ".$e->getMessage();
1598
+				}
1599 1599
 	}
1600 1600
 	
1601 1601
 	public static function update_all() {
Please login to merge, or discard this patch.
require/class.Connection.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 23;
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,19 +28,19 @@  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
 
38 38
 	/**
39
-	* Creates the database connection
40
-	*
41
-	* @return Boolean of the database connection
42
-	*
43
-	*/
39
+	 * Creates the database connection
40
+	 *
41
+	 * @return Boolean of the database connection
42
+	 *
43
+	 */
44 44
 
45 45
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
46 46
 	{
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			return false;
134 134
 		}
135 135
 		if($results->rowCount()>0) {
136
-		    return true; 
136
+			return true; 
137 137
 		}
138 138
 		else return false;
139 139
 	}
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
 				$sum = $sum->fetchColumn(0);
151 151
 			} else $sum = 0;
152 152
 			if (intval($sum) !== 2) {
153
-			     return false;
153
+				 return false;
154 154
 			}
155 155
 			
156 156
 		} catch(PDOException $e) {
157 157
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
158
-            			throw $e;
159
-	                }
160
-	                //echo 'error ! '.$e->getMessage();
158
+						throw $e;
159
+					}
160
+					//echo 'error ! '.$e->getMessage();
161 161
 			return false;
162 162
 		}
163 163
 		return true; 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			return false;
182 182
 		}
183 183
 		if($results->rowCount()>0) {
184
-		    return true; 
184
+			return true; 
185 185
 		}
186 186
 		else return false;
187 187
 	}
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 		$version = 0;
236 236
 		if ($this->tableExists('aircraft')) {
237 237
 			if (!$this->tableExists('config')) {
238
-	    			$version = '1';
239
-	    			return $version;
238
+					$version = '1';
239
+					return $version;
240 240
 			} else {
241 241
 				$Connection = new Connection();
242 242
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	* @return Boolean if latest version or not
258 258
 	*/
259 259
 	public function latest() {
260
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
261
-	    else return false;
260
+		if ($this->check_schema_version() == $this->latest_schema) return true;
261
+		else return false;
262 262
 	}
263 263
 
264 264
 }
Please login to merge, or discard this patch.