Issues (843)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

require/class.MarineImport.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This class is part of FlightAirmap. It's used to import marine data
4
 *
5
 * Copyright (c) Ycarus (Yannick Chabanois) <[email protected]>
6
 * Licensed under AGPL license.
7
 * For more information see: https://www.flightairmap.com/
8
*/
9
require_once(dirname(__FILE__).'/class.Connection.php');
10
require_once(dirname(__FILE__).'/class.AIS.php');
11
require_once(dirname(__FILE__).'/class.Marine.php');
12
require_once(dirname(__FILE__).'/class.MarineLive.php');
13
require_once(dirname(__FILE__).'/class.MarineArchive.php');
14
require_once(dirname(__FILE__).'/class.Scheduler.php');
15
require_once(dirname(__FILE__).'/class.Translation.php');
16
require_once(dirname(__FILE__).'/class.Stats.php');
17
require_once(dirname(__FILE__).'/class.Source.php');
18
if (isset($globalServerAPRS) && $globalServerAPRS) {
19
    require_once(dirname(__FILE__).'/class.APRS.php');
20
}
21
22
class MarineImport {
23
    private $all_tracked = array();
24
    private $last_delete_hourly = 0;
25
    private $last_delete = 0;
26
    private $stats = array();
27
    private $tmd = 0;
28
    private $source_location = array();
29
    public $db = null;
30
    public $nb = 0;
31
32
    public function __construct($dbc = null) {
33
	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
34
	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
35
	    $Connection = new Connection($dbc);
36
	    $this->db = $Connection->db();
37
	    date_default_timezone_set('UTC');
38
	}
39
	// Get previous source stats
40
	/*
41
	$Stats = new Stats($dbc);
42
	$currentdate = date('Y-m-d');
43
	$sourcestat = $Stats->getStatsSource($currentdate);
44
	if (!empty($sourcestat)) {
45
	    foreach($sourcestat as $srcst) {
46
	    	$type = $srcst['stats_type'];
47
		if ($type == 'polar' || $type == 'hist') {
48
		    $source = $srcst['source_name'];
49
		    $data = $srcst['source_data'];
50
		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
51
	        }
52
	    }
53
	}
54
	*/
55
	if (isset($globalServerAPRS) && $globalServerAPRS) {
56
	    $APRSMarine = new APRSMarine();
57
	    //$APRSSpotter->connect();
58
	}
59
    }
60
61
    public function checkAll() {
62
	global $globalDebug, $globalNoDB, $globalVM;
63
	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
64
	    if ($globalDebug) echo "Update last seen tracked data...\n";
65
	    foreach ($this->all_tracked as $key => $flight) {
66
		if (isset($this->all_tracked[$key]['id'])) {
67
		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
68
    		    $Marine = new Marine($this->db);
69
    		    if (isset($globalVM) && $globalVM) {
70
			if ($this->all_tracked[$key]['status'] == 'Racing') {
71
    			    $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'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
72
    			} else {
73
    			    $timerace = (strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
74
    			    if ($timerace > time()) $finaldatetime = NULL;
75
    			    else $finaldatetime = date('Y-m-d H:i:s',$timerace);
76
    			    $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'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
77
    			}
78
    		    } else {
79
			$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'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
80
		    }
81
		}
82
	    }
83
	}
84
    }
85
86
    public function del() {
87
	global $globalDebug, $globalNoDB, $globalNoImport;
88
	// Delete old infos
89
	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
90
	foreach ($this->all_tracked as $key => $flight) {
91
    	    if (isset($flight['lastupdate'])) {
92
        	if ($flight['lastupdate'] < (time()-3000)) {
93
            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
94
            		if (isset($this->all_tracked[$key]['id'])) {
95
            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
96
			    /*
97
			    $MarineLive = new MarineLive();
98
            		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
99
			    $MarineLive->db = null;
100
			    */
101
            		    //$real_arrival = $this->arrival($key);
102
            		    $Marine = new Marine($this->db);
103
            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
104
				if (isset($globalVM) && $globalVM) {
105
				    if ($this->all_tracked[$key]['status'] == 'Racing') {
106
					$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'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
107
				    } else {
108
					$timerace = strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time'];
109
	        			if ($timerace > time()) $finaldatetime = NULL;
110
					else $finaldatetime = date('Y-m-d H:i:s',$timerace);
111
					$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'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
112
				    }
113
				} else {
114
					$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'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
115
				}
116
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
117
			    }
118
			    // Put in archive
119
//				$Marine->db = null;
120
			}
121
            	    }
122
            	    unset($this->all_tracked[$key]);
123
    	        }
124
	    }
125
        }
126
    }
127
128
    public function add($line) {
129
	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM, $globalOnlyID;
130
	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
131
	date_default_timezone_set('UTC');
132
	$dataFound = false;
133
	$send = false;
134
	
135
	// SBS format is CSV format
136
	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
137
	    //print_r($line);
138
  	    if (isset($line['mmsi']) || isset($line['id'])) {
139
140
		
141
		// Increment message number
142
		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
143
		    $current_date = date('Y-m-d');
144
		    if (isset($line['source_name'])) $source = $line['source_name'];
145
		    else $source = '';
146
		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
147
		    if (!isset($this->stats[$current_date][$source]['msg'])) {
148
		    	$this->stats[$current_date][$source]['msg']['date'] = time();
149
		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
150
		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
151
		}
152
		
153
		
154
		$Common = new Common();
155
		$AIS = new AIS();
156
	        if (!isset($line['id'])) $id = trim($line['mmsi']);
157
	        else $id = trim($line['id']);
158
		
159
		if (!isset($this->all_tracked[$id])) {
160
		    $this->all_tracked[$id] = array();
161
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
162
		    $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' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
163
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
164
		    if (!isset($line['id'])) {
165
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
166
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
167
		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
168
		    if ($globalAllTracked !== FALSE) $dataFound = true;
169
		}
170
		
171
		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
172
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
173
		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
174
			$Marine = new Marine($this->db);
175
			$identity = $Marine->getIdentity($line['mmsi']);
176
			if (!empty($identity)) {
177
			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
178
			    $this->all_tracked[$id]['type'] = $identity['type'];
179
			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
180
			}
181
			//print_r($identity);
182
			unset($Marine);
183
			//$dataFound = true;
184
		    }
185
		}
186
		if (isset($line['type_id'])) {
187
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
188
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
189
		}
190
		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
191
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
192
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
193
		} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') {
194
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
195
		}
196
		if (isset($line['status']) && $line['status'] != '') {
197
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
198
		}
199
		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
200
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
201
		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
202
			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
203
			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
204
				$Marine = new Marine($this->db);
205
				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
206
				unset($Marine);
207
			    }
208
			}
209
		    }
210
		}
211
212
213
		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
214
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
215
		}
216
		if (isset($line['imo']) && $line['imo'] != '') {
217
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
218
		}
219
		if (isset($line['callsign']) && $line['callsign'] != '') {
220
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
221
		}
222
		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
223
		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
224
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
225
			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
226
			if ($this->all_tracked[$id]['addedMarine'] != 0) {
227
			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
228
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
229
				    $Marine = new Marine($this->db);
230
				    $fromsource = NULL;
231
				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
232
				    $Marine->db = null;
233
				}
234
			    }
235
			}
236
		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
237
			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
238
			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
239
			if (!isset($line['id'])) {
240
				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
241
				$this->all_tracked[$id]['forcenew'] = 1;
242
				$this->all_tracked[$id]['addedMarine'] = 0;
243
			}
244
		    }
245
		}
246
		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
247
		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
248
		}
249
		if (isset($line['captain_id']) && $line['captain_id'] != '') {
250
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
251
		}
252
		if (isset($line['captain_name']) && $line['captain_name'] != '') {
253
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
254
		}
255
		if (isset($line['race_id']) && $line['race_id'] != '') {
256
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
257
		}
258
		if (isset($line['race_name']) && $line['race_name'] != '') {
259
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
260
		}
261
		if (isset($line['race_rank']) && $line['race_rank'] != '') {
262
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
263
		}
264
		if (isset($line['race_time']) && $line['race_time'] != '') {
265
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
266
		}
267
		if (isset($line['race_begin']) && $line['race_begin'] != '') {
268
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
269
		}
270
		if (isset($line['distance']) && $line['distance'] != '') {
271
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
272
		}
273
274
		//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'])) {
275
		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
276
		    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
277
			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
278
			    $timeelapsed = microtime(true);
0 ignored issues
show
$timeelapsed is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
279
			    $Marine = new Marine($this->db);
280
			    $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']);
281
			    $Marine->db = null;
282
			}
283
		    }
284
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
285
		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
286
			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
287
			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
288
				$timeelapsed = microtime(true);
289
				$Marine = new Marine($this->db);
290
				$fromsource = NULL;
291
				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
292
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
293
				$Marine->db = null;
294
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295
			    }
296
			}
297
		    }
298
		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
299
		}
300
301
		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
302
		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
303
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
304
		    } else {
305
				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";
306
				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";
307
				return '';
308
		    }
309
		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
310
			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
311
			return '';
312
		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
313
			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
314
			return '';
315
		} elseif (!isset($line['datetime'])) {
316
			date_default_timezone_set('UTC');
317
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
318
		} else {
319
			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
320
			return '';
321
		}
322
323
324
		if (isset($line['speed'])) {
325
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
326
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
327
		} 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'])) {
328
		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
329
		    if ($distance > 1000 && $distance < 10000) {
330
			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
331
			$speed = $speed*3.6;
332
			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
333
  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
334
		    }
335
		}
336
337
	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
338
	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
339
	    	    else unset($timediff);
340
	    	    if ($this->tmd > 5 ||
341
	    		!isset($timediff) ||
342
	    		$timediff > $globalLiveInterval ||
343
	    		(
344
	    		    $timediff > 30 && 
345
	    		    isset($this->all_tracked[$id]['latitude']) &&
346
	    		    isset($this->all_tracked[$id]['longitude']) &&
347
	    		    $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
348
	    		)
349
	    		) {
350
			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'])) {
351
			    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'])) {
352
				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
353
				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
354
				$this->all_tracked[$id]['putinarchive'] = true;
355
				
356
				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
357
				$timeelapsed = microtime(true);
358
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
359
				    $Marine = new Marine($this->db);
360
				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
361
				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
362
				    $Marine->db = null;
363
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
364
				}
365
				$this->tmd = 0;
366
				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
367
			    }
368
			}
369
370
			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
371
				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
372
				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') {
373
				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
374
				    $dataFound = true;
375
				    $this->all_tracked[$id]['time_last_coord'] = time();
376
				}
377
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
378
			}
379
			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
380
			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
381
				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
382
				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') {
383
				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
384
				    $dataFound = true;
385
				    $this->all_tracked[$id]['time_last_coord'] = time();
386
				}
387
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
388
			}
389
390
		    } else if ($globalDebug && $timediff > 20) {
391
			$this->tmd = $this->tmd + 1;
392
			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
393
			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
394
			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
395
			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
396
		    }
397
		}
398
		if (isset($line['last_update']) && $line['last_update'] != '') {
399
		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
400
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
401
		}
402
		if (isset($line['format_source']) && $line['format_source'] != '') {
403
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
404
		}
405
		if (isset($line['source_name']) && $line['source_name'] != '') {
406
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
407
		}
408
		if (isset($line['noarchive']) && $line['noarchive'] === true) {
409
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
410
		}
411
		
412
		if (isset($line['heading']) && $line['heading'] != '') {
413
		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
414
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
415
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
416
		    //$dataFound = true;
417
  		} 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']) {
418
  		    $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']);
419
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
420
		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
421
  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
422
  		}
423
		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
424
425
426
427
		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
428
		    $this->all_tracked[$id]['lastupdate'] = time();
429
		    if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
430
		        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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
431
			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
432
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433
				    if ($globalDebug) echo "Check if vessel is already in DB...";
434
				    $timeelapsed = microtime(true);
435
				    $MarineLive = new MarineLive($this->db);
436
				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
437
					$Marine = new Marine($this->db);
438
					$recent_ident = $Marine->checkId($line['id']);
439
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
440
					$Marine->db=null;
441
				    } elseif (isset($line['id'])) {
442
					$recent_ident = $MarineLive->checkIdRecent($line['id']);
443
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
444
				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
445
					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
446
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
447
				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
448
					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
449
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
450
				    } else $recent_ident = '';
451
				    $MarineLive->db=null;
452
				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
453
				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
454
				} else $recent_ident = '';
455
			    } else {
456
				$recent_ident = '';
457
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
458
			    }
459
			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
460
			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
461
			    {
462
				if ($globalDebug) {
463
					if ($this->all_tracked[$id]['mmsi'] != '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
464
					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
465
				}
466
				//adds the spotter data for the archive
467
				    $highlight = '';
0 ignored issues
show
$highlight is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
468
				    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')));
469
				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
470
					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
471
					    $timeelapsed = microtime(true);
472
					    $Marine = new Marine($this->db);
473
					    if (isset($globalVM) && $globalVM && ($this->all_tracked[$id]['race_begin'] != '' || $this->all_tracked[$id]['format_source'] == 'sailaway')) {
474
						$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]['race_begin'], $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'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
475
					    } else {
476
						$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'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
477
					    }
478
					    $Marine->db = null;
479
					    if ($globalDebug && isset($result)) echo $result."\n";
480
					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481
					}
482
				    }
483
				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
484
					// Add source stat in DB
485
					$Stats = new Stats($this->db);
486
					if (!empty($this->stats)) {
487
					    if ($globalDebug) echo 'Add source stats : ';
488
				    	    foreach($this->stats as $date => $data) {
489
						foreach($data as $source => $sourced) {
490
					    	    //print_r($sourced);
491
				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
492
				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
493
				    		    if (isset($sourced['msg'])) {
494
				    			if (time() - $sourced['msg']['date'] > 10) {
495
				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
496
				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
497
			    			    	    unset($this->stats[$date][$source]['msg']);
498
			    				}
499
			    			    }
500
			    			}
501
			    			if ($date != date('Y-m-d')) {
502
			    			    unset($this->stats[$date]);
503
			    			}
504
				    	    }
505
				    	    if ($globalDebug) echo 'Done'."\n";
506
					}
507
					$Stats->db = null;
508
				    }
509
				    
510
				    $this->del();
511
				//$ignoreImport = false;
512
				$this->all_tracked[$id]['addedMarine'] = 1;
513
				//print_r($this->all_tracked[$id]);
514
				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
515
				    if ($globalDebug) echo "---- Deleting Live Marine data older than 12 hours...";
516
				    //MarineLive->deleteLiveMarineDataNotUpdated();
517
				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
518
					$MarineLive = new MarineLive($this->db);
519
					$MarineLive->deleteLiveMarineData();
520
					$MarineLive->db=null;
521
					if ($globalDebug) echo " Done\n";
522
				    }
523
				    $this->last_delete = time();
524
				}
525
			    } elseif ($recent_ident != '') {
526
				$this->all_tracked[$id]['id'] = $recent_ident;
527
				$this->all_tracked[$id]['addedMarine'] = 1;
528
				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
529
				    if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) {
530
					$Marine = new Marine($this->db);
531
					if (isset($globalVM) && $globalVM) {
532
					    if ($this->all_tracked[$id]['status'] == 'Racing') {
533
						$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'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
534
					    } else {
535
						//$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
536
						$timerace = (strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
537
						if ($timerace > time()) $finaldatetime = NULL;
538
						else $finaldatetime = date('Y-m-d H:i:s',$timerace);
539
540
						$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'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
541
					    }
542
					} else {
543
					    $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'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
544
					}
545
					$Marine->db = null;
546
				    }
547
				}
548
				
549
			    }
550
			}
551
		    }
552
		    //adds the spotter LIVE data
553
		    if ($globalDebug) {
554
			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";
555
		    }
556
		    $ignoreImport = false;
557
		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
558
		    if (!$ignoreImport) {
559
			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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
560
				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
561
				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
562
				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
563
					$timeelapsed = microtime(true);
564
					$MarineLive = new MarineLive($this->db);
565
					$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'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
566
					$MarineLive->db = null;
567
					if ($globalDebug) echo $result."\n";
568
					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
569
				    }
570
				}
571
				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
572
					$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']);
573
				}
574
				$this->all_tracked[$id]['putinarchive'] = false;
575
576
				// Put statistics in $this->stats variable
577
				
578
				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
579
					$source = $this->all_tracked[$id]['source_name'];
580
					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
581
					if (!isset($this->source_location[$source])) {
582
						$Location = new Source($this->db);
583
						$coord = $Location->getLocationInfobySourceName($source);
584
						if (count($coord) > 0) {
585
							$latitude = $coord[0]['latitude'];
586
							$longitude = $coord[0]['longitude'];
587
						} else {
588
							$latitude = $globalCenterLatitude;
589
							$longitude = $globalCenterLongitude;
590
						}
591
						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
592
					} else {
593
						$latitude = $this->source_location[$source]['latitude'];
594
						$longitude = $this->source_location[$source]['longitude'];
595
					}
596
					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
597
					//$stats_heading = $stats_heading%22.5;
598
					$stats_heading = round($stats_heading/22.5);
599
					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
600
					$current_date = date('Y-m-d');
601
					if ($stats_heading == 16) $stats_heading = 0;
602
					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
603
						for ($i=0;$i<=15;$i++) {
604
						    $this->stats[$current_date][$source]['polar'][$i] = 0;
605
						}
606
						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
607
					} else {
608
						if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) {
609
							$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
610
						}
611
					}
612
					$distance = (round($stats_distance/10)*10);
613
					//echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n";
614
					//var_dump($this->stats);
615
					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
616
						if (isset($this->stats[$current_date][$source]['hist'][0])) {
617
						    end($this->stats[$current_date][$source]['hist']);
618
						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
619
						} else $mini = 0;
620
						for ($i=$mini;$i<=$distance;$i+=10) {
621
						    $this->stats[$current_date][$source]['hist'][$i] = 0;
622
						}
623
						$this->stats[$current_date][$source]['hist'][$distance] = 1;
624
					} else {
625
						$this->stats[$current_date][$source]['hist'][$distance] += 1;
626
					}
627
				}
628
				
629
630
				$this->all_tracked[$id]['lastupdate'] = time();
631
				if ($this->all_tracked[$id]['putinarchive']) $send = true;
632
			} 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";
633
			//$this->del();
634
			
635
			
636
			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
637
			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
638
				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
639
				$MarineLive = new MarineLive($this->db);
640
				$MarineLive->deleteLiveMarineDataNotUpdated();
641
				$MarineLive->db = null;
642
				//MarineLive->deleteLiveMarineData();
643
				if ($globalDebug) echo " Done\n";
644
			    }
645
			    $this->last_delete_hourly = time();
646
			}
647
			
648
		    }
649
		    //$ignoreImport = false;
650
		}
651
		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
652
		if ($send) return $this->all_tracked[$id];
653
	    }
654
	}
655
    }
656
    
657
    public function race_add($data) {
658
        $Marine = new Marine();
659
        $Marine->addRace($data['id'],$data['name'],$data['creator'],$data['desc'],$data['startdate'],$data['markers']);
660
        $Marine->db = null;
661
    }
662
}
663
?>
664