Completed
Push — master ( cc50d0...0f8c33 )
by Yannick
09:46
created
require/class.TrackerImport.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 
11 11
 class TrackerImport {
12
-    private $all_tracked = array();
13
-    private $last_delete_hourly = 0;
14
-    private $last_delete = 0;
15
-    private $stats = array();
16
-    private $tmd = 0;
17
-    private $source_location = array();
18
-    public $db = null;
19
-    public $nb = 0;
12
+	private $all_tracked = array();
13
+	private $last_delete_hourly = 0;
14
+	private $last_delete = 0;
15
+	private $stats = array();
16
+	private $tmd = 0;
17
+	private $source_location = array();
18
+	public $db = null;
19
+	public $nb = 0;
20 20
 
21
-    public function __construct($dbc = null) {
21
+	public function __construct($dbc = null) {
22 22
 	global $globalBeta;
23 23
 	$Connection = new Connection($dbc);
24 24
 	$this->db = $Connection->db();
@@ -40,50 +40,50 @@  discard block
 block discarded – undo
40 40
 	    }
41 41
 	}
42 42
 	*/
43
-    }
43
+	}
44 44
 
45
-    public function checkAll() {
45
+	public function checkAll() {
46 46
 	global $globalDebug;
47 47
 	if ($globalDebug) echo "Update last seen tracked data...\n";
48 48
 	foreach ($this->all_tracked as $key => $flight) {
49
-	    if (isset($this->all_tracked[$key]['id'])) {
49
+		if (isset($this->all_tracked[$key]['id'])) {
50 50
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
51
-    		$Tracker = new Tracker($this->db);
52
-        	$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
-            }
51
+			$Tracker = new Tracker($this->db);
52
+			$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
+			}
54
+	}
54 55
 	}
55
-    }
56 56
 
57
-    public function del() {
57
+	public function del() {
58 58
 	global $globalDebug;
59 59
 	// Delete old infos
60 60
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
61 61
 	foreach ($this->all_tracked as $key => $flight) {
62
-    	    if (isset($flight['lastupdate'])) {
63
-        	if ($flight['lastupdate'] < (time()-3000)) {
64
-            	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
62
+			if (isset($flight['lastupdate'])) {
63
+			if ($flight['lastupdate'] < (time()-3000)) {
64
+					if (isset($this->all_tracked[$key]['id'])) {
65
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
66 66
 			/*
67 67
 			$TrackerLive = new TrackerLive();
68 68
             		$TrackerLive->deleteLiveTrackerDataById($this->all_tracked[$key]['id']);
69 69
 			$TrackerLive->db = null;
70 70
 			*/
71
-            		//$real_arrival = $this->arrival($key);
72
-            		$Tracker = new Tracker($this->db);
73
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
71
+					//$real_arrival = $this->arrival($key);
72
+					$Tracker = new Tracker($this->db);
73
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 74
 				$result = $Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed']);
75 75
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
76 76
 			}
77 77
 			// Put in archive
78 78
 //			$Tracker->db = null;
79
-            	    }
80
-            	    unset($this->all_tracked[$key]);
81
-    	        }
82
-	    }
83
-        }
84
-    }
79
+					}
80
+					unset($this->all_tracked[$key]);
81
+				}
82
+		}
83
+		}
84
+	}
85 85
 
86
-    public function add($line) {
86
+	public function add($line) {
87 87
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88 88
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
89 89
 	date_default_timezone_set('UTC');
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	
93 93
 	// SBS format is CSV format
94 94
 	if(is_array($line) && isset($line['ident'])) {
95
-	    //print_r($line);
96
-  	    if (isset($line['ident'])) {
95
+		//print_r($line);
96
+  		if (isset($line['ident'])) {
97 97
 
98 98
 		/*
99 99
 		// Increment message number
@@ -109,29 +109,29 @@  discard block
 block discarded – undo
109 109
 		*/
110 110
 		
111 111
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['ident']);
113
-	        else $id = trim($line['id']);
112
+			if (!isset($line['id'])) $id = trim($line['ident']);
113
+			else $id = trim($line['id']);
114 114
 		
115 115
 		if (!isset($this->all_tracked[$id])) {
116
-		    $this->all_tracked[$id] = array();
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
-		    if (!isset($line['id'])) {
116
+			$this->all_tracked[$id] = array();
117
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
118
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
+			if (!isset($line['id'])) {
121 121
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
122 122
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
123
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
+			if ($globalAllTracked !== FALSE) $dataFound = true;
125 125
 		}
126 126
 		
127 127
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
128
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
128
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
129 129
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
130
-		    } else {
130
+			} else {
131 131
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
132 132
 				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";
133 133
 				return '';
134
-		    }
134
+			}
135 135
 		} else {
136 136
 			date_default_timezone_set('UTC');
137 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -139,38 +139,38 @@  discard block
 block discarded – undo
139 139
 
140 140
 		//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'])) {
141 141
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
143
-		    if ($this->all_tracked[$id]['addedTracker'] == 1) {
142
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
143
+			if ($this->all_tracked[$id]['addedTracker'] == 1) {
144 144
 			$timeelapsed = microtime(true);
145
-            		$Tracker = new Tracker($this->db);
146
-            		$fromsource = NULL;
147
-            		$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
145
+					$Tracker = new Tracker($this->db);
146
+					$fromsource = NULL;
147
+					$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
148 148
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
149 149
 			$Tracker->db = null;
150 150
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
151
-		    }
152
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
151
+			}
152
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
153 153
 		}
154 154
 
155 155
 		if (isset($line['speed']) && $line['speed'] != '') {
156
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
156
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
158 158
 		} 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'])) {
159
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
160
-		    if ($distance > 1000 && $distance < 10000) {
159
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
160
+			if ($distance > 1000 && $distance < 10000) {
161 161
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
162 162
 			$speed = $speed*3.6;
163 163
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
164 164
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
165
-		    }
165
+			}
166 166
 		}
167 167
 
168
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
169
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
170
-	    	    else unset($timediff);
171
-	    	    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')))) {
168
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
169
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
170
+				else unset($timediff);
171
+				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')))) {
172 172
 			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'])) {
173
-			    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'])) {
173
+				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'])) {
174 174
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
175 175
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
176 176
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -184,120 +184,120 @@  discard block
 block discarded – undo
184 184
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
185 185
 				$this->tmd = 0;
186 186
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
187
-			    }
187
+				}
188 188
 			}
189 189
 
190 190
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
191 191
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
192 192
 				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') {
193
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
194
-				    $dataFound = true;
195
-				    $this->all_tracked[$id]['time_last_coord'] = time();
193
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
194
+					$dataFound = true;
195
+					$this->all_tracked[$id]['time_last_coord'] = time();
196 196
 				}
197 197
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
198 198
 			}
199 199
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
200
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
200
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
201 201
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
202 202
 				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') {
203
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
204
-				    $dataFound = true;
205
-				    $this->all_tracked[$id]['time_last_coord'] = time();
203
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
204
+					$dataFound = true;
205
+					$this->all_tracked[$id]['time_last_coord'] = time();
206 206
 				}
207 207
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
208 208
 			}
209 209
 
210
-		    } else if ($globalDebug && $timediff > 20) {
210
+			} else if ($globalDebug && $timediff > 20) {
211 211
 			$this->tmd = $this->tmd + 1;
212 212
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
213 213
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
214 214
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
215 215
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
216
-		    }
216
+			}
217 217
 		}
218 218
 		if (isset($line['last_update']) && $line['last_update'] != '') {
219
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
220
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
219
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
220
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
221 221
 		}
222 222
 		if (isset($line['format_source']) && $line['format_source'] != '') {
223
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
223
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
224 224
 		}
225 225
 		if (isset($line['source_name']) && $line['source_name'] != '') {
226
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
226
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
227 227
 		}
228 228
 		if (isset($line['comment']) && $line['comment'] != '') {
229
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
230
-		    //$dataFound = true;
229
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
230
+			//$dataFound = true;
231 231
 		}
232 232
 		if (isset($line['type']) && $line['type'] != '') {
233
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
234
-		    //$dataFound = true;
233
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
234
+			//$dataFound = true;
235 235
 		}
236 236
 
237 237
 		if (isset($line['altitude']) && $line['altitude'] != '') {
238
-		    //if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
238
+			//if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
239 239
 			if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) $this->all_tracked[$id]['putinarchive'] = true;
240 240
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude' => round($line['altitude']/100)));
241 241
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude_real' => $line['altitude']));
242 242
 			//$dataFound = true;
243
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
243
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
244 244
   		}
245 245
 
246 246
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
247
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
248 248
 		}
249 249
 		
250 250
 		if (isset($line['heading']) && $line['heading'] != '') {
251
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
252
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
253
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
254
-		    //$dataFound = true;
251
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
252
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
253
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
254
+			//$dataFound = true;
255 255
   		} 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']) {
256
-  		    $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']);
257
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
258
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
256
+  			$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']);
257
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
258
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
260 260
   		}
261 261
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
262 262
 
263 263
 		if ($dataFound === true && isset($this->all_tracked[$id]['ident'])) {
264
-		    $this->all_tracked[$id]['lastupdate'] = time();
265
-		    if ($this->all_tracked[$id]['addedTracker'] == 0) {
266
-		        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'])) {
267
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
264
+			$this->all_tracked[$id]['lastupdate'] = time();
265
+			if ($this->all_tracked[$id]['addedTracker'] == 0) {
266
+				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'])) {
267
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
268 268
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
269 269
 				$timeelapsed = microtime(true);
270 270
 				$TrackerLive = new TrackerLive($this->db);
271 271
 				if (isset($line['id'])) {
272
-				    $recent_ident = $TrackerLive->checkIdRecent($line['id']);
273
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
272
+					$recent_ident = $TrackerLive->checkIdRecent($line['id']);
273
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
274 274
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
275
-				    $recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
276
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
275
+					$recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
276
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
277 277
 				} else $recent_ident = '';
278 278
 				$TrackerLive->db=null;
279 279
 
280 280
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
281 281
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
282
-			    } else {
282
+				} else {
283 283
 				$recent_ident = '';
284 284
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
285
-			    }
286
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
287
-			    if($recent_ident == "")
288
-			    {
285
+				}
286
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
287
+				if($recent_ident == "")
288
+				{
289 289
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
290 290
 				//adds the spotter data for the archive
291
-				    $highlight = '';
292
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
293
-				    $timeelapsed = microtime(true);
294
-				    $Tracker = new Tracker($this->db);
295
-				    $result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
296
-				    $Tracker->db = null;
297
-				    if ($globalDebug && isset($result)) echo $result."\n";
298
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
291
+					$highlight = '';
292
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
293
+					$timeelapsed = microtime(true);
294
+					$Tracker = new Tracker($this->db);
295
+					$result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
296
+					$Tracker->db = null;
297
+					if ($globalDebug && isset($result)) echo $result."\n";
298
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
299 299
 				    
300
-				    /*
300
+					/*
301 301
 				    // Add source stat in DB
302 302
 				    $Stats = new Stats($this->db);
303 303
 				    if (!empty($this->stats)) {
@@ -324,20 +324,20 @@  discard block
 block discarded – undo
324 324
 				    }
325 325
 				    $Stats->db = null;
326 326
 				    */
327
-				    $this->del();
327
+					$this->del();
328 328
 				//$ignoreImport = false;
329 329
 				$this->all_tracked[$id]['addedTracker'] = 1;
330 330
 				//print_r($this->all_tracked[$id]);
331 331
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
332
-				    if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
333
-				    //TrackerLive->deleteLiveTrackerDataNotUpdated();
334
-				    $TrackerLive = new TrackerLive($this->db);
335
-				    $TrackerLive->deleteLiveTrackerData();
336
-				    $TrackerLive->db=null;
337
-				    if ($globalDebug) echo " Done\n";
338
-				    $this->last_delete = time();
332
+					if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
333
+					//TrackerLive->deleteLiveTrackerDataNotUpdated();
334
+					$TrackerLive = new TrackerLive($this->db);
335
+					$TrackerLive->deleteLiveTrackerData();
336
+					$TrackerLive->db=null;
337
+					if ($globalDebug) echo " Done\n";
338
+					$this->last_delete = time();
339 339
 				}
340
-			    } else {
340
+				} else {
341 341
 				$this->all_tracked[$id]['id'] = $recent_ident;
342 342
 				$this->all_tracked[$id]['addedTracker'] = 1;
343 343
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -346,16 +346,16 @@  discard block
 block discarded – undo
346 346
 					$Tracker->db = null;
347 347
 				}
348 348
 				
349
-			    }
349
+				}
350
+			}
350 351
 			}
351
-		    }
352
-		    //adds the spotter LIVE data
353
-		    if ($globalDebug) {
352
+			//adds the spotter LIVE data
353
+			if ($globalDebug) {
354 354
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Altitude : '.$this->all_tracked[$id]['altitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
355
-		    }
356
-		    $ignoreImport = false;
355
+			}
356
+			$ignoreImport = false;
357 357
 
358
-		    if (!$ignoreImport) {
358
+			if (!$ignoreImport) {
359 359
 			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'])) {
360 360
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
361 361
 				$timeelapsed = microtime(true);
@@ -427,22 +427,22 @@  discard block
 block discarded – undo
427 427
 			
428 428
 			
429 429
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
430
-			    if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
431
-			    $TrackerLive = new TrackerLive($this->db);
432
-			    $TrackerLive->deleteLiveTrackerDataNotUpdated();
433
-			    $TrackerLive->db = null;
434
-			    //TrackerLive->deleteLiveTrackerData();
435
-			    if ($globalDebug) echo " Done\n";
436
-			    $this->last_delete_hourly = time();
430
+				if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
431
+				$TrackerLive = new TrackerLive($this->db);
432
+				$TrackerLive->deleteLiveTrackerDataNotUpdated();
433
+				$TrackerLive->db = null;
434
+				//TrackerLive->deleteLiveTrackerData();
435
+				if ($globalDebug) echo " Done\n";
436
+				$this->last_delete_hourly = time();
437 437
 			}
438 438
 			
439
-		    }
440
-		    //$ignoreImport = false;
439
+			}
440
+			//$ignoreImport = false;
441 441
 		}
442 442
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
443 443
 		if ($send) return $this->all_tracked[$id];
444
-	    }
444
+		}
445
+	}
445 446
 	}
446
-    }
447 447
 }
448 448
 ?>
Please login to merge, or discard this patch.