Completed
Push — master ( dd0fde...0179ab )
by Yannick
51:36 queued 22:27
created
require/class.MarineImport.php 3 patches
Indentation   +206 added lines, -206 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,83 +105,83 @@  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'])));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158 158
 		}
159 159
 		if (isset($line['type']) && $line['type'] != '') {
160
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
160
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
161 161
 		}
162 162
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
164 164
 		}
165 165
 		if (isset($line['imo']) && $line['imo'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
166
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
167 167
 		}
168 168
 		if (isset($line['callsign']) && $line['callsign'] != '') {
169
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
169
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
170 170
 		}
171 171
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
172
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
173 173
 		}
174 174
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
175
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
175
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
176 176
 		}
177 177
 
178 178
 
179 179
 		//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'])) {
180 180
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
182
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
181
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
182
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
183 183
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
184
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
184
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
185 185
 				$timeelapsed = microtime(true);
186 186
 				$Marine = new Marine($this->db);
187 187
 				$fromsource = NULL;
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
190 190
 				$Marine->db = null;
191 191
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
192
-			    }
192
+				}
193 193
 			}
194
-		    }
195
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
194
+			}
195
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
196 196
 		}
197 197
 
198 198
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
199
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
199
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
200 200
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
201
-		    } else {
201
+			} else {
202 202
 				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";
203 203
 				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";
204 204
 				return '';
205
-		    }
205
+			}
206 206
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
207 207
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
208 208
 			return '';
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 		if (isset($line['speed'])) {
222
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
223
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
222
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
223
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
224 224
 		} 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'])) {
225
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
226
-		    if ($distance > 1000 && $distance < 10000) {
225
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
226
+			if ($distance > 1000 && $distance < 10000) {
227 227
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
228 228
 			$speed = $speed*3.6;
229 229
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
230 230
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
231
-		    }
231
+			}
232 232
 		}
233 233
 
234
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
235
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
236
-	    	    else unset($timediff);
237
-	    	    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')))) {
234
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
235
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
236
+				else unset($timediff);
237
+				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')))) {
238 238
 			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'])) {
239
-			    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'])) {
239
+				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'])) {
240 240
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
241 241
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
242 242
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -244,211 +244,211 @@  discard block
 block discarded – undo
244 244
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
245 245
 				$timeelapsed = microtime(true);
246 246
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
247
-				    $Marine = new Marine($this->db);
248
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
249
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
250
-				    $Marine->db = null;
251
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
247
+					$Marine = new Marine($this->db);
248
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
249
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
250
+					$Marine->db = null;
251
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
252 252
 				}
253 253
 				$this->tmd = 0;
254 254
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
255
-			    }
255
+				}
256 256
 			}
257 257
 
258 258
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
259 259
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
260 260
 				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') {
261
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
262
-				    $dataFound = true;
263
-				    $this->all_tracked[$id]['time_last_coord'] = time();
261
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
262
+					$dataFound = true;
263
+					$this->all_tracked[$id]['time_last_coord'] = time();
264 264
 				}
265 265
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
266 266
 			}
267 267
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
268
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
268
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
269 269
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
270 270
 				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') {
271
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
272
-				    $dataFound = true;
273
-				    $this->all_tracked[$id]['time_last_coord'] = time();
271
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
272
+					$dataFound = true;
273
+					$this->all_tracked[$id]['time_last_coord'] = time();
274 274
 				}
275 275
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
276 276
 			}
277 277
 
278
-		    } else if ($globalDebug && $timediff > 20) {
278
+			} else if ($globalDebug && $timediff > 20) {
279 279
 			$this->tmd = $this->tmd + 1;
280 280
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
281 281
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
282 282
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
283 283
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
284
-		    }
284
+			}
285 285
 		}
286 286
 		if (isset($line['last_update']) && $line['last_update'] != '') {
287
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
288
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
287
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
288
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
289 289
 		}
290 290
 		if (isset($line['format_source']) && $line['format_source'] != '') {
291
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
291
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
292 292
 		}
293 293
 		if (isset($line['source_name']) && $line['source_name'] != '') {
294
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
294
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
295 295
 		}
296 296
 		if (isset($line['status']) && $line['status'] != '') {
297
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
297
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
298 298
 		}
299 299
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
300
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
301
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
300
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
301
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
302 302
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
303
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
303
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
304 304
 				$Marine = new Marine($this->db);
305 305
 				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
306 306
 				unset($Marine);
307
-			    }
307
+				}
308
+			}
308 309
 			}
309
-		    }
310 310
 		}
311 311
 
312 312
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
313
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
313
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
314 314
 		}
315 315
 		
316 316
 		if (isset($line['heading']) && $line['heading'] != '') {
317
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
318
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
319
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
320
-		    //$dataFound = true;
317
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
318
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
319
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
320
+			//$dataFound = true;
321 321
   		} 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']) {
322
-  		    $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']);
323
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
324
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
325
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
322
+  			$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']);
323
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
324
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
325
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
326 326
   		}
327 327
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
328 328
 
329 329
 
330 330
 
331 331
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
332
-		    $this->all_tracked[$id]['lastupdate'] = time();
333
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
334
-		        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'])) {
335
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
332
+			$this->all_tracked[$id]['lastupdate'] = time();
333
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
334
+				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'])) {
335
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
336 336
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
337
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
338
-				    $timeelapsed = microtime(true);
339
-				    $MarineLive = new MarineLive($this->db);
340
-				    if (isset($line['id'])) {
337
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
338
+					$timeelapsed = microtime(true);
339
+					$MarineLive = new MarineLive($this->db);
340
+					if (isset($line['id'])) {
341 341
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
342 342
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
343
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
343
+					} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
344 344
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
345 345
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
346
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
346
+					} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
347 347
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
348 348
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
349
-				    } else $recent_ident = '';
350
-				    $MarineLive->db=null;
351
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
352
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
349
+					} else $recent_ident = '';
350
+					$MarineLive->db=null;
351
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
352
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
353 353
 				} else $recent_ident = '';
354
-			    } else {
354
+				} else {
355 355
 				$recent_ident = '';
356 356
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
357
-			    }
358
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
359
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360
-			    {
357
+				}
358
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
359
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360
+				{
361 361
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
362 362
 				//adds the spotter data for the archive
363
-				    $highlight = '';
364
-				    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')));
365
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
363
+					$highlight = '';
364
+					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')));
365
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
366 366
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
367
-					    $timeelapsed = microtime(true);
368
-					    $Marine = new Marine($this->db);
369
-					    $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']);
370
-					    $Marine->db = null;
371
-					    if ($globalDebug && isset($result)) echo $result."\n";
372
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
367
+						$timeelapsed = microtime(true);
368
+						$Marine = new Marine($this->db);
369
+						$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']);
370
+						$Marine->db = null;
371
+						if ($globalDebug && isset($result)) echo $result."\n";
372
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
373
+					}
373 374
 					}
374
-				    }
375
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
375
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
376 376
 					// Add source stat in DB
377 377
 					$Stats = new Stats($this->db);
378 378
 					if (!empty($this->stats)) {
379
-					    if ($globalDebug) echo 'Add source stats : ';
380
-				    	    foreach($this->stats as $date => $data) {
379
+						if ($globalDebug) echo 'Add source stats : ';
380
+							foreach($this->stats as $date => $data) {
381 381
 						foreach($data as $source => $sourced) {
382
-					    	    //print_r($sourced);
383
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
384
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
385
-				    		    if (isset($sourced['msg'])) {
386
-				    			if (time() - $sourced['msg']['date'] > 10) {
387
-				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
388
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
389
-			    			    	    unset($this->stats[$date][$source]['msg']);
390
-			    				}
391
-			    			    }
392
-			    			}
393
-			    			if ($date != date('Y-m-d')) {
394
-			    			    unset($this->stats[$date]);
395
-			    			}
396
-				    	    }
397
-				    	    if ($globalDebug) echo 'Done'."\n";
382
+								//print_r($sourced);
383
+									if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
384
+									if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
385
+								if (isset($sourced['msg'])) {
386
+								if (time() - $sourced['msg']['date'] > 10) {
387
+										$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
388
+										echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
389
+										unset($this->stats[$date][$source]['msg']);
390
+								}
391
+								}
392
+							}
393
+							if ($date != date('Y-m-d')) {
394
+								unset($this->stats[$date]);
395
+							}
396
+							}
397
+							if ($globalDebug) echo 'Done'."\n";
398 398
 					}
399 399
 					$Stats->db = null;
400
-				    }
400
+					}
401 401
 				    
402
-				    $this->del();
402
+					$this->del();
403 403
 				//$ignoreImport = false;
404 404
 				$this->all_tracked[$id]['addedMarine'] = 1;
405 405
 				//print_r($this->all_tracked[$id]);
406 406
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
407
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
408
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
409
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
407
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
408
+					//MarineLive->deleteLiveMarineDataNotUpdated();
409
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
410 410
 					$MarineLive = new MarineLive($this->db);
411 411
 					$MarineLive->deleteLiveMarineData();
412 412
 					$MarineLive->db=null;
413 413
 					if ($globalDebug) echo " Done\n";
414
-				    }
415
-				    $this->last_delete = time();
414
+					}
415
+					$this->last_delete = time();
416 416
 				}
417
-			    } elseif ($recent_ident != '') {
417
+				} elseif ($recent_ident != '') {
418 418
 				$this->all_tracked[$id]['id'] = $recent_ident;
419 419
 				$this->all_tracked[$id]['addedMarine'] = 1;
420 420
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
421
-				    if (isset($globalDaemon) && !$globalDaemon) {
421
+					if (isset($globalDaemon) && !$globalDaemon) {
422 422
 					$Marine = new Marine($this->db);
423 423
 					$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']);
424 424
 					$Marine->db = null;
425
-				    }
425
+					}
426 426
 				}
427 427
 				
428
-			    }
428
+				}
429
+			}
429 430
 			}
430
-		    }
431
-		    //adds the spotter LIVE data
432
-		    if ($globalDebug) {
431
+			//adds the spotter LIVE data
432
+			if ($globalDebug) {
433 433
 			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";
434
-		    }
435
-		    $ignoreImport = false;
434
+			}
435
+			$ignoreImport = false;
436 436
 
437
-		    if (!$ignoreImport) {
437
+			if (!$ignoreImport) {
438 438
 			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'])) {
439 439
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
440 440
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
441
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
441
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442 442
 					$timeelapsed = microtime(true);
443 443
 					$MarineLive = new MarineLive($this->db);
444 444
 					$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']);
445 445
 					$MarineLive->db = null;
446 446
 					if ($globalDebug) echo $result."\n";
447 447
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
448
-				    }
448
+					}
449 449
 				}
450 450
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
451
-				    $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']);
451
+					$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']);
452 452
 				}
453 453
 				$this->all_tracked[$id]['putinarchive'] = false;
454 454
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 					if ($stats_heading == 16) $stats_heading = 0;
481 481
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
482 482
 						for ($i=0;$i<=15;$i++) {
483
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
483
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
484 484
 						}
485 485
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
486 486
 					} else {
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
 					//var_dump($this->stats);
494 494
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
495 495
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
496
-						    end($this->stats[$current_date][$source]['hist']);
497
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
496
+							end($this->stats[$current_date][$source]['hist']);
497
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
498 498
 						} else $mini = 0;
499 499
 						for ($i=$mini;$i<=$distance;$i+=10) {
500
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
500
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
501 501
 						}
502 502
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
503 503
 					} else {
@@ -513,24 +513,24 @@  discard block
 block discarded – undo
513 513
 			
514 514
 			
515 515
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
516
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
516
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
517 517
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
518 518
 				$MarineLive = new MarineLive($this->db);
519 519
 				$MarineLive->deleteLiveMarineDataNotUpdated();
520 520
 				$MarineLive->db = null;
521 521
 				//MarineLive->deleteLiveMarineData();
522 522
 				if ($globalDebug) echo " Done\n";
523
-			    }
524
-			    $this->last_delete_hourly = time();
523
+				}
524
+				$this->last_delete_hourly = time();
525 525
 			}
526 526
 			
527
-		    }
528
-		    //$ignoreImport = false;
527
+			}
528
+			//$ignoreImport = false;
529 529
 		}
530 530
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
531 531
 		if ($send) return $this->all_tracked[$id];
532
-	    }
532
+		}
533
+	}
533 534
 	}
534
-    }
535 535
 }
536 536
 ?>
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 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,64 +154,64 @@  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'])));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
158 158
 		}
159 159
 		if (isset($line['type']) && $line['type'] != '') {
160
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
160
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
161 161
 		}
162 162
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
164 164
 		}
165 165
 		if (isset($line['imo']) && $line['imo'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
166
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
167 167
 		}
168 168
 		if (isset($line['callsign']) && $line['callsign'] != '') {
169
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
169
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
170 170
 		}
171 171
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
172
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
173 173
 		}
174 174
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
175
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
175
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
176 176
 		}
177 177
 
178 178
 
179 179
 		//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'])) {
180 180
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
181
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
182 182
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
183 183
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
184 184
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
185 185
 				$timeelapsed = microtime(true);
186 186
 				$Marine = new Marine($this->db);
187 187
 				$fromsource = NULL;
188
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
188
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
189 189
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
190 190
 				$Marine->db = null;
191
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
191
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
192 192
 			    }
193 193
 			}
194 194
 		    }
195
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
195
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
196 196
 		}
197 197
 
198
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
198
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
199 199
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
200
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
200
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
201 201
 		    } else {
202 202
 				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";
203 203
 				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";
204 204
 				return '';
205 205
 		    }
206
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
206
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
207 207
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
208 208
 			return '';
209
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
209
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
210 210
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
211 211
 			return '';
212 212
 		} elseif (!isset($line['datetime'])) {
213 213
 			date_default_timezone_set('UTC');
214
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
214
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
215 215
 		} else {
216 216
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
217 217
 			return '';
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 		if (isset($line['speed'])) {
222
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
223
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
222
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
223
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
224 224
 		} 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'])) {
225
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
225
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
226 226
 		    if ($distance > 1000 && $distance < 10000) {
227 227
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
228 228
 			$speed = $speed*3.6;
229
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
229
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
230 230
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
231 231
 		    }
232 232
 		}
233 233
 
234 234
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
235
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
235
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
236 236
 	    	    else unset($timediff);
237
-	    	    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')))) {
237
+	    	    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')))) {
238 238
 			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'])) {
239
-			    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'])) {
239
+			    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'])) {
240 240
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
241 241
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
242 242
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 				$timeelapsed = microtime(true);
246 246
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
247 247
 				    $Marine = new Marine($this->db);
248
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
248
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
249 249
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
250 250
 				    $Marine->db = null;
251
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
251
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
252 252
 				}
253 253
 				$this->tmd = 0;
254 254
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -257,52 +257,52 @@  discard block
 block discarded – undo
257 257
 
258 258
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
259 259
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
260
-				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') {
260
+				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') {
261 261
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
262 262
 				    $dataFound = true;
263 263
 				    $this->all_tracked[$id]['time_last_coord'] = time();
264 264
 				}
265
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
265
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
266 266
 			}
267 267
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
268 268
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
269 269
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
270
-				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') {
270
+				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') {
271 271
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
272 272
 				    $dataFound = true;
273 273
 				    $this->all_tracked[$id]['time_last_coord'] = time();
274 274
 				}
275
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
275
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
276 276
 			}
277 277
 
278 278
 		    } else if ($globalDebug && $timediff > 20) {
279 279
 			$this->tmd = $this->tmd + 1;
280 280
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
281
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
282
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
281
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
282
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
283 283
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
284 284
 		    }
285 285
 		}
286 286
 		if (isset($line['last_update']) && $line['last_update'] != '') {
287 287
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
288
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
288
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
289 289
 		}
290 290
 		if (isset($line['format_source']) && $line['format_source'] != '') {
291
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
291
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
292 292
 		}
293 293
 		if (isset($line['source_name']) && $line['source_name'] != '') {
294
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
294
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
295 295
 		}
296 296
 		if (isset($line['status']) && $line['status'] != '') {
297
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
297
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
298 298
 		}
299 299
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
300
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
300
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
301 301
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
302 302
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
303 303
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
304 304
 				$Marine = new Marine($this->db);
305
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
305
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
306 306
 				unset($Marine);
307 307
 			    }
308 308
 			}
@@ -310,18 +310,18 @@  discard block
 block discarded – undo
310 310
 		}
311 311
 
312 312
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
313
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
313
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
314 314
 		}
315 315
 		
316 316
 		if (isset($line['heading']) && $line['heading'] != '') {
317
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
318
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
319
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
317
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
318
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
319
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
320 320
 		    //$dataFound = true;
321 321
   		} 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']) {
322
-  		    $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']);
323
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
324
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
322
+  		    $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']);
323
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
324
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
325 325
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
326 326
   		}
327 327
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
332 332
 		    $this->all_tracked[$id]['lastupdate'] = time();
333 333
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
334
-		        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'])) {
334
+		        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'])) {
335 335
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
336 336
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
337 337
 				    if ($globalDebug) echo "Check if aircraft is already in DB...";
@@ -339,37 +339,37 @@  discard block
 block discarded – undo
339 339
 				    $MarineLive = new MarineLive($this->db);
340 340
 				    if (isset($line['id'])) {
341 341
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
342
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
342
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
343 343
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
344 344
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
345
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
345
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
346 346
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
347 347
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
348
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
348
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
349 349
 				    } else $recent_ident = '';
350
-				    $MarineLive->db=null;
350
+				    $MarineLive->db = null;
351 351
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
352 352
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
353 353
 				} else $recent_ident = '';
354 354
 			    } else {
355 355
 				$recent_ident = '';
356
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
356
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
357 357
 			    }
358 358
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
359
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
359
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360 360
 			    {
361 361
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
362 362
 				//adds the spotter data for the archive
363 363
 				    $highlight = '';
364
-				    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')));
364
+				    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')));
365 365
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
366 366
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
367 367
 					    $timeelapsed = microtime(true);
368 368
 					    $Marine = new Marine($this->db);
369
-					    $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']);
369
+					    $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']);
370 370
 					    $Marine->db = null;
371 371
 					    if ($globalDebug && isset($result)) echo $result."\n";
372
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
373 373
 					}
374 374
 				    }
375 375
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
 					$Stats = new Stats($this->db);
378 378
 					if (!empty($this->stats)) {
379 379
 					    if ($globalDebug) echo 'Add source stats : ';
380
-				    	    foreach($this->stats as $date => $data) {
381
-						foreach($data as $source => $sourced) {
380
+				    	    foreach ($this->stats as $date => $data) {
381
+						foreach ($data as $source => $sourced) {
382 382
 					    	    //print_r($sourced);
383
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
384
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
383
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
384
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
385 385
 				    		    if (isset($sourced['msg'])) {
386 386
 				    			if (time() - $sourced['msg']['date'] > 10) {
387 387
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
388
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
388
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
389 389
 			    			    	    unset($this->stats[$date][$source]['msg']);
390 390
 			    				}
391 391
 			    			    }
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
410 410
 					$MarineLive = new MarineLive($this->db);
411 411
 					$MarineLive->deleteLiveMarineData();
412
-					$MarineLive->db=null;
412
+					$MarineLive->db = null;
413 413
 					if ($globalDebug) echo " Done\n";
414 414
 				    }
415 415
 				    $this->last_delete = time();
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
421 421
 				    if (isset($globalDaemon) && !$globalDaemon) {
422 422
 					$Marine = new Marine($this->db);
423
-					$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']);
423
+					$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']);
424 424
 					$Marine->db = null;
425 425
 				    }
426 426
 				}
@@ -435,20 +435,20 @@  discard block
 block discarded – undo
435 435
 		    $ignoreImport = false;
436 436
 
437 437
 		    if (!$ignoreImport) {
438
-			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'])) {
438
+			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'])) {
439 439
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
440 440
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
441 441
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442 442
 					$timeelapsed = microtime(true);
443 443
 					$MarineLive = new MarineLive($this->db);
444
-					$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']);
444
+					$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']);
445 445
 					$MarineLive->db = null;
446 446
 					if ($globalDebug) echo $result."\n";
447
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
447
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
448 448
 				    }
449 449
 				}
450 450
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
451
-				    $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']);
451
+				    $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']);
452 452
 				}
453 453
 				$this->all_tracked[$id]['putinarchive'] = false;
454 454
 
@@ -467,19 +467,19 @@  discard block
 block discarded – undo
467 467
 							$latitude = $globalCenterLatitude;
468 468
 							$longitude = $globalCenterLongitude;
469 469
 						}
470
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
470
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
471 471
 					} else {
472 472
 						$latitude = $this->source_location[$source]['latitude'];
473 473
 						$longitude = $this->source_location[$source]['longitude'];
474 474
 					}
475
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
475
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
476 476
 					//$stats_heading = $stats_heading%22.5;
477 477
 					$stats_heading = round($stats_heading/22.5);
478
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
478
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
479 479
 					$current_date = date('Y-m-d');
480 480
 					if ($stats_heading == 16) $stats_heading = 0;
481 481
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
482
-						for ($i=0;$i<=15;$i++) {
482
+						for ($i = 0; $i <= 15; $i++) {
483 483
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
484 484
 						}
485 485
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -494,9 +494,9 @@  discard block
 block discarded – undo
494 494
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
495 495
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
496 496
 						    end($this->stats[$current_date][$source]['hist']);
497
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
497
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
498 498
 						} else $mini = 0;
499
-						for ($i=$mini;$i<=$distance;$i+=10) {
499
+						for ($i = $mini; $i <= $distance; $i += 10) {
500 500
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
501 501
 						}
502 502
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 
509 509
 				$this->all_tracked[$id]['lastupdate'] = time();
510 510
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
511
-			} 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";
511
+			} 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";
512 512
 			//$this->del();
513 513
 			
514 514
 			
Please login to merge, or discard this patch.
Braces   +193 added lines, -66 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']) {
@@ -186,34 +212,49 @@  discard block
 block discarded – undo
186 212
 				$Marine = new Marine($this->db);
187 213
 				$fromsource = NULL;
188 214
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
189
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
215
+				if ($globalDebug && $result != 'success') {
216
+					echo '!!! ERROR : '.$result."\n";
217
+				}
190 218
 				$Marine->db = null;
191
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
219
+				if ($globalDebugTimeElapsed) {
220
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
221
+				}
192 222
 			    }
193 223
 			}
194 224
 		    }
195
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
225
+		    if (!isset($this->all_tracked[$id]['id'])) {
226
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
227
+		    }
196 228
 		}
197 229
 
198 230
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
199 231
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
200 232
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
201 233
 		    } else {
202
-				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";
203
-				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";
234
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
235
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
236
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
237
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
238
+				}
204 239
 				return '';
205 240
 		    }
206 241
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
207
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
242
+			if ($globalDebug) {
243
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
244
+			}
208 245
 			return '';
209 246
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
210
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
247
+			if ($globalDebug) {
248
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
249
+			}
211 250
 			return '';
212 251
 		} elseif (!isset($line['datetime'])) {
213 252
 			date_default_timezone_set('UTC');
214 253
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
215 254
 		} else {
216
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
255
+			if ($globalDebug) {
256
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
257
+			}
217 258
 			return '';
218 259
 		}
219 260
 
@@ -226,14 +267,21 @@  discard block
 block discarded – undo
226 267
 		    if ($distance > 1000 && $distance < 10000) {
227 268
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
228 269
 			$speed = $speed*3.6;
229
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
230
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
270
+			if ($speed < 1000) {
271
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
272
+			}
273
+  			if ($globalDebug) {
274
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
275
+  			}
231 276
 		    }
232 277
 		}
233 278
 
234 279
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
235
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
236
-	    	    else unset($timediff);
280
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
281
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
282
+	    	    } else {
283
+	    	    	unset($timediff);
284
+	    	    }
237 285
 	    	    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')))) {
238 286
 			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'])) {
239 287
 			    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'])) {
@@ -241,22 +289,32 @@  discard block
 block discarded – undo
241 289
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
242 290
 				$this->all_tracked[$id]['putinarchive'] = true;
243 291
 				
244
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
292
+				if ($globalDebug) {
293
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
294
+				}
245 295
 				$timeelapsed = microtime(true);
246 296
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
247 297
 				    $Marine = new Marine($this->db);
248 298
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
249
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
299
+				    if (!empty($all_country)) {
300
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
301
+				    }
250 302
 				    $Marine->db = null;
251
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
303
+				    if ($globalDebugTimeElapsed) {
304
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
+				    }
252 306
 				}
253 307
 				$this->tmd = 0;
254
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
308
+				if ($globalDebug) {
309
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
310
+				}
255 311
 			    }
256 312
 			}
257 313
 
258 314
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
259
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
315
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
316
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
317
+				}
260 318
 				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') {
261 319
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
262 320
 				    $dataFound = true;
@@ -265,8 +323,12 @@  discard block
 block discarded – undo
265 323
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
266 324
 			}
267 325
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
268
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
269
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
326
+			    if ($line['longitude'] > 180) {
327
+			    	$line['longitude'] = $line['longitude'] - 360;
328
+			    }
329
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
330
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
331
+				}
270 332
 				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') {
271 333
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
272 334
 				    $dataFound = true;
@@ -284,7 +346,9 @@  discard block
 block discarded – undo
284 346
 		    }
285 347
 		}
286 348
 		if (isset($line['last_update']) && $line['last_update'] != '') {
287
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
349
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
350
+		    	$dataFound = true;
351
+		    }
288 352
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
289 353
 		}
290 354
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -314,15 +378,21 @@  discard block
 block discarded – undo
314 378
 		}
315 379
 		
316 380
 		if (isset($line['heading']) && $line['heading'] != '') {
317
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
381
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
382
+		    	$this->all_tracked[$id]['putinarchive'] = true;
383
+		    }
318 384
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
319 385
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
320 386
 		    //$dataFound = true;
321 387
   		} 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']) {
322 388
   		    $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']);
323 389
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
324
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
325
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
390
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
391
+		    	$this->all_tracked[$id]['putinarchive'] = true;
392
+		    }
393
+  		    if ($globalDebug) {
394
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
395
+  		    }
326 396
   		}
327 397
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
328 398
 
@@ -334,23 +404,38 @@  discard block
 block discarded – undo
334 404
 		        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'])) {
335 405
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
336 406
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
337
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
407
+				    if ($globalDebug) {
408
+				    	echo "Check if aircraft is already in DB...";
409
+				    }
338 410
 				    $timeelapsed = microtime(true);
339 411
 				    $MarineLive = new MarineLive($this->db);
340 412
 				    if (isset($line['id'])) {
341 413
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
342
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
414
+					if ($globalDebugTimeElapsed) {
415
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
416
+					}
343 417
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
344 418
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
345
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
419
+					if ($globalDebugTimeElapsed) {
420
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
421
+					}
346 422
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
347 423
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
348
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
349
-				    } else $recent_ident = '';
424
+					if ($globalDebugTimeElapsed) {
425
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
426
+					}
427
+				    } else {
428
+				    	$recent_ident = '';
429
+				    }
350 430
 				    $MarineLive->db=null;
351
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
352
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
353
-				} else $recent_ident = '';
431
+				    if ($globalDebug && $recent_ident == '') {
432
+				    	echo " Not in DB.\n";
433
+				    } elseif ($globalDebug && $recent_ident != '') {
434
+				    	echo " Already in DB.\n";
435
+				    }
436
+				} else {
437
+					$recent_ident = '';
438
+				}
354 439
 			    } else {
355 440
 				$recent_ident = '';
356 441
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -358,30 +443,44 @@  discard block
 block discarded – undo
358 443
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
359 444
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360 445
 			    {
361
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
446
+				if ($globalDebug) {
447
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
448
+				}
362 449
 				//adds the spotter data for the archive
363 450
 				    $highlight = '';
364
-				    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')));
451
+				    if (!isset($this->all_tracked[$id]['id'])) {
452
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
453
+				    }
365 454
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
366 455
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
367 456
 					    $timeelapsed = microtime(true);
368 457
 					    $Marine = new Marine($this->db);
369 458
 					    $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']);
370 459
 					    $Marine->db = null;
371
-					    if ($globalDebug && isset($result)) echo $result."\n";
372
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+					    if ($globalDebug && isset($result)) {
461
+					    	echo $result."\n";
462
+					    }
463
+					    if ($globalDebugTimeElapsed) {
464
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
465
+					    }
373 466
 					}
374 467
 				    }
375 468
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
376 469
 					// Add source stat in DB
377 470
 					$Stats = new Stats($this->db);
378 471
 					if (!empty($this->stats)) {
379
-					    if ($globalDebug) echo 'Add source stats : ';
472
+					    if ($globalDebug) {
473
+					    	echo 'Add source stats : ';
474
+					    }
380 475
 				    	    foreach($this->stats as $date => $data) {
381 476
 						foreach($data as $source => $sourced) {
382 477
 					    	    //print_r($sourced);
383
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
384
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
478
+				    	    	    if (isset($sourced['polar'])) {
479
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
480
+				    	    	    }
481
+				    	    	    if (isset($sourced['hist'])) {
482
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
483
+				    	    	    }
385 484
 				    		    if (isset($sourced['msg'])) {
386 485
 				    			if (time() - $sourced['msg']['date'] > 10) {
387 486
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -394,7 +493,9 @@  discard block
 block discarded – undo
394 493
 			    			    unset($this->stats[$date]);
395 494
 			    			}
396 495
 				    	    }
397
-				    	    if ($globalDebug) echo 'Done'."\n";
496
+				    	    if ($globalDebug) {
497
+				    	    	echo 'Done'."\n";
498
+				    	    }
398 499
 					}
399 500
 					$Stats->db = null;
400 501
 				    }
@@ -404,13 +505,17 @@  discard block
 block discarded – undo
404 505
 				$this->all_tracked[$id]['addedMarine'] = 1;
405 506
 				//print_r($this->all_tracked[$id]);
406 507
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
407
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
508
+				    if ($globalDebug) {
509
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
510
+				    }
408 511
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
409 512
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
410 513
 					$MarineLive = new MarineLive($this->db);
411 514
 					$MarineLive->deleteLiveMarineData();
412 515
 					$MarineLive->db=null;
413
-					if ($globalDebug) echo " Done\n";
516
+					if ($globalDebug) {
517
+						echo " Done\n";
518
+					}
414 519
 				    }
415 520
 				    $this->last_delete = time();
416 521
 				}
@@ -436,15 +541,21 @@  discard block
 block discarded – undo
436 541
 
437 542
 		    if (!$ignoreImport) {
438 543
 			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'])) {
439
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
544
+				if ($globalDebug) {
545
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
546
+				}
440 547
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
441 548
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442 549
 					$timeelapsed = microtime(true);
443 550
 					$MarineLive = new MarineLive($this->db);
444 551
 					$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']);
445 552
 					$MarineLive->db = null;
446
-					if ($globalDebug) echo $result."\n";
447
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
553
+					if ($globalDebug) {
554
+						echo $result."\n";
555
+					}
556
+					if ($globalDebugTimeElapsed) {
557
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
558
+					}
448 559
 				    }
449 560
 				}
450 561
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -456,7 +567,9 @@  discard block
 block discarded – undo
456 567
 				
457 568
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
458 569
 					$source = $this->all_tracked[$id]['source_name'];
459
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
570
+					if ($source == '') {
571
+						$source = $this->all_tracked[$id]['format_source'];
572
+					}
460 573
 					if (!isset($this->source_location[$source])) {
461 574
 						$Location = new Source($this->db);
462 575
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -477,7 +590,9 @@  discard block
 block discarded – undo
477 590
 					$stats_heading = round($stats_heading/22.5);
478 591
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
479 592
 					$current_date = date('Y-m-d');
480
-					if ($stats_heading == 16) $stats_heading = 0;
593
+					if ($stats_heading == 16) {
594
+						$stats_heading = 0;
595
+					}
481 596
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
482 597
 						for ($i=0;$i<=15;$i++) {
483 598
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -495,7 +610,9 @@  discard block
 block discarded – undo
495 610
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
496 611
 						    end($this->stats[$current_date][$source]['hist']);
497 612
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
498
-						} else $mini = 0;
613
+						} else {
614
+							$mini = 0;
615
+						}
499 616
 						for ($i=$mini;$i<=$distance;$i+=10) {
500 617
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
501 618
 						}
@@ -507,19 +624,27 @@  discard block
 block discarded – undo
507 624
 				
508 625
 
509 626
 				$this->all_tracked[$id]['lastupdate'] = time();
510
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
511
-			} 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";
627
+				if ($this->all_tracked[$id]['putinarchive']) {
628
+					$send = true;
629
+				}
630
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
631
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
632
+			}
512 633
 			//$this->del();
513 634
 			
514 635
 			
515 636
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
516 637
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
517
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
638
+				if ($globalDebug) {
639
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
640
+				}
518 641
 				$MarineLive = new MarineLive($this->db);
519 642
 				$MarineLive->deleteLiveMarineDataNotUpdated();
520 643
 				$MarineLive->db = null;
521 644
 				//MarineLive->deleteLiveMarineData();
522
-				if ($globalDebug) echo " Done\n";
645
+				if ($globalDebug) {
646
+					echo " Done\n";
647
+				}
523 648
 			    }
524 649
 			    $this->last_delete_hourly = time();
525 650
 			}
@@ -528,7 +653,9 @@  discard block
 block discarded – undo
528 653
 		    //$ignoreImport = false;
529 654
 		}
530 655
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
531
-		if ($send) return $this->all_tracked[$id];
656
+		if ($send) {
657
+			return $this->all_tracked[$id];
658
+		}
532 659
 	    }
533 660
 	}
534 661
     }
Please login to merge, or discard this patch.