Completed
Push — master ( 157d06...e82944 )
by Yannick
08:43
created
scripts/daemon-spotter.php 1 patch
Indentation   +904 added lines, -904 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,42 +25,42 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->latest() === false) {
28
-    echo "You MUST update to latest schema. Run install/index.php";
29
-    exit();
28
+	echo "You MUST update to latest schema. Run install/index.php";
29
+	exit();
30 30
 }
31 31
 if (PHP_SAPI != 'cli') {
32
-    echo "This script MUST be called from console, not a web browser.";
32
+	echo "This script MUST be called from console, not a web browser.";
33 33
 //    exit();
34 34
 }
35 35
 
36 36
 // This is to be compatible with old version of settings.php
37 37
 if (!isset($globalSources)) {
38
-    if (isset($globalSBS1Hosts)) {
39
-        //$hosts = $globalSBS1Hosts;
40
-        foreach ($globalSBS1Hosts as $host) {
41
-	    $globalSources[] = array('host' => $host);
42
-    	}
43
-    } else {
44
-        if (!isset($globalSBS1Host)) {
45
-	    echo '$globalSources MUST be defined !';
46
-	    die;
38
+	if (isset($globalSBS1Hosts)) {
39
+		//$hosts = $globalSBS1Hosts;
40
+		foreach ($globalSBS1Hosts as $host) {
41
+		$globalSources[] = array('host' => $host);
42
+		}
43
+	} else {
44
+		if (!isset($globalSBS1Host)) {
45
+		echo '$globalSources MUST be defined !';
46
+		die;
47 47
 	}
48 48
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
49 49
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
50
-    }
50
+	}
51 51
 }
52 52
 
53 53
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver'));
54 54
 //if (isset($options['s'])) $hosts = array($options['s']);
55 55
 //elseif (isset($options['source'])) $hosts = array($options['source']);
56 56
 if (isset($options['s'])) {
57
-    $globalSources = array();
58
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
-    else $globalSources[] = array('host' => $options['s']);
57
+	$globalSources = array();
58
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
+	else $globalSources[] = array('host' => $options['s']);
60 60
 } elseif (isset($options['source'])) {
61
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['source']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['source']);
64 64
 }
65 65
 if (isset($options['aprsserverhost'])) {
66 66
 	$globalServerAPRS = TRUE;
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 if (isset($options['idsource'])) $id_source = $options['idsource'];
76 76
 else $id_source = 1;
77 77
 if (isset($globalServer) && $globalServer) {
78
-    if ($globalDebug) echo "Using Server Mode\n";
79
-    $SI=new SpotterServer();
78
+	if ($globalDebug) echo "Using Server Mode\n";
79
+	$SI=new SpotterServer();
80 80
 /*
81 81
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
82 82
     $SI = new adsb2aprs();
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 } else $SI=new SpotterImport($Connection->db);
86 86
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
87 87
 if (isset($globalMarine) && $globalMarine) {
88
-    $AIS = new AIS();
89
-    $MI = new MarineImport($Connection->db);
88
+	$AIS = new AIS();
89
+	$MI = new MarineImport($Connection->db);
90 90
 }
91 91
 //$APRS=new APRS($Connection->db);
92 92
 $SBS=new SBS();
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
 //$servertz = system('date +%Z');
98 98
 // signal handler - playing nice with sockets and dump1090
99 99
 if (function_exists('pcntl_fork')) {
100
-    pcntl_signal(SIGINT,  function() {
101
-        global $sockets;
102
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
103
-        die("Bye!\n");
104
-    });
105
-    pcntl_signal_dispatch();
100
+	pcntl_signal(SIGINT,  function() {
101
+		global $sockets;
102
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
103
+		die("Bye!\n");
104
+	});
105
+	pcntl_signal_dispatch();
106 106
 }
107 107
 
108 108
 // let's try and connect
@@ -112,36 +112,36 @@  discard block
 block discarded – undo
112 112
 $reset = 0;
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    /*
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			/*
145 145
     	    // Disabled for now, site change source format
146 146
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
147 147
         	//$formats[$id] = 'radarvirtueljson';
@@ -153,118 +153,118 @@  discard block
 block discarded – undo
153 153
         	    exit(0);
154 154
         	}
155 155
     	    */
156
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
157
-        	//$formats[$id] = 'planeupdatefaa';
158
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
159
-        	//$last_exec['planeupdatefaa'] = 0;
160
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
161
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163
-        	    exit(0);
164
-        	}
165
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
166
-        	//$formats[$id] = 'phpvmacars';
167
-        	$globalSources[$id]['format'] = 'phpvmacars';
168
-        	//$last_exec['phpvmacars'] = 0;
169
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
170
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
171
-        	//$formats[$id] = 'phpvmacars';
172
-        	$globalSources[$id]['format'] = 'vam';
173
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
174
-            } else if (preg_match('/whazzup/i',$host)) {
175
-        	//$formats[$id] = 'whazzup';
176
-        	$globalSources[$id]['format'] = 'whazzup';
177
-        	//$last_exec['whazzup'] = 0;
178
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
179
-            } else if (preg_match('/airwhere/i',$host)) {
180
-        	$globalSources[$id]['format'] = 'airwhere';
181
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
182
-            } else if (preg_match('/recentpireps/i',$host)) {
183
-        	//$formats[$id] = 'pirepsjson';
184
-        	$globalSources[$id]['format'] = 'pirepsjson';
185
-        	//$last_exec['pirepsjson'] = 0;
186
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
187
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188
-        	//$formats[$id] = 'fr24json';
189
-        	$globalSources[$id]['format'] = 'fr24json';
190
-        	//$last_exec['fr24json'] = 0;
191
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
192
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194
-        	    exit(0);
195
-        	}
196
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
197
-        	//$formats[$id] = 'fr24json';
198
-        	$globalSources[$id]['format'] = 'myshiptracking';
199
-        	//$last_exec['fr24json'] = 0;
200
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
201
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203
-        	    exit(0);
204
-        	}
205
-            //} else if (preg_match('/10001/',$host)) {
206
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207
-        	//$formats[$id] = 'tsv';
208
-        	$globalSources[$id]['format'] = 'tsv';
209
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
210
-            }
211
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
214
-    		    if ($idf !== false) {
215
-    			$httpfeeds[$id] = $idf;
216
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
217
-    		    }
218
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
220
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221
-	    $hostport = explode(':',$host);
222
-	    if (isset($hostport[1])) {
156
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
157
+			//$formats[$id] = 'planeupdatefaa';
158
+			$globalSources[$id]['format'] = 'planeupdatefaa';
159
+			//$last_exec['planeupdatefaa'] = 0;
160
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
161
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163
+				exit(0);
164
+			}
165
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
166
+			//$formats[$id] = 'phpvmacars';
167
+			$globalSources[$id]['format'] = 'phpvmacars';
168
+			//$last_exec['phpvmacars'] = 0;
169
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
170
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
171
+			//$formats[$id] = 'phpvmacars';
172
+			$globalSources[$id]['format'] = 'vam';
173
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
174
+			} else if (preg_match('/whazzup/i',$host)) {
175
+			//$formats[$id] = 'whazzup';
176
+			$globalSources[$id]['format'] = 'whazzup';
177
+			//$last_exec['whazzup'] = 0;
178
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
179
+			} else if (preg_match('/airwhere/i',$host)) {
180
+			$globalSources[$id]['format'] = 'airwhere';
181
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
182
+			} else if (preg_match('/recentpireps/i',$host)) {
183
+			//$formats[$id] = 'pirepsjson';
184
+			$globalSources[$id]['format'] = 'pirepsjson';
185
+			//$last_exec['pirepsjson'] = 0;
186
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
187
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188
+			//$formats[$id] = 'fr24json';
189
+			$globalSources[$id]['format'] = 'fr24json';
190
+			//$last_exec['fr24json'] = 0;
191
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
192
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194
+				exit(0);
195
+			}
196
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
197
+			//$formats[$id] = 'fr24json';
198
+			$globalSources[$id]['format'] = 'myshiptracking';
199
+			//$last_exec['fr24json'] = 0;
200
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
201
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203
+				exit(0);
204
+			}
205
+			//} else if (preg_match('/10001/',$host)) {
206
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207
+			//$formats[$id] = 'tsv';
208
+			$globalSources[$id]['format'] = 'tsv';
209
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
210
+			}
211
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
214
+				if ($idf !== false) {
215
+				$httpfeeds[$id] = $idf;
216
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
217
+				}
218
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
220
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221
+		$hostport = explode(':',$host);
222
+		if (isset($hostport[1])) {
223 223
 		$port = $hostport[1];
224 224
 		$hostn = $hostport[0];
225
-	    } else {
225
+		} else {
226 226
 		$port = $globalSources[$id]['port'];
227 227
 		$hostn = $globalSources[$id]['host'];
228
-	    }
229
-	    $Common = new Common();
230
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
231
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
232
-    	    } else {
233
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
234
-	    }
235
-	    if ($s) {
236
-    	        $sockets[$id] = $s;
237
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
238
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
228
+		}
229
+		$Common = new Common();
230
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
231
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
232
+			} else {
233
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
234
+		}
235
+		if ($s) {
236
+				$sockets[$id] = $s;
237
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
238
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
239 239
 			//$formats[$id] = 'aprs';
240 240
 			$globalSources[$id]['format'] = 'aprs';
241 241
 			//$aprs_connect = 0;
242 242
 			//$use_aprs = true;
243
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
243
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
244 244
 			$globalSources[$id]['format'] = 'vrstcp';
245
-    		    } elseif ($port == '10001') {
246
-        		//$formats[$id] = 'tsv';
247
-        		$globalSources[$id]['format'] = 'tsv';
248
-		    } elseif ($port == '30002') {
249
-        		//$formats[$id] = 'raw';
250
-        		$globalSources[$id]['format'] = 'raw';
251
-		    } elseif ($port == '5001') {
252
-        		//$formats[$id] = 'raw';
253
-        		$globalSources[$id]['format'] = 'flightgearmp';
254
-		    } elseif ($port == '30005') {
245
+				} elseif ($port == '10001') {
246
+				//$formats[$id] = 'tsv';
247
+				$globalSources[$id]['format'] = 'tsv';
248
+			} elseif ($port == '30002') {
249
+				//$formats[$id] = 'raw';
250
+				$globalSources[$id]['format'] = 'raw';
251
+			} elseif ($port == '5001') {
252
+				//$formats[$id] = 'raw';
253
+				$globalSources[$id]['format'] = 'flightgearmp';
254
+			} elseif ($port == '30005') {
255 255
 			// Not yet supported
256
-        		//$formats[$id] = 'beast';
257
-        		$globalSources[$id]['format'] = 'beast';
258
-		    //} else $formats[$id] = 'sbs';
259
-		    } else $globalSources[$id]['format'] = 'sbs';
260
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
256
+				//$formats[$id] = 'beast';
257
+				$globalSources[$id]['format'] = 'beast';
258
+			//} else $formats[$id] = 'sbs';
259
+			} else $globalSources[$id]['format'] = 'sbs';
260
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
261 261
 		}
262 262
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
263
-            } else {
263
+			} else {
264 264
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
265
-    	    }
266
-        }
267
-    }
265
+			}
266
+		}
267
+	}
268 268
 }
269 269
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
270 270
 
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 //connect_all($globalSources);
288 288
 
289 289
 if (isset($globalProxy) && $globalProxy) {
290
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
290
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
291 291
 } else {
292
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
292
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
293 293
 }
294 294
 
295 295
 // APRS Configuration
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 	die;
299 299
 }
300 300
 foreach ($globalSources as $key => $source) {
301
-    if (!isset($source['format'])) {
302
-        $globalSources[$key]['format'] = 'auto';
303
-    }
301
+	if (!isset($source['format'])) {
302
+		$globalSources[$key]['format'] = 'auto';
303
+	}
304 304
 }
305 305
 connect_all($globalSources);
306 306
 foreach ($globalSources as $key => $source) {
307
-    if (isset($source['format']) && $source['format'] == 'aprs') {
307
+	if (isset($source['format']) && $source['format'] == 'aprs') {
308 308
 	$aprs_connect = 0;
309 309
 	$use_aprs = true;
310 310
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
311 311
 	break;
312
-    }
312
+	}
313 313
 }
314 314
 
315 315
 if ($use_aprs) {
@@ -350,115 +350,115 @@  discard block
 block discarded – undo
350 350
 
351 351
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
352 352
 while ($i > 0) {
353
-    if (!$globalDaemon) $i = $endtime-time();
354
-    // Delete old ATC
355
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
353
+	if (!$globalDaemon) $i = $endtime-time();
354
+	// Delete old ATC
355
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
356 356
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
357
-        $ATC->deleteOldATC();
358
-    }
357
+		$ATC->deleteOldATC();
358
+	}
359 359
     
360
-    if (count($last_exec) == count($globalSources)) {
360
+	if (count($last_exec) == count($globalSources)) {
361 361
 	$max = $globalMinFetch;
362 362
 	foreach ($last_exec as $last) {
363
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
363
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
364 364
 	}
365 365
 	if ($max != $globalMinFetch) {
366
-	    if ($globalDebug) echo 'Sleeping...'."\n";
367
-	    sleep($globalMinFetch-$max+2);
366
+		if ($globalDebug) echo 'Sleeping...'."\n";
367
+		sleep($globalMinFetch-$max+2);
368
+	}
368 369
 	}
369
-    }
370 370
 
371 371
     
372
-    //foreach ($formats as $id => $value) {
373
-    foreach ($globalSources as $id => $value) {
372
+	//foreach ($formats as $id => $value) {
373
+	foreach ($globalSources as $id => $value) {
374 374
 	date_default_timezone_set('UTC');
375 375
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
376 376
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
377
-	    //$buffer = $Common->getData($hosts[$id]);
378
-	    $buffer = $Common->getData($value['host']);
379
-	    if ($buffer != '') $reset = 0;
380
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
381
-	    $buffer = explode('\n',$buffer);
382
-	    foreach ($buffer as $line) {
383
-    		if ($line != '' && count($line) > 7) {
384
-    		    $line = explode(',', $line);
385
-	            $data = array();
386
-	            $data['hex'] = $line[1]; // hex
387
-	            $data['ident'] = $line[2]; // ident
388
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
389
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
390
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
391
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
392
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
393
-	            $data['verticalrate'] = ''; // vertical rate
394
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
395
-	            $data['emergency'] = ''; // emergency
396
-		    $data['datetime'] = date('Y-m-d H:i:s');
397
-		    $data['format_source'] = 'deltadbtxt';
398
-    		    $data['id_source'] = $id_source;
399
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
400
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
401
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
402
-    		    $SI->add($data);
403
-		    unset($data);
404
-    		}
405
-    	    }
406
-    	    $last_exec[$id]['last'] = time();
377
+		//$buffer = $Common->getData($hosts[$id]);
378
+		$buffer = $Common->getData($value['host']);
379
+		if ($buffer != '') $reset = 0;
380
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
381
+		$buffer = explode('\n',$buffer);
382
+		foreach ($buffer as $line) {
383
+			if ($line != '' && count($line) > 7) {
384
+				$line = explode(',', $line);
385
+				$data = array();
386
+				$data['hex'] = $line[1]; // hex
387
+				$data['ident'] = $line[2]; // ident
388
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
389
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
390
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
391
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
392
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
393
+				$data['verticalrate'] = ''; // vertical rate
394
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
395
+				$data['emergency'] = ''; // emergency
396
+			$data['datetime'] = date('Y-m-d H:i:s');
397
+			$data['format_source'] = 'deltadbtxt';
398
+				$data['id_source'] = $id_source;
399
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
400
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
401
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
402
+				$SI->add($data);
403
+			unset($data);
404
+			}
405
+			}
406
+			$last_exec[$id]['last'] = time();
407 407
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
408
-	    date_default_timezone_set('CET');
409
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
410
-	    date_default_timezone_set('UTC');
411
-	    if ($buffer != '') $reset = 0;
412
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
-	    $buffer = explode('\n',$buffer);
414
-	    foreach ($buffer as $line) {
408
+		date_default_timezone_set('CET');
409
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
410
+		date_default_timezone_set('UTC');
411
+		if ($buffer != '') $reset = 0;
412
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
+		$buffer = explode('\n',$buffer);
414
+		foreach ($buffer as $line) {
415 415
 		if ($line != '') {
416
-		    //echo "'".$line."'\n";
417
-		    $add = false;
418
-		    $ais_data = $AIS->parse_line(trim($line));
419
-		    $data = array();
420
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
421
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
422
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
423
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
424
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
425
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
426
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
427
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
428
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
429
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
430
-		    if (isset($ais_data['timestamp'])) {
416
+			//echo "'".$line."'\n";
417
+			$add = false;
418
+			$ais_data = $AIS->parse_line(trim($line));
419
+			$data = array();
420
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
421
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
422
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
423
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
424
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
425
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
426
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
427
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
428
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
429
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
430
+			if (isset($ais_data['timestamp'])) {
431 431
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
432 432
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
433
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
434
-			    $add = true;
433
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
434
+				$add = true;
435 435
 			}
436
-		    } else {
436
+			} else {
437 437
 			$data['datetime'] = date('Y-m-d H:i:s');
438 438
 			$add = true;
439
-		    }
440
-		    $data['format_source'] = 'aisnmeatxt';
441
-    		    $data['id_source'] = $id_source;
442
-		    //print_r($data);
443
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
444
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
445
-		    unset($data);
439
+			}
440
+			$data['format_source'] = 'aisnmeatxt';
441
+				$data['id_source'] = $id_source;
442
+			//print_r($data);
443
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
444
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
445
+			unset($data);
446 446
 		}
447
-    	    }
448
-    	    $last_exec[$id]['last'] = time();
447
+			}
448
+			$last_exec[$id]['last'] = time();
449 449
 	} elseif ($value['format'] == 'aisnmeahttp') {
450
-	    $arr = $httpfeeds;
451
-	    $w = $e = null;
450
+		$arr = $httpfeeds;
451
+		$w = $e = null;
452 452
 	    
453
-	    if (isset($arr[$id])) {
453
+		if (isset($arr[$id])) {
454 454
 		$nn = stream_select($arr,$w,$e,$timeout);
455 455
 		if ($nn > 0) {
456
-		    foreach ($httpfeeds as $feed) {
456
+			foreach ($httpfeeds as $feed) {
457 457
 			$buffer = stream_get_line($feed,2000,"\n");
458 458
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
459 459
 			$buffer = explode('\n',$buffer);
460 460
 			foreach ($buffer as $line) {
461
-			    if ($line != '') {
461
+				if ($line != '') {
462 462
 				$ais_data = $AIS->parse_line(trim($line));
463 463
 				$data = array();
464 464
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -476,96 +476,96 @@  discard block
 block discarded – undo
476 476
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
477 477
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
478 478
 				if (isset($ais_data['timestamp'])) {
479
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
479
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
480 480
 				} else {
481
-				    $data['datetime'] = date('Y-m-d H:i:s');
481
+					$data['datetime'] = date('Y-m-d H:i:s');
482 482
 				}
483 483
 				$data['format_source'] = 'aisnmeahttp';
484 484
 				$data['id_source'] = $id_source;
485 485
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
486 486
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
487 487
 				unset($data);
488
-			    }
488
+				}
489
+			}
489 490
 			}
490
-		    }
491 491
 		} else {
492
-		    $format = $value['format'];
493
-		    if (isset($tt[$format])) $tt[$format]++;
494
-		    else $tt[$format] = 0;
495
-		    if ($tt[$format] > 30) {
492
+			$format = $value['format'];
493
+			if (isset($tt[$format])) $tt[$format]++;
494
+			else $tt[$format] = 0;
495
+			if ($tt[$format] > 30) {
496 496
 			if ($globalDebug) echo 'Reconnect...'."\n";
497 497
 			sleep(2);
498 498
 			$sourceeen[] = $value;
499 499
 			connect_all($sourceeen);
500 500
 			$sourceeen = array();
501
-		    }
501
+			}
502
+		}
502 503
 		}
503
-	    }
504 504
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
505
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
506
-	    if ($buffer != '') {
505
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
506
+		if ($buffer != '') {
507 507
 		//echo $buffer;
508 508
 		$all_data = json_decode($buffer,true);
509 509
 		//print_r($all_data);
510 510
 		if (isset($all_data[0]['DATA'])) {
511
-		    foreach ($all_data[0]['DATA'] as $line) {
511
+			foreach ($all_data[0]['DATA'] as $line) {
512 512
 			if ($line != '') {
513
-			    $data = array();
514
-			    $data['ident'] = $line['NAME'];
515
-			    $data['mmsi'] = $line['MMSI'];
516
-			    $data['speed'] = $line['SOG'];
517
-			    $data['heading'] = $line['COG'];
518
-			    $data['latitude'] = $line['LAT'];
519
-			    $data['longitude'] = $line['LNG'];
520
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
521
-			    $data['imo'] = $line['IMO'];
522
-			    //$data['arrival_code'] = $ais_data['destination'];
523
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
524
-			    $data['format_source'] = 'myshiptracking';
525
-			    $data['id_source'] = $id_source;
526
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
527
-			    $MI->add($data);
528
-			    unset($data);
513
+				$data = array();
514
+				$data['ident'] = $line['NAME'];
515
+				$data['mmsi'] = $line['MMSI'];
516
+				$data['speed'] = $line['SOG'];
517
+				$data['heading'] = $line['COG'];
518
+				$data['latitude'] = $line['LAT'];
519
+				$data['longitude'] = $line['LNG'];
520
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
521
+				$data['imo'] = $line['IMO'];
522
+				//$data['arrival_code'] = $ais_data['destination'];
523
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
524
+				$data['format_source'] = 'myshiptracking';
525
+				$data['id_source'] = $id_source;
526
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
527
+				$MI->add($data);
528
+				unset($data);
529
+			}
529 530
 			}
530
-		    }
531 531
 		}
532
-	    }
533
-	    $last_exec[$id]['last'] = time();
532
+		}
533
+		$last_exec[$id]['last'] = time();
534 534
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
535
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
536
-	    if ($buffer != '') {
535
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
536
+		if ($buffer != '') {
537 537
 		$all_data = json_decode($buffer,true);
538 538
 		if (isset($all_data[0]['mmsi'])) {
539
-		    foreach ($all_data as $line) {
539
+			foreach ($all_data as $line) {
540 540
 			if ($line != '') {
541
-			    $data = array();
542
-			    $data['ident'] = $line['shipname'];
543
-			    $data['callsign'] = $line['callsign'];
544
-			    $data['mmsi'] = $line['mmsi'];
545
-			    $data['speed'] = $line['sog'];
546
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
547
-			    $data['latitude'] = $line['latitude'];
548
-			    $data['longitude'] = $line['longitude'];
549
-			    $data['type_id'] = $line['shiptype'];
550
-			    $data['arrival_code'] = $line['destination'];
551
-			    $data['datetime'] = $line['time'];
552
-			    $data['format_source'] = 'boatbeaconapp';
553
-			    $data['id_source'] = $id_source;
554
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
555
-			    $MI->add($data);
556
-			    unset($data);
541
+				$data = array();
542
+				$data['ident'] = $line['shipname'];
543
+				$data['callsign'] = $line['callsign'];
544
+				$data['mmsi'] = $line['mmsi'];
545
+				$data['speed'] = $line['sog'];
546
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
547
+				$data['latitude'] = $line['latitude'];
548
+				$data['longitude'] = $line['longitude'];
549
+				$data['type_id'] = $line['shiptype'];
550
+				$data['arrival_code'] = $line['destination'];
551
+				$data['datetime'] = $line['time'];
552
+				$data['format_source'] = 'boatbeaconapp';
553
+				$data['id_source'] = $id_source;
554
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
555
+				$MI->add($data);
556
+				unset($data);
557
+			}
557 558
 			}
558
-		    }
559 559
 		}
560 560
 		
561
-	    }
562
-    	    $last_exec[$id]['last'] = time();
561
+		}
562
+			$last_exec[$id]['last'] = time();
563 563
 	} elseif ($value['format'] == 'boatnerd' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
564
-	    $buffer = $Common->getData($value['host']);
565
-	    if ($buffer != '') {
564
+		$buffer = $Common->getData($value['host']);
565
+		if ($buffer != '') {
566 566
 		$all_data = json_decode($buffer,true);
567 567
 		if (isset($all_data['features'][0]['id'])) {
568
-		    foreach ($all_data['features'] as $line) {
568
+			foreach ($all_data['features'] as $line) {
569 569
 			$data = array();
570 570
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
571 571
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
@@ -584,59 +584,59 @@  discard block
 block discarded – undo
584 584
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
585 585
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
586 586
 			unset($data);
587
-		    }
587
+			}
588 588
 		}
589 589
 		
590
-	    }
591
-    	    $last_exec[$id]['last'] = time();
590
+		}
591
+			$last_exec[$id]['last'] = time();
592 592
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
593
-	    echo 'download...';
594
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
595
-	    echo 'done !'."\n";
596
-	    if ($buffer != '') $reset = 0;
597
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
598
-	    $buffer = explode('\n',$buffer);
599
-	    foreach ($buffer as $line) {
593
+		echo 'download...';
594
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
595
+		echo 'done !'."\n";
596
+		if ($buffer != '') $reset = 0;
597
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
598
+		$buffer = explode('\n',$buffer);
599
+		foreach ($buffer as $line) {
600 600
 		if ($line != '') {
601
-		    $data = array();
602
-		    $data['mmsi'] = (int)substr($line,0,9);
603
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
604
-		    //$data['status'] = substr($line,21,2);
605
-		    //$data['type'] = substr($line,24,3);
606
-		    $data['latitude'] = substr($line,29,9);
607
-		    $data['longitude'] = substr($line,41,9);
608
-		    $data['speed'] = round(substr($line,51,5));
609
-		    //$data['course'] = substr($line,57,5);
610
-		    $data['heading'] = round(substr($line,63,3));
611
-		    //$data['draft'] = substr($line,67,4);
612
-		    //$data['length'] = substr($line,72,3);
613
-		    //$data['beam'] = substr($line,76,2);
614
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
615
-		    //$data['callsign'] = trim(substr($line,100,7);
616
-		    //$data['dest'] = substr($line,108,20);
617
-		    //$data['etaDate'] = substr($line,129,5);
618
-		    //$data['etaTime'] = substr($line,135,5);
619
-		    $data['format_source'] = 'shipplotter';
620
-    		    $data['id_source'] = $id_source;
621
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
622
-		    //print_r($data);
623
-		    echo 'Add...'."\n";
624
-		    $MI->add($data);
625
-		    unset($data);
601
+			$data = array();
602
+			$data['mmsi'] = (int)substr($line,0,9);
603
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
604
+			//$data['status'] = substr($line,21,2);
605
+			//$data['type'] = substr($line,24,3);
606
+			$data['latitude'] = substr($line,29,9);
607
+			$data['longitude'] = substr($line,41,9);
608
+			$data['speed'] = round(substr($line,51,5));
609
+			//$data['course'] = substr($line,57,5);
610
+			$data['heading'] = round(substr($line,63,3));
611
+			//$data['draft'] = substr($line,67,4);
612
+			//$data['length'] = substr($line,72,3);
613
+			//$data['beam'] = substr($line,76,2);
614
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
615
+			//$data['callsign'] = trim(substr($line,100,7);
616
+			//$data['dest'] = substr($line,108,20);
617
+			//$data['etaDate'] = substr($line,129,5);
618
+			//$data['etaTime'] = substr($line,135,5);
619
+			$data['format_source'] = 'shipplotter';
620
+				$data['id_source'] = $id_source;
621
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
622
+			//print_r($data);
623
+			echo 'Add...'."\n";
624
+			$MI->add($data);
625
+			unset($data);
626 626
 		}
627
-    	    }
628
-    	    $last_exec[$id]['last'] = time();
627
+			}
628
+			$last_exec[$id]['last'] = time();
629 629
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
630 630
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
631
-	    //$buffer = $Common->getData($hosts[$id]);
632
-	    $buffer = $Common->getData($value['host']);
633
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
634
-	    $buffer = explode('\n',$buffer);
635
-	    $reset = 0;
636
-	    foreach ($buffer as $line) {
637
-    		if ($line != '') {
638
-    		    $line = explode(':', $line);
639
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
631
+		//$buffer = $Common->getData($hosts[$id]);
632
+		$buffer = $Common->getData($value['host']);
633
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
634
+		$buffer = explode('\n',$buffer);
635
+		$reset = 0;
636
+		foreach ($buffer as $line) {
637
+			if ($line != '') {
638
+				$line = explode(':', $line);
639
+				if (count($line) > 30 && $line[0] != 'callsign') {
640 640
 			$data = array();
641 641
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
642 642
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -649,37 +649,37 @@  discard block
 block discarded – undo
649 649
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
650 650
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
651 651
 			$data['latitude'] = $line[5]; // lat
652
-	        	$data['longitude'] = $line[6]; // long
653
-	        	$data['verticalrate'] = ''; // vertical rate
654
-	        	$data['squawk'] = ''; // squawk
655
-	        	$data['emergency'] = ''; // emergency
656
-	        	$data['waypoints'] = $line[30];
652
+				$data['longitude'] = $line[6]; // long
653
+				$data['verticalrate'] = ''; // vertical rate
654
+				$data['squawk'] = ''; // squawk
655
+				$data['emergency'] = ''; // emergency
656
+				$data['waypoints'] = $line[30];
657 657
 			$data['datetime'] = date('Y-m-d H:i:s');
658 658
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
659 659
 			//if (isset($line[37])) $data['last_update'] = $line[37];
660
-		        $data['departure_airport_icao'] = $line[11];
661
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
662
-		        $data['arrival_airport_icao'] = $line[13];
660
+				$data['departure_airport_icao'] = $line[11];
661
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
662
+				$data['arrival_airport_icao'] = $line[13];
663 663
 			$data['frequency'] = $line[4];
664 664
 			$data['type'] = $line[18];
665 665
 			$data['range'] = $line[19];
666 666
 			if (isset($line[35])) $data['info'] = $line[35];
667
-    			$data['id_source'] = $id_source;
668
-	    		//$data['arrival_airport_time'] = ;
669
-	    		if ($line[9] != '') {
670
-	    		    $aircraft_data = explode('/',$line[9]);
671
-	    		    if (isset($aircraft_data[1])) {
672
-	    			$data['aircraft_icao'] = $aircraft_data[1];
673
-	    		    }
674
-        		}
675
-	    		/*
667
+				$data['id_source'] = $id_source;
668
+				//$data['arrival_airport_time'] = ;
669
+				if ($line[9] != '') {
670
+					$aircraft_data = explode('/',$line[9]);
671
+					if (isset($aircraft_data[1])) {
672
+					$data['aircraft_icao'] = $aircraft_data[1];
673
+					}
674
+				}
675
+				/*
676 676
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
677 677
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
678 678
 	    		*/
679
-	    		$data['format_source'] = $value['format'];
679
+				$data['format_source'] = $value['format'];
680 680
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
681 681
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
682
-    			if ($line[3] == 'PILOT') $SI->add($data);
682
+				if ($line[3] == 'PILOT') $SI->add($data);
683 683
 			elseif ($line[3] == 'ATC') {
684 684
 				//print_r($data);
685 685
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -700,16 +700,16 @@  discard block
 block discarded – undo
700 700
 					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
701 701
 				}
702 702
 			}
703
-    			unset($data);
704
-    		    }
705
-    		}
706
-    	    }
707
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
708
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
709
-    	    $last_exec[$id]['last'] = time();
710
-    	} elseif ($value['format'] == 'airwhere' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
711
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
712
-	    if ($buffer != '') {
703
+				unset($data);
704
+				}
705
+			}
706
+			}
707
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
708
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
709
+			$last_exec[$id]['last'] = time();
710
+		} elseif ($value['format'] == 'airwhere' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
711
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
712
+		if ($buffer != '') {
713 713
 		$all_data = simplexml_load_string($buffer);
714 714
 		foreach($all_data->children() as $childdata) {
715 715
 			$data = array();
@@ -731,10 +731,10 @@  discard block
 block discarded – undo
731 731
 			$SI->add($data);
732 732
 			unset($data);
733 733
 		}
734
-	    }
735
-	    $Source->deleteOldLocationByType('gs');
736
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
737
-	    if ($buffer != '') {
734
+		}
735
+		$Source->deleteOldLocationByType('gs');
736
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
737
+		if ($buffer != '') {
738 738
 		$all_data = simplexml_load_string($buffer);
739 739
 		foreach($all_data->children() as $childdata) {
740 740
 			$data = array();
@@ -752,249 +752,249 @@  discard block
 block discarded – undo
752 752
 			}
753 753
 			unset($data);
754 754
 		}
755
-	    }
756
-	    $last_exec[$id]['last'] = time();
755
+		}
756
+		$last_exec[$id]['last'] = time();
757 757
 	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
758
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
759
-	    if ($buffer != '') {
760
-	    $all_data = json_decode($buffer,true);
761
-	    if (isset($all_data['acList'])) {
758
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
759
+		if ($buffer != '') {
760
+		$all_data = json_decode($buffer,true);
761
+		if (isset($all_data['acList'])) {
762 762
 		$reset = 0;
763 763
 		foreach ($all_data['acList'] as $line) {
764
-		    $data = array();
765
-		    $data['hex'] = $line['Icao']; // hex
766
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
767
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
768
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
769
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
770
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
771
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
772
-		    //$data['verticalrate'] = $line['']; // verticale rate
773
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
774
-		    $data['emergency'] = ''; // emergency
775
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
764
+			$data = array();
765
+			$data['hex'] = $line['Icao']; // hex
766
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
767
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
768
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
769
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
770
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
771
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
772
+			//$data['verticalrate'] = $line['']; // verticale rate
773
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
774
+			$data['emergency'] = ''; // emergency
775
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
776 776
 		    
777
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
778
-		    else $data['datetime'] = date('Y-m-d H:i:s');
777
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
778
+			else $data['datetime'] = date('Y-m-d H:i:s');
779 779
 		    
780
-		    //$data['datetime'] = date('Y-m-d H:i:s');
781
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
782
-	    	    $data['format_source'] = 'aircraftlistjson';
783
-		    $data['id_source'] = $id_source;
784
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
785
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
786
-		    if (isset($data['latitude'])) $SI->add($data);
787
-		    unset($data);
780
+			//$data['datetime'] = date('Y-m-d H:i:s');
781
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
782
+				$data['format_source'] = 'aircraftlistjson';
783
+			$data['id_source'] = $id_source;
784
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
785
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
786
+			if (isset($data['latitude'])) $SI->add($data);
787
+			unset($data);
788 788
 		}
789
-	    } elseif (is_array($all_data)) {
789
+		} elseif (is_array($all_data)) {
790 790
 		$reset = 0;
791 791
 		foreach ($all_data as $line) {
792
-		    $data = array();
793
-		    $data['hex'] = $line['hex']; // hex
794
-		    $data['ident'] = $line['flight']; // ident
795
-		    $data['altitude'] = $line['altitude']; // altitude
796
-		    $data['speed'] = $line['speed']; // speed
797
-		    $data['heading'] = $line['track']; // heading
798
-		    $data['latitude'] = $line['lat']; // lat
799
-		    $data['longitude'] = $line['lon']; // long
800
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
801
-		    $data['squawk'] = $line['squawk']; // squawk
802
-		    $data['emergency'] = ''; // emergency
803
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
804
-		    else $data['datetime'] = date('Y-m-d H:i:s');
805
-	    	    $data['format_source'] = 'aircraftlistjson';
806
-    		    $data['id_source'] = $id_source;
807
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
808
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
809
-		    $SI->add($data);
810
-		    unset($data);
792
+			$data = array();
793
+			$data['hex'] = $line['hex']; // hex
794
+			$data['ident'] = $line['flight']; // ident
795
+			$data['altitude'] = $line['altitude']; // altitude
796
+			$data['speed'] = $line['speed']; // speed
797
+			$data['heading'] = $line['track']; // heading
798
+			$data['latitude'] = $line['lat']; // lat
799
+			$data['longitude'] = $line['lon']; // long
800
+			$data['verticalrate'] = $line['vrt']; // verticale rate
801
+			$data['squawk'] = $line['squawk']; // squawk
802
+			$data['emergency'] = ''; // emergency
803
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
804
+			else $data['datetime'] = date('Y-m-d H:i:s');
805
+				$data['format_source'] = 'aircraftlistjson';
806
+				$data['id_source'] = $id_source;
807
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
808
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
809
+			$SI->add($data);
810
+			unset($data);
811
+		}
811 812
 		}
812
-	    }
813
-	    }
814
-    	    //$last_exec['aircraftlistjson'] = time();
815
-    	    $last_exec[$id]['last'] = time();
816
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
817
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
818
-	    $buffer = $Common->getData($value['host']);
819
-	    $all_data = json_decode($buffer,true);
820
-	    if (isset($all_data['planes'])) {
813
+		}
814
+			//$last_exec['aircraftlistjson'] = time();
815
+			$last_exec[$id]['last'] = time();
816
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
817
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
818
+		$buffer = $Common->getData($value['host']);
819
+		$all_data = json_decode($buffer,true);
820
+		if (isset($all_data['planes'])) {
821 821
 		$reset = 0;
822 822
 		foreach ($all_data['planes'] as $key => $line) {
823
-		    $data = array();
824
-		    $data['hex'] = $key; // hex
825
-		    $data['ident'] = $line[3]; // ident
826
-		    $data['altitude'] = $line[6]; // altitude
827
-		    $data['speed'] = $line[8]; // speed
828
-		    $data['heading'] = $line[7]; // heading
829
-		    $data['latitude'] = $line[4]; // lat
830
-		    $data['longitude'] = $line[5]; // long
831
-		    //$data['verticalrate'] = $line[]; // verticale rate
832
-		    $data['squawk'] = $line[10]; // squawk
833
-		    $data['emergency'] = ''; // emergency
834
-		    $data['registration'] = $line[2];
835
-		    $data['aircraft_icao'] = $line[0];
836
-		    $deparr = explode('-',$line[1]);
837
-		    if (count($deparr) == 2) {
823
+			$data = array();
824
+			$data['hex'] = $key; // hex
825
+			$data['ident'] = $line[3]; // ident
826
+			$data['altitude'] = $line[6]; // altitude
827
+			$data['speed'] = $line[8]; // speed
828
+			$data['heading'] = $line[7]; // heading
829
+			$data['latitude'] = $line[4]; // lat
830
+			$data['longitude'] = $line[5]; // long
831
+			//$data['verticalrate'] = $line[]; // verticale rate
832
+			$data['squawk'] = $line[10]; // squawk
833
+			$data['emergency'] = ''; // emergency
834
+			$data['registration'] = $line[2];
835
+			$data['aircraft_icao'] = $line[0];
836
+			$deparr = explode('-',$line[1]);
837
+			if (count($deparr) == 2) {
838 838
 			$data['departure_airport_icao'] = $deparr[0];
839 839
 			$data['arrival_airport_icao'] = $deparr[1];
840
-		    }
841
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
842
-	    	    $data['format_source'] = 'planeupdatefaa';
843
-    		    $data['id_source'] = $id_source;
844
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
845
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
846
-		    $SI->add($data);
847
-		    unset($data);
840
+			}
841
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
842
+				$data['format_source'] = 'planeupdatefaa';
843
+				$data['id_source'] = $id_source;
844
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
845
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
846
+			$SI->add($data);
847
+			unset($data);
848 848
 		}
849
-	    }
850
-    	    //$last_exec['planeupdatefaa'] = time();
851
-    	    $last_exec[$id]['last'] = time();
852
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
853
-	    $buffer = $Common->getData($value['host']);
854
-	    $all_data = json_decode($buffer,true);
855
-	    if (isset($all_data['states'])) {
849
+		}
850
+			//$last_exec['planeupdatefaa'] = time();
851
+			$last_exec[$id]['last'] = time();
852
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
853
+		$buffer = $Common->getData($value['host']);
854
+		$all_data = json_decode($buffer,true);
855
+		if (isset($all_data['states'])) {
856 856
 		$reset = 0;
857 857
 		foreach ($all_data['states'] as $key => $line) {
858
-		    $data = array();
859
-		    $data['hex'] = $line[0]; // hex
860
-		    $data['ident'] = trim($line[1]); // ident
861
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
862
-		    $data['speed'] = round($line[9]*1.94384); // speed
863
-		    $data['heading'] = round($line[10]); // heading
864
-		    $data['latitude'] = $line[6]; // lat
865
-		    $data['longitude'] = $line[5]; // long
866
-		    $data['verticalrate'] = $line[11]; // verticale rate
867
-		    //$data['squawk'] = $line[10]; // squawk
868
-		    //$data['emergency'] = ''; // emergency
869
-		    //$data['registration'] = $line[2];
870
-		    //$data['aircraft_icao'] = $line[0];
871
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
872
-	    	    $data['format_source'] = 'opensky';
873
-    		    $data['id_source'] = $id_source;
874
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
875
-		    $SI->add($data);
876
-		    unset($data);
858
+			$data = array();
859
+			$data['hex'] = $line[0]; // hex
860
+			$data['ident'] = trim($line[1]); // ident
861
+			$data['altitude'] = round($line[7]*3.28084); // altitude
862
+			$data['speed'] = round($line[9]*1.94384); // speed
863
+			$data['heading'] = round($line[10]); // heading
864
+			$data['latitude'] = $line[6]; // lat
865
+			$data['longitude'] = $line[5]; // long
866
+			$data['verticalrate'] = $line[11]; // verticale rate
867
+			//$data['squawk'] = $line[10]; // squawk
868
+			//$data['emergency'] = ''; // emergency
869
+			//$data['registration'] = $line[2];
870
+			//$data['aircraft_icao'] = $line[0];
871
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
872
+				$data['format_source'] = 'opensky';
873
+				$data['id_source'] = $id_source;
874
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
875
+			$SI->add($data);
876
+			unset($data);
877
+		}
877 878
 		}
878
-	    }
879
-    	    //$last_exec['planeupdatefaa'] = time();
880
-    	    $last_exec[$id]['last'] = time();
881
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
882
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
883
-	    //$buffer = $Common->getData($hosts[$id]);
884
-	    $buffer = $Common->getData($value['host']);
885
-	    $all_data = json_decode($buffer,true);
886
-	    if (!empty($all_data)) $reset = 0;
887
-	    foreach ($all_data as $key => $line) {
879
+			//$last_exec['planeupdatefaa'] = time();
880
+			$last_exec[$id]['last'] = time();
881
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
882
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
883
+		//$buffer = $Common->getData($hosts[$id]);
884
+		$buffer = $Common->getData($value['host']);
885
+		$all_data = json_decode($buffer,true);
886
+		if (!empty($all_data)) $reset = 0;
887
+		foreach ($all_data as $key => $line) {
888 888
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
889
-		    $data = array();
890
-		    $data['hex'] = $line[0];
891
-		    $data['ident'] = $line[16]; //$line[13]
892
-	    	    $data['altitude'] = $line[4]; // altitude
893
-	    	    $data['speed'] = $line[5]; // speed
894
-	    	    $data['heading'] = $line[3]; // heading
895
-	    	    $data['latitude'] = $line[1]; // lat
896
-	    	    $data['longitude'] = $line[2]; // long
897
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
898
-	    	    $data['squawk'] = $line[6]; // squawk
899
-	    	    $data['aircraft_icao'] = $line[8];
900
-	    	    $data['registration'] = $line[9];
901
-		    $data['departure_airport_iata'] = $line[11];
902
-		    $data['arrival_airport_iata'] = $line[12];
903
-	    	    $data['emergency'] = ''; // emergency
904
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
905
-	    	    $data['format_source'] = 'fr24json';
906
-    		    $data['id_source'] = $id_source;
907
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
908
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
909
-		    $SI->add($data);
910
-		    unset($data);
889
+			$data = array();
890
+			$data['hex'] = $line[0];
891
+			$data['ident'] = $line[16]; //$line[13]
892
+				$data['altitude'] = $line[4]; // altitude
893
+				$data['speed'] = $line[5]; // speed
894
+				$data['heading'] = $line[3]; // heading
895
+				$data['latitude'] = $line[1]; // lat
896
+				$data['longitude'] = $line[2]; // long
897
+				$data['verticalrate'] = $line[15]; // verticale rate
898
+				$data['squawk'] = $line[6]; // squawk
899
+				$data['aircraft_icao'] = $line[8];
900
+				$data['registration'] = $line[9];
901
+			$data['departure_airport_iata'] = $line[11];
902
+			$data['arrival_airport_iata'] = $line[12];
903
+				$data['emergency'] = ''; // emergency
904
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
905
+				$data['format_source'] = 'fr24json';
906
+				$data['id_source'] = $id_source;
907
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
908
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
909
+			$SI->add($data);
910
+			unset($data);
911 911
 		}
912
-	    }
913
-    	    //$last_exec['fr24json'] = time();
914
-    	    $last_exec[$id]['last'] = time();
915
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
916
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
917
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
918
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
919
-	    //echo $buffer;
920
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
921
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
922
-	    $all_data = json_decode($buffer,true);
923
-	    if (json_last_error() != JSON_ERROR_NONE) {
912
+		}
913
+			//$last_exec['fr24json'] = time();
914
+			$last_exec[$id]['last'] = time();
915
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
916
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
917
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
918
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
919
+		//echo $buffer;
920
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
921
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
922
+		$all_data = json_decode($buffer,true);
923
+		if (json_last_error() != JSON_ERROR_NONE) {
924 924
 		die(json_last_error_msg());
925
-	    }
926
-	    if (isset($all_data['mrkrs'])) {
925
+		}
926
+		if (isset($all_data['mrkrs'])) {
927 927
 		$reset = 0;
928 928
 		foreach ($all_data['mrkrs'] as $key => $line) {
929
-		    if (isset($line['inf'])) {
929
+			if (isset($line['inf'])) {
930 930
 			$data = array();
931 931
 			$data['hex'] = $line['inf']['ia'];
932 932
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
933
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
934
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
935
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
936
-	    		$data['latitude'] = $line['pt'][0]; // lat
937
-	    		$data['longitude'] = $line['pt'][1]; // long
938
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
939
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
940
-	    		//$data['aircraft_icao'] = $line[8];
941
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
933
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
934
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
935
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
936
+				$data['latitude'] = $line['pt'][0]; // lat
937
+				$data['longitude'] = $line['pt'][1]; // long
938
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
939
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
940
+				//$data['aircraft_icao'] = $line[8];
941
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
942 942
 			//$data['departure_airport_iata'] = $line[11];
943 943
 			//$data['arrival_airport_iata'] = $line[12];
944
-	    		//$data['emergency'] = ''; // emergency
944
+				//$data['emergency'] = ''; // emergency
945 945
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
946
-	    		$data['format_source'] = 'radarvirtueljson';
947
-    			$data['id_source'] = $id_source;
946
+				$data['format_source'] = 'radarvirtueljson';
947
+				$data['id_source'] = $id_source;
948 948
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
949 949
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
950 950
 			$SI->add($data);
951 951
 			unset($data);
952
-		    }
952
+			}
953
+		}
953 954
 		}
954
-	    }
955
-    	    //$last_exec['radarvirtueljson'] = time();
956
-    	    $last_exec[$id]['last'] = time();
957
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
958
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
959
-	    //$buffer = $Common->getData($hosts[$id]);
960
-	    $buffer = $Common->getData($value['host'].'?'.time());
961
-	    $all_data = json_decode(utf8_encode($buffer),true);
955
+			//$last_exec['radarvirtueljson'] = time();
956
+			$last_exec[$id]['last'] = time();
957
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
958
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
959
+		//$buffer = $Common->getData($hosts[$id]);
960
+		$buffer = $Common->getData($value['host'].'?'.time());
961
+		$all_data = json_decode(utf8_encode($buffer),true);
962 962
 	    
963
-	    if (isset($all_data['pireps'])) {
963
+		if (isset($all_data['pireps'])) {
964 964
 		$reset = 0;
965
-	        foreach ($all_data['pireps'] as $line) {
966
-		    $data = array();
967
-		    $data['id'] = $line['id'];
968
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
969
-		    $data['ident'] = $line['callsign']; // ident
970
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
971
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
972
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
973
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
974
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
975
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
976
-		    $data['latitude'] = $line['lat']; // lat
977
-		    $data['longitude'] = $line['lon']; // long
978
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
979
-		    //$data['squawk'] = $line['squawk']; // squawk
980
-		    //$data['emergency'] = ''; // emergency
981
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
982
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
983
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
984
-		    //$data['arrival_airport_time'] = $line['arrtime'];
985
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
986
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
987
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
988
-		    else $data['info'] = '';
989
-		    $data['format_source'] = 'pireps';
990
-    		    $data['id_source'] = $id_source;
991
-		    $data['datetime'] = date('Y-m-d H:i:s');
992
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
993
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
994
-		    if ($line['icon'] == 'plane') {
965
+			foreach ($all_data['pireps'] as $line) {
966
+			$data = array();
967
+			$data['id'] = $line['id'];
968
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
969
+			$data['ident'] = $line['callsign']; // ident
970
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
971
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
972
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
973
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
974
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
975
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
976
+			$data['latitude'] = $line['lat']; // lat
977
+			$data['longitude'] = $line['lon']; // long
978
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
979
+			//$data['squawk'] = $line['squawk']; // squawk
980
+			//$data['emergency'] = ''; // emergency
981
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
982
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
983
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
984
+			//$data['arrival_airport_time'] = $line['arrtime'];
985
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
986
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
987
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
988
+			else $data['info'] = '';
989
+			$data['format_source'] = 'pireps';
990
+				$data['id_source'] = $id_source;
991
+			$data['datetime'] = date('Y-m-d H:i:s');
992
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
993
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
994
+			if ($line['icon'] == 'plane') {
995 995
 			$SI->add($data);
996
-		    //    print_r($data);
997
-    		    } elseif ($line['icon'] == 'ct') {
996
+			//    print_r($data);
997
+				} elseif ($line['icon'] == 'ct') {
998 998
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
999 999
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1000 1000
 			$typec = substr($data['ident'],-3);
@@ -1009,203 +1009,203 @@  discard block
 block discarded – undo
1009 1009
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1010 1010
 			else $data['type'] = 'Observer';
1011 1011
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1012
-		    }
1013
-		    unset($data);
1012
+			}
1013
+			unset($data);
1014
+		}
1014 1015
 		}
1015
-	    }
1016
-    	    //$last_exec['pirepsjson'] = time();
1017
-    	    $last_exec[$id]['last'] = time();
1018
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1019
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1020
-	    //$buffer = $Common->getData($hosts[$id]);
1021
-	    if ($globalDebug) echo 'Get Data...'."\n";
1022
-	    $buffer = $Common->getData($value['host']);
1023
-	    $all_data = json_decode($buffer,true);
1024
-	    if ($buffer != '' && is_array($all_data)) {
1016
+			//$last_exec['pirepsjson'] = time();
1017
+			$last_exec[$id]['last'] = time();
1018
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1019
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1020
+		//$buffer = $Common->getData($hosts[$id]);
1021
+		if ($globalDebug) echo 'Get Data...'."\n";
1022
+		$buffer = $Common->getData($value['host']);
1023
+		$all_data = json_decode($buffer,true);
1024
+		if ($buffer != '' && is_array($all_data)) {
1025 1025
 		$reset = 0;
1026 1026
 		foreach ($all_data as $line) {
1027
-	    	    $data = array();
1028
-	    	    //$data['id'] = $line['id']; // id not usable
1029
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1030
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1031
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1032
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1033
-	    	    $data['ident'] = $line['flightnum']; // ident
1034
-	    	    $data['altitude'] = $line['alt']; // altitude
1035
-	    	    $data['speed'] = $line['gs']; // speed
1036
-	    	    $data['heading'] = $line['heading']; // heading
1037
-	    	    $data['latitude'] = $line['lat']; // lat
1038
-	    	    $data['longitude'] = $line['lng']; // long
1039
-	    	    $data['verticalrate'] = ''; // verticale rate
1040
-	    	    $data['squawk'] = ''; // squawk
1041
-	    	    $data['emergency'] = ''; // emergency
1042
-	    	    //$data['datetime'] = $line['lastupdate'];
1043
-	    	    //$data['last_update'] = $line['lastupdate'];
1044
-	    	    if (isset($value['timezone'])) {
1045
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1046
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1047
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1048
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1049
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1050
-	    	    $data['departure_airport_time'] = $line['deptime'];
1051
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1052
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1053
-    		    $data['registration'] = $line['aircraft'];
1054
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1055
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1056
-		    if (isset($line['aircraftname'])) {
1027
+				$data = array();
1028
+				//$data['id'] = $line['id']; // id not usable
1029
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1030
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1031
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1032
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1033
+				$data['ident'] = $line['flightnum']; // ident
1034
+				$data['altitude'] = $line['alt']; // altitude
1035
+				$data['speed'] = $line['gs']; // speed
1036
+				$data['heading'] = $line['heading']; // heading
1037
+				$data['latitude'] = $line['lat']; // lat
1038
+				$data['longitude'] = $line['lng']; // long
1039
+				$data['verticalrate'] = ''; // verticale rate
1040
+				$data['squawk'] = ''; // squawk
1041
+				$data['emergency'] = ''; // emergency
1042
+				//$data['datetime'] = $line['lastupdate'];
1043
+				//$data['last_update'] = $line['lastupdate'];
1044
+				if (isset($value['timezone'])) {
1045
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1046
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1047
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1048
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1049
+				$data['departure_airport_icao'] = $line['depicao'];
1050
+				$data['departure_airport_time'] = $line['deptime'];
1051
+				$data['arrival_airport_icao'] = $line['arricao'];
1052
+				$data['arrival_airport_time'] = $line['arrtime'];
1053
+				$data['registration'] = $line['aircraft'];
1054
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1055
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1056
+			if (isset($line['aircraftname'])) {
1057 1057
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1058 1058
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1059
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1060
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1061
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1062
-	    		else {
1063
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1064
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1065
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1066
-	    		}
1067
-	    	    }
1068
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1069
-    		    $data['id_source'] = $id_source;
1070
-	    	    $data['format_source'] = 'phpvmacars';
1071
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1072
-		    $SI->add($data);
1073
-		    unset($data);
1059
+				$aircraft_data = explode('-',$line['aircraftname']);
1060
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1061
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1062
+				else {
1063
+					$aircraft_data = explode(' ',$line['aircraftname']);
1064
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1065
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1066
+				}
1067
+				}
1068
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1069
+				$data['id_source'] = $id_source;
1070
+				$data['format_source'] = 'phpvmacars';
1071
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1072
+			$SI->add($data);
1073
+			unset($data);
1074 1074
 		}
1075 1075
 		if ($globalDebug) echo 'No more data...'."\n";
1076 1076
 		unset($buffer);
1077 1077
 		unset($all_data);
1078
-	    }
1079
-    	    //$last_exec['phpvmacars'] = time();
1080
-    	    $last_exec[$id]['last'] = time();
1081
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1082
-	    //$buffer = $Common->getData($hosts[$id]);
1083
-	    if ($globalDebug) echo 'Get Data...'."\n";
1084
-	    $buffer = $Common->getData($value['host']);
1085
-	    $all_data = json_decode($buffer,true);
1086
-	    if ($buffer != '' && is_array($all_data)) {
1078
+		}
1079
+			//$last_exec['phpvmacars'] = time();
1080
+			$last_exec[$id]['last'] = time();
1081
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1082
+		//$buffer = $Common->getData($hosts[$id]);
1083
+		if ($globalDebug) echo 'Get Data...'."\n";
1084
+		$buffer = $Common->getData($value['host']);
1085
+		$all_data = json_decode($buffer,true);
1086
+		if ($buffer != '' && is_array($all_data)) {
1087 1087
 		$reset = 0;
1088 1088
 		foreach ($all_data as $line) {
1089
-	    	    $data = array();
1090
-	    	    //$data['id'] = $line['id']; // id not usable
1091
-	    	    $data['id'] = trim($line['flight_id']);
1092
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1093
-	    	    $data['pilot_name'] = $line['pilot_name'];
1094
-	    	    $data['pilot_id'] = $line['pilot_id'];
1095
-	    	    $data['ident'] = trim($line['callsign']); // ident
1096
-	    	    $data['altitude'] = $line['altitude']; // altitude
1097
-	    	    $data['speed'] = $line['gs']; // speed
1098
-	    	    $data['heading'] = $line['heading']; // heading
1099
-	    	    $data['latitude'] = $line['latitude']; // lat
1100
-	    	    $data['longitude'] = $line['longitude']; // long
1101
-	    	    $data['verticalrate'] = ''; // verticale rate
1102
-	    	    $data['squawk'] = ''; // squawk
1103
-	    	    $data['emergency'] = ''; // emergency
1104
-	    	    //$data['datetime'] = $line['lastupdate'];
1105
-	    	    $data['last_update'] = $line['last_update'];
1106
-		    $data['datetime'] = date('Y-m-d H:i:s');
1107
-	    	    $data['departure_airport_icao'] = $line['departure'];
1108
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1109
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1110
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1111
-    		    //$data['registration'] = $line['aircraft'];
1112
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1113
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1114
-    		    $data['id_source'] = $id_source;
1115
-	    	    $data['format_source'] = 'vam';
1116
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1117
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1118
-		    $SI->add($data);
1119
-		    unset($data);
1089
+				$data = array();
1090
+				//$data['id'] = $line['id']; // id not usable
1091
+				$data['id'] = trim($line['flight_id']);
1092
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1093
+				$data['pilot_name'] = $line['pilot_name'];
1094
+				$data['pilot_id'] = $line['pilot_id'];
1095
+				$data['ident'] = trim($line['callsign']); // ident
1096
+				$data['altitude'] = $line['altitude']; // altitude
1097
+				$data['speed'] = $line['gs']; // speed
1098
+				$data['heading'] = $line['heading']; // heading
1099
+				$data['latitude'] = $line['latitude']; // lat
1100
+				$data['longitude'] = $line['longitude']; // long
1101
+				$data['verticalrate'] = ''; // verticale rate
1102
+				$data['squawk'] = ''; // squawk
1103
+				$data['emergency'] = ''; // emergency
1104
+				//$data['datetime'] = $line['lastupdate'];
1105
+				$data['last_update'] = $line['last_update'];
1106
+			$data['datetime'] = date('Y-m-d H:i:s');
1107
+				$data['departure_airport_icao'] = $line['departure'];
1108
+				//$data['departure_airport_time'] = $line['departure_time'];
1109
+				$data['arrival_airport_icao'] = $line['arrival'];
1110
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1111
+				//$data['registration'] = $line['aircraft'];
1112
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1113
+				$data['aircraft_icao'] = $line['plane_type'];
1114
+				$data['id_source'] = $id_source;
1115
+				$data['format_source'] = 'vam';
1116
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1117
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1118
+			$SI->add($data);
1119
+			unset($data);
1120 1120
 		}
1121 1121
 		if ($globalDebug) echo 'No more data...'."\n";
1122 1122
 		unset($buffer);
1123 1123
 		unset($all_data);
1124
-	    }
1125
-    	    //$last_exec['phpvmacars'] = time();
1126
-    	    $last_exec[$id]['last'] = time();
1124
+		}
1125
+			//$last_exec['phpvmacars'] = time();
1126
+			$last_exec[$id]['last'] = time();
1127 1127
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1128 1128
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1129
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1130
-    	    //$last_exec[$id]['last'] = time();
1129
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1130
+			//$last_exec[$id]['last'] = time();
1131 1131
 
1132
-	    //$read = array( $sockets[$id] );
1133
-	    $read = $sockets;
1134
-	    $write = NULL;
1135
-	    $e = NULL;
1136
-	    $n = socket_select($read, $write, $e, $timeout);
1137
-	    if ($e != NULL) var_dump($e);
1138
-	    if ($n > 0) {
1132
+		//$read = array( $sockets[$id] );
1133
+		$read = $sockets;
1134
+		$write = NULL;
1135
+		$e = NULL;
1136
+		$n = socket_select($read, $write, $e, $timeout);
1137
+		if ($e != NULL) var_dump($e);
1138
+		if ($n > 0) {
1139 1139
 		$reset = 0;
1140 1140
 		foreach ($read as $nb => $r) {
1141
-		    //$value = $formats[$nb];
1142
-		    $format = $globalSources[$nb]['format'];
1143
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1141
+			//$value = $formats[$nb];
1142
+			$format = $globalSources[$nb]['format'];
1143
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1144 1144
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1145
-		    } elseif ($format == 'vrstcp') {
1145
+			} elseif ($format == 'vrstcp') {
1146 1146
 			$buffer = @socket_read($r, 6000);
1147
-		    } else {
1147
+			} else {
1148 1148
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1149
-		    }
1150
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1151
-		    //echo $buffer."\n";
1152
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1153
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1154
-		    $error = false;
1155
-		    //$SI::del();
1156
-		    if ($format == 'vrstcp') {
1149
+			}
1150
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1151
+			//echo $buffer."\n";
1152
+			// lets play nice and handle signals such as ctrl-c/kill properly
1153
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1154
+			$error = false;
1155
+			//$SI::del();
1156
+			if ($format == 'vrstcp') {
1157 1157
 			$buffer = explode('},{',$buffer);
1158
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1159
-		    // SBS format is CSV format
1160
-		    if ($buffer !== FALSE && $buffer != '') {
1158
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1159
+			// SBS format is CSV format
1160
+			if ($buffer !== FALSE && $buffer != '') {
1161 1161
 			$tt[$format] = 0;
1162 1162
 			if ($format == 'acarssbs3') {
1163
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1164
-			    $ACARS->add(trim($buffer));
1165
-			    $ACARS->deleteLiveAcarsData();
1163
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1164
+				$ACARS->add(trim($buffer));
1165
+				$ACARS->deleteLiveAcarsData();
1166 1166
 			} elseif ($format == 'raw') {
1167
-			    // AVR format
1168
-			    $data = $SBS->parse($buffer);
1169
-			    if (is_array($data)) {
1167
+				// AVR format
1168
+				$data = $SBS->parse($buffer);
1169
+				if (is_array($data)) {
1170 1170
 				$data['datetime'] = date('Y-m-d H:i:s');
1171 1171
 				$data['format_source'] = 'raw';
1172 1172
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1173 1173
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1174 1174
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1175 1175
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1176
-			    }
1176
+				}
1177 1177
 			} elseif ($format == 'ais') {
1178
-			    $ais_data = $AIS->parse_line(trim($buffer));
1179
-			    $data = array();
1180
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1181
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1182
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1183
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1184
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1185
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1186
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1187
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1188
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1189
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1190
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1191
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1192
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1193
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1194
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1195
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1178
+				$ais_data = $AIS->parse_line(trim($buffer));
1179
+				$data = array();
1180
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1181
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1182
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1183
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1184
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1185
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1186
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1187
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1188
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1189
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1190
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1191
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1192
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1193
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1194
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1195
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1196 1196
 
1197
-			    if (isset($ais_data['timestamp'])) {
1197
+				if (isset($ais_data['timestamp'])) {
1198 1198
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1199
-			    } else {
1199
+				} else {
1200 1200
 				$data['datetime'] = date('Y-m-d H:i:s');
1201
-			    }
1202
-			    $data['format_source'] = 'aisnmea';
1203
-    			    $data['id_source'] = $id_source;
1204
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1205
-			    unset($data);
1206
-                        } elseif ($format == 'flightgearsp') {
1207
-                    	    //echo $buffer."\n";
1208
-                    	    if (strlen($buffer) > 5) {
1201
+				}
1202
+				$data['format_source'] = 'aisnmea';
1203
+					$data['id_source'] = $id_source;
1204
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1205
+				unset($data);
1206
+						} elseif ($format == 'flightgearsp') {
1207
+							//echo $buffer."\n";
1208
+							if (strlen($buffer) > 5) {
1209 1209
 				$line = explode(',',$buffer);
1210 1210
 				$data = array();
1211 1211
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1222,38 +1222,38 @@  discard block
 block discarded – undo
1222 1222
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1223 1223
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1224 1224
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1225
-			    }
1226
-                        } elseif ($format == 'acars') {
1227
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1228
-			    $ACARS->add(trim($buffer));
1229
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1230
-			    $ACARS->deleteLiveAcarsData();
1225
+				}
1226
+						} elseif ($format == 'acars') {
1227
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1228
+				$ACARS->add(trim($buffer));
1229
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1230
+				$ACARS->deleteLiveAcarsData();
1231 1231
 			} elseif ($format == 'flightgearmp') {
1232
-			    if (substr($buffer,0,1) != '#') {
1232
+				if (substr($buffer,0,1) != '#') {
1233 1233
 				$data = array();
1234 1234
 				//echo $buffer."\n";
1235 1235
 				$line = explode(' ',$buffer);
1236 1236
 				if (count($line) == 11) {
1237
-				    $userserver = explode('@',$line[0]);
1238
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1239
-				    $data['ident'] = $userserver[0];
1240
-				    $data['registration'] = $userserver[0];
1241
-				    $data['latitude'] = $line[4];
1242
-				    $data['longitude'] = $line[5];
1243
-				    $data['altitude'] = $line[6];
1244
-				    $data['datetime'] = date('Y-m-d H:i:s');
1245
-				    $aircraft_type = $line[10];
1246
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1247
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1248
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1249
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1237
+					$userserver = explode('@',$line[0]);
1238
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1239
+					$data['ident'] = $userserver[0];
1240
+					$data['registration'] = $userserver[0];
1241
+					$data['latitude'] = $line[4];
1242
+					$data['longitude'] = $line[5];
1243
+					$data['altitude'] = $line[6];
1244
+					$data['datetime'] = date('Y-m-d H:i:s');
1245
+					$aircraft_type = $line[10];
1246
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1247
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1248
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1249
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1250
+				}
1250 1251
 				}
1251
-			    }
1252 1252
 			} elseif ($format == 'beast') {
1253
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1254
-			    die;
1253
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1254
+				die;
1255 1255
 			} elseif ($format == 'vrstcp') {
1256
-			    foreach($buffer as $all_data) {
1256
+				foreach($buffer as $all_data) {
1257 1257
 				$line = json_decode('{'.$all_data.'}',true);
1258 1258
 				$data = array();
1259 1259
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1273,116 +1273,116 @@  discard block
 block discarded – undo
1273 1273
 				*/
1274 1274
 				$data['datetime'] = date('Y-m-d H:i:s');
1275 1275
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1276
-		    		$data['format_source'] = 'vrstcp';
1276
+					$data['format_source'] = 'vrstcp';
1277 1277
 				$data['id_source'] = $id_source;
1278 1278
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1279 1279
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1280 1280
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1281 1281
 				unset($data);
1282
-			    }
1282
+				}
1283 1283
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1284
-			    $line = explode("\t", $buffer);
1285
-			    for($k = 0; $k < count($line); $k=$k+2) {
1284
+				$line = explode("\t", $buffer);
1285
+				for($k = 0; $k < count($line); $k=$k+2) {
1286 1286
 				$key = $line[$k];
1287
-			        $lined[$key] = $line[$k+1];
1288
-			    }
1289
-    			    if (count($lined) > 3) {
1290
-    				$data['hex'] = $lined['hexid'];
1291
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1292
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1293
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1294
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1295
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1296
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1297
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1298
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1299
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1300
-    				$data['id_source'] = $id_source;
1301
-    				$data['format_source'] = 'tsv';
1302
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1303
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1287
+					$lined[$key] = $line[$k+1];
1288
+				}
1289
+					if (count($lined) > 3) {
1290
+					$data['hex'] = $lined['hexid'];
1291
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1292
+					$data['datetime'] = date('Y-m-d H:i:s');;
1293
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1294
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1295
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1296
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1297
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1298
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1299
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1300
+					$data['id_source'] = $id_source;
1301
+					$data['format_source'] = 'tsv';
1302
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1303
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1304 1304
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1305
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1306
-    				unset($lined);
1307
-    				unset($data);
1308
-    			    } else $error = true;
1305
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1306
+					unset($lined);
1307
+					unset($data);
1308
+					} else $error = true;
1309 1309
 			} elseif ($format == 'aprs' && $use_aprs) {
1310
-			    if ($aprs_connect == 0) {
1310
+				if ($aprs_connect == 0) {
1311 1311
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1312 1312
 				$aprs_connect = 1;
1313
-			    }
1313
+				}
1314 1314
 			    
1315
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1315
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1316 1316
 				$aprs_last_tx = time();
1317 1317
 				$data_aprs = "# Keep alive";
1318 1318
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1319
-			    }
1319
+				}
1320 1320
 			    
1321
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1322
-			    //echo 'APRS data : '.$buffer."\n";
1323
-			    $buffer = str_replace('APRS <- ','',$buffer);
1324
-			    $buffer = str_replace('APRS -> ','',$buffer);
1325
-			    //echo $buffer."\n";
1326
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1321
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1322
+				//echo 'APRS data : '.$buffer."\n";
1323
+				$buffer = str_replace('APRS <- ','',$buffer);
1324
+				$buffer = str_replace('APRS -> ','',$buffer);
1325
+				//echo $buffer."\n";
1326
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1327 1327
 				$line = $APRS->parse($buffer);
1328 1328
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1329 1329
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1330
-				    $aprs_last_tx = time();
1331
-				    $data = array();
1332
-				    //print_r($line);
1333
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1334
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1335
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1336
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1337
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1338
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1339
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1340
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1341
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1342
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1343
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1344
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1345
-				    $data['latitude'] = $line['latitude'];
1346
-				    $data['longitude'] = $line['longitude'];
1347
-				    //$data['verticalrate'] = $line[16];
1348
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1349
-				    //else $data['speed'] = 0;
1350
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1351
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1352
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1353
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1354
-				    //else $data['heading'] = 0;
1355
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1356
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1357
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1358
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1359
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1360
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1361
-    				    $data['id_source'] = $id_source;
1362
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1363
-				    else $data['format_source'] = 'aprs';
1364
-				    $data['source_name'] = $line['source'];
1365
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1366
-				    else $data['source_type'] = 'flarm';
1367
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1368
-				    $currentdate = date('Y-m-d H:i:s');
1369
-				    $aprsdate = strtotime($data['datetime']);
1370
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1371
-				    // Accept data if time <= system time + 20s
1372
-				    //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1373
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1330
+					$aprs_last_tx = time();
1331
+					$data = array();
1332
+					//print_r($line);
1333
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1334
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1335
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1336
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1337
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1338
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1339
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1340
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1341
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1342
+					else $data['datetime'] = date('Y-m-d H:i:s');
1343
+					//$data['datetime'] = date('Y-m-d H:i:s');
1344
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1345
+					$data['latitude'] = $line['latitude'];
1346
+					$data['longitude'] = $line['longitude'];
1347
+					//$data['verticalrate'] = $line[16];
1348
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1349
+					//else $data['speed'] = 0;
1350
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1351
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1352
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1353
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1354
+					//else $data['heading'] = 0;
1355
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1356
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1357
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1358
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1359
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1360
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1361
+						$data['id_source'] = $id_source;
1362
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1363
+					else $data['format_source'] = 'aprs';
1364
+					$data['source_name'] = $line['source'];
1365
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1366
+					else $data['source_type'] = 'flarm';
1367
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1368
+					$currentdate = date('Y-m-d H:i:s');
1369
+					$aprsdate = strtotime($data['datetime']);
1370
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1371
+					// Accept data if time <= system time + 20s
1372
+					//if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1373
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1374 1374
 					$send = $SI->add($data);
1375
-				    } elseif ($data['source_type'] == 'ais') {
1375
+					} elseif ($data['source_type'] == 'ais') {
1376 1376
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1377
-				    } elseif (isset($line['stealth'])) {
1377
+					} elseif (isset($line['stealth'])) {
1378 1378
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1379 1379
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1380
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1381
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1382
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1380
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1381
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1382
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1383 1383
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1384 1384
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1385
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1385
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1386 1386
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1387 1387
 					$Source->deleteOldLocationByType('gs');
1388 1388
 					if (count($Source->getLocationInfoByName($data['ident'])) > 0) {
@@ -1390,11 +1390,11 @@  discard block
 block discarded – undo
1390 1390
 					} else {
1391 1391
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1392 1392
 					}
1393
-				    } else {
1394
-				    	echo '/!\ Not added: '.$buffer."\n";
1395
-				    	print_r($line);
1396
-				    }
1397
-				    unset($data);
1393
+					} else {
1394
+						echo '/!\ Not added: '.$buffer."\n";
1395
+						print_r($line);
1396
+					}
1397
+					unset($data);
1398 1398
 				} 
1399 1399
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1400 1400
 					echo '!! Weather Station not yet supported'."\n";
@@ -1410,12 +1410,12 @@  discard block
 block discarded – undo
1410 1410
 				*/
1411 1411
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1412 1412
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1413
-			    }
1413
+				}
1414 1414
 			} else {
1415
-			    $line = explode(',', $buffer);
1416
-    			    if (count($line) > 20) {
1417
-    			    	$data['hex'] = $line[4];
1418
-    				/*
1415
+				$line = explode(',', $buffer);
1416
+					if (count($line) > 20) {
1417
+						$data['hex'] = $line[4];
1418
+					/*
1419 1419
     				$data['datetime'] = $line[6].' '.$line[7];
1420 1420
     					date_default_timezone_set($globalTimezone);
1421 1421
     					$datetime = new DateTime($data['datetime']);
@@ -1423,30 +1423,30 @@  discard block
 block discarded – undo
1423 1423
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1424 1424
     					date_default_timezone_set('UTC');
1425 1425
     				*/
1426
-    				// Force datetime to current UTC datetime
1427
-    				date_default_timezone_set('UTC');
1428
-    				$data['datetime'] = date('Y-m-d H:i:s');
1429
-    				$data['ident'] = trim($line[10]);
1430
-    				$data['latitude'] = $line[14];
1431
-    				$data['longitude'] = $line[15];
1432
-    				$data['verticalrate'] = $line[16];
1433
-    				$data['emergency'] = $line[20];
1434
-    				$data['speed'] = $line[12];
1435
-    				$data['squawk'] = $line[17];
1436
-    				$data['altitude'] = $line[11];
1437
-    				$data['heading'] = $line[13];
1438
-    				$data['ground'] = $line[21];
1439
-    				$data['emergency'] = $line[19];
1440
-    				$data['format_source'] = 'sbs';
1426
+					// Force datetime to current UTC datetime
1427
+					date_default_timezone_set('UTC');
1428
+					$data['datetime'] = date('Y-m-d H:i:s');
1429
+					$data['ident'] = trim($line[10]);
1430
+					$data['latitude'] = $line[14];
1431
+					$data['longitude'] = $line[15];
1432
+					$data['verticalrate'] = $line[16];
1433
+					$data['emergency'] = $line[20];
1434
+					$data['speed'] = $line[12];
1435
+					$data['squawk'] = $line[17];
1436
+					$data['altitude'] = $line[11];
1437
+					$data['heading'] = $line[13];
1438
+					$data['ground'] = $line[21];
1439
+					$data['emergency'] = $line[19];
1440
+					$data['format_source'] = 'sbs';
1441 1441
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1442
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1442
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1443 1443
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444
-    				$data['id_source'] = $id_source;
1445
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1446
-    				else $error = true;
1447
-    				unset($data);
1448
-    			    } else $error = true;
1449
-			    if ($error) {
1444
+					$data['id_source'] = $id_source;
1445
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1446
+					else $error = true;
1447
+					unset($data);
1448
+					} else $error = true;
1449
+				if ($error) {
1450 1450
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1451 1451
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1452 1452
 				} else {
@@ -1462,13 +1462,13 @@  discard block
 block discarded – undo
1462 1462
 					connect_all($sourceer);
1463 1463
 					$sourceer = array();
1464 1464
 				}
1465
-			    }
1465
+				}
1466 1466
 			}
1467 1467
 			// Sleep for xxx microseconds
1468 1468
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1469
-		    } else {
1469
+			} else {
1470 1470
 			if ($format == 'flightgearmp') {
1471
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1471
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1472 1472
 				//@socket_close($r);
1473 1473
 				sleep($globalMinFetch);
1474 1474
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1477,9 +1477,9 @@  discard block
 block discarded – undo
1477 1477
 				break;
1478 1478
 				
1479 1479
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1480
-			    if (isset($tt[$format])) $tt[$format]++;
1481
-			    else $tt[$format] = 0;
1482
-			    if ($tt[$format] > 30) {
1480
+				if (isset($tt[$format])) $tt[$format]++;
1481
+				else $tt[$format] = 0;
1482
+				if ($tt[$format] > 30) {
1483 1483
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1484 1484
 				//@socket_close($r);
1485 1485
 				sleep(2);
@@ -1490,23 +1490,23 @@  discard block
 block discarded – undo
1490 1490
 				//connect_all($globalSources);
1491 1491
 				$tt[$format]=0;
1492 1492
 				break;
1493
-			    }
1493
+				}
1494
+			}
1494 1495
 			}
1495
-		    }
1496 1496
 		}
1497
-	    } else {
1497
+		} else {
1498 1498
 		$error = socket_strerror(socket_last_error());
1499 1499
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1500 1500
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1501 1501
 			if (isset($globalDebug)) echo "Restarting...\n";
1502 1502
 			// Restart the script if possible
1503 1503
 			if (is_array($sockets)) {
1504
-			    if ($globalDebug) echo "Shutdown all sockets...";
1504
+				if ($globalDebug) echo "Shutdown all sockets...";
1505 1505
 			    
1506
-			    foreach ($sockets as $sock) {
1506
+				foreach ($sockets as $sock) {
1507 1507
 				@socket_shutdown($sock,2);
1508 1508
 				@socket_close($sock);
1509
-			    }
1509
+				}
1510 1510
 			    
1511 1511
 			}
1512 1512
 			if ($globalDebug) echo "Waiting...";
@@ -1521,13 +1521,13 @@  discard block
 block discarded – undo
1521 1521
 			if ($globalDebug) echo "Restart all connections...";
1522 1522
 			connect_all($globalSources);
1523 1523
 		}
1524
-	    }
1524
+		}
1525 1525
 	}
1526 1526
 	if ($globalDaemon === false) {
1527
-	    if ($globalDebug) echo 'Check all...'."\n";
1528
-	    $SI->checkAll();
1527
+		if ($globalDebug) echo 'Check all...'."\n";
1528
+		$SI->checkAll();
1529
+	}
1529 1530
 	}
1530
-    }
1531 1531
 }
1532 1532
 
1533 1533
 ?>
Please login to merge, or discard this patch.
install/index.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
 				</tr>
318 318
 				<!--
319 319
 		<?php
320
-		    require_once(dirname(__FILE__).'/../require/class.Connection.php');
321
-		    $Connection = new Connection();
320
+			require_once(dirname(__FILE__).'/../require/class.Connection.php');
321
+			$Connection = new Connection();
322 322
 		?>
323 323
 				-->
324 324
 		<?php
325
-		    if ($Connection->db != NULL) {
325
+			if ($Connection->db != NULL) {
326 326
 			if ($Connection->tableExists('source_location')) {
327
-			    require_once(dirname(__FILE__).'/../require/class.Source.php');
328
-			    $Source = new Source();
329
-			    //$alllocations = $Source->getAllLocationInfo();
330
-			    $alllocations = $Source->getLocationInfobyType('');
331
-			    foreach ($alllocations as $location) {
327
+				require_once(dirname(__FILE__).'/../require/class.Source.php');
328
+				$Source = new Source();
329
+				//$alllocations = $Source->getAllLocationInfo();
330
+				$alllocations = $Source->getLocationInfobyType('');
331
+				foreach ($alllocations as $location) {
332 332
 		?>
333 333
 				<tr>
334 334
 	    				<input type="hidden" name="source_id[]" value="<?php print $location['id']; ?>" />
@@ -342,9 +342,9 @@  discard block
 block discarded – undo
342 342
 				</tr>
343 343
 		
344 344
 		<?php
345
-			    }
345
+				}
346
+			}
346 347
 			}
347
-		    }
348 348
 		?>
349 349
 
350 350
 				<tr>
@@ -452,12 +452,12 @@  discard block
 block discarded – undo
452 452
 ?>
453 453
 							<tr>
454 454
 								<?php
455
-								    if (filter_var($source['host'],FILTER_VALIDATE_URL)) {
455
+									if (filter_var($source['host'],FILTER_VALIDATE_URL)) {
456 456
 								?>
457 457
 								<td><input type="text" name="host[]" id="host" value="<?php print $source['host']; ?>" /></td>
458 458
 								<td><input type="number" name="port[]" class="col-xs-2" id="port" value="<?php if (isset($source['port'])) print $source['port']; ?>" /></td>
459 459
 								<?php
460
-								    } else {
460
+									} else {
461 461
 									$hostport = explode(':',$source['host']);
462 462
 									if (isset($hostport[1])) {
463 463
 										$host = $hostport[0];
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 								<td><input type="text" name="host[]" id="host" value="<?php print $host; ?>" /></td>
471 471
 								<td><input type="number" name="port[]" id="port" class="col-xs-2" value="<?php print $port; ?>" /></td>
472 472
 								<?php
473
-								    }
473
+									}
474 474
 								?>
475 475
 								<td>
476 476
 									<select name="format[]" id="format">
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 			<br />
877 877
 			<p>
878 878
 			<?php 
879
-			    if (extension_loaded('gd') && function_exists('gd_info')) {
879
+				if (extension_loaded('gd') && function_exists('gd_info')) {
880 880
 			?>
881 881
 				<label for="aircrafticoncolor">Color of aircraft icon on map</label>
882 882
 				<input type="color" name="aircrafticoncolor" id="aircrafticoncolor" value="#<?php if (isset($globalAircraftIconColor)) echo $globalAircraftIconColor; else echo '1a3151'; ?>" />
@@ -886,11 +886,11 @@  discard block
 block discarded – undo
886 886
 				<b>The directory cache is not writable, aircraft icon will not be cached</b>
887 887
 			<?php
888 888
 				}
889
-			    } else {
889
+				} else {
890 890
 			?>
891 891
 				<b>PHP GD is not installed, you can't change color of aircraft icon on map</b>
892 892
 			<?php
893
-			    }
893
+				}
894 894
 			?>
895 895
 			</p>
896 896
 			<br />
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
 	</p>
915 915
 <?php
916 916
 	require('../footer.php');
917
-        exit;
917
+		exit;
918 918
 }
919 919
 	
920 920
 $settings = array();
@@ -1005,8 +1005,8 @@  discard block
 block discarded – undo
1005 1005
 	
1006 1006
 	$sources = array();
1007 1007
 	foreach ($source_name as $keys => $name) {
1008
-	    if (isset($source_id[$keys])) $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'id' => $source_id[$keys],'source' => $source_ref[$keys]);
1009
-	    else $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'source' => $source_ref[$keys]);
1008
+		if (isset($source_id[$keys])) $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'id' => $source_id[$keys],'source' => $source_ref[$keys]);
1009
+		else $sources[] = array('name' => $name,'latitude' => $source_latitude[$keys],'longitude' => $source_longitude[$keys],'altitude' => $source_altitude[$keys],'city' => $source_city[$keys],'country' => $source_country[$keys],'source' => $source_ref[$keys]);
1010 1010
 	}
1011 1011
 	if (count($sources) > 0) $_SESSION['sources'] = $sources;
1012 1012
 
@@ -1384,14 +1384,14 @@  discard block
 block discarded – undo
1384 1384
 
1385 1385
 	// Set some defaults values...
1386 1386
 	if (!isset($globalAircraftImageSources)) {
1387
-	    $globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
1388
-	    $settings = array_merge($settings,array('globalAircraftImageSources' => $globalAircraftImageSources));
1387
+		$globalAircraftImageSources = array('ivaomtl','wikimedia','airportdata','deviantart','flickr','bing','jetphotos','planepictures','planespotters');
1388
+		$settings = array_merge($settings,array('globalAircraftImageSources' => $globalAircraftImageSources));
1389 1389
 	}
1390 1390
 
1391 1391
 	if (!isset($globalSchedulesSources)) {
1392
-	    $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1393
-    	    $settings = array_merge($settings,array('globalSchedulesSources' => $globalSchedulesSources));
1394
-    	}
1392
+		$globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1393
+			$settings = array_merge($settings,array('globalSchedulesSources' => $globalSchedulesSources));
1394
+		}
1395 1395
 
1396 1396
 	$settings = array_merge($settings,array('globalInstalled' => 'TRUE'));
1397 1397
 
@@ -1443,21 +1443,21 @@  discard block
 block discarded – undo
1443 1443
 	$popi = false;
1444 1444
 	$popw = false;
1445 1445
 	foreach ($_SESSION['done'] as $done) {
1446
-	    print '<li>'.$done.'....<strong>SUCCESS</strong></li>';
1447
-	    if ($done == 'Create database') $pop = true;
1448
-	    if ($_SESSION['install'] == 'database_create') $pop = true;
1449
-	    if ($_SESSION['install'] == 'database_import') $popi = true;
1450
-	    if ($_SESSION['install'] == 'waypoints') $popw = true;
1446
+		print '<li>'.$done.'....<strong>SUCCESS</strong></li>';
1447
+		if ($done == 'Create database') $pop = true;
1448
+		if ($_SESSION['install'] == 'database_create') $pop = true;
1449
+		if ($_SESSION['install'] == 'database_import') $popi = true;
1450
+		if ($_SESSION['install'] == 'waypoints') $popw = true;
1451 1451
 	}
1452 1452
 	if ($pop) {
1453
-	    sleep(5);
1454
-	    print '<li>Create database....<img src="../images/loading.gif" /></li>';
1453
+		sleep(5);
1454
+		print '<li>Create database....<img src="../images/loading.gif" /></li>';
1455 1455
 	} else if ($popi) {
1456
-	    sleep(5);
1457
-	    print '<li>Create and import tables....<img src="../images/loading.gif" /></li>';
1456
+		sleep(5);
1457
+		print '<li>Create and import tables....<img src="../images/loading.gif" /></li>';
1458 1458
 	} else if ($popw) {
1459
-	    sleep(5);
1460
-	    print '<li>Populate waypoints database....<img src="../images/loading.gif" /></li>';
1459
+		sleep(5);
1460
+		print '<li>Populate waypoints database....<img src="../images/loading.gif" /></li>';
1461 1461
 	} else print '<li>Update schema if needed....<img src="../images/loading.gif" /></li>';
1462 1462
 	print '</div></ul>';
1463 1463
 	print '<div id="error"></div>';
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
 	unset($_COOKIE['install']);
1521 1521
 	print '<div class="info column"><ul>';
1522 1522
 	foreach ($_SESSION['done'] as $done) {
1523
-	    print '<li>'.$done.'....<strong>SUCCESS</strong></li>';
1523
+		print '<li>'.$done.'....<strong>SUCCESS</strong></li>';
1524 1524
 	}
1525 1525
 	print '<li>Reloading page to check all is now ok....<strong>SUCCESS</strong></li>';
1526 1526
 	print '</ul></div>';
Please login to merge, or discard this patch.
require/class.TrackerImport.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 require_once(dirname(__FILE__).'/class.Source.php');
8 8
 
9 9
 class TrackerImport {
10
-    private $all_tracked = array();
11
-    private $last_delete_hourly = 0;
12
-    private $last_delete = 0;
13
-    private $stats = array();
14
-    private $tmd = 0;
15
-    private $source_location = array();
16
-    public $db = null;
17
-    public $nb = 0;
10
+	private $all_tracked = array();
11
+	private $last_delete_hourly = 0;
12
+	private $last_delete = 0;
13
+	private $stats = array();
14
+	private $tmd = 0;
15
+	private $source_location = array();
16
+	public $db = null;
17
+	public $nb = 0;
18 18
 
19
-    public function __construct($dbc = null) {
19
+	public function __construct($dbc = null) {
20 20
 	global $globalBeta;
21 21
 	$Connection = new Connection($dbc);
22 22
 	$this->db = $Connection->db();
@@ -38,50 +38,50 @@  discard block
 block discarded – undo
38 38
 	    }
39 39
 	}
40 40
 	*/
41
-    }
41
+	}
42 42
 
43
-    public function checkAll() {
43
+	public function checkAll() {
44 44
 	global $globalDebug;
45 45
 	if ($globalDebug) echo "Update last seen tracked data...\n";
46 46
 	foreach ($this->all_tracked as $key => $flight) {
47
-	    if (isset($this->all_tracked[$key]['id'])) {
47
+		if (isset($this->all_tracked[$key]['id'])) {
48 48
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
49
-    		$Tracker = new Tracker($this->db);
50
-        	$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
51
-            }
49
+			$Tracker = new Tracker($this->db);
50
+			$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
51
+			}
52
+	}
52 53
 	}
53
-    }
54 54
 
55
-    public function del() {
55
+	public function del() {
56 56
 	global $globalDebug;
57 57
 	// Delete old infos
58 58
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
59 59
 	foreach ($this->all_tracked as $key => $flight) {
60
-    	    if (isset($flight['lastupdate'])) {
61
-        	if ($flight['lastupdate'] < (time()-3000)) {
62
-            	    if (isset($this->all_tracked[$key]['id'])) {
63
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
60
+			if (isset($flight['lastupdate'])) {
61
+			if ($flight['lastupdate'] < (time()-3000)) {
62
+					if (isset($this->all_tracked[$key]['id'])) {
63
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
64 64
 			/*
65 65
 			$TrackerLive = new TrackerLive();
66 66
             		$TrackerLive->deleteLiveTrackerDataById($this->all_tracked[$key]['id']);
67 67
 			$TrackerLive->db = null;
68 68
 			*/
69
-            		//$real_arrival = $this->arrival($key);
70
-            		$Tracker = new Tracker($this->db);
71
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
69
+					//$real_arrival = $this->arrival($key);
70
+					$Tracker = new Tracker($this->db);
71
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
72 72
 				$result = $Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed']);
73 73
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
74 74
 			}
75 75
 			// Put in archive
76 76
 //			$Tracker->db = null;
77
-            	    }
78
-            	    unset($this->all_tracked[$key]);
79
-    	        }
80
-	    }
81
-        }
82
-    }
77
+					}
78
+					unset($this->all_tracked[$key]);
79
+				}
80
+		}
81
+		}
82
+	}
83 83
 
84
-    public function add($line) {
84
+	public function add($line) {
85 85
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
86 86
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
87 87
 	date_default_timezone_set('UTC');
@@ -90,47 +90,47 @@  discard block
 block discarded – undo
90 90
 	
91 91
 	// SBS format is CSV format
92 92
 	if(is_array($line) && isset($line['ident'])) {
93
-	    //print_r($line);
94
-  	    if (isset($line['ident'])) {
93
+		//print_r($line);
94
+  		if (isset($line['ident'])) {
95 95
 
96 96
 		
97 97
 		// Increment message number
98 98
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
99
-		    $current_date = date('Y-m-d');
100
-		    if (isset($line['source_name'])) $source = $line['source_name'];
101
-		    else $source = '';
102
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
103
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
104
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
105
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
106
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
99
+			$current_date = date('Y-m-d');
100
+			if (isset($line['source_name'])) $source = $line['source_name'];
101
+			else $source = '';
102
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
103
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
104
+				$this->stats[$current_date][$source]['msg']['date'] = time();
105
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
106
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
107 107
 		}
108 108
 		
109 109
 		
110 110
 		$Common = new Common();
111
-	        if (!isset($line['id'])) $id = trim($line['ident']);
112
-	        else $id = trim($line['id']);
111
+			if (!isset($line['id'])) $id = trim($line['ident']);
112
+			else $id = trim($line['id']);
113 113
 		
114 114
 		if (!isset($this->all_tracked[$id])) {
115
-		    $this->all_tracked[$id] = array();
116
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
-		    if (!isset($line['id'])) {
115
+			$this->all_tracked[$id] = array();
116
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
117
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
118
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
+			if (!isset($line['id'])) {
120 120
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
121 121
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
122
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
123
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
122
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
123
+			if ($globalAllTracked !== FALSE) $dataFound = true;
124 124
 		}
125 125
 		
126 126
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
127
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
127
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
128 128
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
129
-		    } else {
129
+			} else {
130 130
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n";
131 131
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n";
132 132
 				return '';
133
-		    }
133
+			}
134 134
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
135 135
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n";
136 136
 			return '';
@@ -147,38 +147,38 @@  discard block
 block discarded – undo
147 147
 		
148 148
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
149 149
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
150
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
151
-		    if ($this->all_tracked[$id]['addedTracker'] == 1) {
150
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
151
+			if ($this->all_tracked[$id]['addedTracker'] == 1) {
152 152
 			$timeelapsed = microtime(true);
153
-            		$Tracker = new Tracker($this->db);
154
-            		$fromsource = NULL;
155
-            		$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
153
+					$Tracker = new Tracker($this->db);
154
+					$fromsource = NULL;
155
+					$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
156 156
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
157 157
 			$Tracker->db = null;
158 158
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
159
-		    }
160
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
159
+			}
160
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
161 161
 		}
162 162
 
163 163
 		if (isset($line['speed']) && $line['speed'] != '') {
164
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
165
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
164
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
165
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
166 166
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
167
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
168
-		    if ($distance > 100 && $distance < 10000) {
167
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
168
+			if ($distance > 100 && $distance < 10000) {
169 169
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
170 170
 			$speed = $speed*3.6;
171 171
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
172 172
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['ident']." : ".$speed." - distance : ".$distance."\n";
173
-		    }
173
+			}
174 174
 		}
175 175
 
176
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
177
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
178
-	    	    else unset($timediff);
179
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 100 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
176
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
177
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
178
+				else unset($timediff);
179
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 100 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
180 180
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
181
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
181
+				if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
182 182
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
183 183
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
184 184
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -192,30 +192,30 @@  discard block
 block discarded – undo
192 192
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
193 193
 				$this->tmd = 0;
194 194
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
195
-			    }
195
+				}
196 196
 			}
197 197
 
198 198
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
199 199
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
200 200
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
201
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
202
-				    $dataFound = true;
203
-				    $this->all_tracked[$id]['time_last_coord'] = time();
201
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
202
+					$dataFound = true;
203
+					$this->all_tracked[$id]['time_last_coord'] = time();
204 204
 				}
205 205
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
206 206
 			}
207 207
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
208
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
208
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
209 209
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
210 210
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
211
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
212
-				    $dataFound = true;
213
-				    $this->all_tracked[$id]['time_last_coord'] = time();
211
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
212
+					$dataFound = true;
213
+					$this->all_tracked[$id]['time_last_coord'] = time();
214 214
 				}
215 215
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
216 216
 			}
217 217
 
218
-		    } else if ($globalDebug && $timediff > 20) {
218
+			} else if ($globalDebug && $timediff > 20) {
219 219
 			$this->tmd = $this->tmd + 1;
220 220
 			if ($line['latitude'] != $this->all_tracked[$id]['latitude'] && $line['longitude'] != $this->all_tracked[$id]['longitude']) {
221 221
 				echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
@@ -223,131 +223,131 @@  discard block
 block discarded – undo
223 223
 				echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
224 224
 				echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
225 225
 			}
226
-		    }
226
+			}
227 227
 		}
228 228
 		if (isset($line['last_update']) && $line['last_update'] != '') {
229
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
230
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
229
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
230
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
231 231
 		}
232 232
 		if (isset($line['format_source']) && $line['format_source'] != '') {
233
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
233
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
234 234
 		}
235 235
 		if (isset($line['source_name']) && $line['source_name'] != '') {
236
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
236
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
237 237
 		}
238 238
 		if (isset($line['comment']) && $line['comment'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
240
-		    //$dataFound = true;
239
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
240
+			//$dataFound = true;
241 241
 		}
242 242
 		if (isset($line['type']) && $line['type'] != '') {
243
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
244
-		    //$dataFound = true;
243
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
244
+			//$dataFound = true;
245 245
 		}
246 246
 
247 247
 		if (isset($line['altitude']) && $line['altitude'] != '') {
248
-		    //if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
248
+			//if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
249 249
 			if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) $this->all_tracked[$id]['putinarchive'] = true;
250 250
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude' => $line['altitude']));
251 251
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude_real' => $line['altitude']));
252 252
 			//$dataFound = true;
253
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
253
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
254 254
   		}
255 255
 
256 256
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
257
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
257
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
258 258
 		}
259 259
 		
260 260
 		if (isset($line['heading']) && $line['heading'] != '') {
261
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
263
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
264
-		    //$dataFound = true;
261
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
262
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
263
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
264
+			//$dataFound = true;
265 265
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
266
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
267
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
268
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
269
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
266
+  			$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
267
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
268
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
269
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
270 270
   		}
271 271
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
272 272
 
273 273
 		if ($dataFound === true && isset($this->all_tracked[$id]['ident'])) {
274
-		    $this->all_tracked[$id]['lastupdate'] = time();
275
-		    if ($this->all_tracked[$id]['addedTracker'] == 0) {
276
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
277
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
274
+			$this->all_tracked[$id]['lastupdate'] = time();
275
+			if ($this->all_tracked[$id]['addedTracker'] == 0) {
276
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
277
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
278 278
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
279 279
 				$timeelapsed = microtime(true);
280 280
 				$TrackerLive = new TrackerLive($this->db);
281 281
 				if (isset($line['id'])) {
282
-				    $recent_ident = $TrackerLive->checkIdRecent($line['id']);
283
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
282
+					$recent_ident = $TrackerLive->checkIdRecent($line['id']);
283
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
284 284
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
285
-				    $recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
286
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
285
+					$recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
286
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287 287
 				} else $recent_ident = '';
288 288
 				$TrackerLive->db=null;
289 289
 
290 290
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
291 291
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
292
-			    } else {
292
+				} else {
293 293
 				$recent_ident = '';
294 294
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
295
-			    }
296
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
297
-			    if($recent_ident == "")
298
-			    {
295
+				}
296
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
297
+				if($recent_ident == "")
298
+				{
299 299
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
300 300
 				//adds the spotter data for the archive
301
-				    $highlight = '';
302
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
303
-				    $timeelapsed = microtime(true);
304
-				    $Tracker = new Tracker($this->db);
305
-				    $result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
306
-				    $Tracker->db = null;
307
-				    if ($globalDebug && isset($result)) echo $result."\n";
308
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
301
+					$highlight = '';
302
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
303
+					$timeelapsed = microtime(true);
304
+					$Tracker = new Tracker($this->db);
305
+					$result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
306
+					$Tracker->db = null;
307
+					if ($globalDebug && isset($result)) echo $result."\n";
308
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
309 309
 				    
310 310
 				    
311
-				    // Add source stat in DB
312
-				    $Stats = new Stats($this->db);
313
-				    if (!empty($this->stats)) {
311
+					// Add source stat in DB
312
+					$Stats = new Stats($this->db);
313
+					if (!empty($this->stats)) {
314 314
 					if ($globalDebug) echo 'Add source stats : ';
315
-				        foreach($this->stats as $date => $data) {
316
-					    foreach($data as $source => $sourced) {
317
-					        //print_r($sourced);
318
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date);
319
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date);
320
-				    		if (isset($sourced['msg'])) {
321
-				    		    if (time() - $sourced['msg']['date'] > 10) {
322
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
323
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg_tracker',$date);
324
-			    			        unset($this->stats[$date][$source]['msg']);
325
-			    			    }
326
-			    			}
327
-			    		    }
328
-			    		    if ($date != date('Y-m-d')) {
329
-			    			unset($this->stats[$date]);
330
-			    		    }
331
-				    	}
332
-				    	if ($globalDebug) echo 'Done'."\n";
315
+						foreach($this->stats as $date => $data) {
316
+						foreach($data as $source => $sourced) {
317
+							//print_r($sourced);
318
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date);
319
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date);
320
+							if (isset($sourced['msg'])) {
321
+								if (time() - $sourced['msg']['date'] > 10) {
322
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
323
+									echo $Stats->addStatSource($nbmsg,$source,'msg_tracker',$date);
324
+									unset($this->stats[$date][$source]['msg']);
325
+								}
326
+							}
327
+							}
328
+							if ($date != date('Y-m-d')) {
329
+							unset($this->stats[$date]);
330
+							}
331
+						}
332
+						if ($globalDebug) echo 'Done'."\n";
333 333
 
334
-				    }
335
-				    $Stats->db = null;
334
+					}
335
+					$Stats->db = null;
336 336
 				    
337
-				    $this->del();
337
+					$this->del();
338 338
 				//$ignoreImport = false;
339 339
 				$this->all_tracked[$id]['addedTracker'] = 1;
340 340
 				//print_r($this->all_tracked[$id]);
341 341
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
342
-				    if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
343
-				    //TrackerLive->deleteLiveTrackerDataNotUpdated();
344
-				    $TrackerLive = new TrackerLive($this->db);
345
-				    $TrackerLive->deleteLiveTrackerData();
346
-				    $TrackerLive->db=null;
347
-				    if ($globalDebug) echo " Done\n";
348
-				    $this->last_delete = time();
342
+					if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
343
+					//TrackerLive->deleteLiveTrackerDataNotUpdated();
344
+					$TrackerLive = new TrackerLive($this->db);
345
+					$TrackerLive->deleteLiveTrackerData();
346
+					$TrackerLive->db=null;
347
+					if ($globalDebug) echo " Done\n";
348
+					$this->last_delete = time();
349 349
 				}
350
-			    } else {
350
+				} else {
351 351
 				$this->all_tracked[$id]['id'] = $recent_ident;
352 352
 				$this->all_tracked[$id]['addedTracker'] = 1;
353 353
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
 					$Tracker->db = null;
357 357
 				}
358 358
 				
359
-			    }
359
+				}
360 360
 			}
361
-		    }
362
-		    //adds the spotter LIVE data
363
-		    if ($globalDebug) {
361
+			}
362
+			//adds the spotter LIVE data
363
+			if ($globalDebug) {
364 364
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Altitude : '.$this->all_tracked[$id]['altitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
365
-		    }
366
-		    $ignoreImport = false;
365
+			}
366
+			$ignoreImport = false;
367 367
 
368
-		    if (!$ignoreImport) {
368
+			if (!$ignoreImport) {
369 369
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
370 370
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
371 371
 				$timeelapsed = microtime(true);
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 					if ($stats_heading == 16) $stats_heading = 0;
404 404
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
405 405
 						for ($i=0;$i<=15;$i++) {
406
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
406
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
407 407
 						}
408 408
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
409 409
 					} else {
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 					//var_dump($this->stats);
417 417
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
418 418
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
419
-						    end($this->stats[$current_date][$source]['hist']);
420
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
419
+							end($this->stats[$current_date][$source]['hist']);
420
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
421 421
 						} else $mini = 0;
422 422
 						for ($i=$mini;$i<=$distance;$i+=10) {
423
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
423
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
424 424
 						}
425 425
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
426 426
 					} else {
@@ -436,22 +436,22 @@  discard block
 block discarded – undo
436 436
 			
437 437
 			
438 438
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
439
-			    if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
440
-			    $TrackerLive = new TrackerLive($this->db);
441
-			    $TrackerLive->deleteLiveTrackerDataNotUpdated();
442
-			    $TrackerLive->db = null;
443
-			    //TrackerLive->deleteLiveTrackerData();
444
-			    if ($globalDebug) echo " Done\n";
445
-			    $this->last_delete_hourly = time();
439
+				if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
440
+				$TrackerLive = new TrackerLive($this->db);
441
+				$TrackerLive->deleteLiveTrackerDataNotUpdated();
442
+				$TrackerLive->db = null;
443
+				//TrackerLive->deleteLiveTrackerData();
444
+				if ($globalDebug) echo " Done\n";
445
+				$this->last_delete_hourly = time();
446 446
 			}
447 447
 			
448
-		    }
449
-		    //$ignoreImport = false;
448
+			}
449
+			//$ignoreImport = false;
450 450
 		}
451 451
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
452 452
 		if ($send) return $this->all_tracked[$id];
453
-	    }
453
+		}
454
+	}
454 455
 	}
455
-    }
456 456
 }
457 457
 ?>
Please login to merge, or discard this patch.
require/class.TrackerLive.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	/**
89
-	* Gets all the spotter information based on the latest data entry
90
-	*
91
-	* @return Array the spotter information
92
-	*
93
-	*/
89
+	 * Gets all the spotter information based on the latest data entry
90
+	 *
91
+	 * @return Array the spotter information
92
+	 *
93
+	 */
94 94
 	public function getLiveTrackerData($limit = '', $sort = '', $filter = array())
95 95
 	{
96 96
 		global $globalDBdriver, $globalLiveInterval;
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Gets Minimal Live Spotter data
136
-	*
137
-	* @return Array the spotter information
138
-	*
139
-	*/
135
+	 * Gets Minimal Live Spotter data
136
+	 *
137
+	 * @return Array the spotter information
138
+	 *
139
+	 */
140 140
 	public function getMinLiveTrackerData($filter = array())
141 141
 	{
142 142
 		global $globalDBdriver, $globalLiveInterval;
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	}
171 171
 
172 172
 	/**
173
-	* Gets Minimal Live Spotter data since xx seconds
174
-	*
175
-	* @return Array the spotter information
176
-	*
177
-	*/
173
+	 * Gets Minimal Live Spotter data since xx seconds
174
+	 *
175
+	 * @return Array the spotter information
176
+	 *
177
+	 */
178 178
 	public function getMinLastLiveTrackerData($filter = array())
179 179
 	{
180 180
 		global $globalDBdriver, $globalLiveInterval;
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 			$query  = 'SELECT tracker_live.ident, tracker_live.famtrackid,tracker_live.type, tracker_live.latitude, tracker_live.longitude, tracker_live.altitude, tracker_live.heading, tracker_live.ground_speed, tracker_live.date, tracker_live.format_source 
188 188
 			FROM tracker_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= tracker_live.date AND tracker_live.latitude <> '0' AND tracker_live.longitude <> '0' 
189 189
 			ORDER BY tracker_live.famtrackid, tracker_live.date";
190
-                } else {
190
+				} else {
191 191
 			$query  = "SELECT tracker_live.ident, tracker_live.famtrackid, tracker_live.type,tracker_live.latitude, tracker_live.longitude, tracker_live.altitude, tracker_live.heading, tracker_live.ground_speed, tracker_live.date, tracker_live.format_source 
192 192
 			FROM tracker_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= tracker_live.date AND tracker_live.latitude <> '0' AND tracker_live.longitude <> '0' 
193 193
 			ORDER BY tracker_live.famtrackid, tracker_live.date";
194 194
 		}
195 195
 
196
-    		try {
196
+			try {
197 197
 			$sth = $this->db->prepare($query);
198 198
 			$sth->execute();
199 199
 		} catch(PDOException $e) {
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 	}
206 206
 
207 207
 	/**
208
-	* Gets number of latest data entry
209
-	*
210
-	* @return String number of entry
211
-	*
212
-	*/
208
+	 * Gets number of latest data entry
209
+	 *
210
+	 * @return String number of entry
211
+	 *
212
+	 */
213 213
 	public function getLiveTrackerCount($filter = array())
214 214
 	{
215 215
 		global $globalDBdriver, $globalLiveInterval;
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 	}
235 235
 
236 236
 	/**
237
-	* Gets all the spotter information based on the latest data entry and coord
238
-	*
239
-	* @return Array the spotter information
240
-	*
241
-	*/
237
+	 * Gets all the spotter information based on the latest data entry and coord
238
+	 *
239
+	 * @return Array the spotter information
240
+	 *
241
+	 */
242 242
 	public function getLiveTrackerDatabyCoord($coord, $filter = array())
243 243
 	{
244 244
 		global $globalDBdriver, $globalLiveInterval;
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 	}
263 263
 
264 264
 	/**
265
-	* Gets all the spotter information based on the latest data entry and coord
266
-	*
267
-	* @return Array the spotter information
268
-	*
269
-	*/
265
+	 * Gets all the spotter information based on the latest data entry and coord
266
+	 *
267
+	 * @return Array the spotter information
268
+	 *
269
+	 */
270 270
 	public function getMinLiveTrackerDatabyCoord($coord, $filter = array())
271 271
 	{
272 272
 		global $globalDBdriver, $globalLiveInterval;
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
 	}
294 294
 
295 295
 	/**
296
-	* Gets all the spotter information based on a user's latitude and longitude
297
-	*
298
-	* @return Array the spotter information
299
-	*
300
-	*/
296
+	 * Gets all the spotter information based on a user's latitude and longitude
297
+	 *
298
+	 * @return Array the spotter information
299
+	 *
300
+	 */
301 301
 	public function getLatestTrackerForLayar($lat, $lng, $radius, $interval)
302 302
 	{
303 303
 		$Tracker = new Tracker($this->db);
@@ -310,142 +310,142 @@  discard block
 block discarded – undo
310 310
 		if ($lng != '')
311 311
 		{
312 312
 			if (!is_numeric($lng))
313
-                        {
314
-                                return false;
315
-                        }
316
-                }
317
-
318
-                if ($radius != '')
319
-                {
320
-                        if (!is_numeric($radius))
321
-                        {
322
-                                return false;
323
-                        }
324
-                }
313
+						{
314
+								return false;
315
+						}
316
+				}
317
+
318
+				if ($radius != '')
319
+				{
320
+						if (!is_numeric($radius))
321
+						{
322
+								return false;
323
+						}
324
+				}
325 325
 		$additional_query = '';
326 326
 		if ($interval != '')
327
-                {
328
-                        if (!is_string($interval))
329
-                        {
330
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';
331
-			        return false;
332
-                        } else {
333
-                if ($interval == '1m')
334
-                {
335
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';
336
-                } else if ($interval == '15m'){
337
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= tracker_live.date ';
338
-                } 
339
-            }
340
-                } else {
341
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';   
342
-        }
343
-
344
-                $query  = "SELECT tracker_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM tracker_live 
327
+				{
328
+						if (!is_string($interval))
329
+						{
330
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';
331
+					return false;
332
+						} else {
333
+				if ($interval == '1m')
334
+				{
335
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';
336
+				} else if ($interval == '15m'){
337
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= tracker_live.date ';
338
+				} 
339
+			}
340
+				} else {
341
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= tracker_live.date ';   
342
+		}
343
+
344
+				$query  = "SELECT tracker_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM tracker_live 
345 345
                    WHERE tracker_live.latitude <> '' 
346 346
                                    AND tracker_live.longitude <> '' 
347 347
                    ".$additional_query."
348 348
                    HAVING distance < :radius  
349 349
                                    ORDER BY distance";
350 350
 
351
-                $spotter_array = $Tracker->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
351
+				$spotter_array = $Tracker->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
352 352
 
353
-                return $spotter_array;
354
-        }
353
+				return $spotter_array;
354
+		}
355 355
 
356 356
     
357
-        /**
358
-	* Gets all the spotter information based on a particular callsign
359
-	*
360
-	* @return Array the spotter information
361
-	*
362
-	*/
357
+		/**
358
+		 * Gets all the spotter information based on a particular callsign
359
+		 *
360
+		 * @return Array the spotter information
361
+		 *
362
+		 */
363 363
 	public function getLastLiveTrackerDataByIdent($ident)
364 364
 	{
365 365
 		$Tracker = new Tracker($this->db);
366 366
 		date_default_timezone_set('UTC');
367 367
 
368 368
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
369
-                $query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.ident = :ident GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
369
+				$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.ident = :ident GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
370 370
 
371 371
 		$spotter_array = $Tracker->getDataFromDB($query,array(':ident' => $ident),'',true);
372 372
 
373 373
 		return $spotter_array;
374 374
 	}
375 375
 
376
-        /**
377
-	* Gets all the spotter information based on a particular callsign
378
-	*
379
-	* @return Array the spotter information
380
-	*
381
-	*/
376
+		/**
377
+		 * Gets all the spotter information based on a particular callsign
378
+		 *
379
+		 * @return Array the spotter information
380
+		 *
381
+		 */
382 382
 	public function getDateLiveTrackerDataByIdent($ident,$date)
383 383
 	{
384 384
 		$Tracker = new Tracker($this->db);
385 385
 		date_default_timezone_set('UTC');
386 386
 
387 387
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
388
-                $query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
388
+				$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
389 389
 
390
-                $date = date('c',$date);
390
+				$date = date('c',$date);
391 391
 		$spotter_array = $Tracker->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
392 392
 
393 393
 		return $spotter_array;
394 394
 	}
395 395
 
396
-        /**
397
-	* Gets last spotter information based on a particular callsign
398
-	*
399
-	* @return Array the spotter information
400
-	*
401
-	*/
396
+		/**
397
+		 * Gets last spotter information based on a particular callsign
398
+		 *
399
+		 * @return Array the spotter information
400
+		 *
401
+		 */
402 402
 	public function getLastLiveTrackerDataById($id)
403 403
 	{
404 404
 		$Tracker = new Tracker($this->db);
405 405
 		date_default_timezone_set('UTC');
406 406
 
407 407
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
408
-                $query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.famtrackid = :id GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
408
+				$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.famtrackid = :id GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
409 409
 
410 410
 		$spotter_array = $Tracker->getDataFromDB($query,array(':id' => $id),'',true);
411 411
 
412 412
 		return $spotter_array;
413 413
 	}
414 414
 
415
-        /**
416
-	* Gets last spotter information based on a particular callsign
417
-	*
418
-	* @return Array the spotter information
419
-	*
420
-	*/
415
+		/**
416
+		 * Gets last spotter information based on a particular callsign
417
+		 *
418
+		 * @return Array the spotter information
419
+		 *
420
+		 */
421 421
 	public function getDateLiveTrackerDataById($id,$date)
422 422
 	{
423 423
 		$Tracker = new Tracker($this->db);
424 424
 		date_default_timezone_set('UTC');
425 425
 
426 426
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
427
-                $query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.famtrackid = :id AND l.date <= :date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
428
-                $date = date('c',$date);
427
+				$query  = 'SELECT tracker_live.* FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l WHERE l.famtrackid = :id AND l.date <= :date GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate ORDER BY tracker_live.date DESC';
428
+				$date = date('c',$date);
429 429
 		$spotter_array = $Tracker->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
430 430
 
431 431
 		return $spotter_array;
432 432
 	}
433 433
 
434
-        /**
435
-	* Gets altitude information based on a particular callsign
436
-	*
437
-	* @return Array the spotter information
438
-	*
439
-	*/
434
+		/**
435
+		 * Gets altitude information based on a particular callsign
436
+		 *
437
+		 * @return Array the spotter information
438
+		 *
439
+		 */
440 440
 	public function getAltitudeLiveTrackerDataByIdent($ident)
441 441
 	{
442 442
 
443 443
 		date_default_timezone_set('UTC');
444 444
 
445 445
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
446
-                $query  = 'SELECT tracker_live.altitude, tracker_live.date FROM tracker_live WHERE tracker_live.ident = :ident';
446
+				$query  = 'SELECT tracker_live.altitude, tracker_live.date FROM tracker_live WHERE tracker_live.ident = :ident';
447 447
 
448
-    		try {
448
+			try {
449 449
 			
450 450
 			$sth = $this->db->prepare($query);
451 451
 			$sth->execute(array(':ident' => $ident));
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 		return $spotter_array;
459 459
 	}
460 460
 
461
-        /**
462
-	* Gets all the spotter information based on a particular id
463
-	*
464
-	* @return Array the spotter information
465
-	*
466
-	*/
461
+		/**
462
+		 * Gets all the spotter information based on a particular id
463
+		 *
464
+		 * @return Array the spotter information
465
+		 *
466
+		 */
467 467
 	public function getAllLiveTrackerDataById($id,$liveinterval = false)
468 468
 	{
469 469
 		global $globalDBdriver, $globalLiveInterval;
@@ -491,18 +491,18 @@  discard block
 block discarded – undo
491 491
 		return $spotter_array;
492 492
 	}
493 493
 
494
-        /**
495
-	* Gets all the spotter information based on a particular ident
496
-	*
497
-	* @return Array the spotter information
498
-	*
499
-	*/
494
+		/**
495
+		 * Gets all the spotter information based on a particular ident
496
+		 *
497
+		 * @return Array the spotter information
498
+		 *
499
+		 */
500 500
 	public function getAllLiveTrackerDataByIdent($ident)
501 501
 	{
502 502
 		date_default_timezone_set('UTC');
503 503
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
504 504
 		$query  = self::$global_query.' WHERE tracker_live.ident = :ident';
505
-    		try {
505
+			try {
506 506
 			
507 507
 			$sth = $this->db->prepare($query);
508 508
 			$sth->execute(array(':ident' => $ident));
@@ -516,23 +516,23 @@  discard block
 block discarded – undo
516 516
 
517 517
 
518 518
 	/**
519
-	* Deletes all info in the table
520
-	*
521
-	* @return String success or false
522
-	*
523
-	*/
519
+	 * Deletes all info in the table
520
+	 *
521
+	 * @return String success or false
522
+	 *
523
+	 */
524 524
 	public function deleteLiveTrackerData()
525 525
 	{
526 526
 		global $globalDBdriver;
527 527
 		if ($globalDBdriver == 'mysql') {
528 528
 			//$query  = "DELETE FROM tracker_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= tracker_live.date";
529 529
 			$query  = 'DELETE FROM tracker_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= tracker_live.date';
530
-            		//$query  = "DELETE FROM tracker_live WHERE tracker_live.id IN (SELECT tracker_live.id FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= tracker_live.date)";
530
+					//$query  = "DELETE FROM tracker_live WHERE tracker_live.id IN (SELECT tracker_live.id FROM tracker_live INNER JOIN (SELECT l.famtrackid, max(l.date) as maxdate FROM tracker_live l GROUP BY l.famtrackid) s on tracker_live.famtrackid = s.famtrackid AND tracker_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= tracker_live.date)";
531 531
 		} else {
532 532
 			$query  = "DELETE FROM tracker_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= tracker_live.date";
533 533
 		}
534 534
         
535
-    		try {
535
+			try {
536 536
 			
537 537
 			$sth = $this->db->prepare($query);
538 538
 			$sth->execute();
@@ -544,18 +544,18 @@  discard block
 block discarded – undo
544 544
 	}
545 545
 
546 546
 	/**
547
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
548
-	*
549
-	* @return String success or false
550
-	*
551
-	*/
547
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
548
+	 *
549
+	 * @return String success or false
550
+	 *
551
+	 */
552 552
 	public function deleteLiveTrackerDataNotUpdated()
553 553
 	{
554 554
 		global $globalDBdriver, $globalDebug;
555 555
 		if ($globalDBdriver == 'mysql') {
556 556
 			//$query = 'SELECT famtrackid FROM tracker_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= tracker_live.date AND tracker_live.famtrackid NOT IN (SELECT famtrackid FROM tracker_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < tracker_live.date) LIMIT 800 OFFSET 0';
557
-    			$query = "SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
558
-    			try {
557
+				$query = "SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
558
+				try {
559 559
 				
560 560
 				$sth = $this->db->prepare($query);
561 561
 				$sth->execute();
@@ -563,8 +563,8 @@  discard block
 block discarded – undo
563 563
 				return "error";
564 564
 			}
565 565
 			$query_delete = 'DELETE FROM tracker_live WHERE famtrackid IN (';
566
-                        $i = 0;
567
-                        $j =0;
566
+						$i = 0;
567
+						$j =0;
568 568
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
569 569
 			foreach($all as $row)
570 570
 			{
@@ -572,20 +572,20 @@  discard block
 block discarded – undo
572 572
 				$j++;
573 573
 				if ($j == 30) {
574 574
 					if ($globalDebug) echo ".";
575
-				    	try {
575
+						try {
576 576
 						
577 577
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
578 578
 						$sth->execute();
579 579
 					} catch(PDOException $e) {
580 580
 						return "error";
581 581
 					}
582
-                                	$query_delete = 'DELETE FROM tracker_live WHERE famtrackid IN (';
583
-                                	$j = 0;
582
+									$query_delete = 'DELETE FROM tracker_live WHERE famtrackid IN (';
583
+									$j = 0;
584 584
 				}
585 585
 				$query_delete .= "'".$row['famtrackid']."',";
586 586
 			}
587 587
 			if ($i > 0) {
588
-    				try {
588
+					try {
589 589
 					
590 590
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
591 591
 					$sth->execute();
@@ -596,9 +596,9 @@  discard block
 block discarded – undo
596 596
 			return "success";
597 597
 		} elseif ($globalDBdriver == 'pgsql') {
598 598
 			//$query = "SELECT famtrackid FROM tracker_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= tracker_live.date AND tracker_live.famtrackid NOT IN (SELECT famtrackid FROM tracker_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < tracker_live.date) LIMIT 800 OFFSET 0";
599
-    			//$query = "SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
600
-    			$query = "DELETE FROM tracker_live WHERE famtrackid IN (SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
601
-    			try {
599
+				//$query = "SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
600
+				$query = "DELETE FROM tracker_live WHERE famtrackid IN (SELECT tracker_live.famtrackid FROM tracker_live INNER JOIN (SELECT famtrackid,MAX(date) as max_date FROM tracker_live GROUP BY famtrackid) s ON s.famtrackid = tracker_live.famtrackid AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
601
+				try {
602 602
 				
603 603
 				$sth = $this->db->prepare($query);
604 604
 				$sth->execute();
@@ -642,17 +642,17 @@  discard block
 block discarded – undo
642 642
 	}
643 643
 
644 644
 	/**
645
-	* Deletes all info in the table for an ident
646
-	*
647
-	* @return String success or false
648
-	*
649
-	*/
645
+	 * Deletes all info in the table for an ident
646
+	 *
647
+	 * @return String success or false
648
+	 *
649
+	 */
650 650
 	public function deleteLiveTrackerDataByIdent($ident)
651 651
 	{
652 652
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
653 653
 		$query  = 'DELETE FROM tracker_live WHERE ident = :ident';
654 654
         
655
-    		try {
655
+			try {
656 656
 			
657 657
 			$sth = $this->db->prepare($query);
658 658
 			$sth->execute(array(':ident' => $ident));
@@ -664,17 +664,17 @@  discard block
 block discarded – undo
664 664
 	}
665 665
 
666 666
 	/**
667
-	* Deletes all info in the table for an id
668
-	*
669
-	* @return String success or false
670
-	*
671
-	*/
667
+	 * Deletes all info in the table for an id
668
+	 *
669
+	 * @return String success or false
670
+	 *
671
+	 */
672 672
 	public function deleteLiveTrackerDataById($id)
673 673
 	{
674 674
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
675 675
 		$query  = 'DELETE FROM tracker_live WHERE famtrackid = :id';
676 676
         
677
-    		try {
677
+			try {
678 678
 			
679 679
 			$sth = $this->db->prepare($query);
680 680
 			$sth->execute(array(':id' => $id));
@@ -687,11 +687,11 @@  discard block
 block discarded – undo
687 687
 
688 688
 
689 689
 	/**
690
-	* Gets the aircraft ident within the last hour
691
-	*
692
-	* @return String the ident
693
-	*
694
-	*/
690
+	 * Gets the aircraft ident within the last hour
691
+	 *
692
+	 * @return String the ident
693
+	 *
694
+	 */
695 695
 	public function getIdentFromLastHour($ident)
696 696
 	{
697 697
 		global $globalDBdriver, $globalTimezone;
@@ -717,14 +717,14 @@  discard block
 block discarded – undo
717 717
 			$ident_result = $row['ident'];
718 718
 		}
719 719
 		return $ident_result;
720
-        }
720
+		}
721 721
 
722 722
 	/**
723
-	* Check recent aircraft
724
-	*
725
-	* @return String the ident
726
-	*
727
-	*/
723
+	 * Check recent aircraft
724
+	 *
725
+	 * @return String the ident
726
+	 *
727
+	 */
728 728
 	public function checkIdentRecent($ident)
729 729
 	{
730 730
 		global $globalDBdriver, $globalTimezone;
@@ -750,14 +750,14 @@  discard block
 block discarded – undo
750 750
 			$ident_result = $row['famtrackid'];
751 751
 		}
752 752
 		return $ident_result;
753
-        }
753
+		}
754 754
 
755 755
 	/**
756
-	* Check recent aircraft by id
757
-	*
758
-	* @return String the ident
759
-	*
760
-	*/
756
+	 * Check recent aircraft by id
757
+	 *
758
+	 * @return String the ident
759
+	 *
760
+	 */
761 761
 	public function checkIdRecent($id)
762 762
 	{
763 763
 		global $globalDBdriver, $globalTimezone;
@@ -783,19 +783,19 @@  discard block
 block discarded – undo
783 783
 			$ident_result = $row['famtrackid'];
784 784
 		}
785 785
 		return $ident_result;
786
-        }
786
+		}
787 787
 
788 788
 	/**
789
-	* Adds a new spotter data
790
-	*
791
-	* @param String $famtrackid the ID from flightaware
792
-	* @param String $ident the flight ident
793
-	* @param String $aircraft_icao the aircraft type
794
-	* @param String $departure_airport_icao the departure airport
795
-	* @param String $arrival_airport_icao the arrival airport
796
-	* @return String success or false
797
-	*
798
-	*/
789
+	 * Adds a new spotter data
790
+	 *
791
+	 * @param String $famtrackid the ID from flightaware
792
+	 * @param String $ident the flight ident
793
+	 * @param String $aircraft_icao the aircraft type
794
+	 * @param String $departure_airport_icao the departure airport
795
+	 * @param String $arrival_airport_icao the arrival airport
796
+	 * @return String success or false
797
+	 *
798
+	 */
799 799
 	public function addLiveTrackerData($famtrackid = '', $ident = '', $latitude = '', $longitude = '', $altitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $comment = '', $type = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
800 800
 	{
801 801
 		global $globalURL, $globalArchive, $globalDebug;
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
 		$comment = filter_var($comment,FILTER_SANITIZE_STRING);
869 869
 		$type = filter_var($type,FILTER_SANITIZE_STRING);
870 870
 
871
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
872
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
871
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
872
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
873 873
             	
874 874
 		$query = '';
875 875
 		if ($globalArchive) {
@@ -884,18 +884,18 @@  discard block
 block discarded – undo
884 884
 			
885 885
 			$sth = $this->db->prepare($query);
886 886
 			$sth->execute($query_values);
887
-                } catch(PDOException $e) {
888
-                	return "error : ".$e->getMessage();
889
-                }
890
-                /*
887
+				} catch(PDOException $e) {
888
+					return "error : ".$e->getMessage();
889
+				}
890
+				/*
891 891
                 echo 'putinarchive : '.$putinarchive."\n";
892 892
                 echo 'noarchive : '.$noarchive."\n";
893 893
                 */
894 894
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
895
-		    if ($globalDebug) echo '(Add to Tracker archive '.$famtrackid.' : ';
896
-		    $TrackerArchive = new TrackerArchive($this->db);
897
-		    $result =  $TrackerArchive->addTrackerArchiveData($famtrackid, $ident,$latitude, $longitude, $altitude, $heading, $groundspeed, $date, $putinarchive, $comment, $type,$noarchive,$format_source, $source_name, $over_country);
898
-		    if ($globalDebug) echo $result.')';
895
+			if ($globalDebug) echo '(Add to Tracker archive '.$famtrackid.' : ';
896
+			$TrackerArchive = new TrackerArchive($this->db);
897
+			$result =  $TrackerArchive->addTrackerArchiveData($famtrackid, $ident,$latitude, $longitude, $altitude, $heading, $groundspeed, $date, $putinarchive, $comment, $type,$noarchive,$format_source, $source_name, $over_country);
898
+			if ($globalDebug) echo $result.')';
899 899
 		}
900 900
 
901 901
 		return "success";
Please login to merge, or discard this patch.