Completed
Push — master ( 669803...3326da )
by Yannick
31:15
created
require/class.AIS.php 2 patches
Doc Comments   +25 added lines patch added patch discarded remove patch
@@ -68,6 +68,10 @@  discard block
 block discarded – undo
68 68
        't', 'u', 'v', 'w' // 119
69 69
     ); // char 64
70 70
     */
71
+
72
+	/**
73
+	 * @param integer $ascii
74
+	 */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73 77
 		if ($ascii < 48) { }
@@ -93,6 +97,10 @@  discard block
 block discarded – undo
93 97
 		return(substr($bin, -6)); 
94 98
 	}
95 99
 
100
+	/**
101
+	 * @param integer $_start
102
+	 * @param integer $_size
103
+	 */
96 104
 	private function binchar($_str, $_start, $_size) {
97 105
 		//  ' ' --- '?', // 0x20 - 0x3F
98 106
 		//  '@' --- '_', // 0x40 - 0x5F
@@ -118,6 +126,10 @@  discard block
 block discarded – undo
118 126
 	}
119 127
 
120 128
 	// function for decoding the AIS Message ITU Payload
129
+
130
+	/**
131
+	 * @param string $_aisdata
132
+	 */
121 133
 	private function decode_ais($_aisdata) {
122 134
 		$ro = new stdClass(); // return object
123 135
 		$ro->cls = 0; // AIS class undefined, also indicate unparsed msg
@@ -350,6 +362,12 @@  discard block
 block discarded – undo
350 362
 		elseif ($code == 99) return 'Other Type, no additional information';
351 363
 	}
352 364
 
365
+	/**
366
+	 * @param string $_itu
367
+	 * @param integer $_len
368
+	 * @param integer $_filler
369
+	 * @param string $aux
370
+	 */
353 371
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
354 372
 		global $port; // tcpip port...
355 373
 		static $debug_counter = 0;
@@ -369,6 +387,10 @@  discard block
 block discarded – undo
369 387
 
370 388
 	// char* - AIS \r terminated string
371 389
 	// TCP based streams which send messages in full can use this instead of calling process_ais_buf
390
+
391
+	/**
392
+	 * @param string $rawdata
393
+	 */
372 394
 	public function process_ais_raw($rawdata, $aux = '') { // return int
373 395
 		static $num_seq; // 1 to 9
374 396
 		static $seq; // 1 to 9
@@ -591,6 +613,9 @@  discard block
 block discarded – undo
591 613
 		return $result;
592 614
 	}
593 615
 
616
+	/**
617
+	 * @param string $mmsi
618
+	 */
594 619
 	public function mmsitype($mmsi) {
595 620
 		if (strlen($mmsi) == 9) {
596 621
 			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@  discard block
 block discarded – undo
29 29
 
30 30
 	private function make_latf($temp) { // unsigned long 
31 31
 		$flat = 0.0; // float
32
-		$temp = $temp & 0x07FFFFFF;
33
-		if ($temp & 0x04000000) {
34
-			$temp = $temp ^ 0x07FFFFFF;
32
+		$temp = $temp&0x07FFFFFF;
33
+		if ($temp&0x04000000) {
34
+			$temp = $temp^0x07FFFFFF;
35 35
 			$temp += 1;
36
-			$flat = (float)($temp / (60.0 * 10000.0));
36
+			$flat = (float) ($temp/(60.0*10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else $flat = (float) ($temp/(60.0*10000.0));
39 39
 		return $flat; // float
40 40
 	}
41 41
 
42 42
 	private function make_lonf($temp) { // unsigned long
43 43
 		$flon = 0.0; // float
44
-		$temp = $temp & 0x0FFFFFFF;
45
-		if ($temp & 0x08000000) {
46
-			$temp = $temp ^ 0x0FFFFFFF;
44
+		$temp = $temp&0x0FFFFFFF;
45
+		if ($temp&0x08000000) {
46
+			$temp = $temp^0x0FFFFFFF;
47 47
 			$temp += 1;
48
-			$flon = (float)($temp / (60.0 * 10000.0));
48
+			$flon = (float) ($temp/(60.0*10000.0));
49 49
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
50
+		} else $flon = (float) ($temp/(60.0*10000.0));
51 51
 		return $flon;
52 52
 	}
53 53
 
54 54
 	private function ascii_2_dec($chr) {
55
-		$dec=ord($chr);//get decimal ascii code
56
-		$hex=dechex($dec);//convert decimal to hex
55
+		$dec = ord($chr); //get decimal ascii code
56
+		$hex = dechex($dec); //convert decimal to hex
57 57
 		return ($dec);
58 58
 	}
59 59
 	
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 		//only process in the following range: 48-87, 96-119
73 73
 		if ($ascii < 48) { }
74 74
 		else {
75
-			if($ascii>119) { }
75
+			if ($ascii > 119) { }
76 76
 			else {
77
-				if ($ascii>87 && $ascii<96) ;
77
+				if ($ascii > 87 && $ascii < 96);
78 78
 				else {
79
-					$ascii=$ascii+40;
80
-					if ($ascii>128){
81
-						$ascii=$ascii+32;
79
+					$ascii = $ascii + 40;
80
+					if ($ascii > 128) {
81
+						$ascii = $ascii + 32;
82 82
 					} else {
83
-						$ascii=$ascii+40;
83
+						$ascii = $ascii + 40;
84 84
 					}
85 85
 				}
86 86
 			}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	}
90 90
 
91 91
 	private function dec_2_6bit($dec) {
92
-		$bin=decbin($dec);
92
+		$bin = decbin($dec);
93 93
 		return(substr($bin, -6)); 
94 94
 	}
95 95
 
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 		// "
109 109
 		$rv = '';
110
-		if ($_size % 6 == 0) {
111
-			$len = $_size / 6;
112
-			for ($i=0; $i<$len; $i++) {
113
-				$offset = $i * 6;
114
-				$rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ];
110
+		if ($_size%6 == 0) {
111
+			$len = $_size/6;
112
+			for ($i = 0; $i < $len; $i++) {
113
+				$offset = $i*6;
114
+				$rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))];
115 115
 			}
116 116
 		}
117 117
 		return $rv;
@@ -138,93 +138,93 @@  discard block
 block discarded – undo
138 138
 		$ro->eta_hour = '';
139 139
 		$ro->eta_minute = '';
140 140
 		$ro->ts = time();
141
-		$ro->id = bindec(substr($_aisdata,0,6));
142
-		$ro->mmsi = bindec(substr($_aisdata,8,30));
141
+		$ro->id = bindec(substr($_aisdata, 0, 6));
142
+		$ro->mmsi = bindec(substr($_aisdata, 8, 30));
143 143
 		if ($ro->id >= 1 && $ro->id <= 3) {
144
-			$ro->cog = bindec(substr($_aisdata,116,12))/10;
145
-			$ro->sog = bindec(substr($_aisdata,50,10))/10;
146
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
147
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
144
+			$ro->cog = bindec(substr($_aisdata, 116, 12))/10;
145
+			$ro->sog = bindec(substr($_aisdata, 50, 10))/10;
146
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
147
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
148 148
 			$ro->cls = 1; // class A
149 149
 		} else if ($ro->id == 4) {
150
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28)));
151
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27)));
150
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28)));
151
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27)));
152 152
 			$ro->cls = 1; // class A
153 153
 		} else if ($ro->id == 5) {
154
-			$ro->imo = bindec(substr($_aisdata,40,30));
155
-			$ro->callsign = $this->binchar($_aisdata,70,42);
156
-			$ro->name = $this->binchar($_aisdata,112,120);
157
-			$ro->typeid = bindec(substr($_aisdata,232,8));
154
+			$ro->imo = bindec(substr($_aisdata, 40, 30));
155
+			$ro->callsign = $this->binchar($_aisdata, 70, 42);
156
+			$ro->name = $this->binchar($_aisdata, 112, 120);
157
+			$ro->typeid = bindec(substr($_aisdata, 232, 8));
158 158
 			$ro->type = $this->getShipType($ro->typeid);
159 159
 			//$ro->to_bow = bindec(substr($_aisdata,240,9));
160 160
 			//$ro->to_stern = bindec(substr($_aisdata,249,9));
161 161
 			//$ro->to_port = bindec(substr($_aisdata,258,6));
162 162
 			//$ro->to_starboard = bindec(substr($_aisdata,264,6));
163
-			$ro->eta_month = bindec(substr($_aisdata,274,4));
164
-			$ro->eta_day = bindec(substr($_aisdata,278,5));
165
-			$ro->eta_hour = bindec(substr($_aisdata,283,5));
166
-			$ro->eta_minute = bindec(substr($_aisdata,288,6));
163
+			$ro->eta_month = bindec(substr($_aisdata, 274, 4));
164
+			$ro->eta_day = bindec(substr($_aisdata, 278, 5));
165
+			$ro->eta_hour = bindec(substr($_aisdata, 283, 5));
166
+			$ro->eta_minute = bindec(substr($_aisdata, 288, 6));
167 167
 			//$ro->draught = bindec(substr($_aisdata,294,8));
168
-			$ro->destination = $this->binchar($_aisdata,302,120);
168
+			$ro->destination = $this->binchar($_aisdata, 302, 120);
169 169
 			$ro->cls = 1; // class A
170 170
 		} else if ($ro->id == 9) {
171 171
 			// Search and Rescue aircraft position report
172 172
 		} else if ($ro->id == 18) {
173
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
174
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
175
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177
-			$ro->heading = bindec(substr($_aisdata,124,9));
173
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
174
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
175
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28)));
176
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27)));
177
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
178 178
 			if ($ro->heading == 511) $ro->heading = '';
179 179
 			$ro->cls = 2; // class B
180 180
 		} else if ($ro->id == 19) {
181
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
182
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
183
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
184
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
185
-			$ro->name = $this->binchar($_aisdata,143,120);
181
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
182
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
183
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
184
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
185
+			$ro->name = $this->binchar($_aisdata, 143, 120);
186 186
 			$ro->cls = 2; // class B
187
-			$ro->heading = bindec(substr($_aisdata,124,9));
187
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
188 188
 			if ($ro->heading == 511) $ro->heading = '';
189
-			$ro->typeid = bindec(substr($_aisdata,263,8));
189
+			$ro->typeid = bindec(substr($_aisdata, 263, 8));
190 190
 			$ro->type = $this->getShipType($ro->typeid);
191 191
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
192 192
 			//$ro->to_stern = bindec(substr($_aisdata,280,9));
193 193
 			//$ro->to_port = bindec(substr($_aisdata,289,6));
194 194
 			//$ro->to_starboard = bindec(substr($_aisdata,295,6));
195 195
 		} else if ($ro->id == 21) {
196
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28)));
197
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27)));
198
-			$ro->name = $this->binchar($_aisdata,43,120);
196
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28)));
197
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27)));
198
+			$ro->name = $this->binchar($_aisdata, 43, 120);
199 199
 			//$ro->to_bow = bindec(substr($_aisdata,219,9));
200 200
 			//$ro->to_stern = bindec(substr($_aisdata,228,9));
201 201
 			//$ro->to_port = bindec(substr($_aisdata,237,6));
202 202
 			//$ro->to_starboard = bindec(substr($_aisdata,243,6));
203 203
 			$ro->cls = 2; // class B
204 204
 		} else if ($ro->id == 24) {
205
-			$pn = bindec(substr($_aisdata,38,2));
205
+			$pn = bindec(substr($_aisdata, 38, 2));
206 206
 			if ($pn == 0) {
207
-				$ro->name = $this->binchar($_aisdata,40,120);
207
+				$ro->name = $this->binchar($_aisdata, 40, 120);
208 208
 			}
209
-			$ro->typeid = bindec(substr($_aisdata,40,8));
209
+			$ro->typeid = bindec(substr($_aisdata, 40, 8));
210 210
 			$ro->type = $this->getShipType($ro->typeid);
211
-			$ro->callsign = $this->binchar($_aisdata,90,42);
211
+			$ro->callsign = $this->binchar($_aisdata, 90, 42);
212 212
 			//$ro->to_bow = bindec(substr($_aisdata,132,9));
213 213
 			//$ro->to_stern = bindec(substr($_aisdata,141,9));
214 214
 			//$ro->to_port = bindec(substr($_aisdata,150,6));
215 215
 			//$ro->to_starboard = bindec(substr($_aisdata,156,6));
216 216
 			$ro->cls = 2; // class B
217 217
 		} else if ($ro->id == 27) {
218
-			$ro->cog = bindec(substr($_aisdata,85,9));
218
+			$ro->cog = bindec(substr($_aisdata, 85, 9));
219 219
 			if ($ro->cog == 511) $ro->cog = 0.0;
220
-			$ro->sog = bindec(substr($_aisdata,79,6));
220
+			$ro->sog = bindec(substr($_aisdata, 79, 6));
221 221
 			if ($ro->sog == 63) $ro->sog = 0.0;
222
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
222
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10);
223
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10);
224 224
 			$ro->cls = 1; // class A
225 225
 		
226 226
 		}
227
-		$ro->statusid = bindec(substr($_aisdata,38,4));
227
+		$ro->statusid = bindec(substr($_aisdata, 38, 4));
228 228
 		$ro->status = $this->getStatus($ro->statusid);
229 229
 		return $ro;
230 230
 	}
@@ -353,14 +353,14 @@  discard block
 block discarded – undo
353 353
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
354 354
 		global $port; // tcpip port...
355 355
 		static $debug_counter = 0;
356
-		$aisdata168='';//six bit array of ascii characters
356
+		$aisdata168 = ''; //six bit array of ascii characters
357 357
 		$ais_nmea_array = str_split($_itu); // convert to an array
358 358
 		foreach ($ais_nmea_array as $value) {
359 359
 			$dec = $this->ascii_2_dec($value);
360 360
 			$bit8 = $this->asciidec_2_8bit($dec);
361 361
 			$bit6 = $this->dec_2_6bit($bit8);
362 362
 			//echo $value ."-" .$bit6 ."";
363
-			$aisdata168 .=$bit6;
363
+			$aisdata168 .= $bit6;
364 364
 		}
365 365
 		//echo $aisdata168 . "<br/>";
366 366
 		//return $this->decode_ais($aisdata168, $aux);
@@ -383,24 +383,24 @@  discard block
 block discarded – undo
383 383
 		// calculate checksum after ! till *
384 384
 		// assume 1st ! is valid
385 385
 		// find * ensure that it is at correct position
386
-		$end = strrpos ( $rawdata , '*' );
386
+		$end = strrpos($rawdata, '*');
387 387
 		if ($end === FALSE) return -1; // check for NULLS!!!
388
-		$cs = substr( $rawdata, $end + 1 );
389
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
390
-		$dcs = (int)hexdec( $cs );
391
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
392
-		if ( $chksum == $dcs ) { // NMEA checksum pass
388
+		$cs = substr($rawdata, $end + 1);
389
+		if (strlen($cs) != 2) return -1; // correct cs length
390
+		$dcs = (int) hexdec($cs);
391
+		for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum
392
+		if ($chksum == $dcs) { // NMEA checksum pass
393 393
 			$pcs = explode(',', $rawdata);
394 394
 			// !AI??? identifier
395 395
 			if (!isset($pcs[1])) {
396 396
 				echo "ERROR,INVALID_DATA ".time()." $rawdata\n";
397 397
 				return -1;
398 398
 			}
399
-			$num_seq = (int)$pcs[1]; // number of sequences
400
-			$seq = (int)$pcs[2]; // get sequence
399
+			$num_seq = (int) $pcs[1]; // number of sequences
400
+			$seq = (int) $pcs[2]; // get sequence
401 401
 			// get msg sequence id
402 402
 			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
403
-			else $msg_sid = (int)$pcs[3]; // multipart message
403
+			else $msg_sid = (int) $pcs[3]; // multipart message
404 404
 			$ais_ch = $pcs[4]; // get AIS channel
405 405
 			// message sequence checking
406 406
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 					}
434 434
 				}
435 435
 				$itu = $itu.$pcs[5]; // get itu message
436
-				$filler += (int)$pcs[6][0]; // get filler
436
+				$filler += (int) $pcs[6][0]; // get filler
437 437
 				if ($num_seq == 1 // valid single message
438 438
 				    || $num_seq == $pseq // valid multi-part message
439 439
 				) {
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
 		$cbuf = $cbuf.$ibuf;
454 454
 		$last_pos = 0;
455 455
 		$result = new stdClass();
456
-		while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) {
456
+		while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) {
457 457
 		//while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) {
458 458
 			//DEBUG echo $cbuf;
459
-			if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim?
459
+			if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim?
460 460
 				$tst = substr($cbuf, $start - 3, ($end - $start + 3));
461 461
 				//DEBUG echo "[$start $end $tst]\n";
462
-				$result = $this->process_ais_raw( $tst, "" );
462
+				$result = $this->process_ais_raw($tst, "");
463 463
 				$last_pos = $end + 1;
464 464
 			} else break;
465 465
 		}
@@ -471,41 +471,41 @@  discard block
 block discarded – undo
471 471
 	// incoming data from serial or IP comms
472 472
 	public function process_ais_line($cbuf) {
473 473
 		$result = new stdClass();
474
-		$start = strpos($cbuf,"VDM");
474
+		$start = strpos($cbuf, "VDM");
475 475
 		$tst = substr($cbuf, $start - 3);
476
-		$result = $this->process_ais_raw( $tst, "" );
476
+		$result = $this->process_ais_raw($tst, "");
477 477
 		return $result;
478 478
 	}
479 479
 
480 480
 	/* AIS Encoding
481 481
 	*/
482
-	private function mk_ais_lat( $lat ) {
482
+	private function mk_ais_lat($lat) {
483 483
 		//$lat = 1.2569;
484
-		if ($lat<0.0) {
484
+		if ($lat < 0.0) {
485 485
 			$lat = -$lat;
486
-			$neg=true;
487
-		} else $neg=false;
486
+			$neg = true;
487
+		} else $neg = false;
488 488
 		$latd = 0x00000000;
489
-		$latd = intval ($lat * 600000.0);
490
-		if ($neg==true) {
489
+		$latd = intval($lat*600000.0);
490
+		if ($neg == true) {
491 491
 			$latd = ~$latd;
492
-			$latd+=1;
492
+			$latd += 1;
493 493
 			$latd &= 0x07FFFFFF;
494 494
 		}
495 495
 		return $latd;
496 496
 	}
497 497
 
498
-	private function mk_ais_lon( $lon ) {
498
+	private function mk_ais_lon($lon) {
499 499
 		//$lon = 103.851;
500
-		if ($lon<0.0) {
500
+		if ($lon < 0.0) {
501 501
 			$lon = -$lon;
502
-			$neg=true;
503
-		} else $neg=false;
502
+			$neg = true;
503
+		} else $neg = false;
504 504
 		$lond = 0x00000000;
505
-		$lond = intval ($lon * 600000.0);
506
-		if ($neg==true) {
505
+		$lond = intval($lon*600000.0);
506
+		if ($neg == true) {
507 507
 			$lond = ~$lond;
508
-			$lond+=1;
508
+			$lond += 1;
509 509
 			$lond &= 0x0FFFFFFF;
510 510
 		}
511 511
 		return $lond;
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
 
514 514
 	private function char2bin($name, $max_len) {
515 515
 		$len = strlen($name);
516
-		if ($len > $max_len) $name = substr($name,0,$max_len);
517
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
+		if ($len > $max_len) $name = substr($name, 0, $max_len);
517
+		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6);
518 518
 		else $pad = '';
519 519
 		$rv = '';
520 520
 		$ais_chars = array(
@@ -531,26 +531,26 @@  discard block
 block discarded – undo
531 531
 		if ($_a) foreach ($_a as $_1) {
532 532
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
533 533
 			else $dec = 0;
534
-			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
534
+			$bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT);
535 535
 			$rv .= $bin;
536 536
 			//echo "$_1 $dec ($bin)<br/>";
537 537
 		}
538 538
 		return $rv.$pad;
539 539
 	}
540 540
 
541
-	private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') {
541
+	private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') {
542 542
 		$len_bit = strlen($_enc);
543
-		$rem6 = $len_bit % 6;
543
+		$rem6 = $len_bit%6;
544 544
 		$pad6_len = 0;
545 545
 		if ($rem6) $pad6_len = 6 - $rem6;
546 546
 		//echo  $pad6_len.'<br>';
547 547
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
548
-		$len_enc = strlen($_enc) / 6;
548
+		$len_enc = strlen($_enc)/6;
549 549
 		//echo $_enc.' '.$len_enc.'<br/>';
550 550
 		$itu = '';
551
-		for ($i=0; $i<$len_enc; $i++) {
552
-			$offset = $i * 6;
553
-			$dec = bindec(substr($_enc,$offset,6));
551
+		for ($i = 0; $i < $len_enc; $i++) {
552
+			$offset = $i*6;
553
+			$dec = bindec(substr($_enc, $offset, 6));
554 554
 			if ($dec < 40) $dec += 48;
555 555
 			else $dec += 56;
556 556
 			//echo chr($dec)." $dec<br/>";
@@ -560,15 +560,15 @@  discard block
 block discarded – undo
560 560
 		$chksum = 0;
561 561
 		$itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0";
562 562
 		$len_itu = strlen($itu);
563
-		for ($i=0; $i<$len_itu; $i++) {
564
-			$chksum ^= ord( $itu[$i] );
563
+		for ($i = 0; $i < $len_itu; $i++) {
564
+			$chksum ^= ord($itu[$i]);
565 565
 		}
566
-		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
567
-		$lsb = $chksum & 0x0F;
568
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
566
+		$hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
567
+		$lsb = $chksum&0x0F;
568
+		if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb];
569 569
 		else $lsbc = '0';
570
-		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
571
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
+		$msb = (($chksum&0xF0) >> 4)&0x0F;
571
+		if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb];
572 572
 		else $msbc = '0';
573 573
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
574 574
 		return $itu;
@@ -593,14 +593,14 @@  discard block
 block discarded – undo
593 593
 
594 594
 	public function mmsitype($mmsi) {
595 595
 		if (strlen($mmsi) == 9) {
596
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
597
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
598
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
599
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
600
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
601
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
602
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
603
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
596
+			if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
597
+			elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device';
598
+			elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
599
+			elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft';
600
+			elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship';
601
+			elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation';
602
+			elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations';
603
+			elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships';
604 604
 			else return 'Ship';
605 605
 		}
606 606
 
@@ -611,19 +611,19 @@  discard block
 block discarded – undo
611 611
 		global $globalDebug;
612 612
 		$result = array();
613 613
 		$data = new stdClass();
614
-		$start = strpos($buffer,"VDM");
614
+		$start = strpos($buffer, "VDM");
615 615
 		$tst = substr($buffer, $start - 3);
616
-		$data = $this->process_ais_raw( $tst, "" );
616
+		$data = $this->process_ais_raw($tst, "");
617 617
 		if (!is_object($data)) {
618 618
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
619 619
 			return array();
620 620
 		}
621 621
 		if ($data->lon != 0) $result['longitude'] = $data->lon;
622 622
 		if ($data->lat != 0) $result['latitude'] = $data->lat;
623
-		$result['ident'] = trim(str_replace('@','',$data->name));
623
+		$result['ident'] = trim(str_replace('@', '', $data->name));
624 624
 		$result['timestamp'] = $data->ts;
625 625
 		$result['mmsi'] = $data->mmsi;
626
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
626
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
627 627
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
628 628
 		if ($data->sog != -1.0) $result['speed'] = $data->sog;
629 629
 		if ($data->heading !== '') $result['heading'] = $data->heading;
@@ -633,16 +633,16 @@  discard block
 block discarded – undo
633 633
 		if ($data->type !== '') $result['type'] = $data->type;
634 634
 		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
635 635
 		if ($data->imo !== '') $result['imo'] = $data->imo;
636
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
636
+		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign));
637 637
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
638
-			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
638
+			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
639 639
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
640 640
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
641
-			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
641
+			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
642 642
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
643 643
 		}
644 644
 		if ($data->destination != '') {
645
-			$dest = trim(str_replace('@','',$data->destination));
645
+			$dest = trim(str_replace('@', '', $data->destination));
646 646
 			if ($dest != '') $result['destination'] = $dest;
647 647
 		}
648 648
 		$result['all'] = (array) $data;
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Spacing   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/class.Image.php');
3 3
 $global_query = "SELECT marine_output.* FROM marine_output";
4 4
 
5
-class Marine{
5
+class Marine {
6 6
 	public $db;
7 7
 	
8 8
 	public function __construct($dbc = null) {
@@ -17,33 +17,33 @@  discard block
 block discarded – undo
17 17
 	* @return Array the SQL part
18 18
 	*/
19 19
 	
20
-	public function getFilter($filter = array(),$where = false,$and = false) {
20
+	public function getFilter($filter = array(), $where = false, $and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
22 22
 		$filters = array();
23 23
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
24 24
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
25 25
 				$filters = $globalStatsFilters[$globalFilterName];
26 26
 			} else {
27
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
27
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
28 28
 			}
29 29
 		}
30 30
 		if (isset($filter[0]['source'])) {
31
-			$filters = array_merge($filters,$filter);
31
+			$filters = array_merge($filters, $filter);
32 32
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
33
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
34 34
 		$filter_query_join = '';
35 35
 		$filter_query_where = '';
36
-		foreach($filters as $flt) {
36
+		foreach ($filters as $flt) {
37 37
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
38 38
 				if (isset($flt['source'])) {
39
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
39
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_output.format_source IN ('".implode("','", $flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
40 40
 				} else {
41
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
41
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
42 42
 				}
43 43
 			}
44 44
 		}
45 45
 		if (isset($filter['source']) && !empty($filter['source'])) {
46
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
46
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
47 47
 		}
48 48
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
49 49
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
76 76
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
77 77
 		if ($filter_query_where != '') {
78
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
78
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
79 79
 		}
80 80
 		$filter_query = $filter_query_join.$filter_query_where;
81 81
 		return $filter_query;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	* @return Array the spotter information
91 91
 	*
92 92
 	*/
93
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
93
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
94 94
 	{
95 95
 		date_default_timezone_set('UTC');
96 96
 		if (!is_string($query))
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 			$sth = $this->db->prepare($query.$limitQuery);
111 111
 			$sth->execute($params);
112 112
 		} catch (PDOException $e) {
113
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
113
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
114 114
 			exit();
115 115
 		}
116 116
 		
117 117
 		$num_rows = 0;
118 118
 		$spotter_array = array();
119
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
119
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
120 120
 		{
121 121
 			$num_rows++;
122 122
 			$temp_array = array();
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 			}
149 149
 			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
150 150
 
151
-			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
151
+			if (isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
152 152
 			{
153 153
 				$Image = new Image($this->db);
154
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
154
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'], '', $temp_array['ident']);
155 155
 				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
156 156
 				unset($Image);
157 157
 				if (count($image_array) > 0) {
@@ -187,17 +187,17 @@  discard block
 block discarded – undo
187 187
 				{
188 188
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
189 189
 				} else {
190
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
190
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
191 191
 				}
192 192
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
193
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
194
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
193
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
194
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
195 195
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
196 196
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
197 197
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
198 198
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
199
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
200
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
199
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
200
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
201 201
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
202 202
 					}
203 203
 				}
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 		if ($limit != "")
231 231
 		{
232 232
 			$limit_array = explode(",", $limit);
233
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
234
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
233
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
234
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
235 235
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
236 236
 			{
237 237
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 		} else {
246 246
 			$orderby_query = " ORDER BY marine_output.date DESC";
247 247
 		}
248
-		$query  = $global_query.$filter_query." ".$orderby_query;
249
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
248
+		$query = $global_query.$filter_query." ".$orderby_query;
249
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
250 250
 		return $spotter_array;
251 251
 	}
252 252
     
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 		if ($id == '') return array();
265 265
 		$additional_query = "marine_output.fammarine_id = :id";
266 266
 		$query_values = array(':id' => $id);
267
-		$query  = $global_query." WHERE ".$additional_query." ";
268
-		$spotter_array = $this->getDataFromDB($query,$query_values);
267
+		$query = $global_query." WHERE ".$additional_query." ";
268
+		$spotter_array = $this->getDataFromDB($query, $query_values);
269 269
 		return $spotter_array;
270 270
 	}
271 271
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 		$query_values = array();
285 285
 		$limit_query = '';
286 286
 		$additional_query = '';
287
-		$filter_query = $this->getFilter($filter,true,true);
287
+		$filter_query = $this->getFilter($filter, true, true);
288 288
 		if ($ident != "")
289 289
 		{
290 290
 			if (!is_string($ident))
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 		{
301 301
 			$limit_array = explode(",", $limit);
302 302
 			
303
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
304
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
303
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
304
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
305 305
 			
306 306
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
307 307
 			{
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		return $spotter_array;
326 326
 	}
327 327
 	
328
-	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array())
328
+	public function getMarineDataByDate($date = '', $limit = '', $sort = '', $filter = array())
329 329
 	{
330 330
 		global $global_query, $globalTimezone, $globalDBdriver;
331 331
 		
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		$limit_query = '';
334 334
 		$additional_query = '';
335 335
 
336
-		$filter_query = $this->getFilter($filter,true,true);
336
+		$filter_query = $this->getFilter($filter, true, true);
337 337
 		
338 338
 		if ($date != "")
339 339
 		{
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
 		{
360 360
 			$limit_array = explode(",", $limit);
361 361
 			
362
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
363
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
362
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
363
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
364 364
 			
365 365
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
366 366
 			{
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	* @return Array list of source name
392 392
 	*
393 393
 	*/
394
-	public function getAllSourceName($type = '',$filters = array())
394
+	public function getAllSourceName($type = '', $filters = array())
395 395
 	{
396
-		$filter_query = $this->getFilter($filters,true,true);
396
+		$filter_query = $this->getFilter($filters, true, true);
397 397
 		$query_values = array();
398
-		$query  = "SELECT DISTINCT marine_output.source_name 
398
+		$query = "SELECT DISTINCT marine_output.source_name 
399 399
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
400 400
 		if ($type != '') {
401 401
 			$query_values = array(':type' => $type);
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		$source_array = array();
411 411
 		$temp_array = array();
412 412
 		
413
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
413
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
414 414
 		{
415 415
 			$temp_array['source_name'] = $row['source_name'];
416 416
 			$source_array[] = $temp_array;
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	*/
428 428
 	public function getAllIdents($filters = array())
429 429
 	{
430
-		$filter_query = $this->getFilter($filters,true,true);
431
-		$query  = "SELECT DISTINCT marine_output.ident
430
+		$filter_query = $this->getFilter($filters, true, true);
431
+		$query = "SELECT DISTINCT marine_output.ident
432 432
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
433 433
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
434 434
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 		$ident_array = array();
439 439
 		$temp_array = array();
440 440
 		
441
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
441
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
442 442
 		{
443 443
 			$temp_array['ident'] = $row['ident'];
444 444
 			$ident_array[] = $temp_array;
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 	*/
456 456
 	public function getIdentity($mmsi)
457 457
 	{
458
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
458
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
459 459
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
460 460
 		$sth = $this->db->prepare($query);
461 461
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -468,23 +468,23 @@  discard block
 block discarded – undo
468 468
 	* Add identity
469 469
 	*
470 470
 	*/
471
-	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
471
+	public function addIdentity($mmsi, $imo, $ident, $callsign, $type)
472 472
 	{
473
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
473
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
474 474
 		if ($mmsi != '') {
475
-			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
476
-			$ident = filter_var($ident,FILTER_SANITIZE_STRING);
477
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
478
-			$type = filter_var($type,FILTER_SANITIZE_STRING);
475
+			$imo = filter_var($imo, FILTER_SANITIZE_NUMBER_INT);
476
+			$ident = filter_var($ident, FILTER_SANITIZE_STRING);
477
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
478
+			$type = filter_var($type, FILTER_SANITIZE_STRING);
479 479
 			$identinfo = $this->getIdentity($mmsi);
480 480
 			if (empty($identinfo)) {
481
-				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
481
+				$query = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
482 482
 				$sth = $this->db->prepare($query);
483
-				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
483
+				$sth->execute(array(':mmsi' => $mmsi, ':imo' => $imo, ':call_sign' => $callsign, ':ship_name' => $ident, ':type' => $type));
484 484
 			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) {
485
-				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
485
+				$query = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
486 486
 				$sth = $this->db->prepare($query);
487
-				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type));
487
+				$sth->execute(array(':mmsi' => $mmsi, ':ship_name' => $ident, ':type' => $type));
488 488
 			}
489 489
 		}
490 490
 	}
@@ -505,12 +505,12 @@  discard block
 block discarded – undo
505 505
 		} else $offset = '+00:00';
506 506
 
507 507
 		if ($globalDBdriver == 'mysql') {
508
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
508
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
509 509
 								FROM marine_output
510 510
 								WHERE marine_output.date <> '' 
511 511
 								ORDER BY marine_output.date ASC LIMIT 0,100";
512 512
 		} else {
513
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
513
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
514 514
 								FROM marine_output
515 515
 								WHERE marine_output.date <> '' 
516 516
 								ORDER BY marine_output.date ASC LIMIT 0,100";
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$date_array = array();
523 523
 		$temp_array = array();
524 524
 		
525
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
525
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
526 526
 		{
527 527
 			$temp_array['date'] = $row['date'];
528 528
 
@@ -540,10 +540,10 @@  discard block
 block discarded – undo
540 540
 	* @return String success or false
541 541
 	*
542 542
 	*/
543
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
543
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
544 544
 	{
545 545
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
546
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
546
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
547 547
 		try {
548 548
 			$sth = $this->db->prepare($query);
549 549
 			$sth->execute($query_values);
@@ -562,11 +562,11 @@  discard block
 block discarded – undo
562 562
 	* @return String success or false
563 563
 	*
564 564
 	*/
565
-	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
565
+	public function updateStatusMarineData($fammarine_id = '', $status_id = '', $status = '')
566 566
 	{
567 567
 
568 568
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
569
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
569
+                $query_values = array(':fammarine_id' => $fammarine_id, ':status' => $status, ':status_id' => $status_id);
570 570
 
571 571
 		try {
572 572
 			$sth = $this->db->prepare($query);
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
590 590
 	{
591 591
 		$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';
592
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
592
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
593 593
 
594 594
 		try {
595 595
 			$sth = $this->db->prepare($query);
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	* @param String $verticalrate vertival rate of flight
628 628
 	* @return String success or false
629 629
 	*/
630
-	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$format_source = '', $source_name = '')
630
+	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $format_source = '', $source_name = '')
631 631
 	{
632 632
 		global $globalURL, $globalMarineImageFetch;
633 633
 		
@@ -694,30 +694,30 @@  discard block
 block discarded – undo
694 694
 		}
695 695
 
696 696
     
697
-		if ($date == "" || strtotime($date) < time()-20*60)
697
+		if ($date == "" || strtotime($date) < time() - 20*60)
698 698
 		{
699 699
 			$date = date("Y-m-d H:i:s", time());
700 700
 		}
701 701
 
702
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
703
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
704
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
705
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
706
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
707
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
708
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
709
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
710
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
711
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
712
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
713
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
714
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
715
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
702
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
703
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
704
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
705
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
706
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
707
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
708
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
709
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
710
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
711
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
712
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
713
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
714
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
715
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
716 716
 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
717 717
 			$Image = new Image($this->db);
718
-			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
718
+			$image_array = $Image->getMarineImage($mmsi, $imo, $ident);
719 719
 			if (!isset($image_array[0]['mmsi'])) {
720
-				$Image->addMarineImage($mmsi,$imo,$ident);
720
+				$Image->addMarineImage($mmsi, $imo, $ident);
721 721
 			}
722 722
 			unset($Image);
723 723
 		}
@@ -728,10 +728,10 @@  discard block
 block discarded – undo
728 728
 		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
729 729
 		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
730 730
 		if ($arrival_date == '') $arrival_date = NULL;
731
-		$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) 
731
+		$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) 
732 732
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
733 733
 
734
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
734
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
735 735
 		try {
736 736
 			$sth = $this->db->prepare($query);
737 737
 			$sth->execute($query_values);
@@ -755,13 +755,13 @@  discard block
 block discarded – undo
755 755
 	{
756 756
 		global $globalDBdriver, $globalTimezone;
757 757
 		if ($globalDBdriver == 'mysql') {
758
-			$query  = "SELECT marine_output.ident FROM marine_output 
758
+			$query = "SELECT marine_output.ident FROM marine_output 
759 759
 								WHERE marine_output.ident = :ident 
760 760
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
761 761
 								AND marine_output.date < UTC_TIMESTAMP()";
762 762
 			$query_data = array(':ident' => $ident);
763 763
 		} else {
764
-			$query  = "SELECT marine_output.ident FROM marine_output 
764
+			$query = "SELECT marine_output.ident FROM marine_output 
765 765
 								WHERE marine_output.ident = :ident 
766 766
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
767 767
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 		
771 771
 		$sth = $this->db->prepare($query);
772 772
 		$sth->execute($query_data);
773
-    		$ident_result='';
774
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
773
+    		$ident_result = '';
774
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
775 775
 		{
776 776
 			$ident_result = $row['ident'];
777 777
 		}
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
 				return false;
798 798
 			} else {
799 799
 				$q_array = explode(" ", $q);
800
-				foreach ($q_array as $q_item){
801
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
800
+				foreach ($q_array as $q_item) {
801
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
802 802
 					$additional_query .= " AND (";
803 803
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
804 804
 					$additional_query .= ")";
@@ -806,11 +806,11 @@  discard block
 block discarded – undo
806 806
 			}
807 807
 		}
808 808
 		if ($globalDBdriver == 'mysql') {
809
-			$query  = "SELECT marine_output.* FROM marine_output 
809
+			$query = "SELECT marine_output.* FROM marine_output 
810 810
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
811 811
 				AND marine_output.date < UTC_TIMESTAMP()";
812 812
 		} else {
813
-			$query  = "SELECT marine_output.* FROM marine_output 
813
+			$query = "SELECT marine_output.* FROM marine_output 
814 814
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
815 815
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
816 816
 		}
@@ -829,16 +829,16 @@  discard block
 block discarded – undo
829 829
 	*
830 830
 	*/
831 831
 
832
-	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
832
+	public function countAllMarineOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array())
833 833
 	{
834 834
 		global $globalDBdriver, $globalArchive;
835 835
 		//$filter_query = $this->getFilter($filters,true,true);
836
-		$Connection= new Connection($this->db);
836
+		$Connection = new Connection($this->db);
837 837
 		if (!$Connection->tableExists('countries')) return array();
838 838
 		require_once('class.SpotterLive.php');
839 839
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
840 840
 			$MarineLive = new MarineLive($this->db);
841
-			$filter_query = $MarineLive->getFilter($filters,true,true);
841
+			$filter_query = $MarineLive->getFilter($filters, true, true);
842 842
 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
843 843
 			if ($olderthanmonths > 0) {
844 844
 				if ($globalDBdriver == 'mysql') {
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 		} else {
859 859
 			require_once(dirname(__FILE__)."/class.MarineArchive.php");
860 860
 			$MarineArchive = new MarineArchive($this->db);
861
-			$filter_query = $MarineArchive->getFilter($filters,true,true);
861
+			$filter_query = $MarineArchive->getFilter($filters, true, true);
862 862
 			$filter_query .= " over_country <> ''";
863 863
 			if ($olderthanmonths > 0) {
864 864
 				if ($globalDBdriver == 'mysql') {
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 		$flight_array = array();
887 887
 		$temp_array = array();
888 888
         
889
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
889
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
890 890
 		{
891 891
 			$temp_array['marine_count'] = $row['nb'];
892 892
 			$temp_array['marine_country'] = $row['name'];
@@ -905,11 +905,11 @@  discard block
 block discarded – undo
905 905
 	* @return Array the callsign list
906 906
 	*
907 907
 	*/
908
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
908
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
909 909
 	{
910 910
 		global $globalDBdriver;
911
-		$filter_query = $this->getFilter($filters,true,true);
912
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
911
+		$filter_query = $this->getFilter($filters, true, true);
912
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
913 913
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
914 914
 		 if ($olderthanmonths > 0) {
915 915
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -923,28 +923,28 @@  discard block
 block discarded – undo
923 923
 		if ($year != '') {
924 924
 			if ($globalDBdriver == 'mysql') {
925 925
 				$query .= " AND YEAR(marine_output.date) = :year";
926
-				$query_values = array_merge($query_values,array(':year' => $year));
926
+				$query_values = array_merge($query_values, array(':year' => $year));
927 927
 			} else {
928 928
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
929
-				$query_values = array_merge($query_values,array(':year' => $year));
929
+				$query_values = array_merge($query_values, array(':year' => $year));
930 930
 			}
931 931
 		}
932 932
 		if ($month != '') {
933 933
 			if ($globalDBdriver == 'mysql') {
934 934
 				$query .= " AND MONTH(marine_output.date) = :month";
935
-				$query_values = array_merge($query_values,array(':month' => $month));
935
+				$query_values = array_merge($query_values, array(':month' => $month));
936 936
 			} else {
937 937
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
938
-				$query_values = array_merge($query_values,array(':month' => $month));
938
+				$query_values = array_merge($query_values, array(':month' => $month));
939 939
 			}
940 940
 		}
941 941
 		if ($day != '') {
942 942
 			if ($globalDBdriver == 'mysql') {
943 943
 				$query .= " AND DAY(marine_output.date) = :day";
944
-				$query_values = array_merge($query_values,array(':day' => $day));
944
+				$query_values = array_merge($query_values, array(':day' => $day));
945 945
 			} else {
946 946
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
947
-				$query_values = array_merge($query_values,array(':day' => $day));
947
+				$query_values = array_merge($query_values, array(':day' => $day));
948 948
 			}
949 949
 		}
950 950
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 		$callsign_array = array();
957 957
 		$temp_array = array();
958 958
         
959
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
959
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
960 960
 		{
961 961
 			$temp_array['callsign_icao'] = $row['ident'];
962 962
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 		$date_array = array();
1009 1009
 		$temp_array = array();
1010 1010
         
1011
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1011
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1012 1012
 		{
1013 1013
 			$temp_array['date_name'] = $row['date_name'];
1014 1014
 			$temp_array['date_count'] = $row['date_count'];
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 			$datetime = new DateTime();
1035 1035
 			$offset = $datetime->format('P');
1036 1036
 		} else $offset = '+00:00';
1037
-		$filter_query = $this->getFilter($filters,true,true);
1037
+		$filter_query = $this->getFilter($filters, true, true);
1038 1038
 		if ($globalDBdriver == 'mysql') {
1039 1039
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1040 1040
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 		$date_array = array();
1056 1056
 		$temp_array = array();
1057 1057
         
1058
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1058
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1059 1059
 		{
1060 1060
 			$temp_array['date_name'] = $row['date_name'];
1061 1061
 			$temp_array['date_count'] = $row['date_count'];
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 			$datetime = new DateTime();
1081 1081
 			$offset = $datetime->format('P');
1082 1082
 		} else $offset = '+00:00';
1083
-		$filter_query = $this->getFilter($filters,true,true);
1083
+		$filter_query = $this->getFilter($filters, true, true);
1084 1084
 		if ($globalDBdriver == 'mysql') {
1085 1085
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1086 1086
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 		$date_array = array();
1102 1102
 		$temp_array = array();
1103 1103
         
1104
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1104
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1105 1105
 		{
1106 1106
 			$temp_array['date_name'] = $row['date_name'];
1107 1107
 			$temp_array['date_count'] = $row['date_count'];
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 		$date_array = array();
1149 1149
 		$temp_array = array();
1150 1150
         
1151
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1151
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1152 1152
 		{
1153 1153
 			$temp_array['month_name'] = $row['month_name'];
1154 1154
 			$temp_array['year_name'] = $row['year_name'];
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 			$datetime = new DateTime();
1178 1178
 			$offset = $datetime->format('P');
1179 1179
 		} else $offset = '+00:00';
1180
-		$filter_query = $this->getFilter($filters,true,true);
1180
+		$filter_query = $this->getFilter($filters, true, true);
1181 1181
 		if ($globalDBdriver == 'mysql') {
1182 1182
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
1183 1183
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 		$date_array = array();
1199 1199
 		$temp_array = array();
1200 1200
         
1201
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1201
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1202 1202
 		{
1203 1203
 			$temp_array['year_name'] = $row['year_name'];
1204 1204
 			$temp_array['month_name'] = $row['month_name'];
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
 	* @return Array the hour list
1219 1219
 	*
1220 1220
 	*/
1221
-	public function countAllHours($orderby,$filters = array())
1221
+	public function countAllHours($orderby, $filters = array())
1222 1222
 	{
1223 1223
 		global $globalTimezone, $globalDBdriver;
1224 1224
 		if ($globalTimezone != '') {
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
 		$hour_array = array();
1267 1267
 		$temp_array = array();
1268 1268
         
1269
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1269
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1270 1270
 		{
1271 1271
 			$temp_array['hour_name'] = $row['hour_name'];
1272 1272
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1288,8 +1288,8 @@  discard block
 block discarded – undo
1288 1288
 	public function countAllHoursByDate($date, $filters = array())
1289 1289
 	{
1290 1290
 		global $globalTimezone, $globalDBdriver;
1291
-		$filter_query = $this->getFilter($filters,true,true);
1292
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1291
+		$filter_query = $this->getFilter($filters, true, true);
1292
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1293 1293
 		if ($globalTimezone != '') {
1294 1294
 			date_default_timezone_set($globalTimezone);
1295 1295
 			$datetime = new DateTime($date);
@@ -1297,12 +1297,12 @@  discard block
 block discarded – undo
1297 1297
 		} else $offset = '+00:00';
1298 1298
 
1299 1299
 		if ($globalDBdriver == 'mysql') {
1300
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1300
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1301 1301
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1302 1302
 								GROUP BY hour_name 
1303 1303
 								ORDER BY hour_name ASC";
1304 1304
 		} else {
1305
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1305
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1306 1306
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1307 1307
 								GROUP BY hour_name 
1308 1308
 								ORDER BY hour_name ASC";
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
 		$hour_array = array();
1315 1315
 		$temp_array = array();
1316 1316
         
1317
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1317
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1318 1318
 		{
1319 1319
 			$temp_array['hour_name'] = $row['hour_name'];
1320 1320
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1336,8 +1336,8 @@  discard block
 block discarded – undo
1336 1336
 	public function countAllHoursByIdent($ident, $filters = array())
1337 1337
 	{
1338 1338
 		global $globalTimezone, $globalDBdriver;
1339
-		$filter_query = $this->getFilter($filters,true,true);
1340
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1339
+		$filter_query = $this->getFilter($filters, true, true);
1340
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1341 1341
 		if ($globalTimezone != '') {
1342 1342
 			date_default_timezone_set($globalTimezone);
1343 1343
 			$datetime = new DateTime();
@@ -1345,12 +1345,12 @@  discard block
 block discarded – undo
1345 1345
 		} else $offset = '+00:00';
1346 1346
 
1347 1347
 		if ($globalDBdriver == 'mysql') {
1348
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1348
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1349 1349
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1350 1350
 								GROUP BY hour_name 
1351 1351
 								ORDER BY hour_name ASC";
1352 1352
 		} else {
1353
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1353
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1354 1354
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1355 1355
 								GROUP BY hour_name 
1356 1356
 								ORDER BY hour_name ASC";
@@ -1358,12 +1358,12 @@  discard block
 block discarded – undo
1358 1358
       
1359 1359
 		
1360 1360
 		$sth = $this->db->prepare($query);
1361
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1361
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1362 1362
       
1363 1363
 		$hour_array = array();
1364 1364
 		$temp_array = array();
1365 1365
         
1366
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1366
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1367 1367
 		{
1368 1368
 			$temp_array['hour_name'] = $row['hour_name'];
1369 1369
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1382,33 +1382,33 @@  discard block
 block discarded – undo
1382 1382
 	* @return Integer the number of vessels
1383 1383
 	*
1384 1384
 	*/
1385
-	public function countOverallMarine($filters = array(),$year = '',$month = '')
1385
+	public function countOverallMarine($filters = array(), $year = '', $month = '')
1386 1386
 	{
1387 1387
 		global $globalDBdriver;
1388 1388
 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1389
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1389
+		$queryi = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1390 1390
 		$query_values = array();
1391 1391
 		$query = '';
1392 1392
 		if ($year != '') {
1393 1393
 			if ($globalDBdriver == 'mysql') {
1394 1394
 				$query .= " AND YEAR(marine_output.date) = :year";
1395
-				$query_values = array_merge($query_values,array(':year' => $year));
1395
+				$query_values = array_merge($query_values, array(':year' => $year));
1396 1396
 			} else {
1397 1397
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1398
-				$query_values = array_merge($query_values,array(':year' => $year));
1398
+				$query_values = array_merge($query_values, array(':year' => $year));
1399 1399
 			}
1400 1400
 		}
1401 1401
 		if ($month != '') {
1402 1402
 			if ($globalDBdriver == 'mysql') {
1403 1403
 				$query .= " AND MONTH(marine_output.date) = :month";
1404
-				$query_values = array_merge($query_values,array(':month' => $month));
1404
+				$query_values = array_merge($query_values, array(':month' => $month));
1405 1405
 			} else {
1406 1406
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1407
-				$query_values = array_merge($query_values,array(':month' => $month));
1407
+				$query_values = array_merge($query_values, array(':month' => $month));
1408 1408
 			}
1409 1409
 		}
1410 1410
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1411
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1411
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1412 1412
 		
1413 1413
 		$sth = $this->db->prepare($queryi);
1414 1414
 		$sth->execute($query_values);
@@ -1421,32 +1421,32 @@  discard block
 block discarded – undo
1421 1421
 	* @return Integer the number of vessels
1422 1422
 	*
1423 1423
 	*/
1424
-	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1424
+	public function countOverallMarineTypes($filters = array(), $year = '', $month = '')
1425 1425
 	{
1426 1426
 		global $globalDBdriver;
1427
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1427
+		$queryi = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1428 1428
 		$query_values = array();
1429 1429
 		$query = '';
1430 1430
 		if ($year != '') {
1431 1431
 			if ($globalDBdriver == 'mysql') {
1432 1432
 				$query .= " AND YEAR(marine_output.date) = :year";
1433
-				$query_values = array_merge($query_values,array(':year' => $year));
1433
+				$query_values = array_merge($query_values, array(':year' => $year));
1434 1434
 			} else {
1435 1435
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1436
-				$query_values = array_merge($query_values,array(':year' => $year));
1436
+				$query_values = array_merge($query_values, array(':year' => $year));
1437 1437
 			}
1438 1438
 		}
1439 1439
 		if ($month != '') {
1440 1440
 			if ($globalDBdriver == 'mysql') {
1441 1441
 				$query .= " AND MONTH(marine_output.date) = :month";
1442
-				$query_values = array_merge($query_values,array(':month' => $month));
1442
+				$query_values = array_merge($query_values, array(':month' => $month));
1443 1443
 			} else {
1444 1444
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1445
-				$query_values = array_merge($query_values,array(':month' => $month));
1445
+				$query_values = array_merge($query_values, array(':month' => $month));
1446 1446
 			}
1447 1447
 		}
1448 1448
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1449
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1449
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1450 1450
 		
1451 1451
 		$sth = $this->db->prepare($queryi);
1452 1452
 		$sth->execute($query_values);
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 	public function countAllHoursFromToday($filters = array())
1464 1464
 	{
1465 1465
 		global $globalTimezone, $globalDBdriver;
1466
-		$filter_query = $this->getFilter($filters,true,true);
1466
+		$filter_query = $this->getFilter($filters, true, true);
1467 1467
 		if ($globalTimezone != '') {
1468 1468
 			date_default_timezone_set($globalTimezone);
1469 1469
 			$datetime = new DateTime();
@@ -1471,12 +1471,12 @@  discard block
 block discarded – undo
1471 1471
 		} else $offset = '+00:00';
1472 1472
 
1473 1473
 		if ($globalDBdriver == 'mysql') {
1474
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1474
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1475 1475
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1476 1476
 								GROUP BY hour_name 
1477 1477
 								ORDER BY hour_name ASC";
1478 1478
 		} else {
1479
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1479
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1480 1480
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1481 1481
 								GROUP BY hour_name 
1482 1482
 								ORDER BY hour_name ASC";
@@ -1488,7 +1488,7 @@  discard block
 block discarded – undo
1488 1488
 		$hour_array = array();
1489 1489
 		$temp_array = array();
1490 1490
         
1491
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1491
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1492 1492
 		{
1493 1493
 			$temp_array['hour_name'] = $row['hour_name'];
1494 1494
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1507,9 +1507,9 @@  discard block
 block discarded – undo
1507 1507
 	*/
1508 1508
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1509 1509
 	{
1510
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1510
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1511 1511
 
1512
-		$query  = "SELECT marine_output.marine_id
1512
+		$query = "SELECT marine_output.marine_id
1513 1513
 				FROM marine_output 
1514 1514
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1515 1515
         
@@ -1517,7 +1517,7 @@  discard block
 block discarded – undo
1517 1517
 		$sth = $this->db->prepare($query);
1518 1518
 		$sth->execute();
1519 1519
 
1520
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1520
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1521 1521
 		{
1522 1522
 			return $row['marine_id'];
1523 1523
 		}
@@ -1542,23 +1542,23 @@  discard block
 block discarded – undo
1542 1542
 		}
1543 1543
 		
1544 1544
 		$current_date = date("Y-m-d H:i:s");
1545
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1545
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1546 1546
 		
1547 1547
 		$diff = abs(strtotime($current_date) - strtotime($date));
1548 1548
 
1549
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1549
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1550 1550
 		$years = $time_array['years'];
1551 1551
 		
1552
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1552
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1553 1553
 		$months = $time_array['months'];
1554 1554
 		
1555
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1555
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1556 1556
 		$days = $time_array['days'];
1557
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1557
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1558 1558
 		$hours = $time_array['hours'];
1559
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1559
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1560 1560
 		$minutes = $time_array['minutes'];
1561
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1561
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1562 1562
 		
1563 1563
 		return $time_array;
1564 1564
 	}
@@ -1581,63 +1581,63 @@  discard block
 block discarded – undo
1581 1581
 			$temp_array['direction_degree'] = $direction;
1582 1582
 			$temp_array['direction_shortname'] = "N";
1583 1583
 			$temp_array['direction_fullname'] = "North";
1584
-		} elseif ($direction >= 22.5 && $direction < 45){
1584
+		} elseif ($direction >= 22.5 && $direction < 45) {
1585 1585
 			$temp_array['direction_degree'] = $direction;
1586 1586
 			$temp_array['direction_shortname'] = "NNE";
1587 1587
 			$temp_array['direction_fullname'] = "North-Northeast";
1588
-		} elseif ($direction >= 45 && $direction < 67.5){
1588
+		} elseif ($direction >= 45 && $direction < 67.5) {
1589 1589
 			$temp_array['direction_degree'] = $direction;
1590 1590
 			$temp_array['direction_shortname'] = "NE";
1591 1591
 			$temp_array['direction_fullname'] = "Northeast";
1592
-		} elseif ($direction >= 67.5 && $direction < 90){
1592
+		} elseif ($direction >= 67.5 && $direction < 90) {
1593 1593
 			$temp_array['direction_degree'] = $direction;
1594 1594
 			$temp_array['direction_shortname'] = "ENE";
1595 1595
 			$temp_array['direction_fullname'] = "East-Northeast";
1596
-		} elseif ($direction >= 90 && $direction < 112.5){
1596
+		} elseif ($direction >= 90 && $direction < 112.5) {
1597 1597
 			$temp_array['direction_degree'] = $direction;
1598 1598
 			$temp_array['direction_shortname'] = "E";
1599 1599
 			$temp_array['direction_fullname'] = "East";
1600
-		} elseif ($direction >= 112.5 && $direction < 135){
1600
+		} elseif ($direction >= 112.5 && $direction < 135) {
1601 1601
 			$temp_array['direction_degree'] = $direction;
1602 1602
 			$temp_array['direction_shortname'] = "ESE";
1603 1603
 			$temp_array['direction_fullname'] = "East-Southeast";
1604
-		} elseif ($direction >= 135 && $direction < 157.5){
1604
+		} elseif ($direction >= 135 && $direction < 157.5) {
1605 1605
 			$temp_array['direction_degree'] = $direction;
1606 1606
 			$temp_array['direction_shortname'] = "SE";
1607 1607
 			$temp_array['direction_fullname'] = "Southeast";
1608
-		} elseif ($direction >= 157.5 && $direction < 180){
1608
+		} elseif ($direction >= 157.5 && $direction < 180) {
1609 1609
 			$temp_array['direction_degree'] = $direction;
1610 1610
 			$temp_array['direction_shortname'] = "SSE";
1611 1611
 			$temp_array['direction_fullname'] = "South-Southeast";
1612
-		} elseif ($direction >= 180 && $direction < 202.5){
1612
+		} elseif ($direction >= 180 && $direction < 202.5) {
1613 1613
 			$temp_array['direction_degree'] = $direction;
1614 1614
 			$temp_array['direction_shortname'] = "S";
1615 1615
 			$temp_array['direction_fullname'] = "South";
1616
-		} elseif ($direction >= 202.5 && $direction < 225){
1616
+		} elseif ($direction >= 202.5 && $direction < 225) {
1617 1617
 			$temp_array['direction_degree'] = $direction;
1618 1618
 			$temp_array['direction_shortname'] = "SSW";
1619 1619
 			$temp_array['direction_fullname'] = "South-Southwest";
1620
-		} elseif ($direction >= 225 && $direction < 247.5){
1620
+		} elseif ($direction >= 225 && $direction < 247.5) {
1621 1621
 			$temp_array['direction_degree'] = $direction;
1622 1622
 			$temp_array['direction_shortname'] = "SW";
1623 1623
 			$temp_array['direction_fullname'] = "Southwest";
1624
-		} elseif ($direction >= 247.5 && $direction < 270){
1624
+		} elseif ($direction >= 247.5 && $direction < 270) {
1625 1625
 			$temp_array['direction_degree'] = $direction;
1626 1626
 			$temp_array['direction_shortname'] = "WSW";
1627 1627
 			$temp_array['direction_fullname'] = "West-Southwest";
1628
-		} elseif ($direction >= 270 && $direction < 292.5){
1628
+		} elseif ($direction >= 270 && $direction < 292.5) {
1629 1629
 			$temp_array['direction_degree'] = $direction;
1630 1630
 			$temp_array['direction_shortname'] = "W";
1631 1631
 			$temp_array['direction_fullname'] = "West";
1632
-		} elseif ($direction >= 292.5 && $direction < 315){
1632
+		} elseif ($direction >= 292.5 && $direction < 315) {
1633 1633
 			$temp_array['direction_degree'] = $direction;
1634 1634
 			$temp_array['direction_shortname'] = "WNW";
1635 1635
 			$temp_array['direction_fullname'] = "West-Northwest";
1636
-		} elseif ($direction >= 315 && $direction < 337.5){
1636
+		} elseif ($direction >= 315 && $direction < 337.5) {
1637 1637
 			$temp_array['direction_degree'] = $direction;
1638 1638
 			$temp_array['direction_shortname'] = "NW";
1639 1639
 			$temp_array['direction_fullname'] = "Northwest";
1640
-		} elseif ($direction >= 337.5 && $direction < 360){
1640
+		} elseif ($direction >= 337.5 && $direction < 360) {
1641 1641
 			$temp_array['direction_degree'] = $direction;
1642 1642
 			$temp_array['direction_shortname'] = "NNW";
1643 1643
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1654,11 +1654,11 @@  discard block
 block discarded – undo
1654 1654
 	* @param Float $longitude longitute of the flight
1655 1655
 	* @return String the countrie
1656 1656
 	*/
1657
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1657
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1658 1658
 	{
1659 1659
 		global $globalDBdriver, $globalDebug;
1660
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1661
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1660
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1661
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1662 1662
 	
1663 1663
 		$Connection = new Connection($this->db);
1664 1664
 		if (!$Connection->tableExists('countries')) return '';
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
 	public function getCountryFromISO2($iso2)
1699 1699
 	{
1700 1700
 		global $globalDBdriver, $globalDebug;
1701
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1701
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1702 1702
 	
1703 1703
 		$Connection = new Connection($this->db);
1704 1704
 		if (!$Connection->tableExists('countries')) return '';
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
 		
1747 1747
 		$bitly_data = json_decode($bitly_data);
1748 1748
 		$bitly_url = '';
1749
-		if ($bitly_data->status_txt = "OK"){
1749
+		if ($bitly_data->status_txt = "OK") {
1750 1750
 			$bitly_url = $bitly_data->data->url;
1751 1751
 		}
1752 1752
 
@@ -1760,11 +1760,11 @@  discard block
 block discarded – undo
1760 1760
 	* @return Array the vessel type list
1761 1761
 	*
1762 1762
 	*/
1763
-	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
1763
+	public function countAllMarineTypes($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1764 1764
 	{
1765 1765
 		global $globalDBdriver;
1766
-		$filter_query = $this->getFilter($filters,true,true);
1767
-		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1766
+		$filter_query = $this->getFilter($filters, true, true);
1767
+		$query = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count 
1768 1768
 		    FROM marine_output ".$filter_query." marine_output.type  <> ''";
1769 1769
 		if ($olderthanmonths > 0) {
1770 1770
 			if ($globalDBdriver == 'mysql') {
@@ -1784,28 +1784,28 @@  discard block
 block discarded – undo
1784 1784
 		if ($year != '') {
1785 1785
 			if ($globalDBdriver == 'mysql') {
1786 1786
 				$query .= " AND YEAR(marine_output.date) = :year";
1787
-				$query_values = array_merge($query_values,array(':year' => $year));
1787
+				$query_values = array_merge($query_values, array(':year' => $year));
1788 1788
 			} else {
1789 1789
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1790
-				$query_values = array_merge($query_values,array(':year' => $year));
1790
+				$query_values = array_merge($query_values, array(':year' => $year));
1791 1791
 			}
1792 1792
 		}
1793 1793
 		if ($month != '') {
1794 1794
 			if ($globalDBdriver == 'mysql') {
1795 1795
 				$query .= " AND MONTH(marine_output.date) = :month";
1796
-				$query_values = array_merge($query_values,array(':month' => $month));
1796
+				$query_values = array_merge($query_values, array(':month' => $month));
1797 1797
 			} else {
1798 1798
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1799
-				$query_values = array_merge($query_values,array(':month' => $month));
1799
+				$query_values = array_merge($query_values, array(':month' => $month));
1800 1800
 			}
1801 1801
 		}
1802 1802
 		if ($day != '') {
1803 1803
 			if ($globalDBdriver == 'mysql') {
1804 1804
 				$query .= " AND DAY(marine_output.date) = :day";
1805
-				$query_values = array_merge($query_values,array(':day' => $day));
1805
+				$query_values = array_merge($query_values, array(':day' => $day));
1806 1806
 			} else {
1807 1807
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1808
-				$query_values = array_merge($query_values,array(':day' => $day));
1808
+				$query_values = array_merge($query_values, array(':day' => $day));
1809 1809
 			}
1810 1810
 		}
1811 1811
 		$query .= " GROUP BY marine_output.type ORDER BY marine_type_count DESC";
@@ -1814,7 +1814,7 @@  discard block
 block discarded – undo
1814 1814
 		$sth->execute($query_values);
1815 1815
 		$marine_array = array();
1816 1816
 		$temp_array = array();
1817
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1817
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1818 1818
 		{
1819 1819
 			$temp_array['marine_type'] = $row['marine_type'];
1820 1820
 			$temp_array['marine_type_count'] = $row['marine_type_count'];
@@ -1829,13 +1829,13 @@  discard block
 block discarded – undo
1829 1829
 	* @return Array the tracker information
1830 1830
 	*
1831 1831
 	*/
1832
-	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
1832
+	public function searchMarineData($q = '', $callsign = '', $mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
1833 1833
 	{
1834 1834
 		global $globalTimezone, $globalDBdriver;
1835 1835
 		date_default_timezone_set('UTC');
1836 1836
 		$query_values = array();
1837 1837
 		$additional_query = '';
1838
-		$filter_query = $this->getFilter($filters,true,true);
1838
+		$filter_query = $this->getFilter($filters, true, true);
1839 1839
 		if ($q != "")
1840 1840
 		{
1841 1841
 			if (!is_string($q))
@@ -1843,8 +1843,8 @@  discard block
 block discarded – undo
1843 1843
 				return false;
1844 1844
 			} else {
1845 1845
 				$q_array = explode(" ", $q);
1846
-				foreach ($q_array as $q_item){
1847
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1846
+				foreach ($q_array as $q_item) {
1847
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
1848 1848
 					$additional_query .= " AND (";
1849 1849
 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
1850 1850
 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
@@ -1856,42 +1856,42 @@  discard block
 block discarded – undo
1856 1856
 		}
1857 1857
 		if ($callsign != "")
1858 1858
 		{
1859
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1859
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1860 1860
 			if (!is_string($callsign))
1861 1861
 			{
1862 1862
 				return false;
1863 1863
 			} else {
1864 1864
 				$additional_query .= " AND marine_output.ident = :callsign";
1865
-				$query_values = array_merge($query_values,array(':callsign' => $callsign));
1865
+				$query_values = array_merge($query_values, array(':callsign' => $callsign));
1866 1866
 			}
1867 1867
 		}
1868 1868
 		if ($mmsi != "")
1869 1869
 		{
1870
-			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1870
+			$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
1871 1871
 			if (!is_numeric($mmsi))
1872 1872
 			{
1873 1873
 				return false;
1874 1874
 			} else {
1875 1875
 				$additional_query .= " AND marine_output.mmsi = :mmsi";
1876
-				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
1876
+				$query_values = array_merge($query_values, array(':mmsi' => $mmsi));
1877 1877
 			}
1878 1878
 		}
1879 1879
 		if ($imo != "")
1880 1880
 		{
1881
-			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1881
+			$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1882 1882
 			if (!is_numeric($imo))
1883 1883
 			{
1884 1884
 				return false;
1885 1885
 			} else {
1886 1886
 				$additional_query .= " AND marine_output.imo = :imo";
1887
-				$query_values = array_merge($query_values,array(':imo' => $imo));
1887
+				$query_values = array_merge($query_values, array(':imo' => $imo));
1888 1888
 			}
1889 1889
 		}
1890 1890
 		if ($date_posted != "")
1891 1891
 		{
1892 1892
 			$date_array = explode(",", $date_posted);
1893
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
1894
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
1893
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
1894
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
1895 1895
 			if ($globalTimezone != '') {
1896 1896
 				date_default_timezone_set($globalTimezone);
1897 1897
 				$datetime = new DateTime();
@@ -1918,8 +1918,8 @@  discard block
 block discarded – undo
1918 1918
 		if ($limit != "")
1919 1919
 		{
1920 1920
 			$limit_array = explode(",", $limit);
1921
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1922
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1921
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1922
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1923 1923
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1924 1924
 			{
1925 1925
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -1937,28 +1937,28 @@  discard block
 block discarded – undo
1937 1937
 			}
1938 1938
 		}
1939 1939
 		if ($origLat != "" && $origLon != "" && $dist != "") {
1940
-			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
1940
+			$dist = number_format($dist*0.621371, 2, '.', ''); // convert km to mile
1941 1941
 			if ($globalDBdriver == 'mysql') {
1942
-				$query="SELECT marine_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2))) as distance 
1942
+				$query = "SELECT marine_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2))) as distance 
1943 1943
 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND marine_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and marine_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
1944 1944
 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2)))) < $dist".$orderby_query;
1945 1945
 			} else {
1946
-				$query="SELECT marine_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2))) as distance 
1946
+				$query = "SELECT marine_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2))) as distance 
1947 1947
 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND CAST(marine_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(marine_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) 
1948 1948
 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query.$orderby_query;
1949 1949
 			}
1950 1950
 		} else {
1951
-			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1951
+			$query = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
1952 1952
 			    ".$additional_query."
1953 1953
 			    ".$orderby_query;
1954 1954
 		}
1955
-		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
1955
+		$marine_array = $this->getDataFromDB($query, $query_values, $limit_query);
1956 1956
 		return $marine_array;
1957 1957
 	}
1958 1958
 
1959 1959
 	public function getOrderBy()
1960 1960
 	{
1961
-		$orderby = array("type_asc" => array("key" => "type_asc", "value" => "Type - ASC", "sql" => "ORDER BY marine_output.type ASC"), "type_desc" => array("key" => "type_desc", "value" => "Type - DESC", "sql" => "ORDER BY marine_output.type DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
1961
+		$orderby = array("type_asc" => array("key" => "type_asc", "value" => "Type - ASC", "sql" => "ORDER BY marine_output.type ASC"), "type_desc" => array("key" => "type_desc", "value" => "Type - DESC", "sql" => "ORDER BY marine_output.type DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"), "distance_asc" => array("key" => "distance_asc", "value" => "Distance - ASC", "sql" => "ORDER BY distance ASC"), "distance_desc" => array("key" => "distance_desc", "value" => "Distance - DESC", "sql" => "ORDER BY distance DESC"));
1962 1962
 		
1963 1963
 		return $orderby;
1964 1964
 		
Please login to merge, or discard this patch.
require/class.MarineLive.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@  discard block
 block discarded – undo
17 17
 	* @param Array $filter the filter
18 18
 	* @return Array the SQL part
19 19
 	*/
20
-	public function getFilter($filter = array(),$where = false,$and = false) {
20
+	public function getFilter($filter = array(), $where = false, $and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
22 22
 		$filters = array();
23 23
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
24 24
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
25 25
 				$filters = $globalStatsFilters[$globalFilterName];
26 26
 			} else {
27
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
27
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
28 28
 			}
29 29
 		}
30 30
 		if (isset($filter[0]['source'])) {
31
-			$filters = array_merge($filters,$filter);
31
+			$filters = array_merge($filters, $filter);
32 32
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
33
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
34 34
 		$filter_query_join = '';
35 35
 		$filter_query_where = '';
36
-		foreach($filters as $flt) {
36
+		foreach ($filters as $flt) {
37 37
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
38 38
 				if (isset($flt['source'])) {
39
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
39
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
40 40
 				} else {
41
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
41
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
42 42
 				}
43 43
 			}
44 44
 		}
45 45
 		if (isset($filter['source']) && !empty($filter['source'])) {
46
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
46
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
47 47
 		}
48 48
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
49 49
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -75,15 +75,15 @@  discard block
 block discarded – undo
75 75
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
76 76
 				}
77 77
 			}
78
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
78
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
79 79
 		}
80 80
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
81
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
81
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
82 82
 		}
83 83
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
84 84
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
85 85
 		if ($filter_query_where != '') {
86
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
86
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
87 87
 		}
88 88
 		$filter_query = $filter_query_join.$filter_query_where;
89 89
 		return $filter_query;
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 		if ($limit != '')
107 107
 		{
108 108
 			$limit_array = explode(',', $limit);
109
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
110
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
109
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
110
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
111 111
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
112 112
 			{
113 113
 				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
123 123
 			}
124 124
 		}
125
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
125
+		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
126 126
 
127 127
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
128 128
 		if ($globalDBdriver == 'mysql') {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		} else {
132 132
 			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
133 133
 		}
134
-		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
134
+		$spotter_array = $Marine->getDataFromDB($query.$limit_query, array(), '', true);
135 135
 
136 136
 		return $spotter_array;
137 137
 	}
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		global $globalDBdriver, $globalLiveInterval;
148 148
 		date_default_timezone_set('UTC');
149 149
 
150
-		$filter_query = $this->getFilter($filter,true,true);
150
+		$filter_query = $this->getFilter($filter, true, true);
151 151
 
152 152
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
153 153
 		if ($globalDBdriver == 'mysql') {
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		try {
162 162
 			$sth = $this->db->prepare($query);
163 163
 			$sth->execute();
164
-		} catch(PDOException $e) {
164
+		} catch (PDOException $e) {
165 165
 			echo $e->getMessage();
166 166
 			die;
167 167
 		}
@@ -176,19 +176,19 @@  discard block
 block discarded – undo
176 176
 	* @return Array the spotter information
177 177
 	*
178 178
 	*/
179
-	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false)
179
+	public function getMinLastLiveMarineData($coord = array(), $filter = array(), $limit = false)
180 180
 	{
181 181
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
182 182
 		date_default_timezone_set('UTC');
183 183
 		$usecoord = false;
184 184
 		if (is_array($coord) && !empty($coord)) {
185
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
186
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
187
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
188
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
185
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
186
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
187
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
188
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
189 189
 			$usecoord = true;
190 190
 		}
191
-		$filter_query = $this->getFilter($filter,true,true);
191
+		$filter_query = $this->getFilter($filter, true, true);
192 192
 
193 193
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
194 194
 		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		try {
238 238
 			$sth = $this->db->prepare($query);
239 239
 			$sth->execute();
240
-		} catch(PDOException $e) {
240
+		} catch (PDOException $e) {
241 241
 			echo $e->getMessage();
242 242
 			die;
243 243
 		}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	public function getLiveMarineCount($filter = array())
255 255
 	{
256 256
 		global $globalDBdriver, $globalLiveInterval;
257
-		$filter_query = $this->getFilter($filter,true,true);
257
+		$filter_query = $this->getFilter($filter, true, true);
258 258
 
259 259
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
260 260
 		if ($globalDBdriver == 'mysql') {
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		try {
266 266
 			$sth = $this->db->prepare($query);
267 267
 			$sth->execute();
268
-		} catch(PDOException $e) {
268
+		} catch (PDOException $e) {
269 269
 			echo $e->getMessage();
270 270
 			die;
271 271
 		}
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 		$filter_query = $this->getFilter($filter);
289 289
 
290 290
 		if (is_array($coord)) {
291
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
292
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
293
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
294
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
291
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
292
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
293
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
294
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
295 295
 		} else return array();
296 296
 		if ($globalDBdriver == 'mysql') {
297 297
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
@@ -313,13 +313,13 @@  discard block
 block discarded – undo
313 313
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
314 314
 		$Marine = new Marine($this->db);
315 315
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
316
-		$filter_query = $this->getFilter($filter,true,true);
316
+		$filter_query = $this->getFilter($filter, true, true);
317 317
 
318 318
 		if (is_array($coord)) {
319
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
320
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
321
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
322
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
319
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
320
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
321
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
322
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
323 323
 		} else return array();
324 324
 		/*
325 325
 		if ($globalDBdriver == 'mysql') {
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
 		*/
335 335
 		if ($globalDBdriver == 'mysql') {
336 336
 			if (isset($globalArchive) && $globalArchive === TRUE) {
337
-				$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 
337
+				$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 
338 338
 				    FROM marine_live 
339 339
 				    '.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= marine_live.date 
340 340
 				    AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
341 341
 				    AND marine_live.latitude <> 0 AND marine_live.longitude <> 0';
342 342
 			} else {
343
-				$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 
343
+				$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 
344 344
 				    FROM marine_live 
345 345
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
346 346
 				    FROM marine_live l 
@@ -352,14 +352,14 @@  discard block
 block discarded – undo
352 352
 			}
353 353
 		} else {
354 354
 			if (isset($globalArchive) && $globalArchive === TRUE) {
355
-				$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 
355
+				$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 
356 356
 				    FROM marine_live 
357 357
 				    ".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date 
358 358
 				    AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." 
359 359
 				    AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." 
360 360
 				    AND marine_live.latitude <> '0' AND marine_live.longitude <> '0'";
361 361
 			} else {
362
-				$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 
362
+				$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 
363 363
 				    FROM marine_live 
364 364
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
365 365
 				    FROM marine_live l 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
                 if ($interval == '1m')
417 417
                 {
418 418
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
419
-                } else if ($interval == '15m'){
419
+                } else if ($interval == '15m') {
420 420
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
421 421
                 } 
422 422
             }
@@ -424,14 +424,14 @@  discard block
 block discarded – undo
424 424
          $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
425 425
         }
426 426
 
427
-                $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 
427
+                $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 
428 428
                    WHERE marine_live.latitude <> '' 
429 429
                                    AND marine_live.longitude <> '' 
430 430
                    ".$additional_query."
431 431
                    HAVING distance < :radius  
432 432
                                    ORDER BY distance";
433 433
 
434
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
434
+                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius));
435 435
 
436 436
                 return $spotter_array;
437 437
         }
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
449 449
 		date_default_timezone_set('UTC');
450 450
 
451 451
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
452
-                $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';
452
+                $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';
453 453
 
454
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
454
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident), '', true);
455 455
 
456 456
 		return $spotter_array;
457 457
 	}
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
 	* @return Array the spotter information
463 463
 	*
464 464
 	*/
465
-	public function getDateLiveMarineDataByIdent($ident,$date)
465
+	public function getDateLiveMarineDataByIdent($ident, $date)
466 466
 	{
467 467
 		$Marine = new Marine($this->db);
468 468
 		date_default_timezone_set('UTC');
469 469
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
470 470
 		$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';
471
-		$date = date('c',$date);
472
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
471
+		$date = date('c', $date);
472
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
473 473
 		return $spotter_array;
474 474
 	}
475 475
 
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
 	* @return Array the spotter information
480 480
 	*
481 481
 	*/
482
-	public function getDateLiveMarineDataByMMSI($mmsi,$date)
482
+	public function getDateLiveMarineDataByMMSI($mmsi, $date)
483 483
 	{
484 484
 		$Marine = new Marine($this->db);
485 485
 		date_default_timezone_set('UTC');
486 486
 		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
487 487
 		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.mmsi = :mmsi 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';
488
-		$date = date('c',$date);
489
-		$spotter_array = $Marine->getDataFromDB($query,array(':mmsi' => $mmsi,':date' => $date));
488
+		$date = date('c', $date);
489
+		$spotter_array = $Marine->getDataFromDB($query, array(':mmsi' => $mmsi, ':date' => $date));
490 490
 		return $spotter_array;
491 491
 	}
492 492
 
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 		date_default_timezone_set('UTC');
503 503
 
504 504
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
505
-                $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';
505
+                $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';
506 506
 
507
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
507
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id), '', true);
508 508
 
509 509
 		return $spotter_array;
510 510
 	}
@@ -515,15 +515,15 @@  discard block
 block discarded – undo
515 515
 	* @return Array the spotter information
516 516
 	*
517 517
 	*/
518
-	public function getDateLiveMarineDataById($id,$date)
518
+	public function getDateLiveMarineDataById($id, $date)
519 519
 	{
520 520
 		$Marine = new Marine($this->db);
521 521
 		date_default_timezone_set('UTC');
522 522
 
523 523
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
524
-                $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';
525
-                $date = date('c',$date);
526
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
524
+                $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';
525
+                $date = date('c', $date);
526
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date), '', true);
527 527
 
528 528
 		return $spotter_array;
529 529
 	}
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 	* @return Array the spotter information
536 536
 	*
537 537
 	*/
538
-	public function getAllLiveMarineDataById($id,$liveinterval = false)
538
+	public function getAllLiveMarineDataById($id, $liveinterval = false)
539 539
 	{
540 540
 		global $globalDBdriver, $globalLiveInterval;
541 541
 		date_default_timezone_set('UTC');
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 		try {
555 555
 			$sth = $this->db->prepare($query);
556 556
 			$sth->execute(array(':id' => $id));
557
-		} catch(PDOException $e) {
557
+		} catch (PDOException $e) {
558 558
 			echo $e->getMessage();
559 559
 			die;
560 560
 		}
@@ -572,12 +572,12 @@  discard block
 block discarded – undo
572 572
 	{
573 573
 		date_default_timezone_set('UTC');
574 574
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
575
-		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
575
+		$query = self::$global_query.' WHERE marine_live.ident = :ident';
576 576
     		try {
577 577
 			
578 578
 			$sth = $this->db->prepare($query);
579 579
 			$sth->execute(array(':ident' => $ident));
580
-		} catch(PDOException $e) {
580
+		} catch (PDOException $e) {
581 581
 			echo $e->getMessage();
582 582
 			die;
583 583
 		}
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			
608 608
 			$sth = $this->db->prepare($query);
609 609
 			$sth->execute();
610
-		} catch(PDOException $e) {
610
+		} catch (PDOException $e) {
611 611
 			return "error";
612 612
 		}
613 613
 
@@ -630,14 +630,14 @@  discard block
 block discarded – undo
630 630
 				
631 631
 				$sth = $this->db->prepare($query);
632 632
 				$sth->execute();
633
-			} catch(PDOException $e) {
633
+			} catch (PDOException $e) {
634 634
 				return "error";
635 635
 			}
636 636
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
637 637
                         $i = 0;
638
-                        $j =0;
638
+                        $j = 0;
639 639
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
640
-			foreach($all as $row)
640
+			foreach ($all as $row)
641 641
 			{
642 642
 				$i++;
643 643
 				$j++;
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 					if ($globalDebug) echo ".";
646 646
 				    	try {
647 647
 						
648
-						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
648
+						$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
649 649
 						$sth->execute();
650
-					} catch(PDOException $e) {
650
+					} catch (PDOException $e) {
651 651
 						return "error";
652 652
 					}
653 653
                                 	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
@@ -658,9 +658,9 @@  discard block
 block discarded – undo
658 658
 			if ($i > 0) {
659 659
     				try {
660 660
 					
661
-					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
661
+					$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
662 662
 					$sth->execute();
663
-				} catch(PDOException $e) {
663
+				} catch (PDOException $e) {
664 664
 					return "error";
665 665
 				}
666 666
 			}
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 				
674 674
 				$sth = $this->db->prepare($query);
675 675
 				$sth->execute();
676
-			} catch(PDOException $e) {
676
+			} catch (PDOException $e) {
677 677
 				return "error";
678 678
 			}
679 679
 /*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
 	public function deleteLiveMarineDataByIdent($ident)
722 722
 	{
723 723
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
724
-		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
724
+		$query = 'DELETE FROM marine_live WHERE ident = :ident';
725 725
         
726 726
     		try {
727 727
 			
728 728
 			$sth = $this->db->prepare($query);
729 729
 			$sth->execute(array(':ident' => $ident));
730
-		} catch(PDOException $e) {
730
+		} catch (PDOException $e) {
731 731
 			return "error";
732 732
 		}
733 733
 
@@ -743,13 +743,13 @@  discard block
 block discarded – undo
743 743
 	public function deleteLiveMarineDataById($id)
744 744
 	{
745 745
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
746
-		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
746
+		$query = 'DELETE FROM marine_live WHERE fammarine_id = :id';
747 747
         
748 748
     		try {
749 749
 			
750 750
 			$sth = $this->db->prepare($query);
751 751
 			$sth->execute(array(':id' => $id));
752
-		} catch(PDOException $e) {
752
+		} catch (PDOException $e) {
753 753
 			return "error";
754 754
 		}
755 755
 
@@ -767,13 +767,13 @@  discard block
 block discarded – undo
767 767
 	{
768 768
 		global $globalDBdriver, $globalTimezone;
769 769
 		if ($globalDBdriver == 'mysql') {
770
-			$query  = 'SELECT marine_live.ident FROM marine_live 
770
+			$query = 'SELECT marine_live.ident FROM marine_live 
771 771
 				WHERE marine_live.ident = :ident 
772 772
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
773 773
 				AND marine_live.date < UTC_TIMESTAMP()';
774 774
 			$query_data = array(':ident' => $ident);
775 775
 		} else {
776
-			$query  = "SELECT marine_live.ident FROM marine_live 
776
+			$query = "SELECT marine_live.ident FROM marine_live 
777 777
 				WHERE marine_live.ident = :ident 
778 778
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
779 779
 				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
 		
783 783
 		$sth = $this->db->prepare($query);
784 784
 		$sth->execute($query_data);
785
-		$ident_result='';
786
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
785
+		$ident_result = '';
786
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
787 787
 		{
788 788
 			$ident_result = $row['ident'];
789 789
 		}
@@ -800,13 +800,13 @@  discard block
 block discarded – undo
800 800
 	{
801 801
 		global $globalDBdriver, $globalTimezone;
802 802
 		if ($globalDBdriver == 'mysql') {
803
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
803
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
804 804
 				WHERE marine_live.ident = :ident 
805 805
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
806 806
 //				AND marine_live.date < UTC_TIMESTAMP()";
807 807
 			$query_data = array(':ident' => $ident);
808 808
 		} else {
809
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
809
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
810 810
 				WHERE marine_live.ident = :ident 
811 811
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
812 812
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
 		
816 816
 		$sth = $this->db->prepare($query);
817 817
 		$sth->execute($query_data);
818
-		$ident_result='';
819
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
818
+		$ident_result = '';
819
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
820 820
 		{
821 821
 			$ident_result = $row['fammarine_id'];
822 822
 		}
@@ -833,13 +833,13 @@  discard block
 block discarded – undo
833 833
 	{
834 834
 		global $globalDBdriver, $globalTimezone;
835 835
 		if ($globalDBdriver == 'mysql') {
836
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
836
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
837 837
 				WHERE marine_live.fammarine_id = :id 
838 838
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
839 839
 //				AND marine_live.date < UTC_TIMESTAMP()";
840 840
 			$query_data = array(':id' => $id);
841 841
 		} else {
842
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
842
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
843 843
 				WHERE marine_live.fammarine_id = :id 
844 844
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
845 845
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
 		
849 849
 		$sth = $this->db->prepare($query);
850 850
 		$sth->execute($query_data);
851
-		$ident_result='';
852
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
851
+		$ident_result = '';
852
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
853 853
 		{
854 854
 			$ident_result = $row['fammarine_id'];
855 855
 		}
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
 	{
867 867
 		global $globalDBdriver, $globalTimezone;
868 868
 		if ($globalDBdriver == 'mysql') {
869
-			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
869
+			$query = 'SELECT marine_live.fammarine_id FROM marine_live 
870 870
 				WHERE marine_live.mmsi = :mmsi 
871 871
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
872 872
 //				AND marine_live.date < UTC_TIMESTAMP()";
873 873
 			$query_data = array(':mmsi' => $mmsi);
874 874
 		} else {
875
-			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
875
+			$query = "SELECT marine_live.fammarine_id FROM marine_live 
876 876
 				WHERE marine_live.mmsi = :mmsi 
877 877
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
878 878
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 		
882 882
 		$sth = $this->db->prepare($query);
883 883
 		$sth->execute($query_data);
884
-		$ident_result='';
885
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
884
+		$ident_result = '';
885
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
886 886
 		{
887 887
 			$ident_result = $row['fammarine_id'];
888 888
 		}
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 	* @return String success or false
901 901
 	*
902 902
 	*/
903
-	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
903
+	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '')
904 904
 	{
905 905
 		global $globalURL, $globalArchive, $globalDebug;
906 906
 		$Common = new Common();
@@ -952,26 +952,26 @@  discard block
 block discarded – undo
952 952
 		if ($date == '') $date = date("Y-m-d H:i:s", time());
953 953
 
954 954
         
955
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
956
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
957
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
958
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
959
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
960
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
961
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
962
-		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
963
-		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
964
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
965
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
966
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
967
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
968
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
969
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
970
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
955
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
956
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
957
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
958
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
959
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
960
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
961
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
962
+		$source_name = filter_var($source_name, FILTER_SANITIZE_STRING);
963
+		$over_country = filter_var($over_country, FILTER_SANITIZE_STRING);
964
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
965
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
966
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
967
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
968
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
969
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
970
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
971 971
 		
972 972
 
973
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
974
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
973
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
974
+            	if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
975 975
             	if ($arrival_date == '') $arrival_date = NULL;
976 976
             	$query = '';
977 977
 		if ($globalArchive) {
@@ -980,19 +980,19 @@  discard block
 block discarded – undo
980 980
 		}
981 981
 		$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) 
982 982
 		    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)';
983
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
983
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
984 984
 		try {
985 985
 			$sth = $this->db->prepare($query);
986 986
 			$sth->execute($query_values);
987 987
 			$sth->closeCursor();
988
-		} catch(PDOException $e) {
988
+		} catch (PDOException $e) {
989 989
 			return "error : ".$e->getMessage();
990 990
 		}
991 991
 		
992 992
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
993 993
 			if ($globalDebug) echo '(Add to Marine archive : ';
994 994
 			$MarineArchive = new MarineArchive($this->db);
995
-			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source, $source_name, $over_country);
995
+			$result = $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country);
996 996
 			if ($globalDebug) echo $result.')';
997 997
 		}
998 998
 		return "success";
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
 	public function getOrderBy()
1002 1002
 	{
1003
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1003
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1004 1004
 		return $orderby;
1005 1005
 	}
1006 1006
 
Please login to merge, or discard this patch.
require/class.MarineImport.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60 60
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61 61
     		    $Marine = new Marine($this->db);
62
-    		    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
62
+    		    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
63 63
 		}
64 64
 	    }
65 65
 	}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
72 72
 	foreach ($this->all_tracked as $key => $flight) {
73 73
     	    if (isset($flight['lastupdate'])) {
74
-        	if ($flight['lastupdate'] < (time()-3000)) {
74
+        	if ($flight['lastupdate'] < (time() - 3000)) {
75 75
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
76 76
             		if (isset($this->all_tracked[$key]['id'])) {
77 77
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             		    //$real_arrival = $this->arrival($key);
84 84
             		    $Marine = new Marine($this->db);
85 85
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
86
-				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
86
+				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
87 87
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
88 88
 			    }
89 89
 			    // Put in archive
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
     }
98 98
 
99 99
     public function add($line) {
100
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
100
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine;
101 101
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
102 102
 	date_default_timezone_set('UTC');
103 103
 	$dataFound = false;
104 104
 	$send = false;
105 105
 	
106 106
 	// SBS format is CSV format
107
-	if(is_array($line) && isset($line['mmsi'])) {
107
+	if (is_array($line) && isset($line['mmsi'])) {
108 108
 	    //print_r($line);
109 109
   	    if (isset($line['mmsi'])) {
110 110
 
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
 		
130 130
 		if (!isset($this->all_tracked[$id])) {
131 131
 		    $this->all_tracked[$id] = array();
132
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
133
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
134
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
133
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => ''));
134
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
135 135
 		    if (!isset($line['id'])) {
136 136
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
137
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
138
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
137
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
138
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
139 139
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
140 140
 		}
141 141
 		
142 142
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
143
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
144 144
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
145 145
 			$Marine = new Marine($this->db);
146 146
 			$identity = $Marine->getIdentity($line['mmsi']);
@@ -154,65 +154,65 @@  discard block
 block discarded – undo
154 154
 		    }
155 155
 		}
156 156
 		if (isset($line['type_id'])) {
157
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
157
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
158
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
159 159
 		}
160 160
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
161
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
162 162
 		}
163 163
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
164
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
164
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
165 165
 		}
166 166
 		if (isset($line['imo']) && $line['imo'] != '') {
167
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
167
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
168 168
 		}
169 169
 		if (isset($line['callsign']) && $line['callsign'] != '') {
170
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
170
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
171 171
 		}
172 172
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
173
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
173
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
174 174
 		}
175 175
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
176
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
176
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
177 177
 		}
178 178
 
179 179
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
180 180
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
181
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
182 182
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
183 183
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
184 184
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
185 185
 				$timeelapsed = microtime(true);
186 186
 				$Marine = new Marine($this->db);
187 187
 				$fromsource = NULL;
188
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
188
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
189 189
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
190
-				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
190
+				$Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']);
191 191
 				$Marine->db = null;
192
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
192
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
193 193
 			    }
194 194
 			}
195 195
 		    }
196
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
196
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
197 197
 		}
198 198
 
199
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
199
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
200 200
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
201
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
201
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
202 202
 		    } else {
203 203
 				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";
204 204
 				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";
205 205
 				return '';
206 206
 		    }
207
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
207
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
208 208
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
209 209
 			return '';
210
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
210
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
211 211
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
212 212
 			return '';
213 213
 		} elseif (!isset($line['datetime'])) {
214 214
 			date_default_timezone_set('UTC');
215
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
215
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
216 216
 		} else {
217 217
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!";
218 218
 			return '';
@@ -220,24 +220,24 @@  discard block
 block discarded – undo
220 220
 
221 221
 
222 222
 		if (isset($line['speed'])) {
223
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
224
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
223
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
224
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
225 225
 		} 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'])) {
226
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
226
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
227 227
 		    if ($distance > 1000 && $distance < 10000) {
228 228
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
229 229
 			$speed = $speed*3.6;
230
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
230
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
231 231
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
232 232
 		    }
233 233
 		}
234 234
 
235 235
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
236
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
236
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
237 237
 	    	    else unset($timediff);
238
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
238
+	    	    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')))) {
239 239
 			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'])) {
240
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
240
+			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['livedb_latitude'], $this->all_tracked[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
241 241
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
242 242
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
243 243
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 				$timeelapsed = microtime(true);
247 247
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
248 248
 				    $Marine = new Marine($this->db);
249
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
249
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
250 250
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
251 251
 				    $Marine->db = null;
252
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
252
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
253 253
 				}
254 254
 				$this->tmd = 0;
255 255
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -258,52 +258,52 @@  discard block
 block discarded – undo
258 258
 
259 259
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
260 260
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
261
-				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
261
+				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') {
262 262
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
263 263
 				    $dataFound = true;
264 264
 				    $this->all_tracked[$id]['time_last_coord'] = time();
265 265
 				}
266
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
266
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
267 267
 			}
268 268
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
269 269
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
270 270
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
271
-				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
271
+				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') {
272 272
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
273 273
 				    $dataFound = true;
274 274
 				    $this->all_tracked[$id]['time_last_coord'] = time();
275 275
 				}
276
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
276
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
277 277
 			}
278 278
 
279 279
 		    } else if ($globalDebug && $timediff > 20) {
280 280
 			$this->tmd = $this->tmd + 1;
281 281
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
282
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
283
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
282
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
283
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
284 284
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
285 285
 		    }
286 286
 		}
287 287
 		if (isset($line['last_update']) && $line['last_update'] != '') {
288 288
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
289
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
289
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
290 290
 		}
291 291
 		if (isset($line['format_source']) && $line['format_source'] != '') {
292
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
292
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
293 293
 		}
294 294
 		if (isset($line['source_name']) && $line['source_name'] != '') {
295
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
295
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
296 296
 		}
297 297
 		if (isset($line['status']) && $line['status'] != '') {
298
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
298
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
299 299
 		}
300 300
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
301
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
301
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
302 302
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
303 303
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
304 304
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
305 305
 				$Marine = new Marine($this->db);
306
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
306
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
307 307
 				unset($Marine);
308 308
 			    }
309 309
 			}
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
 		}
312 312
 
313 313
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
314
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
314
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
315 315
 		}
316 316
 		
317 317
 		if (isset($line['heading']) && $line['heading'] != '') {
318
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
319
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
320
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
318
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
319
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
320
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
321 321
 		    //$dataFound = true;
322 322
   		} 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']) {
323
-  		    $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']);
324
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
325
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
323
+  		    $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']);
324
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
325
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
326 326
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
327 327
   		}
328 328
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
333 333
 		    $this->all_tracked[$id]['lastupdate'] = time();
334 334
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
335
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
335
+		        if (!isset($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'])) {
336 336
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
337 337
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
338 338
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -340,37 +340,37 @@  discard block
 block discarded – undo
340 340
 				    $MarineLive = new MarineLive($this->db);
341 341
 				    if (isset($line['id'])) {
342 342
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
343
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
343
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
344 344
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
345 345
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
346
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
346
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
347 347
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
348 348
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
349
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
349
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
350 350
 				    } else $recent_ident = '';
351
-				    $MarineLive->db=null;
351
+				    $MarineLive->db = null;
352 352
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
353 353
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
354 354
 				} else $recent_ident = '';
355 355
 			    } else {
356 356
 				$recent_ident = '';
357
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
357
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
358 358
 			    }
359 359
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
360
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
360
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
361 361
 			    {
362 362
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
363 363
 				//adds the spotter data for the archive
364 364
 				    $highlight = '';
365
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
365
+				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
366 366
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
367 367
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
368 368
 					    $timeelapsed = microtime(true);
369 369
 					    $Marine = new Marine($this->db);
370
-					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
370
+					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']);
371 371
 					    $Marine->db = null;
372 372
 					    if ($globalDebug && isset($result)) echo $result."\n";
373
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
373
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
374 374
 					}
375 375
 				    }
376 376
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
 					$Stats = new Stats($this->db);
379 379
 					if (!empty($this->stats)) {
380 380
 					    if ($globalDebug) echo 'Add source stats : ';
381
-				    	    foreach($this->stats as $date => $data) {
382
-						foreach($data as $source => $sourced) {
381
+				    	    foreach ($this->stats as $date => $data) {
382
+						foreach ($data as $source => $sourced) {
383 383
 					    	    //print_r($sourced);
384
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
385
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
384
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
385
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
386 386
 				    		    if (isset($sourced['msg'])) {
387 387
 				    			if (time() - $sourced['msg']['date'] > 10) {
388 388
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
389
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
389
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
390 390
 			    			    	    unset($this->stats[$date][$source]['msg']);
391 391
 			    				}
392 392
 			    			    }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
411 411
 					$MarineLive = new MarineLive($this->db);
412 412
 					$MarineLive->deleteLiveMarineData();
413
-					$MarineLive->db=null;
413
+					$MarineLive->db = null;
414 414
 					if ($globalDebug) echo " Done\n";
415 415
 				    }
416 416
 				    $this->last_delete = time();
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
422 422
 				    if (isset($globalDaemon) && !$globalDaemon) {
423 423
 					$Marine = new Marine($this->db);
424
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
424
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
425 425
 					$Marine->db = null;
426 426
 				    }
427 427
 				}
@@ -436,20 +436,20 @@  discard block
 block discarded – undo
436 436
 		    $ignoreImport = false;
437 437
 
438 438
 		    if (!$ignoreImport) {
439
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
439
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
440 440
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
441 441
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
442 442
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
443 443
 					$timeelapsed = microtime(true);
444 444
 					$MarineLive = new MarineLive($this->db);
445
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
445
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
446 446
 					$MarineLive->db = null;
447 447
 					if ($globalDebug) echo $result."\n";
448
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
448
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
449 449
 				    }
450 450
 				}
451 451
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
452
-				    $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
452
+				    $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
453 453
 				}
454 454
 				$this->all_tracked[$id]['putinarchive'] = false;
455 455
 
@@ -468,19 +468,19 @@  discard block
 block discarded – undo
468 468
 							$latitude = $globalCenterLatitude;
469 469
 							$longitude = $globalCenterLongitude;
470 470
 						}
471
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
471
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
472 472
 					} else {
473 473
 						$latitude = $this->source_location[$source]['latitude'];
474 474
 						$longitude = $this->source_location[$source]['longitude'];
475 475
 					}
476
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
476
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
477 477
 					//$stats_heading = $stats_heading%22.5;
478 478
 					$stats_heading = round($stats_heading/22.5);
479
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
479
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
480 480
 					$current_date = date('Y-m-d');
481 481
 					if ($stats_heading == 16) $stats_heading = 0;
482 482
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
483
-						for ($i=0;$i<=15;$i++) {
483
+						for ($i = 0; $i <= 15; $i++) {
484 484
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
485 485
 						}
486 486
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -495,9 +495,9 @@  discard block
 block discarded – undo
495 495
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
496 496
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
497 497
 						    end($this->stats[$current_date][$source]['hist']);
498
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
498
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
499 499
 						} else $mini = 0;
500
-						for ($i=$mini;$i<=$distance;$i+=10) {
500
+						for ($i = $mini; $i <= $distance; $i += 10) {
501 501
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
502 502
 						}
503 503
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 
510 510
 				$this->all_tracked[$id]['lastupdate'] = time();
511 511
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
512
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
512
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
513 513
 			//$this->del();
514 514
 			
515 515
 			
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,30 +150,30 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/opensky/i',$host)) {
176
+    	    } else if (preg_match('/opensky/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftlistjson';
178 178
         	$globalSources[$id]['format'] = 'opensky';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
193
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
194 194
         	//$formats[$id] = 'planeupdatefaa';
195 195
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 196
         	//$last_exec['planeupdatefaa'] = 0;
@@ -199,37 +199,37 @@  discard block
 block discarded – undo
199 199
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 200
         	    exit(0);
201 201
         	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
202
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
203 203
         	//$formats[$id] = 'phpvmacars';
204 204
         	$globalSources[$id]['format'] = 'phpvmacars';
205 205
         	//$last_exec['phpvmacars'] = 0;
206 206
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
207
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
208 208
         	//$formats[$id] = 'phpvmacars';
209 209
         	$globalSources[$id]['format'] = 'vaos';
210 210
         	//$last_exec['phpvmacars'] = 0;
211 211
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
212
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
212
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
213 213
         	//$formats[$id] = 'phpvmacars';
214 214
         	$globalSources[$id]['format'] = 'vam';
215 215
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
216
-            } else if (preg_match('/whazzup/i',$host)) {
216
+            } else if (preg_match('/whazzup/i', $host)) {
217 217
         	//$formats[$id] = 'whazzup';
218 218
         	$globalSources[$id]['format'] = 'whazzup';
219 219
         	//$last_exec['whazzup'] = 0;
220 220
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
221
-            } else if (preg_match('/blitzortung/i',$host)) {
221
+            } else if (preg_match('/blitzortung/i', $host)) {
222 222
         	$globalSources[$id]['format'] = 'blitzortung';
223 223
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
224
-            } else if (preg_match('/airwhere/i',$host)) {
224
+            } else if (preg_match('/airwhere/i', $host)) {
225 225
         	$globalSources[$id]['format'] = 'airwhere';
226 226
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
227
-            } else if (preg_match('/recentpireps/i',$host)) {
227
+            } else if (preg_match('/recentpireps/i', $host)) {
228 228
         	//$formats[$id] = 'pirepsjson';
229 229
         	$globalSources[$id]['format'] = 'pirepsjson';
230 230
         	//$last_exec['pirepsjson'] = 0;
231 231
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
232
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
232
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
233 233
         	//$formats[$id] = 'fr24json';
234 234
         	$globalSources[$id]['format'] = 'fr24json';
235 235
         	//$last_exec['fr24json'] = 0;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239 239
         	    exit(0);
240 240
         	}
241
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
241
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
242 242
         	//$formats[$id] = 'fr24json';
243 243
         	$globalSources[$id]['format'] = 'myshiptracking';
244 244
         	//$last_exec['fr24json'] = 0;
@@ -248,21 +248,21 @@  discard block
 block discarded – undo
248 248
         	    exit(0);
249 249
         	}
250 250
             //} else if (preg_match('/10001/',$host)) {
251
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
251
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252 252
         	//$formats[$id] = 'tsv';
253 253
         	$globalSources[$id]['format'] = 'tsv';
254 254
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
255 255
             }
256
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
256
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
257 257
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
258
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
259 259
     		    if ($idf !== false) {
260 260
     			$httpfeeds[$id] = $idf;
261 261
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262 262
     		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263 263
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265
-	    $hostport = explode(':',$host);
264
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
265
+	    $hostport = explode(':', $host);
266 266
 	    if (isset($hostport[1])) {
267 267
 		$port = $hostport[1];
268 268
 		$hostn = $hostport[0];
@@ -272,19 +272,19 @@  discard block
 block discarded – undo
272 272
 	    }
273 273
 	    $Common = new Common();
274 274
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
275
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
275
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
276 276
     	    } else {
277
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
277
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
278 278
 	    }
279 279
 	    if ($s) {
280 280
     	        $sockets[$id] = $s;
281 281
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
282
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
282
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
283 283
 			//$formats[$id] = 'aprs';
284 284
 			$globalSources[$id]['format'] = 'aprs';
285 285
 			//$aprs_connect = 0;
286 286
 			//$use_aprs = true;
287
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
287
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
288 288
 			$globalSources[$id]['format'] = 'vrstcp';
289 289
     		    } elseif ($port == '10001') {
290 290
         		//$formats[$id] = 'tsv';
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
324 324
 else $timeout = 20;
325 325
 $errno = '';
326
-$errstr='';
326
+$errstr = '';
327 327
 
328 328
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
329 329
 /* Initiate connections to all the hosts simultaneously */
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 //connect_all($globalSources);
332 332
 
333 333
 if (isset($globalProxy) && $globalProxy) {
334
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
334
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
335 335
 } else {
336 336
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
337 337
 }
@@ -361,16 +361,16 @@  discard block
 block discarded – undo
361 361
 
362 362
 if ($use_aprs) {
363 363
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
364
-	$APRS=new APRS();
364
+	$APRS = new APRS();
365 365
 	$aprs_connect = 0;
366 366
 	$aprs_keep = 120;
367 367
 	$aprs_last_tx = time();
368 368
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
369
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
369
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
370 370
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
371
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
371
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
372 372
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
373
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
373
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
374 374
 	if ($aprs_full) $aprs_filter = '';
375 375
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
376 376
 	else $aprs_pass = '-1';
@@ -384,12 +384,12 @@  discard block
 block discarded – undo
384 384
 sleep(1);
385 385
 if ($globalDebug) echo "SCAN MODE \n\n";
386 386
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
387
-$endtime = time()+$globalCronEnd;
387
+$endtime = time() + $globalCronEnd;
388 388
 $i = 1;
389 389
 $tt = array();
390 390
 // Delete all ATC
391 391
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
392
-	$ATC=new ATC($Connection->db);
392
+	$ATC = new ATC($Connection->db);
393 393
 }
394 394
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
395 395
 	$ATC->deleteAll();
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
399 399
 while ($i > 0) {
400
-    if (!$globalDaemon) $i = $endtime-time();
400
+    if (!$globalDaemon) $i = $endtime - time();
401 401
     // Delete old ATC
402 402
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
403 403
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	}
412 412
 	if ($max != $globalMinFetch) {
413 413
 	    if ($globalDebug) echo 'Sleeping...'."\n";
414
-	    sleep($globalMinFetch-$max+2);
414
+	    sleep($globalMinFetch - $max + 2);
415 415
 	}
416 416
     }
417 417
 
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
 	    //$buffer = $Common->getData($hosts[$id]);
431 431
 	    $buffer = $Common->getData($value['host']);
432 432
 	    if ($buffer != '') $reset = 0;
433
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434
-	    $buffer = explode('\n',$buffer);
433
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
434
+	    $buffer = explode('\n', $buffer);
435 435
 	    foreach ($buffer as $line) {
436 436
     		if ($line != '' && count($line) > 7) {
437 437
     		    $line = explode(',', $line);
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
 	    )
465 465
 	) {
466 466
 	    date_default_timezone_set('CET');
467
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
467
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
468 468
 	    date_default_timezone_set('UTC');
469 469
 	    if ($buffer != '') $reset = 0;
470
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471
-	    $buffer = explode('\n',$buffer);
470
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
471
+	    $buffer = explode('\n', $buffer);
472 472
 	    foreach ($buffer as $line) {
473 473
 		if ($line != '') {
474 474
 		    //echo "'".$line."'\n";
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 		    $ais_data = $AIS->parse_line(trim($line));
477 477
 		    $data = array();
478 478
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
479
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
480 480
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481 481
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482 482
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
487 487
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
488 488
 		    if (isset($ais_data['timestamp'])) {
489
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
489
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
490 490
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
491 491
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
492 492
 			    $add = true;
@@ -509,21 +509,21 @@  discard block
 block discarded – undo
509 509
 	    $w = $e = null;
510 510
 	    
511 511
 	    if (isset($arr[$id])) {
512
-		$nn = stream_select($arr,$w,$e,$timeout);
512
+		$nn = stream_select($arr, $w, $e, $timeout);
513 513
 		if ($nn > 0) {
514 514
 		    foreach ($httpfeeds as $feed) {
515
-			$buffer = stream_get_line($feed,2000,"\n");
515
+			$buffer = stream_get_line($feed, 2000, "\n");
516 516
 			if ($buffer === FALSE) {
517 517
 			    connect_all($globalSources);
518 518
 			}
519
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
520
-			$buffer = explode('\n',$buffer);
519
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
520
+			$buffer = explode('\n', $buffer);
521 521
 			foreach ($buffer as $line) {
522 522
 			    if ($line != '') {
523 523
 				$ais_data = $AIS->parse_line(trim($line));
524 524
 				$data = array();
525 525
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
526
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
526
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
527 527
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
528 528
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
529 529
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
536 536
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
537 537
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
538
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
538
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
539 539
 				if (isset($ais_data['timestamp'])) {
540
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
540
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
541 541
 				} else {
542 542
 				    $data['datetime'] = date('Y-m-d H:i:s');
543 543
 				}
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
570 570
 	    )
571 571
 	) {
572
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
572
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
573 573
 	    if ($buffer != '') {
574 574
 		//echo $buffer;
575
-		$all_data = json_decode($buffer,true);
575
+		$all_data = json_decode($buffer, true);
576 576
 		//print_r($all_data);
577 577
 		if (isset($all_data[0]['DATA'])) {
578 578
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 			    $data['ident'] = $line['NAME'];
582 582
 			    $data['mmsi'] = $line['MMSI'];
583 583
 			    if (strlen($data['mmsi']) > 9) {
584
-				$data['mmsi'] = substr($data['mmsi'],-9);
584
+				$data['mmsi'] = substr($data['mmsi'], -9);
585 585
 			    }
586 586
 			    $data['speed'] = $line['SOG'];
587 587
 			    $data['heading'] = $line['COG'];
@@ -591,8 +591,8 @@  discard block
 block discarded – undo
591 591
 			    $data['type_id'] = $line['TYPE'];
592 592
 			    $data['imo'] = $line['IMO'];
593 593
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
594
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
595
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
594
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
595
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
596 596
 			    $data['format_source'] = 'myshiptracking';
597 597
 			    $data['id_source'] = $id_source;
598 598
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -609,16 +609,16 @@  discard block
 block discarded – undo
609 609
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
610 610
 	    )
611 611
 	) {
612
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
612
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
613 613
 	    if ($buffer != '') {
614
-		$all_data = json_decode($buffer,true);
614
+		$all_data = json_decode($buffer, true);
615 615
 		if (isset($all_data[0]['mmsi'])) {
616 616
 		    foreach ($all_data as $line) {
617 617
 			if ($line != '') {
618 618
 			    $data = array();
619 619
 			    $data['ident'] = $line['shipname'];
620 620
 			    $data['callsign'] = $line['callsign'];
621
-			    $data['mmsi'] = substr($line['mmsi'],-9);
621
+			    $data['mmsi'] = substr($line['mmsi'], -9);
622 622
 			    $data['speed'] = $line['sog'];
623 623
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
624 624
 			    $data['latitude'] = $line['latitude'];
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
 	) {
646 646
 	    $buffer = $Common->getData($value['host']);
647 647
 	    if ($buffer != '') {
648
-		$all_data = json_decode($buffer,true);
648
+		$all_data = json_decode($buffer, true);
649 649
 		if (isset($all_data['features'][0]['id'])) {
650 650
 		    foreach ($all_data['features'] as $line) {
651 651
 			print_r($line);
652 652
 			$data = array();
653 653
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
654 654
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
655
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
655
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
656 656
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
657 657
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
658 658
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -679,31 +679,31 @@  discard block
 block discarded – undo
679 679
 	    )
680 680
 	) {
681 681
 	    echo 'download...';
682
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
682
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
683 683
 	    echo 'done !'."\n";
684 684
 	    // FIXME: Need more work
685 685
 	    if ($buffer != '') $reset = 0;
686
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
687
-	    $buffer = explode('\n',$buffer);
686
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
687
+	    $buffer = explode('\n', $buffer);
688 688
 	    foreach ($buffer as $line) {
689 689
 		if ($line != '') {
690 690
 		    $data = array();
691 691
 		    echo $line."\n";
692
-		    $data['mmsi'] = (int)substr($line,0,9);
693
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
694
-		    $data['status_id'] = substr($line,21,2);
695
-		    $data['type_id'] = substr($line,24,3);
696
-		    $data['latitude'] = substr($line,29,9);
697
-		    $data['longitude'] = substr($line,41,9);
698
-		    $data['speed'] = round(substr($line,51,5));
692
+		    $data['mmsi'] = (int) substr($line, 0, 9);
693
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
694
+		    $data['status_id'] = substr($line, 21, 2);
695
+		    $data['type_id'] = substr($line, 24, 3);
696
+		    $data['latitude'] = substr($line, 29, 9);
697
+		    $data['longitude'] = substr($line, 41, 9);
698
+		    $data['speed'] = round(substr($line, 51, 5));
699 699
 		    //$data['course'] = substr($line,57,5);
700
-		    $data['heading'] = round(substr($line,63,3));
700
+		    $data['heading'] = round(substr($line, 63, 3));
701 701
 		    //$data['draft'] = substr($line,67,4);
702 702
 		    //$data['length'] = substr($line,72,3);
703 703
 		    //$data['beam'] = substr($line,76,2);
704
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
704
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
705 705
 		    //$data['callsign'] = trim(substr($line,100,7);
706
-		    $data['arrival_code'] = substr($line,108,20);
706
+		    $data['arrival_code'] = substr($line, 108, 20);
707 707
 		    //$data['etaDate'] = substr($line,129,5);
708 708
 		    //$data['etaTime'] = substr($line,135,5);
709 709
 		    $data['format_source'] = 'shipplotter';
@@ -734,8 +734,8 @@  discard block
 block discarded – undo
734 734
 	) {
735 735
 	    //$buffer = $Common->getData($hosts[$id]);
736 736
 	    $buffer = $Common->getData($value['host']);
737
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
738
-	    $buffer = explode('\n',$buffer);
737
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
738
+	    $buffer = explode('\n', $buffer);
739 739
 	    $reset = 0;
740 740
 	    foreach ($buffer as $line) {
741 741
     		if ($line != '') {
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
747 747
 			$data['pilot_id'] = $line[1];
748 748
 			$data['pilot_name'] = $line[2];
749
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
749
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
750 750
 			$data['ident'] = $line[0]; // ident
751 751
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
752 752
 			$data['speed'] = $line[8]; // speed
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
763 763
 			//if (isset($line[37])) $data['last_update'] = $line[37];
764 764
 		        $data['departure_airport_icao'] = $line[11];
765
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
765
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
766 766
 		        $data['arrival_airport_icao'] = $line[13];
767 767
 			$data['frequency'] = $line[4];
768 768
 			$data['type'] = $line[18];
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
     			$data['id_source'] = $id_source;
772 772
 	    		//$data['arrival_airport_time'] = ;
773 773
 	    		if ($line[9] != '') {
774
-	    		    $aircraft_data = explode('/',$line[9]);
774
+	    		    $aircraft_data = explode('/', $line[9]);
775 775
 	    		    if (isset($aircraft_data[1])) {
776 776
 	    			$data['aircraft_icao'] = $aircraft_data[1];
777 777
 	    		    }
@@ -786,9 +786,9 @@  discard block
 block discarded – undo
786 786
     			if ($line[3] == 'PILOT') $SI->add($data);
787 787
 			elseif ($line[3] == 'ATC') {
788 788
 				//print_r($data);
789
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
790
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
791
-				$typec = substr($data['ident'],-3);
789
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
790
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
791
+				$typec = substr($data['ident'], -3);
792 792
 				if ($typec == 'APP') $data['type'] = 'Approach';
793 793
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
794 794
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -800,8 +800,8 @@  discard block
 block discarded – undo
800 800
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
801 801
 				if (!isset($data['source_name'])) $data['source_name'] = '';
802 802
 				if (isset($ATC)) {
803
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
804
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
803
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
804
+					else echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
805 805
 				}
806 806
 			}
807 807
     			unset($data);
@@ -817,24 +817,24 @@  discard block
 block discarded – undo
817 817
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
818 818
     	    )
819 819
     	) {
820
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
820
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
821 821
 	    if ($buffer != '') {
822 822
 		$all_data = simplexml_load_string($buffer);
823
-		foreach($all_data->children() as $childdata) {
823
+		foreach ($all_data->children() as $childdata) {
824 824
 			$data = array();
825 825
 			$line = $childdata;
826 826
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
827
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
828
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
829
-			$data['latitude'] = (float)$line['pktLatitude'];
830
-			$data['longitude'] = (float)$line['pktLongitude'];
831
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
832
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
833
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
827
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
828
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
829
+			$data['latitude'] = (float) $line['pktLatitude'];
830
+			$data['longitude'] = (float) $line['pktLongitude'];
831
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
832
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
833
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
834 834
 			$data['altitude_relative'] = 'AMSL';
835
-			$data['pilot_id'] = (int)$line['pktPilotID'];
835
+			$data['pilot_id'] = (int) $line['pktPilotID'];
836 836
 			$data['aircraft_icao'] = 'PARAGLIDER';
837
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
837
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
838 838
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
839 839
 			$data['format_source'] = $value['format'];
840 840
 			$SI->add($data);
@@ -842,22 +842,22 @@  discard block
 block discarded – undo
842 842
 		}
843 843
 	    }
844 844
 	    $Source->deleteOldLocationByType('gs');
845
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
845
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
846 846
 	    if ($buffer != '') {
847 847
 		$all_data = simplexml_load_string($buffer);
848
-		foreach($all_data->children() as $childdata) {
848
+		foreach ($all_data->children() as $childdata) {
849 849
 			$data = array();
850 850
 			$line = $childdata;
851
-			$data['id'] = (int)$line['gsID'];
852
-			$data['latitude'] = (float)$line['gsLatitude'];
853
-			$data['longitude'] = (float)$line['gsLongitude'];
854
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
851
+			$data['id'] = (int) $line['gsID'];
852
+			$data['latitude'] = (float) $line['gsLatitude'];
853
+			$data['longitude'] = (float) $line['gsLongitude'];
854
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
855 855
 			$data['altitude_relative'] = 'AMSL';
856
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
856
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
857 857
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
858
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
858
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
859 859
 			} else {
860
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
860
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
861 861
 			}
862 862
 			unset($data);
863 863
 		}
@@ -875,9 +875,9 @@  discard block
 block discarded – undo
875 875
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
876 876
 	    )
877 877
 	) {
878
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
878
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
879 879
 	    if ($buffer != '') {
880
-	        $all_data = json_decode($buffer,true);
880
+	        $all_data = json_decode($buffer, true);
881 881
 		if (isset($all_data['acList'])) {
882 882
 		    $reset = 0;
883 883
 		    foreach ($all_data['acList'] as $line) {
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
894 894
 			$data['emergency'] = ''; // emergency
895 895
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
896
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
896
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
897 897
 			else $data['datetime'] = date('Y-m-d H:i:s');
898 898
 			//$data['datetime'] = date('Y-m-d H:i:s');
899 899
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 			$data['verticalrate'] = $line['vrt']; // verticale rate
919 919
 			$data['squawk'] = $line['squawk']; // squawk
920 920
 			$data['emergency'] = ''; // emergency
921
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
921
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
922 922
 			else $data['datetime'] = date('Y-m-d H:i:s');
923 923
 			$data['format_source'] = 'aircraftlistjson';
924 924
 			$data['id_source'] = $id_source;
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
     	    )
940 940
     	) {
941 941
 	    $buffer = $Common->getData($value['host']);
942
-	    $all_data = json_decode($buffer,true);
942
+	    $all_data = json_decode($buffer, true);
943 943
 	    if (isset($all_data['planes'])) {
944 944
 		$reset = 0;
945 945
 		foreach ($all_data['planes'] as $key => $line) {
@@ -956,12 +956,12 @@  discard block
 block discarded – undo
956 956
 		    $data['emergency'] = ''; // emergency
957 957
 		    $data['registration'] = $line[2];
958 958
 		    $data['aircraft_icao'] = $line[0];
959
-		    $deparr = explode('-',$line[1]);
959
+		    $deparr = explode('-', $line[1]);
960 960
 		    if (count($deparr) == 2) {
961 961
 			$data['departure_airport_icao'] = $deparr[0];
962 962
 			$data['arrival_airport_icao'] = $deparr[1];
963 963
 		    }
964
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
964
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
965 965
 	    	    $data['format_source'] = 'planeupdatefaa';
966 966
     		    $data['id_source'] = $id_source;
967 967
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 	    )
980 980
 	) {
981 981
 	    $buffer = $Common->getData($value['host']);
982
-	    $all_data = json_decode($buffer,true);
982
+	    $all_data = json_decode($buffer, true);
983 983
 	    if (isset($all_data['states'])) {
984 984
 		$reset = 0;
985 985
 		foreach ($all_data['states'] as $key => $line) {
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 		    //$data['emergency'] = ''; // emergency
997 997
 		    //$data['registration'] = $line[2];
998 998
 		    //$data['aircraft_icao'] = $line[0];
999
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
999
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1000 1000
 		    $data['format_source'] = 'opensky';
1001 1001
 		    $data['id_source'] = $id_source;
1002 1002
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 	) {
1016 1016
 	    //$buffer = $Common->getData($hosts[$id]);
1017 1017
 	    $buffer = $Common->getData($value['host']);
1018
-	    $all_data = json_decode($buffer,true);
1018
+	    $all_data = json_decode($buffer, true);
1019 1019
 	    if (!empty($all_data)) $reset = 0;
1020 1020
 	    foreach ($all_data as $key => $line) {
1021 1021
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
 	    )
1054 1054
 	) {
1055 1055
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1056
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1056
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1057 1057
 	    //echo $buffer;
1058
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1059
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1060
-	    $all_data = json_decode($buffer,true);
1058
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1059
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1060
+	    $all_data = json_decode($buffer, true);
1061 1061
 	    if (json_last_error() != JSON_ERROR_NONE) {
1062 1062
 		die(json_last_error_msg());
1063 1063
 	    }
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 			//$data['departure_airport_iata'] = $line[11];
1081 1081
 			//$data['arrival_airport_iata'] = $line[12];
1082 1082
 	    		//$data['emergency'] = ''; // emergency
1083
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1083
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1084 1084
 	    		$data['format_source'] = 'radarvirtueljson';
1085 1085
     			$data['id_source'] = $id_source;
1086 1086
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1101,14 +1101,14 @@  discard block
 block discarded – undo
1101 1101
 	) {
1102 1102
 	    //$buffer = $Common->getData($hosts[$id]);
1103 1103
 	    $buffer = $Common->getData($value['host'].'?'.time());
1104
-	    $all_data = json_decode(utf8_encode($buffer),true);
1104
+	    $all_data = json_decode(utf8_encode($buffer), true);
1105 1105
 	    
1106 1106
 	    if (isset($all_data['pireps'])) {
1107 1107
 		$reset = 0;
1108 1108
 	        foreach ($all_data['pireps'] as $line) {
1109 1109
 		    $data = array();
1110 1110
 		    $data['id'] = $line['id'];
1111
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1111
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1112 1112
 		    $data['ident'] = $line['callsign']; // ident
1113 1113
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1114 1114
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1138,9 +1138,9 @@  discard block
 block discarded – undo
1138 1138
 			$SI->add($data);
1139 1139
 		    //    print_r($data);
1140 1140
     		    } elseif ($line['icon'] == 'ct') {
1141
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1142
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1143
-			$typec = substr($data['ident'],-3);
1141
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1142
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1143
+			$typec = substr($data['ident'], -3);
1144 1144
 			$data['type'] = '';
1145 1145
 			if ($typec == 'APP') $data['type'] = 'Approach';
1146 1146
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1152 1152
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1153 1153
 			else $data['type'] = 'Observer';
1154
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1154
+			if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']);
1155 1155
 		    }
1156 1156
 		    unset($data);
1157 1157
 		}
@@ -1168,14 +1168,14 @@  discard block
 block discarded – undo
1168 1168
 	    //$buffer = $Common->getData($hosts[$id]);
1169 1169
 	    if ($globalDebug) echo 'Get Data...'."\n";
1170 1170
 	    $buffer = $Common->getData($value['host']);
1171
-	    $all_data = json_decode($buffer,true);
1171
+	    $all_data = json_decode($buffer, true);
1172 1172
 	    if ($buffer != '' && is_array($all_data)) {
1173 1173
 		$reset = 0;
1174 1174
 		foreach ($all_data as $line) {
1175 1175
 	    	    $data = array();
1176 1176
 	    	    //$data['id'] = $line['id']; // id not usable
1177 1177
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1178
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1178
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1179 1179
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1180 1180
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1181 1181
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 	    	    //$data['datetime'] = $line['lastupdate'];
1191 1191
 	    	    //$data['last_update'] = $line['lastupdate'];
1192 1192
 	    	    if (isset($value['timezone'])) {
1193
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1193
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1194 1194
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1195 1195
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1196 1196
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1206,14 +1206,14 @@  discard block
 block discarded – undo
1206 1206
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1207 1207
 		    if (isset($line['aircraftname'])) {
1208 1208
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1209
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1210
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1209
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1210
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1211 1211
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1212 1212
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1213 1213
 	    		else {
1214
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1215
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1216
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1214
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1215
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1216
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1217 1217
 	    		}
1218 1218
 	    	    }
1219 1219
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
 	    //$buffer = $Common->getData($hosts[$id]);
1239 1239
 	    if ($globalDebug) echo 'Get Data...'."\n";
1240 1240
 	    $buffer = $Common->getData($value['host']);
1241
-	    $all_data = json_decode($buffer,true);
1241
+	    $all_data = json_decode($buffer, true);
1242 1242
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1243 1243
 		$reset = 0;
1244 1244
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1250 1250
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1251 1251
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1252
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1252
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1253 1253
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1254 1254
 	    	    $data['altitude'] = $line['altitude']; // altitude
1255 1255
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 	    	    //$data['squawk'] = ''; // squawk
1261 1261
 	    	    //$data['emergency'] = ''; // emergency
1262 1262
 	    	    if (isset($value['timezone'])) {
1263
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1263
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1264 1264
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1265 1265
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1266 1266
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1296,14 +1296,14 @@  discard block
 block discarded – undo
1296 1296
 	    //$buffer = $Common->getData($hosts[$id]);
1297 1297
 	    if ($globalDebug) echo 'Get Data...'."\n";
1298 1298
 	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1299
+	    $all_data = json_decode($buffer, true);
1300 1300
 	    if ($buffer != '' && is_array($all_data)) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data as $line) {
1303 1303
 	    	    $data = array();
1304 1304
 	    	    //$data['id'] = $line['id']; // id not usable
1305 1305
 	    	    $data['id'] = trim($line['flight_id']);
1306
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1306
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1307 1307
 	    	    $data['pilot_name'] = $line['pilot_name'];
1308 1308
 	    	    $data['pilot_id'] = $line['pilot_id'];
1309 1309
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1347,24 +1347,24 @@  discard block
 block discarded – undo
1347 1347
 	    //$buffer = $Common->getData($hosts[$id]);
1348 1348
 	    if ($globalDebug) echo 'Get Data...'."\n";
1349 1349
 	    $buffer = $Common->getData($value['host']);
1350
-	    $all_data = json_decode($buffer,true);
1350
+	    $all_data = json_decode($buffer, true);
1351 1351
 	    if ($buffer != '') {
1352 1352
 		$Source->deleteLocationBySource('blitzortung');
1353
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1354
-		$buffer = explode('\n',$buffer);
1353
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1354
+		$buffer = explode('\n', $buffer);
1355 1355
 		foreach ($buffer as $buffer_line) {
1356
-		    $line = json_decode($buffer_line,true);
1356
+		    $line = json_decode($buffer_line, true);
1357 1357
 		    if (isset($line['time'])) {
1358 1358
 			$data = array();
1359 1359
 			$data['altitude'] = $line['alt']; // altitude
1360 1360
 			$data['latitude'] = $line['lat']; // lat
1361 1361
 			$data['longitude'] = $line['lon']; // long
1362
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1362
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1363 1363
 			$data['id_source'] = $id_source;
1364 1364
 			$data['format_source'] = 'blitzortung';
1365 1365
 			$SI->add($data);
1366 1366
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1367
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1367
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1368 1368
 			unset($data);
1369 1369
 		    }
1370 1370
 		}
@@ -1389,11 +1389,11 @@  discard block
 block discarded – undo
1389 1389
 		    //$value = $formats[$nb];
1390 1390
 		    $format = $globalSources[$nb]['format'];
1391 1391
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1392
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1392
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1393 1393
 		    } elseif ($format == 'vrstcp') {
1394 1394
 			$buffer = @socket_read($r, 6000);
1395 1395
 		    } else {
1396
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1396
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1397 1397
 		    }
1398 1398
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1399 1399
 		    //echo $buffer."\n";
@@ -1403,8 +1403,8 @@  discard block
 block discarded – undo
1403 1403
 		    //$SI::del();
1404 1404
 		    if ($buffer !== FALSE) {
1405 1405
 			if ($format == 'vrstcp') {
1406
-			    $buffer = explode('},{',$buffer);
1407
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1406
+			    $buffer = explode('},{', $buffer);
1407
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1408 1408
 		    }
1409 1409
 		    // SBS format is CSV format
1410 1410
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 			    $ais_data = $AIS->parse_line(trim($buffer));
1429 1429
 			    $data = array();
1430 1430
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1431
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1431
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1432 1432
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1433 1433
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1434 1434
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1439,13 +1439,13 @@  discard block
 block discarded – undo
1439 1439
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1440 1440
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1441 1441
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1442
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1442
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1443 1443
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1444 1444
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1445 1445
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1446 1446
 
1447 1447
 			    if (isset($ais_data['timestamp'])) {
1448
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1448
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1449 1449
 			    } else {
1450 1450
 				$data['datetime'] = date('Y-m-d H:i:s');
1451 1451
 			    }
@@ -1456,10 +1456,10 @@  discard block
 block discarded – undo
1456 1456
                         } elseif ($format == 'flightgearsp') {
1457 1457
                     	    //echo $buffer."\n";
1458 1458
                     	    if (strlen($buffer) > 5) {
1459
-				$line = explode(',',$buffer);
1459
+				$line = explode(',', $buffer);
1460 1460
 				$data = array();
1461 1461
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1462
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1462
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1463 1463
 				$data['ident'] = $line[6];
1464 1464
 				$data['aircraft_name'] = $line[7];
1465 1465
 				$data['longitude'] = $line[1];
@@ -1476,16 +1476,16 @@  discard block
 block discarded – undo
1476 1476
                         } elseif ($format == 'acars') {
1477 1477
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1478 1478
 			    $ACARS->add(trim($buffer));
1479
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1479
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1480 1480
 			    $ACARS->deleteLiveAcarsData();
1481 1481
 			} elseif ($format == 'flightgearmp') {
1482
-			    if (substr($buffer,0,1) != '#') {
1482
+			    if (substr($buffer, 0, 1) != '#') {
1483 1483
 				$data = array();
1484 1484
 				//echo $buffer."\n";
1485
-				$line = explode(' ',$buffer);
1485
+				$line = explode(' ', $buffer);
1486 1486
 				if (count($line) == 11) {
1487
-				    $userserver = explode('@',$line[0]);
1488
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1487
+				    $userserver = explode('@', $line[0]);
1488
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1489 1489
 				    $data['ident'] = $userserver[0];
1490 1490
 				    $data['registration'] = $userserver[0];
1491 1491
 				    $data['latitude'] = $line[4];
@@ -1493,8 +1493,8 @@  discard block
 block discarded – undo
1493 1493
 				    $data['altitude'] = $line[6];
1494 1494
 				    $data['datetime'] = date('Y-m-d H:i:s');
1495 1495
 				    $aircraft_type = $line[10];
1496
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1497
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1496
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1497
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1498 1498
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1499 1499
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1500 1500
 				}
@@ -1503,8 +1503,8 @@  discard block
 block discarded – undo
1503 1503
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1504 1504
 			    die;
1505 1505
 			} elseif ($format == 'vrstcp') {
1506
-			    foreach($buffer as $all_data) {
1507
-				$line = json_decode('{'.$all_data.'}',true);
1506
+			    foreach ($buffer as $all_data) {
1507
+				$line = json_decode('{'.$all_data.'}', true);
1508 1508
 				$data = array();
1509 1509
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1510 1510
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1530,16 +1530,16 @@  discard block
 block discarded – undo
1530 1530
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1531 1531
 				unset($data);
1532 1532
 			    }
1533
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1533
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1534 1534
 			    $line = explode("\t", $buffer);
1535
-			    for($k = 0; $k < count($line); $k=$k+2) {
1535
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1536 1536
 				$key = $line[$k];
1537
-			        $lined[$key] = $line[$k+1];
1537
+			        $lined[$key] = $line[$k + 1];
1538 1538
 			    }
1539 1539
     			    if (count($lined) > 3) {
1540 1540
     				$data['hex'] = $lined['hexid'];
1541 1541
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1542
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1542
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1543 1543
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1544 1544
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1545 1545
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1558,23 +1558,23 @@  discard block
 block discarded – undo
1558 1558
     			    } else $error = true;
1559 1559
 			} elseif ($format == 'aprs' && $use_aprs) {
1560 1560
 			    if ($aprs_connect == 0) {
1561
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1561
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1562 1562
 				$aprs_connect = 1;
1563 1563
 			    }
1564 1564
 			    
1565
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1565
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1566 1566
 				$aprs_last_tx = time();
1567 1567
 				$data_aprs = "# Keep alive";
1568
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1568
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1569 1569
 			    }
1570 1570
 			    
1571 1571
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1572 1572
 			    //echo 'APRS data : '.$buffer."\n";
1573
-			    $buffer = str_replace('APRS <- ','',$buffer);
1574
-			    $buffer = str_replace('APRS -> ','',$buffer);
1573
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1574
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1575 1575
 			    //echo $buffer."\n";
1576 1576
 			    date_default_timezone_set('UTC');
1577
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1577
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1578 1578
 				$line = $APRS->parse($buffer);
1579 1579
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1580 1580
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1590 1590
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1591 1591
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1592
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1592
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1593 1593
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1594 1594
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1595 1595
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1672,29 +1672,29 @@  discard block
 block discarded – undo
1672 1672
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1673 1673
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1674 1674
 					$Source->deleteOldLocationByType('gs');
1675
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1676
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1675
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1676
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1677 1677
 					} else {
1678
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1678
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1679 1679
 					}
1680 1680
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1681 1681
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1682 1682
 					if ($globalDebug) echo '# Weather Station added'."\n";
1683 1683
 					$Source->deleteOldLocationByType('wx');
1684 1684
 					$weather_data = json_encode($line);
1685
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1686
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1685
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1686
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1687 1687
 					} else {
1688
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1688
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1689 1689
 					}
1690 1690
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1691 1691
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1692 1692
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1693 1693
 					$Source->deleteOldLocationByType('lightning');
1694
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1695
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1694
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1695
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1696 1696
 					} else {
1697
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1697
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1698 1698
 					}
1699 1699
 				    } elseif ($globalDebug) {
1700 1700
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1703,7 +1703,7 @@  discard block
 block discarded – undo
1703 1703
 				    unset($data);
1704 1704
 				}
1705 1705
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1706
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1706
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1707 1707
 				}
1708 1708
 				/*
1709 1709
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
 				*/
1713 1713
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1714 1714
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1715
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1715
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1716 1716
 					$Source->deleteOldLocationByType('lightning');
1717 1717
 					$Source->deleteOldLocationByType('wx');
1718 1718
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
 				connect_all($sourceee);
1798 1798
 				$sourceee = array();
1799 1799
 				//connect_all($globalSources);
1800
-				$tt[$format]=0;
1800
+				$tt[$format] = 0;
1801 1801
 				break;
1802 1802
 			    } 
1803 1803
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -1807,14 +1807,14 @@  discard block
 block discarded – undo
1807 1807
 	    } else {
1808 1808
 		$error = socket_strerror(socket_last_error());
1809 1809
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1810
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1810
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1811 1811
 			if (isset($globalDebug)) echo "Restarting...\n";
1812 1812
 			// Restart the script if possible
1813 1813
 			if (is_array($sockets)) {
1814 1814
 			    if ($globalDebug) echo "Shutdown all sockets...";
1815 1815
 			    
1816 1816
 			    foreach ($sockets as $sock) {
1817
-				@socket_shutdown($sock,2);
1817
+				@socket_shutdown($sock, 2);
1818 1818
 				@socket_close($sock);
1819 1819
 			    }
1820 1820
 			    
Please login to merge, or discard this patch.