Completed
Push — master ( e6c083...dab432 )
by Yannick
31:25
created
scripts/daemon-spotter.php 3 patches
Indentation   +1020 added lines, -1020 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,46 +25,46 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->connectionExists() === false) {
28
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
-    exit();
28
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
+	exit();
30 30
 }
31 31
 if ($Connection->latest() === false) {
32
-    echo "You MUST update to latest schema. Run install/index.php";
33
-    exit();
32
+	echo "You MUST update to latest schema. Run install/index.php";
33
+	exit();
34 34
 }
35 35
 if (PHP_SAPI != 'cli') {
36
-    echo "This script MUST be called from console, not a web browser.";
36
+	echo "This script MUST be called from console, not a web browser.";
37 37
 //    exit();
38 38
 }
39 39
 
40 40
 // This is to be compatible with old version of settings.php
41 41
 if (!isset($globalSources)) {
42
-    if (isset($globalSBS1Hosts)) {
43
-        //$hosts = $globalSBS1Hosts;
44
-        foreach ($globalSBS1Hosts as $host) {
45
-	    $globalSources[] = array('host' => $host);
46
-    	}
47
-    } else {
48
-        if (!isset($globalSBS1Host)) {
49
-	    echo '$globalSources MUST be defined !';
50
-	    die;
42
+	if (isset($globalSBS1Hosts)) {
43
+		//$hosts = $globalSBS1Hosts;
44
+		foreach ($globalSBS1Hosts as $host) {
45
+		$globalSources[] = array('host' => $host);
46
+		}
47
+	} else {
48
+		if (!isset($globalSBS1Host)) {
49
+		echo '$globalSources MUST be defined !';
50
+		die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53 53
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
54
-    }
54
+	}
55 55
 }
56 56
 
57 57
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65
-    $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
65
+	$globalSources = array();
66
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
+	else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
70 70
 	$globalServerAPRS = TRUE;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 if (isset($options['idsource'])) $id_source = $options['idsource'];
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
106
+	if ($globalDebug) echo "Using Server Mode\n";
107
+	$SI=new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
117
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
117
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 119
 }
120 120
 
121 121
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
122 122
 if (isset($globalMarine) && $globalMarine) {
123
-    $AIS = new AIS();
124
-    $MI = new MarineImport($Connection->db);
123
+	$AIS = new AIS();
124
+	$MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127 127
 $SBS=new SBS();
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
138
-        global $sockets;
139
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
-        die("Bye!\n");
141
-    });
142
-    pcntl_signal_dispatch();
137
+	pcntl_signal(SIGINT,  function() {
138
+		global $sockets;
139
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
+		die("Bye!\n");
141
+	});
142
+	pcntl_signal_dispatch();
143 143
 }
144 144
 
145 145
 // let's try and connect
@@ -149,36 +149,36 @@  discard block
 block discarded – undo
149 149
 $reset = 0;
150 150
 
151 151
 function connect_all($hosts) {
152
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
-    $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
156
-    foreach ($hosts as $id => $value) {
152
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
+	$reset++;
155
+	if ($globalDebug) echo 'Connect to all...'."\n";
156
+	foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160 160
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
162
-        	//$formats[$id] = 'deltadbtxt';
163
-        	$globalSources[$id]['format'] = 'deltadbtxt';
164
-        	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
-        	//$formats[$id] = 'vatsimtxt';
168
-        	$globalSources[$id]['format'] = 'vatsimtxt';
169
-        	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172
-        	//$formats[$id] = 'aircraftlistjson';
173
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
174
-        	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/opensky/i',$host)) {
177
-        	//$formats[$id] = 'aircraftlistjson';
178
-        	$globalSources[$id]['format'] = 'opensky';
179
-        	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
181
-    	    /*
161
+			if (preg_match('/deltadb.txt$/i',$host)) {
162
+			//$formats[$id] = 'deltadbtxt';
163
+			$globalSources[$id]['format'] = 'deltadbtxt';
164
+			//$last_exec['deltadbtxt'] = 0;
165
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
+			//$formats[$id] = 'vatsimtxt';
168
+			$globalSources[$id]['format'] = 'vatsimtxt';
169
+			//$last_exec['vatsimtxt'] = 0;
170
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
172
+			//$formats[$id] = 'aircraftlistjson';
173
+			$globalSources[$id]['format'] = 'aircraftlistjson';
174
+			//$last_exec['aircraftlistjson'] = 0;
175
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
+			} else if (preg_match('/opensky/i',$host)) {
177
+			//$formats[$id] = 'aircraftlistjson';
178
+			$globalSources[$id]['format'] = 'opensky';
179
+			//$last_exec['aircraftlistjson'] = 0;
180
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
181
+			/*
182 182
     	    // Disabled for now, site change source format
183 183
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
184 184
         	//$formats[$id] = 'radarvirtueljson';
@@ -190,125 +190,125 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
194
-        	//$formats[$id] = 'planeupdatefaa';
195
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
196
-        	//$last_exec['planeupdatefaa'] = 0;
197
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200
-        	    exit(0);
201
-        	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
203
-        	//$formats[$id] = 'phpvmacars';
204
-        	$globalSources[$id]['format'] = 'phpvmacars';
205
-        	//$last_exec['phpvmacars'] = 0;
206
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
208
-        	//$formats[$id] = 'phpvmacars';
209
-        	$globalSources[$id]['format'] = 'vaos';
210
-        	//$last_exec['phpvmacars'] = 0;
211
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
212
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
213
-        	//$formats[$id] = 'phpvmacars';
214
-        	$globalSources[$id]['format'] = 'vam';
215
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
216
-            } else if (preg_match('/whazzup/i',$host)) {
217
-        	//$formats[$id] = 'whazzup';
218
-        	$globalSources[$id]['format'] = 'whazzup';
219
-        	//$last_exec['whazzup'] = 0;
220
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
221
-            } else if (preg_match('/blitzortung/i',$host)) {
222
-        	$globalSources[$id]['format'] = 'blitzortung';
223
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
224
-            } else if (preg_match('/airwhere/i',$host)) {
225
-        	$globalSources[$id]['format'] = 'airwhere';
226
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
227
-            } else if (preg_match('/recentpireps/i',$host)) {
228
-        	//$formats[$id] = 'pirepsjson';
229
-        	$globalSources[$id]['format'] = 'pirepsjson';
230
-        	//$last_exec['pirepsjson'] = 0;
231
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
232
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
233
-        	//$formats[$id] = 'fr24json';
234
-        	$globalSources[$id]['format'] = 'fr24json';
235
-        	//$last_exec['fr24json'] = 0;
236
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
237
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
238
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239
-        	    exit(0);
240
-        	}
241
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
242
-        	//$formats[$id] = 'fr24json';
243
-        	$globalSources[$id]['format'] = 'myshiptracking';
244
-        	//$last_exec['fr24json'] = 0;
245
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
246
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
247
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
248
-        	    exit(0);
249
-        	}
250
-            //} else if (preg_match('/10001/',$host)) {
251
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252
-        	//$formats[$id] = 'tsv';
253
-        	$globalSources[$id]['format'] = 'tsv';
254
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
255
-            }
256
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
257
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
259
-    		    if ($idf !== false) {
260
-    			$httpfeeds[$id] = $idf;
261
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265
-	    $hostport = explode(':',$host);
266
-	    if (isset($hostport[1])) {
193
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
194
+			//$formats[$id] = 'planeupdatefaa';
195
+			$globalSources[$id]['format'] = 'planeupdatefaa';
196
+			//$last_exec['planeupdatefaa'] = 0;
197
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200
+				exit(0);
201
+			}
202
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
203
+			//$formats[$id] = 'phpvmacars';
204
+			$globalSources[$id]['format'] = 'phpvmacars';
205
+			//$last_exec['phpvmacars'] = 0;
206
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
208
+			//$formats[$id] = 'phpvmacars';
209
+			$globalSources[$id]['format'] = 'vaos';
210
+			//$last_exec['phpvmacars'] = 0;
211
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
212
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
213
+			//$formats[$id] = 'phpvmacars';
214
+			$globalSources[$id]['format'] = 'vam';
215
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
216
+			} else if (preg_match('/whazzup/i',$host)) {
217
+			//$formats[$id] = 'whazzup';
218
+			$globalSources[$id]['format'] = 'whazzup';
219
+			//$last_exec['whazzup'] = 0;
220
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
221
+			} else if (preg_match('/blitzortung/i',$host)) {
222
+			$globalSources[$id]['format'] = 'blitzortung';
223
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
224
+			} else if (preg_match('/airwhere/i',$host)) {
225
+			$globalSources[$id]['format'] = 'airwhere';
226
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
227
+			} else if (preg_match('/recentpireps/i',$host)) {
228
+			//$formats[$id] = 'pirepsjson';
229
+			$globalSources[$id]['format'] = 'pirepsjson';
230
+			//$last_exec['pirepsjson'] = 0;
231
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
232
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
233
+			//$formats[$id] = 'fr24json';
234
+			$globalSources[$id]['format'] = 'fr24json';
235
+			//$last_exec['fr24json'] = 0;
236
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
237
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
238
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239
+				exit(0);
240
+			}
241
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
242
+			//$formats[$id] = 'fr24json';
243
+			$globalSources[$id]['format'] = 'myshiptracking';
244
+			//$last_exec['fr24json'] = 0;
245
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
246
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
247
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
248
+				exit(0);
249
+			}
250
+			//} else if (preg_match('/10001/',$host)) {
251
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252
+			//$formats[$id] = 'tsv';
253
+			$globalSources[$id]['format'] = 'tsv';
254
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
255
+			}
256
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
257
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
259
+				if ($idf !== false) {
260
+				$httpfeeds[$id] = $idf;
261
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265
+		$hostport = explode(':',$host);
266
+		if (isset($hostport[1])) {
267 267
 		$port = $hostport[1];
268 268
 		$hostn = $hostport[0];
269
-	    } else {
269
+		} else {
270 270
 		$port = $globalSources[$id]['port'];
271 271
 		$hostn = $globalSources[$id]['host'];
272
-	    }
273
-	    $Common = new Common();
274
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
275
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
276
-    	    } else {
277
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
278
-	    }
279
-	    if ($s) {
280
-    	        $sockets[$id] = $s;
281
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
282
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
272
+		}
273
+		$Common = new Common();
274
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
275
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
276
+			} else {
277
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
278
+		}
279
+		if ($s) {
280
+				$sockets[$id] = $s;
281
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
282
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
283 283
 			//$formats[$id] = 'aprs';
284 284
 			$globalSources[$id]['format'] = 'aprs';
285 285
 			//$aprs_connect = 0;
286 286
 			//$use_aprs = true;
287
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
287
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
288 288
 			$globalSources[$id]['format'] = 'vrstcp';
289
-    		    } elseif ($port == '10001') {
290
-        		//$formats[$id] = 'tsv';
291
-        		$globalSources[$id]['format'] = 'tsv';
292
-		    } elseif ($port == '30002') {
293
-        		//$formats[$id] = 'raw';
294
-        		$globalSources[$id]['format'] = 'raw';
295
-		    } elseif ($port == '5001') {
296
-        		//$formats[$id] = 'raw';
297
-        		$globalSources[$id]['format'] = 'flightgearmp';
298
-		    } elseif ($port == '30005') {
289
+				} elseif ($port == '10001') {
290
+				//$formats[$id] = 'tsv';
291
+				$globalSources[$id]['format'] = 'tsv';
292
+			} elseif ($port == '30002') {
293
+				//$formats[$id] = 'raw';
294
+				$globalSources[$id]['format'] = 'raw';
295
+			} elseif ($port == '5001') {
296
+				//$formats[$id] = 'raw';
297
+				$globalSources[$id]['format'] = 'flightgearmp';
298
+			} elseif ($port == '30005') {
299 299
 			// Not yet supported
300
-        		//$formats[$id] = 'beast';
301
-        		$globalSources[$id]['format'] = 'beast';
302
-		    //} else $formats[$id] = 'sbs';
303
-		    } else $globalSources[$id]['format'] = 'sbs';
304
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
300
+				//$formats[$id] = 'beast';
301
+				$globalSources[$id]['format'] = 'beast';
302
+			//} else $formats[$id] = 'sbs';
303
+			} else $globalSources[$id]['format'] = 'sbs';
304
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
305 305
 		}
306 306
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
307
-            } else {
307
+			} else {
308 308
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
309
-    	    }
310
-        }
311
-    }
309
+			}
310
+		}
311
+	}
312 312
 }
313 313
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
314 314
 
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 //connect_all($globalSources);
332 332
 
333 333
 if (isset($globalProxy) && $globalProxy) {
334
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
334
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
335 335
 } else {
336
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
336
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
337 337
 }
338 338
 
339 339
 // APRS Configuration
@@ -342,21 +342,21 @@  discard block
 block discarded – undo
342 342
 	die;
343 343
 }
344 344
 foreach ($globalSources as $key => $source) {
345
-    if (!isset($source['format'])) {
346
-        $globalSources[$key]['format'] = 'auto';
347
-    }
348
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
349
-        unset($globalSources[$key]);
350
-    }
345
+	if (!isset($source['format'])) {
346
+		$globalSources[$key]['format'] = 'auto';
347
+	}
348
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
349
+		unset($globalSources[$key]);
350
+	}
351 351
 }
352 352
 connect_all($globalSources);
353 353
 foreach ($globalSources as $key => $source) {
354
-    if (isset($source['format']) && $source['format'] == 'aprs') {
354
+	if (isset($source['format']) && $source['format'] == 'aprs') {
355 355
 	$aprs_connect = 0;
356 356
 	$use_aprs = true;
357 357
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
358 358
 	break;
359
-    }
359
+	}
360 360
 }
361 361
 
362 362
 if ($use_aprs) {
@@ -397,129 +397,129 @@  discard block
 block discarded – undo
397 397
 
398 398
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
399 399
 while ($i > 0) {
400
-    if (!$globalDaemon) $i = $endtime-time();
401
-    // Delete old ATC
402
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
400
+	if (!$globalDaemon) $i = $endtime-time();
401
+	// Delete old ATC
402
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
403 403
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
404
-        $ATC->deleteOldATC();
405
-    }
404
+		$ATC->deleteOldATC();
405
+	}
406 406
     
407
-    if (count($last_exec) == count($globalSources)) {
407
+	if (count($last_exec) == count($globalSources)) {
408 408
 	$max = $globalMinFetch;
409 409
 	foreach ($last_exec as $last) {
410
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
410
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
411 411
 	}
412 412
 	if ($max != $globalMinFetch) {
413
-	    if ($globalDebug) echo 'Sleeping...'."\n";
414
-	    sleep($globalMinFetch-$max+2);
413
+		if ($globalDebug) echo 'Sleeping...'."\n";
414
+		sleep($globalMinFetch-$max+2);
415
+	}
415 416
 	}
416
-    }
417 417
 
418 418
     
419
-    //foreach ($formats as $id => $value) {
420
-    foreach ($globalSources as $id => $value) {
419
+	//foreach ($formats as $id => $value) {
420
+	foreach ($globalSources as $id => $value) {
421 421
 	date_default_timezone_set('UTC');
422 422
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
423 423
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
424 424
 	if ($value['format'] == 'deltadbtxt' && 
425
-	    (
425
+		(
426 426
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
427 427
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
428
-	    )
428
+		)
429 429
 	) {
430
-	    //$buffer = $Common->getData($hosts[$id]);
431
-	    $buffer = $Common->getData($value['host']);
432
-	    if ($buffer != '') $reset = 0;
433
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434
-	    $buffer = explode('\n',$buffer);
435
-	    foreach ($buffer as $line) {
436
-    		if ($line != '' && count($line) > 7) {
437
-    		    $line = explode(',', $line);
438
-	            $data = array();
439
-	            $data['hex'] = $line[1]; // hex
440
-	            $data['ident'] = $line[2]; // ident
441
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
442
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
443
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
444
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
445
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
446
-	            $data['verticalrate'] = ''; // vertical rate
447
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
448
-	            $data['emergency'] = ''; // emergency
449
-		    $data['datetime'] = date('Y-m-d H:i:s');
450
-		    $data['format_source'] = 'deltadbtxt';
451
-    		    $data['id_source'] = $id_source;
452
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
453
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
454
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
455
-    		    $SI->add($data);
456
-		    unset($data);
457
-    		}
458
-    	    }
459
-    	    $last_exec[$id]['last'] = time();
430
+		//$buffer = $Common->getData($hosts[$id]);
431
+		$buffer = $Common->getData($value['host']);
432
+		if ($buffer != '') $reset = 0;
433
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434
+		$buffer = explode('\n',$buffer);
435
+		foreach ($buffer as $line) {
436
+			if ($line != '' && count($line) > 7) {
437
+				$line = explode(',', $line);
438
+				$data = array();
439
+				$data['hex'] = $line[1]; // hex
440
+				$data['ident'] = $line[2]; // ident
441
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
442
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
443
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
444
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
445
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
446
+				$data['verticalrate'] = ''; // vertical rate
447
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
448
+				$data['emergency'] = ''; // emergency
449
+			$data['datetime'] = date('Y-m-d H:i:s');
450
+			$data['format_source'] = 'deltadbtxt';
451
+				$data['id_source'] = $id_source;
452
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
453
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
454
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
455
+				$SI->add($data);
456
+			unset($data);
457
+			}
458
+			}
459
+			$last_exec[$id]['last'] = time();
460 460
 	} elseif ($value['format'] == 'aisnmeatxt' && 
461
-	    (
461
+		(
462 462
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
463 463
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
464
-	    )
464
+		)
465 465
 	) {
466
-	    date_default_timezone_set('CET');
467
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
468
-	    date_default_timezone_set('UTC');
469
-	    if ($buffer != '') $reset = 0;
470
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471
-	    $buffer = explode('\n',$buffer);
472
-	    foreach ($buffer as $line) {
466
+		date_default_timezone_set('CET');
467
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
468
+		date_default_timezone_set('UTC');
469
+		if ($buffer != '') $reset = 0;
470
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471
+		$buffer = explode('\n',$buffer);
472
+		foreach ($buffer as $line) {
473 473
 		if ($line != '') {
474
-		    //echo "'".$line."'\n";
475
-		    $add = false;
476
-		    $ais_data = $AIS->parse_line(trim($line));
477
-		    $data = array();
478
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
480
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
483
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
484
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
485
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
486
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
487
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
488
-		    if (isset($ais_data['timestamp'])) {
474
+			//echo "'".$line."'\n";
475
+			$add = false;
476
+			$ais_data = $AIS->parse_line(trim($line));
477
+			$data = array();
478
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
480
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
483
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
484
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
485
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
486
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
487
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
488
+			if (isset($ais_data['timestamp'])) {
489 489
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
490 490
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
491
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
492
-			    $add = true;
491
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
492
+				$add = true;
493 493
 			}
494
-		    } else {
494
+			} else {
495 495
 			$data['datetime'] = date('Y-m-d H:i:s');
496 496
 			$add = true;
497
-		    }
498
-		    $data['format_source'] = 'aisnmeatxt';
499
-    		    $data['id_source'] = $id_source;
500
-		    //print_r($data);
501
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
502
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
503
-		    unset($data);
497
+			}
498
+			$data['format_source'] = 'aisnmeatxt';
499
+				$data['id_source'] = $id_source;
500
+			//print_r($data);
501
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
502
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
503
+			unset($data);
504 504
 		}
505
-    	    }
506
-    	    $last_exec[$id]['last'] = time();
505
+			}
506
+			$last_exec[$id]['last'] = time();
507 507
 	} elseif ($value['format'] == 'aisnmeahttp') {
508
-	    $arr = $httpfeeds;
509
-	    $w = $e = null;
508
+		$arr = $httpfeeds;
509
+		$w = $e = null;
510 510
 	    
511
-	    if (isset($arr[$id])) {
511
+		if (isset($arr[$id])) {
512 512
 		$nn = stream_select($arr,$w,$e,$timeout);
513 513
 		if ($nn > 0) {
514
-		    foreach ($httpfeeds as $feed) {
514
+			foreach ($httpfeeds as $feed) {
515 515
 			$buffer = stream_get_line($feed,2000,"\n");
516 516
 			if ($buffer === FALSE) {
517
-			    connect_all($globalSources);
517
+				connect_all($globalSources);
518 518
 			}
519 519
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
520 520
 			$buffer = explode('\n',$buffer);
521 521
 			foreach ($buffer as $line) {
522
-			    if ($line != '') {
522
+				if ($line != '') {
523 523
 				$ais_data = $AIS->parse_line(trim($line));
524 524
 				$data = array();
525 525
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -537,117 +537,117 @@  discard block
 block discarded – undo
537 537
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
538 538
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
539 539
 				if (isset($ais_data['timestamp'])) {
540
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
540
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
541 541
 				} else {
542
-				    $data['datetime'] = date('Y-m-d H:i:s');
542
+					$data['datetime'] = date('Y-m-d H:i:s');
543 543
 				}
544 544
 				$data['format_source'] = 'aisnmeahttp';
545 545
 				$data['id_source'] = $id_source;
546 546
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
547 547
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
548 548
 				unset($data);
549
-			    }
549
+				}
550
+			}
550 551
 			}
551
-		    }
552 552
 		} else {
553
-		    $format = $value['format'];
554
-		    if (isset($tt[$format])) $tt[$format]++;
555
-		    else $tt[$format] = 0;
556
-		    if ($tt[$format] > 30) {
553
+			$format = $value['format'];
554
+			if (isset($tt[$format])) $tt[$format]++;
555
+			else $tt[$format] = 0;
556
+			if ($tt[$format] > 30) {
557 557
 			if ($globalDebug) echo 'Reconnect...'."\n";
558 558
 			sleep(2);
559 559
 			//$sourceeen[] = $value;
560 560
 			//connect_all($sourceeen);
561 561
 			//$sourceeen = array();
562 562
 			connect_all($globalSources);
563
-		    }
563
+			}
564
+		}
564 565
 		}
565
-	    }
566 566
 	} elseif ($value['format'] == 'myshiptracking' && 
567
-	    (
567
+		(
568 568
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
569 569
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
570
-	    )
570
+		)
571 571
 	) {
572
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
573
-	    if ($buffer != '') {
572
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
573
+		if ($buffer != '') {
574 574
 		//echo $buffer;
575 575
 		$all_data = json_decode($buffer,true);
576 576
 		//print_r($all_data);
577 577
 		if (isset($all_data[0]['DATA'])) {
578
-		    foreach ($all_data[0]['DATA'] as $line) {
578
+			foreach ($all_data[0]['DATA'] as $line) {
579 579
 			if ($line != '') {
580
-			    $data = array();
581
-			    $data['ident'] = $line['NAME'];
582
-			    $data['mmsi'] = $line['MMSI'];
583
-			    if (strlen($data['mmsi']) > 9) {
580
+				$data = array();
581
+				$data['ident'] = $line['NAME'];
582
+				$data['mmsi'] = $line['MMSI'];
583
+				if (strlen($data['mmsi']) > 9) {
584 584
 				$data['mmsi'] = substr($data['mmsi'],-9);
585
-			    }
586
-			    $data['speed'] = $line['SOG'];
587
-			    $data['heading'] = $line['COG'];
588
-			    $data['latitude'] = $line['LAT'];
589
-			    $data['longitude'] = $line['LNG'];
590
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
591
-			    $data['type_id'] = $line['TYPE'];
592
-			    $data['imo'] = $line['IMO'];
593
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
594
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
595
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
596
-			    $data['format_source'] = 'myshiptracking';
597
-			    $data['id_source'] = $id_source;
598
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
599
-			    $MI->add($data);
600
-			    unset($data);
585
+				}
586
+				$data['speed'] = $line['SOG'];
587
+				$data['heading'] = $line['COG'];
588
+				$data['latitude'] = $line['LAT'];
589
+				$data['longitude'] = $line['LNG'];
590
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
591
+				$data['type_id'] = $line['TYPE'];
592
+				$data['imo'] = $line['IMO'];
593
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
594
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
595
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
596
+				$data['format_source'] = 'myshiptracking';
597
+				$data['id_source'] = $id_source;
598
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
599
+				$MI->add($data);
600
+				unset($data);
601
+			}
601 602
 			}
602
-		    }
603 603
 		}
604
-	    }
605
-	    $last_exec[$id]['last'] = time();
604
+		}
605
+		$last_exec[$id]['last'] = time();
606 606
 	} elseif ($value['format'] == 'boatbeaconapp' && 
607
-	    (
607
+		(
608 608
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
609 609
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
610
-	    )
610
+		)
611 611
 	) {
612
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
613
-	    if ($buffer != '') {
612
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
613
+		if ($buffer != '') {
614 614
 		$all_data = json_decode($buffer,true);
615 615
 		if (isset($all_data[0]['mmsi'])) {
616
-		    foreach ($all_data as $line) {
616
+			foreach ($all_data as $line) {
617 617
 			if ($line != '') {
618
-			    $data = array();
619
-			    $data['ident'] = $line['shipname'];
620
-			    $data['callsign'] = $line['callsign'];
621
-			    $data['mmsi'] = substr($line['mmsi'],-9);
622
-			    $data['speed'] = $line['sog'];
623
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
624
-			    $data['latitude'] = $line['latitude'];
625
-			    $data['longitude'] = $line['longitude'];
626
-			    $data['type_id'] = $line['shiptype'];
627
-			    $data['arrival_code'] = $line['destination'];
628
-			    $data['datetime'] = $line['time'];
629
-			    $data['format_source'] = 'boatbeaconapp';
630
-			    $data['id_source'] = $id_source;
631
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
632
-			    $MI->add($data);
633
-			    unset($data);
618
+				$data = array();
619
+				$data['ident'] = $line['shipname'];
620
+				$data['callsign'] = $line['callsign'];
621
+				$data['mmsi'] = substr($line['mmsi'],-9);
622
+				$data['speed'] = $line['sog'];
623
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
624
+				$data['latitude'] = $line['latitude'];
625
+				$data['longitude'] = $line['longitude'];
626
+				$data['type_id'] = $line['shiptype'];
627
+				$data['arrival_code'] = $line['destination'];
628
+				$data['datetime'] = $line['time'];
629
+				$data['format_source'] = 'boatbeaconapp';
630
+				$data['id_source'] = $id_source;
631
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
632
+				$MI->add($data);
633
+				unset($data);
634
+			}
634 635
 			}
635
-		    }
636 636
 		}
637 637
 		
638
-	    }
639
-    	    $last_exec[$id]['last'] = time();
638
+		}
639
+			$last_exec[$id]['last'] = time();
640 640
 	} elseif ($value['format'] == 'boatnerd' && 
641
-	    (
641
+		(
642 642
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
643 643
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
644
-	    )
644
+		)
645 645
 	) {
646
-	    $buffer = $Common->getData($value['host']);
647
-	    if ($buffer != '') {
646
+		$buffer = $Common->getData($value['host']);
647
+		if ($buffer != '') {
648 648
 		$all_data = json_decode($buffer,true);
649 649
 		if (isset($all_data['features'][0]['id'])) {
650
-		    foreach ($all_data['features'] as $line) {
650
+			foreach ($all_data['features'] as $line) {
651 651
 			print_r($line);
652 652
 			$data = array();
653 653
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -667,80 +667,80 @@  discard block
 block discarded – undo
667 667
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
668 668
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
669 669
 			unset($data);
670
-		    }
670
+			}
671 671
 		}
672 672
 		
673
-	    }
674
-    	    $last_exec[$id]['last'] = time();
673
+		}
674
+			$last_exec[$id]['last'] = time();
675 675
 	} elseif ($value['format'] == 'shipplotter' && 
676
-	    (
676
+		(
677 677
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
678 678
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
679
-	    )
679
+		)
680 680
 	) {
681
-	    echo 'download...';
682
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
683
-	    echo 'done !'."\n";
684
-	    // FIXME: Need more work
685
-	    if ($buffer != '') $reset = 0;
686
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
687
-	    $buffer = explode('\n',$buffer);
688
-	    foreach ($buffer as $line) {
681
+		echo 'download...';
682
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
683
+		echo 'done !'."\n";
684
+		// FIXME: Need more work
685
+		if ($buffer != '') $reset = 0;
686
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
687
+		$buffer = explode('\n',$buffer);
688
+		foreach ($buffer as $line) {
689 689
 		if ($line != '') {
690
-		    $data = array();
691
-		    echo $line."\n";
692
-		    $data['mmsi'] = (int)substr($line,0,9);
693
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
694
-		    $data['status_id'] = substr($line,21,2);
695
-		    $data['type_id'] = substr($line,24,3);
696
-		    $data['latitude'] = substr($line,29,9);
697
-		    $data['longitude'] = substr($line,41,9);
698
-		    $data['speed'] = round(substr($line,51,5));
699
-		    //$data['course'] = substr($line,57,5);
700
-		    $data['heading'] = round(substr($line,63,3));
701
-		    //$data['draft'] = substr($line,67,4);
702
-		    //$data['length'] = substr($line,72,3);
703
-		    //$data['beam'] = substr($line,76,2);
704
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
705
-		    //$data['callsign'] = trim(substr($line,100,7);
706
-		    $data['arrival_code'] = substr($line,108,20);
707
-		    //$data['etaDate'] = substr($line,129,5);
708
-		    //$data['etaTime'] = substr($line,135,5);
709
-		    $data['format_source'] = 'shipplotter';
710
-    		    $data['id_source'] = $id_source;
711
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
712
-		    //print_r($data);
713
-		    echo 'Add...'."\n";
714
-		    $MI->add($data);
715
-		    unset($data);
690
+			$data = array();
691
+			echo $line."\n";
692
+			$data['mmsi'] = (int)substr($line,0,9);
693
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
694
+			$data['status_id'] = substr($line,21,2);
695
+			$data['type_id'] = substr($line,24,3);
696
+			$data['latitude'] = substr($line,29,9);
697
+			$data['longitude'] = substr($line,41,9);
698
+			$data['speed'] = round(substr($line,51,5));
699
+			//$data['course'] = substr($line,57,5);
700
+			$data['heading'] = round(substr($line,63,3));
701
+			//$data['draft'] = substr($line,67,4);
702
+			//$data['length'] = substr($line,72,3);
703
+			//$data['beam'] = substr($line,76,2);
704
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
705
+			//$data['callsign'] = trim(substr($line,100,7);
706
+			$data['arrival_code'] = substr($line,108,20);
707
+			//$data['etaDate'] = substr($line,129,5);
708
+			//$data['etaTime'] = substr($line,135,5);
709
+			$data['format_source'] = 'shipplotter';
710
+				$data['id_source'] = $id_source;
711
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
712
+			//print_r($data);
713
+			echo 'Add...'."\n";
714
+			$MI->add($data);
715
+			unset($data);
716 716
 		}
717
-    	    }
718
-    	    $last_exec[$id]['last'] = time();
717
+			}
718
+			$last_exec[$id]['last'] = time();
719 719
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
720 720
 	} elseif (
721
-	    (
721
+		(
722 722
 		$value['format'] == 'whazzup' && 
723 723
 		(
724
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
725
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
724
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
725
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
726 726
 		)
727
-	    ) || (
727
+		) || (
728 728
 		$value['format'] == 'vatsimtxt' && 
729 729
 		(
730
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
731
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
730
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
731
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
732
+		)
732 733
 		)
733
-	    )
734 734
 	) {
735
-	    //$buffer = $Common->getData($hosts[$id]);
736
-	    $buffer = $Common->getData($value['host']);
737
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
738
-	    $buffer = explode('\n',$buffer);
739
-	    $reset = 0;
740
-	    foreach ($buffer as $line) {
741
-    		if ($line != '') {
742
-    		    $line = explode(':', $line);
743
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
735
+		//$buffer = $Common->getData($hosts[$id]);
736
+		$buffer = $Common->getData($value['host']);
737
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
738
+		$buffer = explode('\n',$buffer);
739
+		$reset = 0;
740
+		foreach ($buffer as $line) {
741
+			if ($line != '') {
742
+				$line = explode(':', $line);
743
+				if (count($line) > 30 && $line[0] != 'callsign') {
744 744
 			$data = array();
745 745
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
746 746
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -753,37 +753,37 @@  discard block
 block discarded – undo
753 753
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
754 754
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
755 755
 			$data['latitude'] = $line[5]; // lat
756
-	        	$data['longitude'] = $line[6]; // long
757
-	        	$data['verticalrate'] = ''; // vertical rate
758
-	        	$data['squawk'] = ''; // squawk
759
-	        	$data['emergency'] = ''; // emergency
760
-	        	$data['waypoints'] = $line[30];
756
+				$data['longitude'] = $line[6]; // long
757
+				$data['verticalrate'] = ''; // vertical rate
758
+				$data['squawk'] = ''; // squawk
759
+				$data['emergency'] = ''; // emergency
760
+				$data['waypoints'] = $line[30];
761 761
 			$data['datetime'] = date('Y-m-d H:i:s');
762 762
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
763 763
 			//if (isset($line[37])) $data['last_update'] = $line[37];
764
-		        $data['departure_airport_icao'] = $line[11];
765
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
766
-		        $data['arrival_airport_icao'] = $line[13];
764
+				$data['departure_airport_icao'] = $line[11];
765
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
766
+				$data['arrival_airport_icao'] = $line[13];
767 767
 			$data['frequency'] = $line[4];
768 768
 			$data['type'] = $line[18];
769 769
 			$data['range'] = $line[19];
770 770
 			if (isset($line[35])) $data['info'] = $line[35];
771
-    			$data['id_source'] = $id_source;
772
-	    		//$data['arrival_airport_time'] = ;
773
-	    		if ($line[9] != '') {
774
-	    		    $aircraft_data = explode('/',$line[9]);
775
-	    		    if (isset($aircraft_data[1])) {
776
-	    			$data['aircraft_icao'] = $aircraft_data[1];
777
-	    		    }
778
-        		}
779
-	    		/*
771
+				$data['id_source'] = $id_source;
772
+				//$data['arrival_airport_time'] = ;
773
+				if ($line[9] != '') {
774
+					$aircraft_data = explode('/',$line[9]);
775
+					if (isset($aircraft_data[1])) {
776
+					$data['aircraft_icao'] = $aircraft_data[1];
777
+					}
778
+				}
779
+				/*
780 780
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
781 781
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
782 782
 	    		*/
783
-	    		$data['format_source'] = $value['format'];
783
+				$data['format_source'] = $value['format'];
784 784
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
785 785
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
786
-    			if ($line[3] == 'PILOT') $SI->add($data);
786
+				if ($line[3] == 'PILOT') $SI->add($data);
787 787
 			elseif ($line[3] == 'ATC') {
788 788
 				//print_r($data);
789 789
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -804,21 +804,21 @@  discard block
 block discarded – undo
804 804
 					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']);
805 805
 				}
806 806
 			}
807
-    			unset($data);
808
-    		    }
809
-    		}
810
-    	    }
811
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
812
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
813
-    	    $last_exec[$id]['last'] = time();
814
-    	} elseif ($value['format'] == 'airwhere' && 
815
-    	    (
816
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
817
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
818
-    	    )
819
-    	) {
820
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
821
-	    if ($buffer != '') {
807
+				unset($data);
808
+				}
809
+			}
810
+			}
811
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
812
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
813
+			$last_exec[$id]['last'] = time();
814
+		} elseif ($value['format'] == 'airwhere' && 
815
+			(
816
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
817
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
818
+			)
819
+		) {
820
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
821
+		if ($buffer != '') {
822 822
 		$all_data = simplexml_load_string($buffer);
823 823
 		foreach($all_data->children() as $childdata) {
824 824
 			$data = array();
@@ -840,10 +840,10 @@  discard block
 block discarded – undo
840 840
 			$SI->add($data);
841 841
 			unset($data);
842 842
 		}
843
-	    }
844
-	    $Source->deleteOldLocationByType('gs');
845
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
846
-	    if ($buffer != '') {
843
+		}
844
+		$Source->deleteOldLocationByType('gs');
845
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
846
+		if ($buffer != '') {
847 847
 		$all_data = simplexml_load_string($buffer);
848 848
 		foreach($all_data->children() as $childdata) {
849 849
 			$data = array();
@@ -861,8 +861,8 @@  discard block
 block discarded – undo
861 861
 			}
862 862
 			unset($data);
863 863
 		}
864
-	    }
865
-	    $last_exec[$id]['last'] = time();
864
+		}
865
+		$last_exec[$id]['last'] = time();
866 866
 	/*
867 867
 	} if ($value['format'] == 'aircraftlistjson') {
868 868
 	    print_r($globalSources);
@@ -870,17 +870,17 @@  discard block
 block discarded – undo
870 870
 	    echo $globalMinFetch;
871 871
 	*/
872 872
 	} elseif ($value['format'] == 'aircraftlistjson' && 
873
-	    (
873
+		(
874 874
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
875 875
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
876
-	    )
876
+		)
877 877
 	) {
878
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
879
-	    if ($buffer != '') {
880
-	        $all_data = json_decode($buffer,true);
878
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
879
+		if ($buffer != '') {
880
+			$all_data = json_decode($buffer,true);
881 881
 		if (isset($all_data['acList'])) {
882
-		    $reset = 0;
883
-		    foreach ($all_data['acList'] as $line) {
882
+			$reset = 0;
883
+			foreach ($all_data['acList'] as $line) {
884 884
 			$data = array();
885 885
 			$data['hex'] = $line['Icao']; // hex
886 886
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -903,10 +903,10 @@  discard block
 block discarded – undo
903 903
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
904 904
 			if (isset($data['latitude'])) $SI->add($data);
905 905
 			unset($data);
906
-		    }
906
+			}
907 907
 		} elseif (is_array($all_data)) {
908
-		    $reset = 0;
909
-		    foreach ($all_data as $line) {
908
+			$reset = 0;
909
+			foreach ($all_data as $line) {
910 910
 			$data = array();
911 911
 			$data['hex'] = $line['hex']; // hex
912 912
 			$data['ident'] = $line['flight']; // ident
@@ -926,218 +926,218 @@  discard block
 block discarded – undo
926 926
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
927 927
 			$SI->add($data);
928 928
 			unset($data);
929
-		    }
929
+			}
930 930
 		}
931
-	    } elseif ($globalDebug) echo 'No data'."\n";
932
-    	    //$last_exec['aircraftlistjson'] = time();
933
-    	    $last_exec[$id]['last'] = time();
934
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
935
-    	} elseif ($value['format'] == 'planeupdatefaa' && 
936
-    	    (
937
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
938
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
939
-    	    )
940
-    	) {
941
-	    $buffer = $Common->getData($value['host']);
942
-	    $all_data = json_decode($buffer,true);
943
-	    if (isset($all_data['planes'])) {
931
+		} elseif ($globalDebug) echo 'No data'."\n";
932
+			//$last_exec['aircraftlistjson'] = time();
933
+			$last_exec[$id]['last'] = time();
934
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
935
+		} elseif ($value['format'] == 'planeupdatefaa' && 
936
+			(
937
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
938
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
939
+			)
940
+		) {
941
+		$buffer = $Common->getData($value['host']);
942
+		$all_data = json_decode($buffer,true);
943
+		if (isset($all_data['planes'])) {
944 944
 		$reset = 0;
945 945
 		foreach ($all_data['planes'] as $key => $line) {
946
-		    $data = array();
947
-		    $data['hex'] = $key; // hex
948
-		    $data['ident'] = $line[3]; // ident
949
-		    $data['altitude'] = $line[6]; // altitude
950
-		    $data['speed'] = $line[8]; // speed
951
-		    $data['heading'] = $line[7]; // heading
952
-		    $data['latitude'] = $line[4]; // lat
953
-		    $data['longitude'] = $line[5]; // long
954
-		    //$data['verticalrate'] = $line[]; // verticale rate
955
-		    $data['squawk'] = $line[10]; // squawk
956
-		    $data['emergency'] = ''; // emergency
957
-		    $data['registration'] = $line[2];
958
-		    $data['aircraft_icao'] = $line[0];
959
-		    $deparr = explode('-',$line[1]);
960
-		    if (count($deparr) == 2) {
946
+			$data = array();
947
+			$data['hex'] = $key; // hex
948
+			$data['ident'] = $line[3]; // ident
949
+			$data['altitude'] = $line[6]; // altitude
950
+			$data['speed'] = $line[8]; // speed
951
+			$data['heading'] = $line[7]; // heading
952
+			$data['latitude'] = $line[4]; // lat
953
+			$data['longitude'] = $line[5]; // long
954
+			//$data['verticalrate'] = $line[]; // verticale rate
955
+			$data['squawk'] = $line[10]; // squawk
956
+			$data['emergency'] = ''; // emergency
957
+			$data['registration'] = $line[2];
958
+			$data['aircraft_icao'] = $line[0];
959
+			$deparr = explode('-',$line[1]);
960
+			if (count($deparr) == 2) {
961 961
 			$data['departure_airport_icao'] = $deparr[0];
962 962
 			$data['arrival_airport_icao'] = $deparr[1];
963
-		    }
964
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
965
-	    	    $data['format_source'] = 'planeupdatefaa';
966
-    		    $data['id_source'] = $id_source;
967
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
968
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
969
-		    $SI->add($data);
970
-		    unset($data);
963
+			}
964
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
965
+				$data['format_source'] = 'planeupdatefaa';
966
+				$data['id_source'] = $id_source;
967
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
968
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
969
+			$SI->add($data);
970
+			unset($data);
971
+		}
971 972
 		}
972
-	    }
973
-	    //$last_exec['planeupdatefaa'] = time();
974
-	    $last_exec[$id]['last'] = time();
973
+		//$last_exec['planeupdatefaa'] = time();
974
+		$last_exec[$id]['last'] = time();
975 975
 	} elseif ($value['format'] == 'opensky' && 
976
-	    (
976
+		(
977 977
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
978 978
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
979
-	    )
979
+		)
980 980
 	) {
981
-	    $buffer = $Common->getData($value['host']);
982
-	    $all_data = json_decode($buffer,true);
983
-	    if (isset($all_data['states'])) {
981
+		$buffer = $Common->getData($value['host']);
982
+		$all_data = json_decode($buffer,true);
983
+		if (isset($all_data['states'])) {
984 984
 		$reset = 0;
985 985
 		foreach ($all_data['states'] as $key => $line) {
986
-		    $data = array();
987
-		    $data['hex'] = $line[0]; // hex
988
-		    $data['ident'] = trim($line[1]); // ident
989
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
990
-		    $data['speed'] = round($line[9]*1.94384); // speed
991
-		    $data['heading'] = round($line[10]); // heading
992
-		    $data['latitude'] = $line[6]; // lat
993
-		    $data['longitude'] = $line[5]; // long
994
-		    $data['verticalrate'] = $line[11]; // verticale rate
995
-		    //$data['squawk'] = $line[10]; // squawk
996
-		    //$data['emergency'] = ''; // emergency
997
-		    //$data['registration'] = $line[2];
998
-		    //$data['aircraft_icao'] = $line[0];
999
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1000
-		    $data['format_source'] = 'opensky';
1001
-		    $data['id_source'] = $id_source;
1002
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1003
-		    $SI->add($data);
1004
-		    unset($data);
986
+			$data = array();
987
+			$data['hex'] = $line[0]; // hex
988
+			$data['ident'] = trim($line[1]); // ident
989
+			$data['altitude'] = round($line[7]*3.28084); // altitude
990
+			$data['speed'] = round($line[9]*1.94384); // speed
991
+			$data['heading'] = round($line[10]); // heading
992
+			$data['latitude'] = $line[6]; // lat
993
+			$data['longitude'] = $line[5]; // long
994
+			$data['verticalrate'] = $line[11]; // verticale rate
995
+			//$data['squawk'] = $line[10]; // squawk
996
+			//$data['emergency'] = ''; // emergency
997
+			//$data['registration'] = $line[2];
998
+			//$data['aircraft_icao'] = $line[0];
999
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1000
+			$data['format_source'] = 'opensky';
1001
+			$data['id_source'] = $id_source;
1002
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1003
+			$SI->add($data);
1004
+			unset($data);
1005
+		}
1005 1006
 		}
1006
-	    }
1007
-	    //$last_exec['planeupdatefaa'] = time();
1008
-	    $last_exec[$id]['last'] = time();
1007
+		//$last_exec['planeupdatefaa'] = time();
1008
+		$last_exec[$id]['last'] = time();
1009 1009
 	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1010 1010
 	} elseif ($value['format'] == 'fr24json' && 
1011
-	    (
1011
+		(
1012 1012
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1013 1013
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1014
-	    )
1014
+		)
1015 1015
 	) {
1016
-	    //$buffer = $Common->getData($hosts[$id]);
1017
-	    $buffer = $Common->getData($value['host']);
1018
-	    $all_data = json_decode($buffer,true);
1019
-	    if (!empty($all_data)) $reset = 0;
1020
-	    foreach ($all_data as $key => $line) {
1016
+		//$buffer = $Common->getData($hosts[$id]);
1017
+		$buffer = $Common->getData($value['host']);
1018
+		$all_data = json_decode($buffer,true);
1019
+		if (!empty($all_data)) $reset = 0;
1020
+		foreach ($all_data as $key => $line) {
1021 1021
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1022
-		    $data = array();
1023
-		    $data['hex'] = $line[0];
1024
-		    $data['ident'] = $line[16]; //$line[13]
1025
-	    	    $data['altitude'] = $line[4]; // altitude
1026
-	    	    $data['speed'] = $line[5]; // speed
1027
-	    	    $data['heading'] = $line[3]; // heading
1028
-	    	    $data['latitude'] = $line[1]; // lat
1029
-	    	    $data['longitude'] = $line[2]; // long
1030
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1031
-	    	    $data['squawk'] = $line[6]; // squawk
1032
-	    	    $data['aircraft_icao'] = $line[8];
1033
-	    	    $data['registration'] = $line[9];
1034
-		    $data['departure_airport_iata'] = $line[11];
1035
-		    $data['arrival_airport_iata'] = $line[12];
1036
-	    	    $data['emergency'] = ''; // emergency
1037
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1038
-	    	    $data['format_source'] = 'fr24json';
1039
-    		    $data['id_source'] = $id_source;
1040
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1041
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1042
-		    $SI->add($data);
1043
-		    unset($data);
1022
+			$data = array();
1023
+			$data['hex'] = $line[0];
1024
+			$data['ident'] = $line[16]; //$line[13]
1025
+				$data['altitude'] = $line[4]; // altitude
1026
+				$data['speed'] = $line[5]; // speed
1027
+				$data['heading'] = $line[3]; // heading
1028
+				$data['latitude'] = $line[1]; // lat
1029
+				$data['longitude'] = $line[2]; // long
1030
+				$data['verticalrate'] = $line[15]; // verticale rate
1031
+				$data['squawk'] = $line[6]; // squawk
1032
+				$data['aircraft_icao'] = $line[8];
1033
+				$data['registration'] = $line[9];
1034
+			$data['departure_airport_iata'] = $line[11];
1035
+			$data['arrival_airport_iata'] = $line[12];
1036
+				$data['emergency'] = ''; // emergency
1037
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1038
+				$data['format_source'] = 'fr24json';
1039
+				$data['id_source'] = $id_source;
1040
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1041
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1042
+			$SI->add($data);
1043
+			unset($data);
1044 1044
 		}
1045
-	    }
1046
-	    //$last_exec['fr24json'] = time();
1047
-	    $last_exec[$id]['last'] = time();
1045
+		}
1046
+		//$last_exec['fr24json'] = time();
1047
+		$last_exec[$id]['last'] = time();
1048 1048
 	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1049 1049
 	} elseif ($value['format'] == 'radarvirtueljson' && 
1050
-	    (
1050
+		(
1051 1051
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1052 1052
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1053
-	    )
1053
+		)
1054 1054
 	) {
1055
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1056
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1057
-	    //echo $buffer;
1058
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1059
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1060
-	    $all_data = json_decode($buffer,true);
1061
-	    if (json_last_error() != JSON_ERROR_NONE) {
1055
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1056
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1057
+		//echo $buffer;
1058
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1059
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1060
+		$all_data = json_decode($buffer,true);
1061
+		if (json_last_error() != JSON_ERROR_NONE) {
1062 1062
 		die(json_last_error_msg());
1063
-	    }
1064
-	    if (isset($all_data['mrkrs'])) {
1063
+		}
1064
+		if (isset($all_data['mrkrs'])) {
1065 1065
 		$reset = 0;
1066 1066
 		foreach ($all_data['mrkrs'] as $key => $line) {
1067
-		    if (isset($line['inf'])) {
1067
+			if (isset($line['inf'])) {
1068 1068
 			$data = array();
1069 1069
 			$data['hex'] = $line['inf']['ia'];
1070 1070
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1071
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1072
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1073
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1074
-	    		$data['latitude'] = $line['pt'][0]; // lat
1075
-	    		$data['longitude'] = $line['pt'][1]; // long
1076
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1077
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1078
-	    		//$data['aircraft_icao'] = $line[8];
1079
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1071
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1072
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1073
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1074
+				$data['latitude'] = $line['pt'][0]; // lat
1075
+				$data['longitude'] = $line['pt'][1]; // long
1076
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1077
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1078
+				//$data['aircraft_icao'] = $line[8];
1079
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1080 1080
 			//$data['departure_airport_iata'] = $line[11];
1081 1081
 			//$data['arrival_airport_iata'] = $line[12];
1082
-	    		//$data['emergency'] = ''; // emergency
1082
+				//$data['emergency'] = ''; // emergency
1083 1083
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1084
-	    		$data['format_source'] = 'radarvirtueljson';
1085
-    			$data['id_source'] = $id_source;
1084
+				$data['format_source'] = 'radarvirtueljson';
1085
+				$data['id_source'] = $id_source;
1086 1086
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1087 1087
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1088 1088
 			$SI->add($data);
1089 1089
 			unset($data);
1090
-		    }
1090
+			}
1091 1091
 		}
1092
-	    }
1093
-	    //$last_exec['radarvirtueljson'] = time();
1094
-	    $last_exec[$id]['last'] = time();
1092
+		}
1093
+		//$last_exec['radarvirtueljson'] = time();
1094
+		$last_exec[$id]['last'] = time();
1095 1095
 	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1096 1096
 	} elseif ($value['format'] == 'pirepsjson' && 
1097
-	    (
1097
+		(
1098 1098
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1099 1099
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1100
-	    )
1100
+		)
1101 1101
 	) {
1102
-	    //$buffer = $Common->getData($hosts[$id]);
1103
-	    $buffer = $Common->getData($value['host'].'?'.time());
1104
-	    $all_data = json_decode(utf8_encode($buffer),true);
1102
+		//$buffer = $Common->getData($hosts[$id]);
1103
+		$buffer = $Common->getData($value['host'].'?'.time());
1104
+		$all_data = json_decode(utf8_encode($buffer),true);
1105 1105
 	    
1106
-	    if (isset($all_data['pireps'])) {
1106
+		if (isset($all_data['pireps'])) {
1107 1107
 		$reset = 0;
1108
-	        foreach ($all_data['pireps'] as $line) {
1109
-		    $data = array();
1110
-		    $data['id'] = $line['id'];
1111
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1112
-		    $data['ident'] = $line['callsign']; // ident
1113
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1114
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1115
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1116
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1117
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1118
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1119
-		    $data['latitude'] = $line['lat']; // lat
1120
-		    $data['longitude'] = $line['lon']; // long
1121
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1122
-		    //$data['squawk'] = $line['squawk']; // squawk
1123
-		    //$data['emergency'] = ''; // emergency
1124
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1125
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1126
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1127
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1128
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1129
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1130
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1131
-		    else $data['info'] = '';
1132
-		    $data['format_source'] = 'pireps';
1133
-    		    $data['id_source'] = $id_source;
1134
-		    $data['datetime'] = date('Y-m-d H:i:s');
1135
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1136
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1137
-		    if ($line['icon'] == 'plane') {
1108
+			foreach ($all_data['pireps'] as $line) {
1109
+			$data = array();
1110
+			$data['id'] = $line['id'];
1111
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1112
+			$data['ident'] = $line['callsign']; // ident
1113
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1114
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1115
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1116
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1117
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1118
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1119
+			$data['latitude'] = $line['lat']; // lat
1120
+			$data['longitude'] = $line['lon']; // long
1121
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1122
+			//$data['squawk'] = $line['squawk']; // squawk
1123
+			//$data['emergency'] = ''; // emergency
1124
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1125
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1126
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1127
+			//$data['arrival_airport_time'] = $line['arrtime'];
1128
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1129
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1130
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1131
+			else $data['info'] = '';
1132
+			$data['format_source'] = 'pireps';
1133
+				$data['id_source'] = $id_source;
1134
+			$data['datetime'] = date('Y-m-d H:i:s');
1135
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1136
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1137
+			if ($line['icon'] == 'plane') {
1138 1138
 			$SI->add($data);
1139
-		    //    print_r($data);
1140
-    		    } elseif ($line['icon'] == 'ct') {
1139
+			//    print_r($data);
1140
+				} elseif ($line['icon'] == 'ct') {
1141 1141
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1142 1142
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1143 1143
 			$typec = substr($data['ident'],-3);
@@ -1152,209 +1152,209 @@  discard block
 block discarded – undo
1152 1152
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1153 1153
 			else $data['type'] = 'Observer';
1154 1154
 			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']);
1155
-		    }
1156
-		    unset($data);
1155
+			}
1156
+			unset($data);
1157
+		}
1157 1158
 		}
1158
-	    }
1159
-	    //$last_exec['pirepsjson'] = time();
1160
-	    $last_exec[$id]['last'] = time();
1159
+		//$last_exec['pirepsjson'] = time();
1160
+		$last_exec[$id]['last'] = time();
1161 1161
 	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1162 1162
 	} elseif ($value['format'] == 'phpvmacars' && 
1163
-	    (
1163
+		(
1164 1164
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1165 1165
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1166
-	    )
1166
+		)
1167 1167
 	) {
1168
-	    //$buffer = $Common->getData($hosts[$id]);
1169
-	    if ($globalDebug) echo 'Get Data...'."\n";
1170
-	    $buffer = $Common->getData($value['host']);
1171
-	    $all_data = json_decode($buffer,true);
1172
-	    if ($buffer != '' && is_array($all_data)) {
1168
+		//$buffer = $Common->getData($hosts[$id]);
1169
+		if ($globalDebug) echo 'Get Data...'."\n";
1170
+		$buffer = $Common->getData($value['host']);
1171
+		$all_data = json_decode($buffer,true);
1172
+		if ($buffer != '' && is_array($all_data)) {
1173 1173
 		$reset = 0;
1174 1174
 		foreach ($all_data as $line) {
1175
-	    	    $data = array();
1176
-	    	    //$data['id'] = $line['id']; // id not usable
1177
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1178
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1179
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1180
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1181
-	    	    $data['ident'] = $line['flightnum']; // ident
1182
-	    	    $data['altitude'] = $line['alt']; // altitude
1183
-	    	    $data['speed'] = $line['gs']; // speed
1184
-	    	    $data['heading'] = $line['heading']; // heading
1185
-	    	    $data['latitude'] = $line['lat']; // lat
1186
-	    	    $data['longitude'] = $line['lng']; // long
1187
-	    	    $data['verticalrate'] = ''; // verticale rate
1188
-	    	    $data['squawk'] = ''; // squawk
1189
-	    	    $data['emergency'] = ''; // emergency
1190
-	    	    //$data['datetime'] = $line['lastupdate'];
1191
-	    	    //$data['last_update'] = $line['lastupdate'];
1192
-	    	    if (isset($value['timezone'])) {
1193
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1194
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1195
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1196
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1197
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1198
-	    	    $data['departure_airport_time'] = $line['deptime'];
1199
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1200
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1201
-    		    if (isset($line['registration'])) {
1202
-    			$data['registration'] = $line['registration'];
1203
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1204
-    		    } else $data['registration'] = $line['aircraft'];
1205
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1206
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1207
-		    if (isset($line['aircraftname'])) {
1175
+				$data = array();
1176
+				//$data['id'] = $line['id']; // id not usable
1177
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1178
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1179
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1180
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1181
+				$data['ident'] = $line['flightnum']; // ident
1182
+				$data['altitude'] = $line['alt']; // altitude
1183
+				$data['speed'] = $line['gs']; // speed
1184
+				$data['heading'] = $line['heading']; // heading
1185
+				$data['latitude'] = $line['lat']; // lat
1186
+				$data['longitude'] = $line['lng']; // long
1187
+				$data['verticalrate'] = ''; // verticale rate
1188
+				$data['squawk'] = ''; // squawk
1189
+				$data['emergency'] = ''; // emergency
1190
+				//$data['datetime'] = $line['lastupdate'];
1191
+				//$data['last_update'] = $line['lastupdate'];
1192
+				if (isset($value['timezone'])) {
1193
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1194
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1195
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1196
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1197
+				$data['departure_airport_icao'] = $line['depicao'];
1198
+				$data['departure_airport_time'] = $line['deptime'];
1199
+				$data['arrival_airport_icao'] = $line['arricao'];
1200
+				$data['arrival_airport_time'] = $line['arrtime'];
1201
+				if (isset($line['registration'])) {
1202
+				$data['registration'] = $line['registration'];
1203
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1204
+				} else $data['registration'] = $line['aircraft'];
1205
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1206
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1207
+			if (isset($line['aircraftname'])) {
1208 1208
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1209 1209
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1210
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1211
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1212
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1213
-	    		else {
1214
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1215
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1216
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1217
-	    		}
1218
-	    	    }
1219
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1220
-    		    $data['id_source'] = $id_source;
1221
-	    	    $data['format_source'] = 'phpvmacars';
1222
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1223
-		    $SI->add($data);
1224
-		    unset($data);
1210
+				$aircraft_data = explode('-',$line['aircraftname']);
1211
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1212
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1213
+				else {
1214
+					$aircraft_data = explode(' ',$line['aircraftname']);
1215
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1216
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1217
+				}
1218
+				}
1219
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1220
+				$data['id_source'] = $id_source;
1221
+				$data['format_source'] = 'phpvmacars';
1222
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1223
+			$SI->add($data);
1224
+			unset($data);
1225 1225
 		}
1226 1226
 		if ($globalDebug) echo 'No more data...'."\n";
1227 1227
 		unset($buffer);
1228 1228
 		unset($all_data);
1229
-	    }
1230
-	    //$last_exec['phpvmacars'] = time();
1231
-	    $last_exec[$id]['last'] = time();
1229
+		}
1230
+		//$last_exec['phpvmacars'] = time();
1231
+		$last_exec[$id]['last'] = time();
1232 1232
 	} elseif ($value['format'] == 'vaos' && 
1233
-	    (
1233
+		(
1234 1234
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1235 1235
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1236
-	    )
1236
+		)
1237 1237
 	) {
1238
-	    //$buffer = $Common->getData($hosts[$id]);
1239
-	    if ($globalDebug) echo 'Get Data...'."\n";
1240
-	    $buffer = $Common->getData($value['host']);
1241
-	    $all_data = json_decode($buffer,true);
1242
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1238
+		//$buffer = $Common->getData($hosts[$id]);
1239
+		if ($globalDebug) echo 'Get Data...'."\n";
1240
+		$buffer = $Common->getData($value['host']);
1241
+		$all_data = json_decode($buffer,true);
1242
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1243 1243
 		$reset = 0;
1244 1244
 		foreach ($all_data['ACARSData'] as $line) {
1245
-		    //print_r($line);
1246
-	    	    $data = array();
1247
-	    	    //$data['id'] = $line['id']; // id not usable
1248
-	    	    $data['id'] = $line['id'];
1249
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1250
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1251
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1252
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1253
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1254
-	    	    $data['altitude'] = $line['altitude']; // altitude
1255
-	    	    $data['speed'] = $line['groundspeed']; // speed
1256
-	    	    $data['heading'] = $line['heading']; // heading
1257
-	    	    $data['latitude'] = $line['lat']; // lat
1258
-	    	    $data['longitude'] = $line['lon']; // long
1259
-	    	    //$data['verticalrate'] = ''; // verticale rate
1260
-	    	    //$data['squawk'] = ''; // squawk
1261
-	    	    //$data['emergency'] = ''; // emergency
1262
-	    	    if (isset($value['timezone'])) {
1263
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1264
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1265
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1266
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1245
+			//print_r($line);
1246
+				$data = array();
1247
+				//$data['id'] = $line['id']; // id not usable
1248
+				$data['id'] = $line['id'];
1249
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1250
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1251
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1252
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1253
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1254
+				$data['altitude'] = $line['altitude']; // altitude
1255
+				$data['speed'] = $line['groundspeed']; // speed
1256
+				$data['heading'] = $line['heading']; // heading
1257
+				$data['latitude'] = $line['lat']; // lat
1258
+				$data['longitude'] = $line['lon']; // long
1259
+				//$data['verticalrate'] = ''; // verticale rate
1260
+				//$data['squawk'] = ''; // squawk
1261
+				//$data['emergency'] = ''; // emergency
1262
+				if (isset($value['timezone'])) {
1263
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1264
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1265
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1266
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1267 1267
 	    	    
1268
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1269
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1270
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1271
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1272
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1268
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1269
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1270
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1271
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1272
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1273 1273
 
1274
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1275
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1276
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1274
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1275
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1276
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1277 1277
 
1278
-    		    $data['id_source'] = $id_source;
1279
-	    	    $data['format_source'] = 'vaos';
1280
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1281
-		    $SI->add($data);
1282
-		    unset($data);
1278
+				$data['id_source'] = $id_source;
1279
+				$data['format_source'] = 'vaos';
1280
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1281
+			$SI->add($data);
1282
+			unset($data);
1283 1283
 		}
1284 1284
 		if ($globalDebug) echo 'No more data...'."\n";
1285 1285
 		unset($buffer);
1286 1286
 		unset($all_data);
1287
-	    }
1288
-	    //$last_exec['phpvmacars'] = time();
1289
-	    $last_exec[$id]['last'] = time();
1287
+		}
1288
+		//$last_exec['phpvmacars'] = time();
1289
+		$last_exec[$id]['last'] = time();
1290 1290
 	} elseif ($value['format'] == 'vam' && 
1291
-	    (
1291
+		(
1292 1292
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1293 1293
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1294
-	    )
1294
+		)
1295 1295
 	) {
1296
-	    //$buffer = $Common->getData($hosts[$id]);
1297
-	    if ($globalDebug) echo 'Get Data...'."\n";
1298
-	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1300
-	    if ($buffer != '' && is_array($all_data)) {
1296
+		//$buffer = $Common->getData($hosts[$id]);
1297
+		if ($globalDebug) echo 'Get Data...'."\n";
1298
+		$buffer = $Common->getData($value['host']);
1299
+		$all_data = json_decode($buffer,true);
1300
+		if ($buffer != '' && is_array($all_data)) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data as $line) {
1303
-	    	    $data = array();
1304
-	    	    //$data['id'] = $line['id']; // id not usable
1305
-	    	    $data['id'] = trim($line['flight_id']);
1306
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1307
-	    	    $data['pilot_name'] = $line['pilot_name'];
1308
-	    	    $data['pilot_id'] = $line['pilot_id'];
1309
-	    	    $data['ident'] = trim($line['callsign']); // ident
1310
-	    	    $data['altitude'] = $line['altitude']; // altitude
1311
-	    	    $data['speed'] = $line['gs']; // speed
1312
-	    	    $data['heading'] = $line['heading']; // heading
1313
-	    	    $data['latitude'] = $line['latitude']; // lat
1314
-	    	    $data['longitude'] = $line['longitude']; // long
1315
-	    	    $data['verticalrate'] = ''; // verticale rate
1316
-	    	    $data['squawk'] = ''; // squawk
1317
-	    	    $data['emergency'] = ''; // emergency
1318
-	    	    //$data['datetime'] = $line['lastupdate'];
1319
-	    	    $data['last_update'] = $line['last_update'];
1320
-		    $data['datetime'] = date('Y-m-d H:i:s');
1321
-	    	    $data['departure_airport_icao'] = $line['departure'];
1322
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1323
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1324
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1325
-    		    //$data['registration'] = $line['aircraft'];
1326
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1327
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1328
-    		    $data['id_source'] = $id_source;
1329
-	    	    $data['format_source'] = 'vam';
1330
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1331
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1332
-		    $SI->add($data);
1333
-		    unset($data);
1303
+				$data = array();
1304
+				//$data['id'] = $line['id']; // id not usable
1305
+				$data['id'] = trim($line['flight_id']);
1306
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1307
+				$data['pilot_name'] = $line['pilot_name'];
1308
+				$data['pilot_id'] = $line['pilot_id'];
1309
+				$data['ident'] = trim($line['callsign']); // ident
1310
+				$data['altitude'] = $line['altitude']; // altitude
1311
+				$data['speed'] = $line['gs']; // speed
1312
+				$data['heading'] = $line['heading']; // heading
1313
+				$data['latitude'] = $line['latitude']; // lat
1314
+				$data['longitude'] = $line['longitude']; // long
1315
+				$data['verticalrate'] = ''; // verticale rate
1316
+				$data['squawk'] = ''; // squawk
1317
+				$data['emergency'] = ''; // emergency
1318
+				//$data['datetime'] = $line['lastupdate'];
1319
+				$data['last_update'] = $line['last_update'];
1320
+			$data['datetime'] = date('Y-m-d H:i:s');
1321
+				$data['departure_airport_icao'] = $line['departure'];
1322
+				//$data['departure_airport_time'] = $line['departure_time'];
1323
+				$data['arrival_airport_icao'] = $line['arrival'];
1324
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1325
+				//$data['registration'] = $line['aircraft'];
1326
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1327
+				$data['aircraft_icao'] = $line['plane_type'];
1328
+				$data['id_source'] = $id_source;
1329
+				$data['format_source'] = 'vam';
1330
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1331
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1332
+			$SI->add($data);
1333
+			unset($data);
1334 1334
 		}
1335 1335
 		if ($globalDebug) echo 'No more data...'."\n";
1336 1336
 		unset($buffer);
1337 1337
 		unset($all_data);
1338
-	    }
1339
-	    //$last_exec['phpvmacars'] = time();
1340
-	    $last_exec[$id]['last'] = time();
1338
+		}
1339
+		//$last_exec['phpvmacars'] = time();
1340
+		$last_exec[$id]['last'] = time();
1341 1341
 	} elseif ($value['format'] == 'blitzortung' && 
1342
-	    (
1342
+		(
1343 1343
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1344 1344
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1345
-	    )
1345
+		)
1346 1346
 	) {
1347
-	    //$buffer = $Common->getData($hosts[$id]);
1348
-	    if ($globalDebug) echo 'Get Data...'."\n";
1349
-	    $buffer = $Common->getData($value['host']);
1350
-	    $all_data = json_decode($buffer,true);
1351
-	    if ($buffer != '') {
1347
+		//$buffer = $Common->getData($hosts[$id]);
1348
+		if ($globalDebug) echo 'Get Data...'."\n";
1349
+		$buffer = $Common->getData($value['host']);
1350
+		$all_data = json_decode($buffer,true);
1351
+		if ($buffer != '') {
1352 1352
 		$Source->deleteLocationBySource('blitzortung');
1353 1353
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1354 1354
 		$buffer = explode('\n',$buffer);
1355 1355
 		foreach ($buffer as $buffer_line) {
1356
-		    $line = json_decode($buffer_line,true);
1357
-		    if (isset($line['time'])) {
1356
+			$line = json_decode($buffer_line,true);
1357
+			if (isset($line['time'])) {
1358 1358
 			$data = array();
1359 1359
 			$data['altitude'] = $line['alt']; // altitude
1360 1360
 			$data['latitude'] = $line['lat']; // lat
@@ -1366,96 +1366,96 @@  discard block
 block discarded – undo
1366 1366
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1367 1367
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1368 1368
 			unset($data);
1369
-		    }
1369
+			}
1370 1370
 		}
1371 1371
 		if ($globalDebug) echo 'No more data...'."\n";
1372 1372
 		unset($buffer);
1373
-	    }
1374
-	    $last_exec[$id]['last'] = time();
1373
+		}
1374
+		$last_exec[$id]['last'] = time();
1375 1375
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1376 1376
 	} 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') {
1377
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1378
-    	    //$last_exec[$id]['last'] = time();
1377
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1378
+			//$last_exec[$id]['last'] = time();
1379 1379
 
1380
-	    //$read = array( $sockets[$id] );
1381
-	    $read = $sockets;
1382
-	    $write = NULL;
1383
-	    $e = NULL;
1384
-	    $n = socket_select($read, $write, $e, $timeout);
1385
-	    if ($e != NULL) var_dump($e);
1386
-	    if ($n > 0) {
1380
+		//$read = array( $sockets[$id] );
1381
+		$read = $sockets;
1382
+		$write = NULL;
1383
+		$e = NULL;
1384
+		$n = socket_select($read, $write, $e, $timeout);
1385
+		if ($e != NULL) var_dump($e);
1386
+		if ($n > 0) {
1387 1387
 		$reset = 0;
1388 1388
 		foreach ($read as $nb => $r) {
1389
-		    //$value = $formats[$nb];
1390
-		    $format = $globalSources[$nb]['format'];
1391
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1389
+			//$value = $formats[$nb];
1390
+			$format = $globalSources[$nb]['format'];
1391
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1392 1392
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1393
-		    } elseif ($format == 'vrstcp') {
1393
+			} elseif ($format == 'vrstcp') {
1394 1394
 			$buffer = @socket_read($r, 6000);
1395
-		    } else {
1395
+			} else {
1396 1396
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1397
-		    }
1398
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1399
-		    //echo $buffer."\n";
1400
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1401
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1402
-		    $error = false;
1403
-		    //$SI::del();
1404
-		    if ($buffer !== FALSE) {
1397
+			}
1398
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1399
+			//echo $buffer."\n";
1400
+			// lets play nice and handle signals such as ctrl-c/kill properly
1401
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1402
+			$error = false;
1403
+			//$SI::del();
1404
+			if ($buffer !== FALSE) {
1405 1405
 			if ($format == 'vrstcp') {
1406
-			    $buffer = explode('},{',$buffer);
1406
+				$buffer = explode('},{',$buffer);
1407 1407
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1408
-		    }
1409
-		    // SBS format is CSV format
1410
-		    if ($buffer !== FALSE && $buffer !== '') {
1408
+			}
1409
+			// SBS format is CSV format
1410
+			if ($buffer !== FALSE && $buffer !== '') {
1411 1411
 			$tt[$format] = 0;
1412 1412
 			if ($format == 'acarssbs3') {
1413
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1414
-			    $ACARS->add(trim($buffer));
1415
-			    $ACARS->deleteLiveAcarsData();
1413
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1414
+				$ACARS->add(trim($buffer));
1415
+				$ACARS->deleteLiveAcarsData();
1416 1416
 			} elseif ($format == 'raw') {
1417
-			    // AVR format
1418
-			    $data = $SBS->parse($buffer);
1419
-			    if (is_array($data)) {
1417
+				// AVR format
1418
+				$data = $SBS->parse($buffer);
1419
+				if (is_array($data)) {
1420 1420
 				$data['datetime'] = date('Y-m-d H:i:s');
1421 1421
 				$data['format_source'] = 'raw';
1422 1422
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1423 1423
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1424 1424
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1425 1425
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1426
-			    }
1426
+				}
1427 1427
 			} elseif ($format == 'ais') {
1428
-			    $ais_data = $AIS->parse_line(trim($buffer));
1429
-			    $data = array();
1430
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1431
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1432
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1433
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1434
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1435
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1436
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1437
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1438
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1439
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1440
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1441
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1442
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1443
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1445
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1428
+				$ais_data = $AIS->parse_line(trim($buffer));
1429
+				$data = array();
1430
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1431
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1432
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1433
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1434
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1435
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1436
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1437
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1438
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1439
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1440
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1441
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1442
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1443
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1445
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1446 1446
 
1447
-			    if (isset($ais_data['timestamp'])) {
1447
+				if (isset($ais_data['timestamp'])) {
1448 1448
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1449
-			    } else {
1449
+				} else {
1450 1450
 				$data['datetime'] = date('Y-m-d H:i:s');
1451
-			    }
1452
-			    $data['format_source'] = 'aisnmea';
1453
-    			    $data['id_source'] = $id_source;
1454
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1455
-			    unset($data);
1456
-                        } elseif ($format == 'flightgearsp') {
1457
-                    	    //echo $buffer."\n";
1458
-                    	    if (strlen($buffer) > 5) {
1451
+				}
1452
+				$data['format_source'] = 'aisnmea';
1453
+					$data['id_source'] = $id_source;
1454
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1455
+				unset($data);
1456
+						} elseif ($format == 'flightgearsp') {
1457
+							//echo $buffer."\n";
1458
+							if (strlen($buffer) > 5) {
1459 1459
 				$line = explode(',',$buffer);
1460 1460
 				$data = array();
1461 1461
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1472,38 +1472,38 @@  discard block
 block discarded – undo
1472 1472
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1473 1473
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1474 1474
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1475
-			    }
1476
-                        } elseif ($format == 'acars') {
1477
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1478
-			    $ACARS->add(trim($buffer));
1479
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1480
-			    $ACARS->deleteLiveAcarsData();
1475
+				}
1476
+						} elseif ($format == 'acars') {
1477
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1478
+				$ACARS->add(trim($buffer));
1479
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1480
+				$ACARS->deleteLiveAcarsData();
1481 1481
 			} elseif ($format == 'flightgearmp') {
1482
-			    if (substr($buffer,0,1) != '#') {
1482
+				if (substr($buffer,0,1) != '#') {
1483 1483
 				$data = array();
1484 1484
 				//echo $buffer."\n";
1485 1485
 				$line = explode(' ',$buffer);
1486 1486
 				if (count($line) == 11) {
1487
-				    $userserver = explode('@',$line[0]);
1488
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1489
-				    $data['ident'] = $userserver[0];
1490
-				    $data['registration'] = $userserver[0];
1491
-				    $data['latitude'] = $line[4];
1492
-				    $data['longitude'] = $line[5];
1493
-				    $data['altitude'] = $line[6];
1494
-				    $data['datetime'] = date('Y-m-d H:i:s');
1495
-				    $aircraft_type = $line[10];
1496
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1497
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1498
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1499
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1487
+					$userserver = explode('@',$line[0]);
1488
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1489
+					$data['ident'] = $userserver[0];
1490
+					$data['registration'] = $userserver[0];
1491
+					$data['latitude'] = $line[4];
1492
+					$data['longitude'] = $line[5];
1493
+					$data['altitude'] = $line[6];
1494
+					$data['datetime'] = date('Y-m-d H:i:s');
1495
+					$aircraft_type = $line[10];
1496
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1497
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1498
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1499
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1500
+				}
1500 1501
 				}
1501
-			    }
1502 1502
 			} elseif ($format == 'beast') {
1503
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1504
-			    die;
1503
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1504
+				die;
1505 1505
 			} elseif ($format == 'vrstcp') {
1506
-			    foreach($buffer as $all_data) {
1506
+				foreach($buffer as $all_data) {
1507 1507
 				$line = json_decode('{'.$all_data.'}',true);
1508 1508
 				$data = array();
1509 1509
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1523,153 +1523,153 @@  discard block
 block discarded – undo
1523 1523
 				*/
1524 1524
 				$data['datetime'] = date('Y-m-d H:i:s');
1525 1525
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1526
-		    		$data['format_source'] = 'vrstcp';
1526
+					$data['format_source'] = 'vrstcp';
1527 1527
 				$data['id_source'] = $id_source;
1528 1528
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1529 1529
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1530 1530
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1531 1531
 				unset($data);
1532
-			    }
1532
+				}
1533 1533
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1534
-			    $line = explode("\t", $buffer);
1535
-			    for($k = 0; $k < count($line); $k=$k+2) {
1534
+				$line = explode("\t", $buffer);
1535
+				for($k = 0; $k < count($line); $k=$k+2) {
1536 1536
 				$key = $line[$k];
1537
-			        $lined[$key] = $line[$k+1];
1538
-			    }
1539
-    			    if (count($lined) > 3) {
1540
-    				$data['hex'] = $lined['hexid'];
1541
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1542
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1543
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1544
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1545
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1546
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1547
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1548
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1549
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1550
-    				$data['id_source'] = $id_source;
1551
-    				$data['format_source'] = 'tsv';
1552
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1553
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1537
+					$lined[$key] = $line[$k+1];
1538
+				}
1539
+					if (count($lined) > 3) {
1540
+					$data['hex'] = $lined['hexid'];
1541
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1542
+					$data['datetime'] = date('Y-m-d H:i:s');;
1543
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1544
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1545
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1546
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1547
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1548
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1549
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1550
+					$data['id_source'] = $id_source;
1551
+					$data['format_source'] = 'tsv';
1552
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1553
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1554 1554
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1555
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1556
-    				unset($lined);
1557
-    				unset($data);
1558
-    			    } else $error = true;
1555
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1556
+					unset($lined);
1557
+					unset($data);
1558
+					} else $error = true;
1559 1559
 			} elseif ($format == 'aprs' && $use_aprs) {
1560
-			    if ($aprs_connect == 0) {
1560
+				if ($aprs_connect == 0) {
1561 1561
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1562 1562
 				$aprs_connect = 1;
1563
-			    }
1563
+				}
1564 1564
 			    
1565
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1565
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1566 1566
 				$aprs_last_tx = time();
1567 1567
 				$data_aprs = "# Keep alive";
1568 1568
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1569
-			    }
1569
+				}
1570 1570
 			    
1571
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1572
-			    //echo 'APRS data : '.$buffer."\n";
1573
-			    $buffer = str_replace('APRS <- ','',$buffer);
1574
-			    $buffer = str_replace('APRS -> ','',$buffer);
1575
-			    //echo $buffer."\n";
1576
-			    date_default_timezone_set('UTC');
1577
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1571
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1572
+				//echo 'APRS data : '.$buffer."\n";
1573
+				$buffer = str_replace('APRS <- ','',$buffer);
1574
+				$buffer = str_replace('APRS -> ','',$buffer);
1575
+				//echo $buffer."\n";
1576
+				date_default_timezone_set('UTC');
1577
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1578 1578
 				$line = $APRS->parse($buffer);
1579 1579
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1580 1580
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1581
-				    $aprs_last_tx = time();
1582
-				    $data = array();
1583
-				    //print_r($line);
1584
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1585
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1586
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1587
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1588
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1589
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1590
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1591
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1592
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1593
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1594
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1595
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1596
-				    $data['latitude'] = $line['latitude'];
1597
-				    $data['longitude'] = $line['longitude'];
1598
-				    //$data['verticalrate'] = $line[16];
1599
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1600
-				    //else $data['speed'] = 0;
1601
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1602
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1603
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1604
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1581
+					$aprs_last_tx = time();
1582
+					$data = array();
1583
+					//print_r($line);
1584
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1585
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1586
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1587
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1588
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1589
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1590
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1591
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1592
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1593
+					else $data['datetime'] = date('Y-m-d H:i:s');
1594
+					//$data['datetime'] = date('Y-m-d H:i:s');
1595
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1596
+					$data['latitude'] = $line['latitude'];
1597
+					$data['longitude'] = $line['longitude'];
1598
+					//$data['verticalrate'] = $line[16];
1599
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1600
+					//else $data['speed'] = 0;
1601
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1602
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1603
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1604
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1605 1605
 				    
1606
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1607
-				    //else echo 'No heading...'."\n";
1608
-				    //else $data['heading'] = 0;
1609
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1610
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1611
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1612
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1613
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1614
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1615
-    				    $data['id_source'] = $id_source;
1616
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1617
-				    else $data['format_source'] = 'aprs';
1618
-				    $data['source_name'] = $line['source'];
1619
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1620
-				    else $data['source_type'] = 'flarm';
1621
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1622
-				    $currentdate = date('Y-m-d H:i:s');
1623
-				    $aprsdate = strtotime($data['datetime']);
1624
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1625
-				    // Accept data if time <= system time + 20s
1626
-				    //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'])))) {
1627
-				    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'])))) {
1606
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1607
+					//else echo 'No heading...'."\n";
1608
+					//else $data['heading'] = 0;
1609
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1610
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1611
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1612
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1613
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1614
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1615
+						$data['id_source'] = $id_source;
1616
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1617
+					else $data['format_source'] = 'aprs';
1618
+					$data['source_name'] = $line['source'];
1619
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1620
+					else $data['source_type'] = 'flarm';
1621
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1622
+					$currentdate = date('Y-m-d H:i:s');
1623
+					$aprsdate = strtotime($data['datetime']);
1624
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1625
+					// Accept data if time <= system time + 20s
1626
+					//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'])))) {
1627
+					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'])))) {
1628 1628
 					$send = $SI->add($data);
1629
-				    } elseif ($data['source_type'] == 'ais') {
1629
+					} elseif ($data['source_type'] == 'ais') {
1630 1630
 					$data['type'] = '';
1631 1631
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1632
-				    } elseif (isset($line['stealth'])) {
1632
+					} elseif (isset($line['stealth'])) {
1633 1633
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1634 1634
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1635
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1636
-					    //$line['symbol'] == 'Balloon' ||
1637
-					    $line['symbol'] == 'Glider' || 
1638
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1639
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1640
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1641
-					    $send = $SI->add($data);
1642
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1643
-					    $line['symbol'] == 'Yacht (Sail)' || 
1644
-					    $line['symbol'] == 'Ship (Power Boat)')) {
1645
-					    $send = $MI->add($data);
1646
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1647
-					    $line['symbol'] == 'Car' || 
1648
-					    $line['symbol'] == 'Ambulance' || 
1649
-					    $line['symbol'] == 'Van' || 
1650
-					    $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1651
-					    $line['symbol'] == 'Motorcycle' || 
1652
-					    $line['symbol'] == 'Tractor' || 
1653
-					    $line['symbol'] == 'Police' || 
1654
-					    $line['symbol'] == 'Bike' || 
1655
-					    $line['symbol'] == 'Jogger' || 
1656
-					    $line['symbol'] == 'Horse' || 
1657
-					    $line['symbol'] == 'Bus' || 
1658
-					    $line['symbol'] == 'Jeep' || 
1659
-					    $line['symbol'] == 'Recreational Vehicle' || 
1660
-					    $line['symbol'] == 'Yacht (Sail)' || 
1661
-					    $line['symbol'] == 'Ship (Power Boat)' || 
1662
-					    $line['symbol'] == 'Firetruck' || 
1663
-					    $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1664
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1665
-					    $line['symbol'] == 'SUV' ||
1666
-					    $line['symbol'] == 'Snowmobile' ||
1667
-					    $line['symbol'] == 'Mobile Satellite Station')) {
1668
-				    //} 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') {
1635
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1636
+						//$line['symbol'] == 'Balloon' ||
1637
+						$line['symbol'] == 'Glider' || 
1638
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1639
+						if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1640
+						if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1641
+						$send = $SI->add($data);
1642
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1643
+						$line['symbol'] == 'Yacht (Sail)' || 
1644
+						$line['symbol'] == 'Ship (Power Boat)')) {
1645
+						$send = $MI->add($data);
1646
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1647
+						$line['symbol'] == 'Car' || 
1648
+						$line['symbol'] == 'Ambulance' || 
1649
+						$line['symbol'] == 'Van' || 
1650
+						$line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1651
+						$line['symbol'] == 'Motorcycle' || 
1652
+						$line['symbol'] == 'Tractor' || 
1653
+						$line['symbol'] == 'Police' || 
1654
+						$line['symbol'] == 'Bike' || 
1655
+						$line['symbol'] == 'Jogger' || 
1656
+						$line['symbol'] == 'Horse' || 
1657
+						$line['symbol'] == 'Bus' || 
1658
+						$line['symbol'] == 'Jeep' || 
1659
+						$line['symbol'] == 'Recreational Vehicle' || 
1660
+						$line['symbol'] == 'Yacht (Sail)' || 
1661
+						$line['symbol'] == 'Ship (Power Boat)' || 
1662
+						$line['symbol'] == 'Firetruck' || 
1663
+						$line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1664
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1665
+						$line['symbol'] == 'SUV' ||
1666
+						$line['symbol'] == 'Snowmobile' ||
1667
+						$line['symbol'] == 'Mobile Satellite Station')) {
1668
+					//} 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') {
1669 1669
 				//    } 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') {
1670 1670
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1671 1671
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1672
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1672
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1673 1673
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1674 1674
 					$Source->deleteOldLocationByType('gs');
1675 1675
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1677,7 +1677,7 @@  discard block
 block discarded – undo
1677 1677
 					} else {
1678 1678
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1679 1679
 					}
1680
-				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1680
+					} elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1681 1681
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1682 1682
 					if ($globalDebug) echo '# Weather Station added'."\n";
1683 1683
 					$Source->deleteOldLocationByType('wx');
@@ -1687,7 +1687,7 @@  discard block
 block discarded – undo
1687 1687
 					} else {
1688 1688
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1689 1689
 					}
1690
-				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1690
+					} elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1691 1691
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1692 1692
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1693 1693
 					$Source->deleteOldLocationByType('lightning');
@@ -1696,11 +1696,11 @@  discard block
 block discarded – undo
1696 1696
 					} else {
1697 1697
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1698 1698
 					}
1699
-				    } elseif ($globalDebug) {
1700
-				    	echo '/!\ Not added: '.$buffer."\n";
1701
-				    	print_r($line);
1702
-				    }
1703
-				    unset($data);
1699
+					} elseif ($globalDebug) {
1700
+						echo '/!\ Not added: '.$buffer."\n";
1701
+						print_r($line);
1702
+					}
1703
+					unset($data);
1704 1704
 				}
1705 1705
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1706 1706
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1719,12 +1719,12 @@  discard block
 block discarded – undo
1719 1719
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1720 1720
 					$globalSources[$nb]['last_weather_clean'] = time();
1721 1721
 				}
1722
-			    }
1722
+				}
1723 1723
 			} else {
1724
-			    $line = explode(',', $buffer);
1725
-    			    if (count($line) > 20) {
1726
-    			    	$data['hex'] = $line[4];
1727
-    				/*
1724
+				$line = explode(',', $buffer);
1725
+					if (count($line) > 20) {
1726
+						$data['hex'] = $line[4];
1727
+					/*
1728 1728
     				$data['datetime'] = $line[6].' '.$line[7];
1729 1729
     					date_default_timezone_set($globalTimezone);
1730 1730
     					$datetime = new DateTime($data['datetime']);
@@ -1732,30 +1732,30 @@  discard block
 block discarded – undo
1732 1732
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1733 1733
     					date_default_timezone_set('UTC');
1734 1734
     				*/
1735
-    				// Force datetime to current UTC datetime
1736
-    				date_default_timezone_set('UTC');
1737
-    				$data['datetime'] = date('Y-m-d H:i:s');
1738
-    				$data['ident'] = trim($line[10]);
1739
-    				$data['latitude'] = $line[14];
1740
-    				$data['longitude'] = $line[15];
1741
-    				$data['verticalrate'] = $line[16];
1742
-    				$data['emergency'] = $line[20];
1743
-    				$data['speed'] = $line[12];
1744
-    				$data['squawk'] = $line[17];
1745
-    				$data['altitude'] = $line[11];
1746
-    				$data['heading'] = $line[13];
1747
-    				$data['ground'] = $line[21];
1748
-    				$data['emergency'] = $line[19];
1749
-    				$data['format_source'] = 'sbs';
1735
+					// Force datetime to current UTC datetime
1736
+					date_default_timezone_set('UTC');
1737
+					$data['datetime'] = date('Y-m-d H:i:s');
1738
+					$data['ident'] = trim($line[10]);
1739
+					$data['latitude'] = $line[14];
1740
+					$data['longitude'] = $line[15];
1741
+					$data['verticalrate'] = $line[16];
1742
+					$data['emergency'] = $line[20];
1743
+					$data['speed'] = $line[12];
1744
+					$data['squawk'] = $line[17];
1745
+					$data['altitude'] = $line[11];
1746
+					$data['heading'] = $line[13];
1747
+					$data['ground'] = $line[21];
1748
+					$data['emergency'] = $line[19];
1749
+					$data['format_source'] = 'sbs';
1750 1750
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1751
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1751
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1752 1752
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1753
-    				$data['id_source'] = $id_source;
1754
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1755
-    				else $error = true;
1756
-    				unset($data);
1757
-    			    } else $error = true;
1758
-			    if ($error) {
1753
+					$data['id_source'] = $id_source;
1754
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1755
+					else $error = true;
1756
+					unset($data);
1757
+					} else $error = true;
1758
+				if ($error) {
1759 1759
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1760 1760
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1761 1761
 				} else {
@@ -1771,13 +1771,13 @@  discard block
 block discarded – undo
1771 1771
 					connect_all($sourceer);
1772 1772
 					$sourceer = array();
1773 1773
 				}
1774
-			    }
1774
+				}
1775 1775
 			}
1776 1776
 			// Sleep for xxx microseconds
1777 1777
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1778
-		    } else {
1778
+			} else {
1779 1779
 			if ($format == 'flightgearmp') {
1780
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1780
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1781 1781
 				//@socket_close($r);
1782 1782
 				sleep($globalMinFetch);
1783 1783
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1786,9 +1786,9 @@  discard block
 block discarded – undo
1786 1786
 				break;
1787 1787
 				
1788 1788
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1789
-			    if (isset($tt[$format])) $tt[$format]++;
1790
-			    else $tt[$format] = 0;
1791
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
1789
+				if (isset($tt[$format])) $tt[$format]++;
1790
+				else $tt[$format] = 0;
1791
+				if ($tt[$format] > 30 || $buffer === FALSE) {
1792 1792
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1793 1793
 				//@socket_close($r);
1794 1794
 				sleep(2);
@@ -1799,24 +1799,24 @@  discard block
 block discarded – undo
1799 1799
 				//connect_all($globalSources);
1800 1800
 				$tt[$format]=0;
1801 1801
 				break;
1802
-			    } 
1803
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1802
+				} 
1803
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
1804
+			}
1804 1805
 			}
1805
-		    }
1806 1806
 		}
1807
-	    } else {
1807
+		} else {
1808 1808
 		$error = socket_strerror(socket_last_error());
1809 1809
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1810 1810
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1811 1811
 			if (isset($globalDebug)) echo "Restarting...\n";
1812 1812
 			// Restart the script if possible
1813 1813
 			if (is_array($sockets)) {
1814
-			    if ($globalDebug) echo "Shutdown all sockets...";
1814
+				if ($globalDebug) echo "Shutdown all sockets...";
1815 1815
 			    
1816
-			    foreach ($sockets as $sock) {
1816
+				foreach ($sockets as $sock) {
1817 1817
 				@socket_shutdown($sock,2);
1818 1818
 				@socket_close($sock);
1819
-			    }
1819
+				}
1820 1820
 			    
1821 1821
 			}
1822 1822
 			if ($globalDebug) echo "Waiting...";
@@ -1831,15 +1831,15 @@  discard block
 block discarded – undo
1831 1831
 			if ($globalDebug) echo "Restart all connections...";
1832 1832
 			connect_all($globalSources);
1833 1833
 		}
1834
-	    }
1834
+		}
1835 1835
 	}
1836 1836
 	if ($globalDaemon === false) {
1837
-	    if ($globalDebug) echo 'Check all...'."\n";
1838
-	    if (isset($SI)) $SI->checkAll();
1839
-	    if (isset($TI)) $TI->checkAll();
1840
-	    if (isset($MI)) $MI->checkAll();
1837
+		if ($globalDebug) echo 'Check all...'."\n";
1838
+		if (isset($SI)) $SI->checkAll();
1839
+		if (isset($TI)) $TI->checkAll();
1840
+		if (isset($MI)) $MI->checkAll();
1841
+	}
1841 1842
 	}
1842
-    }
1843 1843
 }
1844 1844
 
1845 1845
 ?>
Please login to merge, or discard this patch.
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,30 +150,30 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/opensky/i',$host)) {
176
+    	    } else if (preg_match('/opensky/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftlistjson';
178 178
         	$globalSources[$id]['format'] = 'opensky';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
193
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
194 194
         	//$formats[$id] = 'planeupdatefaa';
195 195
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 196
         	//$last_exec['planeupdatefaa'] = 0;
@@ -199,37 +199,37 @@  discard block
 block discarded – undo
199 199
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 200
         	    exit(0);
201 201
         	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
202
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
203 203
         	//$formats[$id] = 'phpvmacars';
204 204
         	$globalSources[$id]['format'] = 'phpvmacars';
205 205
         	//$last_exec['phpvmacars'] = 0;
206 206
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
207
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
208 208
         	//$formats[$id] = 'phpvmacars';
209 209
         	$globalSources[$id]['format'] = 'vaos';
210 210
         	//$last_exec['phpvmacars'] = 0;
211 211
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
212
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
212
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'vam';
215 215
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
216
-            } else if (preg_match('/whazzup/i',$host)) {
216
+            } else if (preg_match('/whazzup/i', $host)) {
217 217
         	//$formats[$id] = 'whazzup';
218 218
         	$globalSources[$id]['format'] = 'whazzup';
219 219
         	//$last_exec['whazzup'] = 0;
220 220
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
221
-            } else if (preg_match('/blitzortung/i',$host)) {
221
+            } else if (preg_match('/blitzortung/i', $host)) {
222 222
         	$globalSources[$id]['format'] = 'blitzortung';
223 223
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
224
-            } else if (preg_match('/airwhere/i',$host)) {
224
+            } else if (preg_match('/airwhere/i', $host)) {
225 225
         	$globalSources[$id]['format'] = 'airwhere';
226 226
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
227
-            } else if (preg_match('/recentpireps/i',$host)) {
227
+            } else if (preg_match('/recentpireps/i', $host)) {
228 228
         	//$formats[$id] = 'pirepsjson';
229 229
         	$globalSources[$id]['format'] = 'pirepsjson';
230 230
         	//$last_exec['pirepsjson'] = 0;
231 231
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
232
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
232
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
233 233
         	//$formats[$id] = 'fr24json';
234 234
         	$globalSources[$id]['format'] = 'fr24json';
235 235
         	//$last_exec['fr24json'] = 0;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239 239
         	    exit(0);
240 240
         	}
241
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
241
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
242 242
         	//$formats[$id] = 'fr24json';
243 243
         	$globalSources[$id]['format'] = 'myshiptracking';
244 244
         	//$last_exec['fr24json'] = 0;
@@ -248,21 +248,21 @@  discard block
 block discarded – undo
248 248
         	    exit(0);
249 249
         	}
250 250
             //} else if (preg_match('/10001/',$host)) {
251
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
251
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252 252
         	//$formats[$id] = 'tsv';
253 253
         	$globalSources[$id]['format'] = 'tsv';
254 254
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
255 255
             }
256
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
256
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
257 257
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
258
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
259 259
     		    if ($idf !== false) {
260 260
     			$httpfeeds[$id] = $idf;
261 261
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262 262
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263 263
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265
-	    $hostport = explode(':',$host);
264
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
265
+	    $hostport = explode(':', $host);
266 266
 	    if (isset($hostport[1])) {
267 267
 		$port = $hostport[1];
268 268
 		$hostn = $hostport[0];
@@ -272,19 +272,19 @@  discard block
 block discarded – undo
272 272
 	    }
273 273
 	    $Common = new Common();
274 274
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
275
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
275
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
276 276
     	    } else {
277
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
277
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
278 278
 	    }
279 279
 	    if ($s) {
280 280
     	        $sockets[$id] = $s;
281 281
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
282
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
282
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
283 283
 			//$formats[$id] = 'aprs';
284 284
 			$globalSources[$id]['format'] = 'aprs';
285 285
 			//$aprs_connect = 0;
286 286
 			//$use_aprs = true;
287
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
287
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
288 288
 			$globalSources[$id]['format'] = 'vrstcp';
289 289
     		    } elseif ($port == '10001') {
290 290
         		//$formats[$id] = 'tsv';
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
324 324
 else $timeout = 20;
325 325
 $errno = '';
326
-$errstr='';
326
+$errstr = '';
327 327
 
328 328
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
329 329
 /* Initiate connections to all the hosts simultaneously */
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 //connect_all($globalSources);
332 332
 
333 333
 if (isset($globalProxy) && $globalProxy) {
334
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
334
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
335 335
 } else {
336 336
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
337 337
 }
@@ -361,16 +361,16 @@  discard block
 block discarded – undo
361 361
 
362 362
 if ($use_aprs) {
363 363
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
364
-	$APRS=new APRS();
364
+	$APRS = new APRS();
365 365
 	$aprs_connect = 0;
366 366
 	$aprs_keep = 120;
367 367
 	$aprs_last_tx = time();
368 368
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
369
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
369
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
370 370
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
371
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
371
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
372 372
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
373
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
373
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
374 374
 	if ($aprs_full) $aprs_filter = '';
375 375
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
376 376
 	else $aprs_pass = '-1';
@@ -384,12 +384,12 @@  discard block
 block discarded – undo
384 384
 sleep(1);
385 385
 if ($globalDebug) echo "SCAN MODE \n\n";
386 386
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
387
-$endtime = time()+$globalCronEnd;
387
+$endtime = time() + $globalCronEnd;
388 388
 $i = 1;
389 389
 $tt = array();
390 390
 // Delete all ATC
391 391
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
392
-	$ATC=new ATC($Connection->db);
392
+	$ATC = new ATC($Connection->db);
393 393
 }
394 394
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
395 395
 	$ATC->deleteAll();
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
399 399
 while ($i > 0) {
400
-    if (!$globalDaemon) $i = $endtime-time();
400
+    if (!$globalDaemon) $i = $endtime - time();
401 401
     // Delete old ATC
402 402
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
403 403
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	}
412 412
 	if ($max != $globalMinFetch) {
413 413
 	    if ($globalDebug) echo 'Sleeping...'."\n";
414
-	    sleep($globalMinFetch-$max+2);
414
+	    sleep($globalMinFetch - $max + 2);
415 415
 	}
416 416
     }
417 417
 
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	    //$buffer = $Common->getData($hosts[$id]);
431 431
 	    $buffer = $Common->getData($value['host']);
432 432
 	    if ($buffer != '') $reset = 0;
433
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434
-	    $buffer = explode('\n',$buffer);
433
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
434
+	    $buffer = explode('\n', $buffer);
435 435
 	    foreach ($buffer as $line) {
436 436
     		if ($line != '' && count($line) > 7) {
437 437
     		    $line = explode(',', $line);
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
 	    )
465 465
 	) {
466 466
 	    date_default_timezone_set('CET');
467
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
467
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
468 468
 	    date_default_timezone_set('UTC');
469 469
 	    if ($buffer != '') $reset = 0;
470
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471
-	    $buffer = explode('\n',$buffer);
470
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
471
+	    $buffer = explode('\n', $buffer);
472 472
 	    foreach ($buffer as $line) {
473 473
 		if ($line != '') {
474 474
 		    //echo "'".$line."'\n";
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 		    $ais_data = $AIS->parse_line(trim($line));
477 477
 		    $data = array();
478 478
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
479
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
480 480
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481 481
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482 482
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
487 487
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
488 488
 		    if (isset($ais_data['timestamp'])) {
489
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
489
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
490 490
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
491 491
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
492 492
 			    $add = true;
@@ -509,21 +509,21 @@  discard block
 block discarded – undo
509 509
 	    $w = $e = null;
510 510
 	    
511 511
 	    if (isset($arr[$id])) {
512
-		$nn = stream_select($arr,$w,$e,$timeout);
512
+		$nn = stream_select($arr, $w, $e, $timeout);
513 513
 		if ($nn > 0) {
514 514
 		    foreach ($httpfeeds as $feed) {
515
-			$buffer = stream_get_line($feed,2000,"\n");
515
+			$buffer = stream_get_line($feed, 2000, "\n");
516 516
 			if ($buffer === FALSE) {
517 517
 			    connect_all($globalSources);
518 518
 			}
519
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
520
-			$buffer = explode('\n',$buffer);
519
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
520
+			$buffer = explode('\n', $buffer);
521 521
 			foreach ($buffer as $line) {
522 522
 			    if ($line != '') {
523 523
 				$ais_data = $AIS->parse_line(trim($line));
524 524
 				$data = array();
525 525
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
526
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
526
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
527 527
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
528 528
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
529 529
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
536 536
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
537 537
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
538
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
538
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
539 539
 				if (isset($ais_data['timestamp'])) {
540
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
540
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
541 541
 				} else {
542 542
 				    $data['datetime'] = date('Y-m-d H:i:s');
543 543
 				}
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
570 570
 	    )
571 571
 	) {
572
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
572
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
573 573
 	    if ($buffer != '') {
574 574
 		//echo $buffer;
575
-		$all_data = json_decode($buffer,true);
575
+		$all_data = json_decode($buffer, true);
576 576
 		//print_r($all_data);
577 577
 		if (isset($all_data[0]['DATA'])) {
578 578
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 			    $data['ident'] = $line['NAME'];
582 582
 			    $data['mmsi'] = $line['MMSI'];
583 583
 			    if (strlen($data['mmsi']) > 9) {
584
-				$data['mmsi'] = substr($data['mmsi'],-9);
584
+				$data['mmsi'] = substr($data['mmsi'], -9);
585 585
 			    }
586 586
 			    $data['speed'] = $line['SOG'];
587 587
 			    $data['heading'] = $line['COG'];
@@ -591,8 +591,8 @@  discard block
 block discarded – undo
591 591
 			    $data['type_id'] = $line['TYPE'];
592 592
 			    $data['imo'] = $line['IMO'];
593 593
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
594
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
595
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
594
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
595
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
596 596
 			    $data['format_source'] = 'myshiptracking';
597 597
 			    $data['id_source'] = $id_source;
598 598
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -609,16 +609,16 @@  discard block
 block discarded – undo
609 609
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
610 610
 	    )
611 611
 	) {
612
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
612
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
613 613
 	    if ($buffer != '') {
614
-		$all_data = json_decode($buffer,true);
614
+		$all_data = json_decode($buffer, true);
615 615
 		if (isset($all_data[0]['mmsi'])) {
616 616
 		    foreach ($all_data as $line) {
617 617
 			if ($line != '') {
618 618
 			    $data = array();
619 619
 			    $data['ident'] = $line['shipname'];
620 620
 			    $data['callsign'] = $line['callsign'];
621
-			    $data['mmsi'] = substr($line['mmsi'],-9);
621
+			    $data['mmsi'] = substr($line['mmsi'], -9);
622 622
 			    $data['speed'] = $line['sog'];
623 623
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
624 624
 			    $data['latitude'] = $line['latitude'];
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
 	) {
646 646
 	    $buffer = $Common->getData($value['host']);
647 647
 	    if ($buffer != '') {
648
-		$all_data = json_decode($buffer,true);
648
+		$all_data = json_decode($buffer, true);
649 649
 		if (isset($all_data['features'][0]['id'])) {
650 650
 		    foreach ($all_data['features'] as $line) {
651 651
 			print_r($line);
652 652
 			$data = array();
653 653
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
654 654
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
655
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
655
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
656 656
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
657 657
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
658 658
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -679,31 +679,31 @@  discard block
 block discarded – undo
679 679
 	    )
680 680
 	) {
681 681
 	    echo 'download...';
682
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
682
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
683 683
 	    echo 'done !'."\n";
684 684
 	    // FIXME: Need more work
685 685
 	    if ($buffer != '') $reset = 0;
686
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
687
-	    $buffer = explode('\n',$buffer);
686
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
687
+	    $buffer = explode('\n', $buffer);
688 688
 	    foreach ($buffer as $line) {
689 689
 		if ($line != '') {
690 690
 		    $data = array();
691 691
 		    echo $line."\n";
692
-		    $data['mmsi'] = (int)substr($line,0,9);
693
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
694
-		    $data['status_id'] = substr($line,21,2);
695
-		    $data['type_id'] = substr($line,24,3);
696
-		    $data['latitude'] = substr($line,29,9);
697
-		    $data['longitude'] = substr($line,41,9);
698
-		    $data['speed'] = round(substr($line,51,5));
692
+		    $data['mmsi'] = (int) substr($line, 0, 9);
693
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
694
+		    $data['status_id'] = substr($line, 21, 2);
695
+		    $data['type_id'] = substr($line, 24, 3);
696
+		    $data['latitude'] = substr($line, 29, 9);
697
+		    $data['longitude'] = substr($line, 41, 9);
698
+		    $data['speed'] = round(substr($line, 51, 5));
699 699
 		    //$data['course'] = substr($line,57,5);
700
-		    $data['heading'] = round(substr($line,63,3));
700
+		    $data['heading'] = round(substr($line, 63, 3));
701 701
 		    //$data['draft'] = substr($line,67,4);
702 702
 		    //$data['length'] = substr($line,72,3);
703 703
 		    //$data['beam'] = substr($line,76,2);
704
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
704
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
705 705
 		    //$data['callsign'] = trim(substr($line,100,7);
706
-		    $data['arrival_code'] = substr($line,108,20);
706
+		    $data['arrival_code'] = substr($line, 108, 20);
707 707
 		    //$data['etaDate'] = substr($line,129,5);
708 708
 		    //$data['etaTime'] = substr($line,135,5);
709 709
 		    $data['format_source'] = 'shipplotter';
@@ -734,8 +734,8 @@  discard block
 block discarded – undo
734 734
 	) {
735 735
 	    //$buffer = $Common->getData($hosts[$id]);
736 736
 	    $buffer = $Common->getData($value['host']);
737
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
738
-	    $buffer = explode('\n',$buffer);
737
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
738
+	    $buffer = explode('\n', $buffer);
739 739
 	    $reset = 0;
740 740
 	    foreach ($buffer as $line) {
741 741
     		if ($line != '') {
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
747 747
 			$data['pilot_id'] = $line[1];
748 748
 			$data['pilot_name'] = $line[2];
749
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
749
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
750 750
 			$data['ident'] = $line[0]; // ident
751 751
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
752 752
 			$data['speed'] = $line[8]; // speed
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
763 763
 			//if (isset($line[37])) $data['last_update'] = $line[37];
764 764
 		        $data['departure_airport_icao'] = $line[11];
765
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
765
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
766 766
 		        $data['arrival_airport_icao'] = $line[13];
767 767
 			$data['frequency'] = $line[4];
768 768
 			$data['type'] = $line[18];
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
     			$data['id_source'] = $id_source;
772 772
 	    		//$data['arrival_airport_time'] = ;
773 773
 	    		if ($line[9] != '') {
774
-	    		    $aircraft_data = explode('/',$line[9]);
774
+	    		    $aircraft_data = explode('/', $line[9]);
775 775
 	    		    if (isset($aircraft_data[1])) {
776 776
 	    			$data['aircraft_icao'] = $aircraft_data[1];
777 777
 	    		    }
@@ -786,9 +786,9 @@  discard block
 block discarded – undo
786 786
     			if ($line[3] == 'PILOT') $SI->add($data);
787 787
 			elseif ($line[3] == 'ATC') {
788 788
 				//print_r($data);
789
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
790
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
791
-				$typec = substr($data['ident'],-3);
789
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
790
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
791
+				$typec = substr($data['ident'], -3);
792 792
 				if ($typec == 'APP') $data['type'] = 'Approach';
793 793
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
794 794
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -800,8 +800,8 @@  discard block
 block discarded – undo
800 800
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
801 801
 				if (!isset($data['source_name'])) $data['source_name'] = '';
802 802
 				if (isset($ATC)) {
803
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
804
-					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']);
803
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($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']);
804
+					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']);
805 805
 				}
806 806
 			}
807 807
     			unset($data);
@@ -817,24 +817,24 @@  discard block
 block discarded – undo
817 817
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
818 818
     	    )
819 819
     	) {
820
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
820
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
821 821
 	    if ($buffer != '') {
822 822
 		$all_data = simplexml_load_string($buffer);
823
-		foreach($all_data->children() as $childdata) {
823
+		foreach ($all_data->children() as $childdata) {
824 824
 			$data = array();
825 825
 			$line = $childdata;
826 826
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
827
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
828
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
829
-			$data['latitude'] = (float)$line['pktLatitude'];
830
-			$data['longitude'] = (float)$line['pktLongitude'];
831
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
832
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
833
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
827
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
828
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
829
+			$data['latitude'] = (float) $line['pktLatitude'];
830
+			$data['longitude'] = (float) $line['pktLongitude'];
831
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
832
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
833
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
834 834
 			$data['altitude_relative'] = 'AMSL';
835
-			$data['pilot_id'] = (int)$line['pktPilotID'];
835
+			$data['pilot_id'] = (int) $line['pktPilotID'];
836 836
 			$data['aircraft_icao'] = 'PARAGLIDER';
837
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
837
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
838 838
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
839 839
 			$data['format_source'] = $value['format'];
840 840
 			$SI->add($data);
@@ -842,22 +842,22 @@  discard block
 block discarded – undo
842 842
 		}
843 843
 	    }
844 844
 	    $Source->deleteOldLocationByType('gs');
845
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
845
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
846 846
 	    if ($buffer != '') {
847 847
 		$all_data = simplexml_load_string($buffer);
848
-		foreach($all_data->children() as $childdata) {
848
+		foreach ($all_data->children() as $childdata) {
849 849
 			$data = array();
850 850
 			$line = $childdata;
851
-			$data['id'] = (int)$line['gsID'];
852
-			$data['latitude'] = (float)$line['gsLatitude'];
853
-			$data['longitude'] = (float)$line['gsLongitude'];
854
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
851
+			$data['id'] = (int) $line['gsID'];
852
+			$data['latitude'] = (float) $line['gsLatitude'];
853
+			$data['longitude'] = (float) $line['gsLongitude'];
854
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
855 855
 			$data['altitude_relative'] = 'AMSL';
856
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
856
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
857 857
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
858
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
858
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
859 859
 			} else {
860
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
860
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
861 861
 			}
862 862
 			unset($data);
863 863
 		}
@@ -875,9 +875,9 @@  discard block
 block discarded – undo
875 875
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
876 876
 	    )
877 877
 	) {
878
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
878
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
879 879
 	    if ($buffer != '') {
880
-	        $all_data = json_decode($buffer,true);
880
+	        $all_data = json_decode($buffer, true);
881 881
 		if (isset($all_data['acList'])) {
882 882
 		    $reset = 0;
883 883
 		    foreach ($all_data['acList'] as $line) {
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
894 894
 			$data['emergency'] = ''; // emergency
895 895
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
896
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
896
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
897 897
 			else $data['datetime'] = date('Y-m-d H:i:s');
898 898
 			//$data['datetime'] = date('Y-m-d H:i:s');
899 899
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 			$data['verticalrate'] = $line['vrt']; // verticale rate
919 919
 			$data['squawk'] = $line['squawk']; // squawk
920 920
 			$data['emergency'] = ''; // emergency
921
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
921
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
922 922
 			else $data['datetime'] = date('Y-m-d H:i:s');
923 923
 			$data['format_source'] = 'aircraftlistjson';
924 924
 			$data['id_source'] = $id_source;
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
     	    )
940 940
     	) {
941 941
 	    $buffer = $Common->getData($value['host']);
942
-	    $all_data = json_decode($buffer,true);
942
+	    $all_data = json_decode($buffer, true);
943 943
 	    if (isset($all_data['planes'])) {
944 944
 		$reset = 0;
945 945
 		foreach ($all_data['planes'] as $key => $line) {
@@ -956,12 +956,12 @@  discard block
 block discarded – undo
956 956
 		    $data['emergency'] = ''; // emergency
957 957
 		    $data['registration'] = $line[2];
958 958
 		    $data['aircraft_icao'] = $line[0];
959
-		    $deparr = explode('-',$line[1]);
959
+		    $deparr = explode('-', $line[1]);
960 960
 		    if (count($deparr) == 2) {
961 961
 			$data['departure_airport_icao'] = $deparr[0];
962 962
 			$data['arrival_airport_icao'] = $deparr[1];
963 963
 		    }
964
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
964
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
965 965
 	    	    $data['format_source'] = 'planeupdatefaa';
966 966
     		    $data['id_source'] = $id_source;
967 967
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 	    )
980 980
 	) {
981 981
 	    $buffer = $Common->getData($value['host']);
982
-	    $all_data = json_decode($buffer,true);
982
+	    $all_data = json_decode($buffer, true);
983 983
 	    if (isset($all_data['states'])) {
984 984
 		$reset = 0;
985 985
 		foreach ($all_data['states'] as $key => $line) {
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 		    //$data['emergency'] = ''; // emergency
997 997
 		    //$data['registration'] = $line[2];
998 998
 		    //$data['aircraft_icao'] = $line[0];
999
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
999
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1000 1000
 		    $data['format_source'] = 'opensky';
1001 1001
 		    $data['id_source'] = $id_source;
1002 1002
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 	) {
1016 1016
 	    //$buffer = $Common->getData($hosts[$id]);
1017 1017
 	    $buffer = $Common->getData($value['host']);
1018
-	    $all_data = json_decode($buffer,true);
1018
+	    $all_data = json_decode($buffer, true);
1019 1019
 	    if (!empty($all_data)) $reset = 0;
1020 1020
 	    foreach ($all_data as $key => $line) {
1021 1021
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
 	    )
1054 1054
 	) {
1055 1055
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1056
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1056
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1057 1057
 	    //echo $buffer;
1058
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1059
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1060
-	    $all_data = json_decode($buffer,true);
1058
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1059
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1060
+	    $all_data = json_decode($buffer, true);
1061 1061
 	    if (json_last_error() != JSON_ERROR_NONE) {
1062 1062
 		die(json_last_error_msg());
1063 1063
 	    }
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 			//$data['departure_airport_iata'] = $line[11];
1081 1081
 			//$data['arrival_airport_iata'] = $line[12];
1082 1082
 	    		//$data['emergency'] = ''; // emergency
1083
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1083
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1084 1084
 	    		$data['format_source'] = 'radarvirtueljson';
1085 1085
     			$data['id_source'] = $id_source;
1086 1086
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1101,14 +1101,14 @@  discard block
 block discarded – undo
1101 1101
 	) {
1102 1102
 	    //$buffer = $Common->getData($hosts[$id]);
1103 1103
 	    $buffer = $Common->getData($value['host'].'?'.time());
1104
-	    $all_data = json_decode(utf8_encode($buffer),true);
1104
+	    $all_data = json_decode(utf8_encode($buffer), true);
1105 1105
 	    
1106 1106
 	    if (isset($all_data['pireps'])) {
1107 1107
 		$reset = 0;
1108 1108
 	        foreach ($all_data['pireps'] as $line) {
1109 1109
 		    $data = array();
1110 1110
 		    $data['id'] = $line['id'];
1111
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1111
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1112 1112
 		    $data['ident'] = $line['callsign']; // ident
1113 1113
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1114 1114
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1138,9 +1138,9 @@  discard block
 block discarded – undo
1138 1138
 			$SI->add($data);
1139 1139
 		    //    print_r($data);
1140 1140
     		    } elseif ($line['icon'] == 'ct') {
1141
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1142
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1143
-			$typec = substr($data['ident'],-3);
1141
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1142
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1143
+			$typec = substr($data['ident'], -3);
1144 1144
 			$data['type'] = '';
1145 1145
 			if ($typec == 'APP') $data['type'] = 'Approach';
1146 1146
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1152 1152
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1153 1153
 			else $data['type'] = 'Observer';
1154
-			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']);
1154
+			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']);
1155 1155
 		    }
1156 1156
 		    unset($data);
1157 1157
 		}
@@ -1168,14 +1168,14 @@  discard block
 block discarded – undo
1168 1168
 	    //$buffer = $Common->getData($hosts[$id]);
1169 1169
 	    if ($globalDebug) echo 'Get Data...'."\n";
1170 1170
 	    $buffer = $Common->getData($value['host']);
1171
-	    $all_data = json_decode($buffer,true);
1171
+	    $all_data = json_decode($buffer, true);
1172 1172
 	    if ($buffer != '' && is_array($all_data)) {
1173 1173
 		$reset = 0;
1174 1174
 		foreach ($all_data as $line) {
1175 1175
 	    	    $data = array();
1176 1176
 	    	    //$data['id'] = $line['id']; // id not usable
1177 1177
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1178
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1178
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1179 1179
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1180 1180
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1181 1181
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 	    	    //$data['datetime'] = $line['lastupdate'];
1191 1191
 	    	    //$data['last_update'] = $line['lastupdate'];
1192 1192
 	    	    if (isset($value['timezone'])) {
1193
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1193
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1194 1194
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1195 1195
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1196 1196
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1206,14 +1206,14 @@  discard block
 block discarded – undo
1206 1206
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1207 1207
 		    if (isset($line['aircraftname'])) {
1208 1208
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1209
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1210
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1209
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1210
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1211 1211
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1212 1212
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1213 1213
 	    		else {
1214
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1215
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1216
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1214
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1215
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1216
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1217 1217
 	    		}
1218 1218
 	    	    }
1219 1219
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
 	    //$buffer = $Common->getData($hosts[$id]);
1239 1239
 	    if ($globalDebug) echo 'Get Data...'."\n";
1240 1240
 	    $buffer = $Common->getData($value['host']);
1241
-	    $all_data = json_decode($buffer,true);
1241
+	    $all_data = json_decode($buffer, true);
1242 1242
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1243 1243
 		$reset = 0;
1244 1244
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1250 1250
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1251 1251
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1252
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1252
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1253 1253
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1254 1254
 	    	    $data['altitude'] = $line['altitude']; // altitude
1255 1255
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 	    	    //$data['squawk'] = ''; // squawk
1261 1261
 	    	    //$data['emergency'] = ''; // emergency
1262 1262
 	    	    if (isset($value['timezone'])) {
1263
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1263
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1264 1264
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1265 1265
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1266 1266
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1296,14 +1296,14 @@  discard block
 block discarded – undo
1296 1296
 	    //$buffer = $Common->getData($hosts[$id]);
1297 1297
 	    if ($globalDebug) echo 'Get Data...'."\n";
1298 1298
 	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1299
+	    $all_data = json_decode($buffer, true);
1300 1300
 	    if ($buffer != '' && is_array($all_data)) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data as $line) {
1303 1303
 	    	    $data = array();
1304 1304
 	    	    //$data['id'] = $line['id']; // id not usable
1305 1305
 	    	    $data['id'] = trim($line['flight_id']);
1306
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1306
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1307 1307
 	    	    $data['pilot_name'] = $line['pilot_name'];
1308 1308
 	    	    $data['pilot_id'] = $line['pilot_id'];
1309 1309
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1347,24 +1347,24 @@  discard block
 block discarded – undo
1347 1347
 	    //$buffer = $Common->getData($hosts[$id]);
1348 1348
 	    if ($globalDebug) echo 'Get Data...'."\n";
1349 1349
 	    $buffer = $Common->getData($value['host']);
1350
-	    $all_data = json_decode($buffer,true);
1350
+	    $all_data = json_decode($buffer, true);
1351 1351
 	    if ($buffer != '') {
1352 1352
 		$Source->deleteLocationBySource('blitzortung');
1353
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1354
-		$buffer = explode('\n',$buffer);
1353
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1354
+		$buffer = explode('\n', $buffer);
1355 1355
 		foreach ($buffer as $buffer_line) {
1356
-		    $line = json_decode($buffer_line,true);
1356
+		    $line = json_decode($buffer_line, true);
1357 1357
 		    if (isset($line['time'])) {
1358 1358
 			$data = array();
1359 1359
 			$data['altitude'] = $line['alt']; // altitude
1360 1360
 			$data['latitude'] = $line['lat']; // lat
1361 1361
 			$data['longitude'] = $line['lon']; // long
1362
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1362
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1363 1363
 			$data['id_source'] = $id_source;
1364 1364
 			$data['format_source'] = 'blitzortung';
1365 1365
 			$SI->add($data);
1366 1366
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1367
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1367
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1368 1368
 			unset($data);
1369 1369
 		    }
1370 1370
 		}
@@ -1389,11 +1389,11 @@  discard block
 block discarded – undo
1389 1389
 		    //$value = $formats[$nb];
1390 1390
 		    $format = $globalSources[$nb]['format'];
1391 1391
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1392
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1392
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1393 1393
 		    } elseif ($format == 'vrstcp') {
1394 1394
 			$buffer = @socket_read($r, 6000);
1395 1395
 		    } else {
1396
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1396
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1397 1397
 		    }
1398 1398
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1399 1399
 		    //echo $buffer."\n";
@@ -1403,8 +1403,8 @@  discard block
 block discarded – undo
1403 1403
 		    //$SI::del();
1404 1404
 		    if ($buffer !== FALSE) {
1405 1405
 			if ($format == 'vrstcp') {
1406
-			    $buffer = explode('},{',$buffer);
1407
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1406
+			    $buffer = explode('},{', $buffer);
1407
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1408 1408
 		    }
1409 1409
 		    // SBS format is CSV format
1410 1410
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 			    $ais_data = $AIS->parse_line(trim($buffer));
1429 1429
 			    $data = array();
1430 1430
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1431
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1431
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1432 1432
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1433 1433
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1434 1434
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1439,13 +1439,13 @@  discard block
 block discarded – undo
1439 1439
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1440 1440
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1441 1441
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1442
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1442
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1443 1443
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444 1444
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1445 1445
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1446 1446
 
1447 1447
 			    if (isset($ais_data['timestamp'])) {
1448
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1448
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1449 1449
 			    } else {
1450 1450
 				$data['datetime'] = date('Y-m-d H:i:s');
1451 1451
 			    }
@@ -1456,10 +1456,10 @@  discard block
 block discarded – undo
1456 1456
                         } elseif ($format == 'flightgearsp') {
1457 1457
                     	    //echo $buffer."\n";
1458 1458
                     	    if (strlen($buffer) > 5) {
1459
-				$line = explode(',',$buffer);
1459
+				$line = explode(',', $buffer);
1460 1460
 				$data = array();
1461 1461
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1462
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1462
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1463 1463
 				$data['ident'] = $line[6];
1464 1464
 				$data['aircraft_name'] = $line[7];
1465 1465
 				$data['longitude'] = $line[1];
@@ -1476,16 +1476,16 @@  discard block
 block discarded – undo
1476 1476
                         } elseif ($format == 'acars') {
1477 1477
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1478 1478
 			    $ACARS->add(trim($buffer));
1479
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1479
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1480 1480
 			    $ACARS->deleteLiveAcarsData();
1481 1481
 			} elseif ($format == 'flightgearmp') {
1482
-			    if (substr($buffer,0,1) != '#') {
1482
+			    if (substr($buffer, 0, 1) != '#') {
1483 1483
 				$data = array();
1484 1484
 				//echo $buffer."\n";
1485
-				$line = explode(' ',$buffer);
1485
+				$line = explode(' ', $buffer);
1486 1486
 				if (count($line) == 11) {
1487
-				    $userserver = explode('@',$line[0]);
1488
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1487
+				    $userserver = explode('@', $line[0]);
1488
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1489 1489
 				    $data['ident'] = $userserver[0];
1490 1490
 				    $data['registration'] = $userserver[0];
1491 1491
 				    $data['latitude'] = $line[4];
@@ -1493,8 +1493,8 @@  discard block
 block discarded – undo
1493 1493
 				    $data['altitude'] = $line[6];
1494 1494
 				    $data['datetime'] = date('Y-m-d H:i:s');
1495 1495
 				    $aircraft_type = $line[10];
1496
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1497
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1496
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1497
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1498 1498
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1499 1499
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1500 1500
 				}
@@ -1503,8 +1503,8 @@  discard block
 block discarded – undo
1503 1503
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1504 1504
 			    die;
1505 1505
 			} elseif ($format == 'vrstcp') {
1506
-			    foreach($buffer as $all_data) {
1507
-				$line = json_decode('{'.$all_data.'}',true);
1506
+			    foreach ($buffer as $all_data) {
1507
+				$line = json_decode('{'.$all_data.'}', true);
1508 1508
 				$data = array();
1509 1509
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1510 1510
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1530,16 +1530,16 @@  discard block
 block discarded – undo
1530 1530
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1531 1531
 				unset($data);
1532 1532
 			    }
1533
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1533
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1534 1534
 			    $line = explode("\t", $buffer);
1535
-			    for($k = 0; $k < count($line); $k=$k+2) {
1535
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1536 1536
 				$key = $line[$k];
1537
-			        $lined[$key] = $line[$k+1];
1537
+			        $lined[$key] = $line[$k + 1];
1538 1538
 			    }
1539 1539
     			    if (count($lined) > 3) {
1540 1540
     				$data['hex'] = $lined['hexid'];
1541 1541
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1542
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1542
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1543 1543
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1544 1544
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1545 1545
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1558,23 +1558,23 @@  discard block
 block discarded – undo
1558 1558
     			    } else $error = true;
1559 1559
 			} elseif ($format == 'aprs' && $use_aprs) {
1560 1560
 			    if ($aprs_connect == 0) {
1561
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1561
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1562 1562
 				$aprs_connect = 1;
1563 1563
 			    }
1564 1564
 			    
1565
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1565
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1566 1566
 				$aprs_last_tx = time();
1567 1567
 				$data_aprs = "# Keep alive";
1568
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1568
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1569 1569
 			    }
1570 1570
 			    
1571 1571
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1572 1572
 			    //echo 'APRS data : '.$buffer."\n";
1573
-			    $buffer = str_replace('APRS <- ','',$buffer);
1574
-			    $buffer = str_replace('APRS -> ','',$buffer);
1573
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1574
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1575 1575
 			    //echo $buffer."\n";
1576 1576
 			    date_default_timezone_set('UTC');
1577
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1577
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1578 1578
 				$line = $APRS->parse($buffer);
1579 1579
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1580 1580
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1590 1590
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1591 1591
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1592
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1592
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1593 1593
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1594 1594
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1595 1595
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1672,29 +1672,29 @@  discard block
 block discarded – undo
1672 1672
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1673 1673
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1674 1674
 					$Source->deleteOldLocationByType('gs');
1675
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1676
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1675
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1676
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1677 1677
 					} else {
1678
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1678
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1679 1679
 					}
1680 1680
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1681 1681
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1682 1682
 					if ($globalDebug) echo '# Weather Station added'."\n";
1683 1683
 					$Source->deleteOldLocationByType('wx');
1684 1684
 					$weather_data = json_encode($line);
1685
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1686
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1685
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1686
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1687 1687
 					} else {
1688
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1688
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1689 1689
 					}
1690 1690
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1691 1691
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1692 1692
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1693 1693
 					$Source->deleteOldLocationByType('lightning');
1694
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1695
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1694
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1695
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1696 1696
 					} else {
1697
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1697
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1698 1698
 					}
1699 1699
 				    } elseif ($globalDebug) {
1700 1700
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1703,7 +1703,7 @@  discard block
 block discarded – undo
1703 1703
 				    unset($data);
1704 1704
 				}
1705 1705
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1706
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1706
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1707 1707
 				}
1708 1708
 				/*
1709 1709
 				elseif (is_array($line) && $globalDebug && 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')) {
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
 				*/
1713 1713
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1714 1714
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1715
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1715
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1716 1716
 					$Source->deleteOldLocationByType('lightning');
1717 1717
 					$Source->deleteOldLocationByType('wx');
1718 1718
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
 				connect_all($sourceee);
1798 1798
 				$sourceee = array();
1799 1799
 				//connect_all($globalSources);
1800
-				$tt[$format]=0;
1800
+				$tt[$format] = 0;
1801 1801
 				break;
1802 1802
 			    } 
1803 1803
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1807,14 +1807,14 @@  discard block
 block discarded – undo
1807 1807
 	    } else {
1808 1808
 		$error = socket_strerror(socket_last_error());
1809 1809
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1810
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1810
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1811 1811
 			if (isset($globalDebug)) echo "Restarting...\n";
1812 1812
 			// Restart the script if possible
1813 1813
 			if (is_array($sockets)) {
1814 1814
 			    if ($globalDebug) echo "Shutdown all sockets...";
1815 1815
 			    
1816 1816
 			    foreach ($sockets as $sock) {
1817
-				@socket_shutdown($sock,2);
1817
+				@socket_shutdown($sock, 2);
1818 1818
 				@socket_close($sock);
1819 1819
 			    }
1820 1820
 			    
Please login to merge, or discard this patch.
Braces   +1087 added lines, -370 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,22 +211,30 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/opensky/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftlistjson';
178 233
         	$globalSources[$id]['format'] = 'opensky';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to opensky source (".$host.")...\n";
237
+        	}
181 238
     	    /*
182 239
     	    // Disabled for now, site change source format
183 240
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -194,7 +251,9 @@  discard block
 block discarded – undo
194 251
         	//$formats[$id] = 'planeupdatefaa';
195 252
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 253
         	//$last_exec['planeupdatefaa'] = 0;
197
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
254
+        	if ($globalDebug) {
255
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
256
+        	}
198 257
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 259
         	    exit(0);
@@ -203,37 +262,53 @@  discard block
 block discarded – undo
203 262
         	//$formats[$id] = 'phpvmacars';
204 263
         	$globalSources[$id]['format'] = 'phpvmacars';
205 264
         	//$last_exec['phpvmacars'] = 0;
206
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
265
+        	if ($globalDebug) {
266
+        		echo "Connect to phpvmacars source (".$host.")...\n";
267
+        	}
207 268
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
208 269
         	//$formats[$id] = 'phpvmacars';
209 270
         	$globalSources[$id]['format'] = 'vaos';
210 271
         	//$last_exec['phpvmacars'] = 0;
211
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
272
+        	if ($globalDebug) {
273
+        		echo "Connect to vaos source (".$host.")...\n";
274
+        	}
212 275
             } else if (preg_match('/VAM-json.php$/i',$host)) {
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'vam';
215
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
278
+        	if ($globalDebug) {
279
+        		echo "Connect to Vam source (".$host.")...\n";
280
+        	}
216 281
             } else if (preg_match('/whazzup/i',$host)) {
217 282
         	//$formats[$id] = 'whazzup';
218 283
         	$globalSources[$id]['format'] = 'whazzup';
219 284
         	//$last_exec['whazzup'] = 0;
220
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
285
+        	if ($globalDebug) {
286
+        		echo "Connect to whazzup source (".$host.")...\n";
287
+        	}
221 288
             } else if (preg_match('/blitzortung/i',$host)) {
222 289
         	$globalSources[$id]['format'] = 'blitzortung';
223
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
290
+        	if ($globalDebug) {
291
+        		echo "Connect to blitzortung source (".$host.")...\n";
292
+        	}
224 293
             } else if (preg_match('/airwhere/i',$host)) {
225 294
         	$globalSources[$id]['format'] = 'airwhere';
226
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
295
+        	if ($globalDebug) {
296
+        		echo "Connect to airwhere source (".$host.")...\n";
297
+        	}
227 298
             } else if (preg_match('/recentpireps/i',$host)) {
228 299
         	//$formats[$id] = 'pirepsjson';
229 300
         	$globalSources[$id]['format'] = 'pirepsjson';
230 301
         	//$last_exec['pirepsjson'] = 0;
231
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
302
+        	if ($globalDebug) {
303
+        		echo "Connect to pirepsjson source (".$host.")...\n";
304
+        	}
232 305
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
233 306
         	//$formats[$id] = 'fr24json';
234 307
         	$globalSources[$id]['format'] = 'fr24json';
235 308
         	//$last_exec['fr24json'] = 0;
236
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to fr24 source (".$host.")...\n";
311
+        	}
237 312
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
238 313
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239 314
         	    exit(0);
@@ -242,7 +317,9 @@  discard block
 block discarded – undo
242 317
         	//$formats[$id] = 'fr24json';
243 318
         	$globalSources[$id]['format'] = 'myshiptracking';
244 319
         	//$last_exec['fr24json'] = 0;
245
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
320
+        	if ($globalDebug) {
321
+        		echo "Connect to myshiptracking source (".$host.")...\n";
322
+        	}
246 323
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
247 324
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
248 325
         	    exit(0);
@@ -251,16 +328,24 @@  discard block
 block discarded – undo
251 328
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252 329
         	//$formats[$id] = 'tsv';
253 330
         	$globalSources[$id]['format'] = 'tsv';
254
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
331
+        	if ($globalDebug) {
332
+        		echo "Connect to tsv source (".$host.")...\n";
333
+        	}
255 334
             }
256 335
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
257 336
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258 337
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
259 338
     		    if ($idf !== false) {
260 339
     			$httpfeeds[$id] = $idf;
261
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
340
+        		if ($globalDebug) {
341
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
342
+        		}
343
+    		    } elseif ($globalDebug) {
344
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
345
+    		    }
346
+    		} elseif ($globalDebug) {
347
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
348
+    		}
264 349
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265 350
 	    $hostport = explode(':',$host);
266 351
 	    if (isset($hostport[1])) {
@@ -300,17 +385,25 @@  discard block
 block discarded – undo
300 385
         		//$formats[$id] = 'beast';
301 386
         		$globalSources[$id]['format'] = 'beast';
302 387
 		    //} else $formats[$id] = 'sbs';
303
-		    } else $globalSources[$id]['format'] = 'sbs';
388
+		    } else {
389
+		    	$globalSources[$id]['format'] = 'sbs';
390
+		    }
304 391
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
305 392
 		}
306
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
393
+		if ($globalDebug) {
394
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
395
+		}
307 396
             } else {
308
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
397
+		if ($globalDebug) {
398
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
399
+		}
309 400
     	    }
310 401
         }
311 402
     }
312 403
 }
313
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
404
+if (!isset($globalMinFetch)) {
405
+	$globalMinFetch = 15;
406
+}
314 407
 
315 408
 // Initialize all
316 409
 $status = array();
@@ -319,13 +412,19 @@  discard block
 block discarded – undo
319 412
 $formats = array();
320 413
 $last_exec = array();
321 414
 $time = time();
322
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
323
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
324
-else $timeout = 20;
415
+if (isset($globalSourcesTimeout)) {
416
+	$timeout = $globalSourcesTimeOut;
417
+} else if (isset($globalSBS1TimeOut)) {
418
+	$timeout = $globalSBS1TimeOut;
419
+} else {
420
+	$timeout = 20;
421
+}
325 422
 $errno = '';
326 423
 $errstr='';
327 424
 
328
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
425
+if (!isset($globalDaemon)) {
426
+	$globalDaemon = TRUE;
427
+}
329 428
 /* Initiate connections to all the hosts simultaneously */
330 429
 //connect_all($hosts);
331 430
 //connect_all($globalSources);
@@ -354,7 +453,9 @@  discard block
 block discarded – undo
354 453
     if (isset($source['format']) && $source['format'] == 'aprs') {
355 454
 	$aprs_connect = 0;
356 455
 	$use_aprs = true;
357
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
456
+	if (isset($source['port']) && $source['port'] == '10152') {
457
+		$aprs_full = true;
458
+	}
358 459
 	break;
359 460
     }
360 461
 }
@@ -365,25 +466,46 @@  discard block
 block discarded – undo
365 466
 	$aprs_connect = 0;
366 467
 	$aprs_keep = 120;
367 468
 	$aprs_last_tx = time();
368
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
369
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
371
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
372
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
373
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
374
-	if ($aprs_full) $aprs_filter = '';
375
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
376
-	else $aprs_pass = '-1';
469
+	if (isset($globalAPRSversion)) {
470
+		$aprs_version = $globalAPRSversion;
471
+	} else {
472
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
473
+	}
474
+	if (isset($globalAPRSssid)) {
475
+		$aprs_ssid = $globalAPRSssid;
476
+	} else {
477
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
478
+	}
479
+	if (isset($globalAPRSfilter)) {
480
+		$aprs_filter = $globalAPRSfilter;
481
+	} else {
482
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
483
+	}
484
+	if ($aprs_full) {
485
+		$aprs_filter = '';
486
+	}
487
+	if (isset($globalAPRSpass)) {
488
+		$aprs_pass = $globalAPRSpass;
489
+	} else {
490
+		$aprs_pass = '-1';
491
+	}
377 492
 
378
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
379
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
380
-}
493
+	if ($aprs_filter != '') {
494
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
495
+	} else {
496
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
497
+	}
498
+	}
381 499
 
382 500
 // connected - lets do some work
383 501
 //if ($globalDebug) echo "Connected!\n";
384 502
 sleep(1);
385
-if ($globalDebug) echo "SCAN MODE \n\n";
386
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
503
+if ($globalDebug) {
504
+	echo "SCAN MODE \n\n";
505
+}
506
+if (!isset($globalCronEnd)) {
507
+	$globalCronEnd = 60;
508
+}
387 509
 $endtime = time()+$globalCronEnd;
388 510
 $i = 1;
389 511
 $tt = array();
@@ -397,20 +519,28 @@  discard block
 block discarded – undo
397 519
 
398 520
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
399 521
 while ($i > 0) {
400
-    if (!$globalDaemon) $i = $endtime-time();
522
+    if (!$globalDaemon) {
523
+    	$i = $endtime-time();
524
+    }
401 525
     // Delete old ATC
402 526
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
403
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
527
+	if ($globalDebug) {
528
+		echo 'Delete old ATC...'."\n";
529
+	}
404 530
         $ATC->deleteOldATC();
405 531
     }
406 532
     
407 533
     if (count($last_exec) == count($globalSources)) {
408 534
 	$max = $globalMinFetch;
409 535
 	foreach ($last_exec as $last) {
410
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
536
+	    if ((time() - $last['last']) < $max) {
537
+	    	$max = time() - $last['last'];
538
+	    }
411 539
 	}
412 540
 	if ($max != $globalMinFetch) {
413
-	    if ($globalDebug) echo 'Sleeping...'."\n";
541
+	    if ($globalDebug) {
542
+	    	echo 'Sleeping...'."\n";
543
+	    }
414 544
 	    sleep($globalMinFetch-$max+2);
415 545
 	}
416 546
     }
@@ -420,7 +550,9 @@  discard block
 block discarded – undo
420 550
     foreach ($globalSources as $id => $value) {
421 551
 	date_default_timezone_set('UTC');
422 552
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
423
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
553
+	if (!isset($last_exec[$id]['last'])) {
554
+		$last_exec[$id]['last'] = 0;
555
+	}
424 556
 	if ($value['format'] == 'deltadbtxt' && 
425 557
 	    (
426 558
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -429,7 +561,9 @@  discard block
 block discarded – undo
429 561
 	) {
430 562
 	    //$buffer = $Common->getData($hosts[$id]);
431 563
 	    $buffer = $Common->getData($value['host']);
432
-	    if ($buffer != '') $reset = 0;
564
+	    if ($buffer != '') {
565
+	    	$reset = 0;
566
+	    }
433 567
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434 568
 	    $buffer = explode('\n',$buffer);
435 569
 	    foreach ($buffer as $line) {
@@ -438,20 +572,41 @@  discard block
 block discarded – undo
438 572
 	            $data = array();
439 573
 	            $data['hex'] = $line[1]; // hex
440 574
 	            $data['ident'] = $line[2]; // ident
441
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
442
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
443
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
444
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
445
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
575
+	            if (isset($line[3])) {
576
+	            	$data['altitude'] = $line[3];
577
+	            }
578
+	            // altitude
579
+	            if (isset($line[4])) {
580
+	            	$data['speed'] = $line[4];
581
+	            }
582
+	            // speed
583
+	            if (isset($line[5])) {
584
+	            	$data['heading'] = $line[5];
585
+	            }
586
+	            // heading
587
+	            if (isset($line[6])) {
588
+	            	$data['latitude'] = $line[6];
589
+	            }
590
+	            // lat
591
+	            if (isset($line[7])) {
592
+	            	$data['longitude'] = $line[7];
593
+	            }
594
+	            // long
446 595
 	            $data['verticalrate'] = ''; // vertical rate
447 596
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
448 597
 	            $data['emergency'] = ''; // emergency
449 598
 		    $data['datetime'] = date('Y-m-d H:i:s');
450 599
 		    $data['format_source'] = 'deltadbtxt';
451 600
     		    $data['id_source'] = $id_source;
452
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
453
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
454
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
601
+		    if (isset($value['name']) && $value['name'] != '') {
602
+		    	$data['source_name'] = $value['name'];
603
+		    }
604
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
605
+		    	$data['noarchive'] = true;
606
+		    }
607
+		    if (isset($value['sourcestats'])) {
608
+		    	$data['sourcestats'] = $value['sourcestats'];
609
+		    }
455 610
     		    $SI->add($data);
456 611
 		    unset($data);
457 612
     		}
@@ -466,7 +621,9 @@  discard block
 block discarded – undo
466 621
 	    date_default_timezone_set('CET');
467 622
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
468 623
 	    date_default_timezone_set('UTC');
469
-	    if ($buffer != '') $reset = 0;
624
+	    if ($buffer != '') {
625
+	    	$reset = 0;
626
+	    }
470 627
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471 628
 	    $buffer = explode('\n',$buffer);
472 629
 	    foreach ($buffer as $line) {
@@ -475,16 +632,36 @@  discard block
 block discarded – undo
475 632
 		    $add = false;
476 633
 		    $ais_data = $AIS->parse_line(trim($line));
477 634
 		    $data = array();
478
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
480
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
483
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
484
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
485
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
486
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
487
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
635
+		    if (isset($ais_data['ident'])) {
636
+		    	$data['ident'] = $ais_data['ident'];
637
+		    }
638
+		    if (isset($ais_data['mmsi'])) {
639
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
640
+		    }
641
+		    if (isset($ais_data['speed'])) {
642
+		    	$data['speed'] = $ais_data['speed'];
643
+		    }
644
+		    if (isset($ais_data['heading'])) {
645
+		    	$data['heading'] = $ais_data['heading'];
646
+		    }
647
+		    if (isset($ais_data['latitude'])) {
648
+		    	$data['latitude'] = $ais_data['latitude'];
649
+		    }
650
+		    if (isset($ais_data['longitude'])) {
651
+		    	$data['longitude'] = $ais_data['longitude'];
652
+		    }
653
+		    if (isset($ais_data['status'])) {
654
+		    	$data['status'] = $ais_data['status'];
655
+		    }
656
+		    if (isset($ais_data['type'])) {
657
+		    	$data['type'] = $ais_data['type'];
658
+		    }
659
+		    if (isset($ais_data['imo'])) {
660
+		    	$data['imo'] = $ais_data['imo'];
661
+		    }
662
+		    if (isset($ais_data['callsign'])) {
663
+		    	$data['callsign'] = $ais_data['callsign'];
664
+		    }
488 665
 		    if (isset($ais_data['timestamp'])) {
489 666
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
490 667
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -498,8 +675,12 @@  discard block
 block discarded – undo
498 675
 		    $data['format_source'] = 'aisnmeatxt';
499 676
     		    $data['id_source'] = $id_source;
500 677
 		    //print_r($data);
501
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
502
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
678
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
679
+		    	$data['noarchive'] = true;
680
+		    }
681
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
682
+		    	$MI->add($data);
683
+		    }
503 684
 		    unset($data);
504 685
 		}
505 686
     	    }
@@ -522,20 +703,48 @@  discard block
 block discarded – undo
522 703
 			    if ($line != '') {
523 704
 				$ais_data = $AIS->parse_line(trim($line));
524 705
 				$data = array();
525
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
526
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
527
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
528
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
529
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
530
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
531
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
532
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
533
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
534
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
535
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
536
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
537
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
538
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
706
+				if (isset($ais_data['ident'])) {
707
+					$data['ident'] = $ais_data['ident'];
708
+				}
709
+				if (isset($ais_data['mmsi'])) {
710
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
711
+				}
712
+				if (isset($ais_data['speed'])) {
713
+					$data['speed'] = $ais_data['speed'];
714
+				}
715
+				if (isset($ais_data['heading'])) {
716
+					$data['heading'] = $ais_data['heading'];
717
+				}
718
+				if (isset($ais_data['latitude'])) {
719
+					$data['latitude'] = $ais_data['latitude'];
720
+				}
721
+				if (isset($ais_data['longitude'])) {
722
+					$data['longitude'] = $ais_data['longitude'];
723
+				}
724
+				if (isset($ais_data['status'])) {
725
+					$data['status'] = $ais_data['status'];
726
+				}
727
+				if (isset($ais_data['statusid'])) {
728
+					$data['status_id'] = $ais_data['statusid'];
729
+				}
730
+				if (isset($ais_data['type'])) {
731
+					$data['type'] = $ais_data['type'];
732
+				}
733
+				if (isset($ais_data['typeid'])) {
734
+					$data['type_id'] = $ais_data['typeid'];
735
+				}
736
+				if (isset($ais_data['imo'])) {
737
+					$data['imo'] = $ais_data['imo'];
738
+				}
739
+				if (isset($ais_data['callsign'])) {
740
+					$data['callsign'] = $ais_data['callsign'];
741
+				}
742
+				if (isset($ais_data['destination'])) {
743
+					$data['arrival_code'] = $ais_data['destination'];
744
+				}
745
+				if (isset($ais_data['eta_ts'])) {
746
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
747
+				}
539 748
 				if (isset($ais_data['timestamp'])) {
540 749
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
541 750
 				} else {
@@ -543,18 +752,27 @@  discard block
 block discarded – undo
543 752
 				}
544 753
 				$data['format_source'] = 'aisnmeahttp';
545 754
 				$data['id_source'] = $id_source;
546
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
547
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
755
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
756
+					$data['noarchive'] = true;
757
+				}
758
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
759
+					$MI->add($data);
760
+				}
548 761
 				unset($data);
549 762
 			    }
550 763
 			}
551 764
 		    }
552 765
 		} else {
553 766
 		    $format = $value['format'];
554
-		    if (isset($tt[$format])) $tt[$format]++;
555
-		    else $tt[$format] = 0;
767
+		    if (isset($tt[$format])) {
768
+		    	$tt[$format]++;
769
+		    } else {
770
+		    	$tt[$format] = 0;
771
+		    }
556 772
 		    if ($tt[$format] > 30) {
557
-			if ($globalDebug) echo 'Reconnect...'."\n";
773
+			if ($globalDebug) {
774
+				echo 'Reconnect...'."\n";
775
+			}
558 776
 			sleep(2);
559 777
 			//$sourceeen[] = $value;
560 778
 			//connect_all($sourceeen);
@@ -590,12 +808,18 @@  discard block
 block discarded – undo
590 808
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
591 809
 			    $data['type_id'] = $line['TYPE'];
592 810
 			    $data['imo'] = $line['IMO'];
593
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
594
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
811
+			    if ($line['DEST'] != '') {
812
+			    	$data['arrival_code'] = $line['DEST'];
813
+			    }
814
+			    if ($line['ARV'] != '') {
815
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
816
+			    }
595 817
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
596 818
 			    $data['format_source'] = 'myshiptracking';
597 819
 			    $data['id_source'] = $id_source;
598
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
820
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
821
+			    	$data['noarchive'] = true;
822
+			    }
599 823
 			    $MI->add($data);
600 824
 			    unset($data);
601 825
 			}
@@ -620,7 +844,9 @@  discard block
 block discarded – undo
620 844
 			    $data['callsign'] = $line['callsign'];
621 845
 			    $data['mmsi'] = substr($line['mmsi'],-9);
622 846
 			    $data['speed'] = $line['sog'];
623
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
847
+			    if ($line['heading'] != '511') {
848
+			    	$data['heading'] = $line['heading'];
849
+			    }
624 850
 			    $data['latitude'] = $line['latitude'];
625 851
 			    $data['longitude'] = $line['longitude'];
626 852
 			    $data['type_id'] = $line['shiptype'];
@@ -628,7 +854,9 @@  discard block
 block discarded – undo
628 854
 			    $data['datetime'] = $line['time'];
629 855
 			    $data['format_source'] = 'boatbeaconapp';
630 856
 			    $data['id_source'] = $id_source;
631
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
857
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
858
+			    	$data['noarchive'] = true;
859
+			    }
632 860
 			    $MI->add($data);
633 861
 			    unset($data);
634 862
 			}
@@ -650,22 +878,44 @@  discard block
 block discarded – undo
650 878
 		    foreach ($all_data['features'] as $line) {
651 879
 			print_r($line);
652 880
 			$data = array();
653
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
654
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
655
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
656
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
657
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
658
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
881
+			if (isset($line['properties']['name'])) {
882
+				$data['ident'] = $line['properties']['name'];
883
+			}
884
+			if (isset($line['properties']['callsign'])) {
885
+				$data['callsign'] = $line['properties']['callsign'];
886
+			}
887
+			if (isset($line['properties']['mmsi'])) {
888
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
889
+			}
890
+			if (isset($line['properties']['imo'])) {
891
+				$data['imo'] = $line['properties']['imo'];
892
+			}
893
+			if (isset($line['properties']['speed'])) {
894
+				$data['speed'] = $line['properties']['speed'];
895
+			}
896
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
897
+				$data['heading'] = $line['properties']['heading'];
898
+			}
659 899
 			$data['latitude'] = $line['geometry']['coordinates'][1];
660 900
 			$data['longitude'] = $line['geometry']['coordinates'][0];
661
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
662
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
663
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
901
+			if (isset($line['properties']['vesselType'])) {
902
+				$data['type'] = $line['properties']['vesselType'];
903
+			}
904
+			if (isset($line['properties']['destination'])) {
905
+				$data['arrival_code'] = $line['properties']['destination'];
906
+			}
907
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
908
+				$data['arrival_date'] = $line['properties']['eta'];
909
+			}
664 910
 			$data['format_source'] = 'boatnerd';
665 911
 			$data['id_source'] = $id_source;
666 912
 			$data['datetime'] = date('Y-m-d H:i:s');
667
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
668
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
913
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
914
+				$data['noarchive'] = true;
915
+			}
916
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
917
+				$MI->add($data);
918
+			}
669 919
 			unset($data);
670 920
 		    }
671 921
 		}
@@ -682,7 +932,9 @@  discard block
 block discarded – undo
682 932
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
683 933
 	    echo 'done !'."\n";
684 934
 	    // FIXME: Need more work
685
-	    if ($buffer != '') $reset = 0;
935
+	    if ($buffer != '') {
936
+	    	$reset = 0;
937
+	    }
686 938
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
687 939
 	    $buffer = explode('\n',$buffer);
688 940
 	    foreach ($buffer as $line) {
@@ -708,7 +960,9 @@  discard block
 block discarded – undo
708 960
 		    //$data['etaTime'] = substr($line,135,5);
709 961
 		    $data['format_source'] = 'shipplotter';
710 962
     		    $data['id_source'] = $id_source;
711
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
963
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
964
+		    	$data['noarchive'] = true;
965
+		    }
712 966
 		    //print_r($data);
713 967
 		    echo 'Add...'."\n";
714 968
 		    $MI->add($data);
@@ -742,16 +996,28 @@  discard block
 block discarded – undo
742 996
     		    $line = explode(':', $line);
743 997
     		    if (count($line) > 30 && $line[0] != 'callsign') {
744 998
 			$data = array();
745
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
746
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
999
+			if (isset($line[37]) && $line[37] != '') {
1000
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1001
+			} else {
1002
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1003
+			}
747 1004
 			$data['pilot_id'] = $line[1];
748 1005
 			$data['pilot_name'] = $line[2];
749 1006
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
750 1007
 			$data['ident'] = $line[0]; // ident
751
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1008
+			if ($line[7] != '' && $line[7] != 0) {
1009
+				$data['altitude'] = $line[7];
1010
+			}
1011
+			// altitude
752 1012
 			$data['speed'] = $line[8]; // speed
753
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
754
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1013
+			if (isset($line[45])) {
1014
+				$data['heading'] = $line[45];
1015
+			}
1016
+			// heading
1017
+			elseif (isset($line[38])) {
1018
+				$data['heading'] = $line[38];
1019
+			}
1020
+			// heading
755 1021
 			$data['latitude'] = $line[5]; // lat
756 1022
 	        	$data['longitude'] = $line[6]; // long
757 1023
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -767,7 +1033,9 @@  discard block
 block discarded – undo
767 1033
 			$data['frequency'] = $line[4];
768 1034
 			$data['type'] = $line[18];
769 1035
 			$data['range'] = $line[19];
770
-			if (isset($line[35])) $data['info'] = $line[35];
1036
+			if (isset($line[35])) {
1037
+				$data['info'] = $line[35];
1038
+			}
771 1039
     			$data['id_source'] = $id_source;
772 1040
 	    		//$data['arrival_airport_time'] = ;
773 1041
 	    		if ($line[9] != '') {
@@ -781,27 +1049,47 @@  discard block
 block discarded – undo
781 1049
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
782 1050
 	    		*/
783 1051
 	    		$data['format_source'] = $value['format'];
784
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
785
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
786
-    			if ($line[3] == 'PILOT') $SI->add($data);
787
-			elseif ($line[3] == 'ATC') {
1052
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1053
+				$data['noarchive'] = true;
1054
+			}
1055
+			if (isset($value['name']) && $value['name'] != '') {
1056
+				$data['source_name'] = $value['name'];
1057
+			}
1058
+    			if ($line[3] == 'PILOT') {
1059
+    				$SI->add($data);
1060
+    			} elseif ($line[3] == 'ATC') {
788 1061
 				//print_r($data);
789 1062
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
790 1063
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
791 1064
 				$typec = substr($data['ident'],-3);
792
-				if ($typec == 'APP') $data['type'] = 'Approach';
793
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
794
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
795
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
796
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
797
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
798
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
799
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
800
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
801
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1065
+				if ($typec == 'APP') {
1066
+					$data['type'] = 'Approach';
1067
+				} elseif ($typec == 'TWR') {
1068
+					$data['type'] = 'Tower';
1069
+				} elseif ($typec == 'OBS') {
1070
+					$data['type'] = 'Observer';
1071
+				} elseif ($typec == 'GND') {
1072
+					$data['type'] = 'Ground';
1073
+				} elseif ($typec == 'DEL') {
1074
+					$data['type'] = 'Delivery';
1075
+				} elseif ($typec == 'DEP') {
1076
+					$data['type'] = 'Departure';
1077
+				} elseif ($typec == 'FSS') {
1078
+					$data['type'] = 'Flight Service Station';
1079
+				} elseif ($typec == 'CTR') {
1080
+					$data['type'] = 'Control Radar or Centre';
1081
+				} elseif ($data['type'] == '') {
1082
+					$data['type'] = 'Observer';
1083
+				}
1084
+				if (!isset($data['source_name'])) {
1085
+					$data['source_name'] = '';
1086
+				}
802 1087
 				if (isset($ATC)) {
803
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
804
-					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']);
1088
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1089
+						echo $ATC->update($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']);
1090
+					} else {
1091
+						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']);
1092
+					}
805 1093
 				}
806 1094
 			}
807 1095
     			unset($data);
@@ -828,14 +1116,20 @@  discard block
 block discarded – undo
828 1116
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
829 1117
 			$data['latitude'] = (float)$line['pktLatitude'];
830 1118
 			$data['longitude'] = (float)$line['pktLongitude'];
831
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
832
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1119
+			if ((float)$line['pktTrack'] != 0) {
1120
+				$data['heading'] = (float)$line['pktTrack'];
1121
+			}
1122
+			if ((int)$line['pktSpeed'] != 0) {
1123
+				$data['speed'] = (int)$line['pktSpeed'];
1124
+			}
833 1125
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
834 1126
 			$data['altitude_relative'] = 'AMSL';
835 1127
 			$data['pilot_id'] = (int)$line['pktPilotID'];
836 1128
 			$data['aircraft_icao'] = 'PARAGLIDER';
837 1129
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
838
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1130
+			if (isset($pilot_data[4])) {
1131
+				$data['pilot_name'] = $pilot_data[4];
1132
+			}
839 1133
 			$data['format_source'] = $value['format'];
840 1134
 			$SI->add($data);
841 1135
 			unset($data);
@@ -883,25 +1177,59 @@  discard block
 block discarded – undo
883 1177
 		    foreach ($all_data['acList'] as $line) {
884 1178
 			$data = array();
885 1179
 			$data['hex'] = $line['Icao']; // hex
886
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
887
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
888
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
889
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
890
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
891
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1180
+			if (isset($line['Call'])) {
1181
+				$data['ident'] = $line['Call'];
1182
+			}
1183
+			// ident
1184
+			if (isset($line['Alt'])) {
1185
+				$data['altitude'] = $line['Alt'];
1186
+			}
1187
+			// altitude
1188
+			if (isset($line['Spd'])) {
1189
+				$data['speed'] = $line['Spd'];
1190
+			}
1191
+			// speed
1192
+			if (isset($line['Trak'])) {
1193
+				$data['heading'] = $line['Trak'];
1194
+			}
1195
+			// heading
1196
+			if (isset($line['Lat'])) {
1197
+				$data['latitude'] = $line['Lat'];
1198
+			}
1199
+			// lat
1200
+			if (isset($line['Long'])) {
1201
+				$data['longitude'] = $line['Long'];
1202
+			}
1203
+			// long
892 1204
 			//$data['verticalrate'] = $line['']; // verticale rate
893
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1205
+			if (isset($line['Sqk'])) {
1206
+				$data['squawk'] = $line['Sqk'];
1207
+			}
1208
+			// squawk
894 1209
 			$data['emergency'] = ''; // emergency
895
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
896
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
897
-			else $data['datetime'] = date('Y-m-d H:i:s');
1210
+			if (isset($line['Reg'])) {
1211
+				$data['registration'] = $line['Reg'];
1212
+			}
1213
+			if (isset($line['PosTime'])) {
1214
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1215
+			} else {
1216
+				$data['datetime'] = date('Y-m-d H:i:s');
1217
+			}
898 1218
 			//$data['datetime'] = date('Y-m-d H:i:s');
899
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1219
+			if (isset($line['Type'])) {
1220
+				$data['aircraft_icao'] = $line['Type'];
1221
+			}
900 1222
 			$data['format_source'] = 'aircraftlistjson';
901 1223
 			$data['id_source'] = $id_source;
902
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
903
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
904
-			if (isset($data['latitude'])) $SI->add($data);
1224
+			if (isset($value['name']) && $value['name'] != '') {
1225
+				$data['source_name'] = $value['name'];
1226
+			}
1227
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1228
+				$data['noarchive'] = true;
1229
+			}
1230
+			if (isset($data['latitude'])) {
1231
+				$SI->add($data);
1232
+			}
905 1233
 			unset($data);
906 1234
 		    }
907 1235
 		} elseif (is_array($all_data)) {
@@ -918,17 +1246,26 @@  discard block
 block discarded – undo
918 1246
 			$data['verticalrate'] = $line['vrt']; // verticale rate
919 1247
 			$data['squawk'] = $line['squawk']; // squawk
920 1248
 			$data['emergency'] = ''; // emergency
921
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
922
-			else $data['datetime'] = date('Y-m-d H:i:s');
1249
+			if (isset($line['PosTime'])) {
1250
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1251
+			} else {
1252
+				$data['datetime'] = date('Y-m-d H:i:s');
1253
+			}
923 1254
 			$data['format_source'] = 'aircraftlistjson';
924 1255
 			$data['id_source'] = $id_source;
925
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
926
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1256
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1257
+				$data['noarchive'] = true;
1258
+			}
1259
+			if (isset($value['name']) && $value['name'] != '') {
1260
+				$data['source_name'] = $value['name'];
1261
+			}
927 1262
 			$SI->add($data);
928 1263
 			unset($data);
929 1264
 		    }
930 1265
 		}
931
-	    } elseif ($globalDebug) echo 'No data'."\n";
1266
+	    } elseif ($globalDebug) {
1267
+	    	echo 'No data'."\n";
1268
+	    }
932 1269
     	    //$last_exec['aircraftlistjson'] = time();
933 1270
     	    $last_exec[$id]['last'] = time();
934 1271
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -964,8 +1301,12 @@  discard block
 block discarded – undo
964 1301
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
965 1302
 	    	    $data['format_source'] = 'planeupdatefaa';
966 1303
     		    $data['id_source'] = $id_source;
967
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
968
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1304
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1305
+		    	$data['noarchive'] = true;
1306
+		    }
1307
+		    if (isset($value['name']) && $value['name'] != '') {
1308
+		    	$data['source_name'] = $value['name'];
1309
+		    }
969 1310
 		    $SI->add($data);
970 1311
 		    unset($data);
971 1312
 		}
@@ -999,7 +1340,9 @@  discard block
 block discarded – undo
999 1340
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1000 1341
 		    $data['format_source'] = 'opensky';
1001 1342
 		    $data['id_source'] = $id_source;
1002
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1343
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1344
+		    	$data['noarchive'] = true;
1345
+		    }
1003 1346
 		    $SI->add($data);
1004 1347
 		    unset($data);
1005 1348
 		}
@@ -1016,7 +1359,9 @@  discard block
 block discarded – undo
1016 1359
 	    //$buffer = $Common->getData($hosts[$id]);
1017 1360
 	    $buffer = $Common->getData($value['host']);
1018 1361
 	    $all_data = json_decode($buffer,true);
1019
-	    if (!empty($all_data)) $reset = 0;
1362
+	    if (!empty($all_data)) {
1363
+	    	$reset = 0;
1364
+	    }
1020 1365
 	    foreach ($all_data as $key => $line) {
1021 1366
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1022 1367
 		    $data = array();
@@ -1037,8 +1382,12 @@  discard block
 block discarded – undo
1037 1382
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1038 1383
 	    	    $data['format_source'] = 'fr24json';
1039 1384
     		    $data['id_source'] = $id_source;
1040
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1041
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1385
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1386
+		    	$data['noarchive'] = true;
1387
+		    }
1388
+		    if (isset($value['name']) && $value['name'] != '') {
1389
+		    	$data['source_name'] = $value['name'];
1390
+		    }
1042 1391
 		    $SI->add($data);
1043 1392
 		    unset($data);
1044 1393
 		}
@@ -1067,24 +1416,42 @@  discard block
 block discarded – undo
1067 1416
 		    if (isset($line['inf'])) {
1068 1417
 			$data = array();
1069 1418
 			$data['hex'] = $line['inf']['ia'];
1070
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1419
+			if (isset($line['inf']['cs'])) {
1420
+				$data['ident'] = $line['inf']['cs'];
1421
+			}
1422
+			//$line[13]
1071 1423
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1072
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1073
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1424
+	    		if (isset($line['inf']['gs'])) {
1425
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1426
+	    		}
1427
+	    		// speed
1428
+	    		if (isset($line['inf']['tr'])) {
1429
+	    			$data['heading'] = $line['inf']['tr'];
1430
+	    		}
1431
+	    		// heading
1074 1432
 	    		$data['latitude'] = $line['pt'][0]; // lat
1075 1433
 	    		$data['longitude'] = $line['pt'][1]; // long
1076 1434
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1077
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1435
+	    		if (isset($line['inf']['sq'])) {
1436
+	    			$data['squawk'] = $line['inf']['sq'];
1437
+	    		}
1438
+	    		// squawk
1078 1439
 	    		//$data['aircraft_icao'] = $line[8];
1079
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1440
+	    		if (isset($line['inf']['rc'])) {
1441
+	    			$data['registration'] = $line['inf']['rc'];
1442
+	    		}
1080 1443
 			//$data['departure_airport_iata'] = $line[11];
1081 1444
 			//$data['arrival_airport_iata'] = $line[12];
1082 1445
 	    		//$data['emergency'] = ''; // emergency
1083 1446
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1084 1447
 	    		$data['format_source'] = 'radarvirtueljson';
1085 1448
     			$data['id_source'] = $id_source;
1086
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1087
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1449
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1450
+				$data['noarchive'] = true;
1451
+			}
1452
+			if (isset($value['name']) && $value['name'] != '') {
1453
+				$data['source_name'] = $value['name'];
1454
+			}
1088 1455
 			$SI->add($data);
1089 1456
 			unset($data);
1090 1457
 		    }
@@ -1110,30 +1477,65 @@  discard block
 block discarded – undo
1110 1477
 		    $data['id'] = $line['id'];
1111 1478
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1112 1479
 		    $data['ident'] = $line['callsign']; // ident
1113
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1114
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1115
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1116
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1117
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1118
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1480
+		    if (isset($line['pilotid'])) {
1481
+		    	$data['pilot_id'] = $line['pilotid'];
1482
+		    }
1483
+		    // pilot id
1484
+		    if (isset($line['name'])) {
1485
+		    	$data['pilot_name'] = $line['name'];
1486
+		    }
1487
+		    // pilot name
1488
+		    if (isset($line['alt'])) {
1489
+		    	$data['altitude'] = $line['alt'];
1490
+		    }
1491
+		    // altitude
1492
+		    if (isset($line['gs'])) {
1493
+		    	$data['speed'] = $line['gs'];
1494
+		    }
1495
+		    // speed
1496
+		    if (isset($line['heading'])) {
1497
+		    	$data['heading'] = $line['heading'];
1498
+		    }
1499
+		    // heading
1500
+		    if (isset($line['route'])) {
1501
+		    	$data['waypoints'] = $line['route'];
1502
+		    }
1503
+		    // route
1119 1504
 		    $data['latitude'] = $line['lat']; // lat
1120 1505
 		    $data['longitude'] = $line['lon']; // long
1121 1506
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1122 1507
 		    //$data['squawk'] = $line['squawk']; // squawk
1123 1508
 		    //$data['emergency'] = ''; // emergency
1124
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1125
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1126
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1509
+		    if (isset($line['depicao'])) {
1510
+		    	$data['departure_airport_icao'] = $line['depicao'];
1511
+		    }
1512
+		    if (isset($line['deptime'])) {
1513
+		    	$data['departure_airport_time'] = $line['deptime'];
1514
+		    }
1515
+		    if (isset($line['arricao'])) {
1516
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1517
+		    }
1127 1518
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1128
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1129
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1130
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1131
-		    else $data['info'] = '';
1519
+		    if (isset($line['aircraft'])) {
1520
+		    	$data['aircraft_icao'] = $line['aircraft'];
1521
+		    }
1522
+		    if (isset($line['transponder'])) {
1523
+		    	$data['squawk'] = $line['transponder'];
1524
+		    }
1525
+		    if (isset($line['atis'])) {
1526
+		    	$data['info'] = $line['atis'];
1527
+		    } else {
1528
+		    	$data['info'] = '';
1529
+		    }
1132 1530
 		    $data['format_source'] = 'pireps';
1133 1531
     		    $data['id_source'] = $id_source;
1134 1532
 		    $data['datetime'] = date('Y-m-d H:i:s');
1135
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1136
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1533
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1534
+		    	$data['noarchive'] = true;
1535
+		    }
1536
+		    if (isset($value['name']) && $value['name'] != '') {
1537
+		    	$data['source_name'] = $value['name'];
1538
+		    }
1137 1539
 		    if ($line['icon'] == 'plane') {
1138 1540
 			$SI->add($data);
1139 1541
 		    //    print_r($data);
@@ -1142,16 +1544,28 @@  discard block
 block discarded – undo
1142 1544
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1143 1545
 			$typec = substr($data['ident'],-3);
1144 1546
 			$data['type'] = '';
1145
-			if ($typec == 'APP') $data['type'] = 'Approach';
1146
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1147
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1148
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1149
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1150
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1151
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1152
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1153
-			else $data['type'] = 'Observer';
1154
-			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']);
1547
+			if ($typec == 'APP') {
1548
+				$data['type'] = 'Approach';
1549
+			} elseif ($typec == 'TWR') {
1550
+				$data['type'] = 'Tower';
1551
+			} elseif ($typec == 'OBS') {
1552
+				$data['type'] = 'Observer';
1553
+			} elseif ($typec == 'GND') {
1554
+				$data['type'] = 'Ground';
1555
+			} elseif ($typec == 'DEL') {
1556
+				$data['type'] = 'Delivery';
1557
+			} elseif ($typec == 'DEP') {
1558
+				$data['type'] = 'Departure';
1559
+			} elseif ($typec == 'FSS') {
1560
+				$data['type'] = 'Flight Service Station';
1561
+			} elseif ($typec == 'CTR') {
1562
+				$data['type'] = 'Control Radar or Centre';
1563
+			} else {
1564
+				$data['type'] = 'Observer';
1565
+			}
1566
+			if (isset($ATC)) {
1567
+				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']);
1568
+			}
1155 1569
 		    }
1156 1570
 		    unset($data);
1157 1571
 		}
@@ -1166,7 +1580,9 @@  discard block
 block discarded – undo
1166 1580
 	    )
1167 1581
 	) {
1168 1582
 	    //$buffer = $Common->getData($hosts[$id]);
1169
-	    if ($globalDebug) echo 'Get Data...'."\n";
1583
+	    if ($globalDebug) {
1584
+	    	echo 'Get Data...'."\n";
1585
+	    }
1170 1586
 	    $buffer = $Common->getData($value['host']);
1171 1587
 	    $all_data = json_decode($buffer,true);
1172 1588
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1174,10 +1590,16 @@  discard block
 block discarded – undo
1174 1590
 		foreach ($all_data as $line) {
1175 1591
 	    	    $data = array();
1176 1592
 	    	    //$data['id'] = $line['id']; // id not usable
1177
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1593
+	    	    if (isset($line['pilotid'])) {
1594
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1595
+	    	    }
1178 1596
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1179
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1180
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1597
+	    	    if (isset($line['pilotname'])) {
1598
+	    	    	$data['pilot_name'] = $line['pilotname'];
1599
+	    	    }
1600
+	    	    if (isset($line['pilotid'])) {
1601
+	    	    	$data['pilot_id'] = $line['pilotid'];
1602
+	    	    }
1181 1603
 	    	    $data['ident'] = $line['flightnum']; // ident
1182 1604
 	    	    $data['altitude'] = $line['alt']; // altitude
1183 1605
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1193,7 +1615,9 @@  discard block
 block discarded – undo
1193 1615
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1194 1616
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1195 1617
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1196
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1618
+	    	    } else {
1619
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1620
+	    	    }
1197 1621
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1198 1622
 	    	    $data['departure_airport_time'] = $line['deptime'];
1199 1623
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1201,29 +1625,47 @@  discard block
 block discarded – undo
1201 1625
     		    if (isset($line['registration'])) {
1202 1626
     			$data['registration'] = $line['registration'];
1203 1627
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1204
-    		    } else $data['registration'] = $line['aircraft'];
1205
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1206
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1628
+    		    } else {
1629
+    		    	$data['registration'] = $line['aircraft'];
1630
+    		    }
1631
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1632
+		    	$data['noarchive'] = true;
1633
+		    }
1634
+		    if (isset($line['route'])) {
1635
+		    	$data['waypoints'] = $line['route'];
1636
+		    }
1637
+		    // route
1207 1638
 		    if (isset($line['aircraftname'])) {
1208 1639
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1209 1640
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1210 1641
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1211
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1212
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1213
-	    		else {
1642
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1643
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1644
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1645
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1646
+	    		} else {
1214 1647
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1215
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1216
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1648
+	    		    if (isset($aircraft_data[1])) {
1649
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1650
+	    		    } else {
1651
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1652
+	    		    }
1217 1653
 	    		}
1218 1654
 	    	    }
1219
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1655
+    		    if (isset($line['route'])) {
1656
+    		    	$data['waypoints'] = $line['route'];
1657
+    		    }
1220 1658
     		    $data['id_source'] = $id_source;
1221 1659
 	    	    $data['format_source'] = 'phpvmacars';
1222
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1660
+		    if (isset($value['name']) && $value['name'] != '') {
1661
+		    	$data['source_name'] = $value['name'];
1662
+		    }
1223 1663
 		    $SI->add($data);
1224 1664
 		    unset($data);
1225 1665
 		}
1226
-		if ($globalDebug) echo 'No more data...'."\n";
1666
+		if ($globalDebug) {
1667
+			echo 'No more data...'."\n";
1668
+		}
1227 1669
 		unset($buffer);
1228 1670
 		unset($all_data);
1229 1671
 	    }
@@ -1236,7 +1678,9 @@  discard block
 block discarded – undo
1236 1678
 	    )
1237 1679
 	) {
1238 1680
 	    //$buffer = $Common->getData($hosts[$id]);
1239
-	    if ($globalDebug) echo 'Get Data...'."\n";
1681
+	    if ($globalDebug) {
1682
+	    	echo 'Get Data...'."\n";
1683
+	    }
1240 1684
 	    $buffer = $Common->getData($value['host']);
1241 1685
 	    $all_data = json_decode($buffer,true);
1242 1686
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1247,10 +1691,16 @@  discard block
 block discarded – undo
1247 1691
 	    	    //$data['id'] = $line['id']; // id not usable
1248 1692
 	    	    $data['id'] = $line['id'];
1249 1693
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1250
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1251
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1694
+	    	    if (isset($line['user']['username'])) {
1695
+	    	    	$data['pilot_name'] = $line['user']['username'];
1696
+	    	    }
1697
+	    	    if (isset($line['user_id'])) {
1698
+	    	    	$data['pilot_id'] = $line['user_id'];
1699
+	    	    }
1252 1700
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1253
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1701
+	    	    if (is_numeric($data['ident'])) {
1702
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1703
+	    	    }
1254 1704
 	    	    $data['altitude'] = $line['altitude']; // altitude
1255 1705
 	    	    $data['speed'] = $line['groundspeed']; // speed
1256 1706
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1263,7 +1713,9 @@  discard block
 block discarded – undo
1263 1713
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1264 1714
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1265 1715
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1266
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1716
+	    	    } else {
1717
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1718
+	    	    }
1267 1719
 	    	    
1268 1720
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1269 1721
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1271,17 +1723,26 @@  discard block
 block discarded – undo
1271 1723
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1272 1724
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1273 1725
 
1274
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1275
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1726
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1727
+		    	$data['noarchive'] = true;
1728
+		    }
1729
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1730
+		    	$data['waypoints'] = $line['bid']['route'];
1731
+		    }
1732
+		    // route
1276 1733
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1277 1734
 
1278 1735
     		    $data['id_source'] = $id_source;
1279 1736
 	    	    $data['format_source'] = 'vaos';
1280
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1737
+		    if (isset($value['name']) && $value['name'] != '') {
1738
+		    	$data['source_name'] = $value['name'];
1739
+		    }
1281 1740
 		    $SI->add($data);
1282 1741
 		    unset($data);
1283 1742
 		}
1284
-		if ($globalDebug) echo 'No more data...'."\n";
1743
+		if ($globalDebug) {
1744
+			echo 'No more data...'."\n";
1745
+		}
1285 1746
 		unset($buffer);
1286 1747
 		unset($all_data);
1287 1748
 	    }
@@ -1294,7 +1755,9 @@  discard block
 block discarded – undo
1294 1755
 	    )
1295 1756
 	) {
1296 1757
 	    //$buffer = $Common->getData($hosts[$id]);
1297
-	    if ($globalDebug) echo 'Get Data...'."\n";
1758
+	    if ($globalDebug) {
1759
+	    	echo 'Get Data...'."\n";
1760
+	    }
1298 1761
 	    $buffer = $Common->getData($value['host']);
1299 1762
 	    $all_data = json_decode($buffer,true);
1300 1763
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1323,16 +1786,25 @@  discard block
 block discarded – undo
1323 1786
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1324 1787
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1325 1788
     		    //$data['registration'] = $line['aircraft'];
1326
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1789
+		    if (isset($line['route'])) {
1790
+		    	$data['waypoints'] = $line['route'];
1791
+		    }
1792
+		    // route
1327 1793
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1328 1794
     		    $data['id_source'] = $id_source;
1329 1795
 	    	    $data['format_source'] = 'vam';
1330
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1331
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1796
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1797
+		    	$data['noarchive'] = true;
1798
+		    }
1799
+		    if (isset($value['name']) && $value['name'] != '') {
1800
+		    	$data['source_name'] = $value['name'];
1801
+		    }
1332 1802
 		    $SI->add($data);
1333 1803
 		    unset($data);
1334 1804
 		}
1335
-		if ($globalDebug) echo 'No more data...'."\n";
1805
+		if ($globalDebug) {
1806
+			echo 'No more data...'."\n";
1807
+		}
1336 1808
 		unset($buffer);
1337 1809
 		unset($all_data);
1338 1810
 	    }
@@ -1345,7 +1817,9 @@  discard block
 block discarded – undo
1345 1817
 	    )
1346 1818
 	) {
1347 1819
 	    //$buffer = $Common->getData($hosts[$id]);
1348
-	    if ($globalDebug) echo 'Get Data...'."\n";
1820
+	    if ($globalDebug) {
1821
+	    	echo 'Get Data...'."\n";
1822
+	    }
1349 1823
 	    $buffer = $Common->getData($value['host']);
1350 1824
 	    $all_data = json_decode($buffer,true);
1351 1825
 	    if ($buffer != '') {
@@ -1363,18 +1837,24 @@  discard block
 block discarded – undo
1363 1837
 			$data['id_source'] = $id_source;
1364 1838
 			$data['format_source'] = 'blitzortung';
1365 1839
 			$SI->add($data);
1366
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1840
+			if ($globalDebug) {
1841
+				echo '☈ Lightning added'."\n";
1842
+			}
1367 1843
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1368 1844
 			unset($data);
1369 1845
 		    }
1370 1846
 		}
1371
-		if ($globalDebug) echo 'No more data...'."\n";
1847
+		if ($globalDebug) {
1848
+			echo 'No more data...'."\n";
1849
+		}
1372 1850
 		unset($buffer);
1373 1851
 	    }
1374 1852
 	    $last_exec[$id]['last'] = time();
1375 1853
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1376 1854
 	} 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') {
1377
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1855
+	    if (function_exists('pcntl_fork')) {
1856
+	    	pcntl_signal_dispatch();
1857
+	    }
1378 1858
     	    //$last_exec[$id]['last'] = time();
1379 1859
 
1380 1860
 	    //$read = array( $sockets[$id] );
@@ -1382,7 +1862,9 @@  discard block
 block discarded – undo
1382 1862
 	    $write = NULL;
1383 1863
 	    $e = NULL;
1384 1864
 	    $n = socket_select($read, $write, $e, $timeout);
1385
-	    if ($e != NULL) var_dump($e);
1865
+	    if ($e != NULL) {
1866
+	    	var_dump($e);
1867
+	    }
1386 1868
 	    if ($n > 0) {
1387 1869
 		$reset = 0;
1388 1870
 		foreach ($read as $nb => $r) {
@@ -1404,13 +1886,17 @@  discard block
 block discarded – undo
1404 1886
 		    if ($buffer !== FALSE) {
1405 1887
 			if ($format == 'vrstcp') {
1406 1888
 			    $buffer = explode('},{',$buffer);
1407
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1889
+			} else {
1890
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1891
+			}
1408 1892
 		    }
1409 1893
 		    // SBS format is CSV format
1410 1894
 		    if ($buffer !== FALSE && $buffer !== '') {
1411 1895
 			$tt[$format] = 0;
1412 1896
 			if ($format == 'acarssbs3') {
1413
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1897
+			    if ($globalDebug) {
1898
+			    	echo 'ACARS : '.$buffer."\n";
1899
+			    }
1414 1900
 			    $ACARS->add(trim($buffer));
1415 1901
 			    $ACARS->deleteLiveAcarsData();
1416 1902
 			} elseif ($format == 'raw') {
@@ -1419,30 +1905,70 @@  discard block
 block discarded – undo
1419 1905
 			    if (is_array($data)) {
1420 1906
 				$data['datetime'] = date('Y-m-d H:i:s');
1421 1907
 				$data['format_source'] = 'raw';
1422
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1423
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1424
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1425
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1908
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1909
+					$data['source_name'] = $globalSources[$nb]['name'];
1910
+				}
1911
+				if (isset($globalSources[$nb]['sourcestats'])) {
1912
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1913
+				}
1914
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1915
+					$data['noarchive'] = true;
1916
+				}
1917
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1918
+					$SI->add($data);
1919
+				}
1426 1920
 			    }
1427 1921
 			} elseif ($format == 'ais') {
1428 1922
 			    $ais_data = $AIS->parse_line(trim($buffer));
1429 1923
 			    $data = array();
1430
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1431
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1432
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1433
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1434
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1435
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1436
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1437
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1438
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1439
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1440
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1441
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1442
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1443
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1445
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1924
+			    if (isset($ais_data['ident'])) {
1925
+			    	$data['ident'] = $ais_data['ident'];
1926
+			    }
1927
+			    if (isset($ais_data['mmsi'])) {
1928
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
1929
+			    }
1930
+			    if (isset($ais_data['speed'])) {
1931
+			    	$data['speed'] = $ais_data['speed'];
1932
+			    }
1933
+			    if (isset($ais_data['heading'])) {
1934
+			    	$data['heading'] = $ais_data['heading'];
1935
+			    }
1936
+			    if (isset($ais_data['latitude'])) {
1937
+			    	$data['latitude'] = $ais_data['latitude'];
1938
+			    }
1939
+			    if (isset($ais_data['longitude'])) {
1940
+			    	$data['longitude'] = $ais_data['longitude'];
1941
+			    }
1942
+			    if (isset($ais_data['status'])) {
1943
+			    	$data['status'] = $ais_data['status'];
1944
+			    }
1945
+			    if (isset($ais_data['statusid'])) {
1946
+			    	$data['status_id'] = $ais_data['statusid'];
1947
+			    }
1948
+			    if (isset($ais_data['type'])) {
1949
+			    	$data['type'] = $ais_data['type'];
1950
+			    }
1951
+			    if (isset($ais_data['imo'])) {
1952
+			    	$data['imo'] = $ais_data['imo'];
1953
+			    }
1954
+			    if (isset($ais_data['callsign'])) {
1955
+			    	$data['callsign'] = $ais_data['callsign'];
1956
+			    }
1957
+			    if (isset($ais_data['destination'])) {
1958
+			    	$data['arrival_code'] = $ais_data['destination'];
1959
+			    }
1960
+			    if (isset($ais_data['eta_ts'])) {
1961
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1962
+			    }
1963
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1964
+			    	$data['noarchive'] = true;
1965
+			    }
1966
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1967
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1968
+			    }
1969
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1970
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1971
+			    }
1446 1972
 
1447 1973
 			    if (isset($ais_data['timestamp'])) {
1448 1974
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1451,7 +1977,9 @@  discard block
 block discarded – undo
1451 1977
 			    }
1452 1978
 			    $data['format_source'] = 'aisnmea';
1453 1979
     			    $data['id_source'] = $id_source;
1454
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1980
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1981
+			    	$MI->add($data);
1982
+			    }
1455 1983
 			    unset($data);
1456 1984
                         } elseif ($format == 'flightgearsp') {
1457 1985
                     	    //echo $buffer."\n";
@@ -1469,12 +1997,18 @@  discard block
 block discarded – undo
1469 1997
 				$data['speed'] = round($line[5]*1.94384);
1470 1998
 				$data['datetime'] = date('Y-m-d H:i:s');
1471 1999
 				$data['format_source'] = 'flightgearsp';
1472
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1473
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2000
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2001
+					$data['noarchive'] = true;
2002
+				}
2003
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2004
+					$SI->add($data);
2005
+				}
1474 2006
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1475 2007
 			    }
1476 2008
                         } elseif ($format == 'acars') {
1477
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2009
+                    	    if ($globalDebug) {
2010
+                    	    	echo 'ACARS : '.$buffer."\n";
2011
+                    	    }
1478 2012
 			    $ACARS->add(trim($buffer));
1479 2013
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1480 2014
 			    $ACARS->deleteLiveAcarsData();
@@ -1495,8 +2029,12 @@  discard block
 block discarded – undo
1495 2029
 				    $aircraft_type = $line[10];
1496 2030
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1497 2031
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1498
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1499
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2032
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2033
+				    	$data['noarchive'] = true;
2034
+				    }
2035
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2036
+				    	$SI->add($data);
2037
+				    }
1500 2038
 				}
1501 2039
 			    }
1502 2040
 			} elseif ($format == 'beast') {
@@ -1506,28 +2044,62 @@  discard block
 block discarded – undo
1506 2044
 			    foreach($buffer as $all_data) {
1507 2045
 				$line = json_decode('{'.$all_data.'}',true);
1508 2046
 				$data = array();
1509
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1510
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1511
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1512
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1513
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1514
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1515
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2047
+				if (isset($line['Icao'])) {
2048
+					$data['hex'] = $line['Icao'];
2049
+				}
2050
+				// hex
2051
+				if (isset($line['Call'])) {
2052
+					$data['ident'] = $line['Call'];
2053
+				}
2054
+				// ident
2055
+				if (isset($line['Alt'])) {
2056
+					$data['altitude'] = $line['Alt'];
2057
+				}
2058
+				// altitude
2059
+				if (isset($line['Spd'])) {
2060
+					$data['speed'] = $line['Spd'];
2061
+				}
2062
+				// speed
2063
+				if (isset($line['Trak'])) {
2064
+					$data['heading'] = $line['Trak'];
2065
+				}
2066
+				// heading
2067
+				if (isset($line['Lat'])) {
2068
+					$data['latitude'] = $line['Lat'];
2069
+				}
2070
+				// lat
2071
+				if (isset($line['Long'])) {
2072
+					$data['longitude'] = $line['Long'];
2073
+				}
2074
+				// long
1516 2075
 				//$data['verticalrate'] = $line['']; // verticale rate
1517
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2076
+				if (isset($line['Sqk'])) {
2077
+					$data['squawk'] = $line['Sqk'];
2078
+				}
2079
+				// squawk
1518 2080
 				$data['emergency'] = ''; // emergency
1519
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2081
+				if (isset($line['Reg'])) {
2082
+					$data['registration'] = $line['Reg'];
2083
+				}
1520 2084
 				/*
1521 2085
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1522 2086
 				else $data['datetime'] = date('Y-m-d H:i:s');
1523 2087
 				*/
1524 2088
 				$data['datetime'] = date('Y-m-d H:i:s');
1525
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2089
+				if (isset($line['Type'])) {
2090
+					$data['aircraft_icao'] = $line['Type'];
2091
+				}
1526 2092
 		    		$data['format_source'] = 'vrstcp';
1527 2093
 				$data['id_source'] = $id_source;
1528
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1529
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1530
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2094
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2095
+					$data['noarchive'] = true;
2096
+				}
2097
+				if (isset($value['name']) && $value['name'] != '') {
2098
+					$data['source_name'] = $value['name'];
2099
+				}
2100
+				if (isset($data['latitude']) && isset($data['hex'])) {
2101
+					$SI->add($data);
2102
+				}
1531 2103
 				unset($data);
1532 2104
 			    }
1533 2105
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1540,22 +2112,46 @@  discard block
 block discarded – undo
1540 2112
     				$data['hex'] = $lined['hexid'];
1541 2113
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1542 2114
     				$data['datetime'] = date('Y-m-d H:i:s');;
1543
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1544
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1545
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1546
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1547
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1548
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1549
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2115
+    				if (isset($lined['ident'])) {
2116
+    					$data['ident'] = $lined['ident'];
2117
+    				}
2118
+    				if (isset($lined['lat'])) {
2119
+    					$data['latitude'] = $lined['lat'];
2120
+    				}
2121
+    				if (isset($lined['lon'])) {
2122
+    					$data['longitude'] = $lined['lon'];
2123
+    				}
2124
+    				if (isset($lined['speed'])) {
2125
+    					$data['speed'] = $lined['speed'];
2126
+    				}
2127
+    				if (isset($lined['squawk'])) {
2128
+    					$data['squawk'] = $lined['squawk'];
2129
+    				}
2130
+    				if (isset($lined['alt'])) {
2131
+    					$data['altitude'] = $lined['alt'];
2132
+    				}
2133
+    				if (isset($lined['heading'])) {
2134
+    					$data['heading'] = $lined['heading'];
2135
+    				}
1550 2136
     				$data['id_source'] = $id_source;
1551 2137
     				$data['format_source'] = 'tsv';
1552
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1553
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1554
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1555
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2138
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2139
+    					$data['source_name'] = $globalSources[$nb]['name'];
2140
+    				}
2141
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2142
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2143
+    				}
2144
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2145
+					$data['noarchive'] = true;
2146
+				}
2147
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2148
+    					$SI->add($data);
2149
+    				}
1556 2150
     				unset($lined);
1557 2151
     				unset($data);
1558
-    			    } else $error = true;
2152
+    			    } else {
2153
+    			    	$error = true;
2154
+    			    }
1559 2155
 			} elseif ($format == 'aprs' && $use_aprs) {
1560 2156
 			    if ($aprs_connect == 0) {
1561 2157
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1581,63 +2177,121 @@  discard block
 block discarded – undo
1581 2177
 				    $aprs_last_tx = time();
1582 2178
 				    $data = array();
1583 2179
 				    //print_r($line);
1584
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1585
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1586
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1587
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1588
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1589
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1590
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1591
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1592
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1593
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2180
+				    if (isset($line['address'])) {
2181
+				    	$data['hex'] = $line['address'];
2182
+				    }
2183
+				    if (isset($line['mmsi'])) {
2184
+				    	$data['mmsi'] = $line['mmsi'];
2185
+				    }
2186
+				    if (isset($line['imo'])) {
2187
+				    	$data['imo'] = $line['imo'];
2188
+				    }
2189
+				    if (isset($line['squawk'])) {
2190
+				    	$data['squawk'] = $line['squawk'];
2191
+				    }
2192
+				    if (isset($line['arrival_code'])) {
2193
+				    	$data['arrival_code'] = $line['arrival_code'];
2194
+				    }
2195
+				    if (isset($line['arrival_date'])) {
2196
+				    	$data['arrival_date'] = $line['arrival_date'];
2197
+				    }
2198
+				    if (isset($line['type_id'])) {
2199
+				    	$data['type_id'] = $line['typeid'];
2200
+				    }
2201
+				    if (isset($line['status_id'])) {
2202
+				    	$data['status_id'] = $line['statusid'];
2203
+				    }
2204
+				    if (isset($line['timestamp'])) {
2205
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2206
+				    } else {
2207
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2208
+				    }
1594 2209
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1595
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2210
+				    if (isset($line['ident'])) {
2211
+				    	$data['ident'] = $line['ident'];
2212
+				    }
1596 2213
 				    $data['latitude'] = $line['latitude'];
1597 2214
 				    $data['longitude'] = $line['longitude'];
1598 2215
 				    //$data['verticalrate'] = $line[16];
1599
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2216
+				    if (isset($line['speed'])) {
2217
+				    	$data['speed'] = $line['speed'];
2218
+				    }
1600 2219
 				    //else $data['speed'] = 0;
1601
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1602
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1603
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2220
+				    if (isset($line['altitude'])) {
2221
+				    	$data['altitude'] = $line['altitude'];
2222
+				    }
2223
+				    if (isset($line['comment'])) {
2224
+				    	$data['comment'] = $line['comment'];
2225
+				    }
2226
+				    if (isset($line['symbol'])) {
2227
+				    	$data['type'] = $line['symbol'];
2228
+				    }
1604 2229
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1605 2230
 				    
1606
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2231
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2232
+				    	$data['heading'] = $line['heading'];
2233
+				    }
1607 2234
 				    //else echo 'No heading...'."\n";
1608 2235
 				    //else $data['heading'] = 0;
1609
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2236
+				    if (isset($line['stealth'])) {
2237
+				    	$data['aircraft_type'] = $line['stealth'];
2238
+				    }
1610 2239
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1611
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1612
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1613
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1614
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2240
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2241
+				    	$data['noarchive'] = true;
2242
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2243
+				    	$data['noarchive'] = false;
2244
+				    }
2245
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2246
+				    	$data['noarchive'] = true;
2247
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2248
+				    	$data['noarchive'] = false;
2249
+				    }
1615 2250
     				    $data['id_source'] = $id_source;
1616
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1617
-				    else $data['format_source'] = 'aprs';
2251
+    				    if (isset($line['format_source'])) {
2252
+    				    	$data['format_source'] = $line['format_source'];
2253
+    				    } else {
2254
+				    	$data['format_source'] = 'aprs';
2255
+				    }
1618 2256
 				    $data['source_name'] = $line['source'];
1619
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1620
-				    else $data['source_type'] = 'flarm';
1621
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2257
+				    if (isset($line['source_type'])) {
2258
+				    	$data['source_type'] = $line['source_type'];
2259
+				    } else {
2260
+				    	$data['source_type'] = 'flarm';
2261
+				    }
2262
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2263
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2264
+    				    }
1622 2265
 				    $currentdate = date('Y-m-d H:i:s');
1623 2266
 				    $aprsdate = strtotime($data['datetime']);
1624
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2267
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2268
+				    	$data['altitude_relative'] = 'AMSL';
2269
+				    }
1625 2270
 				    // Accept data if time <= system time + 20s
1626 2271
 				    //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'])))) {
1627 2272
 				    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'])))) {
1628 2273
 					$send = $SI->add($data);
1629 2274
 				    } elseif ($data['source_type'] == 'ais') {
1630 2275
 					$data['type'] = '';
1631
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2276
+					if (isset($globalMarine) && $globalMarine) {
2277
+						$send = $MI->add($data);
2278
+					}
1632 2279
 				    } elseif (isset($line['stealth'])) {
1633
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1634
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2280
+					if ($line['stealth'] != 0) {
2281
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2282
+					} else {
2283
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2284
+					}
1635 2285
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1636 2286
 					    //$line['symbol'] == 'Balloon' ||
1637 2287
 					    $line['symbol'] == 'Glider' || 
1638 2288
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1639
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1640
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2289
+					    if ($line['symbol'] == 'Ballon') {
2290
+					    	$data['aircraft_icao'] = 'BALL';
2291
+					    }
2292
+					    if ($line['symbol'] == 'Glider') {
2293
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2294
+					    }
1641 2295
 					    $send = $SI->add($data);
1642 2296
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1643 2297
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1668,9 +2322,13 @@  discard block
 block discarded – undo
1668 2322
 				    //} 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') {
1669 2323
 				//    } 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') {
1670 2324
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1671
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2325
+					if (isset($globalTracker) && $globalTracker) {
2326
+						$send = $TI->add($data);
2327
+					}
1672 2328
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1673
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2329
+					if (!isset($data['altitude'])) {
2330
+						$data['altitude'] = 0;
2331
+					}
1674 2332
 					$Source->deleteOldLocationByType('gs');
1675 2333
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1676 2334
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1679,7 +2337,9 @@  discard block
 block discarded – undo
1679 2337
 					}
1680 2338
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1681 2339
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1682
-					if ($globalDebug) echo '# Weather Station added'."\n";
2340
+					if ($globalDebug) {
2341
+						echo '# Weather Station added'."\n";
2342
+					}
1683 2343
 					$Source->deleteOldLocationByType('wx');
1684 2344
 					$weather_data = json_encode($line);
1685 2345
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1689,7 +2349,9 @@  discard block
 block discarded – undo
1689 2349
 					}
1690 2350
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1691 2351
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1692
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2352
+					if ($globalDebug) {
2353
+						echo '☈ Lightning added'."\n";
2354
+					}
1693 2355
 					$Source->deleteOldLocationByType('lightning');
1694 2356
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1695 2357
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1701,8 +2363,7 @@  discard block
 block discarded – undo
1701 2363
 				    	print_r($line);
1702 2364
 				    }
1703 2365
 				    unset($data);
1704
-				}
1705
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2366
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1706 2367
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1707 2368
 				}
1708 2369
 				/*
@@ -1711,7 +2372,9 @@  discard block
 block discarded – undo
1711 2372
 				}
1712 2373
 				*/
1713 2374
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1714
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2375
+				elseif ($line == true && $globalDebug) {
2376
+					echo '!! Failed : '.$buffer."!!\n";
2377
+				}
1715 2378
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1716 2379
 					$Source->deleteOldLocationByType('lightning');
1717 2380
 					$Source->deleteOldLocationByType('wx');
@@ -1747,26 +2410,45 @@  discard block
 block discarded – undo
1747 2410
     				$data['ground'] = $line[21];
1748 2411
     				$data['emergency'] = $line[19];
1749 2412
     				$data['format_source'] = 'sbs';
1750
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1751
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1752
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2413
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2414
+					$data['source_name'] = $globalSources[$nb]['name'];
2415
+				}
2416
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2417
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2418
+    				}
2419
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2420
+					$data['noarchive'] = true;
2421
+				}
1753 2422
     				$data['id_source'] = $id_source;
1754
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1755
-    				else $error = true;
2423
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2424
+    					$send = $SI->add($data);
2425
+    				} else {
2426
+    					$error = true;
2427
+    				}
1756 2428
     				unset($data);
1757
-    			    } else $error = true;
2429
+    			    } else {
2430
+    			    	$error = true;
2431
+    			    }
1758 2432
 			    if ($error) {
1759 2433
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1760
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2434
+					if ($globalDebug) {
2435
+						echo "Not a message. Ignoring... \n";
2436
+					}
1761 2437
 				} else {
1762
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2438
+					if ($globalDebug) {
2439
+						echo "Wrong line format. Ignoring... \n";
2440
+					}
1763 2441
 					if ($globalDebug) {
1764 2442
 						echo $buffer;
1765 2443
 						//print_r($line);
1766 2444
 					}
1767 2445
 					//socket_close($r);
1768
-					if ($globalDebug) echo "Reconnect after an error...\n";
1769
-					if ($format == 'aprs') $aprs_connect = 0;
2446
+					if ($globalDebug) {
2447
+						echo "Reconnect after an error...\n";
2448
+					}
2449
+					if ($format == 'aprs') {
2450
+						$aprs_connect = 0;
2451
+					}
1770 2452
 					$sourceer[$nb] = $globalSources[$nb];
1771 2453
 					connect_all($sourceer);
1772 2454
 					$sourceer = array();
@@ -1774,10 +2456,14 @@  discard block
 block discarded – undo
1774 2456
 			    }
1775 2457
 			}
1776 2458
 			// Sleep for xxx microseconds
1777
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2459
+			if (isset($globalSBSSleep)) {
2460
+				usleep($globalSBSSleep);
2461
+			}
1778 2462
 		    } else {
1779 2463
 			if ($format == 'flightgearmp') {
1780
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2464
+			    	if ($globalDebug) {
2465
+			    		echo "Reconnect FlightGear MP...";
2466
+			    	}
1781 2467
 				//@socket_close($r);
1782 2468
 				sleep($globalMinFetch);
1783 2469
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1786,10 +2472,15 @@  discard block
 block discarded – undo
1786 2472
 				break;
1787 2473
 				
1788 2474
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1789
-			    if (isset($tt[$format])) $tt[$format]++;
1790
-			    else $tt[$format] = 0;
2475
+			    if (isset($tt[$format])) {
2476
+			    	$tt[$format]++;
2477
+			    } else {
2478
+			    	$tt[$format] = 0;
2479
+			    }
1791 2480
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1792
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2481
+				if ($globalDebug) {
2482
+					echo "ERROR : Reconnect ".$format."...";
2483
+				}
1793 2484
 				//@socket_close($r);
1794 2485
 				sleep(2);
1795 2486
 				$aprs_connect = 0;
@@ -1807,11 +2498,17 @@  discard block
 block discarded – undo
1807 2498
 	    } else {
1808 2499
 		$error = socket_strerror(socket_last_error());
1809 2500
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1810
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1811
-			if (isset($globalDebug)) echo "Restarting...\n";
2501
+			if ($globalDebug) {
2502
+				echo "ERROR : socket_select give this error ".$error . "\n";
2503
+			}
2504
+			if (isset($globalDebug)) {
2505
+				echo "Restarting...\n";
2506
+			}
1812 2507
 			// Restart the script if possible
1813 2508
 			if (is_array($sockets)) {
1814
-			    if ($globalDebug) echo "Shutdown all sockets...";
2509
+			    if ($globalDebug) {
2510
+			    	echo "Shutdown all sockets...";
2511
+			    }
1815 2512
 			    
1816 2513
 			    foreach ($sockets as $sock) {
1817 2514
 				@socket_shutdown($sock,2);
@@ -1819,25 +2516,45 @@  discard block
 block discarded – undo
1819 2516
 			    }
1820 2517
 			    
1821 2518
 			}
1822
-			if ($globalDebug) echo "Waiting...";
2519
+			if ($globalDebug) {
2520
+				echo "Waiting...";
2521
+			}
1823 2522
 			sleep(2);
1824 2523
 			$time = time();
1825 2524
 			//connect_all($hosts);
1826 2525
 			$aprs_connect = 0;
1827
-			if ($reset%5 == 0) sleep(20);
1828
-			if ($reset%10 == 0) sleep(100);
1829
-			if ($reset%20 == 0) sleep(200);
1830
-			if ($reset > 100) exit('Too many attempts...');
1831
-			if ($globalDebug) echo "Restart all connections...";
2526
+			if ($reset%5 == 0) {
2527
+				sleep(20);
2528
+			}
2529
+			if ($reset%10 == 0) {
2530
+				sleep(100);
2531
+			}
2532
+			if ($reset%20 == 0) {
2533
+				sleep(200);
2534
+			}
2535
+			if ($reset > 100) {
2536
+				exit('Too many attempts...');
2537
+			}
2538
+			if ($globalDebug) {
2539
+				echo "Restart all connections...";
2540
+			}
1832 2541
 			connect_all($globalSources);
1833 2542
 		}
1834 2543
 	    }
1835 2544
 	}
1836 2545
 	if ($globalDaemon === false) {
1837
-	    if ($globalDebug) echo 'Check all...'."\n";
1838
-	    if (isset($SI)) $SI->checkAll();
1839
-	    if (isset($TI)) $TI->checkAll();
1840
-	    if (isset($MI)) $MI->checkAll();
2546
+	    if ($globalDebug) {
2547
+	    	echo 'Check all...'."\n";
2548
+	    }
2549
+	    if (isset($SI)) {
2550
+	    	$SI->checkAll();
2551
+	    }
2552
+	    if (isset($TI)) {
2553
+	    	$TI->checkAll();
2554
+	    }
2555
+	    if (isset($MI)) {
2556
+	    	$MI->checkAll();
2557
+	    }
1841 2558
 	}
1842 2559
     }
1843 2560
 }
Please login to merge, or discard this patch.
require/class.AIS.php 3 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		return ($dec);
58 58
 	}
59 59
 	
60
-    /*
60
+	/*
61 61
     $ais_map64 = array(
62 62
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // 48
63 63
        ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C',
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 		//  ' ' --- '?', // 0x20 - 0x3F
98 98
 		//  '@' --- '_', // 0x40 - 0x5F
99 99
 		$ais_chars = array(
100
-		    '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
101
-		    'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
102
-		    'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']',
103
-		    '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'',
104
-		    '(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
105
-		    '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
106
-		    '<', '=', '>', '?'
100
+			'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
101
+			'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
102
+			'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']',
103
+			'^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'',
104
+			'(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
105
+			'2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
106
+			'<', '=', '>', '?'
107 107
 		);
108 108
 		// "
109 109
 		$rv = '';
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 				}
422 422
 				if ($num_seq > 1) { // for multipart messages
423 423
 					if ($cmsg_sid != $msg_sid // different msg_sid
424
-					    || $msg_sid == -1 // invalid initial msg_sid
425
-					    || ($seq - $pseq) != 1 // not insequence
424
+						|| $msg_sid == -1 // invalid initial msg_sid
425
+						|| ($seq - $pseq) != 1 // not insequence
426 426
 					) {  // invalid for multipart message
427 427
 						$msg_sid = -1;
428 428
 						$cmsg_sid = -1;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 				$itu = $itu.$pcs[5]; // get itu message
436 436
 				$filler += (int)$pcs[6][0]; // get filler
437 437
 				if ($num_seq == 1 // valid single message
438
-				    || $num_seq == $pseq // valid multi-part message
438
+					|| $num_seq == $pseq // valid multi-part message
439 439
 				) {
440 440
 					/*
441 441
 					if ($num_seq != 1) { // test
@@ -520,13 +520,13 @@  discard block
 block discarded – undo
520 520
 		else $pad = '';
521 521
 		$rv = '';
522 522
 		$ais_chars = array(
523
-		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
524
-		    'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19,
525
-		    'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29,
526
-		    '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39,
527
-		    '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49,
528
-		    '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59,
529
-		    '<'=>60, '='=>61, '>'=>62, '?'=>63
523
+			'@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
524
+			'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19,
525
+			'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29,
526
+			'^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39,
527
+			'('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49,
528
+			'2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59,
529
+			'<'=>60, '='=>61, '>'=>62, '?'=>63
530 530
 		);
531 531
 		// "
532 532
 		$_a = str_split($name);
Please login to merge, or discard this patch.
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -117,31 +117,31 @@  discard block
 block discarded – undo
117 117
 
118 118
 	private function make_latf($temp) { // unsigned long 
119 119
 		$flat = 0.0; // float
120
-		$temp = $temp & 0x07FFFFFF;
121
-		if ($temp & 0x04000000) {
122
-			$temp = $temp ^ 0x07FFFFFF;
120
+		$temp = $temp&0x07FFFFFF;
121
+		if ($temp&0x04000000) {
122
+			$temp = $temp^0x07FFFFFF;
123 123
 			$temp += 1;
124
-			$flat = (float)($temp / (60.0 * 10000.0));
124
+			$flat = (float) ($temp/(60.0*10000.0));
125 125
 			$flat *= -1.0;
126
-		} else $flat = (float)($temp / (60.0 * 10000.0));
126
+		} else $flat = (float) ($temp/(60.0*10000.0));
127 127
 		return $flat; // float
128 128
 	}
129 129
 
130 130
 	private function make_lonf($temp) { // unsigned long
131 131
 		$flon = 0.0; // float
132
-		$temp = $temp & 0x0FFFFFFF;
133
-		if ($temp & 0x08000000) {
134
-			$temp = $temp ^ 0x0FFFFFFF;
132
+		$temp = $temp&0x0FFFFFFF;
133
+		if ($temp&0x08000000) {
134
+			$temp = $temp^0x0FFFFFFF;
135 135
 			$temp += 1;
136
-			$flon = (float)($temp / (60.0 * 10000.0));
136
+			$flon = (float) ($temp/(60.0*10000.0));
137 137
 			$flon *= -1.0;
138
-		} else $flon = (float)($temp / (60.0 * 10000.0));
138
+		} else $flon = (float) ($temp/(60.0*10000.0));
139 139
 		return $flon;
140 140
 	}
141 141
 
142 142
 	private function ascii_2_dec($chr) {
143
-		$dec=ord($chr);//get decimal ascii code
144
-		$hex=dechex($dec);//convert decimal to hex
143
+		$dec = ord($chr); //get decimal ascii code
144
+		$hex = dechex($dec); //convert decimal to hex
145 145
 		return ($dec);
146 146
 	}
147 147
 	
@@ -160,15 +160,15 @@  discard block
 block discarded – undo
160 160
 		//only process in the following range: 48-87, 96-119
161 161
 		if ($ascii < 48) { }
162 162
 		else {
163
-			if($ascii>119) { }
163
+			if ($ascii > 119) { }
164 164
 			else {
165
-				if ($ascii>87 && $ascii<96) ;
165
+				if ($ascii > 87 && $ascii < 96);
166 166
 				else {
167
-					$ascii=$ascii+40;
168
-					if ($ascii>128){
169
-						$ascii=$ascii+32;
167
+					$ascii = $ascii + 40;
168
+					if ($ascii > 128) {
169
+						$ascii = $ascii + 32;
170 170
 					} else {
171
-						$ascii=$ascii+40;
171
+						$ascii = $ascii + 40;
172 172
 					}
173 173
 				}
174 174
 			}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	}
178 178
 
179 179
 	private function dec_2_6bit($dec) {
180
-		$bin=decbin($dec);
180
+		$bin = decbin($dec);
181 181
 		return(substr($bin, -6)); 
182 182
 	}
183 183
 
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
 		);
196 196
 		// "
197 197
 		$rv = '';
198
-		if ($_size % 6 == 0) {
199
-			$len = $_size / 6;
200
-			for ($i=0; $i<$len; $i++) {
201
-				$offset = $i * 6;
202
-				$rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ];
198
+		if ($_size%6 == 0) {
199
+			$len = $_size/6;
200
+			for ($i = 0; $i < $len; $i++) {
201
+				$offset = $i*6;
202
+				$rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))];
203 203
 			}
204 204
 		}
205 205
 		return $rv;
@@ -226,93 +226,93 @@  discard block
 block discarded – undo
226 226
 		$ro->eta_hour = '';
227 227
 		$ro->eta_minute = '';
228 228
 		$ro->ts = time();
229
-		$ro->id = bindec(substr($_aisdata,0,6));
230
-		$ro->mmsi = bindec(substr($_aisdata,8,30));
229
+		$ro->id = bindec(substr($_aisdata, 0, 6));
230
+		$ro->mmsi = bindec(substr($_aisdata, 8, 30));
231 231
 		if ($ro->id >= 1 && $ro->id <= 3) {
232
-			$ro->cog = bindec(substr($_aisdata,116,12))/10;
233
-			$ro->sog = bindec(substr($_aisdata,50,10))/10;
234
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
235
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
232
+			$ro->cog = bindec(substr($_aisdata, 116, 12))/10;
233
+			$ro->sog = bindec(substr($_aisdata, 50, 10))/10;
234
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
235
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
236 236
 			$ro->cls = 1; // class A
237 237
 		} else if ($ro->id == 4) {
238
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28)));
239
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27)));
238
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28)));
239
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27)));
240 240
 			$ro->cls = 1; // class A
241 241
 		} else if ($ro->id == 5) {
242
-			$ro->imo = bindec(substr($_aisdata,40,30));
243
-			$ro->callsign = $this->binchar($_aisdata,70,42);
244
-			$ro->name = $this->binchar($_aisdata,112,120);
245
-			$ro->typeid = bindec(substr($_aisdata,232,8));
242
+			$ro->imo = bindec(substr($_aisdata, 40, 30));
243
+			$ro->callsign = $this->binchar($_aisdata, 70, 42);
244
+			$ro->name = $this->binchar($_aisdata, 112, 120);
245
+			$ro->typeid = bindec(substr($_aisdata, 232, 8));
246 246
 			$ro->type = $this->getShipType($ro->typeid);
247 247
 			//$ro->to_bow = bindec(substr($_aisdata,240,9));
248 248
 			//$ro->to_stern = bindec(substr($_aisdata,249,9));
249 249
 			//$ro->to_port = bindec(substr($_aisdata,258,6));
250 250
 			//$ro->to_starboard = bindec(substr($_aisdata,264,6));
251
-			$ro->eta_month = bindec(substr($_aisdata,274,4));
252
-			$ro->eta_day = bindec(substr($_aisdata,278,5));
253
-			$ro->eta_hour = bindec(substr($_aisdata,283,5));
254
-			$ro->eta_minute = bindec(substr($_aisdata,288,6));
251
+			$ro->eta_month = bindec(substr($_aisdata, 274, 4));
252
+			$ro->eta_day = bindec(substr($_aisdata, 278, 5));
253
+			$ro->eta_hour = bindec(substr($_aisdata, 283, 5));
254
+			$ro->eta_minute = bindec(substr($_aisdata, 288, 6));
255 255
 			//$ro->draught = bindec(substr($_aisdata,294,8));
256
-			$ro->destination = $this->binchar($_aisdata,302,120);
256
+			$ro->destination = $this->binchar($_aisdata, 302, 120);
257 257
 			$ro->cls = 1; // class A
258 258
 		} else if ($ro->id == 9) {
259 259
 			// Search and Rescue aircraft position report
260 260
 		} else if ($ro->id == 18) {
261
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
262
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
263
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
264
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
265
-			$ro->heading = bindec(substr($_aisdata,124,9));
261
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
262
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
263
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28)));
264
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27)));
265
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
266 266
 			if ($ro->heading == 511) $ro->heading = '';
267 267
 			$ro->cls = 2; // class B
268 268
 		} else if ($ro->id == 19) {
269
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
270
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
271
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
272
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
273
-			$ro->name = $this->binchar($_aisdata,143,120);
269
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
270
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
271
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
272
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
273
+			$ro->name = $this->binchar($_aisdata, 143, 120);
274 274
 			$ro->cls = 2; // class B
275
-			$ro->heading = bindec(substr($_aisdata,124,9));
275
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
276 276
 			if ($ro->heading == 511) $ro->heading = '';
277
-			$ro->typeid = bindec(substr($_aisdata,263,8));
277
+			$ro->typeid = bindec(substr($_aisdata, 263, 8));
278 278
 			$ro->type = $this->getShipType($ro->typeid);
279 279
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
280 280
 			//$ro->to_stern = bindec(substr($_aisdata,280,9));
281 281
 			//$ro->to_port = bindec(substr($_aisdata,289,6));
282 282
 			//$ro->to_starboard = bindec(substr($_aisdata,295,6));
283 283
 		} else if ($ro->id == 21) {
284
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28)));
285
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27)));
286
-			$ro->name = $this->binchar($_aisdata,43,120);
284
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28)));
285
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27)));
286
+			$ro->name = $this->binchar($_aisdata, 43, 120);
287 287
 			//$ro->to_bow = bindec(substr($_aisdata,219,9));
288 288
 			//$ro->to_stern = bindec(substr($_aisdata,228,9));
289 289
 			//$ro->to_port = bindec(substr($_aisdata,237,6));
290 290
 			//$ro->to_starboard = bindec(substr($_aisdata,243,6));
291 291
 			$ro->cls = 2; // class B
292 292
 		} else if ($ro->id == 24) {
293
-			$pn = bindec(substr($_aisdata,38,2));
293
+			$pn = bindec(substr($_aisdata, 38, 2));
294 294
 			if ($pn == 0) {
295
-				$ro->name = $this->binchar($_aisdata,40,120);
295
+				$ro->name = $this->binchar($_aisdata, 40, 120);
296 296
 			}
297
-			$ro->typeid = bindec(substr($_aisdata,40,8));
297
+			$ro->typeid = bindec(substr($_aisdata, 40, 8));
298 298
 			$ro->type = $this->getShipType($ro->typeid);
299
-			$ro->callsign = $this->binchar($_aisdata,90,42);
299
+			$ro->callsign = $this->binchar($_aisdata, 90, 42);
300 300
 			//$ro->to_bow = bindec(substr($_aisdata,132,9));
301 301
 			//$ro->to_stern = bindec(substr($_aisdata,141,9));
302 302
 			//$ro->to_port = bindec(substr($_aisdata,150,6));
303 303
 			//$ro->to_starboard = bindec(substr($_aisdata,156,6));
304 304
 			$ro->cls = 2; // class B
305 305
 		} else if ($ro->id == 27) {
306
-			$ro->cog = bindec(substr($_aisdata,85,9));
306
+			$ro->cog = bindec(substr($_aisdata, 85, 9));
307 307
 			if ($ro->cog == 511) $ro->cog = 0.0;
308
-			$ro->sog = bindec(substr($_aisdata,79,6));
308
+			$ro->sog = bindec(substr($_aisdata, 79, 6));
309 309
 			if ($ro->sog == 63) $ro->sog = 0.0;
310
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
311
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
310
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10);
311
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10);
312 312
 			$ro->cls = 1; // class A
313 313
 		
314 314
 		}
315
-		$ro->statusid = bindec(substr($_aisdata,38,4));
315
+		$ro->statusid = bindec(substr($_aisdata, 38, 4));
316 316
 		$ro->status = $this->getStatus($ro->statusid);
317 317
 		return $ro;
318 318
 	}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	}
360 360
 
361 361
 	public function getShipTypeID($type) {
362
-		$typeid = array_search($type,$this->shiptype);
362
+		$typeid = array_search($type, $this->shiptype);
363 363
 		if ($typeid !== FALSE) return $typeid;
364 364
 		else return '';
365 365
 	}
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
368 368
 		global $port; // tcpip port...
369 369
 		static $debug_counter = 0;
370
-		$aisdata168='';//six bit array of ascii characters
370
+		$aisdata168 = ''; //six bit array of ascii characters
371 371
 		$ais_nmea_array = str_split($_itu); // convert to an array
372 372
 		foreach ($ais_nmea_array as $value) {
373 373
 			$dec = $this->ascii_2_dec($value);
374 374
 			$bit8 = $this->asciidec_2_8bit($dec);
375 375
 			$bit6 = $this->dec_2_6bit($bit8);
376 376
 			//echo $value ."-" .$bit6 ."";
377
-			$aisdata168 .=$bit6;
377
+			$aisdata168 .= $bit6;
378 378
 		}
379 379
 		//echo $aisdata168 . "<br/>";
380 380
 		//return $this->decode_ais($aisdata168, $aux);
@@ -397,24 +397,24 @@  discard block
 block discarded – undo
397 397
 		// calculate checksum after ! till *
398 398
 		// assume 1st ! is valid
399 399
 		// find * ensure that it is at correct position
400
-		$end = strrpos ( $rawdata , '*' );
400
+		$end = strrpos($rawdata, '*');
401 401
 		if ($end === FALSE) return -1; // check for NULLS!!!
402
-		$cs = substr( $rawdata, $end + 1 );
403
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
404
-		$dcs = (int)hexdec( $cs );
405
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
406
-		if ( $chksum == $dcs ) { // NMEA checksum pass
402
+		$cs = substr($rawdata, $end + 1);
403
+		if (strlen($cs) != 2) return -1; // correct cs length
404
+		$dcs = (int) hexdec($cs);
405
+		for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum
406
+		if ($chksum == $dcs) { // NMEA checksum pass
407 407
 			$pcs = explode(',', $rawdata);
408 408
 			// !AI??? identifier
409 409
 			if (!isset($pcs[1])) {
410 410
 				echo "ERROR,INVALID_DATA ".time()." $rawdata\n";
411 411
 				return -1;
412 412
 			}
413
-			$num_seq = (int)$pcs[1]; // number of sequences
414
-			$seq = (int)$pcs[2]; // get sequence
413
+			$num_seq = (int) $pcs[1]; // number of sequences
414
+			$seq = (int) $pcs[2]; // get sequence
415 415
 			// get msg sequence id
416 416
 			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
417
-			else $msg_sid = (int)$pcs[3]; // multipart message
417
+			else $msg_sid = (int) $pcs[3]; // multipart message
418 418
 			$ais_ch = $pcs[4]; // get AIS channel
419 419
 			// message sequence checking
420 420
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 					}
448 448
 				}
449 449
 				$itu = $itu.$pcs[5]; // get itu message
450
-				$filler += (int)$pcs[6][0]; // get filler
450
+				$filler += (int) $pcs[6][0]; // get filler
451 451
 				if ($num_seq == 1 // valid single message
452 452
 				    || $num_seq == $pseq // valid multi-part message
453 453
 				) {
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 		$cbuf = $cbuf.$ibuf;
470 470
 		$last_pos = 0;
471 471
 		$result = new stdClass();
472
-		while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) {
472
+		while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) {
473 473
 		//while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) {
474 474
 			//DEBUG echo $cbuf;
475
-			if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim?
475
+			if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim?
476 476
 				$tst = substr($cbuf, $start - 3, ($end - $start + 3));
477 477
 				//DEBUG echo "[$start $end $tst]\n";
478
-				$result = $this->process_ais_raw( $tst, "" );
478
+				$result = $this->process_ais_raw($tst, "");
479 479
 				$last_pos = $end + 1;
480 480
 			} else break;
481 481
 		}
@@ -487,41 +487,41 @@  discard block
 block discarded – undo
487 487
 	// incoming data from serial or IP comms
488 488
 	public function process_ais_line($cbuf) {
489 489
 		$result = new stdClass();
490
-		$start = strpos($cbuf,"VDM");
490
+		$start = strpos($cbuf, "VDM");
491 491
 		$tst = substr($cbuf, $start - 3);
492
-		$result = $this->process_ais_raw( $tst, "" );
492
+		$result = $this->process_ais_raw($tst, "");
493 493
 		return $result;
494 494
 	}
495 495
 
496 496
 	/* AIS Encoding
497 497
 	*/
498
-	private function mk_ais_lat( $lat ) {
498
+	private function mk_ais_lat($lat) {
499 499
 		//$lat = 1.2569;
500
-		if ($lat<0.0) {
500
+		if ($lat < 0.0) {
501 501
 			$lat = -$lat;
502
-			$neg=true;
503
-		} else $neg=false;
502
+			$neg = true;
503
+		} else $neg = false;
504 504
 		$latd = 0x00000000;
505
-		$latd = intval ($lat * 600000.0);
506
-		if ($neg==true) {
505
+		$latd = intval($lat*600000.0);
506
+		if ($neg == true) {
507 507
 			$latd = ~$latd;
508
-			$latd+=1;
508
+			$latd += 1;
509 509
 			$latd &= 0x07FFFFFF;
510 510
 		}
511 511
 		return $latd;
512 512
 	}
513 513
 
514
-	private function mk_ais_lon( $lon ) {
514
+	private function mk_ais_lon($lon) {
515 515
 		//$lon = 103.851;
516
-		if ($lon<0.0) {
516
+		if ($lon < 0.0) {
517 517
 			$lon = -$lon;
518
-			$neg=true;
519
-		} else $neg=false;
518
+			$neg = true;
519
+		} else $neg = false;
520 520
 		$lond = 0x00000000;
521
-		$lond = intval ($lon * 600000.0);
522
-		if ($neg==true) {
521
+		$lond = intval($lon*600000.0);
522
+		if ($neg == true) {
523 523
 			$lond = ~$lond;
524
-			$lond+=1;
524
+			$lond += 1;
525 525
 			$lond &= 0x0FFFFFFF;
526 526
 		}
527 527
 		return $lond;
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 
530 530
 	private function char2bin($name, $max_len) {
531 531
 		$len = strlen($name);
532
-		if ($len > $max_len) $name = substr($name,0,$max_len);
533
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
532
+		if ($len > $max_len) $name = substr($name, 0, $max_len);
533
+		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6);
534 534
 		else $pad = '';
535 535
 		$rv = '';
536 536
 		$ais_chars = array(
@@ -547,26 +547,26 @@  discard block
 block discarded – undo
547 547
 		if ($_a) foreach ($_a as $_1) {
548 548
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
549 549
 			else $dec = 0;
550
-			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
550
+			$bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT);
551 551
 			$rv .= $bin;
552 552
 			//echo "$_1 $dec ($bin)<br/>";
553 553
 		}
554 554
 		return $rv.$pad;
555 555
 	}
556 556
 
557
-	private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') {
557
+	private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') {
558 558
 		$len_bit = strlen($_enc);
559
-		$rem6 = $len_bit % 6;
559
+		$rem6 = $len_bit%6;
560 560
 		$pad6_len = 0;
561 561
 		if ($rem6) $pad6_len = 6 - $rem6;
562 562
 		//echo  $pad6_len.'<br>';
563 563
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
564
-		$len_enc = strlen($_enc) / 6;
564
+		$len_enc = strlen($_enc)/6;
565 565
 		//echo $_enc.' '.$len_enc.'<br/>';
566 566
 		$itu = '';
567
-		for ($i=0; $i<$len_enc; $i++) {
568
-			$offset = $i * 6;
569
-			$dec = bindec(substr($_enc,$offset,6));
567
+		for ($i = 0; $i < $len_enc; $i++) {
568
+			$offset = $i*6;
569
+			$dec = bindec(substr($_enc, $offset, 6));
570 570
 			if ($dec < 40) $dec += 48;
571 571
 			else $dec += 56;
572 572
 			//echo chr($dec)." $dec<br/>";
@@ -576,15 +576,15 @@  discard block
 block discarded – undo
576 576
 		$chksum = 0;
577 577
 		$itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0";
578 578
 		$len_itu = strlen($itu);
579
-		for ($i=0; $i<$len_itu; $i++) {
580
-			$chksum ^= ord( $itu[$i] );
579
+		for ($i = 0; $i < $len_itu; $i++) {
580
+			$chksum ^= ord($itu[$i]);
581 581
 		}
582
-		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
583
-		$lsb = $chksum & 0x0F;
584
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
582
+		$hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
583
+		$lsb = $chksum&0x0F;
584
+		if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb];
585 585
 		else $lsbc = '0';
586
-		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
587
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
586
+		$msb = (($chksum&0xF0) >> 4)&0x0F;
587
+		if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb];
588 588
 		else $msbc = '0';
589 589
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
590 590
 		return $itu;
@@ -609,14 +609,14 @@  discard block
 block discarded – undo
609 609
 
610 610
 	public function mmsitype($mmsi) {
611 611
 		if (strlen($mmsi) == 9) {
612
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
613
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
614
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
615
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
616
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
617
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
618
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
619
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
612
+			if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
613
+			elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device';
614
+			elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
615
+			elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft';
616
+			elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship';
617
+			elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation';
618
+			elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations';
619
+			elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships';
620 620
 			else return 'Ship';
621 621
 		}
622 622
 
@@ -627,19 +627,19 @@  discard block
 block discarded – undo
627 627
 		global $globalDebug;
628 628
 		$result = array();
629 629
 		$data = new stdClass();
630
-		$start = strpos($buffer,"VDM");
630
+		$start = strpos($buffer, "VDM");
631 631
 		$tst = substr($buffer, $start - 3);
632
-		$data = $this->process_ais_raw( $tst, "" );
632
+		$data = $this->process_ais_raw($tst, "");
633 633
 		if (!is_object($data)) {
634 634
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
635 635
 			return array();
636 636
 		}
637 637
 		if ($data->lon != 0) $result['longitude'] = $data->lon;
638 638
 		if ($data->lat != 0) $result['latitude'] = $data->lat;
639
-		$result['ident'] = trim(str_replace('@','',$data->name));
639
+		$result['ident'] = trim(str_replace('@', '', $data->name));
640 640
 		$result['timestamp'] = $data->ts;
641 641
 		$result['mmsi'] = $data->mmsi;
642
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
642
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
643 643
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
644 644
 		if ($data->sog != -1.0) $result['speed'] = $data->sog;
645 645
 		if ($data->heading !== '') $result['heading'] = $data->heading;
@@ -649,16 +649,16 @@  discard block
 block discarded – undo
649 649
 		if ($data->type !== '') $result['type'] = $data->type;
650 650
 		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
651 651
 		if ($data->imo !== '') $result['imo'] = $data->imo;
652
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
652
+		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign));
653 653
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
654
-			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
654
+			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
655 655
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
656 656
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
657
-			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
657
+			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
658 658
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
659 659
 		}
660 660
 		if ($data->destination != '') {
661
-			$dest = trim(str_replace('@','',$data->destination));
661
+			$dest = trim(str_replace('@', '', $data->destination));
662 662
 			if ($dest != '') $result['destination'] = $dest;
663 663
 		}
664 664
 		$result['all'] = (array) $data;
Please login to merge, or discard this patch.
Braces   +176 added lines, -65 removed lines patch added patch discarded remove patch
@@ -123,7 +123,9 @@  discard block
 block discarded – undo
123 123
 			$temp += 1;
124 124
 			$flat = (float)($temp / (60.0 * 10000.0));
125 125
 			$flat *= -1.0;
126
-		} else $flat = (float)($temp / (60.0 * 10000.0));
126
+		} else {
127
+			$flat = (float)($temp / (60.0 * 10000.0));
128
+		}
127 129
 		return $flat; // float
128 130
 	}
129 131
 
@@ -135,7 +137,9 @@  discard block
 block discarded – undo
135 137
 			$temp += 1;
136 138
 			$flon = (float)($temp / (60.0 * 10000.0));
137 139
 			$flon *= -1.0;
138
-		} else $flon = (float)($temp / (60.0 * 10000.0));
140
+		} else {
141
+			$flon = (float)($temp / (60.0 * 10000.0));
142
+		}
139 143
 		return $flon;
140 144
 	}
141 145
 
@@ -158,10 +162,8 @@  discard block
 block discarded – undo
158 162
     */
159 163
 	private function asciidec_2_8bit($ascii) {
160 164
 		//only process in the following range: 48-87, 96-119
161
-		if ($ascii < 48) { }
162
-		else {
163
-			if($ascii>119) { }
164
-			else {
165
+		if ($ascii < 48) { } else {
166
+			if($ascii>119) { } else {
165 167
 				if ($ascii>87 && $ascii<96) ;
166 168
 				else {
167 169
 					$ascii=$ascii+40;
@@ -263,7 +265,9 @@  discard block
 block discarded – undo
263 265
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
264 266
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
265 267
 			$ro->heading = bindec(substr($_aisdata,124,9));
266
-			if ($ro->heading == 511) $ro->heading = '';
268
+			if ($ro->heading == 511) {
269
+				$ro->heading = '';
270
+			}
267 271
 			$ro->cls = 2; // class B
268 272
 		} else if ($ro->id == 19) {
269 273
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -273,7 +277,9 @@  discard block
 block discarded – undo
273 277
 			$ro->name = $this->binchar($_aisdata,143,120);
274 278
 			$ro->cls = 2; // class B
275 279
 			$ro->heading = bindec(substr($_aisdata,124,9));
276
-			if ($ro->heading == 511) $ro->heading = '';
280
+			if ($ro->heading == 511) {
281
+				$ro->heading = '';
282
+			}
277 283
 			$ro->typeid = bindec(substr($_aisdata,263,8));
278 284
 			$ro->type = $this->getShipType($ro->typeid);
279 285
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -304,9 +310,13 @@  discard block
 block discarded – undo
304 310
 			$ro->cls = 2; // class B
305 311
 		} else if ($ro->id == 27) {
306 312
 			$ro->cog = bindec(substr($_aisdata,85,9));
307
-			if ($ro->cog == 511) $ro->cog = 0.0;
313
+			if ($ro->cog == 511) {
314
+				$ro->cog = 0.0;
315
+			}
308 316
 			$ro->sog = bindec(substr($_aisdata,79,6));
309
-			if ($ro->sog == 63) $ro->sog = 0.0;
317
+			if ($ro->sog == 63) {
318
+				$ro->sog = 0.0;
319
+			}
310 320
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
311 321
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
312 322
 			$ro->cls = 1; // class A
@@ -354,14 +364,20 @@  discard block
 block discarded – undo
354 364
 	}
355 365
 	
356 366
 	public function getShipType($code) {
357
-		if (isset($this->shiptype[$code])) return $this->shiptype[$code];
358
-		else return '';
367
+		if (isset($this->shiptype[$code])) {
368
+			return $this->shiptype[$code];
369
+		} else {
370
+			return '';
371
+		}
359 372
 	}
360 373
 
361 374
 	public function getShipTypeID($type) {
362 375
 		$typeid = array_search($type,$this->shiptype);
363
-		if ($typeid !== FALSE) return $typeid;
364
-		else return '';
376
+		if ($typeid !== FALSE) {
377
+			return $typeid;
378
+		} else {
379
+			return '';
380
+		}
365 381
 	}
366 382
 
367 383
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -398,11 +414,20 @@  discard block
 block discarded – undo
398 414
 		// assume 1st ! is valid
399 415
 		// find * ensure that it is at correct position
400 416
 		$end = strrpos ( $rawdata , '*' );
401
-		if ($end === FALSE) return -1; // check for NULLS!!!
417
+		if ($end === FALSE) {
418
+			return -1;
419
+		}
420
+		// check for NULLS!!!
402 421
 		$cs = substr( $rawdata, $end + 1 );
403
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
422
+		if ( strlen($cs) != 2 ) {
423
+			return -1;
424
+		}
425
+		// correct cs length
404 426
 		$dcs = (int)hexdec( $cs );
405
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
427
+		for ( $alias=1; $alias<$end; $alias++) {
428
+			$chksum ^= ord( $rawdata[$alias] );
429
+		}
430
+		// perform XOR for NMEA checksum
406 431
 		if ( $chksum == $dcs ) { // NMEA checksum pass
407 432
 			$pcs = explode(',', $rawdata);
408 433
 			// !AI??? identifier
@@ -413,8 +438,14 @@  discard block
 block discarded – undo
413 438
 			$num_seq = (int)$pcs[1]; // number of sequences
414 439
 			$seq = (int)$pcs[2]; // get sequence
415 440
 			// get msg sequence id
416
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
417
-			else $msg_sid = (int)$pcs[3]; // multipart message
441
+			if ($pcs[3] == '') {
442
+				$msg_sid = -1;
443
+			}
444
+			// non-multipart message, set to -1
445
+			else {
446
+				$msg_sid = (int)$pcs[3];
447
+			}
448
+			// multipart message
418 449
 			$ais_ch = $pcs[4]; // get AIS channel
419 450
 			// message sequence checking
420 451
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -477,10 +508,18 @@  discard block
 block discarded – undo
477 508
 				//DEBUG echo "[$start $end $tst]\n";
478 509
 				$result = $this->process_ais_raw( $tst, "" );
479 510
 				$last_pos = $end + 1;
480
-			} else break;
511
+			} else {
512
+				break;
513
+			}
514
+		}
515
+		if ($last_pos > 0) {
516
+			$cbuf = substr($cbuf, $last_pos);
481 517
 		}
482
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
483
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
518
+		// move...
519
+		if (strlen($cbuf) > 1024) {
520
+			$cbuf = "";
521
+		}
522
+		// prevent overflow simple mode...
484 523
 		return $result;
485 524
 	}
486 525
 
@@ -500,7 +539,9 @@  discard block
 block discarded – undo
500 539
 		if ($lat<0.0) {
501 540
 			$lat = -$lat;
502 541
 			$neg=true;
503
-		} else $neg=false;
542
+		} else {
543
+			$neg=false;
544
+		}
504 545
 		$latd = 0x00000000;
505 546
 		$latd = intval ($lat * 600000.0);
506 547
 		if ($neg==true) {
@@ -516,7 +557,9 @@  discard block
 block discarded – undo
516 557
 		if ($lon<0.0) {
517 558
 			$lon = -$lon;
518 559
 			$neg=true;
519
-		} else $neg=false;
560
+		} else {
561
+			$neg=false;
562
+		}
520 563
 		$lond = 0x00000000;
521 564
 		$lond = intval ($lon * 600000.0);
522 565
 		if ($neg==true) {
@@ -529,9 +572,14 @@  discard block
 block discarded – undo
529 572
 
530 573
 	private function char2bin($name, $max_len) {
531 574
 		$len = strlen($name);
532
-		if ($len > $max_len) $name = substr($name,0,$max_len);
533
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
534
-		else $pad = '';
575
+		if ($len > $max_len) {
576
+			$name = substr($name,0,$max_len);
577
+		}
578
+		if ($len < $max_len) {
579
+			$pad = str_repeat('0', ($max_len - $len) * 6);
580
+		} else {
581
+			$pad = '';
582
+		}
535 583
 		$rv = '';
536 584
 		$ais_chars = array(
537 585
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -544,9 +592,12 @@  discard block
 block discarded – undo
544 592
 		);
545 593
 		// "
546 594
 		$_a = str_split($name);
547
-		if ($_a) foreach ($_a as $_1) {
595
+		if ($_a) {
596
+			foreach ($_a as $_1) {
548 597
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
549
-			else $dec = 0;
598
+		} else {
599
+				$dec = 0;
600
+			}
550 601
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
551 602
 			$rv .= $bin;
552 603
 			//echo "$_1 $dec ($bin)<br/>";
@@ -558,7 +609,9 @@  discard block
 block discarded – undo
558 609
 		$len_bit = strlen($_enc);
559 610
 		$rem6 = $len_bit % 6;
560 611
 		$pad6_len = 0;
561
-		if ($rem6) $pad6_len = 6 - $rem6;
612
+		if ($rem6) {
613
+			$pad6_len = 6 - $rem6;
614
+		}
562 615
 		//echo  $pad6_len.'<br>';
563 616
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
564 617
 		$len_enc = strlen($_enc) / 6;
@@ -567,8 +620,11 @@  discard block
 block discarded – undo
567 620
 		for ($i=0; $i<$len_enc; $i++) {
568 621
 			$offset = $i * 6;
569 622
 			$dec = bindec(substr($_enc,$offset,6));
570
-			if ($dec < 40) $dec += 48;
571
-			else $dec += 56;
623
+			if ($dec < 40) {
624
+				$dec += 48;
625
+			} else {
626
+				$dec += 56;
627
+			}
572 628
 			//echo chr($dec)." $dec<br/>";
573 629
 			$itu .= chr($dec);
574 630
 		}
@@ -581,25 +637,41 @@  discard block
 block discarded – undo
581 637
 		}
582 638
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
583 639
 		$lsb = $chksum & 0x0F;
584
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
585
-		else $lsbc = '0';
640
+		if ($lsb >=0 && $lsb <= 15 ) {
641
+			$lsbc = $hex_arr[$lsb];
642
+		} else {
643
+			$lsbc = '0';
644
+		}
586 645
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
587
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
588
-		else $msbc = '0';
646
+		if ($msb >=0 && $msb <= 15 ) {
647
+			$msbc = $hex_arr[$msb];
648
+		} else {
649
+			$msbc = '0';
650
+		}
589 651
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
590 652
 		return $itu;
591 653
 	}
592 654
 
593 655
 	public function parse($buffer) {
594 656
 		$data = $this->process_ais_buf($buffer);
595
-		if (!is_object($data)) return array();
596
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
597
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
657
+		if (!is_object($data)) {
658
+			return array();
659
+		}
660
+		if ($data->lon != 0) {
661
+			$result['longitude'] = $data->lon;
662
+		}
663
+		if ($data->lat != 0) {
664
+			$result['latitude'] = $data->lat;
665
+		}
598 666
 		$result['ident'] = trim($data->name);
599 667
 		$result['timestamp'] = $data->ts;
600 668
 		$result['mmsi'] = $data->mmsi;
601
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
602
-		if ($data->cog != 0) $result['heading'] = $data->cog;
669
+		if ($data->sog != -1.0) {
670
+			$result['speed'] = $data->sog;
671
+		}
672
+		if ($data->cog != 0) {
673
+			$result['heading'] = $data->cog;
674
+		}
603 675
 		/*
604 676
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
605 677
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -609,15 +681,25 @@  discard block
 block discarded – undo
609 681
 
610 682
 	public function mmsitype($mmsi) {
611 683
 		if (strlen($mmsi) == 9) {
612
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
613
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
614
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
615
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
616
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
617
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
618
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
619
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
620
-			else return 'Ship';
684
+			if (substr($mmsi,0,3) == '974') {
685
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
686
+			} elseif (substr($mmsi,0,3) == '972') {
687
+				return 'MOB (Man Overboard) device';
688
+			} elseif (substr($mmsi,0,3) == '970') {
689
+				return 'AIS SART (Search and Rescue Transmitter)';
690
+			} elseif (substr($mmsi,0,3) == '111') {
691
+				return 'SAR (Search and Rescue) aircraft';
692
+			} elseif (substr($mmsi,0,2) == '98') {
693
+				return 'Auxiliary craft associated with a parent ship';
694
+			} elseif (substr($mmsi,0,2) == '99') {
695
+				return 'Aids to Navigation';
696
+			} elseif (substr($mmsi,0,2) == '00') {
697
+				return 'Coastal stations';
698
+			} elseif (substr($mmsi,0,1) == '0') {
699
+				return 'Group of ships';
700
+			} else {
701
+				return 'Ship';
702
+			}
621 703
 		}
622 704
 
623 705
 	
@@ -634,32 +716,61 @@  discard block
 block discarded – undo
634 716
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
635 717
 			return array();
636 718
 		}
637
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
638
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
639 725
 		$result['ident'] = trim(str_replace('@','',$data->name));
640 726
 		$result['timestamp'] = $data->ts;
641 727
 		$result['mmsi'] = $data->mmsi;
642
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
728
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') {
729
+			$result['mmsi'] = '3'.$result['mmsi'];
730
+		}
643 731
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
644
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
645
-		if ($data->heading !== '') $result['heading'] = $data->heading;
646
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
647
-		if ($data->status != '') $result['status'] = $data->status;
648
-		if ($data->statusid !== '') $result['statusid'] = $data->statusid;
649
-		if ($data->type !== '') $result['type'] = $data->type;
650
-		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
651
-		if ($data->imo !== '') $result['imo'] = $data->imo;
652
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
732
+		if ($data->sog != -1.0) {
733
+			$result['speed'] = $data->sog;
734
+		}
735
+		if ($data->heading !== '') {
736
+			$result['heading'] = $data->heading;
737
+		} elseif ($data->cog != 0) {
738
+			$result['heading'] = $data->cog;
739
+		}
740
+		if ($data->status != '') {
741
+			$result['status'] = $data->status;
742
+		}
743
+		if ($data->statusid !== '') {
744
+			$result['statusid'] = $data->statusid;
745
+		}
746
+		if ($data->type !== '') {
747
+			$result['type'] = $data->type;
748
+		}
749
+		if ($data->typeid !== '') {
750
+			$result['typeid'] = $data->typeid;
751
+		}
752
+		if ($data->imo !== '') {
753
+			$result['imo'] = $data->imo;
754
+		}
755
+		if ($data->callsign !== '') {
756
+			$result['callsign'] = trim(str_replace('@','',$data->callsign));
757
+		}
653 758
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
654 759
 			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
655
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
760
+			if ($eta_ts != '') {
761
+				$result['eta_ts'] = $eta_ts;
762
+			}
656 763
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
657 764
 			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
658
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
765
+			if ($eta_ts != '') {
766
+				$result['eta_ts'] = $eta_ts;
767
+			}
659 768
 		}
660 769
 		if ($data->destination != '') {
661 770
 			$dest = trim(str_replace('@','',$data->destination));
662
-			if ($dest != '') $result['destination'] = $dest;
771
+			if ($dest != '') {
772
+				$result['destination'] = $dest;
773
+			}
663 774
 		}
664 775
 		$result['all'] = (array) $data;
665 776
 		/*
Please login to merge, or discard this patch.
marine-type-detailed.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -62,12 +62,12 @@
 block discarded – undo
62 62
 	*/
63 63
 		//if ($aircraft_type != "NA")
64 64
 		//{
65
-	    		print '<div class="info column">';
66
-	      		print '<h1>'.$spotter_array[0]['type'].'</h1>';
67
-	      		//print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['aircraft_name'].'</div>';
68
-	      		//print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['aircraft_type'].'</div>'; 
69
-	      		//if (isset($spotter_array[0]['aircraft_manufacturer'])) print '<div><span class="label">'._("Manufacturer").'</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>';
70
-	    		print '</div>';
65
+				print '<div class="info column">';
66
+		  		print '<h1>'.$spotter_array[0]['type'].'</h1>';
67
+		  		//print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['aircraft_name'].'</div>';
68
+		  		//print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['aircraft_type'].'</div>'; 
69
+		  		//if (isset($spotter_array[0]['aircraft_manufacturer'])) print '<div><span class="label">'._("Manufacturer").'</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>';
70
+				print '</div>';
71 71
 		//} else {
72 72
 		//	print '<div class="alert alert-warning">'._("This special aircraft profile shows all flights in where the aircraft type is unknown.").'</div>';
73 73
 		//}
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,16 +5,16 @@  discard block
 block discarded – undo
5 5
 require_once('require/class.Language.php');
6 6
 $Marine = new Marine();
7 7
 $type = 'marine';
8
-if (!isset($_GET['type'])){
8
+if (!isset($_GET['type'])) {
9 9
 	header('Location: '.$globalURL.'/');
10 10
 } else {
11 11
 	//calculuation for the pagination
12
-	if(!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2)
12
+	if (!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2)
13 13
 	{
14 14
 		$limit_start = 0;
15 15
 		$limit_end = 25;
16 16
 		$absolute_difference = 25;
17
-	}  else {
17
+	} else {
18 18
 		$limit_explode = explode(",", $_GET['limit']);
19 19
 		$limit_start = $limit_explode[0];
20 20
 		$limit_end = $limit_explode[1];
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
 	$limit_previous_1 = $limit_start - $absolute_difference;
29 29
 	$limit_previous_2 = $limit_end - $absolute_difference;
30 30
 	
31
-	$marine_type = filter_input(INPUT_GET,'type',FILTER_SANITIZE_STRING);
31
+	$marine_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING);
32 32
 	$page_url = $globalURL.'/marine/type/'.$marine_type;
33
-	$sort = htmlspecialchars(filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING));
34
-	$spotter_array = $Marine->getMarineDataByType($marine_type,$limit_start.",".$absolute_difference, $sort);
33
+	$sort = htmlspecialchars(filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING));
34
+	$spotter_array = $Marine->getMarineDataByType($marine_type, $limit_start.",".$absolute_difference, $sort);
35 35
 	
36 36
 	if (!empty($spotter_array))
37 37
 	{
38
-		$title = sprintf(_("Detailed View for %s"),$spotter_array[0]['type']);
38
+		$title = sprintf(_("Detailed View for %s"), $spotter_array[0]['type']);
39 39
 		require_once('header.php');
40 40
 	
41 41
 	/*    
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		//include('aircraft-sub-menu.php');
76 76
 	        
77 77
 		print '<div class="table column">';
78
-		print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."),$spotter_array[0]['type']).'</p>';
78
+		print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."), $spotter_array[0]['type']).'</p>';
79 79
 		  
80 80
 		include('table-output.php');
81 81
 		  
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 		$limit_start = 0;
15 15
 		$limit_end = 25;
16 16
 		$absolute_difference = 25;
17
-	}  else {
17
+	} else {
18 18
 		$limit_explode = explode(",", $_GET['limit']);
19 19
 		$limit_start = $limit_explode[0];
20 20
 		$limit_end = $limit_explode[1];
Please login to merge, or discard this patch.
statistics-type.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
 
8 8
 $type = 'marine';
9 9
 if (!isset($filter_name)) $filter_name = '';
10
-$year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT);
11
-$month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT);
10
+$year = filter_input(INPUT_GET, 'year', FILTER_SANITIZE_NUMBER_INT);
11
+$month = filter_input(INPUT_GET, 'month', FILTER_SANITIZE_NUMBER_INT);
12 12
 
13 13
 require_once('header.php');
14 14
 
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 	</div>
21 21
 	<p>'._("Below are the <strong>Top 10</strong> most common vessel types.").'</p>';
22 22
 	  
23
-$type_array = $Marine->countAllMarineTypes(true,0,'',$filter_name,$year,$month);
23
+$type_array = $Marine->countAllMarineTypes(true, 0, '', $filter_name, $year, $month);
24 24
 print '<div id="chart" class="chart" width="100%"></div><script>';
25 25
 $type_data = '';
26
-foreach($type_array as $type_item)
26
+foreach ($type_array as $type_item)
27 27
 {
28 28
 	$type_data .= '["'.$type_item['marine_type'].'",'.$type_item['marine_type_count'].'],';
29 29
 }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	print '</thead>';
49 49
 	print '<tbody>';
50 50
 	$i = 1;
51
-	foreach($type_array as $type_item)
51
+	foreach ($type_array as $type_item)
52 52
 	{
53 53
 		print '<tr>';
54 54
 		print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@
 block discarded – undo
6 6
 $title = _("Statistics").' - '._("Most common Vessel Type");
7 7
 
8 8
 $type = 'marine';
9
-if (!isset($filter_name)) $filter_name = '';
9
+if (!isset($filter_name)) {
10
+	$filter_name = '';
11
+}
10 12
 $year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT);
11 13
 $month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT);
12 14
 
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Stats.php');
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 if (isset($globalServerAPRS) && $globalServerAPRS) {
12
-    require_once(dirname(__FILE__).'/class.APRS.php');
12
+	require_once(dirname(__FILE__).'/class.APRS.php');
13 13
 }
14 14
 
15 15
 class MarineImport {
16
-    private $all_tracked = array();
17
-    private $last_delete_hourly = 0;
18
-    private $last_delete = 0;
19
-    private $stats = array();
20
-    private $tmd = 0;
21
-    private $source_location = array();
22
-    public $db = null;
23
-    public $nb = 0;
16
+	private $all_tracked = array();
17
+	private $last_delete_hourly = 0;
18
+	private $last_delete = 0;
19
+	private $stats = array();
20
+	private $tmd = 0;
21
+	private $source_location = array();
22
+	public $db = null;
23
+	public $nb = 0;
24 24
 
25
-    public function __construct($dbc = null) {
25
+	public function __construct($dbc = null) {
26 26
 	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
27 27
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
28
-	    $Connection = new Connection($dbc);
29
-	    $this->db = $Connection->db();
30
-	    date_default_timezone_set('UTC');
28
+		$Connection = new Connection($dbc);
29
+		$this->db = $Connection->db();
30
+		date_default_timezone_set('UTC');
31 31
 	}
32 32
 	// Get previous source stats
33 33
 	/*
@@ -46,57 +46,57 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 	*/
48 48
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
49
-	    $APRSMarine = new APRSMarine();
50
-	    //$APRSSpotter->connect();
49
+		$APRSMarine = new APRSMarine();
50
+		//$APRSSpotter->connect();
51
+	}
51 52
 	}
52
-    }
53 53
 
54
-    public function checkAll() {
54
+	public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
58
-	    foreach ($this->all_tracked as $key => $flight) {
57
+		if ($globalDebug) echo "Update last seen tracked data...\n";
58
+		foreach ($this->all_tracked as $key => $flight) {
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60
-		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61
-    		    $Marine = new Marine($this->db);
62
-    		    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
60
+			//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61
+				$Marine = new Marine($this->db);
62
+				$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
63
+		}
63 64
 		}
64
-	    }
65 65
 	}
66
-    }
66
+	}
67 67
 
68
-    public function del() {
68
+	public function del() {
69 69
 	global $globalDebug, $globalNoDB, $globalNoImport;
70 70
 	// Delete old infos
71 71
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
72 72
 	foreach ($this->all_tracked as $key => $flight) {
73
-    	    if (isset($flight['lastupdate'])) {
74
-        	if ($flight['lastupdate'] < (time()-3000)) {
75
-            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76
-            		if (isset($this->all_tracked[$key]['id'])) {
77
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
78
-			    /*
73
+			if (isset($flight['lastupdate'])) {
74
+			if ($flight['lastupdate'] < (time()-3000)) {
75
+					if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76
+					if (isset($this->all_tracked[$key]['id'])) {
77
+						if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
78
+				/*
79 79
 			    $MarineLive = new MarineLive();
80 80
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
81 81
 			    $MarineLive->db = null;
82 82
 			    */
83
-            		    //$real_arrival = $this->arrival($key);
84
-            		    $Marine = new Marine($this->db);
85
-            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
83
+						//$real_arrival = $this->arrival($key);
84
+						$Marine = new Marine($this->db);
85
+						if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86 86
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
87 87
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
88
-			    }
89
-			    // Put in archive
88
+				}
89
+				// Put in archive
90 90
 //				$Marine->db = null;
91 91
 			}
92
-            	    }
93
-            	    unset($this->all_tracked[$key]);
94
-    	        }
95
-	    }
96
-        }
97
-    }
92
+					}
93
+					unset($this->all_tracked[$key]);
94
+				}
95
+		}
96
+		}
97
+	}
98 98
 
99
-    public function add($line) {
99
+	public function add($line) {
100 100
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
101 101
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
102 102
 	date_default_timezone_set('UTC');
@@ -105,103 +105,103 @@  discard block
 block discarded – undo
105 105
 	
106 106
 	// SBS format is CSV format
107 107
 	if(is_array($line) && isset($line['mmsi'])) {
108
-	    //print_r($line);
109
-  	    if (isset($line['mmsi'])) {
108
+		//print_r($line);
109
+  		if (isset($line['mmsi'])) {
110 110
 
111 111
 		
112 112
 		// Increment message number
113 113
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
114
-		    $current_date = date('Y-m-d');
115
-		    if (isset($line['source_name'])) $source = $line['source_name'];
116
-		    else $source = '';
117
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
118
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
119
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
120
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
114
+			$current_date = date('Y-m-d');
115
+			if (isset($line['source_name'])) $source = $line['source_name'];
116
+			else $source = '';
117
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
118
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
119
+				$this->stats[$current_date][$source]['msg']['date'] = time();
120
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
122 122
 		}
123 123
 		
124 124
 		
125 125
 		$Common = new Common();
126 126
 		$AIS = new AIS();
127
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
128
-	        else $id = trim($line['id']);
127
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
128
+			else $id = trim($line['id']);
129 129
 		
130 130
 		if (!isset($this->all_tracked[$id])) {
131
-		    $this->all_tracked[$id] = array();
132
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
133
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
135
-		    if (!isset($line['id'])) {
131
+			$this->all_tracked[$id] = array();
132
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
133
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
135
+			if (!isset($line['id'])) {
136 136
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
137 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
139
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
139
+			if ($globalAllTracked !== FALSE) $dataFound = true;
140 140
 		}
141 141
 		
142 142
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
144
-		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
143
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
144
+			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
145 145
 			$Marine = new Marine($this->db);
146 146
 			$identity = $Marine->getIdentity($line['mmsi']);
147 147
 			if (!empty($identity)) {
148
-			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
149
-			    $this->all_tracked[$id]['type'] = $identity['type'];
148
+				$this->all_tracked[$id]['ident'] = $identity['ship_name'];
149
+				$this->all_tracked[$id]['type'] = $identity['type'];
150 150
 			}
151 151
 			//print_r($identity);
152 152
 			unset($Marine);
153 153
 			//$dataFound = true;
154
-		    }
154
+			}
155 155
 		}
156 156
 		if (isset($line['type_id'])) {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
159 159
 		}
160 160
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
162
-		    if (!isset($line['type_id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
161
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
162
+			if (!isset($line['type_id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
163 163
 		}
164 164
 		if (isset($line['status']) && $line['status'] != '') {
165
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
165
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
166 166
 		}
167 167
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
168
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
169
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
168
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
169
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
170 170
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
171
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
171
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
172 172
 				$Marine = new Marine($this->db);
173 173
 				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
174 174
 				unset($Marine);
175
-			    }
175
+				}
176
+			}
176 177
 			}
177
-		    }
178 178
 		}
179 179
 
180 180
 
181 181
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
182
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
182
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
183 183
 		}
184 184
 		if (isset($line['imo']) && $line['imo'] != '') {
185
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
185
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
186 186
 		}
187 187
 		if (isset($line['callsign']) && $line['callsign'] != '') {
188
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
188
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
189 189
 		}
190 190
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
191
-		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
191
+			if (!isset($this->all_tracked[$id]['arrival_code'])) {
192 192
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
193 193
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
194 194
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
195
-			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
195
+				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
196 196
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
197
-				    $Marine = new Marine($this->db);
198
-				    $fromsource = NULL;
199
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
200
-				    $Marine->db = null;
197
+					$Marine = new Marine($this->db);
198
+					$fromsource = NULL;
199
+					$Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
200
+					$Marine->db = null;
201
+				}
201 202
 				}
202
-			    }
203 203
 			}
204
-		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
204
+			} elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
205 205
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
206 206
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
207 207
 			if (!isset($line['id'])) {
@@ -209,18 +209,18 @@  discard block
 block discarded – undo
209 209
 				$this->all_tracked[$id]['forcenew'] = 1;
210 210
 				$this->all_tracked[$id]['addedMarine'] = 0;
211 211
 			}
212
-		    }
212
+			}
213 213
 		}
214 214
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
215
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
215
+			if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
216 216
 		}
217 217
 
218 218
 		//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'])) {
219 219
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
220
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
221
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
220
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
221
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
222 222
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
223
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
223
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
224 224
 				$timeelapsed = microtime(true);
225 225
 				$Marine = new Marine($this->db);
226 226
 				$fromsource = NULL;
@@ -229,20 +229,20 @@  discard block
 block discarded – undo
229 229
 				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
230 230
 				$Marine->db = null;
231 231
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
232
-			    }
232
+				}
233
+			}
233 234
 			}
234
-		    }
235
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
235
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
236 236
 		}
237 237
 
238 238
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
239
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
239
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
240 240
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
241
-		    } else {
241
+			} else {
242 242
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
243 243
 				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]['hex']." - format : ".$line['format_source']."\n";
244 244
 				return '';
245
-		    }
245
+			}
246 246
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
247 247
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
248 248
 			return '';
@@ -259,24 +259,24 @@  discard block
 block discarded – undo
259 259
 
260 260
 
261 261
 		if (isset($line['speed'])) {
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
263
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
262
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
263
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
264 264
 		} 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'])) {
265
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
266
-		    if ($distance > 1000 && $distance < 10000) {
265
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
266
+			if ($distance > 1000 && $distance < 10000) {
267 267
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
268 268
 			$speed = $speed*3.6;
269 269
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
270 270
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
271
-		    }
271
+			}
272 272
 		}
273 273
 
274
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
275
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
276
-	    	    else unset($timediff);
277
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($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')))) {
274
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
275
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
276
+				else unset($timediff);
277
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($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')))) {
278 278
 			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'])) {
279
-			    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'])) {
279
+				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'])) {
280 280
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
281 281
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
282 282
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -284,195 +284,195 @@  discard block
 block discarded – undo
284 284
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
285 285
 				$timeelapsed = microtime(true);
286 286
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
287
-				    $Marine = new Marine($this->db);
288
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
289
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
290
-				    $Marine->db = null;
291
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287
+					$Marine = new Marine($this->db);
288
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
289
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
290
+					$Marine->db = null;
291
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
292 292
 				}
293 293
 				$this->tmd = 0;
294 294
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
295
-			    }
295
+				}
296 296
 			}
297 297
 
298 298
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
299 299
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
300 300
 				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') {
301
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
302
-				    $dataFound = true;
303
-				    $this->all_tracked[$id]['time_last_coord'] = time();
301
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
302
+					$dataFound = true;
303
+					$this->all_tracked[$id]['time_last_coord'] = time();
304 304
 				}
305 305
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
306 306
 			}
307 307
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
308
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
308
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
309 309
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
310 310
 				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') {
311
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
312
-				    $dataFound = true;
313
-				    $this->all_tracked[$id]['time_last_coord'] = time();
311
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
312
+					$dataFound = true;
313
+					$this->all_tracked[$id]['time_last_coord'] = time();
314 314
 				}
315 315
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
316 316
 			}
317 317
 
318
-		    } else if ($globalDebug && $timediff > 20) {
318
+			} else if ($globalDebug && $timediff > 20) {
319 319
 			$this->tmd = $this->tmd + 1;
320 320
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
321 321
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
322 322
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
323 323
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
324
-		    }
324
+			}
325 325
 		}
326 326
 		if (isset($line['last_update']) && $line['last_update'] != '') {
327
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
328
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
327
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
328
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
329 329
 		}
330 330
 		if (isset($line['format_source']) && $line['format_source'] != '') {
331
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
331
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
332 332
 		}
333 333
 		if (isset($line['source_name']) && $line['source_name'] != '') {
334
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
334
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
335 335
 		}
336 336
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
337
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
337
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
338 338
 		}
339 339
 		
340 340
 		if (isset($line['heading']) && $line['heading'] != '') {
341
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
342
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
343
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
344
-		    //$dataFound = true;
341
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
342
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
343
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
344
+			//$dataFound = true;
345 345
   		} 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']) {
346
-  		    $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']);
347
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
348
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
349
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
346
+  			$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']);
347
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
348
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
349
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
350 350
   		}
351 351
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
352 352
 
353 353
 
354 354
 
355 355
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
356
-		    $this->all_tracked[$id]['lastupdate'] = time();
357
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
358
-		        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'])) {
359
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
356
+			$this->all_tracked[$id]['lastupdate'] = time();
357
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
358
+				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'])) {
359
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
360 360
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
361
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
362
-				    $timeelapsed = microtime(true);
363
-				    $MarineLive = new MarineLive($this->db);
364
-				    if (isset($line['id'])) {
361
+					if ($globalDebug) echo "Check if vessel is already in DB...";
362
+					$timeelapsed = microtime(true);
363
+					$MarineLive = new MarineLive($this->db);
364
+					if (isset($line['id'])) {
365 365
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
366 366
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
367
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
367
+					} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
368 368
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
369 369
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
370
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
370
+					} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
371 371
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
372 372
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
373
-				    } else $recent_ident = '';
374
-				    $MarineLive->db=null;
375
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
376
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
373
+					} else $recent_ident = '';
374
+					$MarineLive->db=null;
375
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
376
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
377 377
 				} else $recent_ident = '';
378
-			    } else {
378
+				} else {
379 379
 				$recent_ident = '';
380 380
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
381
-			    }
382
-			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
383
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
384
-			    {
381
+				}
382
+				//if there was no vessel with the same callsign within the last hour and go post it into the archive
383
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
384
+				{
385 385
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
386 386
 				//adds the spotter data for the archive
387
-				    $highlight = '';
388
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
389
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
387
+					$highlight = '';
388
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
389
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
390 390
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
391
-					    $timeelapsed = microtime(true);
392
-					    $Marine = new Marine($this->db);
393
-					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
394
-					    $Marine->db = null;
395
-					    if ($globalDebug && isset($result)) echo $result."\n";
396
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
391
+						$timeelapsed = microtime(true);
392
+						$Marine = new Marine($this->db);
393
+						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
394
+						$Marine->db = null;
395
+						if ($globalDebug && isset($result)) echo $result."\n";
396
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397 397
 					}
398
-				    }
399
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
398
+					}
399
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
400 400
 					// Add source stat in DB
401 401
 					$Stats = new Stats($this->db);
402 402
 					if (!empty($this->stats)) {
403
-					    if ($globalDebug) echo 'Add source stats : ';
404
-				    	    foreach($this->stats as $date => $data) {
403
+						if ($globalDebug) echo 'Add source stats : ';
404
+							foreach($this->stats as $date => $data) {
405 405
 						foreach($data as $source => $sourced) {
406
-					    	    //print_r($sourced);
407
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
408
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
409
-				    		    if (isset($sourced['msg'])) {
410
-				    			if (time() - $sourced['msg']['date'] > 10) {
411
-				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
412
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
413
-			    			    	    unset($this->stats[$date][$source]['msg']);
414
-			    				}
415
-			    			    }
416
-			    			}
417
-			    			if ($date != date('Y-m-d')) {
418
-			    			    unset($this->stats[$date]);
419
-			    			}
420
-				    	    }
421
-				    	    if ($globalDebug) echo 'Done'."\n";
406
+								//print_r($sourced);
407
+									if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
408
+									if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
409
+								if (isset($sourced['msg'])) {
410
+								if (time() - $sourced['msg']['date'] > 10) {
411
+										$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
412
+										echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
413
+										unset($this->stats[$date][$source]['msg']);
414
+								}
415
+								}
416
+							}
417
+							if ($date != date('Y-m-d')) {
418
+								unset($this->stats[$date]);
419
+							}
420
+							}
421
+							if ($globalDebug) echo 'Done'."\n";
422 422
 					}
423 423
 					$Stats->db = null;
424
-				    }
424
+					}
425 425
 				    
426
-				    $this->del();
426
+					$this->del();
427 427
 				//$ignoreImport = false;
428 428
 				$this->all_tracked[$id]['addedMarine'] = 1;
429 429
 				//print_r($this->all_tracked[$id]);
430 430
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
431
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
432
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
433
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
431
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
432
+					//MarineLive->deleteLiveMarineDataNotUpdated();
433
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
434 434
 					$MarineLive = new MarineLive($this->db);
435 435
 					$MarineLive->deleteLiveMarineData();
436 436
 					$MarineLive->db=null;
437 437
 					if ($globalDebug) echo " Done\n";
438
-				    }
439
-				    $this->last_delete = time();
438
+					}
439
+					$this->last_delete = time();
440 440
 				}
441
-			    } elseif ($recent_ident != '') {
441
+				} elseif ($recent_ident != '') {
442 442
 				$this->all_tracked[$id]['id'] = $recent_ident;
443 443
 				$this->all_tracked[$id]['addedMarine'] = 1;
444 444
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
445
-				    if (isset($globalDaemon) && !$globalDaemon) {
445
+					if (isset($globalDaemon) && !$globalDaemon) {
446 446
 					$Marine = new Marine($this->db);
447 447
 					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
448 448
 					$Marine->db = null;
449
-				    }
449
+					}
450 450
 				}
451 451
 				
452
-			    }
452
+				}
453
+			}
453 454
 			}
454
-		    }
455
-		    //adds the spotter LIVE data
456
-		    if ($globalDebug) {
455
+			//adds the spotter LIVE data
456
+			if ($globalDebug) {
457 457
 			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'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
458
-		    }
459
-		    $ignoreImport = false;
458
+			}
459
+			$ignoreImport = false;
460 460
 
461
-		    if (!$ignoreImport) {
461
+			if (!$ignoreImport) {
462 462
 			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'])) {
463 463
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
464 464
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
465
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
465
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466 466
 					$timeelapsed = microtime(true);
467 467
 					$MarineLive = new MarineLive($this->db);
468 468
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
469 469
 					$MarineLive->db = null;
470 470
 					if ($globalDebug) echo $result."\n";
471 471
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
472
-				    }
472
+					}
473 473
 				}
474 474
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
475
-				    $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
475
+					$APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
476 476
 				}
477 477
 				$this->all_tracked[$id]['putinarchive'] = false;
478 478
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 					if ($stats_heading == 16) $stats_heading = 0;
505 505
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
506 506
 						for ($i=0;$i<=15;$i++) {
507
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
507
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
508 508
 						}
509 509
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
510 510
 					} else {
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 					//var_dump($this->stats);
518 518
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
519 519
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
520
-						    end($this->stats[$current_date][$source]['hist']);
521
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
520
+							end($this->stats[$current_date][$source]['hist']);
521
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
522 522
 						} else $mini = 0;
523 523
 						for ($i=$mini;$i<=$distance;$i+=10) {
524
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
524
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
525 525
 						}
526 526
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
527 527
 					} else {
@@ -537,24 +537,24 @@  discard block
 block discarded – undo
537 537
 			
538 538
 			
539 539
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
540
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
540
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
541 541
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
542 542
 				$MarineLive = new MarineLive($this->db);
543 543
 				$MarineLive->deleteLiveMarineDataNotUpdated();
544 544
 				$MarineLive->db = null;
545 545
 				//MarineLive->deleteLiveMarineData();
546 546
 				if ($globalDebug) echo " Done\n";
547
-			    }
548
-			    $this->last_delete_hourly = time();
547
+				}
548
+				$this->last_delete_hourly = time();
549 549
 			}
550 550
 			
551
-		    }
552
-		    //$ignoreImport = false;
551
+			}
552
+			//$ignoreImport = false;
553 553
 		}
554 554
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
555 555
 		if ($send) return $this->all_tracked[$id];
556
-	    }
556
+		}
557
+	}
557 558
 	}
558
-    }
559 559
 }
560 560
 ?>
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60 60
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61 61
     		    $Marine = new Marine($this->db);
62
-    		    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
62
+    		    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
63 63
 		}
64 64
 	    }
65 65
 	}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
72 72
 	foreach ($this->all_tracked as $key => $flight) {
73 73
     	    if (isset($flight['lastupdate'])) {
74
-        	if ($flight['lastupdate'] < (time()-3000)) {
74
+        	if ($flight['lastupdate'] < (time() - 3000)) {
75 75
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 76
             		if (isset($this->all_tracked[$key]['id'])) {
77 77
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             		    //$real_arrival = $this->arrival($key);
84 84
             		    $Marine = new Marine($this->db);
85 85
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86
-				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
86
+				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
87 87
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
88 88
 			    }
89 89
 			    // Put in archive
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
     }
98 98
 
99 99
     public function add($line) {
100
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
100
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine;
101 101
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
102 102
 	date_default_timezone_set('UTC');
103 103
 	$dataFound = false;
104 104
 	$send = false;
105 105
 	
106 106
 	// SBS format is CSV format
107
-	if(is_array($line) && isset($line['mmsi'])) {
107
+	if (is_array($line) && isset($line['mmsi'])) {
108 108
 	    //print_r($line);
109 109
   	    if (isset($line['mmsi'])) {
110 110
 
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
 		
130 130
 		if (!isset($this->all_tracked[$id])) {
131 131
 		    $this->all_tracked[$id] = array();
132
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
133
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
133
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => ''));
134
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
135 135
 		    if (!isset($line['id'])) {
136 136
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
137
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
137
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
138
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
139 139
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
140 140
 		}
141 141
 		
142 142
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
143
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
144 144
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
145 145
 			$Marine = new Marine($this->db);
146 146
 			$identity = $Marine->getIdentity($line['mmsi']);
@@ -154,23 +154,23 @@  discard block
 block discarded – undo
154 154
 		    }
155 155
 		}
156 156
 		if (isset($line['type_id'])) {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
158
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
159 159
 		}
160 160
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
162
-		    if (!isset($line['type_id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
161
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
162
+		    if (!isset($line['type_id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($line['type'])));
163 163
 		}
164 164
 		if (isset($line['status']) && $line['status'] != '') {
165
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
165
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
166 166
 		}
167 167
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
168
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
168
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
169 169
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
170 170
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
171 171
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
172 172
 				$Marine = new Marine($this->db);
173
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
173
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
174 174
 				unset($Marine);
175 175
 			    }
176 176
 			}
@@ -179,24 +179,24 @@  discard block
 block discarded – undo
179 179
 
180 180
 
181 181
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
182
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
182
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
183 183
 		}
184 184
 		if (isset($line['imo']) && $line['imo'] != '') {
185
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
185
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
186 186
 		}
187 187
 		if (isset($line['callsign']) && $line['callsign'] != '') {
188
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
188
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
189 189
 		}
190 190
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
191 191
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
192
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
192
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
193 193
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
194 194
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
195 195
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
196 196
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
197 197
 				    $Marine = new Marine($this->db);
198 198
 				    $fromsource = NULL;
199
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
199
+				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource);
200 200
 				    $Marine->db = null;
201 201
 				}
202 202
 			    }
@@ -212,46 +212,46 @@  discard block
 block discarded – undo
212 212
 		    }
213 213
 		}
214 214
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
215
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
215
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
216 216
 		}
217 217
 
218 218
 		//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'])) {
219 219
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
220
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
220
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
221 221
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
222 222
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
223 223
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
224 224
 				$timeelapsed = microtime(true);
225 225
 				$Marine = new Marine($this->db);
226 226
 				$fromsource = NULL;
227
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
227
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
228 228
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
229
-				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
229
+				$Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']);
230 230
 				$Marine->db = null;
231
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
231
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
232 232
 			    }
233 233
 			}
234 234
 		    }
235
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
235
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
236 236
 		}
237 237
 
238
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
238
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
239 239
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
240
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
240
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
241 241
 		    } else {
242 242
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
243 243
 				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]['hex']." - format : ".$line['format_source']."\n";
244 244
 				return '';
245 245
 		    }
246
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
246
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
247 247
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
248 248
 			return '';
249
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
249
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
250 250
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
251 251
 			return '';
252 252
 		} elseif (!isset($line['datetime'])) {
253 253
 			date_default_timezone_set('UTC');
254
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
255 255
 		} else {
256 256
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
257 257
 			return '';
@@ -259,24 +259,24 @@  discard block
 block discarded – undo
259 259
 
260 260
 
261 261
 		if (isset($line['speed'])) {
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
263
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
262
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
263
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
264 264
 		} 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'])) {
265
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
265
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
266 266
 		    if ($distance > 1000 && $distance < 10000) {
267 267
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
268 268
 			$speed = $speed*3.6;
269
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
269
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
270 270
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
271 271
 		    }
272 272
 		}
273 273
 
274 274
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
275
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
275
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
276 276
 	    	    else unset($timediff);
277
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($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')))) {
277
+	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($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')))) {
278 278
 			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'])) {
279
-			    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'])) {
279
+			    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'])) {
280 280
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
281 281
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
282 282
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -285,10 +285,10 @@  discard block
 block discarded – undo
285 285
 				$timeelapsed = microtime(true);
286 286
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
287 287
 				    $Marine = new Marine($this->db);
288
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
288
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
289 289
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
290 290
 				    $Marine->db = null;
291
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
291
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
292 292
 				}
293 293
 				$this->tmd = 0;
294 294
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -297,55 +297,55 @@  discard block
 block discarded – undo
297 297
 
298 298
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
299 299
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
300
-				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') {
300
+				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') {
301 301
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
302 302
 				    $dataFound = true;
303 303
 				    $this->all_tracked[$id]['time_last_coord'] = time();
304 304
 				}
305
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
305
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
306 306
 			}
307 307
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
308 308
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
309 309
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
310
-				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') {
310
+				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') {
311 311
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
312 312
 				    $dataFound = true;
313 313
 				    $this->all_tracked[$id]['time_last_coord'] = time();
314 314
 				}
315
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
315
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
316 316
 			}
317 317
 
318 318
 		    } else if ($globalDebug && $timediff > 20) {
319 319
 			$this->tmd = $this->tmd + 1;
320 320
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
321
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
322
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
321
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
322
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
323 323
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
324 324
 		    }
325 325
 		}
326 326
 		if (isset($line['last_update']) && $line['last_update'] != '') {
327 327
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
328
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
328
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
329 329
 		}
330 330
 		if (isset($line['format_source']) && $line['format_source'] != '') {
331
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
331
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
332 332
 		}
333 333
 		if (isset($line['source_name']) && $line['source_name'] != '') {
334
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
334
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
335 335
 		}
336 336
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
337
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
337
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
338 338
 		}
339 339
 		
340 340
 		if (isset($line['heading']) && $line['heading'] != '') {
341
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
342
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
343
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
341
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
342
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
343
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
344 344
 		    //$dataFound = true;
345 345
   		} 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']) {
346
-  		    $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']);
347
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
348
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
346
+  		    $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']);
347
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
348
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
349 349
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
350 350
   		}
351 351
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
356 356
 		    $this->all_tracked[$id]['lastupdate'] = time();
357 357
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
358
-		        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'])) {
358
+		        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'])) {
359 359
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
360 360
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
361 361
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -363,37 +363,37 @@  discard block
 block discarded – undo
363 363
 				    $MarineLive = new MarineLive($this->db);
364 364
 				    if (isset($line['id'])) {
365 365
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
366
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
366
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
367 367
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
368 368
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
369
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
370 370
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
371 371
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
372
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
373 373
 				    } else $recent_ident = '';
374
-				    $MarineLive->db=null;
374
+				    $MarineLive->db = null;
375 375
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
376 376
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
377 377
 				} else $recent_ident = '';
378 378
 			    } else {
379 379
 				$recent_ident = '';
380
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
380
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
381 381
 			    }
382 382
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
383
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
383
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
384 384
 			    {
385 385
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
386 386
 				//adds the spotter data for the archive
387 387
 				    $highlight = '';
388
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
388
+				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
389 389
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
390 390
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
391 391
 					    $timeelapsed = microtime(true);
392 392
 					    $Marine = new Marine($this->db);
393
-					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
393
+					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']);
394 394
 					    $Marine->db = null;
395 395
 					    if ($globalDebug && isset($result)) echo $result."\n";
396
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
396
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
397 397
 					}
398 398
 				    }
399 399
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -401,15 +401,15 @@  discard block
 block discarded – undo
401 401
 					$Stats = new Stats($this->db);
402 402
 					if (!empty($this->stats)) {
403 403
 					    if ($globalDebug) echo 'Add source stats : ';
404
-				    	    foreach($this->stats as $date => $data) {
405
-						foreach($data as $source => $sourced) {
404
+				    	    foreach ($this->stats as $date => $data) {
405
+						foreach ($data as $source => $sourced) {
406 406
 					    	    //print_r($sourced);
407
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
408
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
407
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
408
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
409 409
 				    		    if (isset($sourced['msg'])) {
410 410
 				    			if (time() - $sourced['msg']['date'] > 10) {
411 411
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
412
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
412
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
413 413
 			    			    	    unset($this->stats[$date][$source]['msg']);
414 414
 			    				}
415 415
 			    			    }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
434 434
 					$MarineLive = new MarineLive($this->db);
435 435
 					$MarineLive->deleteLiveMarineData();
436
-					$MarineLive->db=null;
436
+					$MarineLive->db = null;
437 437
 					if ($globalDebug) echo " Done\n";
438 438
 				    }
439 439
 				    $this->last_delete = time();
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
445 445
 				    if (isset($globalDaemon) && !$globalDaemon) {
446 446
 					$Marine = new Marine($this->db);
447
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
447
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
448 448
 					$Marine->db = null;
449 449
 				    }
450 450
 				}
@@ -459,20 +459,20 @@  discard block
 block discarded – undo
459 459
 		    $ignoreImport = false;
460 460
 
461 461
 		    if (!$ignoreImport) {
462
-			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'])) {
462
+			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'])) {
463 463
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
464 464
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
465 465
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466 466
 					$timeelapsed = microtime(true);
467 467
 					$MarineLive = new MarineLive($this->db);
468
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
468
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
469 469
 					$MarineLive->db = null;
470 470
 					if ($globalDebug) echo $result."\n";
471
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
471
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
472 472
 				    }
473 473
 				}
474 474
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
475
-				    $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
475
+				    $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
476 476
 				}
477 477
 				$this->all_tracked[$id]['putinarchive'] = false;
478 478
 
@@ -491,19 +491,19 @@  discard block
 block discarded – undo
491 491
 							$latitude = $globalCenterLatitude;
492 492
 							$longitude = $globalCenterLongitude;
493 493
 						}
494
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
494
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
495 495
 					} else {
496 496
 						$latitude = $this->source_location[$source]['latitude'];
497 497
 						$longitude = $this->source_location[$source]['longitude'];
498 498
 					}
499
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
499
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
500 500
 					//$stats_heading = $stats_heading%22.5;
501 501
 					$stats_heading = round($stats_heading/22.5);
502
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
502
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
503 503
 					$current_date = date('Y-m-d');
504 504
 					if ($stats_heading == 16) $stats_heading = 0;
505 505
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
506
-						for ($i=0;$i<=15;$i++) {
506
+						for ($i = 0; $i <= 15; $i++) {
507 507
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
508 508
 						}
509 509
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -518,9 +518,9 @@  discard block
 block discarded – undo
518 518
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
519 519
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
520 520
 						    end($this->stats[$current_date][$source]['hist']);
521
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
521
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
522 522
 						} else $mini = 0;
523
-						for ($i=$mini;$i<=$distance;$i+=10) {
523
+						for ($i = $mini; $i <= $distance; $i += 10) {
524 524
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
525 525
 						}
526 526
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 
533 533
 				$this->all_tracked[$id]['lastupdate'] = time();
534 534
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
535
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
535
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
536 536
 			//$this->del();
537 537
 			
538 538
 			
Please login to merge, or discard this patch.
Braces   +205 added lines, -70 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
     public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
57
+	    if ($globalDebug) {
58
+	    	echo "Update last seen tracked data...\n";
59
+	    }
58 60
 	    foreach ($this->all_tracked as $key => $flight) {
59 61
 		if (isset($this->all_tracked[$key]['id'])) {
60 62
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -68,13 +70,17 @@  discard block
 block discarded – undo
68 70
     public function del() {
69 71
 	global $globalDebug, $globalNoDB, $globalNoImport;
70 72
 	// Delete old infos
71
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
73
+	if ($globalDebug) {
74
+		echo 'Delete old values and update latest data...'."\n";
75
+	}
72 76
 	foreach ($this->all_tracked as $key => $flight) {
73 77
     	    if (isset($flight['lastupdate'])) {
74 78
         	if ($flight['lastupdate'] < (time()-3000)) {
75 79
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 80
             		if (isset($this->all_tracked[$key]['id'])) {
77
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
81
+            		    if ($globalDebug) {
82
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
83
+            		    }
78 84
 			    /*
79 85
 			    $MarineLive = new MarineLive();
80 86
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -84,7 +90,9 @@  discard block
 block discarded – undo
84 90
             		    $Marine = new Marine($this->db);
85 91
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86 92
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
87
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
93
+				if ($globalDebug && $result != 'success') {
94
+					echo '!!! ERROR : '.$result."\n";
95
+				}
88 96
 			    }
89 97
 			    // Put in archive
90 98
 //				$Marine->db = null;
@@ -98,7 +106,9 @@  discard block
 block discarded – undo
98 106
 
99 107
     public function add($line) {
100 108
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
101
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
109
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
110
+		$globalCoordMinChange = '0.02';
111
+	}
102 112
 	date_default_timezone_set('UTC');
103 113
 	$dataFound = false;
104 114
 	$send = false;
@@ -112,20 +122,30 @@  discard block
 block discarded – undo
112 122
 		// Increment message number
113 123
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
114 124
 		    $current_date = date('Y-m-d');
115
-		    if (isset($line['source_name'])) $source = $line['source_name'];
116
-		    else $source = '';
117
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
125
+		    if (isset($line['source_name'])) {
126
+		    	$source = $line['source_name'];
127
+		    } else {
128
+		    	$source = '';
129
+		    }
130
+		    if ($source == '' || $line['format_source'] == 'aprs') {
131
+		    	$source = $line['format_source'];
132
+		    }
118 133
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
119 134
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
120 135
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
121
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
136
+		    } else {
137
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
138
+		    }
122 139
 		}
123 140
 		
124 141
 		
125 142
 		$Common = new Common();
126 143
 		$AIS = new AIS();
127
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
128
-	        else $id = trim($line['id']);
144
+	        if (!isset($line['id'])) {
145
+	        	$id = trim($line['mmsi']);
146
+	        } else {
147
+	        	$id = trim($line['id']);
148
+	        }
129 149
 		
130 150
 		if (!isset($this->all_tracked[$id])) {
131 151
 		    $this->all_tracked[$id] = array();
@@ -133,10 +153,16 @@  discard block
 block discarded – undo
133 153
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134 154
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
135 155
 		    if (!isset($line['id'])) {
136
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
156
+			if (!isset($globalDaemon)) {
157
+				$globalDaemon = TRUE;
158
+			}
137 159
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
139
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
160
+		     } else {
161
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
162
+		     }
163
+		    if ($globalAllTracked !== FALSE) {
164
+		    	$dataFound = true;
165
+		    }
140 166
 		}
141 167
 		
142 168
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -159,7 +185,9 @@  discard block
 block discarded – undo
159 185
 		}
160 186
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
161 187
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
162
-		    if (!isset($line['type_id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
188
+		    if (!isset($line['type_id'])) {
189
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
190
+		    }
163 191
 		}
164 192
 		if (isset($line['status']) && $line['status'] != '') {
165 193
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
@@ -190,7 +218,9 @@  discard block
 block discarded – undo
190 218
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
191 219
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
192 220
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
193
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
221
+			if ($globalDebug) {
222
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
223
+			}
194 224
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
195 225
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
196 226
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -203,7 +233,9 @@  discard block
 block discarded – undo
203 233
 			}
204 234
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
205 235
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
206
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
236
+			if ($globalDebug) {
237
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
238
+			}
207 239
 			if (!isset($line['id'])) {
208 240
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
209 241
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -212,7 +244,9 @@  discard block
 block discarded – undo
212 244
 		    }
213 245
 		}
214 246
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
215
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
247
+		    if (strtotime($line['arrival_date']) > time()) {
248
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
249
+		    }
216 250
 		}
217 251
 
218 252
 		//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'])) {
@@ -225,35 +259,50 @@  discard block
 block discarded – undo
225 259
 				$Marine = new Marine($this->db);
226 260
 				$fromsource = NULL;
227 261
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
228
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
262
+				if ($globalDebug && $result != 'success') {
263
+					echo '!!! ERROR : '.$result."\n";
264
+				}
229 265
 				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
230 266
 				$Marine->db = null;
231
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
267
+				if ($globalDebugTimeElapsed) {
268
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
269
+				}
232 270
 			    }
233 271
 			}
234 272
 		    }
235
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
273
+		    if (!isset($this->all_tracked[$id]['id'])) {
274
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
275
+		    }
236 276
 		}
237 277
 
238 278
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
239 279
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
240 280
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
241 281
 		    } else {
242
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
243
-				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]['hex']." - format : ".$line['format_source']."\n";
282
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
283
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
284
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
285
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
286
+				}
244 287
 				return '';
245 288
 		    }
246 289
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
247
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
290
+			if ($globalDebug) {
291
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
292
+			}
248 293
 			return '';
249 294
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
250
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
295
+			if ($globalDebug) {
296
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
297
+			}
251 298
 			return '';
252 299
 		} elseif (!isset($line['datetime'])) {
253 300
 			date_default_timezone_set('UTC');
254 301
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
255 302
 		} else {
256
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
303
+			if ($globalDebug) {
304
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
305
+			}
257 306
 			return '';
258 307
 		}
259 308
 
@@ -266,14 +315,21 @@  discard block
 block discarded – undo
266 315
 		    if ($distance > 1000 && $distance < 10000) {
267 316
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
268 317
 			$speed = $speed*3.6;
269
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
270
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
318
+			if ($speed < 1000) {
319
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
320
+			}
321
+  			if ($globalDebug) {
322
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
323
+  			}
271 324
 		    }
272 325
 		}
273 326
 
274 327
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
275
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
276
-	    	    else unset($timediff);
328
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
329
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
330
+	    	    } else {
331
+	    	    	unset($timediff);
332
+	    	    }
277 333
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($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')))) {
278 334
 			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'])) {
279 335
 			    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'])) {
@@ -281,22 +337,32 @@  discard block
 block discarded – undo
281 337
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
282 338
 				$this->all_tracked[$id]['putinarchive'] = true;
283 339
 				
284
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
340
+				if ($globalDebug) {
341
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
342
+				}
285 343
 				$timeelapsed = microtime(true);
286 344
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
287 345
 				    $Marine = new Marine($this->db);
288 346
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
289
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
347
+				    if (!empty($all_country)) {
348
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
349
+				    }
290 350
 				    $Marine->db = null;
291
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+				    if ($globalDebugTimeElapsed) {
352
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353
+				    }
292 354
 				}
293 355
 				$this->tmd = 0;
294
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
356
+				if ($globalDebug) {
357
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
358
+				}
295 359
 			    }
296 360
 			}
297 361
 
298 362
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
299
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
363
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
364
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
365
+				}
300 366
 				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') {
301 367
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
302 368
 				    $dataFound = true;
@@ -305,8 +371,12 @@  discard block
 block discarded – undo
305 371
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
306 372
 			}
307 373
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
308
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
309
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
374
+			    if ($line['longitude'] > 180) {
375
+			    	$line['longitude'] = $line['longitude'] - 360;
376
+			    }
377
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
378
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
379
+				}
310 380
 				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') {
311 381
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
312 382
 				    $dataFound = true;
@@ -324,7 +394,9 @@  discard block
 block discarded – undo
324 394
 		    }
325 395
 		}
326 396
 		if (isset($line['last_update']) && $line['last_update'] != '') {
327
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
397
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
398
+		    	$dataFound = true;
399
+		    }
328 400
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
329 401
 		}
330 402
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -338,15 +410,21 @@  discard block
 block discarded – undo
338 410
 		}
339 411
 		
340 412
 		if (isset($line['heading']) && $line['heading'] != '') {
341
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
413
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
414
+		    	$this->all_tracked[$id]['putinarchive'] = true;
415
+		    }
342 416
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
343 417
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
344 418
 		    //$dataFound = true;
345 419
   		} 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']) {
346 420
   		    $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']);
347 421
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
348
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
349
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
422
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
423
+		    	$this->all_tracked[$id]['putinarchive'] = true;
424
+		    }
425
+  		    if ($globalDebug) {
426
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
427
+  		    }
350 428
   		}
351 429
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
352 430
 
@@ -358,23 +436,38 @@  discard block
 block discarded – undo
358 436
 		        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'])) {
359 437
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
360 438
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
361
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
439
+				    if ($globalDebug) {
440
+				    	echo "Check if vessel is already in DB...";
441
+				    }
362 442
 				    $timeelapsed = microtime(true);
363 443
 				    $MarineLive = new MarineLive($this->db);
364 444
 				    if (isset($line['id'])) {
365 445
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
366
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
446
+					if ($globalDebugTimeElapsed) {
447
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
448
+					}
367 449
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
368 450
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
369
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+					if ($globalDebugTimeElapsed) {
452
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
453
+					}
370 454
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
371 455
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
372
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
373
-				    } else $recent_ident = '';
456
+					if ($globalDebugTimeElapsed) {
457
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
458
+					}
459
+				    } else {
460
+				    	$recent_ident = '';
461
+				    }
374 462
 				    $MarineLive->db=null;
375
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
376
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
377
-				} else $recent_ident = '';
463
+				    if ($globalDebug && $recent_ident == '') {
464
+				    	echo " Not in DB.\n";
465
+				    } elseif ($globalDebug && $recent_ident != '') {
466
+				    	echo " Already in DB.\n";
467
+				    }
468
+				} else {
469
+					$recent_ident = '';
470
+				}
378 471
 			    } else {
379 472
 				$recent_ident = '';
380 473
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -382,30 +475,44 @@  discard block
 block discarded – undo
382 475
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
383 476
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
384 477
 			    {
385
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
478
+				if ($globalDebug) {
479
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
480
+				}
386 481
 				//adds the spotter data for the archive
387 482
 				    $highlight = '';
388
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
483
+				    if (!isset($this->all_tracked[$id]['id'])) {
484
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
485
+				    }
389 486
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
390 487
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
391 488
 					    $timeelapsed = microtime(true);
392 489
 					    $Marine = new Marine($this->db);
393 490
 					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
394 491
 					    $Marine->db = null;
395
-					    if ($globalDebug && isset($result)) echo $result."\n";
396
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
492
+					    if ($globalDebug && isset($result)) {
493
+					    	echo $result."\n";
494
+					    }
495
+					    if ($globalDebugTimeElapsed) {
496
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
497
+					    }
397 498
 					}
398 499
 				    }
399 500
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
400 501
 					// Add source stat in DB
401 502
 					$Stats = new Stats($this->db);
402 503
 					if (!empty($this->stats)) {
403
-					    if ($globalDebug) echo 'Add source stats : ';
504
+					    if ($globalDebug) {
505
+					    	echo 'Add source stats : ';
506
+					    }
404 507
 				    	    foreach($this->stats as $date => $data) {
405 508
 						foreach($data as $source => $sourced) {
406 509
 					    	    //print_r($sourced);
407
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
408
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
510
+				    	    	    if (isset($sourced['polar'])) {
511
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
512
+				    	    	    }
513
+				    	    	    if (isset($sourced['hist'])) {
514
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
515
+				    	    	    }
409 516
 				    		    if (isset($sourced['msg'])) {
410 517
 				    			if (time() - $sourced['msg']['date'] > 10) {
411 518
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -418,7 +525,9 @@  discard block
 block discarded – undo
418 525
 			    			    unset($this->stats[$date]);
419 526
 			    			}
420 527
 				    	    }
421
-				    	    if ($globalDebug) echo 'Done'."\n";
528
+				    	    if ($globalDebug) {
529
+				    	    	echo 'Done'."\n";
530
+				    	    }
422 531
 					}
423 532
 					$Stats->db = null;
424 533
 				    }
@@ -428,13 +537,17 @@  discard block
 block discarded – undo
428 537
 				$this->all_tracked[$id]['addedMarine'] = 1;
429 538
 				//print_r($this->all_tracked[$id]);
430 539
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
431
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
540
+				    if ($globalDebug) {
541
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
542
+				    }
432 543
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
433 544
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
434 545
 					$MarineLive = new MarineLive($this->db);
435 546
 					$MarineLive->deleteLiveMarineData();
436 547
 					$MarineLive->db=null;
437
-					if ($globalDebug) echo " Done\n";
548
+					if ($globalDebug) {
549
+						echo " Done\n";
550
+					}
438 551
 				    }
439 552
 				    $this->last_delete = time();
440 553
 				}
@@ -460,15 +573,21 @@  discard block
 block discarded – undo
460 573
 
461 574
 		    if (!$ignoreImport) {
462 575
 			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'])) {
463
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
576
+				if ($globalDebug) {
577
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
578
+				}
464 579
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
465 580
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
466 581
 					$timeelapsed = microtime(true);
467 582
 					$MarineLive = new MarineLive($this->db);
468 583
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
469 584
 					$MarineLive->db = null;
470
-					if ($globalDebug) echo $result."\n";
471
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
585
+					if ($globalDebug) {
586
+						echo $result."\n";
587
+					}
588
+					if ($globalDebugTimeElapsed) {
589
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
590
+					}
472 591
 				    }
473 592
 				}
474 593
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -480,7 +599,9 @@  discard block
 block discarded – undo
480 599
 				
481 600
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
482 601
 					$source = $this->all_tracked[$id]['source_name'];
483
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
602
+					if ($source == '') {
603
+						$source = $this->all_tracked[$id]['format_source'];
604
+					}
484 605
 					if (!isset($this->source_location[$source])) {
485 606
 						$Location = new Source($this->db);
486 607
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -501,7 +622,9 @@  discard block
 block discarded – undo
501 622
 					$stats_heading = round($stats_heading/22.5);
502 623
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
503 624
 					$current_date = date('Y-m-d');
504
-					if ($stats_heading == 16) $stats_heading = 0;
625
+					if ($stats_heading == 16) {
626
+						$stats_heading = 0;
627
+					}
505 628
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
506 629
 						for ($i=0;$i<=15;$i++) {
507 630
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -519,7 +642,9 @@  discard block
 block discarded – undo
519 642
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
520 643
 						    end($this->stats[$current_date][$source]['hist']);
521 644
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
522
-						} else $mini = 0;
645
+						} else {
646
+							$mini = 0;
647
+						}
523 648
 						for ($i=$mini;$i<=$distance;$i+=10) {
524 649
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
525 650
 						}
@@ -531,19 +656,27 @@  discard block
 block discarded – undo
531 656
 				
532 657
 
533 658
 				$this->all_tracked[$id]['lastupdate'] = time();
534
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
535
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
659
+				if ($this->all_tracked[$id]['putinarchive']) {
660
+					$send = true;
661
+				}
662
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
663
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
664
+			}
536 665
 			//$this->del();
537 666
 			
538 667
 			
539 668
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
540 669
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
541
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
670
+				if ($globalDebug) {
671
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
672
+				}
542 673
 				$MarineLive = new MarineLive($this->db);
543 674
 				$MarineLive->deleteLiveMarineDataNotUpdated();
544 675
 				$MarineLive->db = null;
545 676
 				//MarineLive->deleteLiveMarineData();
546
-				if ($globalDebug) echo " Done\n";
677
+				if ($globalDebug) {
678
+					echo " Done\n";
679
+				}
547 680
 			    }
548 681
 			    $this->last_delete_hourly = time();
549 682
 			}
@@ -552,7 +685,9 @@  discard block
 block discarded – undo
552 685
 		    //$ignoreImport = false;
553 686
 		}
554 687
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
555
-		if ($send) return $this->all_tracked[$id];
688
+		if ($send) {
689
+			return $this->all_tracked[$id];
690
+		}
556 691
 	    }
557 692
 	}
558 693
     }
Please login to merge, or discard this patch.