Completed
Push — master ( 3a8aa2...f2121d )
by Yannick
31:04
created
require/class.MarineLive.php 1 patch
Braces   +113 added lines, -38 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.');
11
+		if ($this->db === null) {
12
+			die('Error: No DB connection.');
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) {
@@ -77,8 +81,11 @@  discard block
 block discarded – undo
77 81
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
78 82
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
79 83
 		}
80
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
81
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
84
+		if ($filter_query_where == '' && $where) {
85
+			$filter_query_where = ' WHERE';
86
+		} elseif ($filter_query_where != '' && $and) {
87
+			$filter_query_where .= ' AND';
88
+		}
82 89
 		if ($filter_query_where != '') {
83 90
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
84 91
 		}
@@ -119,9 +126,13 @@  discard block
 block discarded – undo
119 126
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
120 127
 			}
121 128
 		}
122
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
129
+		if ($orderby_query == '') {
130
+			$orderby_query= ' ORDER BY date DESC';
131
+		}
123 132
 
124
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
133
+		if (!isset($globalLiveInterval)) {
134
+			$globalLiveInterval = '200';
135
+		}
125 136
 		if ($globalDBdriver == 'mysql') {
126 137
 			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
127 138
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -146,7 +157,9 @@  discard block
 block discarded – undo
146 157
 
147 158
 		$filter_query = $this->getFilter($filter,true,true);
148 159
 
149
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
160
+		if (!isset($globalLiveInterval)) {
161
+			$globalLiveInterval = '200';
162
+		}
150 163
 		if ($globalDBdriver == 'mysql') {
151 164
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
152 165
 			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0";
@@ -187,48 +200,72 @@  discard block
 block discarded – undo
187 200
 		}
188 201
 		$filter_query = $this->getFilter($filter,true,true);
189 202
 
190
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
191
-		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
203
+		if (!isset($globalLiveInterval)) {
204
+			$globalLiveInterval = '200';
205
+		}
206
+		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') {
207
+			$globalMap3DMarinesLimit = '300';
208
+		}
192 209
 		if ($globalDBdriver == 'mysql') {
193 210
 			if (isset($globalArchive) && $globalArchive === TRUE) {
194 211
 				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source 
195 212
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date) l ON l.flightaware_id = marine_archive.flightaware_id ";
196
-				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
213
+				if ($usecoord) {
214
+					$query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
215
+				}
197 216
 				$query .= "UNION
198 217
 				    SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
199 218
 				    FROM marine_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date";
200
-				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
219
+				if ($usecoord) {
220
+					$query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
221
+				}
201 222
 				$query .= ") AS marine 
202 223
 				    WHERE latitude <> '0' AND longitude <> '0' 
203 224
 				    ORDER BY fammarine_id, date";
204
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
225
+				if ($limit) {
226
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
227
+				}
205 228
 			} else {
206 229
 				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
207 230
 				    FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date ";
208
-				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
231
+				if ($usecoord) {
232
+					$query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
233
+				}
209 234
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
210 235
 				ORDER BY marine_live.fammarine_id, marine_live.date";
211
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
236
+				if ($limit) {
237
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
238
+				}
212 239
 			}
213 240
 		} else {
214 241
 			if (isset($globalArchive) && $globalArchive === TRUE) {
215 242
 				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source 
216 243
 				    FROM marine_archive INNER JOIN (SELECT flightaware_id FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date) l ON l.flightaware_id = marine_archive.flightaware_id ";
217
-				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
244
+				if ($usecoord) {
245
+					$query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
246
+				}
218 247
 				$query .= "UNION
219 248
 				    SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
220 249
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date";
221
-				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
250
+				if ($usecoord) {
251
+					$query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
252
+				}
222 253
 				$query .= ") AS marine WHERE latitude <> '0' AND longitude <> '0' ";
223 254
 				$query .= "ORDER BY fammarine_id, date";
224
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
255
+				if ($limit) {
256
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
257
+				}
225 258
 			} else {
226 259
 				$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
227 260
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date ";
228
-				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
261
+				if ($usecoord) {
262
+					$query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
263
+				}
229 264
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
230 265
 				ORDER BY marine_live.fammarine_id, marine_live.date";
231
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
266
+				if ($limit) {
267
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
268
+				}
232 269
 			}
233 270
 		}
234 271
 		try {
@@ -253,7 +290,9 @@  discard block
 block discarded – undo
253 290
 		global $globalDBdriver, $globalLiveInterval;
254 291
 		$filter_query = $this->getFilter($filter,true,true);
255 292
 
256
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
293
+		if (!isset($globalLiveInterval)) {
294
+			$globalLiveInterval = '200';
295
+		}
257 296
 		if ($globalDBdriver == 'mysql') {
258 297
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
259 298
 		} else {
@@ -281,7 +320,9 @@  discard block
 block discarded – undo
281 320
 	{
282 321
 		global $globalDBdriver, $globalLiveInterval;
283 322
 		$Marine = new Marine($this->db);
284
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
323
+		if (!isset($globalLiveInterval)) {
324
+			$globalLiveInterval = '200';
325
+		}
285 326
 		$filter_query = $this->getFilter($filter);
286 327
 
287 328
 		if (is_array($coord)) {
@@ -289,7 +330,9 @@  discard block
 block discarded – undo
289 330
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
290 331
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
291 332
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
292
-		} else return array();
333
+		} else {
334
+			return array();
335
+		}
293 336
 		if ($globalDBdriver == 'mysql') {
294 337
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
295 338
 		} else {
@@ -309,7 +352,9 @@  discard block
 block discarded – undo
309 352
 	{
310 353
 		global $globalDBdriver, $globalLiveInterval;
311 354
 		$Marine = new Marine($this->db);
312
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
355
+		if (!isset($globalLiveInterval)) {
356
+			$globalLiveInterval = '200';
357
+		}
313 358
 		$filter_query = $this->getFilter($filter);
314 359
 
315 360
 		if (is_array($coord)) {
@@ -317,7 +362,9 @@  discard block
 block discarded – undo
317 362
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
318 363
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
319 364
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
320
-		} else return array();
365
+		} else {
366
+			return array();
367
+		}
321 368
 		/*
322 369
 		if ($globalDBdriver == 'mysql') {
323 370
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
@@ -526,11 +573,15 @@  discard block
 block discarded – undo
526 573
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
527 574
 		if ($globalDBdriver == 'mysql') {
528 575
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
529
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
576
+			if ($liveinterval) {
577
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
578
+			}
530 579
 			$query .= ' ORDER BY date';
531 580
 		} else {
532 581
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
533
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
582
+			if ($liveinterval) {
583
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
584
+			}
534 585
 			$query .= ' ORDER BY date';
535 586
 		}
536 587
 
@@ -625,7 +676,9 @@  discard block
 block discarded – undo
625 676
 				$i++;
626 677
 				$j++;
627 678
 				if ($j == 30) {
628
-					if ($globalDebug) echo ".";
679
+					if ($globalDebug) {
680
+						echo ".";
681
+					}
629 682
 				    	try {
630 683
 						
631 684
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -905,7 +958,9 @@  discard block
 block discarded – undo
905 958
 			{
906 959
 				return false;
907 960
 			}
908
-		} else return '';
961
+		} else {
962
+			return '';
963
+		}
909 964
 
910 965
 		if ($longitude != '')
911 966
 		{
@@ -913,7 +968,9 @@  discard block
 block discarded – undo
913 968
 			{
914 969
 				return false;
915 970
 			}
916
-		} else return '';
971
+		} else {
972
+			return '';
973
+		}
917 974
 
918 975
 
919 976
 		if ($heading != '')
@@ -922,7 +979,9 @@  discard block
 block discarded – undo
922 979
 			{
923 980
 				return false;
924 981
 			}
925
-		} else $heading = 0;
982
+		} else {
983
+			$heading = 0;
984
+		}
926 985
 
927 986
 		if ($groundspeed != '')
928 987
 		{
@@ -930,9 +989,13 @@  discard block
 block discarded – undo
930 989
 			{
931 990
 				return false;
932 991
 			}
933
-		} else $groundspeed = 0;
992
+		} else {
993
+			$groundspeed = 0;
994
+		}
934 995
 		date_default_timezone_set('UTC');
935
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
996
+		if ($date == '') {
997
+			$date = date("Y-m-d H:i:s", time());
998
+		}
936 999
 
937 1000
         
938 1001
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -953,12 +1016,20 @@  discard block
 block discarded – undo
953 1016
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
954 1017
 		
955 1018
 
956
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
957
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
958
-            	if ($arrival_date == '') $arrival_date = NULL;
1019
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1020
+            		$groundspeed = 0;
1021
+            	}
1022
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1023
+            		$heading = 0;
1024
+            	}
1025
+            	if ($arrival_date == '') {
1026
+            		$arrival_date = NULL;
1027
+            	}
959 1028
             	$query = '';
960 1029
 		if ($globalArchive) {
961
-			if ($globalDebug) echo '-- Delete previous data -- ';
1030
+			if ($globalDebug) {
1031
+				echo '-- Delete previous data -- ';
1032
+			}
962 1033
 			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
963 1034
 		}
964 1035
 		$query .= 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
@@ -974,10 +1045,14 @@  discard block
 block discarded – undo
974 1045
 		}
975 1046
 		
976 1047
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
977
-			if ($globalDebug) echo '(Add to Marine archive : ';
1048
+			if ($globalDebug) {
1049
+				echo '(Add to Marine archive : ';
1050
+			}
978 1051
 			$MarineArchive = new MarineArchive($this->db);
979 1052
 			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source, $source_name, $over_country);
980
-			if ($globalDebug) echo $result.')';
1053
+			if ($globalDebug) {
1054
+				echo $result.')';
1055
+			}
981 1056
 		}
982 1057
 		return "success";
983 1058
 	}
Please login to merge, or discard this patch.