Completed
Push — master ( 56221e...3c95ac )
by Yannick
07:57
created
require/class.MarineImport.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class MarineImport {
13
-    private $all_tracked = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
13
+	private $all_tracked = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21 21
 
22
-    public function __construct($dbc = null) {
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -41,50 +41,50 @@  discard block
 block discarded – undo
41 41
 	    }
42 42
 	}
43 43
 	*/
44
-    }
44
+	}
45 45
 
46
-    public function checkAll() {
46
+	public function checkAll() {
47 47
 	global $globalDebug;
48 48
 	if ($globalDebug) echo "Update last seen tracked data...\n";
49 49
 	foreach ($this->all_tracked as $key => $flight) {
50
-	    if (isset($this->all_tracked[$key]['id'])) {
50
+		if (isset($this->all_tracked[$key]['id'])) {
51 51
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
52
-    		$Marine = new Marine($this->db);
53
-        	$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']);
54
-            }
52
+			$Marine = new Marine($this->db);
53
+			$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']);
54
+			}
55
+	}
55 56
 	}
56
-    }
57 57
 
58
-    public function del() {
58
+	public function del() {
59 59
 	global $globalDebug;
60 60
 	// Delete old infos
61 61
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62 62
 	foreach ($this->all_tracked as $key => $flight) {
63
-    	    if (isset($flight['lastupdate'])) {
64
-        	if ($flight['lastupdate'] < (time()-3000)) {
65
-            	    if (isset($this->all_tracked[$key]['id'])) {
66
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
63
+			if (isset($flight['lastupdate'])) {
64
+			if ($flight['lastupdate'] < (time()-3000)) {
65
+					if (isset($this->all_tracked[$key]['id'])) {
66
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
67 67
 			/*
68 68
 			$MarineLive = new MarineLive();
69 69
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
70 70
 			$MarineLive->db = null;
71 71
 			*/
72
-            		//$real_arrival = $this->arrival($key);
73
-            		$Marine = new Marine($this->db);
74
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
72
+					//$real_arrival = $this->arrival($key);
73
+					$Marine = new Marine($this->db);
74
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
75 75
 				$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']);
76 76
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
77 77
 			}
78 78
 			// Put in archive
79 79
 //			$Marine->db = null;
80
-            	    }
81
-            	    unset($this->all_tracked[$key]);
82
-    	        }
83
-	    }
84
-        }
85
-    }
80
+					}
81
+					unset($this->all_tracked[$key]);
82
+				}
83
+		}
84
+		}
85
+	}
86 86
 
87
-    public function add($line) {
87
+	public function add($line) {
88 88
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
89 89
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
90 90
 	date_default_timezone_set('UTC');
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	
94 94
 	// SBS format is CSV format
95 95
 	if(is_array($line) && isset($line['mmsi'])) {
96
-	    //print_r($line);
97
-  	    if (isset($line['mmsi'])) {
96
+		//print_r($line);
97
+  		if (isset($line['mmsi'])) {
98 98
 
99 99
 		/*
100 100
 		// Increment message number
@@ -111,87 +111,87 @@  discard block
 block discarded – undo
111 111
 		
112 112
 		$Common = new Common();
113 113
 		$AIS = new AIS();
114
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
115
-	        else $id = trim($line['id']);
114
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
115
+			else $id = trim($line['id']);
116 116
 		
117 117
 		if (!isset($this->all_tracked[$id])) {
118
-		    $this->all_tracked[$id] = array();
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
-		    if (!isset($line['id'])) {
118
+			$this->all_tracked[$id] = array();
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
120
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
121
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
122
+			if (!isset($line['id'])) {
123 123
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
124 124
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
125
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
125
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
126
+			if ($globalAllTracked !== FALSE) $dataFound = true;
127 127
 		}
128 128
 		
129 129
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
130
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
-		    $Marine = new Marine($this->db);
132
-		    $identity = $Marine->getIdentity($line['mmsi']);
133
-		    if (!empty($identity)) {
130
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
131
+			$Marine = new Marine($this->db);
132
+			$identity = $Marine->getIdentity($line['mmsi']);
133
+			if (!empty($identity)) {
134 134
 			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
135 135
 			$this->all_tracked[$id]['type'] = $identity['type'];
136
-		    }
137
-		    //print_r($identity);
138
-		    unset($Marine);
139
-		    //$dataFound = true;
136
+			}
137
+			//print_r($identity);
138
+			unset($Marine);
139
+			//$dataFound = true;
140 140
 		}
141 141
 		if (isset($line['type_id']) && $line['type_id'] != '') {
142
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
142
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
143 143
 		}
144 144
 		if (isset($line['type']) && $line['type'] != '') {
145
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
145
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
146 146
 		}
147 147
 		if (isset($line['imo']) && $line['imo'] != '') {
148
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
148
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
149 149
 		}
150 150
 		if (isset($line['callsign']) && $line['callsign'] != '') {
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
151
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
152 152
 		}
153 153
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
154
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
154
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
155 155
 		}
156 156
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
157
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
158 158
 		}
159 159
 
160 160
 
161 161
 		//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'])) {
162 162
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
164
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
165 165
 			$timeelapsed = microtime(true);
166
-            		$Marine = new Marine($this->db);
167
-            		$fromsource = NULL;
168
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
166
+					$Marine = new Marine($this->db);
167
+					$fromsource = NULL;
168
+					$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
169 169
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
170 170
 			$Marine->db = null;
171 171
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
172
-		    }
173
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
172
+			}
173
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
174 174
 		}
175 175
 
176 176
 		if (isset($line['speed']) && $line['speed'] != '') {
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
177
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
178
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
179 179
 		} 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'])) {
180
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
-		    if ($distance > 1000 && $distance < 10000) {
180
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
181
+			if ($distance > 1000 && $distance < 10000) {
182 182
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
183 183
 			$speed = $speed*3.6;
184 184
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
185 185
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
186
-		    }
186
+			}
187 187
 		}
188 188
 
189
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
-	    	    else unset($timediff);
192
-	    	    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')))) {
189
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
190
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
191
+				else unset($timediff);
192
+				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')))) {
193 193
 			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'])) {
194
-			    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'])) {
194
+				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'])) {
195 195
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
196 196
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
197 197
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -205,76 +205,76 @@  discard block
 block discarded – undo
205 205
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
206 206
 				$this->tmd = 0;
207 207
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
208
-			    }
208
+				}
209 209
 			}
210 210
 
211 211
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
212 212
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
213 213
 				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') {
214
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
-				    $dataFound = true;
216
-				    $this->all_tracked[$id]['time_last_coord'] = time();
214
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
215
+					$dataFound = true;
216
+					$this->all_tracked[$id]['time_last_coord'] = time();
217 217
 				}
218 218
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
219 219
 			}
220 220
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
221
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
221
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
222 222
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
223 223
 				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') {
224
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
-				    $dataFound = true;
226
-				    $this->all_tracked[$id]['time_last_coord'] = time();
224
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
225
+					$dataFound = true;
226
+					$this->all_tracked[$id]['time_last_coord'] = time();
227 227
 				}
228 228
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
229 229
 			}
230 230
 
231
-		    } else if ($globalDebug && $timediff > 20) {
231
+			} else if ($globalDebug && $timediff > 20) {
232 232
 			$this->tmd = $this->tmd + 1;
233 233
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
234 234
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
235 235
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
236 236
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
237
-		    }
237
+			}
238 238
 		}
239 239
 		if (isset($line['last_update']) && $line['last_update'] != '') {
240
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
240
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
241
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
242 242
 		}
243 243
 		if (isset($line['format_source']) && $line['format_source'] != '') {
244
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
244
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
245 245
 		}
246 246
 		if (isset($line['source_name']) && $line['source_name'] != '') {
247
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
247
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
248 248
 		}
249 249
 		if (isset($line['status']) && $line['status'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
250
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
251 251
 		}
252 252
 
253 253
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
255 255
 		}
256 256
 		
257 257
 		if (isset($line['heading']) && $line['heading'] != '') {
258
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
-		    //$dataFound = true;
258
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
259
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
261
+			//$dataFound = true;
262 262
   		} 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']) {
263
-  		    $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']);
264
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
263
+  			$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']);
264
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
265
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
266
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
267 267
   		}
268 268
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
269 269
 
270 270
 		if (isset($line['datetime'])) {
271
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
271
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
272 272
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
273
-		    } else {
273
+			} else {
274 274
 				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";
275 275
 				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";
276 276
 				return '';
277
-		    }
277
+			}
278 278
 		} else {
279 279
 			date_default_timezone_set('UTC');
280 280
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -282,45 +282,45 @@  discard block
 block discarded – undo
282 282
 
283 283
 
284 284
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
285
-		    $this->all_tracked[$id]['lastupdate'] = time();
286
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
-		        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'])) {
288
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
285
+			$this->all_tracked[$id]['lastupdate'] = time();
286
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
287
+				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'])) {
288
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
289 289
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
290 290
 				$timeelapsed = microtime(true);
291 291
 				$MarineLive = new MarineLive($this->db);
292 292
 				if (isset($line['id'])) {
293
-				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
294
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
293
+					$recent_ident = $MarineLive->checkIdRecent($line['id']);
294
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295 295
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
296
-				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
296
+					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
297
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
298 298
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
299
-				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
299
+					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
300
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
301 301
 				} else $recent_ident = '';
302 302
 				$MarineLive->db=null;
303 303
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
304 304
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
305
-			    } else {
305
+				} else {
306 306
 				$recent_ident = '';
307 307
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
308
-			    }
309
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
-			    {
308
+				}
309
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
310
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
311
+				{
312 312
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
313 313
 				//adds the spotter data for the archive
314
-				    $highlight = '';
315
-				    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')));
316
-				    $timeelapsed = microtime(true);
317
-				    $Marine = new Marine($this->db);
318
-				    $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]['format_source'],$this->all_tracked[$id]['source_name']);
319
-				    $Marine->db = null;
320
-				    if ($globalDebug && isset($result)) echo $result."\n";
321
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
314
+					$highlight = '';
315
+					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')));
316
+					$timeelapsed = microtime(true);
317
+					$Marine = new Marine($this->db);
318
+					$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]['format_source'],$this->all_tracked[$id]['source_name']);
319
+					$Marine->db = null;
320
+					if ($globalDebug && isset($result)) echo $result."\n";
321
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
322 322
 				    
323
-				    /*
323
+					/*
324 324
 				    // Add source stat in DB
325 325
 				    $Stats = new Stats($this->db);
326 326
 				    if (!empty($this->stats)) {
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
 				    }
348 348
 				    $Stats->db = null;
349 349
 				    */
350
-				    $this->del();
350
+					$this->del();
351 351
 				//$ignoreImport = false;
352 352
 				$this->all_tracked[$id]['addedMarine'] = 1;
353 353
 				//print_r($this->all_tracked[$id]);
354 354
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
355
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
357
-				    $MarineLive = new MarineLive($this->db);
358
-				    $MarineLive->deleteLiveMarineData();
359
-				    $MarineLive->db=null;
360
-				    if ($globalDebug) echo " Done\n";
361
-				    $this->last_delete = time();
355
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
356
+					//MarineLive->deleteLiveMarineDataNotUpdated();
357
+					$MarineLive = new MarineLive($this->db);
358
+					$MarineLive->deleteLiveMarineData();
359
+					$MarineLive->db=null;
360
+					if ($globalDebug) echo " Done\n";
361
+					$this->last_delete = time();
362 362
 				}
363
-			    } elseif ($recent_ident != '') {
363
+				} elseif ($recent_ident != '') {
364 364
 				$this->all_tracked[$id]['id'] = $recent_ident;
365 365
 				$this->all_tracked[$id]['addedMarine'] = 1;
366 366
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -369,16 +369,16 @@  discard block
 block discarded – undo
369 369
 					$Marine->db = null;
370 370
 				}
371 371
 				
372
-			    }
372
+				}
373
+			}
373 374
 			}
374
-		    }
375
-		    //adds the spotter LIVE data
376
-		    if ($globalDebug) {
375
+			//adds the spotter LIVE data
376
+			if ($globalDebug) {
377 377
 			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";
378
-		    }
379
-		    $ignoreImport = false;
378
+			}
379
+			$ignoreImport = false;
380 380
 
381
-		    if (!$ignoreImport) {
381
+			if (!$ignoreImport) {
382 382
 			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'])) {
383 383
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
384 384
 				$timeelapsed = microtime(true);
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 			
451 451
 			
452 452
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
453
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
454
-			    $MarineLive = new MarineLive($this->db);
455
-			    $MarineLive->deleteLiveMarineDataNotUpdated();
456
-			    $MarineLive->db = null;
457
-			    //MarineLive->deleteLiveMarineData();
458
-			    if ($globalDebug) echo " Done\n";
459
-			    $this->last_delete_hourly = time();
453
+				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
454
+				$MarineLive = new MarineLive($this->db);
455
+				$MarineLive->deleteLiveMarineDataNotUpdated();
456
+				$MarineLive->db = null;
457
+				//MarineLive->deleteLiveMarineData();
458
+				if ($globalDebug) echo " Done\n";
459
+				$this->last_delete_hourly = time();
460 460
 			}
461 461
 			
462
-		    }
463
-		    //$ignoreImport = false;
462
+			}
463
+			//$ignoreImport = false;
464 464
 		}
465 465
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
466 466
 		if ($send) return $this->all_tracked[$id];
467
-	    }
467
+		}
468
+	}
468 469
 	}
469
-    }
470 470
 }
471 471
 ?>
Please login to merge, or discard this patch.
require/class.MarineLive.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	/**
89
-	* Gets all the spotter information based on the latest data entry
90
-	*
91
-	* @return Array the spotter information
92
-	*
93
-	*/
89
+	 * Gets all the spotter information based on the latest data entry
90
+	 *
91
+	 * @return Array the spotter information
92
+	 *
93
+	 */
94 94
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
95 95
 	{
96 96
 		global $globalDBdriver, $globalLiveInterval;
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Gets Minimal Live Spotter data
136
-	*
137
-	* @return Array the spotter information
138
-	*
139
-	*/
135
+	 * Gets Minimal Live Spotter data
136
+	 *
137
+	 * @return Array the spotter information
138
+	 *
139
+	 */
140 140
 	public function getMinLiveMarineData($filter = array())
141 141
 	{
142 142
 		global $globalDBdriver, $globalLiveInterval;
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 	/**
169
-	* Gets Minimal Live Spotter data since xx seconds
170
-	*
171
-	* @return Array the spotter information
172
-	*
173
-	*/
169
+	 * Gets Minimal Live Spotter data since xx seconds
170
+	 *
171
+	 * @return Array the spotter information
172
+	 *
173
+	 */
174 174
 	public function getMinLastLiveMarineData($filter = array())
175 175
 	{
176 176
 		global $globalDBdriver, $globalLiveInterval;
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186
-                } else {
186
+				} else {
187 187
 			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
191 191
 
192
-    		try {
192
+			try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195 195
 		} catch(PDOException $e) {
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 	}
202 202
 
203 203
 	/**
204
-	* Gets number of latest data entry
205
-	*
206
-	* @return String number of entry
207
-	*
208
-	*/
204
+	 * Gets number of latest data entry
205
+	 *
206
+	 * @return String number of entry
207
+	 *
208
+	 */
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 
232 232
 	/**
233
-	* Gets all the spotter information based on the latest data entry and coord
234
-	*
235
-	* @return Array the spotter information
236
-	*
237
-	*/
233
+	 * Gets all the spotter information based on the latest data entry and coord
234
+	 *
235
+	 * @return Array the spotter information
236
+	 *
237
+	 */
238 238
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
239 239
 	{
240 240
 		global $globalDBdriver, $globalLiveInterval;
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Gets all the spotter information based on a user's latitude and longitude
262
-	*
263
-	* @return Array the spotter information
264
-	*
265
-	*/
261
+	 * Gets all the spotter information based on a user's latitude and longitude
262
+	 *
263
+	 * @return Array the spotter information
264
+	 *
265
+	 */
266 266
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
267 267
 	{
268 268
 		$Marine = new Marine($this->db);
@@ -275,134 +275,134 @@  discard block
 block discarded – undo
275 275
 		if ($lng != '')
276 276
 		{
277 277
 			if (!is_numeric($lng))
278
-                        {
279
-                                return false;
280
-                        }
281
-                }
282
-
283
-                if ($radius != '')
284
-                {
285
-                        if (!is_numeric($radius))
286
-                        {
287
-                                return false;
288
-                        }
289
-                }
278
+						{
279
+								return false;
280
+						}
281
+				}
282
+
283
+				if ($radius != '')
284
+				{
285
+						if (!is_numeric($radius))
286
+						{
287
+								return false;
288
+						}
289
+				}
290 290
 		$additional_query = '';
291 291
 		if ($interval != '')
292
-                {
293
-                        if (!is_string($interval))
294
-                        {
295
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
-			        return false;
297
-                        } else {
298
-                if ($interval == '1m')
299
-                {
300
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
302
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
-                } 
304
-            }
305
-                } else {
306
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
-        }
308
-
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
292
+				{
293
+						if (!is_string($interval))
294
+						{
295
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
+					return false;
297
+						} else {
298
+				if ($interval == '1m')
299
+				{
300
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
+				} else if ($interval == '15m'){
302
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
+				} 
304
+			}
305
+				} else {
306
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
+		}
308
+
309
+				$query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+				$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
317 317
 
318
-                return $spotter_array;
319
-        }
318
+				return $spotter_array;
319
+		}
320 320
 
321 321
     
322
-        /**
323
-	* Gets all the spotter information based on a particular callsign
324
-	*
325
-	* @return Array the spotter information
326
-	*
327
-	*/
322
+		/**
323
+		 * Gets all the spotter information based on a particular callsign
324
+		 *
325
+		 * @return Array the spotter information
326
+		 *
327
+		 */
328 328
 	public function getLastLiveMarineDataByIdent($ident)
329 329
 	{
330 330
 		$Marine = new Marine($this->db);
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336 336
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
340 340
 
341
-        /**
342
-	* Gets all the spotter information based on a particular callsign
343
-	*
344
-	* @return Array the spotter information
345
-	*
346
-	*/
341
+		/**
342
+		 * Gets all the spotter information based on a particular callsign
343
+		 *
344
+		 * @return Array the spotter information
345
+		 *
346
+		 */
347 347
 	public function getDateLiveMarineDataByIdent($ident,$date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
355
+				$date = date('c',$date);
356 356
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
360 360
 
361
-        /**
362
-	* Gets last spotter information based on a particular callsign
363
-	*
364
-	* @return Array the spotter information
365
-	*
366
-	*/
361
+		/**
362
+		 * Gets last spotter information based on a particular callsign
363
+		 *
364
+		 * @return Array the spotter information
365
+		 *
366
+		 */
367 367
 	public function getLastLiveMarineDataById($id)
368 368
 	{
369 369
 		$Marine = new Marine($this->db);
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375 375
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
379 379
 
380
-        /**
381
-	* Gets last spotter information based on a particular callsign
382
-	*
383
-	* @return Array the spotter information
384
-	*
385
-	*/
380
+		/**
381
+		 * Gets last spotter information based on a particular callsign
382
+		 *
383
+		 * @return Array the spotter information
384
+		 *
385
+		 */
386 386
 	public function getDateLiveMarineDataById($id,$date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
392
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+				$date = date('c',$date);
394 394
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
398 398
 
399 399
 
400
-        /**
401
-	* Gets all the spotter information based on a particular id
402
-	*
403
-	* @return Array the spotter information
404
-	*
405
-	*/
400
+		/**
401
+		 * Gets all the spotter information based on a particular id
402
+		 *
403
+		 * @return Array the spotter information
404
+		 *
405
+		 */
406 406
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
 		return $spotter_array;
431 431
 	}
432 432
 
433
-        /**
434
-	* Gets all the spotter information based on a particular ident
435
-	*
436
-	* @return Array the spotter information
437
-	*
438
-	*/
433
+		/**
434
+		 * Gets all the spotter information based on a particular ident
435
+		 *
436
+		 * @return Array the spotter information
437
+		 *
438
+		 */
439 439
 	public function getAllLiveMarineDataByIdent($ident)
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443 443
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
444
-    		try {
444
+			try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
 
456 456
 
457 457
 	/**
458
-	* Deletes all info in the table
459
-	*
460
-	* @return String success or false
461
-	*
462
-	*/
458
+	 * Deletes all info in the table
459
+	 *
460
+	 * @return String success or false
461
+	 *
462
+	 */
463 463
 	public function deleteLiveMarineData()
464 464
 	{
465 465
 		global $globalDBdriver;
466 466
 		if ($globalDBdriver == 'mysql') {
467 467
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
468 468
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
469
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
469
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
470 470
 		} else {
471 471
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
472 472
 		}
473 473
         
474
-    		try {
474
+			try {
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
487
-	*
488
-	* @return String success or false
489
-	*
490
-	*/
486
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
487
+	 *
488
+	 * @return String success or false
489
+	 *
490
+	 */
491 491
 	public function deleteLiveMarineDataNotUpdated()
492 492
 	{
493 493
 		global $globalDBdriver, $globalDebug;
494 494
 		if ($globalDBdriver == 'mysql') {
495 495
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
496
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
-    			try {
496
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
+				try {
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505
-                        $i = 0;
506
-                        $j =0;
505
+						$i = 0;
506
+						$j =0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508 508
 			foreach($all as $row)
509 509
 			{
@@ -511,20 +511,20 @@  discard block
 block discarded – undo
511 511
 				$j++;
512 512
 				if ($j == 30) {
513 513
 					if ($globalDebug) echo ".";
514
-				    	try {
514
+						try {
515 515
 						
516 516
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
517 517
 						$sth->execute();
518 518
 					} catch(PDOException $e) {
519 519
 						return "error";
520 520
 					}
521
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
-                                	$j = 0;
521
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
+									$j = 0;
523 523
 				}
524 524
 				$query_delete .= "'".$row['fammarine_id']."',";
525 525
 			}
526 526
 			if ($i > 0) {
527
-    				try {
527
+					try {
528 528
 					
529 529
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
530 530
 					$sth->execute();
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 			return "success";
536 536
 		} elseif ($globalDBdriver == 'pgsql') {
537 537
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
538
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
-    			try {
538
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
+				try {
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
@@ -581,17 +581,17 @@  discard block
 block discarded – undo
581 581
 	}
582 582
 
583 583
 	/**
584
-	* Deletes all info in the table for an ident
585
-	*
586
-	* @return String success or false
587
-	*
588
-	*/
584
+	 * Deletes all info in the table for an ident
585
+	 *
586
+	 * @return String success or false
587
+	 *
588
+	 */
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592 592
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594
-    		try {
594
+			try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	}
604 604
 
605 605
 	/**
606
-	* Deletes all info in the table for an id
607
-	*
608
-	* @return String success or false
609
-	*
610
-	*/
606
+	 * Deletes all info in the table for an id
607
+	 *
608
+	 * @return String success or false
609
+	 *
610
+	 */
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614 614
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616
-    		try {
616
+			try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
@@ -626,11 +626,11 @@  discard block
 block discarded – undo
626 626
 
627 627
 
628 628
 	/**
629
-	* Gets the aircraft ident within the last hour
630
-	*
631
-	* @return String the ident
632
-	*
633
-	*/
629
+	 * Gets the aircraft ident within the last hour
630
+	 *
631
+	 * @return String the ident
632
+	 *
633
+	 */
634 634
 	public function getIdentFromLastHour($ident)
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
@@ -656,14 +656,14 @@  discard block
 block discarded – undo
656 656
 			$ident_result = $row['ident'];
657 657
 		}
658 658
 		return $ident_result;
659
-        }
659
+		}
660 660
 
661 661
 	/**
662
-	* Check recent aircraft
663
-	*
664
-	* @return String the ident
665
-	*
666
-	*/
662
+	 * Check recent aircraft
663
+	 *
664
+	 * @return String the ident
665
+	 *
666
+	 */
667 667
 	public function checkIdentRecent($ident)
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
691 691
 		return $ident_result;
692
-        }
692
+		}
693 693
 
694 694
 	/**
695
-	* Check recent aircraft by id
696
-	*
697
-	* @return String the ident
698
-	*
699
-	*/
695
+	 * Check recent aircraft by id
696
+	 *
697
+	 * @return String the ident
698
+	 *
699
+	 */
700 700
 	public function checkIdRecent($id)
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
@@ -722,14 +722,14 @@  discard block
 block discarded – undo
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
724 724
 		return $ident_result;
725
-        }
725
+		}
726 726
 
727 727
 	/**
728
-	* Check recent aircraft by mmsi
729
-	*
730
-	* @return String the ident
731
-	*
732
-	*/
728
+	 * Check recent aircraft by mmsi
729
+	 *
730
+	 * @return String the ident
731
+	 *
732
+	 */
733 733
 	public function checkMMSIRecent($mmsi)
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
@@ -755,19 +755,19 @@  discard block
 block discarded – undo
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
757 757
 		return $ident_result;
758
-        }
758
+		}
759 759
 
760 760
 	/**
761
-	* Adds a new spotter data
762
-	*
763
-	* @param String $fammarine_id the ID from flightaware
764
-	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769
-	*
770
-	*/
761
+	 * Adds a new spotter data
762
+	 *
763
+	 * @param String $fammarine_id the ID from flightaware
764
+	 * @param String $ident the flight ident
765
+	 * @param String $aircraft_icao the aircraft type
766
+	 * @param String $departure_airport_icao the departure airport
767
+	 * @param String $arrival_airport_icao the arrival airport
768
+	 * @return String success or false
769
+	 *
770
+	 */
771 771
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
@@ -838,9 +838,9 @@  discard block
 block discarded – undo
838 838
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
839 839
 		
840 840
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
-            	if ($arrival_date == '') $arrival_date = NULL;
841
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
+				if ($arrival_date == '') $arrival_date = NULL;
844 844
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 845
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 846
 
@@ -849,9 +849,9 @@  discard block
 block discarded – undo
849 849
 			
850 850
 			$sth = $this->db->prepare($query);
851 851
 			$sth->execute($query_values);
852
-                } catch(PDOException $e) {
853
-                	return "error : ".$e->getMessage();
854
-                }
852
+				} catch(PDOException $e) {
853
+					return "error : ".$e->getMessage();
854
+				}
855 855
 		/*
856 856
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
857 857
 		    if ($globalDebug) echo '(Add to SBS archive : ';
Please login to merge, or discard this patch.
require/class.Common.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 	//protected $cookies = array();
8 8
 	
9 9
 	/**
10
-	* Get data from form result
11
-	* @param String $url form URL
12
-	* @param String $type type of submit form method (get or post)
13
-	* @param String|Array $data values form post method
14
-	* @param Array $headers header to submit with the form
15
-	* @return String the result
16
-	*/
10
+	 * Get data from form result
11
+	 * @param String $url form URL
12
+	 * @param String $type type of submit form method (get or post)
13
+	 * @param String|Array $data values form post method
14
+	 * @param Array $headers header to submit with the form
15
+	 * @return String the result
16
+	 */
17 17
 	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	}
108 108
 	
109 109
 	/**
110
-	* Convert a HTML table to an array
111
-	* @param String $data HTML page
112
-	* @return Array array of the tables in HTML page
113
-	*/
110
+	 * Convert a HTML table to an array
111
+	 * @param String $data HTML page
112
+	 * @return Array array of the tables in HTML page
113
+	 */
114 114
 	public function table2array($data) {
115 115
 		if (!is_string($data)) return array();
116 116
 		if ($data == '') return array();
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 	
146 146
 	/**
147
-	* Convert <p> part of a HTML page to an array
148
-	* @param String $data HTML page
149
-	* @return Array array of the <p> in HTML page
150
-	*/
147
+	 * Convert <p> part of a HTML page to an array
148
+	 * @param String $data HTML page
149
+	 * @return Array array of the <p> in HTML page
150
+	 */
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
@@ -162,14 +162,14 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 
164 164
 	/**
165
-	* Give distance between 2 coordonnates
166
-	* @param Float $lat latitude of first point
167
-	* @param Float $lon longitude of first point
168
-	* @param Float $latc latitude of second point
169
-	* @param Float $lonc longitude of second point
170
-	* @param String $unit km else no unit used
171
-	* @return Float Distance in $unit
172
-	*/
165
+	 * Give distance between 2 coordonnates
166
+	 * @param Float $lat latitude of first point
167
+	 * @param Float $lon longitude of first point
168
+	 * @param Float $latc latitude of second point
169
+	 * @param Float $lonc longitude of second point
170
+	 * @param String $unit km else no unit used
171
+	 * @return Float Distance in $unit
172
+	 */
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175 175
 		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 	}
188 188
 
189 189
 	/**
190
-	* Check is distance realistic
191
-	* @param int $timeDifference the time between the reception of both messages
192
-	* @param float $distance distance covered
193
-	* @return whether distance is realistic
194
-	*/
190
+	 * Check is distance realistic
191
+	 * @param int $timeDifference the time between the reception of both messages
192
+	 * @param float $distance distance covered
193
+	 * @return whether distance is realistic
194
+	 */
195 195
 	public function withinThreshold ($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	}
210 210
 
211 211
 	public function isInteger($input){
212
-	    return(ctype_digit(strval($input)));
212
+		return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 	}
241 241
 	
242 242
 	/**
243
-	* Copy folder contents
244
-	* @param       string   $source    Source path
245
-	* @param       string   $dest      Destination path
246
-	* @return      bool     Returns true on success, false on failure
247
-	*/
243
+	 * Copy folder contents
244
+	 * @param       string   $source    Source path
245
+	 * @param       string   $dest      Destination path
246
+	 * @return      bool     Returns true on success, false on failure
247
+	 */
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
@@ -256,20 +256,20 @@  discard block
 block discarded – undo
256 256
 	}
257 257
 	
258 258
 	/**
259
-	* Check if an url exist
260
-	* @param	String $url url to check
261
-	* @return	bool Return true on succes false on failure
262
-	*/
259
+	 * Check if an url exist
260
+	 * @param	String $url url to check
261
+	 * @return	bool Return true on succes false on failure
262
+	 */
263 263
 	public function urlexist($url){
264 264
 		$headers=get_headers($url);
265 265
 		return stripos($headers[0],"200 OK")?true:false;
266 266
 	}
267 267
 	
268 268
 	/**
269
-	* Convert hexa to string
270
-	* @param	String $hex data in hexa
271
-	* @return	String Return result
272
-	*/
269
+	 * Convert hexa to string
270
+	 * @param	String $hex data in hexa
271
+	 * @return	String Return result
272
+	 */
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	}
351 351
 	
352 352
 	/**
353
-	* Returns list of available locales
354
-	*
355
-	* @return array
353
+	 * Returns list of available locales
354
+	 *
355
+	 * @return array
356 356
 	 */
357 357
 	public function listLocaleDir()
358 358
 	{
@@ -447,100 +447,100 @@  discard block
 block discarded – undo
447 447
 	public function remove_accents($string) {
448 448
 		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
449 449
 		$chars = array(
450
-		    // Decompositions for Latin-1 Supplement
451
-		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
-		    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
-		    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
-		    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
-		    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
-		    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
-		    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
-		    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
-		    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
-		    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
-		    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
-		    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
-		    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
-		    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
-		    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
-		    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
-		    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
-		    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
-		    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
-		    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
-		    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
-		    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
-		    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
-		    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
-		    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
-		    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
-		    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
-		    chr(195).chr(191) => 'y',
479
-		    // Decompositions for Latin Extended-A
480
-		    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
-		    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
-		    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
-		    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
-		    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
-		    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
-		    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
-		    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
-		    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
-		    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
-		    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
-		    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
-		    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
-		    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
-		    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
-		    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
-		    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
-		    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
-		    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
-		    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
-		    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
-		    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
-		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
-		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
-		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
-		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
-		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
-		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
-		    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
-		    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
-		    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
-		    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
-		    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
-		    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
-		    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
-		    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
-		    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
-		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
-		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
-		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
-		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
-		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
-		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
-		    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
-		    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
-		    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
-		    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
-		    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
-		    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
-		    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
-		    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
-		    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
-		    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
-		    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
-		    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
-		    chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
450
+			// Decompositions for Latin-1 Supplement
451
+			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
+			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
+			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
+			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
+			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
+			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
+			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
+			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
+			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
+			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
+			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
+			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
+			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
+			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
+			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
+			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
+			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
+			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
+			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
+			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
+			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
+			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
+			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
+			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
+			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
+			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
+			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
+			chr(195).chr(191) => 'y',
479
+			// Decompositions for Latin Extended-A
480
+			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
+			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
+			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
+			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
+			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
+			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
+			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
+			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
+			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
+			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
+			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
+			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
+			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
+			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
+			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
+			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
+			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
+			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
+			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
+			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
+			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
+			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
+			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
+			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
+			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
+			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
+			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
+			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
+			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
+			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
+			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
+			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
+			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
+			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
+			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
+			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
+			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
+			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
+			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
+			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
+			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
+			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
+			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
+			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
+			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
+			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
+			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
+			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
+			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
+			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
+			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
+			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
+			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
+			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
+			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
+			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
+			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
+			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
+			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
+			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
+			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
+			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
+			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
+			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
544 544
 		);
545 545
 		$string = strtr($string, $chars);
546 546
 		return $string;
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class SpotterImport {
13
-    private $all_flights = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
21
-
22
-    public function __construct($dbc = null) {
13
+	private $all_flights = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21
+
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta, $globalServerAPRS, $APRSSpotter;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
34
-	    	$type = $srcst['stats_type'];
33
+		foreach($sourcestat as $srcst) {
34
+			$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36
-		    $source = $srcst['source_name'];
37
-		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
-	        }
40
-	    }
36
+			$source = $srcst['source_name'];
37
+			$data = $srcst['source_data'];
38
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
+			}
40
+		}
41 41
 	}
42 42
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
43 43
 		$APRSSpotter = new APRSSpotter();
44 44
 		$APRSSpotter->connect();
45 45
 	}
46 46
 
47
-    }
47
+	}
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+	public function get_Schedule($id,$ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -66,42 +66,42 @@  discard block
 block discarded – undo
66 66
 	$operator = $Spotter->getOperator($ident);
67 67
 	$scheduleexist = false;
68 68
 	if ($Schedule->checkSchedule($operator) == 0) {
69
-	    $operator = $Translation->checkTranslation($ident);
70
-	    if ($Schedule->checkSchedule($operator) == 0) {
69
+		$operator = $Translation->checkTranslation($ident);
70
+		if ($Schedule->checkSchedule($operator) == 0) {
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
-		    // Should also check if route schedule = route from DB
77
-		    if ($schedule['DepartureAirportIATA'] != '') {
73
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
+			// Should also check if route schedule = route from DB
77
+			if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
79
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
-			    if (trim($airport_icao) != '') {
79
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
+				if (trim($airport_icao) != '') {
81 81
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82 82
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
83
-			    }
83
+				}
84
+			}
84 85
 			}
85
-		    }
86
-		    if ($schedule['ArrivalAirportIATA'] != '') {
86
+			if ($schedule['ArrivalAirportIATA'] != '') {
87 87
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
88
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
-			    if (trim($airport_icao) != '') {
88
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
+				if (trim($airport_icao) != '') {
90 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91 91
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
92
-			    }
92
+				}
93
+			}
93 94
 			}
94
-		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 96
 		}
97
-	    } else $scheduleexist = true;
97
+		} else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
99 99
 	// close connection, at least one way will work ?
100
-       if ($scheduleexist) {
100
+	   if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102
-    		$sch = $Schedule->getSchedule($operator);
102
+			$sch = $Schedule->getSchedule($operator);
103 103
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104
-       }
104
+	   }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
107 107
 	$Translation->db = null;
@@ -116,96 +116,96 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 	  */
118 118
 	}
119
-    }
119
+	}
120 120
 
121
-    public function checkAll() {
121
+	public function checkAll() {
122 122
 	global $globalDebug, $globalNoImport;
123 123
 	if ($globalDebug) echo "Update last seen flights data...\n";
124 124
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125
-	    foreach ($this->all_flights as $key => $flight) {
125
+		foreach ($this->all_flights as $key => $flight) {
126 126
 		if (isset($this->all_flights[$key]['id'])) {
127
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
-    		    $Spotter = new Spotter($this->db);
129
-        	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
-        	}
132
-	    }
127
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
+				$Spotter = new Spotter($this->db);
129
+				$real_arrival = $this->arrival($key);
130
+				$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
+			}
132
+		}
133
+	}
133 134
 	}
134
-    }
135 135
 
136
-    public function arrival($key) {
136
+	public function arrival($key) {
137 137
 	global $globalClosestMinDist, $globalDebug;
138 138
 	if ($globalDebug) echo 'Update arrival...'."\n";
139 139
 	$Spotter = new Spotter($this->db);
140
-        $airport_icao = '';
141
-        $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
140
+		$airport_icao = '';
141
+		$airport_time = '';
142
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
-    	    if (isset($closestAirports[0])) {
146
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
-        	    $airport_icao = $closestAirports[0]['icao'];
148
-        	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
-        	    foreach ($closestAirports as $airport) {
152
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
-        		    $airport_icao = $airport['icao'];
154
-        		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
-        		    break;
157
-        		}
158
-        	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
-        		$airport_icao = $closestAirports[0]['icao'];
161
-        		$airport_time = $this->all_flights[$key]['datetime'];
162
-        	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
-        	}
165
-    	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
-    	    }
168
-
169
-        } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
-        }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
-    }
174
-
175
-
176
-
177
-    public function del() {
144
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
+			if (isset($closestAirports[0])) {
146
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
+				$airport_icao = $closestAirports[0]['icao'];
148
+				$airport_time = $this->all_flights[$key]['datetime'];
149
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
+				foreach ($closestAirports as $airport) {
152
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
+					$airport_icao = $airport['icao'];
154
+					$airport_time = $this->all_flights[$key]['datetime'];
155
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
+					break;
157
+				}
158
+				}
159
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
+				$airport_icao = $closestAirports[0]['icao'];
161
+				$airport_time = $this->all_flights[$key]['datetime'];
162
+			} else {
163
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
+			}
165
+			} else {
166
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
+			}
168
+
169
+		} else {
170
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
+		}
172
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
+	}
174
+
175
+
176
+
177
+	public function del() {
178 178
 	global $globalDebug, $globalNoImport;
179 179
 	// Delete old infos
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182
-    	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
184
-            	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
182
+			if (isset($flight['lastupdate'])) {
183
+			if ($flight['lastupdate'] < (time()-3000)) {
184
+					if (isset($this->all_flights[$key]['id'])) {
185
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
187 187
 			$SpotterLive = new SpotterLive();
188 188
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
189 189
 			$SpotterLive->db = null;
190 190
 			*/
191 191
 			if (!isset($globalNoImport) || $globalNoImport === FALSE) {
192
-            		    $real_arrival = $this->arrival($key);
193
-            		    $Spotter = new Spotter($this->db);
194
-            	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
192
+						$real_arrival = $this->arrival($key);
193
+						$Spotter = new Spotter($this->db);
194
+							if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 195
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197
-			    }
197
+				}
198 198
 			// Put in archive
199 199
 //				$Spotter->db = null;
200 200
 			}
201
-            	    }
202
-            	    unset($this->all_flights[$key]);
203
-    	        }
204
-	    }
205
-        }
206
-    }
201
+					}
202
+					unset($this->all_flights[$key]);
203
+				}
204
+		}
205
+		}
206
+	}
207 207
 
208
-    public function add($line) {
208
+	public function add($line) {
209 209
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 210
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211 211
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 	
231 231
 	// SBS format is CSV format
232 232
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233
-	    //print_r($line);
234
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
233
+		//print_r($line);
234
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
236 236
 		// Increment message number
237 237
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238
-		    $current_date = date('Y-m-d');
239
-		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
238
+			$current_date = date('Y-m-d');
239
+			$source = $line['source_name'];
240
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
242
+				$this->stats[$current_date][$source]['msg']['date'] = time();
243
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
245 245
 		}
246 246
 		
247 247
 		/*
@@ -257,34 +257,34 @@  discard block
 block discarded – undo
257 257
 		//$this->db = $dbc;
258 258
 
259 259
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
260
+			if (!isset($line['id'])) $id = trim($line['hex']);
261
+			else $id = trim($line['id']);
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264
-		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
-		    if (!isset($line['id'])) {
264
+			$this->all_flights[$id] = array();
265
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
+			if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272 272
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
273
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
273
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
+			if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
283
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
286
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 			$Spotter->db = null;
296 296
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297 297
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
298
-		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298
+			}
299
+			if ($globalAllFlights !== FALSE) $dataFound = true;
300
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 303
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323 323
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
324
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
324
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 325
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326
-		    } else {
326
+			} else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
329 329
 				/*
@@ -332,41 +332,41 @@  discard block
 block discarded – undo
332 332
 				print_r($line);
333 333
 				*/
334 334
 				return '';
335
-		    }
335
+			}
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338 338
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
355
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358
-            		$Spotter = new Spotter($this->db);
359
-            		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
358
+					$Spotter = new Spotter($this->db);
359
+					$fromsource = NULL;
360
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368 368
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
-		    }
369
+			}
370 370
 
371 371
 /*
372 372
 		    if (!isset($line['id'])) {
@@ -376,26 +376,26 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381
-		    //$putinarchive = true;
382
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
381
+			//$putinarchive = true;
382
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383 383
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
384
-		    }
385
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
384
+			}
385
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386 386
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
387
-		    }
388
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
387
+			}
388
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
395
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396 396
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397 397
 
398
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
398
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
400 400
 			$Spotter = new Spotter($this->db);
401 401
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -409,43 +409,43 @@  discard block
 block discarded – undo
409 409
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
412
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
-		    	    }
415
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
+					}
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420 420
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
421 421
 			}
422
-		    }
422
+			}
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
-		    //$dataFound = true;
427
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
+			//$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
-		    if ($distance > 1000 && $distance < 10000) {
433
-		    // use datetime
431
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
+			if ($distance > 1000 && $distance < 10000) {
433
+			// use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436 436
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438
-		    }
438
+			}
439 439
 		}
440 440
 
441 441
 
442 442
 
443
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
443
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
+				else unset($timediff);
446
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -459,16 +459,16 @@  discard block
 block discarded – undo
459 459
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460 460
 				$this->tmd = 0;
461 461
 				if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462
-			    }
462
+				}
463 463
 			}
464 464
 
465 465
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
466
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
466
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467 467
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
468 468
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470
-				    $dataFound = true;
471
-				    $this->all_flights[$id]['time_last_coord'] = time();
469
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
470
+					$dataFound = true;
471
+					$this->all_flights[$id]['time_last_coord'] = time();
472 472
 				}
473 473
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
474 474
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -479,20 +479,20 @@  discard block
 block discarded – undo
479 479
 				    //$putinarchive = true;
480 480
 				}
481 481
 				*/
482
-			    /*
482
+				/*
483 483
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
484 484
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
485 485
 			    }
486 486
 			    */
487 487
 			}
488 488
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
489
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
490
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
489
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
490
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
491 491
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
492 492
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494
-				    $dataFound = true;
495
-				    $this->all_flights[$id]['time_last_coord'] = time();
493
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
494
+					$dataFound = true;
495
+					$this->all_flights[$id]['time_last_coord'] = time();
496 496
 				}
497 497
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
498 498
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -510,54 +510,54 @@  discard block
 block discarded – undo
510 510
 			    */
511 511
 			}
512 512
 
513
-		    } else if ($globalDebug && $timediff > 20) {
513
+			} else if ($globalDebug && $timediff > 20) {
514 514
 			$this->tmd = $this->tmd + 1;
515 515
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
516 516
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
517 517
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
518 518
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
519
-		    }
519
+			}
520 520
 		}
521 521
 		if (isset($line['last_update']) && $line['last_update'] != '') {
522
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
523
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
522
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
523
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524 524
 		}
525 525
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
526
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
-		    //$dataFound = true;
526
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
+			//$dataFound = true;
528 528
 		}
529 529
 		if (isset($line['format_source']) && $line['format_source'] != '') {
530
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
530
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531 531
 		}
532 532
 		if (isset($line['source_name']) && $line['source_name'] != '') {
533
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
533
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534 534
 		}
535 535
 		if (isset($line['emergency']) && $line['emergency'] != '') {
536
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
-		    //$dataFound = true;
536
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
+			//$dataFound = true;
538 538
 		}
539 539
 		if (isset($line['ground']) && $line['ground'] != '') {
540
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
540
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
541 541
 			// Here we force archive of flight because after ground it's a new one (or should be)
542 542
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
543 543
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
544 544
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
545
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
545
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546 546
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
547
-		    }
548
-		    if ($line['ground'] != 1) $line['ground'] = 0;
549
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
-		    //$dataFound = true;
547
+			}
548
+			if ($line['ground'] != 1) $line['ground'] = 0;
549
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
+			//$dataFound = true;
551 551
 		}
552 552
 		if (isset($line['squawk']) && $line['squawk'] != '') {
553
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
555
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
-			    $highlight = '';
557
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
560
-			    if ($highlight != '') {
553
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
554
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
555
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
+				$highlight = '';
557
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
558
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
559
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
560
+				if ($highlight != '') {
561 561
 				$timeelapsed = microtime(true);
562 562
 				$Spotter = new Spotter($this->db);
563 563
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -566,38 +566,38 @@  discard block
 block discarded – undo
566 566
 
567 567
 				//$putinarchive = true;
568 568
 				//$highlight = '';
569
-			    }
569
+				}
570 570
 			    
571
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
-		    //$dataFound = true;
571
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
+			//$dataFound = true;
573 573
 		}
574 574
 
575 575
 		if (isset($line['altitude']) && $line['altitude'] != '') {
576
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
576
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577 577
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
578 578
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
579 579
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
580 580
 			//$dataFound = true;
581
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
581
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
582 582
   		}
583 583
 
584 584
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
585
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
585
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586 586
 		}
587 587
 		
588 588
 		if (isset($line['heading']) && $line['heading'] != '') {
589
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592
-		    //$dataFound = true;
589
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
590
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
591
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
592
+			//$dataFound = true;
593 593
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
594
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
594
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
595
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
596
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
597
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
598 598
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
599
-  		    // If not enough messages and ACARS set heading to 0
600
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
599
+  			// If not enough messages and ACARS set heading to 0
600
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601 601
   		}
602 602
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
603 603
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -608,121 +608,121 @@  discard block
 block discarded – undo
608 608
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
609 609
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
610 610
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
611
-		    $this->all_flights[$id]['lastupdate'] = time();
612
-		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
613
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
-			    //print_r($this->all_flights);
615
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
611
+			$this->all_flights[$id]['lastupdate'] = time();
612
+			if ($this->all_flights[$id]['addedSpotter'] == 0) {
613
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
+				//print_r($this->all_flights);
615
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
616
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
617
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
618 618
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
619 619
 				$timeelapsed = microtime(true);
620 620
 				$SpotterLive = new SpotterLive($this->db);
621 621
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
622
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
622
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
623
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
624 624
 				} elseif (isset($line['id'])) {
625
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
625
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
626
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
627 627
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
628
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
628
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
629
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630 630
 				} else $recent_ident = '';
631 631
 				$SpotterLive->db=null;
632 632
 
633 633
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
634 634
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
635
-			    } else {
635
+				} else {
636 636
 				$recent_ident = '';
637 637
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
638
-			    }
639
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
640
-			    if($recent_ident == "")
641
-			    {
638
+				}
639
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
640
+				if($recent_ident == "")
641
+				{
642 642
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
643 643
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
644 644
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
645 645
 				//adds the spotter data for the archive
646 646
 				$ignoreImport = false;
647 647
 				foreach($globalAirportIgnore as $airportIgnore) {
648
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
648
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
649 649
 					$ignoreImport = true;
650
-				    }
650
+					}
651 651
 				}
652 652
 				if (count($globalAirportAccept) > 0) {
653
-				    $ignoreImport = true;
654
-				    foreach($globalAirportIgnore as $airportIgnore) {
653
+					$ignoreImport = true;
654
+					foreach($globalAirportIgnore as $airportIgnore) {
655 655
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
656
-					    $ignoreImport = false;
656
+						$ignoreImport = false;
657
+					}
657 658
 					}
658
-				    }
659 659
 				}
660 660
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
661
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
661
+					foreach($globalAirlineIgnore as $airlineIgnore) {
662 662
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
663
-					    $ignoreImport = true;
663
+						$ignoreImport = true;
664
+					}
664 665
 					}
665
-				    }
666 666
 				}
667 667
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
668
-				    $ignoreImport = true;
669
-				    foreach($globalAirlineAccept as $airlineAccept) {
668
+					$ignoreImport = true;
669
+					foreach($globalAirlineAccept as $airlineAccept) {
670 670
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
671
-					    $ignoreImport = false;
671
+						$ignoreImport = false;
672
+					}
672 673
 					}
673
-				    }
674 674
 				}
675 675
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
676
-				    $ignoreImport = true;
677
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
676
+					$ignoreImport = true;
677
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
678 678
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
679
-					    $ignoreImport = false;
679
+						$ignoreImport = false;
680
+					}
680 681
 					}
681
-				    }
682 682
 				}
683 683
 				
684 684
 				if (!$ignoreImport) {
685
-				    $highlight = '';
686
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
-				    $timeelapsed = microtime(true);
691
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
685
+					$highlight = '';
686
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
687
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
688
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
689
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
+					$timeelapsed = microtime(true);
691
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
692 692
 					$Spotter = new Spotter($this->db);
693 693
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694 694
 					$Spotter->db = null;
695 695
 					if ($globalDebug && isset($result)) echo $result."\n";
696
-				    }
697
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696
+					}
697
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698 698
 				    
699
-				    // Add source stat in DB
700
-				    $Stats = new Stats($this->db);
701
-				    if (!empty($this->stats)) {
699
+					// Add source stat in DB
700
+					$Stats = new Stats($this->db);
701
+					if (!empty($this->stats)) {
702 702
 					if ($globalDebug) echo 'Add source stats : ';
703
-				        foreach($this->stats as $date => $data) {
704
-					    foreach($data as $source => $sourced) {
705
-					        //print_r($sourced);
706
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
708
-				    		if (isset($sourced['msg'])) {
709
-				    		    if (time() - $sourced['msg']['date'] > 10) {
710
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
711
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
-			    			        unset($this->stats[$date][$source]['msg']);
713
-			    			    }
714
-			    			}
715
-			    		    }
716
-			    		    if ($date != date('Y-m-d')) {
717
-			    			unset($this->stats[$date]);
718
-			    		    }
719
-				    	}
720
-				    	if ($globalDebug) echo 'Done'."\n";
721
-
722
-				    }
723
-				    $Stats->db = null;
703
+						foreach($this->stats as $date => $data) {
704
+						foreach($data as $source => $sourced) {
705
+							//print_r($sourced);
706
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
707
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
708
+							if (isset($sourced['msg'])) {
709
+								if (time() - $sourced['msg']['date'] > 10) {
710
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
711
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
+									unset($this->stats[$date][$source]['msg']);
713
+								}
714
+							}
715
+							}
716
+							if ($date != date('Y-m-d')) {
717
+							unset($this->stats[$date]);
718
+							}
719
+						}
720
+						if ($globalDebug) echo 'Done'."\n";
721
+
722
+					}
723
+					$Stats->db = null;
724 724
 				    
725
-				    $this->del();
725
+					$this->del();
726 726
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
727 727
 				//$ignoreImport = false;
728 728
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -740,37 +740,37 @@  discard block
 block discarded – undo
740 740
 			*/
741 741
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
742 742
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
743
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
744
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
745
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
743
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
744
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
745
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
746 746
 					$SpotterLive = new SpotterLive($this->db);
747 747
 					$SpotterLive->deleteLiveSpotterData();
748 748
 					$SpotterLive->db=null;
749
-				    }
750
-				    if ($globalDebug) echo " Done\n";
751
-				    $this->last_delete = time();
749
+					}
750
+					if ($globalDebug) echo " Done\n";
751
+					$this->last_delete = time();
752 752
 				}
753
-			    } else {
753
+				} else {
754 754
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
755
-				    $this->all_flights[$id]['id'] = $recent_ident;
756
-				    $this->all_flights[$id]['addedSpotter'] = 1;
755
+					$this->all_flights[$id]['id'] = $recent_ident;
756
+					$this->all_flights[$id]['addedSpotter'] = 1;
757 757
 				}
758 758
 				if (isset($globalDaemon) && !$globalDaemon) {
759
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
759
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
760 760
 					$Spotter = new Spotter($this->db);
761 761
 					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
762 762
 					$Spotter->db = null;
763
-				    }
763
+					}
764 764
 				}
765 765
 				
766
-			    }
766
+				}
767
+			}
767 768
 			}
768
-		    }
769
-		    //adds the spotter LIVE data
770
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
771
-		    //echo "\nAdd in Live !! \n";
772
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773
-		    if ($globalDebug) {
769
+			//adds the spotter LIVE data
770
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
771
+			//echo "\nAdd in Live !! \n";
772
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
773
+			if ($globalDebug) {
774 774
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
775 775
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
776 776
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -778,49 +778,49 @@  discard block
 block discarded – undo
778 778
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
779 779
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
780 780
 			}
781
-		    }
782
-		    $ignoreImport = false;
783
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
784
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
781
+			}
782
+			$ignoreImport = false;
783
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
784
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
785 785
 
786
-		    foreach($globalAirportIgnore as $airportIgnore) {
787
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788
-			    $ignoreImport = true;
786
+			foreach($globalAirportIgnore as $airportIgnore) {
787
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788
+				$ignoreImport = true;
789
+			}
789 790
 			}
790
-		    }
791
-		    if (count($globalAirportAccept) > 0) {
792
-		        $ignoreImport = true;
793
-		        foreach($globalAirportIgnore as $airportIgnore) {
794
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
791
+			if (count($globalAirportAccept) > 0) {
792
+				$ignoreImport = true;
793
+				foreach($globalAirportIgnore as $airportIgnore) {
794
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
795 795
 				$ignoreImport = false;
796
-			    }
796
+				}
797
+			}
797 798
 			}
798
-		    }
799
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
799
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
800 800
 			foreach($globalAirlineIgnore as $airlineIgnore) {
801
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
801
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
802 802
 				$ignoreImport = true;
803
-			    }
803
+				}
804
+			}
804 805
 			}
805
-		    }
806
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
806
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
807 807
 			$ignoreImport = true;
808 808
 			foreach($globalAirlineAccept as $airlineAccept) {
809
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
809
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
810 810
 				$ignoreImport = false;
811
-			    }
811
+				}
812
+			}
812 813
 			}
813
-		    }
814
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
814
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
815 815
 			$ignoreImport = true;
816 816
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
817
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
818
-			        $ignoreImport = false;
819
-			    }
817
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
818
+					$ignoreImport = false;
819
+				}
820
+			}
820 821
 			}
821
-		    }
822 822
 
823
-		    if (!$ignoreImport) {
823
+			if (!$ignoreImport) {
824 824
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825 825
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
826 826
 				$timeelapsed = microtime(true);
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 					if ($stats_heading == 16) $stats_heading = 0;
865 865
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
866 866
 						for ($i=0;$i<=15;$i++) {
867
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
867
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
868 868
 						}
869 869
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
870 870
 					} else {
@@ -877,11 +877,11 @@  discard block
 block discarded – undo
877 877
 					//var_dump($this->stats);
878 878
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
879 879
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
880
-						    end($this->stats[$current_date][$source]['hist']);
881
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
880
+							end($this->stats[$current_date][$source]['hist']);
881
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
882 882
 						} else $mini = 0;
883 883
 						for ($i=$mini;$i<=$distance;$i+=10) {
884
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
884
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
885 885
 						}
886 886
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
887 887
 					} else {
@@ -898,22 +898,22 @@  discard block
 block discarded – undo
898 898
 			
899 899
 			
900 900
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901
-			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
902
-			    $SpotterLive = new SpotterLive($this->db);
903
-			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
904
-			    $SpotterLive->db = null;
905
-			    //SpotterLive->deleteLiveSpotterData();
906
-			    if ($globalDebug) echo " Done\n";
907
-			    $this->last_delete_hourly = time();
901
+				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
902
+				$SpotterLive = new SpotterLive($this->db);
903
+				$SpotterLive->deleteLiveSpotterDataNotUpdated();
904
+				$SpotterLive->db = null;
905
+				//SpotterLive->deleteLiveSpotterData();
906
+				if ($globalDebug) echo " Done\n";
907
+				$this->last_delete_hourly = time();
908 908
 			}
909 909
 			
910
-		    }
911
-		    //$ignoreImport = false;
910
+			}
911
+			//$ignoreImport = false;
912 912
 		}
913 913
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
914 914
 		if ($send) return $this->all_flights[$id];
915
-	    }
915
+		}
916
+	}
916 917
 	}
917
-    }
918 918
 }
919 919
 ?>
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	/**
83
-	* Executes the SQL statements to get the spotter information
84
-	*
85
-	* @param String $query the SQL query
86
-	* @param Array $params parameter of the query
87
-	* @param String $limitQuery the limit query
88
-	* @return Array the spotter information
89
-	*
90
-	*/
83
+	 * Executes the SQL statements to get the spotter information
84
+	 *
85
+	 * @param String $query the SQL query
86
+	 * @param Array $params parameter of the query
87
+	 * @param String $limitQuery the limit query
88
+	 * @return Array the spotter information
89
+	 *
90
+	 */
91 91
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	
200 200
 	
201 201
 	/**
202
-	* Gets all the spotter information based on the latest data entry
203
-	*
204
-	* @return Array the spotter information
205
-	*
206
-	*/
202
+	 * Gets all the spotter information based on the latest data entry
203
+	 *
204
+	 * @return Array the spotter information
205
+	 *
206
+	 */
207 207
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
208 208
 	{
209 209
 		global $global_query;
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	/**
264
-	* Gets all the spotter information based on the callsign
265
-	*
266
-	* @return Array the spotter information
267
-	*
268
-	*/
264
+	 * Gets all the spotter information based on the callsign
265
+	 *
266
+	 * @return Array the spotter information
267
+	 *
268
+	 */
269 269
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
270 270
 	{
271 271
 		global $global_query;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 
378 378
 	/**
379
-	* Gets all source name
380
-	*
381
-	* @param String type format of source
382
-	* @return Array list of source name
383
-	*
384
-	*/
379
+	 * Gets all source name
380
+	 *
381
+	 * @param String type format of source
382
+	 * @return Array list of source name
383
+	 *
384
+	 */
385 385
 	public function getAllSourceName($type = '',$filters = array())
386 386
 	{
387 387
 		$filter_query = $this->getFilter($filters,true,true);
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 	/**
414
-	* Gets a list of all idents/callsigns
415
-	*
416
-	* @return Array list of ident/callsign names
417
-	*
418
-	*/
414
+	 * Gets a list of all idents/callsigns
415
+	 *
416
+	 * @return Array list of ident/callsign names
417
+	 *
418
+	 */
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421 421
 		$filter_query = $this->getFilter($filters,true,true);
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 
441 441
 	/**
442
-	* Gets all info from a mmsi
443
-	*
444
-	* @return Array list of mmsi info
445
-	*
446
-	*/
442
+	 * Gets all info from a mmsi
443
+	 *
444
+	 * @return Array list of mmsi info
445
+	 *
446
+	 */
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449 449
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	
502 502
 	/**
503
-	* Update ident tracker data
504
-	*
505
-	* @param String $fammarine_id the ID
506
-	* @param String $ident the marine ident
507
-	* @return String success or false
508
-	*
509
-	*/	
503
+	 * Update ident tracker data
504
+	 *
505
+	 * @param String $fammarine_id the ID
506
+	 * @param String $ident the marine ident
507
+	 * @return String success or false
508
+	 *
509
+	 */	
510 510
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
 	}
526 526
 	/**
527
-	* Update latest marine data
528
-	*
529
-	* @param String $fammarine_id the ID
530
-	* @param String $ident the marine ident
531
-	* @return String success or false
532
-	*
533
-	*/	
527
+	 * Update latest marine data
528
+	 *
529
+	 * @param String $fammarine_id the ID
530
+	 * @param String $ident the marine ident
531
+	 * @return String success or false
532
+	 *
533
+	 */	
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+				$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -548,30 +548,30 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 
550 550
 	/**
551
-	* Adds a new spotter data
552
-	*
553
-	* @param String $fammarine_id the ID
554
-	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574
-	*/
551
+	 * Adds a new spotter data
552
+	 *
553
+	 * @param String $fammarine_id the ID
554
+	 * @param String $ident the marine ident
555
+	 * @param String $departure_airport_icao the departure airport
556
+	 * @param String $arrival_airport_icao the arrival airport
557
+	 * @param String $latitude latitude of flight
558
+	 * @param String $longitude latitude of flight
559
+	 * @param String $waypoints waypoints of flight
560
+	 * @param String $heading heading of flight
561
+	 * @param String $groundspeed speed of flight
562
+	 * @param String $date date of flight
563
+	 * @param String $departure_airport_time departure time of flight
564
+	 * @param String $arrival_airport_time arrival time of flight
565
+	 * @param String $squawk squawk code of flight
566
+	 * @param String $route_stop route stop of flight
567
+	 * @param String $highlight highlight or not
568
+	 * @param String $ModeS ModesS code of flight
569
+	 * @param String $registration registration code of flight
570
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
571
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
572
+	 * @param String $verticalrate vertival rate of flight
573
+	 * @return String success or false
574
+	 */
575 575
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660 660
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
661 661
 	
662
-                if ($latitude == '' && $longitude == '') {
663
-            		$latitude = 0;
664
-            		$longitude = 0;
665
-            	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
662
+				if ($latitude == '' && $longitude == '') {
663
+					$latitude = 0;
664
+					$longitude = 0;
665
+				}
666
+				if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
+				if ($arrival_date == '') $arrival_date = NULL;
669 669
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			$sth->execute($query_values);
677 677
 			$this->db = null;
678 678
 		} catch (PDOException $e) {
679
-		    return "error : ".$e->getMessage();
679
+			return "error : ".$e->getMessage();
680 680
 		}
681 681
 		
682 682
 		return "success";
@@ -685,11 +685,11 @@  discard block
 block discarded – undo
685 685
 	
686 686
   
687 687
 	/**
688
-	* Gets the aircraft ident within the last hour
689
-	*
690
-	* @return String the ident
691
-	*
692
-	*/
688
+	 * Gets the aircraft ident within the last hour
689
+	 *
690
+	 * @return String the ident
691
+	 *
692
+	 */
693 693
 	public function getIdentFromLastHour($ident)
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
@@ -705,11 +705,11 @@  discard block
 block discarded – undo
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
707 707
 			$query_data = array(':ident' => $ident);
708
-    		}
708
+			}
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
712
+			$ident_result='';
713 713
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	
721 721
 	
722 722
 	/**
723
-	* Gets the aircraft data from the last 20 seconds
724
-	*
725
-	* @return Array the spotter data
726
-	*
727
-	*/
723
+	 * Gets the aircraft data from the last 20 seconds
724
+	 *
725
+	 * @return Array the spotter data
726
+	 *
727
+	 */
728 728
 	public function getRealTimeData($q = '')
729 729
 	{
730 730
 		global $globalDBdriver;
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 	
763 763
 
764 764
 	/**
765
-	* Gets all number of flight over countries
766
-	*
767
-	* @return Array the airline country list
768
-	*
769
-	*/
765
+	 * Gets all number of flight over countries
766
+	 *
767
+	 * @return Array the airline country list
768
+	 *
769
+	 */
770 770
 /*
771 771
 	public function countAllTrackedOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
772 772
 	{
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	
818 818
 	
819 819
 	/**
820
-	* Gets all callsigns that have flown over
821
-	*
822
-	* @return Array the callsign list
823
-	*
824
-	*/
820
+	 * Gets all callsigns that have flown over
821
+	 *
822
+	 * @return Array the callsign list
823
+	 *
824
+	 */
825 825
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
@@ -888,11 +888,11 @@  discard block
 block discarded – undo
888 888
 
889 889
 
890 890
 	/**
891
-	* Counts all dates
892
-	*
893
-	* @return Array the date list
894
-	*
895
-	*/
891
+	 * Counts all dates
892
+	 *
893
+	 * @return Array the date list
894
+	 *
895
+	 */
896 896
 	public function countAllDates($filters = array())
897 897
 	{
898 898
 		global $globalTimezone, $globalDBdriver;
@@ -938,11 +938,11 @@  discard block
 block discarded – undo
938 938
 	
939 939
 	
940 940
 	/**
941
-	* Counts all dates during the last 7 days
942
-	*
943
-	* @return Array the date list
944
-	*
945
-	*/
941
+	 * Counts all dates during the last 7 days
942
+	 *
943
+	 * @return Array the date list
944
+	 *
945
+	 */
946 946
 	public function countAllDatesLast7Days($filters = array())
947 947
 	{
948 948
 		global $globalTimezone, $globalDBdriver;
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 			$query .= " GROUP BY date_name 
965 965
 								ORDER BY date_name ASC";
966 966
 			$query_data = array(':offset' => $offset);
967
-    		}
967
+			}
968 968
 		
969 969
 		$sth = $this->db->prepare($query);
970 970
 		$sth->execute($query_data);
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
 	}
985 985
 
986 986
 	/**
987
-	* Counts all dates during the last month
988
-	*
989
-	* @return Array the date list
990
-	*
991
-	*/
987
+	 * Counts all dates during the last month
988
+	 *
989
+	 * @return Array the date list
990
+	 *
991
+	 */
992 992
 	public function countAllDatesLastMonth($filters = array())
993 993
 	{
994 994
 		global $globalTimezone, $globalDBdriver;
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 			$query .= " GROUP BY date_name 
1011 1011
 								ORDER BY date_name ASC";
1012 1012
 			$query_data = array(':offset' => $offset);
1013
-    		}
1013
+			}
1014 1014
 		
1015 1015
 		$sth = $this->db->prepare($query);
1016 1016
 		$sth->execute($query_data);
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 
1034 1034
 	/**
1035
-	* Counts all month
1036
-	*
1037
-	* @return Array the month list
1038
-	*
1039
-	*/
1035
+	 * Counts all month
1036
+	 *
1037
+	 * @return Array the month list
1038
+	 *
1039
+	 */
1040 1040
 	public function countAllMonths($filters = array())
1041 1041
 	{
1042 1042
 		global $globalTimezone, $globalDBdriver;
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
 	
1082 1082
 
1083 1083
 	/**
1084
-	* Counts all dates during the last year
1085
-	*
1086
-	* @return Array the date list
1087
-	*
1088
-	*/
1084
+	 * Counts all dates during the last year
1085
+	 *
1086
+	 * @return Array the date list
1087
+	 *
1088
+	 */
1089 1089
 	public function countAllMonthsLastYear($filters)
1090 1090
 	{
1091 1091
 		global $globalTimezone, $globalDBdriver;
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			$query .= " GROUP BY year_name, month_name
1108 1108
 								ORDER BY year_name, month_name ASC";
1109 1109
 			$query_data = array(':offset' => $offset);
1110
-    		}
1110
+			}
1111 1111
 		
1112 1112
 		$sth = $this->db->prepare($query);
1113 1113
 		$sth->execute($query_data);
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 	
1131 1131
 	
1132 1132
 	/**
1133
-	* Counts all hours
1134
-	*
1135
-	* @return Array the hour list
1136
-	*
1137
-	*/
1133
+	 * Counts all hours
1134
+	 *
1135
+	 * @return Array the hour list
1136
+	 *
1137
+	 */
1138 1138
 	public function countAllHours($orderby,$filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
@@ -1197,11 +1197,11 @@  discard block
 block discarded – undo
1197 1197
 	
1198 1198
 	
1199 1199
 	/**
1200
-	* Counts all hours by date
1201
-	*
1202
-	* @return Array the hour list
1203
-	*
1204
-	*/
1200
+	 * Counts all hours by date
1201
+	 *
1202
+	 * @return Array the hour list
1203
+	 *
1204
+	 */
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
@@ -1245,11 +1245,11 @@  discard block
 block discarded – undo
1245 1245
 	
1246 1246
 	
1247 1247
 	/**
1248
-	* Counts all hours by a ident/callsign
1249
-	*
1250
-	* @return Array the hour list
1251
-	*
1252
-	*/
1248
+	 * Counts all hours by a ident/callsign
1249
+	 *
1250
+	 * @return Array the hour list
1251
+	 *
1252
+	 */
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
@@ -1294,11 +1294,11 @@  discard block
 block discarded – undo
1294 1294
 	
1295 1295
 	
1296 1296
 	/**
1297
-	* Counts all flights that have flown over
1298
-	*
1299
-	* @return Integer the number of flights
1300
-	*
1301
-	*/
1297
+	 * Counts all flights that have flown over
1298
+	 *
1299
+	 * @return Integer the number of flights
1300
+	 *
1301
+	 */
1302 1302
 	public function countOverallTracked($filters = array(),$year = '',$month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
@@ -1333,11 +1333,11 @@  discard block
 block discarded – undo
1333 1333
 	
1334 1334
   
1335 1335
 	/**
1336
-	* Counts all hours of today
1337
-	*
1338
-	* @return Array the hour list
1339
-	*
1340
-	*/
1336
+	 * Counts all hours of today
1337
+	 *
1338
+	 * @return Array the hour list
1339
+	 *
1340
+	 */
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
@@ -1377,12 +1377,12 @@  discard block
 block discarded – undo
1377 1377
 	}
1378 1378
     
1379 1379
     
1380
-     /**
1381
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1382
-	*
1383
-	* @return Integer the Barrie Spotter ID
1380
+	 /**
1381
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1382
+	  *
1383
+	  * @return Integer the Barrie Spotter ID
1384 1384
 q	*
1385
-	*/
1385
+	  */
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388 1388
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1403,13 +1403,13 @@  discard block
 block discarded – undo
1403 1403
   
1404 1404
  
1405 1405
 	/**
1406
-	* Parses a date string
1407
-	*
1408
-	* @param String $dateString the date string
1409
-	* @param String $timezone the timezone of a user
1410
-	* @return Array the time information
1411
-	*
1412
-	*/
1406
+	 * Parses a date string
1407
+	 *
1408
+	 * @param String $dateString the date string
1409
+	 * @param String $timezone the timezone of a user
1410
+	 * @return Array the time information
1411
+	 *
1412
+	 */
1413 1413
 	public function parseDateString($dateString, $timezone = '')
1414 1414
 	{
1415 1415
 		$time_array = array();
@@ -1442,12 +1442,12 @@  discard block
 block discarded – undo
1442 1442
 	}
1443 1443
 	
1444 1444
 	/**
1445
-	* Parses the direction degrees to working
1446
-	*
1447
-	* @param Float $direction the direction in degrees
1448
-	* @return Array the direction information
1449
-	*
1450
-	*/
1445
+	 * Parses the direction degrees to working
1446
+	 *
1447
+	 * @param Float $direction the direction in degrees
1448
+	 * @return Array the direction information
1449
+	 *
1450
+	 */
1451 1451
 	public function parseDirection($direction = 0)
1452 1452
 	{
1453 1453
 		if ($direction == '') $direction = 0;
@@ -1526,12 +1526,12 @@  discard block
 block discarded – undo
1526 1526
 	
1527 1527
 	
1528 1528
 	/**
1529
-	* Gets Country from latitude/longitude
1530
-	*
1531
-	* @param Float $latitude latitute of the flight
1532
-	* @param Float $longitude longitute of the flight
1533
-	* @return String the countrie
1534
-	*/
1529
+	 * Gets Country from latitude/longitude
1530
+	 *
1531
+	 * @param Float $latitude latitute of the flight
1532
+	 * @param Float $longitude longitute of the flight
1533
+	 * @return String the countrie
1534
+	 */
1535 1535
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
@@ -1568,11 +1568,11 @@  discard block
 block discarded – undo
1568 1568
 	}
1569 1569
 
1570 1570
 	/**
1571
-	* Gets Country from iso2
1572
-	*
1573
-	* @param String $iso2 ISO2 country code
1574
-	* @return String the countrie
1575
-	*/
1571
+	 * Gets Country from iso2
1572
+	 *
1573
+	 * @param String $iso2 ISO2 country code
1574
+	 * @return String the countrie
1575
+	 */
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
@@ -1601,12 +1601,12 @@  discard block
 block discarded – undo
1601 1601
 
1602 1602
 	
1603 1603
 	/**
1604
-	* Gets the short url from bit.ly
1605
-	*
1606
-	* @param String $url the full url
1607
-	* @return String the bit.ly url
1608
-	*
1609
-	*/
1604
+	 * Gets the short url from bit.ly
1605
+	 *
1606
+	 * @param String $url the full url
1607
+	 * @return String the bit.ly url
1608
+	 *
1609
+	 */
1610 1610
 	public function getBitlyURL($url)
1611 1611
 	{
1612 1612
 		global $globalBitlyAccessToken;
Please login to merge, or discard this patch.
require/class.APRS.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
5
+	private $socket;
6 6
 
7
-    protected $symbols = array('!' => 'Police',
7
+	protected $symbols = array('!' => 'Police',
8 8
 	'#' => 'DIGI',
9 9
 	'$' => 'Phone',
10 10
 	'%' => 'DX Cluster',
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 	'y' => 'Yagi At QTH');
89 89
 	
90 90
 
91
-    private function urshift($n, $s) {
91
+	private function urshift($n, $s) {
92 92
 	return ($n >= 0) ? ($n >> $s) :
93
-	    (($n & 0x7fffffff) >> $s) | 
93
+		(($n & 0x7fffffff) >> $s) | 
94 94
 		(0x40000000 >> ($s - 1));
95
-    }
95
+	}
96 96
 
97
-    public function parse($input) {
97
+	public function parse($input) {
98 98
 	global $globalDebug;
99 99
 	$debug = false;
100 100
 	$result = array();
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	
107 107
 	/* Check that end was found and body has at least one byte. */
108 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
109
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
-	    return false;
109
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+		return false;
111 111
 	}
112 112
 	
113 113
 	if ($debug) echo 'input : '.$input."\n";
@@ -121,23 +121,23 @@  discard block
 block discarded – undo
121 121
 	/* Parse source, target and path. */
122 122
 	//FLRDF0A52>APRS,qAS,LSTB
123 123
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
124
-	    $ident = $matches[1];
125
-	    $all_elements = $matches[2];
126
-	    if ($debug) echo 'ident : '.$ident."\n";
127
-	    $result['ident'] = $ident;
124
+		$ident = $matches[1];
125
+		$all_elements = $matches[2];
126
+		if ($debug) echo 'ident : '.$ident."\n";
127
+		$result['ident'] = $ident;
128 128
 	} else return false;
129 129
 	$elements = explode(',',$all_elements);
130 130
 	$source = end($elements);
131 131
 	$result['source'] = $source;
132 132
 	foreach ($elements as $element) {
133
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
134
-	        //echo "ok";
135
-	        //if ($element == 'TCPIP*') return false;
136
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
133
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
134
+			//echo "ok";
135
+			//if ($element == 'TCPIP*') return false;
136
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
137 137
 		if ($debug) echo 'element : '.$element."\n";
138 138
 		return false;
139
-	    }
140
-	    /*
139
+		}
140
+		/*
141 141
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
142 142
 		//echo "ok";
143 143
 	    } else {
@@ -160,49 +160,49 @@  discard block
 block discarded – undo
160 160
 	$body_parse = substr($body,1);
161 161
 	//echo 'Body : '.$body."\n";
162 162
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
163
-	    $body_parse = substr($body_parse,10);
164
-	    $find = true;
165
-	    //echo $body_parse."\n";
163
+		$body_parse = substr($body_parse,10);
164
+		$find = true;
165
+		//echo $body_parse."\n";
166 166
 	}
167 167
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
168
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
169
-	    $find = true;
170
-	    //echo $body_parse."\n";
168
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
169
+		$find = true;
170
+		//echo $body_parse."\n";
171 171
 	}
172 172
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
173
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
174
-	    $find = true;
175
-	    //echo $body_parse."\n";
173
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
174
+		$find = true;
175
+		//echo $body_parse."\n";
176 176
 	}
177 177
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
178
-	    $find = true;
179
-	    //print_r($matches);
180
-	    $timestamp = $matches[0];
181
-	    if ($matches[4] == 'h') {
178
+		$find = true;
179
+		//print_r($matches);
180
+		$timestamp = $matches[0];
181
+		if ($matches[4] == 'h') {
182 182
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
183 183
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
184 184
 		/*
185 185
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
186 186
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
187 187
 		*/
188
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
188
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
189 189
 		// This work or not ?
190 190
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
191
-	    }
192
-	    $body_parse = substr($body_parse,7);
193
-	    $result['timestamp'] = $timestamp;
194
-	    //echo date('Ymd H:i:s',$timestamp);
191
+		}
192
+		$body_parse = substr($body_parse,7);
193
+		$result['timestamp'] = $timestamp;
194
+		//echo date('Ymd H:i:s',$timestamp);
195 195
 	}
196 196
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
197
-	    $find = true;
198
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
-	    $body_parse = substr($body_parse,8);
200
-	    $result['timestamp'] = $timestamp;
201
-	    //echo date('Ymd H:i:s',$timestamp);
197
+		$find = true;
198
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
199
+		$body_parse = substr($body_parse,8);
200
+		$result['timestamp'] = $timestamp;
201
+		//echo date('Ymd H:i:s',$timestamp);
202 202
 	}
203 203
 	//if (strlen($body_parse) > 19) {
204
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
205
-	    $find = true;
204
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
205
+		$find = true;
206 206
 		// 4658.70N/00707.78Ez
207 207
 		//print_r(str_split($body_parse));
208 208
 		
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		$lon = intval($lon_deg);
220 220
 		if ($lat > 89 || $lon > 179) return false;
221 221
 	    
222
-	    /*
222
+		/*
223 223
 	    $tmp_5b = str_replace('.','',$lat_min);
224 224
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
225 225
 	        print_r($matches);
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 		$result['longitude'] = $longitude;
234 234
 		$body_parse = substr($body_parse,18);
235 235
 		$body_parse_len = strlen($body_parse);
236
-	    }
237
-	    $body_parse_len = strlen($body_parse);
238
-	    if ($body_parse_len > 0) {
236
+		}
237
+		$body_parse_len = strlen($body_parse);
238
+		if ($body_parse_len > 0) {
239 239
 		/*
240 240
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
241 241
 			$body_split = str_split($body);
@@ -264,73 +264,73 @@  discard block
 block discarded – undo
264 264
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
265 265
 			if ($symbol_code != '_') {
266 266
 			}
267
-		    //$body_parse = substr($body_parse,1);
268
-		    //$body_parse = trim($body_parse);
269
-		    //$body_parse_len = strlen($body_parse);
270
-		    if ($body_parse_len >= 7) {
267
+			//$body_parse = substr($body_parse,1);
268
+			//$body_parse = trim($body_parse);
269
+			//$body_parse_len = strlen($body_parse);
270
+			if ($body_parse_len >= 7) {
271 271
 			
272
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
-		    	    $course = substr($body_parse,0,3);
274
-		    	    $tmp_s = intval($course);
275
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
-		    	    $speed = substr($body_parse,4,3);
277
-		    	    if ($speed != '...') {
278
-		    		    $result['speed'] = round($speed*1.852);
279
-		    	    }
280
-		    	    $body_parse = substr($body_parse,7);
281
-		        }
282
-		        // Check PHGR, PHG, RNG
283
-		    } 
284
-		    /*
272
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
273
+					$course = substr($body_parse,0,3);
274
+					$tmp_s = intval($course);
275
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
276
+					$speed = substr($body_parse,4,3);
277
+					if ($speed != '...') {
278
+						$result['speed'] = round($speed*1.852);
279
+					}
280
+					$body_parse = substr($body_parse,7);
281
+				}
282
+				// Check PHGR, PHG, RNG
283
+			} 
284
+			/*
285 285
 		    else if ($body_parse_len > 0) {
286 286
 			$rest = $body_parse;
287 287
 		    }
288 288
 		    */
289
-		    if (strlen($body_parse) > 0) {
290
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
291
-		            $altitude = intval($matches[1]);
292
-		            //$result['altitude'] = round($altitude*0.3048);
293
-		            $result['altitude'] = $altitude;
294
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
296
-		        }
297
-		    }
289
+			if (strlen($body_parse) > 0) {
290
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
291
+					$altitude = intval($matches[1]);
292
+					//$result['altitude'] = round($altitude*0.3048);
293
+					$result['altitude'] = $altitude;
294
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
295
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
296
+				}
297
+			}
298 298
 		    
299
-		    // Telemetry
300
-		    /*
299
+			// Telemetry
300
+			/*
301 301
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
302 302
 		        // Nothing yet...
303 303
 		    }
304 304
 		    */
305
-		    // DAO
306
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
307
-			    $dao = $matches[1];
308
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
305
+			// DAO
306
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
307
+				$dao = $matches[1];
308
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
309 309
 				$dao_split = str_split($dao);
310
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
310
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
311
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
312 312
 			    
313 313
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
314 314
 				else $result['latitude'] += $lat_off;
315 315
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
316 316
 				else $result['longitude'] += $lon_off;
317
-			    }
318
-		            $body_parse = substr($body_parse,6);
319
-		    }
317
+				}
318
+					$body_parse = substr($body_parse,6);
319
+			}
320 320
 		    
321
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
321
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
322 322
 			$result['callsign'] = $matches[1];
323
-		    }
324
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
323
+			}
324
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
325 325
 			$result['squawk'] = $matches[1];
326
-		    }
327
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
326
+			}
327
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
328 328
 			$result['aircraft_icao'] = $matches[1];
329
-		    }
330
-		    // OGN comment
329
+			}
330
+			// OGN comment
331 331
 		   // echo "Before OGN : ".$body_parse."\n";
332
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
332
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
333
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
334 334
 			$id = $matches[1];
335 335
 			//$mode = substr($id,0,2);
336 336
 			$address = substr($id,2);
@@ -360,53 +360,53 @@  discard block
 block discarded – undo
360 360
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
361 361
 			$result['stealth'] = $stealth;
362 362
 			$result['address'] = $address;
363
-		    }
363
+			}
364 364
 		    
365
-		    //Comment
366
-		    $result['comment'] = trim($body_parse);
365
+			//Comment
366
+			$result['comment'] = trim($body_parse);
367 367
 		} else {
368
-		    // parse weather
369
-		    //$body_parse = substr($body_parse,1);
370
-		    //$body_parse_len = strlen($body_parse);
368
+			// parse weather
369
+			//$body_parse = substr($body_parse,1);
370
+			//$body_parse_len = strlen($body_parse);
371 371
 
372
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
-			    $result['wind_dir'] = intval($matches[1]);
374
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
378
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
372
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
373
+				$result['wind_dir'] = intval($matches[1]);
374
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
375
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
376
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
377
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
378
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
379 379
 			$result['wind_dir'] = intval($matches[1]);
380 380
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
381 381
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
382 382
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
383
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
384
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
383
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
384
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
385 385
 			$result['wind_dir'] = intval($matches[1]);
386 386
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
387 387
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
388
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
389
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
388
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
389
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
390 390
 			$result['wind_dir'] = intval($matches[1]);
391 391
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
392 392
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
393
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
394
-		    }
395
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
393
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
394
+			}
395
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
396 396
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
397
-		    }
397
+			}
398 398
 		}
399 399
 		} else $result['comment'] = trim($body_parse);
400 400
 
401
-	    }
401
+		}
402 402
 	//}
403 403
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
404 404
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
405 405
 	if ($debug) print_r($result);
406 406
 	return $result;
407
-    }
407
+	}
408 408
     
409
-    function connect() {
409
+	function connect() {
410 410
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
411 411
 	$aprs_connect = 0;
412 412
 	$aprs_keep = 120;
@@ -430,22 +430,22 @@  discard block
 block discarded – undo
430 430
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
431 431
 			echo $msgin."\n";
432 432
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
433
-			    echo 'Verified !';
434
-			    return true;
435
-			    break;
433
+				echo 'Verified !';
434
+				return true;
435
+				break;
436 436
 			}
437 437
 			if (time()-$authstart > 5) {
438
-			    echo 'Timeout';
439
-			    break;
438
+				echo 'Timeout';
439
+				break;
440 440
 			}
441 441
 		}
442 442
 	}
443
-    }
443
+	}
444 444
     
445
-    function send($data) {
445
+	function send($data) {
446 446
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
447 447
 	if ($send === FALSE) $this->connect();
448
-    }
448
+	}
449 449
 }
450 450
 
451 451
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Indentation   +839 added lines, -839 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,47 +24,47 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['server'])) $globalServer = TRUE;
63 63
 if (isset($options['idsource'])) $id_source = $options['idsource'];
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
66
+	if ($globalDebug) echo "Using Server Mode\n";
67
+	$SI=new SpotterServer();
68 68
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 } else $SI=new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76
-    $AIS = new AIS();
77
-    $MI = new MarineImport($Connection->db);
76
+	$AIS = new AIS();
77
+	$MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80 80
 $SBS=new SBS();
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
88
-        global $sockets;
89
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
-        die("Bye!\n");
91
-    });
92
-    pcntl_signal_dispatch();
87
+	pcntl_signal(SIGINT,  function() {
88
+		global $sockets;
89
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
+		die("Bye!\n");
91
+	});
92
+	pcntl_signal_dispatch();
93 93
 }
94 94
 
95 95
 // let's try and connect
@@ -99,151 +99,151 @@  discard block
 block discarded – undo
99 99
 $reset = 0;
100 100
 
101 101
 function connect_all($hosts) {
102
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
-    $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
106
-    foreach ($hosts as $id => $value) {
102
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+	$reset++;
105
+	if ($globalDebug) echo 'Connect to all...'."\n";
106
+	foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110 110
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
112
-        	//$formats[$id] = 'deltadbtxt';
113
-        	$globalSources[$id]['format'] = 'deltadbtxt';
114
-        	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
-        	//$formats[$id] = 'vatsimtxt';
118
-        	$globalSources[$id]['format'] = 'vatsimtxt';
119
-        	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
-        	//$formats[$id] = 'aircraftlistjson';
123
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
124
-        	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
127
-        	//$formats[$id] = 'aircraftlistjson';
128
-        	$globalSources[$id]['format'] = 'opensky';
129
-        	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
-        	//$formats[$id] = 'radarvirtueljson';
133
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
134
-        	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
-        	    exit(0);
139
-        	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
-        	//$formats[$id] = 'planeupdatefaa';
142
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
143
-        	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
-        	    exit(0);
148
-        	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
-        	//$formats[$id] = 'phpvmacars';
151
-        	$globalSources[$id]['format'] = 'phpvmacars';
152
-        	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
-        	//$formats[$id] = 'phpvmacars';
156
-        	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
159
-        	//$formats[$id] = 'whazzup';
160
-        	$globalSources[$id]['format'] = 'whazzup';
161
-        	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
164
-        	//$formats[$id] = 'pirepsjson';
165
-        	$globalSources[$id]['format'] = 'pirepsjson';
166
-        	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
-        	//$formats[$id] = 'fr24json';
170
-        	$globalSources[$id]['format'] = 'fr24json';
171
-        	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
-        	    exit(0);
176
-        	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
-        	//$formats[$id] = 'fr24json';
179
-        	$globalSources[$id]['format'] = 'myshiptracking';
180
-        	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
-        	    exit(0);
185
-        	}
186
-            //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
-        	//$formats[$id] = 'tsv';
189
-        	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
-            }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
-    		    if ($idf !== false) {
196
-    			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-    		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
203
-	    if (isset($hostport[1])) {
111
+			if (preg_match('/deltadb.txt$/i',$host)) {
112
+			//$formats[$id] = 'deltadbtxt';
113
+			$globalSources[$id]['format'] = 'deltadbtxt';
114
+			//$last_exec['deltadbtxt'] = 0;
115
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+			//$formats[$id] = 'vatsimtxt';
118
+			$globalSources[$id]['format'] = 'vatsimtxt';
119
+			//$last_exec['vatsimtxt'] = 0;
120
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+			//$formats[$id] = 'aircraftlistjson';
123
+			$globalSources[$id]['format'] = 'aircraftlistjson';
124
+			//$last_exec['aircraftlistjson'] = 0;
125
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
+			} else if (preg_match('/opensky/i',$host)) {
127
+			//$formats[$id] = 'aircraftlistjson';
128
+			$globalSources[$id]['format'] = 'opensky';
129
+			//$last_exec['aircraftlistjson'] = 0;
130
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+			//$formats[$id] = 'radarvirtueljson';
133
+			$globalSources[$id]['format'] = 'radarvirtueljson';
134
+			//$last_exec['radarvirtueljson'] = 0;
135
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
+				exit(0);
139
+			}
140
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+			//$formats[$id] = 'planeupdatefaa';
142
+			$globalSources[$id]['format'] = 'planeupdatefaa';
143
+			//$last_exec['planeupdatefaa'] = 0;
144
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
+				exit(0);
148
+			}
149
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+			//$formats[$id] = 'phpvmacars';
151
+			$globalSources[$id]['format'] = 'phpvmacars';
152
+			//$last_exec['phpvmacars'] = 0;
153
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
155
+			//$formats[$id] = 'phpvmacars';
156
+			$globalSources[$id]['format'] = 'vam';
157
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
+			} else if (preg_match('/whazzup/i',$host)) {
159
+			//$formats[$id] = 'whazzup';
160
+			$globalSources[$id]['format'] = 'whazzup';
161
+			//$last_exec['whazzup'] = 0;
162
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
+			} else if (preg_match('/recentpireps/i',$host)) {
164
+			//$formats[$id] = 'pirepsjson';
165
+			$globalSources[$id]['format'] = 'pirepsjson';
166
+			//$last_exec['pirepsjson'] = 0;
167
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+			//$formats[$id] = 'fr24json';
170
+			$globalSources[$id]['format'] = 'fr24json';
171
+			//$last_exec['fr24json'] = 0;
172
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
+				exit(0);
176
+			}
177
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+			//$formats[$id] = 'fr24json';
179
+			$globalSources[$id]['format'] = 'myshiptracking';
180
+			//$last_exec['fr24json'] = 0;
181
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
+				exit(0);
185
+			}
186
+			//} else if (preg_match('/10001/',$host)) {
187
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+			//$formats[$id] = 'tsv';
189
+			$globalSources[$id]['format'] = 'tsv';
190
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
+			}
192
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+				if ($idf !== false) {
196
+				$httpfeeds[$id] = $idf;
197
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+				}
199
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
+		$hostport = explode(':',$host);
203
+		if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
206
-	    } else {
206
+		} else {
207 207
 		$port = $globalSources[$id]['port'];
208 208
 		$hostn = $globalSources[$id]['host'];
209
-	    }
210
-	    $Common = new Common();
211
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
-    	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
-	    }
216
-	    if ($s) {
217
-    	        $sockets[$id] = $s;
218
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
209
+		}
210
+		$Common = new Common();
211
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+			} else {
214
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+		}
216
+		if ($s) {
217
+				$sockets[$id] = $s;
218
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
223 223
 			//$use_aprs = true;
224
-    		    } elseif ($port == '10001') {
225
-        		//$formats[$id] = 'tsv';
226
-        		$globalSources[$id]['format'] = 'tsv';
227
-		    } elseif ($port == '30002') {
228
-        		//$formats[$id] = 'raw';
229
-        		$globalSources[$id]['format'] = 'raw';
230
-		    } elseif ($port == '5001') {
231
-        		//$formats[$id] = 'raw';
232
-        		$globalSources[$id]['format'] = 'flightgearmp';
233
-		    } elseif ($port == '30005') {
224
+				} elseif ($port == '10001') {
225
+				//$formats[$id] = 'tsv';
226
+				$globalSources[$id]['format'] = 'tsv';
227
+			} elseif ($port == '30002') {
228
+				//$formats[$id] = 'raw';
229
+				$globalSources[$id]['format'] = 'raw';
230
+			} elseif ($port == '5001') {
231
+				//$formats[$id] = 'raw';
232
+				$globalSources[$id]['format'] = 'flightgearmp';
233
+			} elseif ($port == '30005') {
234 234
 			// Not yet supported
235
-        		//$formats[$id] = 'beast';
236
-        		$globalSources[$id]['format'] = 'beast';
237
-		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
239
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
235
+				//$formats[$id] = 'beast';
236
+				$globalSources[$id]['format'] = 'beast';
237
+			//} else $formats[$id] = 'sbs';
238
+			} else $globalSources[$id]['format'] = 'sbs';
239
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 240
 		}
241 241
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
242
-            } else {
242
+			} else {
243 243
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
244
-    	    }
245
-        }
246
-    }
244
+			}
245
+		}
246
+	}
247 247
 }
248 248
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
249 249
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
270 270
 } else {
271
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
271
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
273 273
 
274 274
 // APRS Configuration
@@ -277,18 +277,18 @@  discard block
 block discarded – undo
277 277
 	die;
278 278
 }
279 279
 foreach ($globalSources as $key => $source) {
280
-    if (!isset($source['format'])) {
281
-        $globalSources[$key]['format'] = 'auto';
282
-    }
280
+	if (!isset($source['format'])) {
281
+		$globalSources[$key]['format'] = 'auto';
282
+	}
283 283
 }
284 284
 connect_all($globalSources);
285 285
 foreach ($globalSources as $key => $source) {
286
-    if (isset($source['format']) && $source['format'] == 'aprs') {
286
+	if (isset($source['format']) && $source['format'] == 'aprs') {
287 287
 	$aprs_connect = 0;
288 288
 	$use_aprs = true;
289 289
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
290 290
 	break;
291
-    }
291
+	}
292 292
 }
293 293
 
294 294
 if ($use_aprs) {
@@ -329,152 +329,152 @@  discard block
 block discarded – undo
329 329
 
330 330
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
331 331
 while ($i > 0) {
332
-    if (!$globalDaemon) $i = $endtime-time();
333
-    // Delete old ATC
334
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
332
+	if (!$globalDaemon) $i = $endtime-time();
333
+	// Delete old ATC
334
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
335 335
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
336
-        $ATC->deleteOldATC();
337
-    }
336
+		$ATC->deleteOldATC();
337
+	}
338 338
     
339
-    //if (count($last_exec) > 0) {
340
-    if (count($last_exec) == count($globalSources)) {
339
+	//if (count($last_exec) > 0) {
340
+	if (count($last_exec) == count($globalSources)) {
341 341
 	$max = $globalMinFetch;
342 342
 	foreach ($last_exec as $last) {
343
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
343
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
344 344
 	}
345 345
 	if ($max != $globalMinFetch) {
346
-	    if ($globalDebug) echo 'Sleeping...'."\n";
347
-	    sleep($globalMinFetch-$max+2);
346
+		if ($globalDebug) echo 'Sleeping...'."\n";
347
+		sleep($globalMinFetch-$max+2);
348
+	}
348 349
 	}
349
-    }
350 350
 
351 351
     
352
-    //foreach ($formats as $id => $value) {
353
-    foreach ($globalSources as $id => $value) {
352
+	//foreach ($formats as $id => $value) {
353
+	foreach ($globalSources as $id => $value) {
354 354
 	date_default_timezone_set('UTC');
355 355
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
356 356
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
357
-	    //$buffer = $Common->getData($hosts[$id]);
358
-	    $buffer = $Common->getData($value['host']);
359
-	    if ($buffer != '') $reset = 0;
360
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361
-	    $buffer = explode('\n',$buffer);
362
-	    foreach ($buffer as $line) {
363
-    		if ($line != '' && count($line) > 7) {
364
-    		    $line = explode(',', $line);
365
-	            $data = array();
366
-	            $data['hex'] = $line[1]; // hex
367
-	            $data['ident'] = $line[2]; // ident
368
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
373
-	            $data['verticalrate'] = ''; // vertical rate
374
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375
-	            $data['emergency'] = ''; // emergency
376
-		    $data['datetime'] = date('Y-m-d H:i:s');
377
-		    $data['format_source'] = 'deltadbtxt';
378
-    		    $data['id_source'] = $id_source;
379
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
381
-    		    $SI->add($data);
382
-		    unset($data);
383
-    		}
384
-    	    }
385
-    	    $last_exec[$id]['last'] = time();
357
+		//$buffer = $Common->getData($hosts[$id]);
358
+		$buffer = $Common->getData($value['host']);
359
+		if ($buffer != '') $reset = 0;
360
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
361
+		$buffer = explode('\n',$buffer);
362
+		foreach ($buffer as $line) {
363
+			if ($line != '' && count($line) > 7) {
364
+				$line = explode(',', $line);
365
+				$data = array();
366
+				$data['hex'] = $line[1]; // hex
367
+				$data['ident'] = $line[2]; // ident
368
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
369
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
370
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
371
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
372
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
373
+				$data['verticalrate'] = ''; // vertical rate
374
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
375
+				$data['emergency'] = ''; // emergency
376
+			$data['datetime'] = date('Y-m-d H:i:s');
377
+			$data['format_source'] = 'deltadbtxt';
378
+				$data['id_source'] = $id_source;
379
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
380
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
381
+				$SI->add($data);
382
+			unset($data);
383
+			}
384
+			}
385
+			$last_exec[$id]['last'] = time();
386 386
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
387
-	    date_default_timezone_set('CET');
388
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389
-	    date_default_timezone_set('UTC');
390
-	    if ($buffer != '') $reset = 0;
391
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392
-	    $buffer = explode('\n',$buffer);
393
-	    foreach ($buffer as $line) {
387
+		date_default_timezone_set('CET');
388
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389
+		date_default_timezone_set('UTC');
390
+		if ($buffer != '') $reset = 0;
391
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
392
+		$buffer = explode('\n',$buffer);
393
+		foreach ($buffer as $line) {
394 394
 		if ($line != '') {
395
-		    echo "'".$line."'\n";
396
-		    $add = false;
397
-		    $ais_data = $AIS->parse_line(trim($line));
398
-		    $data = array();
399
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
409
-		    if (isset($ais_data['timestamp'])) {
395
+			echo "'".$line."'\n";
396
+			$add = false;
397
+			$ais_data = $AIS->parse_line(trim($line));
398
+			$data = array();
399
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
400
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
401
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
402
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
403
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
404
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
405
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
406
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
407
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
408
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
409
+			if (isset($ais_data['timestamp'])) {
410 410
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
411 411
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
412
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
413
-			    $add = true;
412
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
413
+				$add = true;
414 414
 			}
415
-		    } else {
415
+			} else {
416 416
 			$data['datetime'] = date('Y-m-d H:i:s');
417 417
 			$add = true;
418
-		    }
419
-		    $data['format_source'] = 'aisnmeatxt';
420
-    		    $data['id_source'] = $id_source;
421
-		    print_r($data);
422
-		    echo 'Add...'."\n";
423
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
424
-		    unset($data);
418
+			}
419
+			$data['format_source'] = 'aisnmeatxt';
420
+				$data['id_source'] = $id_source;
421
+			print_r($data);
422
+			echo 'Add...'."\n";
423
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
424
+			unset($data);
425 425
 		}
426
-    	    }
427
-    	    $last_exec[$id]['last'] = time();
426
+			}
427
+			$last_exec[$id]['last'] = time();
428 428
 	} elseif ($value['format'] == 'aisnmeahttp') {
429
-	    $arr = $httpfeeds;
430
-	    $w = $e = null;
429
+		$arr = $httpfeeds;
430
+		$w = $e = null;
431 431
 	    
432
-	    if (isset($arr[$id])) {
433
-	    $nn = stream_select($arr,$w,$e,$timeout);
434
-	    if ($nn > 0) {
432
+		if (isset($arr[$id])) {
433
+		$nn = stream_select($arr,$w,$e,$timeout);
434
+		if ($nn > 0) {
435 435
 		foreach ($httpfeeds as $feed) {
436
-		    $buffer = stream_get_line($feed,2000,"\n");
437
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
438
-		    $buffer = explode('\n',$buffer);
439
-		    foreach ($buffer as $line) {
436
+			$buffer = stream_get_line($feed,2000,"\n");
437
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
438
+			$buffer = explode('\n',$buffer);
439
+			foreach ($buffer as $line) {
440 440
 			if ($line != '') {
441
-			    $ais_data = $AIS->parse_line(trim($line));
442
-			    $data = array();
443
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
455
-			    if (isset($ais_data['timestamp'])) {
441
+				$ais_data = $AIS->parse_line(trim($line));
442
+				$data = array();
443
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
444
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
445
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
446
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
447
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
448
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
449
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
450
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
451
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
452
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
453
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
454
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
455
+				if (isset($ais_data['timestamp'])) {
456 456
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
457
-			    } else {
457
+				} else {
458 458
 				$data['datetime'] = date('Y-m-d H:i:s');
459
-			    }
460
-			    $data['format_source'] = 'aisnmeahttp';
461
-			    $data['id_source'] = $id_source;
462
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
463
-			    unset($data);
459
+				}
460
+				$data['format_source'] = 'aisnmeahttp';
461
+				$data['id_source'] = $id_source;
462
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
463
+				unset($data);
464
+			}
464 465
 			}
465
-		    }
466 466
 		}
467 467
 		}
468
-	    }
468
+		}
469 469
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
470
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
471
-	    if ($buffer != '') {
470
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
471
+		if ($buffer != '') {
472 472
 		//echo $buffer;
473 473
 		$all_data = json_decode($buffer,true);
474 474
 		//print_r($all_data);
475 475
 		if (isset($all_data[0]['DATA'])) {
476 476
 		foreach ($all_data[0]['DATA'] as $line) {
477
-		    if ($line != '') {
477
+			if ($line != '') {
478 478
 			$data = array();
479 479
 			$data['ident'] = $line['NAME'];
480 480
 			$data['mmsi'] = $line['MMSI'];
@@ -490,23 +490,23 @@  discard block
 block discarded – undo
490 490
 			$data['id_source'] = $id_source;
491 491
 			$MI->add($data);
492 492
 			unset($data);
493
-		    }
493
+			}
494 494
 		}
495 495
 		}
496 496
 		
497
-	    }
498
-    	    $last_exec[$id]['last'] = time();
497
+		}
498
+			$last_exec[$id]['last'] = time();
499 499
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
500
-	    echo 'Try ?'."\n";
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
-	    echo $buffer;
503
-	    if ($buffer != '') {
500
+		echo 'Try ?'."\n";
501
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
+		echo $buffer;
503
+		if ($buffer != '') {
504 504
 		//echo $buffer;
505 505
 		$all_data = json_decode($buffer,true);
506 506
 		print_r($all_data);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508 508
 		foreach ($all_data as $line) {
509
-		    if ($line != '') {
509
+			if ($line != '') {
510 510
 			$data = array();
511 511
 			$data['ident'] = $line['shipname'];
512 512
 			$data['callsign'] = $line['callsign'];
@@ -522,59 +522,59 @@  discard block
 block discarded – undo
522 522
 			$data['id_source'] = $id_source;
523 523
 			$MI->add($data);
524 524
 			unset($data);
525
-		    }
525
+			}
526 526
 		}
527 527
 		}
528 528
 		
529
-	    }
530
-    	    $last_exec[$id]['last'] = time();
529
+		}
530
+			$last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532
-	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
-	    echo 'done !'."\n";
535
-	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
538
-	    foreach ($buffer as $line) {
532
+		echo 'download...';
533
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
534
+		echo 'done !'."\n";
535
+		if ($buffer != '') $reset = 0;
536
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
+		$buffer = explode('\n',$buffer);
538
+		foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540
-		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
-		    //$data['status'] = substr($line,21,2);
544
-		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
548
-		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
550
-		    //$data['draft'] = substr($line,67,4);
551
-		    //$data['length'] = substr($line,72,3);
552
-		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
-		    //$data['callsign'] = trim(substr($line,100,7);
555
-		    //$data['dest'] = substr($line,108,20);
556
-		    //$data['etaDate'] = substr($line,129,5);
557
-		    //$data['etaTime'] = substr($line,135,5);
558
-		    $data['format_source'] = 'shipplotter';
559
-    		    $data['id_source'] = $id_source;
560
-		    print_r($data);
561
-		    echo 'Add...'."\n";
562
-		    $MI->add($data);
563
-		    unset($data);
540
+			$data = array();
541
+			$data['mmsi'] = (int)substr($line,0,9);
542
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
543
+			//$data['status'] = substr($line,21,2);
544
+			//$data['type'] = substr($line,24,3);
545
+			$data['latitude'] = substr($line,29,9);
546
+			$data['longitude'] = substr($line,41,9);
547
+			$data['speed'] = round(substr($line,51,5));
548
+			//$data['course'] = substr($line,57,5);
549
+			$data['heading'] = round(substr($line,63,3));
550
+			//$data['draft'] = substr($line,67,4);
551
+			//$data['length'] = substr($line,72,3);
552
+			//$data['beam'] = substr($line,76,2);
553
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
554
+			//$data['callsign'] = trim(substr($line,100,7);
555
+			//$data['dest'] = substr($line,108,20);
556
+			//$data['etaDate'] = substr($line,129,5);
557
+			//$data['etaTime'] = substr($line,135,5);
558
+			$data['format_source'] = 'shipplotter';
559
+				$data['id_source'] = $id_source;
560
+			print_r($data);
561
+			echo 'Add...'."\n";
562
+			$MI->add($data);
563
+			unset($data);
564 564
 		}
565
-    	    }
566
-    	    $last_exec[$id]['last'] = time();
565
+			}
566
+			$last_exec[$id]['last'] = time();
567 567
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569
-	    //$buffer = $Common->getData($hosts[$id]);
570
-	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
573
-	    $reset = 0;
574
-	    foreach ($buffer as $line) {
575
-    		if ($line != '') {
576
-    		    $line = explode(':', $line);
577
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
569
+		//$buffer = $Common->getData($hosts[$id]);
570
+		$buffer = $Common->getData($value['host']);
571
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
+		$buffer = explode('\n',$buffer);
573
+		$reset = 0;
574
+		foreach ($buffer as $line) {
575
+			if ($line != '') {
576
+				$line = explode(':', $line);
577
+				if (count($line) > 30 && $line[0] != 'callsign') {
578 578
 			$data = array();
579 579
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -587,36 +587,36 @@  discard block
 block discarded – undo
587 587
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
588 588
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
589 589
 			$data['latitude'] = $line[5]; // lat
590
-	        	$data['longitude'] = $line[6]; // long
591
-	        	$data['verticalrate'] = ''; // vertical rate
592
-	        	$data['squawk'] = ''; // squawk
593
-	        	$data['emergency'] = ''; // emergency
594
-	        	$data['waypoints'] = $line[30];
590
+				$data['longitude'] = $line[6]; // long
591
+				$data['verticalrate'] = ''; // vertical rate
592
+				$data['squawk'] = ''; // squawk
593
+				$data['emergency'] = ''; // emergency
594
+				$data['waypoints'] = $line[30];
595 595
 			$data['datetime'] = date('Y-m-d H:i:s');
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598
-		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
-		        $data['arrival_airport_icao'] = $line[13];
598
+				$data['departure_airport_icao'] = $line[11];
599
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
600
+				$data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
603 603
 			$data['range'] = $line[19];
604 604
 			if (isset($line[35])) $data['info'] = $line[35];
605
-    			$data['id_source'] = $id_source;
606
-	    		//$data['arrival_airport_time'] = ;
607
-	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
609
-	    		    if (isset($aircraft_data[1])) {
610
-	    			$data['aircraft_icao'] = $aircraft_data[1];
611
-	    		    }
612
-        		}
613
-	    		/*
605
+				$data['id_source'] = $id_source;
606
+				//$data['arrival_airport_time'] = ;
607
+				if ($line[9] != '') {
608
+					$aircraft_data = explode('/',$line[9]);
609
+					if (isset($aircraft_data[1])) {
610
+					$data['aircraft_icao'] = $aircraft_data[1];
611
+					}
612
+				}
613
+				/*
614 614
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
615 615
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
616 616
 	    		*/
617
-	    		$data['format_source'] = $value['format'];
617
+				$data['format_source'] = $value['format'];
618 618
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
619
-    			if ($line[3] == 'PILOT') $SI->add($data);
619
+				if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622 622
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -634,247 +634,247 @@  discard block
 block discarded – undo
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635 635
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
636 636
 			}
637
-    			unset($data);
638
-    		    }
639
-    		}
640
-    	    }
641
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
-    	    $last_exec[$id]['last'] = time();
644
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
647
-	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
649
-	    if (isset($all_data['acList'])) {
637
+				unset($data);
638
+				}
639
+			}
640
+			}
641
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
642
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
643
+			$last_exec[$id]['last'] = time();
644
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
647
+		if ($buffer != '') {
648
+		$all_data = json_decode($buffer,true);
649
+		if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
652
-		    $data = array();
653
-		    $data['hex'] = $line['Icao']; // hex
654
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
-		    //$data['verticalrate'] = $line['']; // verticale rate
661
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
-		    $data['emergency'] = ''; // emergency
663
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
-		    /*
652
+			$data = array();
653
+			$data['hex'] = $line['Icao']; // hex
654
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
655
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
656
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
657
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
658
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
659
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
660
+			//$data['verticalrate'] = $line['']; // verticale rate
661
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
662
+			$data['emergency'] = ''; // emergency
663
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
664
+			/*
665 665
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
666 666
 		    else $data['datetime'] = date('Y-m-d H:i:s');
667 667
 		    */
668
-		    $data['datetime'] = date('Y-m-d H:i:s');
669
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
-	    	    $data['format_source'] = 'aircraftlistjson';
671
-		    $data['id_source'] = $id_source;
672
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
-		    if (isset($data['datetime'])) $SI->add($data);
674
-		    unset($data);
668
+			$data['datetime'] = date('Y-m-d H:i:s');
669
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
670
+				$data['format_source'] = 'aircraftlistjson';
671
+			$data['id_source'] = $id_source;
672
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
673
+			if (isset($data['datetime'])) $SI->add($data);
674
+			unset($data);
675 675
 		}
676
-	    } else {
676
+		} else {
677 677
 		$reset = 0;
678 678
 		foreach ($all_data as $line) {
679
-		    $data = array();
680
-		    $data['hex'] = $line['hex']; // hex
681
-		    $data['ident'] = $line['flight']; // ident
682
-		    $data['altitude'] = $line['altitude']; // altitude
683
-		    $data['speed'] = $line['speed']; // speed
684
-		    $data['heading'] = $line['track']; // heading
685
-		    $data['latitude'] = $line['lat']; // lat
686
-		    $data['longitude'] = $line['lon']; // long
687
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
688
-		    $data['squawk'] = $line['squawk']; // squawk
689
-		    $data['emergency'] = ''; // emergency
690
-		    $data['datetime'] = date('Y-m-d H:i:s');
691
-	    	    $data['format_source'] = 'aircraftlistjson';
692
-    		    $data['id_source'] = $id_source;
693
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
-		    $SI->add($data);
695
-		    unset($data);
679
+			$data = array();
680
+			$data['hex'] = $line['hex']; // hex
681
+			$data['ident'] = $line['flight']; // ident
682
+			$data['altitude'] = $line['altitude']; // altitude
683
+			$data['speed'] = $line['speed']; // speed
684
+			$data['heading'] = $line['track']; // heading
685
+			$data['latitude'] = $line['lat']; // lat
686
+			$data['longitude'] = $line['lon']; // long
687
+			$data['verticalrate'] = $line['vrt']; // verticale rate
688
+			$data['squawk'] = $line['squawk']; // squawk
689
+			$data['emergency'] = ''; // emergency
690
+			$data['datetime'] = date('Y-m-d H:i:s');
691
+				$data['format_source'] = 'aircraftlistjson';
692
+				$data['id_source'] = $id_source;
693
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
694
+			$SI->add($data);
695
+			unset($data);
696 696
 		}
697
-	    }
698
-	    }
699
-    	    //$last_exec['aircraftlistjson'] = time();
700
-    	    $last_exec[$id]['last'] = time();
701
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
-	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
705
-	    if (isset($all_data['planes'])) {
697
+		}
698
+		}
699
+			//$last_exec['aircraftlistjson'] = time();
700
+			$last_exec[$id]['last'] = time();
701
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703
+		$buffer = $Common->getData($value['host']);
704
+		$all_data = json_decode($buffer,true);
705
+		if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
708
-		    $data = array();
709
-		    $data['hex'] = $key; // hex
710
-		    $data['ident'] = $line[3]; // ident
711
-		    $data['altitude'] = $line[6]; // altitude
712
-		    $data['speed'] = $line[8]; // speed
713
-		    $data['heading'] = $line[7]; // heading
714
-		    $data['latitude'] = $line[4]; // lat
715
-		    $data['longitude'] = $line[5]; // long
716
-		    //$data['verticalrate'] = $line[]; // verticale rate
717
-		    $data['squawk'] = $line[10]; // squawk
718
-		    $data['emergency'] = ''; // emergency
719
-		    $data['registration'] = $line[2];
720
-		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
722
-		    if (count($deparr) == 2) {
708
+			$data = array();
709
+			$data['hex'] = $key; // hex
710
+			$data['ident'] = $line[3]; // ident
711
+			$data['altitude'] = $line[6]; // altitude
712
+			$data['speed'] = $line[8]; // speed
713
+			$data['heading'] = $line[7]; // heading
714
+			$data['latitude'] = $line[4]; // lat
715
+			$data['longitude'] = $line[5]; // long
716
+			//$data['verticalrate'] = $line[]; // verticale rate
717
+			$data['squawk'] = $line[10]; // squawk
718
+			$data['emergency'] = ''; // emergency
719
+			$data['registration'] = $line[2];
720
+			$data['aircraft_icao'] = $line[0];
721
+			$deparr = explode('-',$line[1]);
722
+			if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725
-		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
-	    	    $data['format_source'] = 'planeupdatefaa';
728
-    		    $data['id_source'] = $id_source;
729
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
-		    $SI->add($data);
731
-		    unset($data);
725
+			}
726
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
727
+				$data['format_source'] = 'planeupdatefaa';
728
+				$data['id_source'] = $id_source;
729
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
730
+			$SI->add($data);
731
+			unset($data);
732 732
 		}
733
-	    }
734
-    	    //$last_exec['planeupdatefaa'] = time();
735
-    	    $last_exec[$id]['last'] = time();
736
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
-	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
739
-	    if (isset($all_data['states'])) {
733
+		}
734
+			//$last_exec['planeupdatefaa'] = time();
735
+			$last_exec[$id]['last'] = time();
736
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737
+		$buffer = $Common->getData($value['host']);
738
+		$all_data = json_decode($buffer,true);
739
+		if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
742
-		    $data = array();
743
-		    $data['hex'] = $line[0]; // hex
744
-		    $data['ident'] = trim($line[1]); // ident
745
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
746
-		    $data['speed'] = round($line[9]*1.94384); // speed
747
-		    $data['heading'] = round($line[10]); // heading
748
-		    $data['latitude'] = $line[5]; // lat
749
-		    $data['longitude'] = $line[6]; // long
750
-		    $data['verticalrate'] = $line[11]; // verticale rate
751
-		    //$data['squawk'] = $line[10]; // squawk
752
-		    //$data['emergency'] = ''; // emergency
753
-		    //$data['registration'] = $line[2];
754
-		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
-	    	    $data['format_source'] = 'opensky';
757
-    		    $data['id_source'] = $id_source;
758
-		    $SI->add($data);
759
-		    unset($data);
742
+			$data = array();
743
+			$data['hex'] = $line[0]; // hex
744
+			$data['ident'] = trim($line[1]); // ident
745
+			$data['altitude'] = round($line[7]*3.28084); // altitude
746
+			$data['speed'] = round($line[9]*1.94384); // speed
747
+			$data['heading'] = round($line[10]); // heading
748
+			$data['latitude'] = $line[5]; // lat
749
+			$data['longitude'] = $line[6]; // long
750
+			$data['verticalrate'] = $line[11]; // verticale rate
751
+			//$data['squawk'] = $line[10]; // squawk
752
+			//$data['emergency'] = ''; // emergency
753
+			//$data['registration'] = $line[2];
754
+			//$data['aircraft_icao'] = $line[0];
755
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
756
+				$data['format_source'] = 'opensky';
757
+				$data['id_source'] = $id_source;
758
+			$SI->add($data);
759
+			unset($data);
760 760
 		}
761
-	    }
762
-    	    //$last_exec['planeupdatefaa'] = time();
763
-    	    $last_exec[$id]['last'] = time();
764
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
-	    //$buffer = $Common->getData($hosts[$id]);
767
-	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
769
-	    if (!empty($all_data)) $reset = 0;
770
-	    foreach ($all_data as $key => $line) {
761
+		}
762
+			//$last_exec['planeupdatefaa'] = time();
763
+			$last_exec[$id]['last'] = time();
764
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
765
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766
+		//$buffer = $Common->getData($hosts[$id]);
767
+		$buffer = $Common->getData($value['host']);
768
+		$all_data = json_decode($buffer,true);
769
+		if (!empty($all_data)) $reset = 0;
770
+		foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
772
-		    $data = array();
773
-		    $data['hex'] = $line[0];
774
-		    $data['ident'] = $line[16]; //$line[13]
775
-	    	    $data['altitude'] = $line[4]; // altitude
776
-	    	    $data['speed'] = $line[5]; // speed
777
-	    	    $data['heading'] = $line[3]; // heading
778
-	    	    $data['latitude'] = $line[1]; // lat
779
-	    	    $data['longitude'] = $line[2]; // long
780
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
781
-	    	    $data['squawk'] = $line[6]; // squawk
782
-	    	    $data['aircraft_icao'] = $line[8];
783
-	    	    $data['registration'] = $line[9];
784
-		    $data['departure_airport_iata'] = $line[11];
785
-		    $data['arrival_airport_iata'] = $line[12];
786
-	    	    $data['emergency'] = ''; // emergency
787
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
-	    	    $data['format_source'] = 'fr24json';
789
-    		    $data['id_source'] = $id_source;
790
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
-		    $SI->add($data);
792
-		    unset($data);
772
+			$data = array();
773
+			$data['hex'] = $line[0];
774
+			$data['ident'] = $line[16]; //$line[13]
775
+				$data['altitude'] = $line[4]; // altitude
776
+				$data['speed'] = $line[5]; // speed
777
+				$data['heading'] = $line[3]; // heading
778
+				$data['latitude'] = $line[1]; // lat
779
+				$data['longitude'] = $line[2]; // long
780
+				$data['verticalrate'] = $line[15]; // verticale rate
781
+				$data['squawk'] = $line[6]; // squawk
782
+				$data['aircraft_icao'] = $line[8];
783
+				$data['registration'] = $line[9];
784
+			$data['departure_airport_iata'] = $line[11];
785
+			$data['arrival_airport_iata'] = $line[12];
786
+				$data['emergency'] = ''; // emergency
787
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
788
+				$data['format_source'] = 'fr24json';
789
+				$data['id_source'] = $id_source;
790
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
791
+			$SI->add($data);
792
+			unset($data);
793 793
 		}
794
-	    }
795
-    	    //$last_exec['fr24json'] = time();
796
-    	    $last_exec[$id]['last'] = time();
797
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
801
-	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
805
-	    if (json_last_error() != JSON_ERROR_NONE) {
794
+		}
795
+			//$last_exec['fr24json'] = time();
796
+			$last_exec[$id]['last'] = time();
797
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
801
+		//echo $buffer;
802
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
803
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
+		$all_data = json_decode($buffer,true);
805
+		if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807
-	    }
808
-	    if (isset($all_data['mrkrs'])) {
807
+		}
808
+		if (isset($all_data['mrkrs'])) {
809 809
 		$reset = 0;
810 810
 		foreach ($all_data['mrkrs'] as $key => $line) {
811
-		    if (isset($line['inf'])) {
811
+			if (isset($line['inf'])) {
812 812
 			$data = array();
813 813
 			$data['hex'] = $line['inf']['ia'];
814 814
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
815
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
-	    		$data['latitude'] = $line['pt'][0]; // lat
819
-	    		$data['longitude'] = $line['pt'][1]; // long
820
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
-	    		//$data['aircraft_icao'] = $line[8];
823
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
815
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
816
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
817
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
818
+				$data['latitude'] = $line['pt'][0]; // lat
819
+				$data['longitude'] = $line['pt'][1]; // long
820
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
821
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
822
+				//$data['aircraft_icao'] = $line[8];
823
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826
-	    		//$data['emergency'] = ''; // emergency
826
+				//$data['emergency'] = ''; // emergency
827 827
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
828
-	    		$data['format_source'] = 'radarvirtueljson';
829
-    			$data['id_source'] = $id_source;
828
+				$data['format_source'] = 'radarvirtueljson';
829
+				$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
831 831
 			$SI->add($data);
832 832
 			unset($data);
833
-		    }
833
+			}
834
+		}
834 835
 		}
835
-	    }
836
-    	    //$last_exec['radarvirtueljson'] = time();
837
-    	    $last_exec[$id]['last'] = time();
838
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
-	    //$buffer = $Common->getData($hosts[$id]);
841
-	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
836
+			//$last_exec['radarvirtueljson'] = time();
837
+			$last_exec[$id]['last'] = time();
838
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
839
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840
+		//$buffer = $Common->getData($hosts[$id]);
841
+		$buffer = $Common->getData($value['host'].'?'.time());
842
+		$all_data = json_decode(utf8_encode($buffer),true);
843 843
 	    
844
-	    if (isset($all_data['pireps'])) {
844
+		if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846
-	        foreach ($all_data['pireps'] as $line) {
847
-		    $data = array();
848
-		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
-		    $data['ident'] = $line['callsign']; // ident
851
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
-		    $data['latitude'] = $line['lat']; // lat
858
-		    $data['longitude'] = $line['lon']; // long
859
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
860
-		    //$data['squawk'] = $line['squawk']; // squawk
861
-		    //$data['emergency'] = ''; // emergency
862
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
-		    //$data['arrival_airport_time'] = $line['arrtime'];
866
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
869
-		    else $data['info'] = '';
870
-		    $data['format_source'] = 'pireps';
871
-    		    $data['id_source'] = $id_source;
872
-		    $data['datetime'] = date('Y-m-d H:i:s');
873
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
-		    if ($line['icon'] == 'plane') {
846
+			foreach ($all_data['pireps'] as $line) {
847
+			$data = array();
848
+			$data['id'] = $line['id'];
849
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
850
+			$data['ident'] = $line['callsign']; // ident
851
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
853
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
854
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
855
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
856
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
857
+			$data['latitude'] = $line['lat']; // lat
858
+			$data['longitude'] = $line['lon']; // long
859
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
860
+			//$data['squawk'] = $line['squawk']; // squawk
861
+			//$data['emergency'] = ''; // emergency
862
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
863
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
864
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
865
+			//$data['arrival_airport_time'] = $line['arrtime'];
866
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
867
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
868
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
869
+			else $data['info'] = '';
870
+			$data['format_source'] = 'pireps';
871
+				$data['id_source'] = $id_source;
872
+			$data['datetime'] = date('Y-m-d H:i:s');
873
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
874
+			if ($line['icon'] == 'plane') {
875 875
 			$SI->add($data);
876
-		    //    print_r($data);
877
-    		    } elseif ($line['icon'] == 'ct') {
876
+			//    print_r($data);
877
+				} elseif ($line['icon'] == 'ct') {
878 878
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879 879
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880 880
 			$typec = substr($data['ident'],-3);
@@ -889,188 +889,188 @@  discard block
 block discarded – undo
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891 891
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
892
-		    }
893
-		    unset($data);
892
+			}
893
+			unset($data);
894
+		}
894 895
 		}
895
-	    }
896
-    	    //$last_exec['pirepsjson'] = time();
897
-    	    $last_exec[$id]['last'] = time();
898
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
-	    //$buffer = $Common->getData($hosts[$id]);
901
-	    if ($globalDebug) echo 'Get Data...'."\n";
902
-	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
904
-	    if ($buffer != '' && is_array($all_data)) {
896
+			//$last_exec['pirepsjson'] = time();
897
+			$last_exec[$id]['last'] = time();
898
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
899
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
900
+		//$buffer = $Common->getData($hosts[$id]);
901
+		if ($globalDebug) echo 'Get Data...'."\n";
902
+		$buffer = $Common->getData($value['host']);
903
+		$all_data = json_decode($buffer,true);
904
+		if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907
-	    	    $data = array();
908
-	    	    //$data['id'] = $line['id']; // id not usable
909
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
-	    	    $data['ident'] = $line['flightnum']; // ident
914
-	    	    $data['altitude'] = $line['alt']; // altitude
915
-	    	    $data['speed'] = $line['gs']; // speed
916
-	    	    $data['heading'] = $line['heading']; // heading
917
-	    	    $data['latitude'] = $line['lat']; // lat
918
-	    	    $data['longitude'] = $line['lng']; // long
919
-	    	    $data['verticalrate'] = ''; // verticale rate
920
-	    	    $data['squawk'] = ''; // squawk
921
-	    	    $data['emergency'] = ''; // emergency
922
-	    	    //$data['datetime'] = $line['lastupdate'];
923
-	    	    $data['last_update'] = $line['lastupdate'];
924
-		    $data['datetime'] = date('Y-m-d H:i:s');
925
-	    	    $data['departure_airport_icao'] = $line['depicao'];
926
-	    	    $data['departure_airport_time'] = $line['deptime'];
927
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
928
-    		    $data['arrival_airport_time'] = $line['arrtime'];
929
-    		    $data['registration'] = $line['aircraft'];
930
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
-		    if (isset($line['aircraftname'])) {
907
+				$data = array();
908
+				//$data['id'] = $line['id']; // id not usable
909
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
911
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913
+				$data['ident'] = $line['flightnum']; // ident
914
+				$data['altitude'] = $line['alt']; // altitude
915
+				$data['speed'] = $line['gs']; // speed
916
+				$data['heading'] = $line['heading']; // heading
917
+				$data['latitude'] = $line['lat']; // lat
918
+				$data['longitude'] = $line['lng']; // long
919
+				$data['verticalrate'] = ''; // verticale rate
920
+				$data['squawk'] = ''; // squawk
921
+				$data['emergency'] = ''; // emergency
922
+				//$data['datetime'] = $line['lastupdate'];
923
+				$data['last_update'] = $line['lastupdate'];
924
+			$data['datetime'] = date('Y-m-d H:i:s');
925
+				$data['departure_airport_icao'] = $line['depicao'];
926
+				$data['departure_airport_time'] = $line['deptime'];
927
+				$data['arrival_airport_icao'] = $line['arricao'];
928
+				$data['arrival_airport_time'] = $line['arrtime'];
929
+				$data['registration'] = $line['aircraft'];
930
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931
+			if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933 933
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
935
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
939
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941
-	    		}
942
-	    	    }
943
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
-    		    $data['id_source'] = $id_source;
945
-	    	    $data['format_source'] = 'phpvmacars';
946
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
-		    $SI->add($data);
948
-		    unset($data);
934
+				$aircraft_data = explode('-',$line['aircraftname']);
935
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937
+				else {
938
+					$aircraft_data = explode(' ',$line['aircraftname']);
939
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940
+					else $data['aircraft_icao'] = $line['aircraftname'];
941
+				}
942
+				}
943
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
944
+				$data['id_source'] = $id_source;
945
+				$data['format_source'] = 'phpvmacars';
946
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
947
+			$SI->add($data);
948
+			unset($data);
949 949
 		}
950 950
 		if ($globalDebug) echo 'No more data...'."\n";
951 951
 		unset($buffer);
952 952
 		unset($all_data);
953
-	    }
954
-    	    //$last_exec['phpvmacars'] = time();
955
-    	    $last_exec[$id]['last'] = time();
956
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
-	    //$buffer = $Common->getData($hosts[$id]);
958
-	    if ($globalDebug) echo 'Get Data...'."\n";
959
-	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
961
-	    if ($buffer != '' && is_array($all_data)) {
953
+		}
954
+			//$last_exec['phpvmacars'] = time();
955
+			$last_exec[$id]['last'] = time();
956
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
+		//$buffer = $Common->getData($hosts[$id]);
958
+		if ($globalDebug) echo 'Get Data...'."\n";
959
+		$buffer = $Common->getData($value['host']);
960
+		$all_data = json_decode($buffer,true);
961
+		if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964
-	    	    $data = array();
965
-	    	    //$data['id'] = $line['id']; // id not usable
966
-	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
-	    	    $data['pilot_name'] = $line['pilot_name'];
969
-	    	    $data['pilot_id'] = $line['pilot_id'];
970
-	    	    $data['ident'] = trim($line['callsign']); // ident
971
-	    	    $data['altitude'] = $line['altitude']; // altitude
972
-	    	    $data['speed'] = $line['gs']; // speed
973
-	    	    $data['heading'] = $line['heading']; // heading
974
-	    	    $data['latitude'] = $line['latitude']; // lat
975
-	    	    $data['longitude'] = $line['longitude']; // long
976
-	    	    $data['verticalrate'] = ''; // verticale rate
977
-	    	    $data['squawk'] = ''; // squawk
978
-	    	    $data['emergency'] = ''; // emergency
979
-	    	    //$data['datetime'] = $line['lastupdate'];
980
-	    	    $data['last_update'] = $line['last_update'];
981
-		    $data['datetime'] = date('Y-m-d H:i:s');
982
-	    	    $data['departure_airport_icao'] = $line['departure'];
983
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
984
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
985
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
986
-    		    //$data['registration'] = $line['aircraft'];
987
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
-	    	    $data['aircraft_icao'] = $line['plane_type'];
989
-    		    $data['id_source'] = $id_source;
990
-	    	    $data['format_source'] = 'vam';
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
-		    $SI->add($data);
993
-		    unset($data);
964
+				$data = array();
965
+				//$data['id'] = $line['id']; // id not usable
966
+				$data['id'] = trim($line['flight_id']);
967
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
968
+				$data['pilot_name'] = $line['pilot_name'];
969
+				$data['pilot_id'] = $line['pilot_id'];
970
+				$data['ident'] = trim($line['callsign']); // ident
971
+				$data['altitude'] = $line['altitude']; // altitude
972
+				$data['speed'] = $line['gs']; // speed
973
+				$data['heading'] = $line['heading']; // heading
974
+				$data['latitude'] = $line['latitude']; // lat
975
+				$data['longitude'] = $line['longitude']; // long
976
+				$data['verticalrate'] = ''; // verticale rate
977
+				$data['squawk'] = ''; // squawk
978
+				$data['emergency'] = ''; // emergency
979
+				//$data['datetime'] = $line['lastupdate'];
980
+				$data['last_update'] = $line['last_update'];
981
+			$data['datetime'] = date('Y-m-d H:i:s');
982
+				$data['departure_airport_icao'] = $line['departure'];
983
+				//$data['departure_airport_time'] = $line['departure_time'];
984
+				$data['arrival_airport_icao'] = $line['arrival'];
985
+				//$data['arrival_airport_time'] = $line['arrival_time'];
986
+				//$data['registration'] = $line['aircraft'];
987
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
988
+				$data['aircraft_icao'] = $line['plane_type'];
989
+				$data['id_source'] = $id_source;
990
+				$data['format_source'] = 'vam';
991
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
+			$SI->add($data);
993
+			unset($data);
994 994
 		}
995 995
 		if ($globalDebug) echo 'No more data...'."\n";
996 996
 		unset($buffer);
997 997
 		unset($all_data);
998
-	    }
999
-    	    //$last_exec['phpvmacars'] = time();
1000
-    	    $last_exec[$id]['last'] = time();
998
+		}
999
+			//$last_exec['phpvmacars'] = time();
1000
+			$last_exec[$id]['last'] = time();
1001 1001
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1002 1002
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1003
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
-    	    //$last_exec[$id]['last'] = time();
1003
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1004
+			//$last_exec[$id]['last'] = time();
1005 1005
 
1006
-	    //$read = array( $sockets[$id] );
1007
-	    $read = $sockets;
1008
-	    $write = NULL;
1009
-	    $e = NULL;
1010
-	    $n = socket_select($read, $write, $e, $timeout);
1011
-	    if ($e != NULL) var_dump($e);
1012
-	    if ($n > 0) {
1006
+		//$read = array( $sockets[$id] );
1007
+		$read = $sockets;
1008
+		$write = NULL;
1009
+		$e = NULL;
1010
+		$n = socket_select($read, $write, $e, $timeout);
1011
+		if ($e != NULL) var_dump($e);
1012
+		if ($n > 0) {
1013 1013
 		$reset = 0;
1014 1014
 		foreach ($read as $nb => $r) {
1015
-		    //$value = $formats[$nb];
1016
-		    $format = $globalSources[$nb]['format'];
1017
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
-        	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
-	    	    }
1022
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
-        	    //echo $buffer."\n";
1024
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1025
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
-		    $error = false;
1027
-		    //$SI::del();
1028
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
-		    // SBS format is CSV format
1030
-		    if ($buffer != '') {
1015
+			//$value = $formats[$nb];
1016
+			$format = $globalSources[$nb]['format'];
1017
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1018
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1019
+				} else {
1020
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1021
+				}
1022
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023
+				//echo $buffer."\n";
1024
+			// lets play nice and handle signals such as ctrl-c/kill properly
1025
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1026
+			$error = false;
1027
+			//$SI::del();
1028
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
+			// SBS format is CSV format
1030
+			if ($buffer != '') {
1031 1031
 			$tt[$format] = 0;
1032 1032
 			if ($format == 'acarssbs3') {
1033
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1034
-			    $ACARS->add(trim($buffer));
1035
-			    $ACARS->deleteLiveAcarsData();
1033
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1034
+				$ACARS->add(trim($buffer));
1035
+				$ACARS->deleteLiveAcarsData();
1036 1036
 			} elseif ($format == 'raw') {
1037
-			    // AVR format
1038
-			    $data = $SBS->parse($buffer);
1039
-			    if (is_array($data)) {
1037
+				// AVR format
1038
+				$data = $SBS->parse($buffer);
1039
+				if (is_array($data)) {
1040 1040
 				$data['datetime'] = date('Y-m-d H:i:s');
1041 1041
 				$data['format_source'] = 'raw';
1042 1042
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1043
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1045
-                            }
1046
-                        } elseif ($format == 'ais') {
1047
-			    $ais_data = $AIS->parse_line(trim($buffer));
1048
-			    $data = array();
1049
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1043
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1044
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1045
+							}
1046
+						} elseif ($format == 'ais') {
1047
+				$ais_data = $AIS->parse_line(trim($buffer));
1048
+				$data = array();
1049
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1050
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1051
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1052
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1053
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1054
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1055
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1056
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1057
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1058
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1059
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1060
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1061 1061
 
1062
-			    if (isset($ais_data['timestamp'])) {
1062
+				if (isset($ais_data['timestamp'])) {
1063 1063
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1064
-			    } else {
1064
+				} else {
1065 1065
 				$data['datetime'] = date('Y-m-d H:i:s');
1066
-			    }
1067
-			    $data['format_source'] = 'aisnmea';
1068
-    			    $data['id_source'] = $id_source;
1069
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1070
-			    unset($data);
1071
-                        } elseif ($format == 'flightgearsp') {
1072
-                    	    //echo $buffer."\n";
1073
-                    	    if (strlen($buffer) > 5) {
1066
+				}
1067
+				$data['format_source'] = 'aisnmea';
1068
+					$data['id_source'] = $id_source;
1069
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1070
+				unset($data);
1071
+						} elseif ($format == 'flightgearsp') {
1072
+							//echo $buffer."\n";
1073
+							if (strlen($buffer) > 5) {
1074 1074
 				$line = explode(',',$buffer);
1075 1075
 				$data = array();
1076 1076
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1086,121 +1086,121 @@  discard block
 block discarded – undo
1086 1086
 				$data['format_source'] = 'flightgearsp';
1087 1087
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1088 1088
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1089
-			    }
1090
-                        } elseif ($format == 'acars') {
1091
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1092
-			    $ACARS->add(trim($buffer));
1093
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094
-			    $ACARS->deleteLiveAcarsData();
1089
+				}
1090
+						} elseif ($format == 'acars') {
1091
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1092
+				$ACARS->add(trim($buffer));
1093
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1094
+				$ACARS->deleteLiveAcarsData();
1095 1095
 			} elseif ($format == 'flightgearmp') {
1096
-			    if (substr($buffer,0,1) != '#') {
1096
+				if (substr($buffer,0,1) != '#') {
1097 1097
 				$data = array();
1098 1098
 				//echo $buffer."\n";
1099 1099
 				$line = explode(' ',$buffer);
1100 1100
 				if (count($line) == 11) {
1101
-				    $userserver = explode('@',$line[0]);
1102
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
-				    $data['ident'] = $userserver[0];
1104
-				    $data['registration'] = $userserver[0];
1105
-				    $data['latitude'] = $line[4];
1106
-				    $data['longitude'] = $line[5];
1107
-				    $data['altitude'] = $line[6];
1108
-				    $data['datetime'] = date('Y-m-d H:i:s');
1109
-				    $aircraft_type = $line[10];
1110
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1111
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1101
+					$userserver = explode('@',$line[0]);
1102
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
+					$data['ident'] = $userserver[0];
1104
+					$data['registration'] = $userserver[0];
1105
+					$data['latitude'] = $line[4];
1106
+					$data['longitude'] = $line[5];
1107
+					$data['altitude'] = $line[6];
1108
+					$data['datetime'] = date('Y-m-d H:i:s');
1109
+					$aircraft_type = $line[10];
1110
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1111
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1113
+				}
1113 1114
 				}
1114
-			    }
1115 1115
 			} elseif ($format == 'beast') {
1116
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1117
-			    die;
1116
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1117
+				die;
1118 1118
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1119
-			    $line = explode("\t", $buffer);
1120
-			    for($k = 0; $k < count($line); $k=$k+2) {
1119
+				$line = explode("\t", $buffer);
1120
+				for($k = 0; $k < count($line); $k=$k+2) {
1121 1121
 				$key = $line[$k];
1122
-			        $lined[$key] = $line[$k+1];
1123
-			    }
1124
-    			    if (count($lined) > 3) {
1125
-    				$data['hex'] = $lined['hexid'];
1126
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1128
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1135
-    				$data['id_source'] = $id_source;
1136
-    				$data['format_source'] = 'tsv';
1137
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1140
-    				unset($lined);
1141
-    				unset($data);
1142
-    			    } else $error = true;
1122
+					$lined[$key] = $line[$k+1];
1123
+				}
1124
+					if (count($lined) > 3) {
1125
+					$data['hex'] = $lined['hexid'];
1126
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1127
+					$data['datetime'] = date('Y-m-d H:i:s');;
1128
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1129
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1130
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1131
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1132
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1133
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1134
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1135
+					$data['id_source'] = $id_source;
1136
+					$data['format_source'] = 'tsv';
1137
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1138
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1139
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1140
+					unset($lined);
1141
+					unset($data);
1142
+					} else $error = true;
1143 1143
 			} elseif ($format == 'aprs' && $use_aprs) {
1144
-			    if ($aprs_connect == 0) {
1144
+				if ($aprs_connect == 0) {
1145 1145
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1146 1146
 				$aprs_connect = 1;
1147
-			    }
1147
+				}
1148 1148
 			    
1149
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1149
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1150 1150
 				$aprs_last_tx = time();
1151 1151
 				$data_aprs = "# Keep alive";
1152 1152
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1153
-			    }
1153
+				}
1154 1154
 			    
1155
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1156
-			    //echo 'APRS data : '.$buffer."\n";
1157
-			    $buffer = str_replace('APRS <- ','',$buffer);
1158
-			    $buffer = str_replace('APRS -> ','',$buffer);
1159
-			    //echo $buffer."\n";
1160
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1155
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1156
+				//echo 'APRS data : '.$buffer."\n";
1157
+				$buffer = str_replace('APRS <- ','',$buffer);
1158
+				$buffer = str_replace('APRS -> ','',$buffer);
1159
+				//echo $buffer."\n";
1160
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1161 1161
 				$line = $APRS->parse($buffer);
1162 1162
 				//print_r($line);
1163 1163
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1164 1164
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && isset($line['ident'])) {
1165
-				    $aprs_last_tx = time();
1166
-				    $data = array();
1167
-				    //print_r($line);
1168
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1169
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1171
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1172
-				    $data['ident'] = $line['ident'];
1173
-				    $data['latitude'] = $line['latitude'];
1174
-				    $data['longitude'] = $line['longitude'];
1175
-				    //$data['verticalrate'] = $line[16];
1176
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
-				    else $data['speed'] = 0;
1178
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1182
-				    //else $data['heading'] = 0;
1183
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1185
-    				    $data['id_source'] = $id_source;
1186
-				    $data['format_source'] = 'aprs';
1187
-				    $data['source_name'] = $line['source'];
1188
-				    $data['source_type'] = 'flarm';
1189
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1190
-				    $currentdate = date('Y-m-d H:i:s');
1191
-				    $aprsdate = strtotime($data['datetime']);
1192
-				    // Accept data if time <= system time + 20s
1193
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1165
+					$aprs_last_tx = time();
1166
+					$data = array();
1167
+					//print_r($line);
1168
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1169
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1170
+					else $data['datetime'] = date('Y-m-d H:i:s');
1171
+					//$data['datetime'] = date('Y-m-d H:i:s');
1172
+					$data['ident'] = $line['ident'];
1173
+					$data['latitude'] = $line['latitude'];
1174
+					$data['longitude'] = $line['longitude'];
1175
+					//$data['verticalrate'] = $line[16];
1176
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1177
+					else $data['speed'] = 0;
1178
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1179
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1180
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1181
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1182
+					//else $data['heading'] = 0;
1183
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1184
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1185
+						$data['id_source'] = $id_source;
1186
+					$data['format_source'] = 'aprs';
1187
+					$data['source_name'] = $line['source'];
1188
+					$data['source_type'] = 'flarm';
1189
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1190
+					$currentdate = date('Y-m-d H:i:s');
1191
+					$aprsdate = strtotime($data['datetime']);
1192
+					// Accept data if time <= system time + 20s
1193
+					if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1194 1194
 					$send = $SI->add($data);
1195
-				    } elseif (isset($line['stealth'])) {
1195
+					} elseif (isset($line['stealth'])) {
1196 1196
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1197 1197
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1198
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1198
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1199
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1200 1200
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1201 1201
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1202
-				    }
1203
-				    unset($data);
1202
+					}
1203
+					unset($data);
1204 1204
 				} 
1205 1205
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1206 1206
 					echo '!! Weather Station not yet supported'."\n";
@@ -1210,12 +1210,12 @@  discard block
 block discarded – undo
1210 1210
 				}
1211 1211
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1212 1212
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1213
-			    }
1213
+				}
1214 1214
 			} else {
1215
-			    $line = explode(',', $buffer);
1216
-    			    if (count($line) > 20) {
1217
-    			    	$data['hex'] = $line[4];
1218
-    				/*
1215
+				$line = explode(',', $buffer);
1216
+					if (count($line) > 20) {
1217
+						$data['hex'] = $line[4];
1218
+					/*
1219 1219
     				$data['datetime'] = $line[6].' '.$line[7];
1220 1220
     					date_default_timezone_set($globalTimezone);
1221 1221
     					$datetime = new DateTime($data['datetime']);
@@ -1223,29 +1223,29 @@  discard block
 block discarded – undo
1223 1223
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1224 1224
     					date_default_timezone_set('UTC');
1225 1225
     				*/
1226
-    				// Force datetime to current UTC datetime
1227
-    				date_default_timezone_set('UTC');
1228
-    				$data['datetime'] = date('Y-m-d H:i:s');
1229
-    				$data['ident'] = trim($line[10]);
1230
-    				$data['latitude'] = $line[14];
1231
-    				$data['longitude'] = $line[15];
1232
-    				$data['verticalrate'] = $line[16];
1233
-    				$data['emergency'] = $line[20];
1234
-    				$data['speed'] = $line[12];
1235
-    				$data['squawk'] = $line[17];
1236
-    				$data['altitude'] = $line[11];
1237
-    				$data['heading'] = $line[13];
1238
-    				$data['ground'] = $line[21];
1239
-    				$data['emergency'] = $line[19];
1240
-    				$data['format_source'] = 'sbs';
1226
+					// Force datetime to current UTC datetime
1227
+					date_default_timezone_set('UTC');
1228
+					$data['datetime'] = date('Y-m-d H:i:s');
1229
+					$data['ident'] = trim($line[10]);
1230
+					$data['latitude'] = $line[14];
1231
+					$data['longitude'] = $line[15];
1232
+					$data['verticalrate'] = $line[16];
1233
+					$data['emergency'] = $line[20];
1234
+					$data['speed'] = $line[12];
1235
+					$data['squawk'] = $line[17];
1236
+					$data['altitude'] = $line[11];
1237
+					$data['heading'] = $line[13];
1238
+					$data['ground'] = $line[21];
1239
+					$data['emergency'] = $line[19];
1240
+					$data['format_source'] = 'sbs';
1241 1241
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1242
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1243
-    				$data['id_source'] = $id_source;
1244
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
-    				else $error = true;
1246
-    				unset($data);
1247
-    			    } else $error = true;
1248
-			    if ($error) {
1242
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1243
+					$data['id_source'] = $id_source;
1244
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1245
+					else $error = true;
1246
+					unset($data);
1247
+					} else $error = true;
1248
+				if ($error) {
1249 1249
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1250 1250
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1251 1251
 				} else {
@@ -1261,13 +1261,13 @@  discard block
 block discarded – undo
1261 1261
 					connect_all($sourceer);
1262 1262
 					$sourceer = array();
1263 1263
 				}
1264
-			    }
1264
+				}
1265 1265
 			}
1266 1266
 			// Sleep for xxx microseconds
1267 1267
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1268
-		    } else {
1268
+			} else {
1269 1269
 			if ($format == 'flightgearmp') {
1270
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1270
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1271 1271
 				//@socket_close($r);
1272 1272
 				sleep($globalMinFetch);
1273 1273
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1276,9 +1276,9 @@  discard block
 block discarded – undo
1276 1276
 				break;
1277 1277
 				
1278 1278
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1279
-			    if (isset($tt[$format])) $tt[$format]++;
1280
-			    else $tt[$format] = 0;
1281
-			    if ($tt[$format] > 30) {
1279
+				if (isset($tt[$format])) $tt[$format]++;
1280
+				else $tt[$format] = 0;
1281
+				if ($tt[$format] > 30) {
1282 1282
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1283 1283
 				//@socket_close($r);
1284 1284
 				sleep(2);
@@ -1289,23 +1289,23 @@  discard block
 block discarded – undo
1289 1289
 				//connect_all($globalSources);
1290 1290
 				$tt[$format]=0;
1291 1291
 				break;
1292
-			    }
1292
+				}
1293
+			}
1293 1294
 			}
1294
-		    }
1295 1295
 		}
1296
-	    } else {
1296
+		} else {
1297 1297
 		$error = socket_strerror(socket_last_error());
1298 1298
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1299 1299
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1300 1300
 			if (isset($globalDebug)) echo "Restarting...\n";
1301 1301
 			// Restart the script if possible
1302 1302
 			if (is_array($sockets)) {
1303
-			    if ($globalDebug) echo "Shutdown all sockets...";
1303
+				if ($globalDebug) echo "Shutdown all sockets...";
1304 1304
 			    
1305
-			    foreach ($sockets as $sock) {
1305
+				foreach ($sockets as $sock) {
1306 1306
 				@socket_shutdown($sock,2);
1307 1307
 				@socket_close($sock);
1308
-			    }
1308
+				}
1309 1309
 			    
1310 1310
 			}
1311 1311
 			if ($globalDebug) echo "Restart all connections...";
@@ -1316,13 +1316,13 @@  discard block
 block discarded – undo
1316 1316
 			if ($reset > 40) exit('Too many attempts...');
1317 1317
 			connect_all($globalSources);
1318 1318
 		}
1319
-	    }
1319
+		}
1320 1320
 	}
1321 1321
 	if ($globalDaemon === false) {
1322
-	    if ($globalDebug) echo 'Check all...'."\n";
1323
-	    $SI->checkAll();
1322
+		if ($globalDebug) echo 'Check all...'."\n";
1323
+		$SI->checkAll();
1324
+	}
1324 1325
 	}
1325
-    }
1326 1326
 }
1327 1327
 
1328 1328
 ?>
Please login to merge, or discard this patch.