Completed
Push — master ( edc2c3...411a33 )
by Yannick
57:10 queued 24:31
created
require/class.Marine.php 3 patches
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 	}
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	
20 20
 	public function getFilter($filter = array(),$where = false,$and = false) {
21 21
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
 	}
89 89
 
90 90
 	/**
91
-	* Executes the SQL statements to get the spotter information
92
-	*
93
-	* @param String $query the SQL query
94
-	* @param Array $params parameter of the query
95
-	* @param String $limitQuery the limit query
96
-	* @return Array the spotter information
97
-	*
98
-	*/
91
+	 * Executes the SQL statements to get the spotter information
92
+	 *
93
+	 * @param String $query the SQL query
94
+	 * @param Array $params parameter of the query
95
+	 * @param String $limitQuery the limit query
96
+	 * @return Array the spotter information
97
+	 *
98
+	 */
99 99
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
100 100
 	{
101 101
 		date_default_timezone_set('UTC');
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 	
234 234
 	
235 235
 	/**
236
-	* Gets all the spotter information based on the latest data entry
237
-	*
238
-	* @return Array the spotter information
239
-	*
240
-	*/
236
+	 * Gets all the spotter information based on the latest data entry
237
+	 *
238
+	 * @return Array the spotter information
239
+	 *
240
+	 */
241 241
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
242 242
 	{
243 243
 		global $global_marine_query;
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 	}
287 287
 
288 288
 	/**
289
-	* Gets all the spotter information based on the callsign
290
-	*
291
-	* @return Array the spotter information
292
-	*
293
-	*/
289
+	 * Gets all the spotter information based on the callsign
290
+	 *
291
+	 * @return Array the spotter information
292
+	 *
293
+	 */
294 294
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
295 295
 	{
296 296
 		global $global_marine_query;
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 	}
343 343
 
344 344
 	/**
345
-	* Gets all the marine information based on the type
346
-	*
347
-	* @return Array the marine information
348
-	*
349
-	*/
345
+	 * Gets all the marine information based on the type
346
+	 *
347
+	 * @return Array the marine information
348
+	 *
349
+	 */
350 350
 	public function getMarineDataByType($type = '', $limit = '', $sort = '', $filter = array())
351 351
 	{
352 352
 		global $global_marine_query;
@@ -452,11 +452,11 @@  discard block
 block discarded – undo
452 452
 	}
453 453
 
454 454
 	/**
455
-	* Gets all the marine information based on the captain
456
-	*
457
-	* @return Array the marine information
458
-	*
459
-	*/
455
+	 * Gets all the marine information based on the captain
456
+	 *
457
+	 * @return Array the marine information
458
+	 *
459
+	 */
460 460
 	public function getMarineDataByCaptain($captain = '', $limit = '', $sort = '', $filter = array())
461 461
 	{
462 462
 		global $global_marine_query;
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
 	}
496 496
 
497 497
 	/**
498
-	* Gets all the marine information based on the race
499
-	*
500
-	* @return Array the marine information
501
-	*
502
-	*/
498
+	 * Gets all the marine information based on the race
499
+	 *
500
+	 * @return Array the marine information
501
+	 *
502
+	 */
503 503
 	public function getMarineDataByRace($race = '', $limit = '', $sort = '', $filter = array())
504 504
 	{
505 505
 		global $global_marine_query;
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
 	}
539 539
 
540 540
 	/**
541
-	* Count races by captain
542
-	*
543
-	* @return String Duration of all races
544
-	*
545
-	*/
541
+	 * Count races by captain
542
+	 *
543
+	 * @return String Duration of all races
544
+	 *
545
+	 */
546 546
 	public function countRacesByCaptain($captain,$filters = array())
547 547
 	{
548 548
 		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
 	}
559 559
 
560 560
 	/**
561
-	* Count captains by race
562
-	*
563
-	* @return String Duration of all races
564
-	*
565
-	*/
561
+	 * Count captains by race
562
+	 *
563
+	 * @return String Duration of all races
564
+	 *
565
+	 */
566 566
 	public function countCaptainsByRace($race,$filters = array())
567 567
 	{
568 568
 		$race = filter_var($race,FILTER_SANITIZE_STRING);
@@ -578,11 +578,11 @@  discard block
 block discarded – undo
578 578
 	}
579 579
 
580 580
 	/**
581
-	* Gets all boat types that have been used by a captain
582
-	*
583
-	* @return Array the boat list
584
-	*
585
-	*/
581
+	 * Gets all boat types that have been used by a captain
582
+	 *
583
+	 * @return Array the boat list
584
+	 *
585
+	 */
586 586
 	public function countAllBoatTypesByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
587 587
 	{
588 588
 		global $globalDBdriver;
@@ -627,11 +627,11 @@  discard block
 block discarded – undo
627 627
 	}
628 628
 
629 629
 	/**
630
-	* Gets all boat types that have been used on a race
631
-	*
632
-	* @return Array the boat list
633
-	*
634
-	*/
630
+	 * Gets all boat types that have been used on a race
631
+	 *
632
+	 * @return Array the boat list
633
+	 *
634
+	 */
635 635
 	public function countAllBoatTypesByRace($race,$filters = array(),$year = '',$month = '',$day = '')
636 636
 	{
637 637
 		global $globalDBdriver;
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
 	}
677 677
 
678 678
 	/**
679
-	* Gets race duration by captain
680
-	*
681
-	* @return String Duration of all race
682
-	*
683
-	*/
679
+	 * Gets race duration by captain
680
+	 *
681
+	 * @return String Duration of all race
682
+	 *
683
+	 */
684 684
 	public function getRaceDurationByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
685 685
 	{
686 686
 		global $globalDBdriver;
@@ -726,11 +726,11 @@  discard block
 block discarded – undo
726 726
 	}
727 727
 
728 728
 	/**
729
-	* Gets a list of all captain names and captain ids
730
-	*
731
-	* @return Array list of captain names and captain ids
732
-	*
733
-	*/
729
+	 * Gets a list of all captain names and captain ids
730
+	 *
731
+	 * @return Array list of captain names and captain ids
732
+	 *
733
+	 */
734 734
 	public function getAllCaptainNames($filters = array())
735 735
 	{
736 736
 		$filter_query = $this->getFilter($filters,true,true);
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
 	} 
745 745
 
746 746
 	/**
747
-	* Gets a list of all race names and race ids
748
-	*
749
-	* @return Array list of race names and race ids
750
-	*
751
-	*/
747
+	 * Gets a list of all race names and race ids
748
+	 *
749
+	 * @return Array list of race names and race ids
750
+	 *
751
+	 */
752 752
 	public function getAllRaceNames($filters = array())
753 753
 	{
754 754
 		$filter_query = $this->getFilter($filters,true,true);
@@ -762,12 +762,12 @@  discard block
 block discarded – undo
762 762
 	} 
763 763
 
764 764
 	/**
765
-	* Gets all source name
766
-	*
767
-	* @param String type format of source
768
-	* @return Array list of source name
769
-	*
770
-	*/
765
+	 * Gets all source name
766
+	 *
767
+	 * @param String type format of source
768
+	 * @return Array list of source name
769
+	 *
770
+	 */
771 771
 	public function getAllSourceName($type = '',$filters = array())
772 772
 	{
773 773
 		$filter_query = $this->getFilter($filters,true,true);
@@ -797,11 +797,11 @@  discard block
 block discarded – undo
797 797
 
798 798
 
799 799
 	/**
800
-	* Gets a list of all idents/callsigns
801
-	*
802
-	* @return Array list of ident/callsign names
803
-	*
804
-	*/
800
+	 * Gets a list of all idents/callsigns
801
+	 *
802
+	 * @return Array list of ident/callsign names
803
+	 *
804
+	 */
805 805
 	public function getAllIdents($filters = array())
806 806
 	{
807 807
 		$filter_query = $this->getFilter($filters,true,true);
@@ -825,11 +825,11 @@  discard block
 block discarded – undo
825 825
 	}
826 826
 
827 827
 	/**
828
-	* Gets all info from a mmsi
829
-	*
830
-	* @return Array ident
831
-	*
832
-	*/
828
+	 * Gets all info from a mmsi
829
+	 *
830
+	 * @return Array ident
831
+	 *
832
+	 */
833 833
 	public function getIdentity($mmsi)
834 834
 	{
835 835
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -842,9 +842,9 @@  discard block
 block discarded – undo
842 842
 	}
843 843
 
844 844
 	/**
845
-	* Add identity
846
-	*
847
-	*/
845
+	 * Add identity
846
+	 *
847
+	 */
848 848
 	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
849 849
 	{
850 850
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -910,13 +910,13 @@  discard block
 block discarded – undo
910 910
 	}
911 911
 
912 912
 	/**
913
-	* Update ident tracker data
914
-	*
915
-	* @param String $fammarine_id the ID
916
-	* @param String $ident the marine ident
917
-	* @return String success or false
918
-	*
919
-	*/
913
+	 * Update ident tracker data
914
+	 *
915
+	 * @param String $fammarine_id the ID
916
+	 * @param String $ident the marine ident
917
+	 * @return String success or false
918
+	 *
919
+	 */
920 920
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
921 921
 	{
922 922
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
@@ -931,13 +931,13 @@  discard block
 block discarded – undo
931 931
 	}
932 932
 
933 933
 	/**
934
-	* Update arrival marine data
935
-	*
936
-	* @param String $fammarine_id the ID
937
-	* @param String $arrival_code the marine ident
938
-	* @return String success or false
939
-	*
940
-	*/
934
+	 * Update arrival marine data
935
+	 *
936
+	 * @param String $fammarine_id the ID
937
+	 * @param String $arrival_code the marine ident
938
+	 * @return String success or false
939
+	 *
940
+	 */
941 941
 	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL)
942 942
 	{
943 943
 		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id';
@@ -952,19 +952,19 @@  discard block
 block discarded – undo
952 952
 	}
953 953
 
954 954
 	/**
955
-	* Update Status data
956
-	*
957
-	* @param String $fammarine_id the ID
958
-	* @param String $status_id the marine status id
959
-	* @param String $status the marine status
960
-	* @return String success or false
961
-	*
962
-	*/
955
+	 * Update Status data
956
+	 *
957
+	 * @param String $fammarine_id the ID
958
+	 * @param String $status_id the marine status id
959
+	 * @param String $status the marine status
960
+	 * @return String success or false
961
+	 *
962
+	 */
963 963
 	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
964 964
 	{
965 965
 
966 966
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
967
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
967
+				$query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
968 968
 
969 969
 		try {
970 970
 			$sth = $this->db->prepare($query);
@@ -977,13 +977,13 @@  discard block
 block discarded – undo
977 977
 
978 978
 	}
979 979
 	/**
980
-	* Update latest marine data
981
-	*
982
-	* @param String $fammarine_id the ID
983
-	* @param String $ident the marine ident
984
-	* @return String success or false
985
-	*
986
-	*/	
980
+	 * Update latest marine data
981
+	 *
982
+	 * @param String $fammarine_id the ID
983
+	 * @param String $ident the marine ident
984
+	 * @return String success or false
985
+	 *
986
+	 */	
987 987
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '',$distance = NULL,$race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '')
988 988
 	{
989 989
 		if ($latitude == '') $latitude = NULL;
@@ -1009,30 +1009,30 @@  discard block
 block discarded – undo
1009 1009
 	}
1010 1010
 
1011 1011
 	/**
1012
-	* Adds a new marine data
1013
-	*
1014
-	* @param String $fammarine_id the ID
1015
-	* @param String $ident the marine ident
1016
-	* @param String $departure_airport_icao the departure airport
1017
-	* @param String $arrival_airport_icao the arrival airport
1018
-	* @param String $latitude latitude of flight
1019
-	* @param String $longitude latitude of flight
1020
-	* @param String $waypoints waypoints of flight
1021
-	* @param String $heading heading of flight
1022
-	* @param String $groundspeed speed of flight
1023
-	* @param String $date date of flight
1024
-	* @param String $departure_airport_time departure time of flight
1025
-	* @param String $arrival_airport_time arrival time of flight
1026
-	* @param String $squawk squawk code of flight
1027
-	* @param String $route_stop route stop of flight
1028
-	* @param String $highlight highlight or not
1029
-	* @param String $ModeS ModesS code of flight
1030
-	* @param String $registration registration code of flight
1031
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
1032
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
1033
-	* @param String $verticalrate vertival rate of flight
1034
-	* @return String success or false
1035
-	*/
1012
+	 * Adds a new marine data
1013
+	 *
1014
+	 * @param String $fammarine_id the ID
1015
+	 * @param String $ident the marine ident
1016
+	 * @param String $departure_airport_icao the departure airport
1017
+	 * @param String $arrival_airport_icao the arrival airport
1018
+	 * @param String $latitude latitude of flight
1019
+	 * @param String $longitude latitude of flight
1020
+	 * @param String $waypoints waypoints of flight
1021
+	 * @param String $heading heading of flight
1022
+	 * @param String $groundspeed speed of flight
1023
+	 * @param String $date date of flight
1024
+	 * @param String $departure_airport_time departure time of flight
1025
+	 * @param String $arrival_airport_time arrival time of flight
1026
+	 * @param String $squawk squawk code of flight
1027
+	 * @param String $route_stop route stop of flight
1028
+	 * @param String $highlight highlight or not
1029
+	 * @param String $ModeS ModesS code of flight
1030
+	 * @param String $registration registration code of flight
1031
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
1032
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
1033
+	 * @param String $verticalrate vertival rate of flight
1034
+	 * @return String success or false
1035
+	 */
1036 1036
 	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 = '', $captain_id = '',$captain_name = '',$race_id = '', $race_name = '', $distance = '',$race_rank = '', $race_time = '')
1037 1037
 	{
1038 1038
 		global $globalURL, $globalMarineImageFetch;
@@ -1165,11 +1165,11 @@  discard block
 block discarded – undo
1165 1165
 	
1166 1166
   
1167 1167
 	/**
1168
-	* Gets the aircraft ident within the last hour
1169
-	*
1170
-	* @return String the ident
1171
-	*
1172
-	*/
1168
+	 * Gets the aircraft ident within the last hour
1169
+	 *
1170
+	 * @return String the ident
1171
+	 *
1172
+	 */
1173 1173
 	public function getIdentFromLastHour($ident)
1174 1174
 	{
1175 1175
 		global $globalDBdriver, $globalTimezone;
@@ -1185,11 +1185,11 @@  discard block
 block discarded – undo
1185 1185
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
1186 1186
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
1187 1187
 			$query_data = array(':ident' => $ident);
1188
-    		}
1188
+			}
1189 1189
 		
1190 1190
 		$sth = $this->db->prepare($query);
1191 1191
 		$sth->execute($query_data);
1192
-    		$ident_result='';
1192
+			$ident_result='';
1193 1193
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1194 1194
 		{
1195 1195
 			$ident_result = $row['ident'];
@@ -1200,11 +1200,11 @@  discard block
 block discarded – undo
1200 1200
 	
1201 1201
 	
1202 1202
 	/**
1203
-	* Gets the aircraft data from the last 20 seconds
1204
-	*
1205
-	* @return Array the marine data
1206
-	*
1207
-	*/
1203
+	 * Gets the aircraft data from the last 20 seconds
1204
+	 *
1205
+	 * @return Array the marine data
1206
+	 *
1207
+	 */
1208 1208
 	public function getRealTimeData($q = '')
1209 1209
 	{
1210 1210
 		global $globalDBdriver;
@@ -1242,11 +1242,11 @@  discard block
 block discarded – undo
1242 1242
 	
1243 1243
 
1244 1244
 	/**
1245
-	* Gets all number of flight over countries
1246
-	*
1247
-	* @return Array the airline country list
1248
-	*
1249
-	*/
1245
+	 * Gets all number of flight over countries
1246
+	 *
1247
+	 * @return Array the airline country list
1248
+	 *
1249
+	 */
1250 1250
 
1251 1251
 	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
1252 1252
 	{
@@ -1319,11 +1319,11 @@  discard block
 block discarded – undo
1319 1319
 	
1320 1320
 	
1321 1321
 	/**
1322
-	* Gets all callsigns that have flown over
1323
-	*
1324
-	* @return Array the callsign list
1325
-	*
1326
-	*/
1322
+	 * Gets all callsigns that have flown over
1323
+	 *
1324
+	 * @return Array the callsign list
1325
+	 *
1326
+	 */
1327 1327
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
1328 1328
 	{
1329 1329
 		global $globalDBdriver;
@@ -1390,11 +1390,11 @@  discard block
 block discarded – undo
1390 1390
 
1391 1391
 
1392 1392
 	/**
1393
-	* Counts all dates
1394
-	*
1395
-	* @return Array the date list
1396
-	*
1397
-	*/
1393
+	 * Counts all dates
1394
+	 *
1395
+	 * @return Array the date list
1396
+	 *
1397
+	 */
1398 1398
 	public function countAllDates($filters = array())
1399 1399
 	{
1400 1400
 		global $globalTimezone, $globalDBdriver;
@@ -1440,11 +1440,11 @@  discard block
 block discarded – undo
1440 1440
 	
1441 1441
 	
1442 1442
 	/**
1443
-	* Counts all dates during the last 7 days
1444
-	*
1445
-	* @return Array the date list
1446
-	*
1447
-	*/
1443
+	 * Counts all dates during the last 7 days
1444
+	 *
1445
+	 * @return Array the date list
1446
+	 *
1447
+	 */
1448 1448
 	public function countAllDatesLast7Days($filters = array())
1449 1449
 	{
1450 1450
 		global $globalTimezone, $globalDBdriver;
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 			$query .= " GROUP BY date_name 
1467 1467
 								ORDER BY date_name ASC";
1468 1468
 			$query_data = array(':offset' => $offset);
1469
-    		}
1469
+			}
1470 1470
 		
1471 1471
 		$sth = $this->db->prepare($query);
1472 1472
 		$sth->execute($query_data);
@@ -1486,11 +1486,11 @@  discard block
 block discarded – undo
1486 1486
 	}
1487 1487
 
1488 1488
 	/**
1489
-	* Counts all dates during the last month
1490
-	*
1491
-	* @return Array the date list
1492
-	*
1493
-	*/
1489
+	 * Counts all dates during the last month
1490
+	 *
1491
+	 * @return Array the date list
1492
+	 *
1493
+	 */
1494 1494
 	public function countAllDatesLastMonth($filters = array())
1495 1495
 	{
1496 1496
 		global $globalTimezone, $globalDBdriver;
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
 			$query .= " GROUP BY date_name 
1513 1513
 								ORDER BY date_name ASC";
1514 1514
 			$query_data = array(':offset' => $offset);
1515
-    		}
1515
+			}
1516 1516
 		
1517 1517
 		$sth = $this->db->prepare($query);
1518 1518
 		$sth->execute($query_data);
@@ -1534,11 +1534,11 @@  discard block
 block discarded – undo
1534 1534
 
1535 1535
 
1536 1536
 	/**
1537
-	* Counts all month
1538
-	*
1539
-	* @return Array the month list
1540
-	*
1541
-	*/
1537
+	 * Counts all month
1538
+	 *
1539
+	 * @return Array the month list
1540
+	 *
1541
+	 */
1542 1542
 	public function countAllMonths($filters = array())
1543 1543
 	{
1544 1544
 		global $globalTimezone, $globalDBdriver;
@@ -1583,11 +1583,11 @@  discard block
 block discarded – undo
1583 1583
 	
1584 1584
 
1585 1585
 	/**
1586
-	* Counts all dates during the last year
1587
-	*
1588
-	* @return Array the date list
1589
-	*
1590
-	*/
1586
+	 * Counts all dates during the last year
1587
+	 *
1588
+	 * @return Array the date list
1589
+	 *
1590
+	 */
1591 1591
 	public function countAllMonthsLastYear($filters)
1592 1592
 	{
1593 1593
 		global $globalTimezone, $globalDBdriver;
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
 			$query .= " GROUP BY year_name, month_name
1610 1610
 								ORDER BY year_name, month_name ASC";
1611 1611
 			$query_data = array(':offset' => $offset);
1612
-    		}
1612
+			}
1613 1613
 		
1614 1614
 		$sth = $this->db->prepare($query);
1615 1615
 		$sth->execute($query_data);
@@ -1632,11 +1632,11 @@  discard block
 block discarded – undo
1632 1632
 	
1633 1633
 	
1634 1634
 	/**
1635
-	* Counts all hours
1636
-	*
1637
-	* @return Array the hour list
1638
-	*
1639
-	*/
1635
+	 * Counts all hours
1636
+	 *
1637
+	 * @return Array the hour list
1638
+	 *
1639
+	 */
1640 1640
 	public function countAllHours($orderby,$filters = array())
1641 1641
 	{
1642 1642
 		global $globalTimezone, $globalDBdriver;
@@ -1699,11 +1699,11 @@  discard block
 block discarded – undo
1699 1699
 	
1700 1700
 	
1701 1701
 	/**
1702
-	* Counts all hours by date
1703
-	*
1704
-	* @return Array the hour list
1705
-	*
1706
-	*/
1702
+	 * Counts all hours by date
1703
+	 *
1704
+	 * @return Array the hour list
1705
+	 *
1706
+	 */
1707 1707
 	public function countAllHoursByDate($date, $filters = array())
1708 1708
 	{
1709 1709
 		global $globalTimezone, $globalDBdriver;
@@ -1747,11 +1747,11 @@  discard block
 block discarded – undo
1747 1747
 	
1748 1748
 	
1749 1749
 	/**
1750
-	* Counts all hours by a ident/callsign
1751
-	*
1752
-	* @return Array the hour list
1753
-	*
1754
-	*/
1750
+	 * Counts all hours by a ident/callsign
1751
+	 *
1752
+	 * @return Array the hour list
1753
+	 *
1754
+	 */
1755 1755
 	public function countAllHoursByIdent($ident, $filters = array())
1756 1756
 	{
1757 1757
 		global $globalTimezone, $globalDBdriver;
@@ -1796,11 +1796,11 @@  discard block
 block discarded – undo
1796 1796
 	
1797 1797
 	
1798 1798
 	/**
1799
-	* Counts all vessels
1800
-	*
1801
-	* @return Integer the number of vessels
1802
-	*
1803
-	*/
1799
+	 * Counts all vessels
1800
+	 *
1801
+	 * @return Integer the number of vessels
1802
+	 *
1803
+	 */
1804 1804
 	public function countOverallMarine($filters = array(),$year = '',$month = '')
1805 1805
 	{
1806 1806
 		global $globalDBdriver;
@@ -1835,11 +1835,11 @@  discard block
 block discarded – undo
1835 1835
 	}
1836 1836
 	
1837 1837
 	/**
1838
-	* Counts all vessel type
1839
-	*
1840
-	* @return Integer the number of vessels
1841
-	*
1842
-	*/
1838
+	 * Counts all vessel type
1839
+	 *
1840
+	 * @return Integer the number of vessels
1841
+	 *
1842
+	 */
1843 1843
 	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1844 1844
 	{
1845 1845
 		global $globalDBdriver;
@@ -1874,11 +1874,11 @@  discard block
 block discarded – undo
1874 1874
 	
1875 1875
   
1876 1876
 	/**
1877
-	* Counts all hours of today
1878
-	*
1879
-	* @return Array the hour list
1880
-	*
1881
-	*/
1877
+	 * Counts all hours of today
1878
+	 *
1879
+	 * @return Array the hour list
1880
+	 *
1881
+	 */
1882 1882
 	public function countAllHoursFromToday($filters = array())
1883 1883
 	{
1884 1884
 		global $globalTimezone, $globalDBdriver;
@@ -1918,12 +1918,12 @@  discard block
 block discarded – undo
1918 1918
 	}
1919 1919
     
1920 1920
     
1921
-     /**
1922
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1923
-	*
1924
-	* @return Integer the Barrie Spotter ID
1921
+	 /**
1922
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1923
+	  *
1924
+	  * @return Integer the Barrie Spotter ID
1925 1925
 q	*
1926
-	*/
1926
+	  */
1927 1927
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1928 1928
 	{
1929 1929
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1944,13 +1944,13 @@  discard block
 block discarded – undo
1944 1944
   
1945 1945
  
1946 1946
 	/**
1947
-	* Parses a date string
1948
-	*
1949
-	* @param String $dateString the date string
1950
-	* @param String $timezone the timezone of a user
1951
-	* @return Array the time information
1952
-	*
1953
-	*/
1947
+	 * Parses a date string
1948
+	 *
1949
+	 * @param String $dateString the date string
1950
+	 * @param String $timezone the timezone of a user
1951
+	 * @return Array the time information
1952
+	 *
1953
+	 */
1954 1954
 	public function parseDateString($dateString, $timezone = '')
1955 1955
 	{
1956 1956
 		$time_array = array();
@@ -1983,12 +1983,12 @@  discard block
 block discarded – undo
1983 1983
 	}
1984 1984
 	
1985 1985
 	/**
1986
-	* Parses the direction degrees to working
1987
-	*
1988
-	* @param Float $direction the direction in degrees
1989
-	* @return Array the direction information
1990
-	*
1991
-	*/
1986
+	 * Parses the direction degrees to working
1987
+	 *
1988
+	 * @param Float $direction the direction in degrees
1989
+	 * @return Array the direction information
1990
+	 *
1991
+	 */
1992 1992
 	public function parseDirection($direction = 0)
1993 1993
 	{
1994 1994
 		if ($direction == '') $direction = 0;
@@ -2067,12 +2067,12 @@  discard block
 block discarded – undo
2067 2067
 	
2068 2068
 	
2069 2069
 	/**
2070
-	* Gets Country from latitude/longitude
2071
-	*
2072
-	* @param Float $latitude latitute of the flight
2073
-	* @param Float $longitude longitute of the flight
2074
-	* @return String the countrie
2075
-	*/
2070
+	 * Gets Country from latitude/longitude
2071
+	 *
2072
+	 * @param Float $latitude latitute of the flight
2073
+	 * @param Float $longitude longitute of the flight
2074
+	 * @return String the countrie
2075
+	 */
2076 2076
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
2077 2077
 	{
2078 2078
 		global $globalDBdriver, $globalDebug;
@@ -2109,11 +2109,11 @@  discard block
 block discarded – undo
2109 2109
 	}
2110 2110
 
2111 2111
 	/**
2112
-	* Gets Country from iso2
2113
-	*
2114
-	* @param String $iso2 ISO2 country code
2115
-	* @return String the countrie
2116
-	*/
2112
+	 * Gets Country from iso2
2113
+	 *
2114
+	 * @param String $iso2 ISO2 country code
2115
+	 * @return String the countrie
2116
+	 */
2117 2117
 	public function getCountryFromISO2($iso2)
2118 2118
 	{
2119 2119
 		global $globalDBdriver, $globalDebug;
@@ -2142,12 +2142,12 @@  discard block
 block discarded – undo
2142 2142
 
2143 2143
 	
2144 2144
 	/**
2145
-	* Gets the short url from bit.ly
2146
-	*
2147
-	* @param String $url the full url
2148
-	* @return String the bit.ly url
2149
-	*
2150
-	*/
2145
+	 * Gets the short url from bit.ly
2146
+	 *
2147
+	 * @param String $url the full url
2148
+	 * @return String the bit.ly url
2149
+	 *
2150
+	 */
2151 2151
 	public function getBitlyURL($url)
2152 2152
 	{
2153 2153
 		global $globalBitlyAccessToken;
@@ -2174,11 +2174,11 @@  discard block
 block discarded – undo
2174 2174
 
2175 2175
 	
2176 2176
 	/**
2177
-	* Gets all vessels types that have flown over
2178
-	*
2179
-	* @return Array the vessel type list
2180
-	*
2181
-	*/
2177
+	 * Gets all vessels types that have flown over
2178
+	 *
2179
+	 * @return Array the vessel type list
2180
+	 *
2181
+	 */
2182 2182
 	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
2183 2183
 	{
2184 2184
 		global $globalDBdriver;
@@ -2244,11 +2244,11 @@  discard block
 block discarded – undo
2244 2244
 	}
2245 2245
 
2246 2246
 	/**
2247
-	* Gets all the tracker information
2248
-	*
2249
-	* @return Array the tracker information
2250
-	*
2251
-	*/
2247
+	 * Gets all the tracker information
2248
+	 *
2249
+	 * @return Array the tracker information
2250
+	 *
2251
+	 */
2252 2252
 	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
2253 2253
 	{
2254 2254
 		global $globalTimezone, $globalDBdriver;
@@ -2377,11 +2377,11 @@  discard block
 block discarded – undo
2377 2377
 	}
2378 2378
 
2379 2379
 	/**
2380
-	* Check marine by id
2381
-	*
2382
-	* @return String the ident
2383
-	*
2384
-	*/
2380
+	 * Check marine by id
2381
+	 *
2382
+	 * @return String the ident
2383
+	 *
2384
+	 */
2385 2385
 	public function checkId($id)
2386 2386
 	{
2387 2387
 		global $globalDBdriver, $globalTimezone;
Please login to merge, or discard this patch.
Spacing   +274 added lines, -274 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_marine_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']."'";
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
82 82
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
83 83
 		if ($filter_query_where != '') {
84
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
84
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
85 85
 		}
86 86
 		$filter_query = $filter_query_join.$filter_query_where;
87 87
 		return $filter_query;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	* @return Array the spotter information
97 97
 	*
98 98
 	*/
99
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
99
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
100 100
 	{
101 101
 		date_default_timezone_set('UTC');
102 102
 		if (!is_string($query))
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
 			$sth = $this->db->prepare($query.$limitQuery);
117 117
 			$sth->execute($params);
118 118
 		} catch (PDOException $e) {
119
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
119
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
120 120
 			exit();
121 121
 		}
122 122
 		
123 123
 		$num_rows = 0;
124 124
 		$spotter_array = array();
125
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
125
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
126 126
 		{
127 127
 			$num_rows++;
128 128
 			$temp_array = array();
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 			}
165 165
 			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
166 166
 
167
-			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
167
+			if (isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
168 168
 			{
169 169
 				$Image = new Image($this->db);
170
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
170
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'], '', $temp_array['ident']);
171 171
 				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
172 172
 				unset($Image);
173 173
 				if (count($image_array) > 0) {
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
 				{
204 204
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
205 205
 				} else {
206
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
206
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
207 207
 				}
208 208
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
209
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
210
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
209
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
210
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
211 211
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
212 212
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
213 213
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
214 214
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
215
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
216
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
215
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
216
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
217 217
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
218 218
 					}
219 219
 				}
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 		if ($limit != "")
247 247
 		{
248 248
 			$limit_array = explode(",", $limit);
249
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
250
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
249
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
250
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
251 251
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
252 252
 			{
253 253
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 		} else {
262 262
 			$orderby_query = " ORDER BY marine_output.date DESC";
263 263
 		}
264
-		$query  = $global_marine_query.$filter_query." ".$orderby_query;
265
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
264
+		$query = $global_marine_query.$filter_query." ".$orderby_query;
265
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
266 266
 		return $spotter_array;
267 267
 	}
268 268
     
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
 		if ($id == '') return array();
281 281
 		$additional_query = "marine_output.fammarine_id = :id";
282 282
 		$query_values = array(':id' => $id);
283
-		$query  = $global_marine_query." WHERE ".$additional_query." ";
284
-		$spotter_array = $this->getDataFromDB($query,$query_values);
283
+		$query = $global_marine_query." WHERE ".$additional_query." ";
284
+		$spotter_array = $this->getDataFromDB($query, $query_values);
285 285
 		return $spotter_array;
286 286
 	}
287 287
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		$query_values = array();
301 301
 		$limit_query = '';
302 302
 		$additional_query = '';
303
-		$filter_query = $this->getFilter($filter,true,true);
303
+		$filter_query = $this->getFilter($filter, true, true);
304 304
 		if ($ident != "")
305 305
 		{
306 306
 			if (!is_string($ident))
@@ -316,8 +316,8 @@  discard block
 block discarded – undo
316 316
 		{
317 317
 			$limit_array = explode(",", $limit);
318 318
 			
319
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
320
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
319
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
320
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
321 321
 			
322 322
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
323 323
 			{
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		$query_values = array();
357 357
 		$limit_query = '';
358 358
 		$additional_query = '';
359
-		$filter_query = $this->getFilter($filter,true,true);
359
+		$filter_query = $this->getFilter($filter, true, true);
360 360
 		if (!is_string($type))
361 361
 		{
362 362
 			return false;
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 		{
370 370
 			$limit_array = explode(",", $limit);
371 371
 			
372
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
373
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
372
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
373
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
374 374
 			
375 375
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
376 376
 			{
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 		return $spotter_array;
395 395
 	}
396 396
 	
397
-	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array())
397
+	public function getMarineDataByDate($date = '', $limit = '', $sort = '', $filter = array())
398 398
 	{
399 399
 		global $global_marine_query, $globalTimezone, $globalDBdriver;
400 400
 		
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 		$limit_query = '';
403 403
 		$additional_query = '';
404 404
 
405
-		$filter_query = $this->getFilter($filter,true,true);
405
+		$filter_query = $this->getFilter($filter, true, true);
406 406
 		
407 407
 		if ($date != "")
408 408
 		{
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 		{
429 429
 			$limit_array = explode(",", $limit);
430 430
 			
431
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
432
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
431
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
432
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
433 433
 			
434 434
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
435 435
 			{
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 		$query_values = array();
465 465
 		$limit_query = '';
466 466
 		$additional_query = '';
467
-		$filter_query = $this->getFilter($filter,true,true);
468
-		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
467
+		$filter_query = $this->getFilter($filter, true, true);
468
+		$captain = filter_var($captain, FILTER_SANITIZE_STRING);
469 469
 		if ($captain != "")
470 470
 		{
471 471
 			$additional_query = " AND (marine_output.captain_name = :captain OR marine_output.captain_id = :captain)";
@@ -474,8 +474,8 @@  discard block
 block discarded – undo
474 474
 		if ($limit != "")
475 475
 		{
476 476
 			$limit_array = explode(",", $limit);
477
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
478
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
477
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
478
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
479 479
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
480 480
 			{
481 481
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -507,8 +507,8 @@  discard block
 block discarded – undo
507 507
 		$query_values = array();
508 508
 		$limit_query = '';
509 509
 		$additional_query = '';
510
-		$filter_query = $this->getFilter($filter,true,true);
511
-		$race = filter_var($race,FILTER_SANITIZE_STRING);
510
+		$filter_query = $this->getFilter($filter, true, true);
511
+		$race = filter_var($race, FILTER_SANITIZE_STRING);
512 512
 		if ($race != "")
513 513
 		{
514 514
 			$additional_query = " AND (marine_output.race_name = :race OR marine_output.race_id = :race)";
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 		if ($limit != "")
518 518
 		{
519 519
 			$limit_array = explode(",", $limit);
520
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
521
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
520
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
521
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
522 522
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
523 523
 			{
524 524
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
@@ -543,14 +543,14 @@  discard block
 block discarded – undo
543 543
 	* @return String Duration of all races
544 544
 	*
545 545
 	*/
546
-	public function countRacesByCaptain($captain,$filters = array())
546
+	public function countRacesByCaptain($captain, $filters = array())
547 547
 	{
548
-		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
549
-		$filter_query = $this->getFilter($filters,true,true);
550
-		$query  = "SELECT COUNT(*) AS nb 
548
+		$captain = filter_var($captain, FILTER_SANITIZE_STRING);
549
+		$filter_query = $this->getFilter($filters, true, true);
550
+		$query = "SELECT COUNT(*) AS nb 
551 551
 			FROM marine_output".$filter_query." (marine_output.captain_name = :captain OR marine_output.captain_id = :captain)";
552 552
 		$query_values = array();
553
-		$query_values = array_merge($query_values,array(':captain' => $captain));
553
+		$query_values = array_merge($query_values, array(':captain' => $captain));
554 554
 		$sth = $this->db->prepare($query);
555 555
 		$sth->execute($query_values);
556 556
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -563,14 +563,14 @@  discard block
 block discarded – undo
563 563
 	* @return String Duration of all races
564 564
 	*
565 565
 	*/
566
-	public function countCaptainsByRace($race,$filters = array())
566
+	public function countCaptainsByRace($race, $filters = array())
567 567
 	{
568
-		$race = filter_var($race,FILTER_SANITIZE_STRING);
569
-		$filter_query = $this->getFilter($filters,true,true);
570
-		$query  = "SELECT COUNT(*) AS nb 
568
+		$race = filter_var($race, FILTER_SANITIZE_STRING);
569
+		$filter_query = $this->getFilter($filters, true, true);
570
+		$query = "SELECT COUNT(*) AS nb 
571 571
 			FROM marine_output".$filter_query." (marine_output.race_name = :race OR marine_output.race_id = :race)";
572 572
 		$query_values = array();
573
-		$query_values = array_merge($query_values,array(':race' => $race));
573
+		$query_values = array_merge($query_values, array(':race' => $race));
574 574
 		$sth = $this->db->prepare($query);
575 575
 		$sth->execute($query_values);
576 576
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -583,44 +583,44 @@  discard block
 block discarded – undo
583 583
 	* @return Array the boat list
584 584
 	*
585 585
 	*/
586
-	public function countAllBoatTypesByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
586
+	public function countAllBoatTypesByCaptain($captain, $filters = array(), $year = '', $month = '', $day = '')
587 587
 	{
588 588
 		global $globalDBdriver;
589
-		$filter_query = $this->getFilter($filters,true,true);
590
-		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
591
-		$query  = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
589
+		$filter_query = $this->getFilter($filters, true, true);
590
+		$captain = filter_var($captain, FILTER_SANITIZE_STRING);
591
+		$query = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
592 592
 			FROM marine_output".$filter_query." (marine_output.captain_id = :captain OR marine_output.captain_name = :captain)";
593 593
 		$query_values = array();
594 594
 		if ($year != '') {
595 595
 			if ($globalDBdriver == 'mysql') {
596 596
 				$query .= " AND YEAR(marine_output.date) = :year";
597
-				$query_values = array_merge($query_values,array(':year' => $year));
597
+				$query_values = array_merge($query_values, array(':year' => $year));
598 598
 			} else {
599 599
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
600
-				$query_values = array_merge($query_values,array(':year' => $year));
600
+				$query_values = array_merge($query_values, array(':year' => $year));
601 601
 			}
602 602
 		}
603 603
 		if ($month != '') {
604 604
 			if ($globalDBdriver == 'mysql') {
605 605
 				$query .= " AND MONTH(marine_output.date) = :month";
606
-				$query_values = array_merge($query_values,array(':month' => $month));
606
+				$query_values = array_merge($query_values, array(':month' => $month));
607 607
 			} else {
608 608
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
609
-				$query_values = array_merge($query_values,array(':month' => $month));
609
+				$query_values = array_merge($query_values, array(':month' => $month));
610 610
 			}
611 611
 		}
612 612
 		if ($day != '') {
613 613
 			if ($globalDBdriver == 'mysql') {
614 614
 				$query .= " AND DAY(marine_output.date) = :day";
615
-				$query_values = array_merge($query_values,array(':day' => $day));
615
+				$query_values = array_merge($query_values, array(':day' => $day));
616 616
 			} else {
617 617
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
618
-				$query_values = array_merge($query_values,array(':day' => $day));
618
+				$query_values = array_merge($query_values, array(':day' => $day));
619 619
 			}
620 620
 		}
621 621
 		$query .= " GROUP BY marine_output.type
622 622
 			ORDER BY type_count DESC";
623
-		$query_values = array_merge($query_values,array(':captain' => $captain));
623
+		$query_values = array_merge($query_values, array(':captain' => $captain));
624 624
 		$sth = $this->db->prepare($query);
625 625
 		$sth->execute($query_values);
626 626
 		return $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -632,44 +632,44 @@  discard block
 block discarded – undo
632 632
 	* @return Array the boat list
633 633
 	*
634 634
 	*/
635
-	public function countAllBoatTypesByRace($race,$filters = array(),$year = '',$month = '',$day = '')
635
+	public function countAllBoatTypesByRace($race, $filters = array(), $year = '', $month = '', $day = '')
636 636
 	{
637 637
 		global $globalDBdriver;
638
-		$filter_query = $this->getFilter($filters,true,true);
639
-		$race = filter_var($race,FILTER_SANITIZE_STRING);
640
-		$query  = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
638
+		$filter_query = $this->getFilter($filters, true, true);
639
+		$race = filter_var($race, FILTER_SANITIZE_STRING);
640
+		$query = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
641 641
 			FROM marine_output".$filter_query." (marine_output.race_id = :race OR marine_output.race_name = :race)";
642 642
 		$query_values = array();
643 643
 		if ($year != '') {
644 644
 			if ($globalDBdriver == 'mysql') {
645 645
 				$query .= " AND YEAR(marine_output.date) = :year";
646
-				$query_values = array_merge($query_values,array(':year' => $year));
646
+				$query_values = array_merge($query_values, array(':year' => $year));
647 647
 			} else {
648 648
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
649
-				$query_values = array_merge($query_values,array(':year' => $year));
649
+				$query_values = array_merge($query_values, array(':year' => $year));
650 650
 			}
651 651
 		}
652 652
 		if ($month != '') {
653 653
 			if ($globalDBdriver == 'mysql') {
654 654
 				$query .= " AND MONTH(marine_output.date) = :month";
655
-				$query_values = array_merge($query_values,array(':month' => $month));
655
+				$query_values = array_merge($query_values, array(':month' => $month));
656 656
 			} else {
657 657
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
658
-				$query_values = array_merge($query_values,array(':month' => $month));
658
+				$query_values = array_merge($query_values, array(':month' => $month));
659 659
 			}
660 660
 		}
661 661
 		if ($day != '') {
662 662
 			if ($globalDBdriver == 'mysql') {
663 663
 				$query .= " AND DAY(marine_output.date) = :day";
664
-				$query_values = array_merge($query_values,array(':day' => $day));
664
+				$query_values = array_merge($query_values, array(':day' => $day));
665 665
 			} else {
666 666
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
667
-				$query_values = array_merge($query_values,array(':day' => $day));
667
+				$query_values = array_merge($query_values, array(':day' => $day));
668 668
 			}
669 669
 		}
670 670
 		$query .= " GROUP BY marine_output.type
671 671
 			ORDER BY type_count DESC";
672
-		$query_values = array_merge($query_values,array(':race' => $race));
672
+		$query_values = array_merge($query_values, array(':race' => $race));
673 673
 		$sth = $this->db->prepare($query);
674 674
 		$sth->execute($query_values);
675 675
 		return $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -681,47 +681,47 @@  discard block
 block discarded – undo
681 681
 	* @return String Duration of all race
682 682
 	*
683 683
 	*/
684
-	public function getRaceDurationByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
684
+	public function getRaceDurationByCaptain($captain, $filters = array(), $year = '', $month = '', $day = '')
685 685
 	{
686 686
 		global $globalDBdriver;
687
-		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
688
-		$filter_query = $this->getFilter($filters,true,true);
689
-		$query  = "SELECT SUM(last_seen - date) AS duration 
687
+		$captain = filter_var($captain, FILTER_SANITIZE_STRING);
688
+		$filter_query = $this->getFilter($filters, true, true);
689
+		$query = "SELECT SUM(last_seen - date) AS duration 
690 690
 		    FROM marine_output".$filter_query." (marine_output.captain_name = :captain OR marine_output.captain_id = :captain) 
691 691
 		    AND last_seen > date";
692 692
 		$query_values = array();
693 693
 		if ($year != '') {
694 694
 			if ($globalDBdriver == 'mysql') {
695 695
 				$query .= " AND YEAR(marine_output.date) = :year";
696
-				$query_values = array_merge($query_values,array(':year' => $year));
696
+				$query_values = array_merge($query_values, array(':year' => $year));
697 697
 			} else {
698 698
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
699
-				$query_values = array_merge($query_values,array(':year' => $year));
699
+				$query_values = array_merge($query_values, array(':year' => $year));
700 700
 			}
701 701
 		}
702 702
 		if ($month != '') {
703 703
 			if ($globalDBdriver == 'mysql') {
704 704
 				$query .= " AND MONTH(marine_output.date) = :month";
705
-				$query_values = array_merge($query_values,array(':month' => $month));
705
+				$query_values = array_merge($query_values, array(':month' => $month));
706 706
 			} else {
707 707
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
708
-				$query_values = array_merge($query_values,array(':month' => $month));
708
+				$query_values = array_merge($query_values, array(':month' => $month));
709 709
 			}
710 710
 		}
711 711
 		if ($day != '') {
712 712
 			if ($globalDBdriver == 'mysql') {
713 713
 				$query .= " AND DAY(marine_output.date) = :day";
714
-				$query_values = array_merge($query_values,array(':day' => $day));
714
+				$query_values = array_merge($query_values, array(':day' => $day));
715 715
 			} else {
716 716
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
717
-				$query_values = array_merge($query_values,array(':day' => $day));
717
+				$query_values = array_merge($query_values, array(':day' => $day));
718 718
 			}
719 719
 		}
720
-		$query_values = array_merge($query_values,array(':captain' => $captain));
720
+		$query_values = array_merge($query_values, array(':captain' => $captain));
721 721
 		$sth = $this->db->prepare($query);
722 722
 		$sth->execute($query_values);
723 723
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
724
-		if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']);
724
+		if (is_int($result[0]['duration'])) return gmdate('H:i:s', $result[0]['duration']);
725 725
 		else return $result[0]['duration'];
726 726
 	}
727 727
 
@@ -733,8 +733,8 @@  discard block
 block discarded – undo
733 733
 	*/
734 734
 	public function getAllCaptainNames($filters = array())
735 735
 	{
736
-		$filter_query = $this->getFilter($filters,true,true);
737
-		$query  = "SELECT DISTINCT marine_output.captain_name, marine_output.captain_id
736
+		$filter_query = $this->getFilter($filters, true, true);
737
+		$query = "SELECT DISTINCT marine_output.captain_name, marine_output.captain_id
738 738
 			FROM marine_output".$filter_query." marine_output.captain_name <> '' 
739 739
 			ORDER BY marine_output.captain_name ASC";
740 740
 	
@@ -751,8 +751,8 @@  discard block
 block discarded – undo
751 751
 	*/
752 752
 	public function getAllRaceNames($filters = array())
753 753
 	{
754
-		$filter_query = $this->getFilter($filters,true,true);
755
-		$query  = "SELECT DISTINCT marine_output.race_name, marine_output.race_id
754
+		$filter_query = $this->getFilter($filters, true, true);
755
+		$query = "SELECT DISTINCT marine_output.race_name, marine_output.race_id
756 756
 			FROM marine_output".$filter_query." marine_output.race_name <> '' 
757 757
 			ORDER BY marine_output.race_name ASC";
758 758
 	
@@ -768,11 +768,11 @@  discard block
 block discarded – undo
768 768
 	* @return Array list of source name
769 769
 	*
770 770
 	*/
771
-	public function getAllSourceName($type = '',$filters = array())
771
+	public function getAllSourceName($type = '', $filters = array())
772 772
 	{
773
-		$filter_query = $this->getFilter($filters,true,true);
773
+		$filter_query = $this->getFilter($filters, true, true);
774 774
 		$query_values = array();
775
-		$query  = "SELECT DISTINCT marine_output.source_name 
775
+		$query = "SELECT DISTINCT marine_output.source_name 
776 776
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
777 777
 		if ($type != '') {
778 778
 			$query_values = array(':type' => $type);
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 		$source_array = array();
788 788
 		$temp_array = array();
789 789
 		
790
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
790
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
791 791
 		{
792 792
 			$temp_array['source_name'] = $row['source_name'];
793 793
 			$source_array[] = $temp_array;
@@ -804,8 +804,8 @@  discard block
 block discarded – undo
804 804
 	*/
805 805
 	public function getAllIdents($filters = array())
806 806
 	{
807
-		$filter_query = $this->getFilter($filters,true,true);
808
-		$query  = "SELECT DISTINCT marine_output.ident
807
+		$filter_query = $this->getFilter($filters, true, true);
808
+		$query = "SELECT DISTINCT marine_output.ident
809 809
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
810 810
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
811 811
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 		$ident_array = array();
816 816
 		$temp_array = array();
817 817
 		
818
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
818
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
819 819
 		{
820 820
 			$temp_array['ident'] = $row['ident'];
821 821
 			$ident_array[] = $temp_array;
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 	*/
833 833
 	public function getIdentity($mmsi)
834 834
 	{
835
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
835
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
836 836
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
837 837
 		$sth = $this->db->prepare($query);
838 838
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -845,23 +845,23 @@  discard block
 block discarded – undo
845 845
 	* Add identity
846 846
 	*
847 847
 	*/
848
-	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
848
+	public function addIdentity($mmsi, $imo, $ident, $callsign, $type)
849 849
 	{
850
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
850
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
851 851
 		if ($mmsi != '') {
852
-			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
853
-			$ident = filter_var($ident,FILTER_SANITIZE_STRING);
854
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
855
-			$type = filter_var($type,FILTER_SANITIZE_STRING);
852
+			$imo = filter_var($imo, FILTER_SANITIZE_NUMBER_INT);
853
+			$ident = filter_var($ident, FILTER_SANITIZE_STRING);
854
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
855
+			$type = filter_var($type, FILTER_SANITIZE_STRING);
856 856
 			$identinfo = $this->getIdentity($mmsi);
857 857
 			if (empty($identinfo)) {
858
-				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
858
+				$query = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
859 859
 				$sth = $this->db->prepare($query);
860
-				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
860
+				$sth->execute(array(':mmsi' => $mmsi, ':imo' => $imo, ':call_sign' => $callsign, ':ship_name' => $ident, ':type' => $type));
861 861
 			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) {
862
-				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
862
+				$query = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
863 863
 				$sth = $this->db->prepare($query);
864
-				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type));
864
+				$sth->execute(array(':mmsi' => $mmsi, ':ship_name' => $ident, ':type' => $type));
865 865
 			}
866 866
 		}
867 867
 	}
@@ -882,12 +882,12 @@  discard block
 block discarded – undo
882 882
 		} else $offset = '+00:00';
883 883
 
884 884
 		if ($globalDBdriver == 'mysql') {
885
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
885
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
886 886
 								FROM marine_output
887 887
 								WHERE marine_output.date <> '' 
888 888
 								ORDER BY marine_output.date ASC LIMIT 0,100";
889 889
 		} else {
890
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
890
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
891 891
 								FROM marine_output
892 892
 								WHERE marine_output.date <> '' 
893 893
 								ORDER BY marine_output.date ASC LIMIT 0,100";
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 		$date_array = array();
900 900
 		$temp_array = array();
901 901
 		
902
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
902
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
903 903
 		{
904 904
 			$temp_array['date'] = $row['date'];
905 905
 
@@ -917,10 +917,10 @@  discard block
 block discarded – undo
917 917
 	* @return String success or false
918 918
 	*
919 919
 	*/
920
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
920
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
921 921
 	{
922 922
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
923
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
923
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
924 924
 		try {
925 925
 			$sth = $this->db->prepare($query);
926 926
 			$sth->execute($query_values);
@@ -938,10 +938,10 @@  discard block
 block discarded – undo
938 938
 	* @return String success or false
939 939
 	*
940 940
 	*/
941
-	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL)
941
+	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '', $fromsource = NULL)
942 942
 	{
943 943
 		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id';
944
-		$query_values = array(':fammarine_id' => $fammarine_id,':arrival_code' => $arrival_code);
944
+		$query_values = array(':fammarine_id' => $fammarine_id, ':arrival_code' => $arrival_code);
945 945
 		try {
946 946
 			$sth = $this->db->prepare($query);
947 947
 			$sth->execute($query_values);
@@ -960,11 +960,11 @@  discard block
 block discarded – undo
960 960
 	* @return String success or false
961 961
 	*
962 962
 	*/
963
-	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
963
+	public function updateStatusMarineData($fammarine_id = '', $status_id = '', $status = '')
964 964
 	{
965 965
 
966 966
 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
967
-                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
967
+                $query_values = array(':fammarine_id' => $fammarine_id, ':status' => $status, ':status_id' => $status_id);
968 968
 
969 969
 		try {
970 970
 			$sth = $this->db->prepare($query);
@@ -984,17 +984,17 @@  discard block
 block discarded – undo
984 984
 	* @return String success or false
985 985
 	*
986 986
 	*/	
987
-	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '',$distance = NULL,$race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '')
987
+	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '', $distance = NULL, $race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '')
988 988
 	{
989 989
 		if ($latitude == '') $latitude = NULL;
990 990
 		if ($longitude == '') $longitude = NULL;
991 991
 		$groundspeed = round($groundspeed);
992 992
 		if ($race_begin != '') {
993 993
 			$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, distance = :distance, race_rank = :race_rank, race_time = :race_time, status = :status, date = :race_begin WHERE fammarine_id = :fammarine_id';
994
-			$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident,':distance' => $distance,':race_rank' => $race_rank,':race_time' => $race_time,':status' => $status,':race_begin' => $race_begin);
994
+			$query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident, ':distance' => $distance, ':race_rank' => $race_rank, ':race_time' => $race_time, ':status' => $status, ':race_begin' => $race_begin);
995 995
 		} else {
996 996
 			$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, distance = :distance, race_rank = :race_rank, race_time = :race_time, status = :status WHERE fammarine_id = :fammarine_id';
997
-			$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident,':distance' => $distance,':race_rank' => $race_rank,':race_time' => $race_time,':status' => $status);
997
+			$query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident, ':distance' => $distance, ':race_rank' => $race_rank, ':race_time' => $race_time, ':status' => $status);
998 998
 		}
999 999
 		try {
1000 1000
 			$sth = $this->db->prepare($query);
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 	* @param String $verticalrate vertival rate of flight
1034 1034
 	* @return String success or false
1035 1035
 	*/
1036
-	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 = '', $captain_id = '',$captain_name = '',$race_id = '', $race_name = '', $distance = '',$race_rank = '', $race_time = '')
1036
+	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 = '', $captain_id = '', $captain_name = '', $race_id = '', $race_name = '', $distance = '', $race_rank = '', $race_time = '')
1037 1037
 	{
1038 1038
 		global $globalURL, $globalMarineImageFetch;
1039 1039
 		
@@ -1105,33 +1105,33 @@  discard block
 block discarded – undo
1105 1105
 			$date = date("Y-m-d H:i:s", time());
1106 1106
 		}
1107 1107
 
1108
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1109
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1110
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1111
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1112
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
1113
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1114
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
1115
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1116
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
1117
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
1118
-		$type_id = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
1119
-		$status_id = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
1120
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1121
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1122
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
1123
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
1124
-		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
1125
-		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
1126
-		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
1127
-		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
1128
-		$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
1129
-		$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1108
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1109
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1110
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1111
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1112
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
1113
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1114
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
1115
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
1116
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
1117
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
1118
+		$type_id = filter_var($typeid, FILTER_SANITIZE_NUMBER_INT);
1119
+		$status_id = filter_var($statusid, FILTER_SANITIZE_NUMBER_INT);
1120
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1121
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1122
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
1123
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
1124
+		$captain_id = filter_var($captain_id, FILTER_SANITIZE_STRING);
1125
+		$captain_name = filter_var($captain_name, FILTER_SANITIZE_STRING);
1126
+		$race_id = filter_var($race_id, FILTER_SANITIZE_STRING);
1127
+		$race_name = filter_var($race_name, FILTER_SANITIZE_STRING);
1128
+		$race_rank = filter_var($race_rank, FILTER_SANITIZE_NUMBER_INT);
1129
+		$race_time = filter_var($race_time, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1130 1130
 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
1131 1131
 			$Image = new Image($this->db);
1132
-			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
1132
+			$image_array = $Image->getMarineImage($mmsi, $imo, $ident);
1133 1133
 			if (!isset($image_array[0]['mmsi'])) {
1134
-				$Image->addMarineImage($mmsi,$imo,$ident);
1134
+				$Image->addMarineImage($mmsi, $imo, $ident);
1135 1135
 			}
1136 1136
 			unset($Image);
1137 1137
 		}
@@ -1147,10 +1147,10 @@  discard block
 block discarded – undo
1147 1147
 		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
1148 1148
 		//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
1149 1149
 		if ($arrival_date == '') $arrival_date = NULL;
1150
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name, distance, race_rank,race_time) 
1150
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name, distance, race_rank,race_time) 
1151 1151
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name, :distance, :race_rank,:race_time)";
1152 1152
 
1153
-		$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,':type_id' => $type_id,':status' => $status,':status_id' => $status_id,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date,':captain_id' => $captain_id,':captain_name' => $captain_name,':race_id' => $race_id,':race_name' => $race_name,':distance' => $distance,':race_rank' => $race_rank,':race_time' => $race_time);
1153
+		$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, ':type_id' => $type_id, ':status' => $status, ':status_id' => $status_id, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date, ':captain_id' => $captain_id, ':captain_name' => $captain_name, ':race_id' => $race_id, ':race_name' => $race_name, ':distance' => $distance, ':race_rank' => $race_rank, ':race_time' => $race_time);
1154 1154
 		try {
1155 1155
 			$sth = $this->db->prepare($query);
1156 1156
 			$sth->execute($query_values);
@@ -1174,13 +1174,13 @@  discard block
 block discarded – undo
1174 1174
 	{
1175 1175
 		global $globalDBdriver, $globalTimezone;
1176 1176
 		if ($globalDBdriver == 'mysql') {
1177
-			$query  = "SELECT marine_output.ident FROM marine_output 
1177
+			$query = "SELECT marine_output.ident FROM marine_output 
1178 1178
 								WHERE marine_output.ident = :ident 
1179 1179
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
1180 1180
 								AND marine_output.date < UTC_TIMESTAMP()";
1181 1181
 			$query_data = array(':ident' => $ident);
1182 1182
 		} else {
1183
-			$query  = "SELECT marine_output.ident FROM marine_output 
1183
+			$query = "SELECT marine_output.ident FROM marine_output 
1184 1184
 								WHERE marine_output.ident = :ident 
1185 1185
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
1186 1186
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -1189,8 +1189,8 @@  discard block
 block discarded – undo
1189 1189
 		
1190 1190
 		$sth = $this->db->prepare($query);
1191 1191
 		$sth->execute($query_data);
1192
-    		$ident_result='';
1193
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1192
+    		$ident_result = '';
1193
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1194 1194
 		{
1195 1195
 			$ident_result = $row['ident'];
1196 1196
 		}
@@ -1216,8 +1216,8 @@  discard block
 block discarded – undo
1216 1216
 				return false;
1217 1217
 			} else {
1218 1218
 				$q_array = explode(" ", $q);
1219
-				foreach ($q_array as $q_item){
1220
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1219
+				foreach ($q_array as $q_item) {
1220
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
1221 1221
 					$additional_query .= " AND (";
1222 1222
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
1223 1223
 					$additional_query .= ")";
@@ -1225,11 +1225,11 @@  discard block
 block discarded – undo
1225 1225
 			}
1226 1226
 		}
1227 1227
 		if ($globalDBdriver == 'mysql') {
1228
-			$query  = "SELECT marine_output.* FROM marine_output 
1228
+			$query = "SELECT marine_output.* FROM marine_output 
1229 1229
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
1230 1230
 				AND marine_output.date < UTC_TIMESTAMP()";
1231 1231
 		} else {
1232
-			$query  = "SELECT marine_output.* FROM marine_output 
1232
+			$query = "SELECT marine_output.* FROM marine_output 
1233 1233
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
1234 1234
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1235 1235
 		}
@@ -1248,16 +1248,16 @@  discard block
 block discarded – undo
1248 1248
 	*
1249 1249
 	*/
1250 1250
 
1251
-	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
1251
+	public function countAllMarineOverCountries($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array())
1252 1252
 	{
1253 1253
 		global $globalDBdriver, $globalArchive;
1254 1254
 		//$filter_query = $this->getFilter($filters,true,true);
1255
-		$Connection= new Connection($this->db);
1255
+		$Connection = new Connection($this->db);
1256 1256
 		if (!$Connection->tableExists('countries')) return array();
1257 1257
 		require_once('class.SpotterLive.php');
1258 1258
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
1259 1259
 			$MarineLive = new MarineLive($this->db);
1260
-			$filter_query = $MarineLive->getFilter($filters,true,true);
1260
+			$filter_query = $MarineLive->getFilter($filters, true, true);
1261 1261
 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
1262 1262
 			if ($olderthanmonths > 0) {
1263 1263
 				if ($globalDBdriver == 'mysql') {
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 		} else {
1278 1278
 			require_once(dirname(__FILE__)."/class.MarineArchive.php");
1279 1279
 			$MarineArchive = new MarineArchive($this->db);
1280
-			$filter_query = $MarineArchive->getFilter($filters,true,true);
1280
+			$filter_query = $MarineArchive->getFilter($filters, true, true);
1281 1281
 			$filter_query .= " over_country <> ''";
1282 1282
 			if ($olderthanmonths > 0) {
1283 1283
 				if ($globalDBdriver == 'mysql') {
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 		$flight_array = array();
1306 1306
 		$temp_array = array();
1307 1307
         
1308
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1308
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1309 1309
 		{
1310 1310
 			$temp_array['marine_count'] = $row['nb'];
1311 1311
 			$temp_array['marine_country'] = $row['name'];
@@ -1324,11 +1324,11 @@  discard block
 block discarded – undo
1324 1324
 	* @return Array the callsign list
1325 1325
 	*
1326 1326
 	*/
1327
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
1327
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
1328 1328
 	{
1329 1329
 		global $globalDBdriver;
1330
-		$filter_query = $this->getFilter($filters,true,true);
1331
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1330
+		$filter_query = $this->getFilter($filters, true, true);
1331
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1332 1332
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
1333 1333
 		 if ($olderthanmonths > 0) {
1334 1334
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -1342,28 +1342,28 @@  discard block
 block discarded – undo
1342 1342
 		if ($year != '') {
1343 1343
 			if ($globalDBdriver == 'mysql') {
1344 1344
 				$query .= " AND YEAR(marine_output.date) = :year";
1345
-				$query_values = array_merge($query_values,array(':year' => $year));
1345
+				$query_values = array_merge($query_values, array(':year' => $year));
1346 1346
 			} else {
1347 1347
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1348
-				$query_values = array_merge($query_values,array(':year' => $year));
1348
+				$query_values = array_merge($query_values, array(':year' => $year));
1349 1349
 			}
1350 1350
 		}
1351 1351
 		if ($month != '') {
1352 1352
 			if ($globalDBdriver == 'mysql') {
1353 1353
 				$query .= " AND MONTH(marine_output.date) = :month";
1354
-				$query_values = array_merge($query_values,array(':month' => $month));
1354
+				$query_values = array_merge($query_values, array(':month' => $month));
1355 1355
 			} else {
1356 1356
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1357
-				$query_values = array_merge($query_values,array(':month' => $month));
1357
+				$query_values = array_merge($query_values, array(':month' => $month));
1358 1358
 			}
1359 1359
 		}
1360 1360
 		if ($day != '') {
1361 1361
 			if ($globalDBdriver == 'mysql') {
1362 1362
 				$query .= " AND DAY(marine_output.date) = :day";
1363
-				$query_values = array_merge($query_values,array(':day' => $day));
1363
+				$query_values = array_merge($query_values, array(':day' => $day));
1364 1364
 			} else {
1365 1365
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1366
-				$query_values = array_merge($query_values,array(':day' => $day));
1366
+				$query_values = array_merge($query_values, array(':day' => $day));
1367 1367
 			}
1368 1368
 		}
1369 1369
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
 		$callsign_array = array();
1376 1376
 		$temp_array = array();
1377 1377
         
1378
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1378
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1379 1379
 		{
1380 1380
 			$temp_array['callsign_icao'] = $row['ident'];
1381 1381
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
 		$date_array = array();
1428 1428
 		$temp_array = array();
1429 1429
         
1430
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1430
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1431 1431
 		{
1432 1432
 			$temp_array['date_name'] = $row['date_name'];
1433 1433
 			$temp_array['date_count'] = $row['date_count'];
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 			$datetime = new DateTime();
1454 1454
 			$offset = $datetime->format('P');
1455 1455
 		} else $offset = '+00:00';
1456
-		$filter_query = $this->getFilter($filters,true,true);
1456
+		$filter_query = $this->getFilter($filters, true, true);
1457 1457
 		if ($globalDBdriver == 'mysql') {
1458 1458
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1459 1459
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 		$date_array = array();
1475 1475
 		$temp_array = array();
1476 1476
         
1477
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1477
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1478 1478
 		{
1479 1479
 			$temp_array['date_name'] = $row['date_name'];
1480 1480
 			$temp_array['date_count'] = $row['date_count'];
@@ -1499,7 +1499,7 @@  discard block
 block discarded – undo
1499 1499
 			$datetime = new DateTime();
1500 1500
 			$offset = $datetime->format('P');
1501 1501
 		} else $offset = '+00:00';
1502
-		$filter_query = $this->getFilter($filters,true,true);
1502
+		$filter_query = $this->getFilter($filters, true, true);
1503 1503
 		if ($globalDBdriver == 'mysql') {
1504 1504
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1505 1505
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
 		$date_array = array();
1521 1521
 		$temp_array = array();
1522 1522
         
1523
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1523
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1524 1524
 		{
1525 1525
 			$temp_array['date_name'] = $row['date_name'];
1526 1526
 			$temp_array['date_count'] = $row['date_count'];
@@ -1567,7 +1567,7 @@  discard block
 block discarded – undo
1567 1567
 		$date_array = array();
1568 1568
 		$temp_array = array();
1569 1569
         
1570
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1570
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1571 1571
 		{
1572 1572
 			$temp_array['month_name'] = $row['month_name'];
1573 1573
 			$temp_array['year_name'] = $row['year_name'];
@@ -1596,7 +1596,7 @@  discard block
 block discarded – undo
1596 1596
 			$datetime = new DateTime();
1597 1597
 			$offset = $datetime->format('P');
1598 1598
 		} else $offset = '+00:00';
1599
-		$filter_query = $this->getFilter($filters,true,true);
1599
+		$filter_query = $this->getFilter($filters, true, true);
1600 1600
 		if ($globalDBdriver == 'mysql') {
1601 1601
 			$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
1602 1602
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1617,7 +1617,7 @@  discard block
 block discarded – undo
1617 1617
 		$date_array = array();
1618 1618
 		$temp_array = array();
1619 1619
         
1620
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1620
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1621 1621
 		{
1622 1622
 			$temp_array['year_name'] = $row['year_name'];
1623 1623
 			$temp_array['month_name'] = $row['month_name'];
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
 	* @return Array the hour list
1638 1638
 	*
1639 1639
 	*/
1640
-	public function countAllHours($orderby,$filters = array())
1640
+	public function countAllHours($orderby, $filters = array())
1641 1641
 	{
1642 1642
 		global $globalTimezone, $globalDBdriver;
1643 1643
 		if ($globalTimezone != '') {
@@ -1685,7 +1685,7 @@  discard block
 block discarded – undo
1685 1685
 		$hour_array = array();
1686 1686
 		$temp_array = array();
1687 1687
         
1688
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1688
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1689 1689
 		{
1690 1690
 			$temp_array['hour_name'] = $row['hour_name'];
1691 1691
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1707,8 +1707,8 @@  discard block
 block discarded – undo
1707 1707
 	public function countAllHoursByDate($date, $filters = array())
1708 1708
 	{
1709 1709
 		global $globalTimezone, $globalDBdriver;
1710
-		$filter_query = $this->getFilter($filters,true,true);
1711
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1710
+		$filter_query = $this->getFilter($filters, true, true);
1711
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1712 1712
 		if ($globalTimezone != '') {
1713 1713
 			date_default_timezone_set($globalTimezone);
1714 1714
 			$datetime = new DateTime($date);
@@ -1716,12 +1716,12 @@  discard block
 block discarded – undo
1716 1716
 		} else $offset = '+00:00';
1717 1717
 
1718 1718
 		if ($globalDBdriver == 'mysql') {
1719
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1719
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1720 1720
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1721 1721
 								GROUP BY hour_name 
1722 1722
 								ORDER BY hour_name ASC";
1723 1723
 		} else {
1724
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1724
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1725 1725
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1726 1726
 								GROUP BY hour_name 
1727 1727
 								ORDER BY hour_name ASC";
@@ -1733,7 +1733,7 @@  discard block
 block discarded – undo
1733 1733
 		$hour_array = array();
1734 1734
 		$temp_array = array();
1735 1735
         
1736
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1736
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1737 1737
 		{
1738 1738
 			$temp_array['hour_name'] = $row['hour_name'];
1739 1739
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1755,8 +1755,8 @@  discard block
 block discarded – undo
1755 1755
 	public function countAllHoursByIdent($ident, $filters = array())
1756 1756
 	{
1757 1757
 		global $globalTimezone, $globalDBdriver;
1758
-		$filter_query = $this->getFilter($filters,true,true);
1759
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1758
+		$filter_query = $this->getFilter($filters, true, true);
1759
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1760 1760
 		if ($globalTimezone != '') {
1761 1761
 			date_default_timezone_set($globalTimezone);
1762 1762
 			$datetime = new DateTime();
@@ -1764,12 +1764,12 @@  discard block
 block discarded – undo
1764 1764
 		} else $offset = '+00:00';
1765 1765
 
1766 1766
 		if ($globalDBdriver == 'mysql') {
1767
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1767
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1768 1768
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1769 1769
 								GROUP BY hour_name 
1770 1770
 								ORDER BY hour_name ASC";
1771 1771
 		} else {
1772
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1772
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1773 1773
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1774 1774
 								GROUP BY hour_name 
1775 1775
 								ORDER BY hour_name ASC";
@@ -1777,12 +1777,12 @@  discard block
 block discarded – undo
1777 1777
       
1778 1778
 		
1779 1779
 		$sth = $this->db->prepare($query);
1780
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1780
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1781 1781
       
1782 1782
 		$hour_array = array();
1783 1783
 		$temp_array = array();
1784 1784
         
1785
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1785
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1786 1786
 		{
1787 1787
 			$temp_array['hour_name'] = $row['hour_name'];
1788 1788
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1801,33 +1801,33 @@  discard block
 block discarded – undo
1801 1801
 	* @return Integer the number of vessels
1802 1802
 	*
1803 1803
 	*/
1804
-	public function countOverallMarine($filters = array(),$year = '',$month = '')
1804
+	public function countOverallMarine($filters = array(), $year = '', $month = '')
1805 1805
 	{
1806 1806
 		global $globalDBdriver;
1807 1807
 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1808
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1808
+		$queryi = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1809 1809
 		$query_values = array();
1810 1810
 		$query = '';
1811 1811
 		if ($year != '') {
1812 1812
 			if ($globalDBdriver == 'mysql') {
1813 1813
 				$query .= " AND YEAR(marine_output.date) = :year";
1814
-				$query_values = array_merge($query_values,array(':year' => $year));
1814
+				$query_values = array_merge($query_values, array(':year' => $year));
1815 1815
 			} else {
1816 1816
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1817
-				$query_values = array_merge($query_values,array(':year' => $year));
1817
+				$query_values = array_merge($query_values, array(':year' => $year));
1818 1818
 			}
1819 1819
 		}
1820 1820
 		if ($month != '') {
1821 1821
 			if ($globalDBdriver == 'mysql') {
1822 1822
 				$query .= " AND MONTH(marine_output.date) = :month";
1823
-				$query_values = array_merge($query_values,array(':month' => $month));
1823
+				$query_values = array_merge($query_values, array(':month' => $month));
1824 1824
 			} else {
1825 1825
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1826
-				$query_values = array_merge($query_values,array(':month' => $month));
1826
+				$query_values = array_merge($query_values, array(':month' => $month));
1827 1827
 			}
1828 1828
 		}
1829 1829
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1830
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1830
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1831 1831
 		
1832 1832
 		$sth = $this->db->prepare($queryi);
1833 1833
 		$sth->execute($query_values);
@@ -1840,32 +1840,32 @@  discard block
 block discarded – undo
1840 1840
 	* @return Integer the number of vessels
1841 1841
 	*
1842 1842
 	*/
1843
-	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1843
+	public function countOverallMarineTypes($filters = array(), $year = '', $month = '')
1844 1844
 	{
1845 1845
 		global $globalDBdriver;
1846
-		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1846
+		$queryi = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1847 1847
 		$query_values = array();
1848 1848
 		$query = '';
1849 1849
 		if ($year != '') {
1850 1850
 			if ($globalDBdriver == 'mysql') {
1851 1851
 				$query .= " AND YEAR(marine_output.date) = :year";
1852
-				$query_values = array_merge($query_values,array(':year' => $year));
1852
+				$query_values = array_merge($query_values, array(':year' => $year));
1853 1853
 			} else {
1854 1854
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1855
-				$query_values = array_merge($query_values,array(':year' => $year));
1855
+				$query_values = array_merge($query_values, array(':year' => $year));
1856 1856
 			}
1857 1857
 		}
1858 1858
 		if ($month != '') {
1859 1859
 			if ($globalDBdriver == 'mysql') {
1860 1860
 				$query .= " AND MONTH(marine_output.date) = :month";
1861
-				$query_values = array_merge($query_values,array(':month' => $month));
1861
+				$query_values = array_merge($query_values, array(':month' => $month));
1862 1862
 			} else {
1863 1863
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1864
-				$query_values = array_merge($query_values,array(':month' => $month));
1864
+				$query_values = array_merge($query_values, array(':month' => $month));
1865 1865
 			}
1866 1866
 		}
1867 1867
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1868
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1868
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1869 1869
 		
1870 1870
 		$sth = $this->db->prepare($queryi);
1871 1871
 		$sth->execute($query_values);
@@ -1882,7 +1882,7 @@  discard block
 block discarded – undo
1882 1882
 	public function countAllHoursFromToday($filters = array())
1883 1883
 	{
1884 1884
 		global $globalTimezone, $globalDBdriver;
1885
-		$filter_query = $this->getFilter($filters,true,true);
1885
+		$filter_query = $this->getFilter($filters, true, true);
1886 1886
 		if ($globalTimezone != '') {
1887 1887
 			date_default_timezone_set($globalTimezone);
1888 1888
 			$datetime = new DateTime();
@@ -1890,12 +1890,12 @@  discard block
 block discarded – undo
1890 1890
 		} else $offset = '+00:00';
1891 1891
 
1892 1892
 		if ($globalDBdriver == 'mysql') {
1893
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1893
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1894 1894
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1895 1895
 								GROUP BY hour_name 
1896 1896
 								ORDER BY hour_name ASC";
1897 1897
 		} else {
1898
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1898
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1899 1899
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1900 1900
 								GROUP BY hour_name 
1901 1901
 								ORDER BY hour_name ASC";
@@ -1907,7 +1907,7 @@  discard block
 block discarded – undo
1907 1907
 		$hour_array = array();
1908 1908
 		$temp_array = array();
1909 1909
         
1910
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1910
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1911 1911
 		{
1912 1912
 			$temp_array['hour_name'] = $row['hour_name'];
1913 1913
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1926,9 +1926,9 @@  discard block
 block discarded – undo
1926 1926
 	*/
1927 1927
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1928 1928
 	{
1929
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1929
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1930 1930
 
1931
-		$query  = "SELECT marine_output.marine_id
1931
+		$query = "SELECT marine_output.marine_id
1932 1932
 				FROM marine_output 
1933 1933
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1934 1934
         
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
 		$sth = $this->db->prepare($query);
1937 1937
 		$sth->execute();
1938 1938
 
1939
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1939
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1940 1940
 		{
1941 1941
 			return $row['marine_id'];
1942 1942
 		}
@@ -1961,23 +1961,23 @@  discard block
 block discarded – undo
1961 1961
 		}
1962 1962
 		
1963 1963
 		$current_date = date("Y-m-d H:i:s");
1964
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1964
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1965 1965
 		
1966 1966
 		$diff = abs(strtotime($current_date) - strtotime($date));
1967 1967
 
1968
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1968
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1969 1969
 		$years = $time_array['years'];
1970 1970
 		
1971
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1971
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1972 1972
 		$months = $time_array['months'];
1973 1973
 		
1974
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1974
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1975 1975
 		$days = $time_array['days'];
1976
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1976
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1977 1977
 		$hours = $time_array['hours'];
1978
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1978
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1979 1979
 		$minutes = $time_array['minutes'];
1980
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1980
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1981 1981
 		
1982 1982
 		return $time_array;
1983 1983
 	}
@@ -2000,63 +2000,63 @@  discard block
 block discarded – undo
2000 2000
 			$temp_array['direction_degree'] = $direction;
2001 2001
 			$temp_array['direction_shortname'] = "N";
2002 2002
 			$temp_array['direction_fullname'] = "North";
2003
-		} elseif ($direction >= 22.5 && $direction < 45){
2003
+		} elseif ($direction >= 22.5 && $direction < 45) {
2004 2004
 			$temp_array['direction_degree'] = $direction;
2005 2005
 			$temp_array['direction_shortname'] = "NNE";
2006 2006
 			$temp_array['direction_fullname'] = "North-Northeast";
2007
-		} elseif ($direction >= 45 && $direction < 67.5){
2007
+		} elseif ($direction >= 45 && $direction < 67.5) {
2008 2008
 			$temp_array['direction_degree'] = $direction;
2009 2009
 			$temp_array['direction_shortname'] = "NE";
2010 2010
 			$temp_array['direction_fullname'] = "Northeast";
2011
-		} elseif ($direction >= 67.5 && $direction < 90){
2011
+		} elseif ($direction >= 67.5 && $direction < 90) {
2012 2012
 			$temp_array['direction_degree'] = $direction;
2013 2013
 			$temp_array['direction_shortname'] = "ENE";
2014 2014
 			$temp_array['direction_fullname'] = "East-Northeast";
2015
-		} elseif ($direction >= 90 && $direction < 112.5){
2015
+		} elseif ($direction >= 90 && $direction < 112.5) {
2016 2016
 			$temp_array['direction_degree'] = $direction;
2017 2017
 			$temp_array['direction_shortname'] = "E";
2018 2018
 			$temp_array['direction_fullname'] = "East";
2019
-		} elseif ($direction >= 112.5 && $direction < 135){
2019
+		} elseif ($direction >= 112.5 && $direction < 135) {
2020 2020
 			$temp_array['direction_degree'] = $direction;
2021 2021
 			$temp_array['direction_shortname'] = "ESE";
2022 2022
 			$temp_array['direction_fullname'] = "East-Southeast";
2023
-		} elseif ($direction >= 135 && $direction < 157.5){
2023
+		} elseif ($direction >= 135 && $direction < 157.5) {
2024 2024
 			$temp_array['direction_degree'] = $direction;
2025 2025
 			$temp_array['direction_shortname'] = "SE";
2026 2026
 			$temp_array['direction_fullname'] = "Southeast";
2027
-		} elseif ($direction >= 157.5 && $direction < 180){
2027
+		} elseif ($direction >= 157.5 && $direction < 180) {
2028 2028
 			$temp_array['direction_degree'] = $direction;
2029 2029
 			$temp_array['direction_shortname'] = "SSE";
2030 2030
 			$temp_array['direction_fullname'] = "South-Southeast";
2031
-		} elseif ($direction >= 180 && $direction < 202.5){
2031
+		} elseif ($direction >= 180 && $direction < 202.5) {
2032 2032
 			$temp_array['direction_degree'] = $direction;
2033 2033
 			$temp_array['direction_shortname'] = "S";
2034 2034
 			$temp_array['direction_fullname'] = "South";
2035
-		} elseif ($direction >= 202.5 && $direction < 225){
2035
+		} elseif ($direction >= 202.5 && $direction < 225) {
2036 2036
 			$temp_array['direction_degree'] = $direction;
2037 2037
 			$temp_array['direction_shortname'] = "SSW";
2038 2038
 			$temp_array['direction_fullname'] = "South-Southwest";
2039
-		} elseif ($direction >= 225 && $direction < 247.5){
2039
+		} elseif ($direction >= 225 && $direction < 247.5) {
2040 2040
 			$temp_array['direction_degree'] = $direction;
2041 2041
 			$temp_array['direction_shortname'] = "SW";
2042 2042
 			$temp_array['direction_fullname'] = "Southwest";
2043
-		} elseif ($direction >= 247.5 && $direction < 270){
2043
+		} elseif ($direction >= 247.5 && $direction < 270) {
2044 2044
 			$temp_array['direction_degree'] = $direction;
2045 2045
 			$temp_array['direction_shortname'] = "WSW";
2046 2046
 			$temp_array['direction_fullname'] = "West-Southwest";
2047
-		} elseif ($direction >= 270 && $direction < 292.5){
2047
+		} elseif ($direction >= 270 && $direction < 292.5) {
2048 2048
 			$temp_array['direction_degree'] = $direction;
2049 2049
 			$temp_array['direction_shortname'] = "W";
2050 2050
 			$temp_array['direction_fullname'] = "West";
2051
-		} elseif ($direction >= 292.5 && $direction < 315){
2051
+		} elseif ($direction >= 292.5 && $direction < 315) {
2052 2052
 			$temp_array['direction_degree'] = $direction;
2053 2053
 			$temp_array['direction_shortname'] = "WNW";
2054 2054
 			$temp_array['direction_fullname'] = "West-Northwest";
2055
-		} elseif ($direction >= 315 && $direction < 337.5){
2055
+		} elseif ($direction >= 315 && $direction < 337.5) {
2056 2056
 			$temp_array['direction_degree'] = $direction;
2057 2057
 			$temp_array['direction_shortname'] = "NW";
2058 2058
 			$temp_array['direction_fullname'] = "Northwest";
2059
-		} elseif ($direction >= 337.5 && $direction < 360){
2059
+		} elseif ($direction >= 337.5 && $direction < 360) {
2060 2060
 			$temp_array['direction_degree'] = $direction;
2061 2061
 			$temp_array['direction_shortname'] = "NNW";
2062 2062
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -2073,11 +2073,11 @@  discard block
 block discarded – undo
2073 2073
 	* @param Float $longitude longitute of the flight
2074 2074
 	* @return String the countrie
2075 2075
 	*/
2076
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
2076
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
2077 2077
 	{
2078 2078
 		global $globalDBdriver, $globalDebug;
2079
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
2080
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
2079
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
2080
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
2081 2081
 	
2082 2082
 		$Connection = new Connection($this->db);
2083 2083
 		if (!$Connection->tableExists('countries')) return '';
@@ -2117,7 +2117,7 @@  discard block
 block discarded – undo
2117 2117
 	public function getCountryFromISO2($iso2)
2118 2118
 	{
2119 2119
 		global $globalDBdriver, $globalDebug;
2120
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
2120
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
2121 2121
 	
2122 2122
 		$Connection = new Connection($this->db);
2123 2123
 		if (!$Connection->tableExists('countries')) return '';
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
 		
2166 2166
 		$bitly_data = json_decode($bitly_data);
2167 2167
 		$bitly_url = '';
2168
-		if ($bitly_data->status_txt = "OK"){
2168
+		if ($bitly_data->status_txt = "OK") {
2169 2169
 			$bitly_url = $bitly_data->data->url;
2170 2170
 		}
2171 2171
 
@@ -2179,11 +2179,11 @@  discard block
 block discarded – undo
2179 2179
 	* @return Array the vessel type list
2180 2180
 	*
2181 2181
 	*/
2182
-	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
2182
+	public function countAllMarineTypes($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
2183 2183
 	{
2184 2184
 		global $globalDBdriver;
2185
-		$filter_query = $this->getFilter($filters,true,true);
2186
-		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id 
2185
+		$filter_query = $this->getFilter($filters, true, true);
2186
+		$query = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id 
2187 2187
 		    FROM marine_output ".$filter_query." marine_output.type <> '' AND marine_output.type_id IS NOT NULL";
2188 2188
 		if ($olderthanmonths > 0) {
2189 2189
 			if ($globalDBdriver == 'mysql') {
@@ -2203,28 +2203,28 @@  discard block
 block discarded – undo
2203 2203
 		if ($year != '') {
2204 2204
 			if ($globalDBdriver == 'mysql') {
2205 2205
 				$query .= " AND YEAR(marine_output.date) = :year";
2206
-				$query_values = array_merge($query_values,array(':year' => $year));
2206
+				$query_values = array_merge($query_values, array(':year' => $year));
2207 2207
 			} else {
2208 2208
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
2209
-				$query_values = array_merge($query_values,array(':year' => $year));
2209
+				$query_values = array_merge($query_values, array(':year' => $year));
2210 2210
 			}
2211 2211
 		}
2212 2212
 		if ($month != '') {
2213 2213
 			if ($globalDBdriver == 'mysql') {
2214 2214
 				$query .= " AND MONTH(marine_output.date) = :month";
2215
-				$query_values = array_merge($query_values,array(':month' => $month));
2215
+				$query_values = array_merge($query_values, array(':month' => $month));
2216 2216
 			} else {
2217 2217
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
2218
-				$query_values = array_merge($query_values,array(':month' => $month));
2218
+				$query_values = array_merge($query_values, array(':month' => $month));
2219 2219
 			}
2220 2220
 		}
2221 2221
 		if ($day != '') {
2222 2222
 			if ($globalDBdriver == 'mysql') {
2223 2223
 				$query .= " AND DAY(marine_output.date) = :day";
2224
-				$query_values = array_merge($query_values,array(':day' => $day));
2224
+				$query_values = array_merge($query_values, array(':day' => $day));
2225 2225
 			} else {
2226 2226
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
2227
-				$query_values = array_merge($query_values,array(':day' => $day));
2227
+				$query_values = array_merge($query_values, array(':day' => $day));
2228 2228
 			}
2229 2229
 		}
2230 2230
 		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC";
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
 		$sth->execute($query_values);
2234 2234
 		$marine_array = array();
2235 2235
 		$temp_array = array();
2236
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2236
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
2237 2237
 		{
2238 2238
 			$temp_array['marine_type'] = $row['marine_type'];
2239 2239
 			$temp_array['marine_type_id'] = $row['marine_type_id'];
@@ -2249,13 +2249,13 @@  discard block
 block discarded – undo
2249 2249
 	* @return Array the tracker information
2250 2250
 	*
2251 2251
 	*/
2252
-	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
2252
+	public function searchMarineData($q = '', $callsign = '', $mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '', $origLat = '', $origLon = '', $dist = '', $filters = array())
2253 2253
 	{
2254 2254
 		global $globalTimezone, $globalDBdriver;
2255 2255
 		date_default_timezone_set('UTC');
2256 2256
 		$query_values = array();
2257 2257
 		$additional_query = '';
2258
-		$filter_query = $this->getFilter($filters,true,true);
2258
+		$filter_query = $this->getFilter($filters, true, true);
2259 2259
 		if ($q != "")
2260 2260
 		{
2261 2261
 			if (!is_string($q))
@@ -2263,8 +2263,8 @@  discard block
 block discarded – undo
2263 2263
 				return false;
2264 2264
 			} else {
2265 2265
 				$q_array = explode(" ", $q);
2266
-				foreach ($q_array as $q_item){
2267
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
2266
+				foreach ($q_array as $q_item) {
2267
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
2268 2268
 					$additional_query .= " AND (";
2269 2269
 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
2270 2270
 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
@@ -2276,42 +2276,42 @@  discard block
 block discarded – undo
2276 2276
 		}
2277 2277
 		if ($callsign != "")
2278 2278
 		{
2279
-			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
2279
+			$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
2280 2280
 			if (!is_string($callsign))
2281 2281
 			{
2282 2282
 				return false;
2283 2283
 			} else {
2284 2284
 				$additional_query .= " AND marine_output.ident = :callsign";
2285
-				$query_values = array_merge($query_values,array(':callsign' => $callsign));
2285
+				$query_values = array_merge($query_values, array(':callsign' => $callsign));
2286 2286
 			}
2287 2287
 		}
2288 2288
 		if ($mmsi != "")
2289 2289
 		{
2290
-			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
2290
+			$mmsi = filter_var($mmsi, FILTER_SANITIZE_STRING);
2291 2291
 			if (!is_numeric($mmsi))
2292 2292
 			{
2293 2293
 				return false;
2294 2294
 			} else {
2295 2295
 				$additional_query .= " AND marine_output.mmsi = :mmsi";
2296
-				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
2296
+				$query_values = array_merge($query_values, array(':mmsi' => $mmsi));
2297 2297
 			}
2298 2298
 		}
2299 2299
 		if ($imo != "")
2300 2300
 		{
2301
-			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
2301
+			$imo = filter_var($imo, FILTER_SANITIZE_STRING);
2302 2302
 			if (!is_numeric($imo))
2303 2303
 			{
2304 2304
 				return false;
2305 2305
 			} else {
2306 2306
 				$additional_query .= " AND marine_output.imo = :imo";
2307
-				$query_values = array_merge($query_values,array(':imo' => $imo));
2307
+				$query_values = array_merge($query_values, array(':imo' => $imo));
2308 2308
 			}
2309 2309
 		}
2310 2310
 		if ($date_posted != "")
2311 2311
 		{
2312 2312
 			$date_array = explode(",", $date_posted);
2313
-			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
2314
-			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
2313
+			$date_array[0] = filter_var($date_array[0], FILTER_SANITIZE_STRING);
2314
+			$date_array[1] = filter_var($date_array[1], FILTER_SANITIZE_STRING);
2315 2315
 			if ($globalTimezone != '') {
2316 2316
 				date_default_timezone_set($globalTimezone);
2317 2317
 				$datetime = new DateTime();
@@ -2338,8 +2338,8 @@  discard block
 block discarded – undo
2338 2338
 		if ($limit != "")
2339 2339
 		{
2340 2340
 			$limit_array = explode(",", $limit);
2341
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
2342
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
2341
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
2342
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
2343 2343
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
2344 2344
 			{
2345 2345
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -2357,22 +2357,22 @@  discard block
 block discarded – undo
2357 2357
 			}
2358 2358
 		}
2359 2359
 		if ($origLat != "" && $origLon != "" && $dist != "") {
2360
-			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
2360
+			$dist = number_format($dist*0.621371, 2, '.', ''); // convert km to mile
2361 2361
 			if ($globalDBdriver == 'mysql') {
2362
-				$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 
2362
+				$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 
2363 2363
 				    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)) 
2364 2364
 				    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;
2365 2365
 			} else {
2366
-				$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 
2366
+				$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 
2367 2367
 				    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)) 
2368 2368
 				    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;
2369 2369
 			}
2370 2370
 		} else {
2371
-			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
2371
+			$query = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
2372 2372
 			    ".$additional_query."
2373 2373
 			    ".$orderby_query;
2374 2374
 		}
2375
-		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
2375
+		$marine_array = $this->getDataFromDB($query, $query_values, $limit_query);
2376 2376
 		return $marine_array;
2377 2377
 	}
2378 2378
 
@@ -2385,12 +2385,12 @@  discard block
 block discarded – undo
2385 2385
 	public function checkId($id)
2386 2386
 	{
2387 2387
 		global $globalDBdriver, $globalTimezone;
2388
-		$query  = 'SELECT marine_output.ident, marine_output.fammarine_id FROM marine_output WHERE marine_output.fammarine_id = :id';
2388
+		$query = 'SELECT marine_output.ident, marine_output.fammarine_id FROM marine_output WHERE marine_output.fammarine_id = :id';
2389 2389
 		$query_data = array(':id' => $id);
2390 2390
 		$sth = $this->db->prepare($query);
2391 2391
 		$sth->execute($query_data);
2392
-		$ident_result='';
2393
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2392
+		$ident_result = '';
2393
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
2394 2394
 		{
2395 2395
 			$ident_result = $row['fammarine_id'];
2396 2396
 		}
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
 
2400 2400
 	public function getOrderBy()
2401 2401
 	{
2402
-		$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 port - ASC", "sql" => "ORDER BY marine_output.departure_port_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"));
2402
+		$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 port - ASC", "sql" => "ORDER BY marine_output.departure_port_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"));
2403 2403
 		
2404 2404
 		return $orderby;
2405 2405
 		
Please login to merge, or discard this patch.
Braces   +244 added lines, -86 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
 	public function __construct($dbc = null) {
9 9
 		$Connection = new Connection($dbc);
10 10
 		$this->db = $Connection->db();
11
-		if ($this->db === null) die('Error: No DB connection. (Marine)');
11
+		if ($this->db === null) {
12
+			die('Error: No DB connection. (Marine)');
13
+		}
12 14
 	}
13 15
 
14 16
 	/**
@@ -30,7 +32,9 @@  discard block
 block discarded – undo
30 32
 		if (isset($filter[0]['source'])) {
31 33
 			$filters = array_merge($filters,$filter);
32 34
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
35
+		if (is_array($globalFilter)) {
36
+			$filter = array_merge($filter,$globalFilter);
37
+		}
34 38
 		$filter_query_join = '';
35 39
 		$filter_query_where = '';
36 40
 		foreach($filters as $flt) {
@@ -78,8 +82,11 @@  discard block
 block discarded – undo
78 82
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
79 83
 			}
80 84
 		}
81
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
82
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
85
+		if ($filter_query_where == '' && $where) {
86
+			$filter_query_where = ' WHERE';
87
+		} elseif ($filter_query_where != '' && $and) {
88
+			$filter_query_where .= ' AND';
89
+		}
83 90
 		if ($filter_query_where != '') {
84 91
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
85 92
 		}
@@ -133,42 +140,84 @@  discard block
 block discarded – undo
133 140
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
134 141
 			} elseif (isset($row['spotter_archive_output_id'])) {
135 142
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
136
-			*/} 
137
-			elseif (isset($row['marineid'])) {
143
+			*/} elseif (isset($row['marineid'])) {
138 144
 				$temp_array['marine_id'] = $row['marineid'];
139 145
 			} else {
140 146
 				$temp_array['marine_id'] = '';
141 147
 			}
142
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
143
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
144
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
145
-			if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id'];
146
-			if (isset($row['status'])) $temp_array['status'] = $row['status'];
147
-			if (isset($row['status_id'])) $temp_array['status_id'] = $row['status_id'];
148
-			if (isset($row['captain_id'])) $temp_array['captain_id'] = $row['captain_id'];
149
-			if (isset($row['captain_name'])) $temp_array['captain_name'] = $row['captain_name'];
150
-			if (isset($row['race_id'])) $temp_array['race_id'] = $row['race_id'];
151
-			if (isset($row['race_name'])) $temp_array['race_name'] = $row['race_name'];
152
-			if (isset($row['race_time']) && isset($row['status']) && $row['status'] != 'Racing' && $row['race_time'] > 0) $temp_array['race_time'] = $row['race_time'];
153
-			if (isset($row['race_rank'])) $temp_array['race_rank'] = $row['race_rank'];
154
-			if (isset($row['ident'])) $temp_array['ident'] = $row['ident'];
155
-			if (isset($row['arrival_port_name'])) $temp_array['arrival_port_name'] = $row['arrival_port_name'];
156
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
157
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
158
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
159
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
148
+			if (isset($row['fammarine_id'])) {
149
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
150
+			}
151
+			if (isset($row['mmsi'])) {
152
+				$temp_array['mmsi'] = $row['mmsi'];
153
+			}
154
+			if (isset($row['type'])) {
155
+				$temp_array['type'] = $row['type'];
156
+			}
157
+			if (isset($row['type_id'])) {
158
+				$temp_array['type_id'] = $row['type_id'];
159
+			}
160
+			if (isset($row['status'])) {
161
+				$temp_array['status'] = $row['status'];
162
+			}
163
+			if (isset($row['status_id'])) {
164
+				$temp_array['status_id'] = $row['status_id'];
165
+			}
166
+			if (isset($row['captain_id'])) {
167
+				$temp_array['captain_id'] = $row['captain_id'];
168
+			}
169
+			if (isset($row['captain_name'])) {
170
+				$temp_array['captain_name'] = $row['captain_name'];
171
+			}
172
+			if (isset($row['race_id'])) {
173
+				$temp_array['race_id'] = $row['race_id'];
174
+			}
175
+			if (isset($row['race_name'])) {
176
+				$temp_array['race_name'] = $row['race_name'];
177
+			}
178
+			if (isset($row['race_time']) && isset($row['status']) && $row['status'] != 'Racing' && $row['race_time'] > 0) {
179
+				$temp_array['race_time'] = $row['race_time'];
180
+			}
181
+			if (isset($row['race_rank'])) {
182
+				$temp_array['race_rank'] = $row['race_rank'];
183
+			}
184
+			if (isset($row['ident'])) {
185
+				$temp_array['ident'] = $row['ident'];
186
+			}
187
+			if (isset($row['arrival_port_name'])) {
188
+				$temp_array['arrival_port_name'] = $row['arrival_port_name'];
189
+			}
190
+			if (isset($row['latitude'])) {
191
+				$temp_array['latitude'] = $row['latitude'];
192
+			}
193
+			if (isset($row['longitude'])) {
194
+				$temp_array['longitude'] = $row['longitude'];
195
+			}
196
+			if (isset($row['distance']) && $row['distance'] != '') {
197
+				$temp_array['distance'] = $row['distance'];
198
+			}
199
+			if (isset($row['format_source'])) {
200
+				$temp_array['format_source'] = $row['format_source'];
201
+			}
160 202
 			if (isset($row['heading'])) {
161 203
 				$temp_array['heading'] = $row['heading'];
162 204
 				$heading_direction = $this->parseDirection($row['heading']);
163
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
205
+				if (isset($heading_direction[0]['direction_fullname'])) {
206
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
207
+				}
208
+			}
209
+			if (isset($row['ground_speed'])) {
210
+				$temp_array['ground_speed'] = $row['ground_speed'];
164 211
 			}
165
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
166 212
 
167 213
 			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
168 214
 			{
169 215
 				$Image = new Image($this->db);
170
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
171
-				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
216
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') {
217
+					$image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
218
+				} else {
219
+					$image_array = $Image->getMarineImage($temp_array['mmsi']);
220
+				}
172 221
 				unset($Image);
173 222
 				if (count($image_array) > 0) {
174 223
 					$temp_array['image'] = $image_array[0]['image'];
@@ -220,13 +269,21 @@  discard block
 block discarded – undo
220 269
 			}
221 270
 			
222 271
 			$fromsource = NULL;
223
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
224
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
225
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
272
+			if (isset($row['source_name']) && $row['source_name'] != '') {
273
+				$temp_array['source_name'] = $row['source_name'];
274
+			}
275
+			if (isset($row['over_country']) && $row['over_country'] != '') {
276
+				$temp_array['over_country'] = $row['over_country'];
277
+			}
278
+			if (isset($row['distance']) && $row['distance'] != '') {
279
+				$temp_array['distance'] = $row['distance'];
280
+			}
226 281
 			$temp_array['query_number_rows'] = $num_rows;
227 282
 			$spotter_array[] = $temp_array;
228 283
 		}
229
-		if ($num_rows == 0) return array();
284
+		if ($num_rows == 0) {
285
+			return array();
286
+		}
230 287
 		$spotter_array[0]['query_number_rows'] = $num_rows;
231 288
 		return $spotter_array;
232 289
 	}	
@@ -252,8 +309,12 @@  discard block
 block discarded – undo
252 309
 			{
253 310
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
254 311
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
255
-			} else $limit_query = "";
256
-		} else $limit_query = "";
312
+			} else {
313
+				$limit_query = "";
314
+			}
315
+		} else {
316
+			$limit_query = "";
317
+		}
257 318
 		if ($sort != "")
258 319
 		{
259 320
 			$search_orderby_array = $this->getOrderBy();
@@ -277,7 +338,9 @@  discard block
 block discarded – undo
277 338
 		global $global_marine_query;
278 339
 		
279 340
 		date_default_timezone_set('UTC');
280
-		if ($id == '') return array();
341
+		if ($id == '') {
342
+			return array();
343
+		}
281 344
 		$additional_query = "marine_output.fammarine_id = :id";
282 345
 		$query_values = array(':id' => $id);
283 346
 		$query  = $global_marine_query." WHERE ".$additional_query." ";
@@ -721,8 +784,11 @@  discard block
 block discarded – undo
721 784
 		$sth = $this->db->prepare($query);
722 785
 		$sth->execute($query_values);
723 786
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
724
-		if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']);
725
-		else return $result[0]['duration'];
787
+		if (is_int($result[0]['duration'])) {
788
+			return gmdate('H:i:s',$result[0]['duration']);
789
+		} else {
790
+			return $result[0]['duration'];
791
+		}
726 792
 	}
727 793
 
728 794
 	/**
@@ -781,8 +847,11 @@  discard block
 block discarded – undo
781 847
 		$query .= " ORDER BY marine_output.source_name ASC";
782 848
 
783 849
 		$sth = $this->db->prepare($query);
784
-		if (!empty($query_values)) $sth->execute($query_values);
785
-		else $sth->execute();
850
+		if (!empty($query_values)) {
851
+			$sth->execute($query_values);
852
+		} else {
853
+			$sth->execute();
854
+		}
786 855
 
787 856
 		$source_array = array();
788 857
 		$temp_array = array();
@@ -837,8 +906,11 @@  discard block
 block discarded – undo
837 906
 		$sth = $this->db->prepare($query);
838 907
 		$sth->execute(array(':mmsi' => $mmsi));
839 908
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
840
-		if (isset($result[0])) return $result[0];
841
-		else return array();
909
+		if (isset($result[0])) {
910
+			return $result[0];
911
+		} else {
912
+			return array();
913
+		}
842 914
 	}
843 915
 
844 916
 	/**
@@ -879,7 +951,9 @@  discard block
 block discarded – undo
879 951
 			date_default_timezone_set($globalTimezone);
880 952
 			$datetime = new DateTime();
881 953
 			$offset = $datetime->format('P');
882
-		} else $offset = '+00:00';
954
+		} else {
955
+			$offset = '+00:00';
956
+		}
883 957
 
884 958
 		if ($globalDBdriver == 'mysql') {
885 959
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -986,8 +1060,12 @@  discard block
 block discarded – undo
986 1060
 	*/	
987 1061
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '',$distance = NULL,$race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '')
988 1062
 	{
989
-		if ($latitude == '') $latitude = NULL;
990
-		if ($longitude == '') $longitude = NULL;
1063
+		if ($latitude == '') {
1064
+			$latitude = NULL;
1065
+		}
1066
+		if ($longitude == '') {
1067
+			$longitude = NULL;
1068
+		}
991 1069
 		$groundspeed = round($groundspeed);
992 1070
 		if ($race_begin != '') {
993 1071
 			$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, distance = :distance, race_rank = :race_rank, race_time = :race_time, status = :status, date = :race_begin WHERE fammarine_id = :fammarine_id';
@@ -1139,14 +1217,28 @@  discard block
 block discarded – undo
1139 1217
 			$latitude = 0;
1140 1218
 			$longitude = 0;
1141 1219
 		}
1142
-		if ($type_id == '') $type_id = NULL;
1143
-		if ($status_id == '') $status_id = NULL;
1144
-		if ($distance == '') $distance = NULL;
1145
-		if ($race_rank == '') $race_rank = NULL;
1146
-		if ($race_time == '') $race_time = NULL;
1147
-		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
1220
+		if ($type_id == '') {
1221
+			$type_id = NULL;
1222
+		}
1223
+		if ($status_id == '') {
1224
+			$status_id = NULL;
1225
+		}
1226
+		if ($distance == '') {
1227
+			$distance = NULL;
1228
+		}
1229
+		if ($race_rank == '') {
1230
+			$race_rank = NULL;
1231
+		}
1232
+		if ($race_time == '') {
1233
+			$race_time = NULL;
1234
+		}
1235
+		if ($heading == '' || $Common->isInteger($heading) === false) {
1236
+			$heading = 0;
1237
+		}
1148 1238
 		//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
1149
-		if ($arrival_date == '') $arrival_date = NULL;
1239
+		if ($arrival_date == '') {
1240
+			$arrival_date = NULL;
1241
+		}
1150 1242
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name, distance, race_rank,race_time) 
1151 1243
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name, :distance, :race_rank,:race_time)";
1152 1244
 
@@ -1253,7 +1345,9 @@  discard block
 block discarded – undo
1253 1345
 		global $globalDBdriver, $globalArchive;
1254 1346
 		//$filter_query = $this->getFilter($filters,true,true);
1255 1347
 		$Connection= new Connection($this->db);
1256
-		if (!$Connection->tableExists('countries')) return array();
1348
+		if (!$Connection->tableExists('countries')) {
1349
+			return array();
1350
+		}
1257 1351
 		require_once('class.SpotterLive.php');
1258 1352
 		if (!isset($globalArchive) || $globalArchive !== TRUE) {
1259 1353
 			$MarineLive = new MarineLive($this->db);
@@ -1297,7 +1391,9 @@  discard block
 block discarded – undo
1297 1391
 			$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_archive".$filter_query.") l ON c.iso2 = l.over_country ";
1298 1392
 		}
1299 1393
 		$query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC";
1300
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1394
+		if ($limit) {
1395
+			$query .= " LIMIT 10 OFFSET 0";
1396
+		}
1301 1397
 
1302 1398
 		$sth = $this->db->prepare($query);
1303 1399
 		$sth->execute();
@@ -1331,12 +1427,18 @@  discard block
 block discarded – undo
1331 1427
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1332 1428
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
1333 1429
 		 if ($olderthanmonths > 0) {
1334
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
1335
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1430
+			if ($globalDBdriver == 'mysql') {
1431
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
1432
+			} else {
1433
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1434
+			}
1336 1435
 		}
1337 1436
 		if ($sincedate != '') {
1338
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
1339
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
1437
+			if ($globalDBdriver == 'mysql') {
1438
+				$query .= " AND marine_output.date > '".$sincedate."'";
1439
+			} else {
1440
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
1441
+			}
1340 1442
 		}
1341 1443
 		$query_values = array();
1342 1444
 		if ($year != '') {
@@ -1367,7 +1469,9 @@  discard block
 block discarded – undo
1367 1469
 			}
1368 1470
 		}
1369 1471
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
1370
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1472
+		if ($limit) {
1473
+			$query .= " LIMIT 10 OFFSET 0";
1474
+		}
1371 1475
       		
1372 1476
 		$sth = $this->db->prepare($query);
1373 1477
 		$sth->execute($query_values);
@@ -1402,7 +1506,9 @@  discard block
 block discarded – undo
1402 1506
 			date_default_timezone_set($globalTimezone);
1403 1507
 			$datetime = new DateTime();
1404 1508
 			$offset = $datetime->format('P');
1405
-		} else $offset = '+00:00';
1509
+		} else {
1510
+			$offset = '+00:00';
1511
+		}
1406 1512
 
1407 1513
 		if ($globalDBdriver == 'mysql') {
1408 1514
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1452,7 +1558,9 @@  discard block
 block discarded – undo
1452 1558
 			date_default_timezone_set($globalTimezone);
1453 1559
 			$datetime = new DateTime();
1454 1560
 			$offset = $datetime->format('P');
1455
-		} else $offset = '+00:00';
1561
+		} else {
1562
+			$offset = '+00:00';
1563
+		}
1456 1564
 		$filter_query = $this->getFilter($filters,true,true);
1457 1565
 		if ($globalDBdriver == 'mysql') {
1458 1566
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1498,7 +1606,9 @@  discard block
 block discarded – undo
1498 1606
 			date_default_timezone_set($globalTimezone);
1499 1607
 			$datetime = new DateTime();
1500 1608
 			$offset = $datetime->format('P');
1501
-		} else $offset = '+00:00';
1609
+		} else {
1610
+			$offset = '+00:00';
1611
+		}
1502 1612
 		$filter_query = $this->getFilter($filters,true,true);
1503 1613
 		if ($globalDBdriver == 'mysql') {
1504 1614
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1546,7 +1656,9 @@  discard block
 block discarded – undo
1546 1656
 			date_default_timezone_set($globalTimezone);
1547 1657
 			$datetime = new DateTime();
1548 1658
 			$offset = $datetime->format('P');
1549
-		} else $offset = '+00:00';
1659
+		} else {
1660
+			$offset = '+00:00';
1661
+		}
1550 1662
 
1551 1663
 		if ($globalDBdriver == 'mysql') {
1552 1664
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1595,7 +1707,9 @@  discard block
 block discarded – undo
1595 1707
 			date_default_timezone_set($globalTimezone);
1596 1708
 			$datetime = new DateTime();
1597 1709
 			$offset = $datetime->format('P');
1598
-		} else $offset = '+00:00';
1710
+		} else {
1711
+			$offset = '+00:00';
1712
+		}
1599 1713
 		$filter_query = $this->getFilter($filters,true,true);
1600 1714
 		if ($globalDBdriver == 'mysql') {
1601 1715
 			$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
@@ -1644,7 +1758,9 @@  discard block
 block discarded – undo
1644 1758
 			date_default_timezone_set($globalTimezone);
1645 1759
 			$datetime = new DateTime();
1646 1760
 			$offset = $datetime->format('P');
1647
-		} else $offset = '+00:00';
1761
+		} else {
1762
+			$offset = '+00:00';
1763
+		}
1648 1764
 
1649 1765
 		$orderby_sql = '';
1650 1766
 		if ($orderby == "hour")
@@ -1713,7 +1829,9 @@  discard block
 block discarded – undo
1713 1829
 			date_default_timezone_set($globalTimezone);
1714 1830
 			$datetime = new DateTime($date);
1715 1831
 			$offset = $datetime->format('P');
1716
-		} else $offset = '+00:00';
1832
+		} else {
1833
+			$offset = '+00:00';
1834
+		}
1717 1835
 
1718 1836
 		if ($globalDBdriver == 'mysql') {
1719 1837
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1761,7 +1879,9 @@  discard block
 block discarded – undo
1761 1879
 			date_default_timezone_set($globalTimezone);
1762 1880
 			$datetime = new DateTime();
1763 1881
 			$offset = $datetime->format('P');
1764
-		} else $offset = '+00:00';
1882
+		} else {
1883
+			$offset = '+00:00';
1884
+		}
1765 1885
 
1766 1886
 		if ($globalDBdriver == 'mysql') {
1767 1887
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1826,8 +1946,11 @@  discard block
 block discarded – undo
1826 1946
 				$query_values = array_merge($query_values,array(':month' => $month));
1827 1947
 			}
1828 1948
 		}
1829
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1830
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1949
+		if (empty($query_values)) {
1950
+			$queryi .= $this->getFilter($filters);
1951
+		} else {
1952
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1953
+		}
1831 1954
 		
1832 1955
 		$sth = $this->db->prepare($queryi);
1833 1956
 		$sth->execute($query_values);
@@ -1864,8 +1987,11 @@  discard block
 block discarded – undo
1864 1987
 				$query_values = array_merge($query_values,array(':month' => $month));
1865 1988
 			}
1866 1989
 		}
1867
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1868
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1990
+		if (empty($query_values)) {
1991
+			$queryi .= $this->getFilter($filters);
1992
+		} else {
1993
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1994
+		}
1869 1995
 		
1870 1996
 		$sth = $this->db->prepare($queryi);
1871 1997
 		$sth->execute($query_values);
@@ -1887,7 +2013,9 @@  discard block
 block discarded – undo
1887 2013
 			date_default_timezone_set($globalTimezone);
1888 2014
 			$datetime = new DateTime();
1889 2015
 			$offset = $datetime->format('P');
1890
-		} else $offset = '+00:00';
2016
+		} else {
2017
+			$offset = '+00:00';
2018
+		}
1891 2019
 
1892 2020
 		if ($globalDBdriver == 'mysql') {
1893 2021
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1991,7 +2119,9 @@  discard block
 block discarded – undo
1991 2119
 	*/
1992 2120
 	public function parseDirection($direction = 0)
1993 2121
 	{
1994
-		if ($direction == '') $direction = 0;
2122
+		if ($direction == '') {
2123
+			$direction = 0;
2124
+		}
1995 2125
 		$direction_array = array();
1996 2126
 		$temp_array = array();
1997 2127
 
@@ -2080,7 +2210,9 @@  discard block
 block discarded – undo
2080 2210
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
2081 2211
 	
2082 2212
 		$Connection = new Connection($this->db);
2083
-		if (!$Connection->tableExists('countries')) return '';
2213
+		if (!$Connection->tableExists('countries')) {
2214
+			return '';
2215
+		}
2084 2216
 	
2085 2217
 		try {
2086 2218
 			/*
@@ -2100,9 +2232,13 @@  discard block
 block discarded – undo
2100 2232
 			$sth->closeCursor();
2101 2233
 			if (count($row) > 0) {
2102 2234
 				return $row;
2103
-			} else return '';
2235
+			} else {
2236
+				return '';
2237
+			}
2104 2238
 		} catch (PDOException $e) {
2105
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
2239
+			if (isset($globalDebug) && $globalDebug) {
2240
+				echo 'Error : '.$e->getMessage()."\n";
2241
+			}
2106 2242
 			return '';
2107 2243
 		}
2108 2244
 	
@@ -2120,7 +2256,9 @@  discard block
 block discarded – undo
2120 2256
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
2121 2257
 	
2122 2258
 		$Connection = new Connection($this->db);
2123
-		if (!$Connection->tableExists('countries')) return '';
2259
+		if (!$Connection->tableExists('countries')) {
2260
+			return '';
2261
+		}
2124 2262
 	
2125 2263
 		try {
2126 2264
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -2132,9 +2270,13 @@  discard block
 block discarded – undo
2132 2270
 			$sth->closeCursor();
2133 2271
 			if (count($row) > 0) {
2134 2272
 				return $row;
2135
-			} else return '';
2273
+			} else {
2274
+				return '';
2275
+			}
2136 2276
 		} catch (PDOException $e) {
2137
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
2277
+			if (isset($globalDebug) && $globalDebug) {
2278
+				echo 'Error : '.$e->getMessage()."\n";
2279
+			}
2138 2280
 			return '';
2139 2281
 		}
2140 2282
 	
@@ -2152,7 +2294,9 @@  discard block
 block discarded – undo
2152 2294
 	{
2153 2295
 		global $globalBitlyAccessToken;
2154 2296
 		
2155
-		if ($globalBitlyAccessToken == '') return $url;
2297
+		if ($globalBitlyAccessToken == '') {
2298
+			return $url;
2299
+		}
2156 2300
         
2157 2301
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
2158 2302
 		
@@ -2228,7 +2372,9 @@  discard block
 block discarded – undo
2228 2372
 			}
2229 2373
 		}
2230 2374
 		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC";
2231
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
2375
+		if ($limit) {
2376
+			$query .= " LIMIT 10 OFFSET 0";
2377
+		}
2232 2378
 		$sth = $this->db->prepare($query);
2233 2379
 		$sth->execute($query_values);
2234 2380
 		$marine_array = array();
@@ -2266,9 +2412,15 @@  discard block
 block discarded – undo
2266 2412
 				foreach ($q_array as $q_item){
2267 2413
 					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
2268 2414
 					$additional_query .= " AND (";
2269
-					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
2270
-					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
2271
-					if (is_int($q_item)) $additional_query .= "(marine_output.imo = '".$q_item."') OR ";
2415
+					if (is_int($q_item)) {
2416
+						$additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
2417
+					}
2418
+					if (is_int($q_item)) {
2419
+						$additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
2420
+					}
2421
+					if (is_int($q_item)) {
2422
+						$additional_query .= "(marine_output.imo = '".$q_item."') OR ";
2423
+					}
2272 2424
 					$additional_query .= "(marine_output.ident like '%".$q_item."%') OR ";
2273 2425
 					$additional_query .= ")";
2274 2426
 				}
@@ -2316,7 +2468,9 @@  discard block
 block discarded – undo
2316 2468
 				date_default_timezone_set($globalTimezone);
2317 2469
 				$datetime = new DateTime();
2318 2470
 				$offset = $datetime->format('P');
2319
-			} else $offset = '+00:00';
2471
+			} else {
2472
+				$offset = '+00:00';
2473
+			}
2320 2474
 			if ($date_array[1] != "")
2321 2475
 			{
2322 2476
 				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
@@ -2343,8 +2497,12 @@  discard block
 block discarded – undo
2343 2497
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
2344 2498
 			{
2345 2499
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
2346
-			} else $limit_query = "";
2347
-		} else $limit_query = "";
2500
+			} else {
2501
+				$limit_query = "";
2502
+			}
2503
+		} else {
2504
+			$limit_query = "";
2505
+		}
2348 2506
 		if ($sort != "")
2349 2507
 		{
2350 2508
 			$search_orderby_array = $this->getOrderBy();
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Stats.php');
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 if (isset($globalServerAPRS) && $globalServerAPRS) {
12
-    require_once(dirname(__FILE__).'/class.APRS.php');
12
+	require_once(dirname(__FILE__).'/class.APRS.php');
13 13
 }
14 14
 
15 15
 class MarineImport {
16
-    private $all_tracked = array();
17
-    private $last_delete_hourly = 0;
18
-    private $last_delete = 0;
19
-    private $stats = array();
20
-    private $tmd = 0;
21
-    private $source_location = array();
22
-    public $db = null;
23
-    public $nb = 0;
16
+	private $all_tracked = array();
17
+	private $last_delete_hourly = 0;
18
+	private $last_delete = 0;
19
+	private $stats = array();
20
+	private $tmd = 0;
21
+	private $source_location = array();
22
+	public $db = null;
23
+	public $nb = 0;
24 24
 
25
-    public function __construct($dbc = null) {
25
+	public function __construct($dbc = null) {
26 26
 	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
27 27
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
28
-	    $Connection = new Connection($dbc);
29
-	    $this->db = $Connection->db();
30
-	    date_default_timezone_set('UTC');
28
+		$Connection = new Connection($dbc);
29
+		$this->db = $Connection->db();
30
+		date_default_timezone_set('UTC');
31 31
 	}
32 32
 	// Get previous source stats
33 33
 	/*
@@ -46,75 +46,75 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 	*/
48 48
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
49
-	    $APRSMarine = new APRSMarine();
50
-	    //$APRSSpotter->connect();
49
+		$APRSMarine = new APRSMarine();
50
+		//$APRSSpotter->connect();
51
+	}
51 52
 	}
52
-    }
53 53
 
54
-    public function checkAll() {
54
+	public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
58
-	    foreach ($this->all_tracked as $key => $flight) {
57
+		if ($globalDebug) echo "Update last seen tracked data...\n";
58
+		foreach ($this->all_tracked as $key => $flight) {
59 59
 		if (isset($this->all_tracked[$key]['id'])) {
60
-		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61
-    		    $Marine = new Marine($this->db);
62
-    		    if (isset($globalVM) && $globalVM) {
60
+			//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
61
+				$Marine = new Marine($this->db);
62
+				if (isset($globalVM) && $globalVM) {
63 63
 			if ($this->all_tracked[$key]['status'] == 'Racing') {
64
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
65
-    			} else {
66
-    			    $finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
67
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
68
-    			}
69
-    		    } else {
64
+					$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
65
+				} else {
66
+					$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
67
+					$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
68
+				}
69
+				} else {
70 70
 			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
71
-		    }
71
+			}
72 72
 		}
73
-	    }
73
+		}
74
+	}
74 75
 	}
75
-    }
76 76
 
77
-    public function del() {
77
+	public function del() {
78 78
 	global $globalDebug, $globalNoDB, $globalNoImport;
79 79
 	// Delete old infos
80 80
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
81 81
 	foreach ($this->all_tracked as $key => $flight) {
82
-    	    if (isset($flight['lastupdate'])) {
83
-        	if ($flight['lastupdate'] < (time()-3000)) {
84
-            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
85
-            		if (isset($this->all_tracked[$key]['id'])) {
86
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
87
-			    /*
82
+			if (isset($flight['lastupdate'])) {
83
+			if ($flight['lastupdate'] < (time()-3000)) {
84
+					if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
85
+					if (isset($this->all_tracked[$key]['id'])) {
86
+						if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
87
+				/*
88 88
 			    $MarineLive = new MarineLive();
89 89
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
90 90
 			    $MarineLive->db = null;
91 91
 			    */
92
-            		    //$real_arrival = $this->arrival($key);
93
-            		    $Marine = new Marine($this->db);
94
-            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
92
+						//$real_arrival = $this->arrival($key);
93
+						$Marine = new Marine($this->db);
94
+						if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
95 95
 				if (isset($globalVM) && $globalVM) {
96
-				    if ($this->all_tracked[$key]['status'] == 'Racing') {
96
+					if ($this->all_tracked[$key]['status'] == 'Racing') {
97 97
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
98
-				    } else {
98
+					} else {
99 99
 					$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
100 100
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
101
-				    }
101
+					}
102 102
 				} else {
103 103
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
104 104
 				}
105 105
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
106
-			    }
107
-			    // Put in archive
106
+				}
107
+				// Put in archive
108 108
 //				$Marine->db = null;
109 109
 			}
110
-            	    }
111
-            	    unset($this->all_tracked[$key]);
112
-    	        }
113
-	    }
114
-        }
115
-    }
110
+					}
111
+					unset($this->all_tracked[$key]);
112
+				}
113
+		}
114
+		}
115
+	}
116 116
 
117
-    public function add($line) {
117
+	public function add($line) {
118 118
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM;
119 119
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
120 120
 	date_default_timezone_set('UTC');
@@ -123,106 +123,106 @@  discard block
 block discarded – undo
123 123
 	
124 124
 	// SBS format is CSV format
125 125
 	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
126
-	    //print_r($line);
127
-  	    if (isset($line['mmsi']) || isset($line['id'])) {
126
+		//print_r($line);
127
+  		if (isset($line['mmsi']) || isset($line['id'])) {
128 128
 
129 129
 		
130 130
 		// Increment message number
131 131
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
132
-		    $current_date = date('Y-m-d');
133
-		    if (isset($line['source_name'])) $source = $line['source_name'];
134
-		    else $source = '';
135
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
136
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
137
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
138
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
139
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
132
+			$current_date = date('Y-m-d');
133
+			if (isset($line['source_name'])) $source = $line['source_name'];
134
+			else $source = '';
135
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
136
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
137
+				$this->stats[$current_date][$source]['msg']['date'] = time();
138
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
139
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
140 140
 		}
141 141
 		
142 142
 		
143 143
 		$Common = new Common();
144 144
 		$AIS = new AIS();
145
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
146
-	        else $id = trim($line['id']);
145
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
146
+			else $id = trim($line['id']);
147 147
 		
148 148
 		if (!isset($this->all_tracked[$id])) {
149
-		    $this->all_tracked[$id] = array();
150
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
152
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
153
-		    if (!isset($line['id'])) {
149
+			$this->all_tracked[$id] = array();
150
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
151
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
152
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
153
+			if (!isset($line['id'])) {
154 154
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
155 155
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
156
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
157
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
156
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
157
+			if ($globalAllTracked !== FALSE) $dataFound = true;
158 158
 		}
159 159
 		
160 160
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
162
-		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
161
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
162
+			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
163 163
 			$Marine = new Marine($this->db);
164 164
 			$identity = $Marine->getIdentity($line['mmsi']);
165 165
 			if (!empty($identity)) {
166
-			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
167
-			    $this->all_tracked[$id]['type'] = $identity['type'];
168
-			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
166
+				$this->all_tracked[$id]['ident'] = $identity['ship_name'];
167
+				$this->all_tracked[$id]['type'] = $identity['type'];
168
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
169 169
 			}
170 170
 			//print_r($identity);
171 171
 			unset($Marine);
172 172
 			//$dataFound = true;
173
-		    }
173
+			}
174 174
 		}
175 175
 		if (isset($line['type_id'])) {
176
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
176
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
177
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
178 178
 		}
179 179
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
180
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
180
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
181
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
182 182
 		} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') {
183
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
183
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
184 184
 		}
185 185
 		if (isset($line['status']) && $line['status'] != '') {
186
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
186
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
187 187
 		}
188 188
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
189
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
190
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
189
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
190
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
191 191
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
192
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
192
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
193 193
 				$Marine = new Marine($this->db);
194 194
 				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
195 195
 				unset($Marine);
196
-			    }
196
+				}
197
+			}
197 198
 			}
198
-		    }
199 199
 		}
200 200
 
201 201
 
202 202
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
203
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
203
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
204 204
 		}
205 205
 		if (isset($line['imo']) && $line['imo'] != '') {
206
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
206
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
207 207
 		}
208 208
 		if (isset($line['callsign']) && $line['callsign'] != '') {
209
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
209
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
210 210
 		}
211 211
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
212
-		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
212
+			if (!isset($this->all_tracked[$id]['arrival_code'])) {
213 213
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
214 214
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
215 215
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
216
-			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
216
+				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
217 217
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
218
-				    $Marine = new Marine($this->db);
219
-				    $fromsource = NULL;
220
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
221
-				    $Marine->db = null;
218
+					$Marine = new Marine($this->db);
219
+					$fromsource = NULL;
220
+					$Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
221
+					$Marine->db = null;
222
+				}
222 223
 				}
223
-			    }
224 224
 			}
225
-		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
225
+			} elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
226 226
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
227 227
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
228 228
 			if (!isset($line['id'])) {
@@ -230,50 +230,50 @@  discard block
 block discarded – undo
230 230
 				$this->all_tracked[$id]['forcenew'] = 1;
231 231
 				$this->all_tracked[$id]['addedMarine'] = 0;
232 232
 			}
233
-		    }
233
+			}
234 234
 		}
235 235
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
236
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
236
+			if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
237 237
 		}
238 238
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
239
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
240 240
 		}
241 241
 		if (isset($line['captain_name']) && $line['captain_name'] != '') {
242
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
242
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
243 243
 		}
244 244
 		if (isset($line['race_id']) && $line['race_id'] != '') {
245
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
245
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
246 246
 		}
247 247
 		if (isset($line['race_name']) && $line['race_name'] != '') {
248
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
248
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
249 249
 		}
250 250
 		if (isset($line['race_rank']) && $line['race_rank'] != '') {
251
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
251
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
252 252
 		}
253 253
 		if (isset($line['race_time']) && $line['race_time'] != '') {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
255 255
 		}
256 256
 		if (isset($line['race_begin']) && $line['race_begin'] != '') {
257
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
257
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
258 258
 		}
259 259
 		if (isset($line['distance']) && $line['distance'] != '') {
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
261 261
 		}
262 262
 
263 263
 		//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'])) {
264 264
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
265
-		    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
265
+			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
266 266
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
267
-			    $timeelapsed = microtime(true);
268
-			    $Marine = new Marine($this->db);
269
-			    $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']);
270
-			    $Marine->db = null;
267
+				$timeelapsed = microtime(true);
268
+				$Marine = new Marine($this->db);
269
+				$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']);
270
+				$Marine->db = null;
271
+			}
271 272
 			}
272
-		    }
273
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
274
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
273
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
274
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
275 275
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
276
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
276
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
277 277
 				$timeelapsed = microtime(true);
278 278
 				$Marine = new Marine($this->db);
279 279
 				$fromsource = NULL;
@@ -281,20 +281,20 @@  discard block
 block discarded – undo
281 281
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
282 282
 				$Marine->db = null;
283 283
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
284
-			    }
284
+				}
285
+			}
285 286
 			}
286
-		    }
287
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
287
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
288 288
 		}
289 289
 
290 290
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
291
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
291
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
292 292
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
293
-		    } else {
293
+			} else {
294 294
 				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";
295 295
 				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";
296 296
 				return '';
297
-		    }
297
+			}
298 298
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
299 299
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
300 300
 			return '';
@@ -311,33 +311,33 @@  discard block
 block discarded – undo
311 311
 
312 312
 
313 313
 		if (isset($line['speed'])) {
314
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
315
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
314
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
315
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
316 316
 		} 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'])) {
317
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
318
-		    if ($distance > 1000 && $distance < 10000) {
317
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
318
+			if ($distance > 1000 && $distance < 10000) {
319 319
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
320 320
 			$speed = $speed*3.6;
321 321
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
322 322
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
323
-		    }
323
+			}
324 324
 		}
325 325
 
326
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
327
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
328
-	    	    else unset($timediff);
329
-	    	    if ($this->tmd > 5 ||
330
-	    		!isset($timediff) ||
331
-	    		$timediff > $globalLiveInterval ||
332
-	    		(
333
-	    		    $timediff > 30 && 
334
-	    		    isset($this->all_tracked[$id]['latitude']) &&
335
-	    		    isset($this->all_tracked[$id]['longitude']) &&
336
-	    		    $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
337
-	    		)
338
-	    		) {
326
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
327
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
328
+				else unset($timediff);
329
+				if ($this->tmd > 5 ||
330
+				!isset($timediff) ||
331
+				$timediff > $globalLiveInterval ||
332
+				(
333
+					$timediff > 30 && 
334
+					isset($this->all_tracked[$id]['latitude']) &&
335
+					isset($this->all_tracked[$id]['longitude']) &&
336
+					$Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
337
+				)
338
+				) {
339 339
 			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'])) {
340
-			    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'])) {
340
+				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'])) {
341 341
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
342 342
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
343 343
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -345,213 +345,213 @@  discard block
 block discarded – undo
345 345
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
346 346
 				$timeelapsed = microtime(true);
347 347
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
348
-				    $Marine = new Marine($this->db);
349
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
350
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
351
-				    $Marine->db = null;
352
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
348
+					$Marine = new Marine($this->db);
349
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
350
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
351
+					$Marine->db = null;
352
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353 353
 				}
354 354
 				$this->tmd = 0;
355 355
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
356
-			    }
356
+				}
357 357
 			}
358 358
 
359 359
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
360 360
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
361 361
 				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') {
362
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
363
-				    $dataFound = true;
364
-				    $this->all_tracked[$id]['time_last_coord'] = time();
362
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
363
+					$dataFound = true;
364
+					$this->all_tracked[$id]['time_last_coord'] = time();
365 365
 				}
366 366
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
367 367
 			}
368 368
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
369
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
369
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
370 370
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
371 371
 				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') {
372
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
373
-				    $dataFound = true;
374
-				    $this->all_tracked[$id]['time_last_coord'] = time();
372
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
373
+					$dataFound = true;
374
+					$this->all_tracked[$id]['time_last_coord'] = time();
375 375
 				}
376 376
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
377 377
 			}
378 378
 
379
-		    } else if ($globalDebug && $timediff > 20) {
379
+			} else if ($globalDebug && $timediff > 20) {
380 380
 			$this->tmd = $this->tmd + 1;
381 381
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
382 382
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
383 383
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
384 384
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
385
-		    }
385
+			}
386 386
 		}
387 387
 		if (isset($line['last_update']) && $line['last_update'] != '') {
388
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
389
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
388
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
389
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
390 390
 		}
391 391
 		if (isset($line['format_source']) && $line['format_source'] != '') {
392
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
392
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
393 393
 		}
394 394
 		if (isset($line['source_name']) && $line['source_name'] != '') {
395
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
395
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
396 396
 		}
397 397
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
398
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
398
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
399 399
 		}
400 400
 		
401 401
 		if (isset($line['heading']) && $line['heading'] != '') {
402
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
403
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
404
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
405
-		    //$dataFound = true;
402
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
403
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
404
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
405
+			//$dataFound = true;
406 406
   		} 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']) {
407
-  		    $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']);
408
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
409
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
410
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
407
+  			$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']);
408
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
409
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
410
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
411 411
   		}
412 412
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
413 413
 
414 414
 
415 415
 
416 416
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
417
-		    $this->all_tracked[$id]['lastupdate'] = time();
418
-		    if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
419
-		        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'])) {
420
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
417
+			$this->all_tracked[$id]['lastupdate'] = time();
418
+			if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
419
+				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'])) {
420
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
421 421
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
422
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
423
-				    $timeelapsed = microtime(true);
424
-				    $MarineLive = new MarineLive($this->db);
425
-				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
422
+					if ($globalDebug) echo "Check if vessel is already in DB...";
423
+					$timeelapsed = microtime(true);
424
+					$MarineLive = new MarineLive($this->db);
425
+					if (isset($line['id']) && isset($globalVM) && $globalVM) {
426 426
 					$Marine = new Marine($this->db);
427 427
 					$recent_ident = $Marine->checkId($line['id']);
428 428
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
429 429
 					$Marine->db=null;
430
-				    } elseif (isset($line['id'])) {
430
+					} elseif (isset($line['id'])) {
431 431
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
432 432
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
433
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
433
+					} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
434 434
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
435 435
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
436
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
436
+					} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
437 437
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
438 438
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
439
-				    } else $recent_ident = '';
440
-				    $MarineLive->db=null;
441
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
442
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
439
+					} else $recent_ident = '';
440
+					$MarineLive->db=null;
441
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
442
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
443 443
 				} else $recent_ident = '';
444
-			    } else {
444
+				} else {
445 445
 				$recent_ident = '';
446 446
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
447
-			    }
448
-			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
449
-			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
450
-			    {
447
+				}
448
+				//if there was no vessel with the same callsign within the last hour and go post it into the archive
449
+				if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
450
+				{
451 451
 				if ($globalDebug) {
452 452
 					if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
453 453
 					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
454 454
 				}
455 455
 				//adds the spotter data for the archive
456
-				    $highlight = '';
457
-				    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')));
458
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
456
+					$highlight = '';
457
+					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')));
458
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
459 459
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
460
-					    $timeelapsed = microtime(true);
461
-					    $Marine = new Marine($this->db);
462
-					    if (isset($globalVM) && $globalVM && $this->all_tracked[$id]['race_begin'] != '') {
460
+						$timeelapsed = microtime(true);
461
+						$Marine = new Marine($this->db);
462
+						if (isset($globalVM) && $globalVM && $this->all_tracked[$id]['race_begin'] != '') {
463 463
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
464
-					    } else {
464
+						} else {
465 465
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
466
-					    }
467
-					    $Marine->db = null;
468
-					    if ($globalDebug && isset($result)) echo $result."\n";
469
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
466
+						}
467
+						$Marine->db = null;
468
+						if ($globalDebug && isset($result)) echo $result."\n";
469
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
470
+					}
470 471
 					}
471
-				    }
472
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
472
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
473 473
 					// Add source stat in DB
474 474
 					$Stats = new Stats($this->db);
475 475
 					if (!empty($this->stats)) {
476
-					    if ($globalDebug) echo 'Add source stats : ';
477
-				    	    foreach($this->stats as $date => $data) {
476
+						if ($globalDebug) echo 'Add source stats : ';
477
+							foreach($this->stats as $date => $data) {
478 478
 						foreach($data as $source => $sourced) {
479
-					    	    //print_r($sourced);
480
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
481
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
482
-				    		    if (isset($sourced['msg'])) {
483
-				    			if (time() - $sourced['msg']['date'] > 10) {
484
-				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
485
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
486
-			    			    	    unset($this->stats[$date][$source]['msg']);
487
-			    				}
488
-			    			    }
489
-			    			}
490
-			    			if ($date != date('Y-m-d')) {
491
-			    			    unset($this->stats[$date]);
492
-			    			}
493
-				    	    }
494
-				    	    if ($globalDebug) echo 'Done'."\n";
479
+								//print_r($sourced);
480
+									if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
481
+									if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
482
+								if (isset($sourced['msg'])) {
483
+								if (time() - $sourced['msg']['date'] > 10) {
484
+										$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
485
+										echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
486
+										unset($this->stats[$date][$source]['msg']);
487
+								}
488
+								}
489
+							}
490
+							if ($date != date('Y-m-d')) {
491
+								unset($this->stats[$date]);
492
+							}
493
+							}
494
+							if ($globalDebug) echo 'Done'."\n";
495 495
 					}
496 496
 					$Stats->db = null;
497
-				    }
497
+					}
498 498
 				    
499
-				    $this->del();
499
+					$this->del();
500 500
 				//$ignoreImport = false;
501 501
 				$this->all_tracked[$id]['addedMarine'] = 1;
502 502
 				//print_r($this->all_tracked[$id]);
503 503
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
504
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
505
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
506
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
504
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
505
+					//MarineLive->deleteLiveMarineDataNotUpdated();
506
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
507 507
 					$MarineLive = new MarineLive($this->db);
508 508
 					$MarineLive->deleteLiveMarineData();
509 509
 					$MarineLive->db=null;
510 510
 					if ($globalDebug) echo " Done\n";
511
-				    }
512
-				    $this->last_delete = time();
511
+					}
512
+					$this->last_delete = time();
513 513
 				}
514
-			    } elseif ($recent_ident != '') {
514
+				} elseif ($recent_ident != '') {
515 515
 				$this->all_tracked[$id]['id'] = $recent_ident;
516 516
 				$this->all_tracked[$id]['addedMarine'] = 1;
517 517
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
518
-				    if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) {
518
+					if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) {
519 519
 					$Marine = new Marine($this->db);
520 520
 					if (isset($globalVM) && $globalVM) {
521
-					    if ($this->all_tracked[$id]['status'] == 'Racing') {
521
+						if ($this->all_tracked[$id]['status'] == 'Racing') {
522 522
 						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
523
-					    } else {
523
+						} else {
524 524
 						$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
525 525
 						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
526
-					    }
526
+						}
527 527
 					} else {
528
-					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
528
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
529 529
 					}
530 530
 					$Marine->db = null;
531
-				    }
531
+					}
532 532
 				}
533 533
 				
534
-			    }
534
+				}
535
+			}
535 536
 			}
536
-		    }
537
-		    //adds the spotter LIVE data
538
-		    if ($globalDebug) {
537
+			//adds the spotter LIVE data
538
+			if ($globalDebug) {
539 539
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
540
-		    }
541
-		    $ignoreImport = false;
542
-		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
543
-		    if (!$ignoreImport) {
540
+			}
541
+			$ignoreImport = false;
542
+			if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
543
+			if (!$ignoreImport) {
544 544
 			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'])) {
545 545
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
546 546
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
547
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
547
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
548 548
 					$timeelapsed = microtime(true);
549 549
 					$MarineLive = new MarineLive($this->db);
550 550
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
551 551
 					$MarineLive->db = null;
552 552
 					if ($globalDebug) echo $result."\n";
553 553
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
554
-				    }
554
+					}
555 555
 				}
556 556
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
557 557
 					$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']);
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 					if ($stats_heading == 16) $stats_heading = 0;
587 587
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
588 588
 						for ($i=0;$i<=15;$i++) {
589
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
589
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
590 590
 						}
591 591
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
592 592
 					} else {
@@ -599,11 +599,11 @@  discard block
 block discarded – undo
599 599
 					//var_dump($this->stats);
600 600
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
601 601
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
602
-						    end($this->stats[$current_date][$source]['hist']);
603
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
602
+							end($this->stats[$current_date][$source]['hist']);
603
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
604 604
 						} else $mini = 0;
605 605
 						for ($i=$mini;$i<=$distance;$i+=10) {
606
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
606
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
607 607
 						}
608 608
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
609 609
 					} else {
@@ -619,24 +619,24 @@  discard block
 block discarded – undo
619 619
 			
620 620
 			
621 621
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
622
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
622
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
623 623
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
624 624
 				$MarineLive = new MarineLive($this->db);
625 625
 				$MarineLive->deleteLiveMarineDataNotUpdated();
626 626
 				$MarineLive->db = null;
627 627
 				//MarineLive->deleteLiveMarineData();
628 628
 				if ($globalDebug) echo " Done\n";
629
-			    }
630
-			    $this->last_delete_hourly = time();
629
+				}
630
+				$this->last_delete_hourly = time();
631 631
 			}
632 632
 			
633
-		    }
634
-		    //$ignoreImport = false;
633
+			}
634
+			//$ignoreImport = false;
635 635
 		}
636 636
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
637 637
 		if ($send) return $this->all_tracked[$id];
638
-	    }
638
+		}
639
+	}
639 640
 	}
640
-    }
641 641
 }
642 642
 ?>
Please login to merge, or discard this patch.
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
     		    $Marine = new Marine($this->db);
62 62
     		    if (isset($globalVM) && $globalVM) {
63 63
 			if ($this->all_tracked[$key]['status'] == 'Racing') {
64
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
64
+    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
65 65
     			} else {
66
-    			    $finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
67
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
66
+    			    $finaldatetime = date('Y-m-d H:i:s', strtotime($this->all_tracked[$key]['race_begin']) + $this->all_tracked[$key]['race_time']);
67
+    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $finaldatetime, $this->all_tracked[$id]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
68 68
     			}
69 69
     		    } else {
70
-			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
70
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
71 71
 		    }
72 72
 		}
73 73
 	    }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
81 81
 	foreach ($this->all_tracked as $key => $flight) {
82 82
     	    if (isset($flight['lastupdate'])) {
83
-        	if ($flight['lastupdate'] < (time()-3000)) {
83
+        	if ($flight['lastupdate'] < (time() - 3000)) {
84 84
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
85 85
             		if (isset($this->all_tracked[$key]['id'])) {
86 86
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
95 95
 				if (isset($globalVM) && $globalVM) {
96 96
 				    if ($this->all_tracked[$key]['status'] == 'Racing') {
97
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
97
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
98 98
 				    } else {
99
-					$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
100
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
99
+					$finaldatetime = date('Y-m-d H:i:s', strtotime($this->all_tracked[$key]['race_begin']) + $this->all_tracked[$key]['race_time']);
100
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $finaldatetime, $this->all_tracked[$id]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
101 101
 				    }
102 102
 				} else {
103
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
103
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
104 104
 				}
105 105
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
106 106
 			    }
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
     }
116 116
 
117 117
     public function add($line) {
118
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM;
118
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine, $globalLiveInterval, $globalVM;
119 119
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
120 120
 	date_default_timezone_set('UTC');
121 121
 	$dataFound = false;
122 122
 	$send = false;
123 123
 	
124 124
 	// SBS format is CSV format
125
-	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
125
+	if (is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
126 126
 	    //print_r($line);
127 127
   	    if (isset($line['mmsi']) || isset($line['id'])) {
128 128
 
@@ -147,25 +147,25 @@  discard block
 block discarded – undo
147 147
 		
148 148
 		if (!isset($this->all_tracked[$id])) {
149 149
 		    $this->all_tracked[$id] = array();
150
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
151
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
152
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
150
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
151
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => '', 'captain_id' => '', 'captain_name' => '', 'race_id' => '', 'race_name' => '', 'distance' => NULL, 'race_rank' => NULL, 'race_time' => NULL, 'race_begin' => ''));
152
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
153 153
 		    if (!isset($line['id'])) {
154 154
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
155
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
156
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
155
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
156
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
157 157
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
158 158
 		}
159 159
 		
160 160
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
161
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
162 162
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
163 163
 			$Marine = new Marine($this->db);
164 164
 			$identity = $Marine->getIdentity($line['mmsi']);
165 165
 			if (!empty($identity)) {
166 166
 			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
167 167
 			    $this->all_tracked[$id]['type'] = $identity['type'];
168
-			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
168
+			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($identity['type'])));
169 169
 			}
170 170
 			//print_r($identity);
171 171
 			unset($Marine);
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 		    }
174 174
 		}
175 175
 		if (isset($line['type_id'])) {
176
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
177
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
176
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
177
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
178 178
 		}
179 179
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
180
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
181
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
180
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
181
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($line['type'])));
182 182
 		} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') {
183
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
183
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
184 184
 		}
185 185
 		if (isset($line['status']) && $line['status'] != '') {
186
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
186
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
187 187
 		}
188 188
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
189
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
189
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
190 190
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
191 191
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
192 192
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
193 193
 				$Marine = new Marine($this->db);
194
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
194
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
195 195
 				unset($Marine);
196 196
 			    }
197 197
 			}
@@ -200,24 +200,24 @@  discard block
 block discarded – undo
200 200
 
201 201
 
202 202
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
203
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
203
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
204 204
 		}
205 205
 		if (isset($line['imo']) && $line['imo'] != '') {
206
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
206
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
207 207
 		}
208 208
 		if (isset($line['callsign']) && $line['callsign'] != '') {
209
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
209
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
210 210
 		}
211 211
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
212 212
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
213
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
213
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
214 214
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
215 215
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
216 216
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
217 217
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
218 218
 				    $Marine = new Marine($this->db);
219 219
 				    $fromsource = NULL;
220
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
220
+				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource);
221 221
 				    $Marine->db = null;
222 222
 				}
223 223
 			    }
@@ -233,31 +233,31 @@  discard block
 block discarded – undo
233 233
 		    }
234 234
 		}
235 235
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
236
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
236
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
237 237
 		}
238 238
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
239
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_id' => $line['captain_id']));
240 240
 		}
241 241
 		if (isset($line['captain_name']) && $line['captain_name'] != '') {
242
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
242
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_name' => $line['captain_name']));
243 243
 		}
244 244
 		if (isset($line['race_id']) && $line['race_id'] != '') {
245
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
245
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_id' => $line['race_id']));
246 246
 		}
247 247
 		if (isset($line['race_name']) && $line['race_name'] != '') {
248
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
248
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_name' => $line['race_name']));
249 249
 		}
250 250
 		if (isset($line['race_rank']) && $line['race_rank'] != '') {
251
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
251
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_rank' => $line['race_rank']));
252 252
 		}
253 253
 		if (isset($line['race_time']) && $line['race_time'] != '') {
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
254
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_time' => $line['race_time']));
255 255
 		}
256 256
 		if (isset($line['race_begin']) && $line['race_begin'] != '') {
257
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
257
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_begin' => $line['race_begin']));
258 258
 		}
259 259
 		if (isset($line['distance']) && $line['distance'] != '') {
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
260
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('distance' => $line['distance']));
261 261
 		}
262 262
 
263 263
 		//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'])) {
@@ -266,44 +266,44 @@  discard block
 block discarded – undo
266 266
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
267 267
 			    $timeelapsed = microtime(true);
268 268
 			    $Marine = new Marine($this->db);
269
-			    $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']);
269
+			    $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']);
270 270
 			    $Marine->db = null;
271 271
 			}
272 272
 		    }
273
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
273
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
274 274
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
275 275
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
276 276
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
277 277
 				$timeelapsed = microtime(true);
278 278
 				$Marine = new Marine($this->db);
279 279
 				$fromsource = NULL;
280
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
280
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
281 281
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
282 282
 				$Marine->db = null;
283
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
283
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
284 284
 			    }
285 285
 			}
286 286
 		    }
287
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
287
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
288 288
 		}
289 289
 
290
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
290
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
291 291
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
292
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
292
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
293 293
 		    } else {
294 294
 				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";
295 295
 				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";
296 296
 				return '';
297 297
 		    }
298
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
298
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
299 299
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
300 300
 			return '';
301
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
301
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
302 302
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
303 303
 			return '';
304 304
 		} elseif (!isset($line['datetime'])) {
305 305
 			date_default_timezone_set('UTC');
306
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
306
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
307 307
 		} else {
308 308
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
309 309
 			return '';
@@ -311,20 +311,20 @@  discard block
 block discarded – undo
311 311
 
312 312
 
313 313
 		if (isset($line['speed'])) {
314
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
315
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
314
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'], 2)));
315
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
316 316
 		} 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'])) {
317
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
317
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
318 318
 		    if ($distance > 1000 && $distance < 10000) {
319 319
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
320 320
 			$speed = $speed*3.6;
321
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
321
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed, 2)));
322 322
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
323 323
 		    }
324 324
 		}
325 325
 
326 326
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
327
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
327
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
328 328
 	    	    else unset($timediff);
329 329
 	    	    if ($this->tmd > 5 ||
330 330
 	    		!isset($timediff) ||
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
 	    		    $timediff > 30 && 
334 334
 	    		    isset($this->all_tracked[$id]['latitude']) &&
335 335
 	    		    isset($this->all_tracked[$id]['longitude']) &&
336
-	    		    $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
336
+	    		    $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'))
337 337
 	    		)
338 338
 	    		) {
339 339
 			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'])) {
340
-			    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'])) {
340
+			    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'])) {
341 341
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
342 342
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
343 343
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
 				$timeelapsed = microtime(true);
347 347
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
348 348
 				    $Marine = new Marine($this->db);
349
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
349
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
350 350
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
351 351
 				    $Marine->db = null;
352
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
352
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
353 353
 				}
354 354
 				$this->tmd = 0;
355 355
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -358,55 +358,55 @@  discard block
 block discarded – undo
358 358
 
359 359
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
360 360
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
361
-				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') {
361
+				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') {
362 362
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
363 363
 				    $dataFound = true;
364 364
 				    $this->all_tracked[$id]['time_last_coord'] = time();
365 365
 				}
366
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
366
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
367 367
 			}
368 368
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
369 369
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
370 370
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
371
-				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') {
371
+				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') {
372 372
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
373 373
 				    $dataFound = true;
374 374
 				    $this->all_tracked[$id]['time_last_coord'] = time();
375 375
 				}
376
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
376
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
377 377
 			}
378 378
 
379 379
 		    } else if ($globalDebug && $timediff > 20) {
380 380
 			$this->tmd = $this->tmd + 1;
381 381
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
382
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
383
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
382
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
383
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
384 384
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
385 385
 		    }
386 386
 		}
387 387
 		if (isset($line['last_update']) && $line['last_update'] != '') {
388 388
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
389
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
389
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
390 390
 		}
391 391
 		if (isset($line['format_source']) && $line['format_source'] != '') {
392
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
392
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
393 393
 		}
394 394
 		if (isset($line['source_name']) && $line['source_name'] != '') {
395
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
395
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
396 396
 		}
397 397
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
398
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
398
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
399 399
 		}
400 400
 		
401 401
 		if (isset($line['heading']) && $line['heading'] != '') {
402
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
403
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
404
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
402
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
403
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
404
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
405 405
 		    //$dataFound = true;
406 406
   		} 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']) {
407
-  		    $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']);
408
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
409
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
407
+  		    $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']);
408
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
409
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
410 410
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
411 411
   		}
412 412
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
417 417
 		    $this->all_tracked[$id]['lastupdate'] = time();
418 418
 		    if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
419
-		        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'])) {
419
+		        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'])) {
420 420
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
421 421
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
422 422
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -425,28 +425,28 @@  discard block
 block discarded – undo
425 425
 				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
426 426
 					$Marine = new Marine($this->db);
427 427
 					$recent_ident = $Marine->checkId($line['id']);
428
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
429
-					$Marine->db=null;
428
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
429
+					$Marine->db = null;
430 430
 				    } elseif (isset($line['id'])) {
431 431
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
432
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
432
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
433 433
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
434 434
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
435
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
435
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
436 436
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
437 437
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
438
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
438
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
439 439
 				    } else $recent_ident = '';
440
-				    $MarineLive->db=null;
440
+				    $MarineLive->db = null;
441 441
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
442 442
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
443 443
 				} else $recent_ident = '';
444 444
 			    } else {
445 445
 				$recent_ident = '';
446
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
446
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
447 447
 			    }
448 448
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
449
-			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
449
+			    if ($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
450 450
 			    {
451 451
 				if ($globalDebug) {
452 452
 					if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
 				}
455 455
 				//adds the spotter data for the archive
456 456
 				    $highlight = '';
457
-				    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')));
457
+				    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')));
458 458
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
459 459
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
460 460
 					    $timeelapsed = microtime(true);
461 461
 					    $Marine = new Marine($this->db);
462 462
 					    if (isset($globalVM) && $globalVM && $this->all_tracked[$id]['race_begin'] != '') {
463
-						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
463
+						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
464 464
 					    } else {
465
-						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
465
+						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
466 466
 					    }
467 467
 					    $Marine->db = null;
468 468
 					    if ($globalDebug && isset($result)) echo $result."\n";
469
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
469
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
470 470
 					}
471 471
 				    }
472 472
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
 					$Stats = new Stats($this->db);
475 475
 					if (!empty($this->stats)) {
476 476
 					    if ($globalDebug) echo 'Add source stats : ';
477
-				    	    foreach($this->stats as $date => $data) {
478
-						foreach($data as $source => $sourced) {
477
+				    	    foreach ($this->stats as $date => $data) {
478
+						foreach ($data as $source => $sourced) {
479 479
 					    	    //print_r($sourced);
480
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
481
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
480
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
481
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
482 482
 				    		    if (isset($sourced['msg'])) {
483 483
 				    			if (time() - $sourced['msg']['date'] > 10) {
484 484
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
485
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
485
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
486 486
 			    			    	    unset($this->stats[$date][$source]['msg']);
487 487
 			    				}
488 488
 			    			    }
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
507 507
 					$MarineLive = new MarineLive($this->db);
508 508
 					$MarineLive->deleteLiveMarineData();
509
-					$MarineLive->db=null;
509
+					$MarineLive->db = null;
510 510
 					if ($globalDebug) echo " Done\n";
511 511
 				    }
512 512
 				    $this->last_delete = time();
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 					$Marine = new Marine($this->db);
520 520
 					if (isset($globalVM) && $globalVM) {
521 521
 					    if ($this->all_tracked[$id]['status'] == 'Racing') {
522
-						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
522
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
523 523
 					    } else {
524
-						$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
525
-						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
524
+						$finaldatetime = date('Y-m-d H:i:s', strtotime($this->all_tracked[$id]['race_begin']) + $this->all_tracked[$id]['race_time']);
525
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $finaldatetime, $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
526 526
 					    }
527 527
 					} else {
528
-					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
528
+					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
529 529
 					}
530 530
 					$Marine->db = null;
531 531
 				    }
@@ -541,20 +541,20 @@  discard block
 block discarded – undo
541 541
 		    $ignoreImport = false;
542 542
 		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
543 543
 		    if (!$ignoreImport) {
544
-			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'])) {
544
+			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'])) {
545 545
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
546 546
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
547 547
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
548 548
 					$timeelapsed = microtime(true);
549 549
 					$MarineLive = new MarineLive($this->db);
550
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
550
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
551 551
 					$MarineLive->db = null;
552 552
 					if ($globalDebug) echo $result."\n";
553
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
553
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
554 554
 				    }
555 555
 				}
556 556
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
557
-					$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']);
557
+					$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']);
558 558
 				}
559 559
 				$this->all_tracked[$id]['putinarchive'] = false;
560 560
 
@@ -573,19 +573,19 @@  discard block
 block discarded – undo
573 573
 							$latitude = $globalCenterLatitude;
574 574
 							$longitude = $globalCenterLongitude;
575 575
 						}
576
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
576
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
577 577
 					} else {
578 578
 						$latitude = $this->source_location[$source]['latitude'];
579 579
 						$longitude = $this->source_location[$source]['longitude'];
580 580
 					}
581
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
581
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
582 582
 					//$stats_heading = $stats_heading%22.5;
583 583
 					$stats_heading = round($stats_heading/22.5);
584
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
584
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
585 585
 					$current_date = date('Y-m-d');
586 586
 					if ($stats_heading == 16) $stats_heading = 0;
587 587
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
588
-						for ($i=0;$i<=15;$i++) {
588
+						for ($i = 0; $i <= 15; $i++) {
589 589
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
590 590
 						}
591 591
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
601 601
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
602 602
 						    end($this->stats[$current_date][$source]['hist']);
603
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
603
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
604 604
 						} else $mini = 0;
605
-						for ($i=$mini;$i<=$distance;$i+=10) {
605
+						for ($i = $mini; $i <= $distance; $i += 10) {
606 606
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
607 607
 						}
608 608
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 
615 615
 				$this->all_tracked[$id]['lastupdate'] = time();
616 616
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
617
-			} 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";
617
+			} 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";
618 618
 			//$this->del();
619 619
 			
620 620
 			
Please login to merge, or discard this patch.
Braces   +210 added lines, -72 removed lines patch added patch discarded remove patch
@@ -54,7 +54,9 @@  discard block
 block discarded – undo
54 54
     public function checkAll() {
55 55
 	global $globalDebug, $globalNoDB;
56 56
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
57
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
57
+	    if ($globalDebug) {
58
+	    	echo "Update last seen tracked data...\n";
59
+	    }
58 60
 	    foreach ($this->all_tracked as $key => $flight) {
59 61
 		if (isset($this->all_tracked[$key]['id'])) {
60 62
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -77,13 +79,17 @@  discard block
 block discarded – undo
77 79
     public function del() {
78 80
 	global $globalDebug, $globalNoDB, $globalNoImport;
79 81
 	// Delete old infos
80
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
82
+	if ($globalDebug) {
83
+		echo 'Delete old values and update latest data...'."\n";
84
+	}
81 85
 	foreach ($this->all_tracked as $key => $flight) {
82 86
     	    if (isset($flight['lastupdate'])) {
83 87
         	if ($flight['lastupdate'] < (time()-3000)) {
84 88
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
85 89
             		if (isset($this->all_tracked[$key]['id'])) {
86
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
90
+            		    if ($globalDebug) {
91
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
92
+            		    }
87 93
 			    /*
88 94
 			    $MarineLive = new MarineLive();
89 95
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -102,7 +108,9 @@  discard block
 block discarded – undo
102 108
 				} else {
103 109
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
104 110
 				}
105
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
111
+				if ($globalDebug && $result != 'success') {
112
+					echo '!!! ERROR : '.$result."\n";
113
+				}
106 114
 			    }
107 115
 			    // Put in archive
108 116
 //				$Marine->db = null;
@@ -116,7 +124,9 @@  discard block
 block discarded – undo
116 124
 
117 125
     public function add($line) {
118 126
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM;
119
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
127
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
128
+		$globalCoordMinChange = '0.02';
129
+	}
120 130
 	date_default_timezone_set('UTC');
121 131
 	$dataFound = false;
122 132
 	$send = false;
@@ -130,20 +140,30 @@  discard block
 block discarded – undo
130 140
 		// Increment message number
131 141
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
132 142
 		    $current_date = date('Y-m-d');
133
-		    if (isset($line['source_name'])) $source = $line['source_name'];
134
-		    else $source = '';
135
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
143
+		    if (isset($line['source_name'])) {
144
+		    	$source = $line['source_name'];
145
+		    } else {
146
+		    	$source = '';
147
+		    }
148
+		    if ($source == '' || $line['format_source'] == 'aprs') {
149
+		    	$source = $line['format_source'];
150
+		    }
136 151
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
137 152
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
138 153
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
139
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
154
+		    } else {
155
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
156
+		    }
140 157
 		}
141 158
 		
142 159
 		
143 160
 		$Common = new Common();
144 161
 		$AIS = new AIS();
145
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
146
-	        else $id = trim($line['id']);
162
+	        if (!isset($line['id'])) {
163
+	        	$id = trim($line['mmsi']);
164
+	        } else {
165
+	        	$id = trim($line['id']);
166
+	        }
147 167
 		
148 168
 		if (!isset($this->all_tracked[$id])) {
149 169
 		    $this->all_tracked[$id] = array();
@@ -151,10 +171,16 @@  discard block
 block discarded – undo
151 171
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
152 172
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
153 173
 		    if (!isset($line['id'])) {
154
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
174
+			if (!isset($globalDaemon)) {
175
+				$globalDaemon = TRUE;
176
+			}
155 177
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
156
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
157
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
178
+		     } else {
179
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
180
+		     }
181
+		    if ($globalAllTracked !== FALSE) {
182
+		    	$dataFound = true;
183
+		    }
158 184
 		}
159 185
 		
160 186
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -211,7 +237,9 @@  discard block
 block discarded – undo
211 237
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
212 238
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
213 239
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
214
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
240
+			if ($globalDebug) {
241
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
242
+			}
215 243
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
216 244
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
217 245
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -224,7 +252,9 @@  discard block
 block discarded – undo
224 252
 			}
225 253
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
226 254
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
227
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
255
+			if ($globalDebug) {
256
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
257
+			}
228 258
 			if (!isset($line['id'])) {
229 259
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
230 260
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -233,7 +263,9 @@  discard block
 block discarded – undo
233 263
 		    }
234 264
 		}
235 265
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
236
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
266
+		    if (strtotime($line['arrival_date']) > time()) {
267
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
268
+		    }
237 269
 		}
238 270
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
239 271
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
@@ -278,34 +310,49 @@  discard block
 block discarded – undo
278 310
 				$Marine = new Marine($this->db);
279 311
 				$fromsource = NULL;
280 312
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
281
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
313
+				if ($globalDebug && $result != 'success') {
314
+					echo '!!! ERROR : '.$result."\n";
315
+				}
282 316
 				$Marine->db = null;
283
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
317
+				if ($globalDebugTimeElapsed) {
318
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
319
+				}
284 320
 			    }
285 321
 			}
286 322
 		    }
287
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
323
+		    if (!isset($this->all_tracked[$id]['id'])) {
324
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
325
+		    }
288 326
 		}
289 327
 
290 328
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
291 329
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
292 330
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
293 331
 		    } else {
294
-				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";
295
-				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";
332
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
333
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
334
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
335
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
336
+				}
296 337
 				return '';
297 338
 		    }
298 339
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
299
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
340
+			if ($globalDebug) {
341
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
342
+			}
300 343
 			return '';
301 344
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
302
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
345
+			if ($globalDebug) {
346
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
347
+			}
303 348
 			return '';
304 349
 		} elseif (!isset($line['datetime'])) {
305 350
 			date_default_timezone_set('UTC');
306 351
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
307 352
 		} else {
308
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
353
+			if ($globalDebug) {
354
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
355
+			}
309 356
 			return '';
310 357
 		}
311 358
 
@@ -318,14 +365,21 @@  discard block
 block discarded – undo
318 365
 		    if ($distance > 1000 && $distance < 10000) {
319 366
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
320 367
 			$speed = $speed*3.6;
321
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
322
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
368
+			if ($speed < 1000) {
369
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
370
+			}
371
+  			if ($globalDebug) {
372
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
373
+  			}
323 374
 		    }
324 375
 		}
325 376
 
326 377
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
327
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
328
-	    	    else unset($timediff);
378
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
379
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
380
+	    	    } else {
381
+	    	    	unset($timediff);
382
+	    	    }
329 383
 	    	    if ($this->tmd > 5 ||
330 384
 	    		!isset($timediff) ||
331 385
 	    		$timediff > $globalLiveInterval ||
@@ -342,22 +396,32 @@  discard block
 block discarded – undo
342 396
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
343 397
 				$this->all_tracked[$id]['putinarchive'] = true;
344 398
 				
345
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
399
+				if ($globalDebug) {
400
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
401
+				}
346 402
 				$timeelapsed = microtime(true);
347 403
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
348 404
 				    $Marine = new Marine($this->db);
349 405
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
350
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
406
+				    if (!empty($all_country)) {
407
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
408
+				    }
351 409
 				    $Marine->db = null;
352
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
410
+				    if ($globalDebugTimeElapsed) {
411
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
412
+				    }
353 413
 				}
354 414
 				$this->tmd = 0;
355
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
415
+				if ($globalDebug) {
416
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
417
+				}
356 418
 			    }
357 419
 			}
358 420
 
359 421
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
360
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
422
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
423
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
424
+				}
361 425
 				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') {
362 426
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
363 427
 				    $dataFound = true;
@@ -366,8 +430,12 @@  discard block
 block discarded – undo
366 430
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
367 431
 			}
368 432
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
369
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
370
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
433
+			    if ($line['longitude'] > 180) {
434
+			    	$line['longitude'] = $line['longitude'] - 360;
435
+			    }
436
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
437
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
438
+				}
371 439
 				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') {
372 440
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
373 441
 				    $dataFound = true;
@@ -385,7 +453,9 @@  discard block
 block discarded – undo
385 453
 		    }
386 454
 		}
387 455
 		if (isset($line['last_update']) && $line['last_update'] != '') {
388
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
456
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
457
+		    	$dataFound = true;
458
+		    }
389 459
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
390 460
 		}
391 461
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -399,15 +469,21 @@  discard block
 block discarded – undo
399 469
 		}
400 470
 		
401 471
 		if (isset($line['heading']) && $line['heading'] != '') {
402
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
472
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
473
+		    	$this->all_tracked[$id]['putinarchive'] = true;
474
+		    }
403 475
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
404 476
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
405 477
 		    //$dataFound = true;
406 478
   		} 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']) {
407 479
   		    $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']);
408 480
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
409
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
410
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
481
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
482
+		    	$this->all_tracked[$id]['putinarchive'] = true;
483
+		    }
484
+  		    if ($globalDebug) {
485
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
486
+  		    }
411 487
   		}
412 488
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
413 489
 
@@ -419,28 +495,45 @@  discard block
 block discarded – undo
419 495
 		        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'])) {
420 496
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
421 497
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
422
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
498
+				    if ($globalDebug) {
499
+				    	echo "Check if vessel is already in DB...";
500
+				    }
423 501
 				    $timeelapsed = microtime(true);
424 502
 				    $MarineLive = new MarineLive($this->db);
425 503
 				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
426 504
 					$Marine = new Marine($this->db);
427 505
 					$recent_ident = $Marine->checkId($line['id']);
428
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
506
+					if ($globalDebugTimeElapsed) {
507
+						echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
508
+					}
429 509
 					$Marine->db=null;
430 510
 				    } elseif (isset($line['id'])) {
431 511
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
432
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
512
+					if ($globalDebugTimeElapsed) {
513
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
514
+					}
433 515
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
434 516
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
435
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
517
+					if ($globalDebugTimeElapsed) {
518
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
519
+					}
436 520
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
437 521
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
438
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
439
-				    } else $recent_ident = '';
522
+					if ($globalDebugTimeElapsed) {
523
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
524
+					}
525
+				    } else {
526
+				    	$recent_ident = '';
527
+				    }
440 528
 				    $MarineLive->db=null;
441
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
442
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
443
-				} else $recent_ident = '';
529
+				    if ($globalDebug && $recent_ident == '') {
530
+				    	echo " Not in DB.\n";
531
+				    } elseif ($globalDebug && $recent_ident != '') {
532
+				    	echo " Already in DB.\n";
533
+				    }
534
+				} else {
535
+					$recent_ident = '';
536
+				}
444 537
 			    } else {
445 538
 				$recent_ident = '';
446 539
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -449,12 +542,17 @@  discard block
 block discarded – undo
449 542
 			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
450 543
 			    {
451 544
 				if ($globalDebug) {
452
-					if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
453
-					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
545
+					if ($this->all_tracked[$id]['mmsi'] == '') {
546
+						echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
547
+					} else {
548
+						echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
549
+					}
454 550
 				}
455 551
 				//adds the spotter data for the archive
456 552
 				    $highlight = '';
457
-				    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')));
553
+				    if (!isset($this->all_tracked[$id]['id'])) {
554
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
555
+				    }
458 556
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
459 557
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
460 558
 					    $timeelapsed = microtime(true);
@@ -465,20 +563,30 @@  discard block
 block discarded – undo
465 563
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
466 564
 					    }
467 565
 					    $Marine->db = null;
468
-					    if ($globalDebug && isset($result)) echo $result."\n";
469
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+					    if ($globalDebug && isset($result)) {
567
+					    	echo $result."\n";
568
+					    }
569
+					    if ($globalDebugTimeElapsed) {
570
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
571
+					    }
470 572
 					}
471 573
 				    }
472 574
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
473 575
 					// Add source stat in DB
474 576
 					$Stats = new Stats($this->db);
475 577
 					if (!empty($this->stats)) {
476
-					    if ($globalDebug) echo 'Add source stats : ';
578
+					    if ($globalDebug) {
579
+					    	echo 'Add source stats : ';
580
+					    }
477 581
 				    	    foreach($this->stats as $date => $data) {
478 582
 						foreach($data as $source => $sourced) {
479 583
 					    	    //print_r($sourced);
480
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
481
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
584
+				    	    	    if (isset($sourced['polar'])) {
585
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
586
+				    	    	    }
587
+				    	    	    if (isset($sourced['hist'])) {
588
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
589
+				    	    	    }
482 590
 				    		    if (isset($sourced['msg'])) {
483 591
 				    			if (time() - $sourced['msg']['date'] > 10) {
484 592
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -491,7 +599,9 @@  discard block
 block discarded – undo
491 599
 			    			    unset($this->stats[$date]);
492 600
 			    			}
493 601
 				    	    }
494
-				    	    if ($globalDebug) echo 'Done'."\n";
602
+				    	    if ($globalDebug) {
603
+				    	    	echo 'Done'."\n";
604
+				    	    }
495 605
 					}
496 606
 					$Stats->db = null;
497 607
 				    }
@@ -501,13 +611,17 @@  discard block
 block discarded – undo
501 611
 				$this->all_tracked[$id]['addedMarine'] = 1;
502 612
 				//print_r($this->all_tracked[$id]);
503 613
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
504
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
614
+				    if ($globalDebug) {
615
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
616
+				    }
505 617
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
506 618
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
507 619
 					$MarineLive = new MarineLive($this->db);
508 620
 					$MarineLive->deleteLiveMarineData();
509 621
 					$MarineLive->db=null;
510
-					if ($globalDebug) echo " Done\n";
622
+					if ($globalDebug) {
623
+						echo " Done\n";
624
+					}
511 625
 				    }
512 626
 				    $this->last_delete = time();
513 627
 				}
@@ -539,18 +653,26 @@  discard block
 block discarded – undo
539 653
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
540 654
 		    }
541 655
 		    $ignoreImport = false;
542
-		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
656
+		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') {
657
+		    	$ignoreImport = true;
658
+		    }
543 659
 		    if (!$ignoreImport) {
544 660
 			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'])) {
545
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
661
+				if ($globalDebug) {
662
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
663
+				}
546 664
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
547 665
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
548 666
 					$timeelapsed = microtime(true);
549 667
 					$MarineLive = new MarineLive($this->db);
550 668
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
551 669
 					$MarineLive->db = null;
552
-					if ($globalDebug) echo $result."\n";
553
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
670
+					if ($globalDebug) {
671
+						echo $result."\n";
672
+					}
673
+					if ($globalDebugTimeElapsed) {
674
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
675
+					}
554 676
 				    }
555 677
 				}
556 678
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -562,7 +684,9 @@  discard block
 block discarded – undo
562 684
 				
563 685
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
564 686
 					$source = $this->all_tracked[$id]['source_name'];
565
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
687
+					if ($source == '') {
688
+						$source = $this->all_tracked[$id]['format_source'];
689
+					}
566 690
 					if (!isset($this->source_location[$source])) {
567 691
 						$Location = new Source($this->db);
568 692
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -583,7 +707,9 @@  discard block
 block discarded – undo
583 707
 					$stats_heading = round($stats_heading/22.5);
584 708
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
585 709
 					$current_date = date('Y-m-d');
586
-					if ($stats_heading == 16) $stats_heading = 0;
710
+					if ($stats_heading == 16) {
711
+						$stats_heading = 0;
712
+					}
587 713
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
588 714
 						for ($i=0;$i<=15;$i++) {
589 715
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -601,7 +727,9 @@  discard block
 block discarded – undo
601 727
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
602 728
 						    end($this->stats[$current_date][$source]['hist']);
603 729
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
604
-						} else $mini = 0;
730
+						} else {
731
+							$mini = 0;
732
+						}
605 733
 						for ($i=$mini;$i<=$distance;$i+=10) {
606 734
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
607 735
 						}
@@ -613,19 +741,27 @@  discard block
 block discarded – undo
613 741
 				
614 742
 
615 743
 				$this->all_tracked[$id]['lastupdate'] = time();
616
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
617
-			} 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";
744
+				if ($this->all_tracked[$id]['putinarchive']) {
745
+					$send = true;
746
+				}
747
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
748
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
749
+			}
618 750
 			//$this->del();
619 751
 			
620 752
 			
621 753
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
622 754
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
623
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
755
+				if ($globalDebug) {
756
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
757
+				}
624 758
 				$MarineLive = new MarineLive($this->db);
625 759
 				$MarineLive->deleteLiveMarineDataNotUpdated();
626 760
 				$MarineLive->db = null;
627 761
 				//MarineLive->deleteLiveMarineData();
628
-				if ($globalDebug) echo " Done\n";
762
+				if ($globalDebug) {
763
+					echo " Done\n";
764
+				}
629 765
 			    }
630 766
 			    $this->last_delete_hourly = time();
631 767
 			}
@@ -634,7 +770,9 @@  discard block
 block discarded – undo
634 770
 		    //$ignoreImport = false;
635 771
 		}
636 772
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
637
-		if ($send) return $this->all_tracked[$id];
773
+		if ($send) {
774
+			return $this->all_tracked[$id];
775
+		}
638 776
 	    }
639 777
 	}
640 778
     }
Please login to merge, or discard this patch.