Completed
Push — master ( 7303c2...e8d7a9 )
by Yannick
29:27
created

Marine   D

Complexity

Total Complexity 406

Size/Duplication

Total Lines 2409
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 2409
rs 4.4102
c 0
b 0
f 0
wmc 406
lcom 1
cbo 5

52 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
F getFilter() 0 69 34
F getDataFromDB() 0 134 60
B getLatestMarineData() 0 27 5
A getMarineDataByID() 0 12 2
C getMarineDataByIdent() 0 49 7
B getMarineDataByType() 0 46 6
B getMarineDataByDate() 0 56 9
B getMarineDataByCaptain() 0 36 6
C getMarineDataByRace() 0 40 7
A countRacesByCaptain() 0 13 1
A countCaptainsByRace() 0 13 1
C countAllBoatTypesByCaptain() 0 42 7
C countAllBoatTypesByRace() 0 42 7
C getRaceDurationByCaptain() 0 43 8
A getAllCaptainNames() 0 11 1
A getAllRaceNames() 0 11 1
B getAllSourceName() 0 26 4
A getAllIdents() 0 21 2
A getIdentity() 0 10 2
B addIdentity() 0 20 5
B getAllDates() 0 36 4
A updateIdentMarineData() 0 12 2
A updateArrivalPortNameMarineData() 0 12 2
A updateStatusMarineData() 0 16 2
B updateLatestMarineData() 0 23 5
F addMarineData() 0 130 30
B getIdentFromLastHour() 0 27 3
B getRealTimeData() 0 32 5
C countAllMarineOverCountries() 0 67 14
F countAllCallsigns() 0 63 13
B countAllDates() 0 42 4
B countAllDatesLast7Days() 0 39 4
B countAllDatesLastMonth() 0 39 4
B countAllMonths() 0 39 4
B countAllMonthsLastYear() 0 40 4
B countAllHours() 0 58 6
B countAllHoursByDate() 0 39 4
B countAllHoursByIdent() 0 40 4
B countOverallMarine() 0 32 6
B countOverallMarineTypes() 0 31 6
B countAllHoursFromToday() 0 37 4
A getMarineIDBasedOnFamMarineID() 0 17 2
B parseDateString() 0 30 2
C parseDirection() 0 75 35
B getCountryFromLatitudeLongitude() 0 34 6
B getCountryFromISO2() 0 25 6
A getBitlyURL() 0 23 3
F countAllMarineTypes() 0 63 13
F searchMarineData() 0 126 29
A checkId() 0 14 2
A getOrderBy() 0 7 1

How to fix   Complexity   

Complex Class

Complex classes like Marine often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Marine, and based on these observations, apply Extract Interface, too.

1
<?php
2
require_once(dirname(__FILE__).'/class.Image.php');
3
$global_marine_query = "SELECT marine_output.* FROM marine_output";
4
5
class Marine{
6
	public $db;
7
	
8
	public function __construct($dbc = null) {
9
		$Connection = new Connection($dbc);
10
		$this->db = $Connection->db();
11
		if ($this->db === null) die('Error: No DB connection. (Marine)');
12
	}
13
14
	/**
15
	* Get SQL query part for filter used
16
	* @param Array $filter the filter
17
	* @return Array the SQL part
18
	*/
19
	
20
	public function getFilter($filter = array(),$where = false,$and = false) {
21
		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
22
		$filters = array();
23
		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
24
			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
25
				$filters = $globalStatsFilters[$globalFilterName];
26
			} else {
27
				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
28
			}
29
		}
30
		if (isset($filter[0]['source'])) {
31
			$filters = array_merge($filters,$filter);
32
		}
33
		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
		$filter_query_join = '';
35
		$filter_query_where = '';
36
		foreach($filters as $flt) {
37
			if (isset($flt['idents']) && !empty($flt['idents'])) {
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";
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";
42
				}
43
			}
44
		}
45
		if (isset($filter['source']) && !empty($filter['source'])) {
46
			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
47
		}
48
		if (isset($filter['ident']) && !empty($filter['ident'])) {
49
			$filter_query_where .= " AND ident = '".$filter['ident']."'";
50
		}
51
		if (isset($filter['id']) && !empty($filter['id'])) {
52
			$filter_query_where .= " AND fammarine_id = '".$filter['id']."'";
53
		}
54
		if (isset($filter['mmsi']) && !empty($filter['mmsi'])) {
55
			$filter_query_where .= " AND mmsi = '".$filter['mmsi']."'";
56
		}
57
		if (isset($filter['race']) && !empty($filter['race'])) {
58
			$filter_query_where .= " AND race_id = '".$filter['race']."'";
59
		}
60
		if (isset($filter['year']) && $filter['year'] != '') {
61
			if ($globalDBdriver == 'mysql') {
62
				$filter_query_where .= " AND YEAR(marine_output.date) = '".$filter['year']."'";
63
			} else {
64
				$filter_query_where .= " AND EXTRACT(YEAR FROM marine_output.date) = '".$filter['year']."'";
65
			}
66
		}
67
		if (isset($filter['month']) && $filter['month'] != '') {
68
			if ($globalDBdriver == 'mysql') {
69
				$filter_query_where .= " AND MONTH(marine_output.date) = '".$filter['month']."'";
70
			} else {
71
				$filter_query_where .= " AND EXTRACT(MONTH FROM marine_output.date) = '".$filter['month']."'";
72
			}
73
		}
74
		if (isset($filter['day']) && $filter['day'] != '') {
75
			if ($globalDBdriver == 'mysql') {
76
				$filter_query_where .= " AND DAY(marine_output.date) = '".$filter['day']."'";
77
			} else {
78
				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
79
			}
80
		}
81
		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
82
		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
83
		if ($filter_query_where != '') {
84
			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
85
		}
86
		$filter_query = $filter_query_join.$filter_query_where;
87
		return $filter_query;
88
	}
89
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
	*/
99
	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
0 ignored issues
show
Unused Code introduced by
The parameter $schedules is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
	{
101
		date_default_timezone_set('UTC');
102
		if (!is_string($query))
103
		{
104
			return false;
105
		}
106
		
107
		if ($limitQuery != "")
108
		{
109
			if (!is_string($limitQuery))
110
			{
111
				return false;
112
			}
113
		}
114
115
		try {
116
			$sth = $this->db->prepare($query.$limitQuery);
117
			$sth->execute($params);
118
		} catch (PDOException $e) {
119
			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
120
			exit();
121
		}
122
		
123
		$num_rows = 0;
124
		$spotter_array = array();
125
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
126
		{
127
			$num_rows++;
128
			$temp_array = array();
129
			if (isset($row['marine_live_id'])) {
130
				$temp_array['marine_id'] = $this->getMarineIDBasedOnFamMarineID($row['fammarine_id']);
131
			/*
132
			} elseif (isset($row['spotter_archive_id'])) {
133
				$temp_array['spotter_id'] = $row['spotter_archive_id'];
134
			} elseif (isset($row['spotter_archive_output_id'])) {
135
				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
136
			*/} 
137
			elseif (isset($row['marineid'])) {
138
				$temp_array['marine_id'] = $row['marineid'];
139
			} else {
140
				$temp_array['marine_id'] = '';
141
			}
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'];
160
			if (isset($row['heading'])) {
161
				$temp_array['heading'] = $row['heading'];
162
				$heading_direction = $this->parseDirection($row['heading']);
163
				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
164
			}
165
			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
166
167
			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "")
168
			{
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']);
171
				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
172
				unset($Image);
173
				if (count($image_array) > 0) {
174
					$temp_array['image'] = $image_array[0]['image'];
175
					$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
176
					$temp_array['image_source'] = $image_array[0]['image_source'];
177
					$temp_array['image_source_website'] = $image_array[0]['image_source_website'];
178
					$temp_array['image_copyright'] = $image_array[0]['image_copyright'];
179
				}
180
			}
181
			
182
			if (isset($row['date'])) {
183
				$dateArray = $this->parseDateString($row['date']);
184
				if ($dateArray['seconds'] < 10)
185
				{
186
					$temp_array['date'] = "a few seconds ago";
187
				} elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30)
188
				{
189
					$temp_array['date'] = "half a minute ago";
190
				} elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60)
191
				{
192
					$temp_array['date'] = "about a minute ago";
193
				} elseif ($dateArray['minutes'] < 5)
194
				{
195
					$temp_array['date'] = "a few minutes ago";
196
				} elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60)
197
				{
198
					$temp_array['date'] = "about ".$dateArray['minutes']." minutes ago";
199
				} elseif ($dateArray['hours'] < 2)
200
				{
201
					$temp_array['date'] = "about an hour ago";
202
				} elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24)
203
				{
204
					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
205
				} else {
206
					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
207
				}
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"));
211
				$temp_array['date_unix'] = strtotime($row['date']." UTC");
212
				if (isset($row['last_seen']) && $row['last_seen'] != '') {
213
					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
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"));
217
						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
218
					}
219
				}
220
			}
221
			
222
			$fromsource = NULL;
0 ignored issues
show
Unused Code introduced by
$fromsource is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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'];
226
			$temp_array['query_number_rows'] = $num_rows;
227
			$spotter_array[] = $temp_array;
228
		}
229
		if ($num_rows == 0) return array();
230
		$spotter_array[0]['query_number_rows'] = $num_rows;
231
		return $spotter_array;
232
	}	
233
	
234
	
235
	/**
236
	* Gets all the spotter information based on the latest data entry
237
	*
238
	* @return Array the spotter information
239
	*
240
	*/
241
	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
242
	{
243
		global $global_marine_query;
244
		date_default_timezone_set('UTC');
245
		$filter_query = $this->getFilter($filter);
246
		if ($limit != "")
247
		{
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);
251
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
252
			{
253
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
254
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
255
			} else $limit_query = "";
256
		} else $limit_query = "";
257
		if ($sort != "")
258
		{
259
			$search_orderby_array = $this->getOrderBy();
260
			$orderby_query = $search_orderby_array[$sort]['sql'];
261
		} else {
262
			$orderby_query = " ORDER BY marine_output.date DESC";
263
		}
264
		$query  = $global_marine_query.$filter_query." ".$orderby_query;
265
		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
266
		return $spotter_array;
267
	}
268
    
269
	/*
270
	* Gets all the spotter information based on the spotter id
271
	*
272
	* @return Array the spotter information
273
	*
274
	*/
275
	public function getMarineDataByID($id = '')
276
	{
277
		global $global_marine_query;
278
		
279
		date_default_timezone_set('UTC');
280
		if ($id == '') return array();
281
		$additional_query = "marine_output.fammarine_id = :id";
282
		$query_values = array(':id' => $id);
283
		$query  = $global_marine_query." WHERE ".$additional_query." ";
284
		$spotter_array = $this->getDataFromDB($query,$query_values);
285
		return $spotter_array;
286
	}
287
288
	/**
289
	* Gets all the spotter information based on the callsign
290
	*
291
	* @return Array the spotter information
292
	*
293
	*/
294
	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
295
	{
296
		global $global_marine_query;
297
		
298
		date_default_timezone_set('UTC');
299
		
300
		$query_values = array();
301
		$limit_query = '';
302
		$additional_query = '';
303
		$filter_query = $this->getFilter($filter,true,true);
304
		if ($ident != "")
305
		{
306
			if (!is_string($ident))
307
			{
308
				return false;
309
			} else {
310
				$additional_query = " AND (marine_output.ident = :ident)";
311
				$query_values = array(':ident' => $ident);
312
			}
313
		}
314
		
315
		if ($limit != "")
316
		{
317
			$limit_array = explode(",", $limit);
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);
321
			
322
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
323
			{
324
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
325
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
326
			}
327
		}
328
329
		if ($sort != "")
330
		{
331
			$search_orderby_array = $this->getOrderBy();
332
			$orderby_query = $search_orderby_array[$sort]['sql'];
333
		} else {
334
			$orderby_query = " ORDER BY marine_output.date DESC";
335
		}
336
337
		$query = $global_marine_query.$filter_query." marine_output.ident <> '' ".$additional_query." ".$orderby_query;
338
		//echo $query."\n";
339
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
340
341
		return $spotter_array;
342
	}
343
344
	/**
345
	* Gets all the marine information based on the type
346
	*
347
	* @return Array the marine information
348
	*
349
	*/
350
	public function getMarineDataByType($type = '', $limit = '', $sort = '', $filter = array())
351
	{
352
		global $global_marine_query;
353
		
354
		date_default_timezone_set('UTC');
355
		
356
		$query_values = array();
0 ignored issues
show
Unused Code introduced by
$query_values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
357
		$limit_query = '';
358
		$additional_query = '';
0 ignored issues
show
Unused Code introduced by
$additional_query is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
359
		$filter_query = $this->getFilter($filter,true,true);
360
		if (!is_string($type))
361
		{
362
			return false;
363
		} else {
364
			$additional_query = " AND marine_output.type_id = :type";
365
			$query_values = array(':type' => $type);
366
		}
367
		
368
		if ($limit != "")
369
		{
370
			$limit_array = explode(",", $limit);
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);
374
			
375
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
376
			{
377
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
378
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
379
			}
380
		}
381
382
		if ($sort != "")
383
		{
384
			$search_orderby_array = $this->getOrderBy();
385
			$orderby_query = $search_orderby_array[$sort]['sql'];
386
		} else {
387
			$orderby_query = " ORDER BY marine_output.date DESC";
388
		}
389
390
		$query = $global_marine_query.$filter_query." marine_output.type <> '' ".$additional_query." ".$orderby_query;
391
		//echo $query."\n";
392
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
393
394
		return $spotter_array;
395
	}
396
	
397
	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array())
398
	{
399
		global $global_marine_query, $globalTimezone, $globalDBdriver;
400
		
401
		$query_values = array();
402
		$limit_query = '';
403
		$additional_query = '';
404
405
		$filter_query = $this->getFilter($filter,true,true);
406
		
407
		if ($date != "")
408
		{
409
			if ($globalTimezone != '') {
410
				date_default_timezone_set($globalTimezone);
411
				$datetime = new DateTime($date);
412
				$offset = $datetime->format('P');
413
			} else {
414
				date_default_timezone_set('UTC');
415
				$datetime = new DateTime($date);
416
				$offset = '+00:00';
417
			}
418
			if ($globalDBdriver == 'mysql') {
419
				$additional_query = " AND DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date ";
420
				$query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset);
421
			} elseif ($globalDBdriver == 'pgsql') {
422
				$additional_query = " AND to_char(marine_output.date AT TIME ZONE :timezone,'YYYY-mm-dd') = :date ";
423
				$query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone);
424
			}
425
		}
426
		
427
		if ($limit != "")
428
		{
429
			$limit_array = explode(",", $limit);
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);
433
			
434
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
435
			{
436
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
437
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
438
			}
439
		}
440
441
		if ($sort != "")
442
		{
443
			$search_orderby_array = $this->getOrderBy();
444
			$orderby_query = $search_orderby_array[$sort]['sql'];
445
		} else {
446
			$orderby_query = " ORDER BY marine_output.date DESC";
447
		}
448
449
		$query = $global_marine_query.$filter_query." marine_output.ident <> '' ".$additional_query.$orderby_query;
450
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
451
		return $spotter_array;
452
	}
453
454
	/**
455
	* Gets all the marine information based on the captain
456
	*
457
	* @return Array the marine information
458
	*
459
	*/
460
	public function getMarineDataByCaptain($captain = '', $limit = '', $sort = '', $filter = array())
461
	{
462
		global $global_marine_query;
463
		date_default_timezone_set('UTC');
464
		$query_values = array();
465
		$limit_query = '';
466
		$additional_query = '';
467
		$filter_query = $this->getFilter($filter,true,true);
468
		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
469
		if ($captain != "")
470
		{
471
			$additional_query = " AND (marine_output.captain_name = :captain OR marine_output.captain_id = :captain)";
472
			$query_values = array(':captain' => $captain);
473
		}
474
		if ($limit != "")
475
		{
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);
479
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
480
			{
481
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
482
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
483
			}
484
		}
485
		if ($sort != "")
486
		{
487
			$search_orderby_array = $this->getOrderBy();
488
			$orderby_query = $search_orderby_array[$sort]['sql'];
489
		} else {
490
			$orderby_query = " ORDER BY marine_output.date DESC";
491
		}
492
		$query = $global_marine_query.$filter_query." marine_output.captain_name <> '' ".$additional_query." ".$orderby_query;
493
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
494
		return $spotter_array;
495
	}
496
497
	/**
498
	* Gets all the marine information based on the race
499
	*
500
	* @return Array the marine information
501
	*
502
	*/
503
	public function getMarineDataByRace($race = '', $limit = '', $sort = '', $filter = array())
504
	{
505
		global $global_marine_query,$globalDBdriver;
506
		date_default_timezone_set('UTC');
507
		$query_values = array();
508
		$limit_query = '';
509
		$additional_query = '';
510
		$filter_query = $this->getFilter($filter,true,true);
511
		$race = filter_var($race,FILTER_SANITIZE_STRING);
512
		if ($race != "")
513
		{
514
			$additional_query = " AND (marine_output.race_name = :race OR marine_output.race_id = :race)";
515
			$query_values = array(':race' => $race);
516
		}
517
		if ($limit != "")
518
		{
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);
522
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
523
			{
524
				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
525
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
526
			}
527
		}
528
		if ($sort != "")
529
		{
530
			$search_orderby_array = $this->getOrderBy();
531
			$orderby_query = $search_orderby_array[$sort]['sql'];
532
		} else {
533
			if ($globalDBdriver == 'mysql') {
534
				$orderby_query = " ORDER BY -marine_output.race_rank DESC, marine_output.distance ASC";
535
			} else {
536
				$orderby_query = " ORDER BY marine_output.race_rank ASC, marine_output.distance ASC";
537
			}
538
		}
539
		$query = $global_marine_query.$filter_query." marine_output.race_name <> '' ".$additional_query." ".$orderby_query;
540
		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query);
541
		return $spotter_array;
542
	}
543
544
	/**
545
	* Count races by captain
546
	*
547
	* @return String Duration of all races
548
	*
549
	*/
550
	public function countRacesByCaptain($captain,$filters = array())
551
	{
552
		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
553
		$filter_query = $this->getFilter($filters,true,true);
554
		$query  = "SELECT COUNT(*) AS nb 
555
			FROM marine_output".$filter_query." (marine_output.captain_name = :captain OR marine_output.captain_id = :captain)";
556
		$query_values = array();
557
		$query_values = array_merge($query_values,array(':captain' => $captain));
558
		$sth = $this->db->prepare($query);
559
		$sth->execute($query_values);
560
		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
561
		return $result[0]['nb'];
562
	}
563
564
	/**
565
	* Count captains by race
566
	*
567
	* @return String Duration of all races
568
	*
569
	*/
570
	public function countCaptainsByRace($race,$filters = array())
571
	{
572
		$race = filter_var($race,FILTER_SANITIZE_STRING);
573
		$filter_query = $this->getFilter($filters,true,true);
574
		$query  = "SELECT COUNT(*) AS nb 
575
			FROM marine_output".$filter_query." (marine_output.race_name = :race OR marine_output.race_id = :race)";
576
		$query_values = array();
577
		$query_values = array_merge($query_values,array(':race' => $race));
578
		$sth = $this->db->prepare($query);
579
		$sth->execute($query_values);
580
		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
581
		return $result[0]['nb'];
582
	}
583
584
	/**
585
	* Gets all boat types that have been used by a captain
586
	*
587
	* @return Array the boat list
588
	*
589
	*/
590
	public function countAllBoatTypesByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
591
	{
592
		global $globalDBdriver;
593
		$filter_query = $this->getFilter($filters,true,true);
594
		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
595
		$query  = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
596
			FROM marine_output".$filter_query." (marine_output.captain_id = :captain OR marine_output.captain_name = :captain)";
597
		$query_values = array();
598
		if ($year != '') {
599
			if ($globalDBdriver == 'mysql') {
600
				$query .= " AND YEAR(marine_output.date) = :year";
601
				$query_values = array_merge($query_values,array(':year' => $year));
602
			} else {
603
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
604
				$query_values = array_merge($query_values,array(':year' => $year));
605
			}
606
		}
607
		if ($month != '') {
608
			if ($globalDBdriver == 'mysql') {
609
				$query .= " AND MONTH(marine_output.date) = :month";
610
				$query_values = array_merge($query_values,array(':month' => $month));
611
			} else {
612
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
613
				$query_values = array_merge($query_values,array(':month' => $month));
614
			}
615
		}
616
		if ($day != '') {
617
			if ($globalDBdriver == 'mysql') {
618
				$query .= " AND DAY(marine_output.date) = :day";
619
				$query_values = array_merge($query_values,array(':day' => $day));
620
			} else {
621
				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
622
				$query_values = array_merge($query_values,array(':day' => $day));
623
			}
624
		}
625
		$query .= " GROUP BY marine_output.type
626
			ORDER BY type_count DESC";
627
		$query_values = array_merge($query_values,array(':captain' => $captain));
628
		$sth = $this->db->prepare($query);
629
		$sth->execute($query_values);
630
		return $sth->fetchAll(PDO::FETCH_ASSOC);
631
	}
632
633
	/**
634
	* Gets all boat types that have been used on a race
635
	*
636
	* @return Array the boat list
637
	*
638
	*/
639
	public function countAllBoatTypesByRace($race,$filters = array(),$year = '',$month = '',$day = '')
640
	{
641
		global $globalDBdriver;
642
		$filter_query = $this->getFilter($filters,true,true);
643
		$race = filter_var($race,FILTER_SANITIZE_STRING);
644
		$query  = "SELECT DISTINCT marine_output.type, COUNT(marine_output.type) AS type_count
645
			FROM marine_output".$filter_query." (marine_output.race_id = :race OR marine_output.race_name = :race)";
646
		$query_values = array();
647
		if ($year != '') {
648
			if ($globalDBdriver == 'mysql') {
649
				$query .= " AND YEAR(marine_output.date) = :year";
650
				$query_values = array_merge($query_values,array(':year' => $year));
651
			} else {
652
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
653
				$query_values = array_merge($query_values,array(':year' => $year));
654
			}
655
		}
656
		if ($month != '') {
657
			if ($globalDBdriver == 'mysql') {
658
				$query .= " AND MONTH(marine_output.date) = :month";
659
				$query_values = array_merge($query_values,array(':month' => $month));
660
			} else {
661
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
662
				$query_values = array_merge($query_values,array(':month' => $month));
663
			}
664
		}
665
		if ($day != '') {
666
			if ($globalDBdriver == 'mysql') {
667
				$query .= " AND DAY(marine_output.date) = :day";
668
				$query_values = array_merge($query_values,array(':day' => $day));
669
			} else {
670
				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
671
				$query_values = array_merge($query_values,array(':day' => $day));
672
			}
673
		}
674
		$query .= " GROUP BY marine_output.type
675
			ORDER BY type_count DESC";
676
		$query_values = array_merge($query_values,array(':race' => $race));
677
		$sth = $this->db->prepare($query);
678
		$sth->execute($query_values);
679
		return $sth->fetchAll(PDO::FETCH_ASSOC);
680
	}
681
682
	/**
683
	* Gets race duration by captain
684
	*
685
	* @return String Duration of all race
686
	*
687
	*/
688
	public function getRaceDurationByCaptain($captain,$filters = array(),$year = '',$month = '',$day = '')
689
	{
690
		global $globalDBdriver;
691
		$captain = filter_var($captain,FILTER_SANITIZE_STRING);
692
		$filter_query = $this->getFilter($filters,true,true);
693
		$query  = "SELECT SUM(last_seen - date) AS duration 
694
		    FROM marine_output".$filter_query." (marine_output.captain_name = :captain OR marine_output.captain_id = :captain) 
695
		    AND last_seen > date";
696
		$query_values = array();
697
		if ($year != '') {
698
			if ($globalDBdriver == 'mysql') {
699
				$query .= " AND YEAR(marine_output.date) = :year";
700
				$query_values = array_merge($query_values,array(':year' => $year));
701
			} else {
702
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
703
				$query_values = array_merge($query_values,array(':year' => $year));
704
			}
705
		}
706
		if ($month != '') {
707
			if ($globalDBdriver == 'mysql') {
708
				$query .= " AND MONTH(marine_output.date) = :month";
709
				$query_values = array_merge($query_values,array(':month' => $month));
710
			} else {
711
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
712
				$query_values = array_merge($query_values,array(':month' => $month));
713
			}
714
		}
715
		if ($day != '') {
716
			if ($globalDBdriver == 'mysql') {
717
				$query .= " AND DAY(marine_output.date) = :day";
718
				$query_values = array_merge($query_values,array(':day' => $day));
719
			} else {
720
				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
721
				$query_values = array_merge($query_values,array(':day' => $day));
722
			}
723
		}
724
		$query_values = array_merge($query_values,array(':captain' => $captain));
725
		$sth = $this->db->prepare($query);
726
		$sth->execute($query_values);
727
		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
728
		if (is_int($result[0]['duration'])) return gmdate('H:i:s',$result[0]['duration']);
729
		else return $result[0]['duration'];
730
	}
731
732
	/**
733
	* Gets a list of all captain names and captain ids
734
	*
735
	* @return Array list of captain names and captain ids
736
	*
737
	*/
738
	public function getAllCaptainNames($filters = array())
739
	{
740
		$filter_query = $this->getFilter($filters,true,true);
741
		$query  = "SELECT DISTINCT marine_output.captain_name, marine_output.captain_id
742
			FROM marine_output".$filter_query." marine_output.captain_name <> '' 
743
			ORDER BY marine_output.captain_name ASC";
744
	
745
		$sth = $this->db->prepare($query);
746
		$sth->execute();
747
		return $sth->fetchAll(PDO::FETCH_ASSOC);
748
	} 
749
750
	/**
751
	* Gets a list of all race names and race ids
752
	*
753
	* @return Array list of race names and race ids
754
	*
755
	*/
756
	public function getAllRaceNames($filters = array())
757
	{
758
		$filter_query = $this->getFilter($filters,true,true);
759
		$query  = "SELECT DISTINCT marine_output.race_name, marine_output.race_id
760
			FROM marine_output".$filter_query." marine_output.race_name <> '' 
761
			ORDER BY marine_output.race_name ASC";
762
	
763
		$sth = $this->db->prepare($query);
764
		$sth->execute();
765
		return $sth->fetchAll(PDO::FETCH_ASSOC);
766
	} 
767
768
	/**
769
	* Gets all source name
770
	*
771
	* @param String type format of source
772
	* @return Array list of source name
773
	*
774
	*/
775
	public function getAllSourceName($type = '',$filters = array())
776
	{
777
		$filter_query = $this->getFilter($filters,true,true);
778
		$query_values = array();
779
		$query  = "SELECT DISTINCT marine_output.source_name 
780
				FROM marine_output".$filter_query." marine_output.source_name <> ''";
781
		if ($type != '') {
782
			$query_values = array(':type' => $type);
783
			$query .= " AND format_source = :type";
784
		}
785
		$query .= " ORDER BY marine_output.source_name ASC";
786
787
		$sth = $this->db->prepare($query);
788
		if (!empty($query_values)) $sth->execute($query_values);
789
		else $sth->execute();
790
791
		$source_array = array();
792
		$temp_array = array();
793
		
794
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
795
		{
796
			$temp_array['source_name'] = $row['source_name'];
797
			$source_array[] = $temp_array;
798
		}
799
		return $source_array;
800
	}
801
802
803
	/**
804
	* Gets a list of all idents/callsigns
805
	*
806
	* @return Array list of ident/callsign names
807
	*
808
	*/
809
	public function getAllIdents($filters = array())
810
	{
811
		$filter_query = $this->getFilter($filters,true,true);
812
		$query  = "SELECT DISTINCT marine_output.ident
813
								FROM marine_output".$filter_query." marine_output.ident <> '' 
814
								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
815
816
		$sth = $this->db->prepare($query);
817
		$sth->execute();
818
    
819
		$ident_array = array();
820
		$temp_array = array();
821
		
822
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
823
		{
824
			$temp_array['ident'] = $row['ident'];
825
			$ident_array[] = $temp_array;
826
		}
827
828
		return $ident_array;
829
	}
830
831
	/**
832
	* Gets all info from a mmsi
833
	*
834
	* @return Array ident
835
	*
836
	*/
837
	public function getIdentity($mmsi)
838
	{
839
		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
840
		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
841
		$sth = $this->db->prepare($query);
842
		$sth->execute(array(':mmsi' => $mmsi));
843
		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
844
		if (isset($result[0])) return $result[0];
845
		else return array();
846
	}
847
848
	/**
849
	* Add identity
850
	*
851
	*/
852
	public function addIdentity($mmsi,$imo,$ident,$callsign,$type)
853
	{
854
		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
855
		if ($mmsi != '') {
856
			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT);
857
			$ident = filter_var($ident,FILTER_SANITIZE_STRING);
858
			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
859
			$type = filter_var($type,FILTER_SANITIZE_STRING);
860
			$identinfo = $this->getIdentity($mmsi);
861
			if (empty($identinfo)) {
862
				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)";
863
				$sth = $this->db->prepare($query);
864
				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type));
865
			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) {
866
				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi";
867
				$sth = $this->db->prepare($query);
868
				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type));
869
			}
870
		}
871
	}
872
873
	/*
874
	* Gets a list of all dates
875
	*
876
	* @return Array list of date names
877
	*
878
	*/
879
	public function getAllDates()
880
	{
881
		global $globalTimezone, $globalDBdriver;
882
		if ($globalTimezone != '') {
883
			date_default_timezone_set($globalTimezone);
884
			$datetime = new DateTime();
885
			$offset = $datetime->format('P');
886
		} else $offset = '+00:00';
887
888
		if ($globalDBdriver == 'mysql') {
889
			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
890
								FROM marine_output
891
								WHERE marine_output.date <> '' 
892
								ORDER BY marine_output.date ASC LIMIT 0,100";
893
		} else {
894
			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
895
								FROM marine_output
896
								WHERE marine_output.date <> '' 
897
								ORDER BY marine_output.date ASC LIMIT 0,100";
898
		}
899
		
900
		$sth = $this->db->prepare($query);
901
		$sth->execute(array(':offset' => $offset));
902
    
903
		$date_array = array();
904
		$temp_array = array();
905
		
906
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
907
		{
908
			$temp_array['date'] = $row['date'];
909
910
			$date_array[] = $temp_array;
911
		}
912
913
		return $date_array;
914
	}
915
916
	/**
917
	* Update ident tracker data
918
	*
919
	* @param String $fammarine_id the ID
920
	* @param String $ident the marine ident
921
	* @return String success or false
922
	*
923
	*/
924
	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $fromsource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
925
	{
926
		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
927
		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
928
		try {
929
			$sth = $this->db->prepare($query);
930
			$sth->execute($query_values);
931
		} catch (PDOException $e) {
932
			return "error : ".$e->getMessage();
933
		}
934
		return "success";
935
	}
936
937
	/**
938
	* Update arrival marine data
939
	*
940
	* @param String $fammarine_id the ID
941
	* @param String $arrival_code the marine ident
942
	* @return String success or false
943
	*
944
	*/
945
	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $fromsource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
946
	{
947
		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id';
948
		$query_values = array(':fammarine_id' => $fammarine_id,':arrival_code' => $arrival_code);
949
		try {
950
			$sth = $this->db->prepare($query);
951
			$sth->execute($query_values);
952
		} catch (PDOException $e) {
953
			return "error : ".$e->getMessage();
954
		}
955
		return "success";
956
	}
957
958
	/**
959
	* Update Status data
960
	*
961
	* @param String $fammarine_id the ID
962
	* @param String $status_id the marine status id
963
	* @param String $status the marine status
964
	* @return String success or false
965
	*
966
	*/
967
	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '')
968
	{
969
970
		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id';
971
                $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id);
972
973
		try {
974
			$sth = $this->db->prepare($query);
975
			$sth->execute($query_values);
976
		} catch (PDOException $e) {
977
			return "error : ".$e->getMessage();
978
		}
979
		
980
		return "success";
981
982
	}
983
	/**
984
	* Update latest marine data
985
	*
986
	* @param String $fammarine_id the ID
987
	* @param String $ident the marine ident
988
	* @return String success or false
989
	*
990
	*/	
991
	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '',$distance = NULL,$race_rank = NULL, $race_time = NULL, $status = '', $race_begin = '')
992
	{
993
		if ($latitude == '') $latitude = NULL;
994
		if ($longitude == '') $longitude = NULL;
995
		$groundspeed = round($groundspeed);
996
		if ($race_begin != '') {
997
			$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';
998
			$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);
999
		} else {
1000
			$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';
1001
			$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);
1002
		}
1003
		try {
1004
			$sth = $this->db->prepare($query);
1005
			$sth->execute($query_values);
1006
		} catch (PDOException $e) {
1007
			echo "error : ".$e->getMessage();
1008
			return "error : ".$e->getMessage();
1009
		}
1010
		
1011
		return "success";
1012
1013
	}
1014
1015
	/**
1016
	* Adds a new marine data
1017
	*
1018
	* @param String $fammarine_id the ID
1019
	* @param String $ident the marine ident
1020
	* @param String $departure_airport_icao the departure airport
0 ignored issues
show
Bug introduced by
There is no parameter named $departure_airport_icao. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1021
	* @param String $arrival_airport_icao the arrival airport
0 ignored issues
show
Bug introduced by
There is no parameter named $arrival_airport_icao. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1022
	* @param String $latitude latitude of flight
1023
	* @param String $longitude latitude of flight
1024
	* @param String $waypoints waypoints of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $waypoints. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1025
	* @param String $heading heading of flight
1026
	* @param String $groundspeed speed of flight
1027
	* @param String $date date of flight
1028
	* @param String $departure_airport_time departure time of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $departure_airport_time. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1029
	* @param String $arrival_airport_time arrival time of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $arrival_airport_time. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1030
	* @param String $squawk squawk code of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $squawk. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1031
	* @param String $route_stop route stop of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $route_stop. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1032
	* @param String $highlight highlight or not
0 ignored issues
show
Bug introduced by
There is no parameter named $highlight. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1033
	* @param String $ModeS ModesS code of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $ModeS. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1034
	* @param String $registration registration code of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $registration. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1035
	* @param String $pilot_id pilot id of flight (for virtual airlines)
0 ignored issues
show
Bug introduced by
There is no parameter named $pilot_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1036
	* @param String $pilot_name pilot name of flight (for virtual airlines)
0 ignored issues
show
Bug introduced by
There is no parameter named $pilot_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1037
	* @param String $verticalrate vertival rate of flight
0 ignored issues
show
Bug introduced by
There is no parameter named $verticalrate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1038
	* @return String success or false
1039
	*/
1040
	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 = '')
1041
	{
1042
		global $globalURL, $globalMarineImageFetch;
1043
		
1044
		//$Image = new Image($this->db);
1045
		$Common = new Common();
1046
		
1047
		date_default_timezone_set('UTC');
1048
		
1049
		//getting the registration
1050
		if ($fammarine_id != "")
1051
		{
1052
			if (!is_string($fammarine_id))
1053
			{
1054
				return false;
1055
			}
1056
		}
1057
		$fromsource = NULL;
0 ignored issues
show
Unused Code introduced by
$fromsource is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1058
		//getting the airline information
1059
		if ($ident != "")
1060
		{
1061
			if (!is_string($ident))
1062
			{
1063
				return false;
1064
			}
1065
		}
1066
1067
		if ($latitude != "")
1068
		{
1069
			if (!is_numeric($latitude))
1070
			{
1071
				return false;
1072
			}
1073
		}
1074
		
1075
		if ($longitude != "")
1076
		{
1077
			if (!is_numeric($longitude))
1078
			{
1079
				return false;
1080
			}
1081
		}
1082
		
1083
		if ($heading != "")
1084
		{
1085
			if (!is_numeric($heading))
1086
			{
1087
				return false;
1088
			}
1089
		}
1090
		if ($mmsi != "")
1091
		{
1092
			if (!is_numeric($mmsi))
1093
			{
1094
				return false;
1095
			}
1096
		}
1097
		
1098
		if ($groundspeed != "")
1099
		{
1100
			if (!is_numeric($groundspeed))
1101
			{
1102
				return false;
1103
			}
1104
		}
1105
1106
    
1107
		if ($date == "")
1108
		{
1109
			$date = date("Y-m-d H:i:s", time());
1110
		}
1111
1112
		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1113
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1114
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1115
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1116
		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
1117
		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1118
		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
1119
		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
1120
		$type = filter_var($type,FILTER_SANITIZE_STRING);
1121
		$status = filter_var($status,FILTER_SANITIZE_STRING);
1122
		$type_id = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
1123
		$status_id = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
1124
		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1125
		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
0 ignored issues
show
Unused Code introduced by
$callsign is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1126
		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
1127
		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
1128
		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
1129
		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
1130
		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
1131
		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
1132
		$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
1133
		$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1134
		$distance = filter_var($distance,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1135
		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) {
1136
			$Image = new Image($this->db);
1137
			$image_array = $Image->getMarineImage($mmsi,$imo,$ident);
1138
			if (!isset($image_array[0]['mmsi'])) {
1139
				$Image->addMarineImage($mmsi,$imo,$ident);
1140
			}
1141
			unset($Image);
1142
		}
1143
		if ($latitude == '' && $longitude == '') {
1144
			$latitude = 0;
1145
			$longitude = 0;
1146
		}
1147
		if ($type_id == '') $type_id = NULL;
1148
		if ($status_id == '') $status_id = NULL;
1149
		if ($distance == '') $distance = NULL;
1150
		if ($race_rank == '') $race_rank = NULL;
1151
		if ($race_time == '') $race_time = NULL;
1152
		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
1153
		//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
1154
		if ($arrival_date == '') $arrival_date = NULL;
1155
		$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) 
1156
		    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)";
1157
1158
		$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);
1159
		try {
1160
			$sth = $this->db->prepare($query);
1161
			$sth->execute($query_values);
1162
			$this->db = null;
1163
		} catch (PDOException $e) {
1164
			return "error : ".$e->getMessage();
1165
		}
1166
		
1167
		return "success";
1168
1169
	}
1170
	
1171
  
1172
	/**
1173
	* Gets the aircraft ident within the last hour
1174
	*
1175
	* @return String the ident
1176
	*
1177
	*/
1178
	public function getIdentFromLastHour($ident)
1179
	{
1180
		global $globalDBdriver, $globalTimezone;
1181
		if ($globalDBdriver == 'mysql') {
1182
			$query  = "SELECT marine_output.ident FROM marine_output 
1183
								WHERE marine_output.ident = :ident 
1184
								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
1185
								AND marine_output.date < UTC_TIMESTAMP()";
1186
			$query_data = array(':ident' => $ident);
1187
		} else {
1188
			$query  = "SELECT marine_output.ident FROM marine_output 
1189
								WHERE marine_output.ident = :ident 
1190
								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
1191
								AND marine_output.date < now() AT TIME ZONE 'UTC'";
1192
			$query_data = array(':ident' => $ident);
1193
    		}
1194
		
1195
		$sth = $this->db->prepare($query);
1196
		$sth->execute($query_data);
1197
    		$ident_result='';
1198
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1199
		{
1200
			$ident_result = $row['ident'];
1201
		}
1202
1203
		return $ident_result;
1204
	}
1205
	
1206
	
1207
	/**
1208
	* Gets the aircraft data from the last 20 seconds
1209
	*
1210
	* @return Array the marine data
1211
	*
1212
	*/
1213
	public function getRealTimeData($q = '')
1214
	{
1215
		global $globalDBdriver;
1216
		$additional_query = '';
1217
		if ($q != "")
1218
		{
1219
			if (!is_string($q))
1220
			{
1221
				return false;
1222
			} else {
1223
				$q_array = explode(" ", $q);
1224
				foreach ($q_array as $q_item){
1225
					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1226
					$additional_query .= " AND (";
1227
					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
1228
					$additional_query .= ")";
1229
				}
1230
			}
1231
		}
1232
		if ($globalDBdriver == 'mysql') {
1233
			$query  = "SELECT marine_output.* FROM marine_output 
1234
				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
1235
				AND marine_output.date < UTC_TIMESTAMP()";
1236
		} else {
1237
			$query  = "SELECT marine_output.* FROM marine_output 
1238
				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
1239
				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1240
		}
1241
		$marine_array = $this->getDataFromDB($query, array());
1242
1243
		return $marine_array;
1244
	}
1245
	
1246
	
1247
	
1248
1249
	/**
1250
	* Gets all number of flight over countries
1251
	*
1252
	* @return Array the airline country list
1253
	*
1254
	*/
1255
1256
	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
1257
	{
1258
		global $globalDBdriver, $globalArchive;
1259
		//$filter_query = $this->getFilter($filters,true,true);
1260
		$Connection= new Connection($this->db);
1261
		if (!$Connection->tableExists('countries')) return array();
1262
		require_once('class.SpotterLive.php');
1263
		if (!isset($globalArchive) || $globalArchive !== TRUE) {
1264
			$MarineLive = new MarineLive($this->db);
1265
			$filter_query = $MarineLive->getFilter($filters,true,true);
1266
			$filter_query .= " over_country IS NOT NULL AND over_country <> ''";
1267
			if ($olderthanmonths > 0) {
1268
				if ($globalDBdriver == 'mysql') {
1269
					$filter_query .= ' AND marine_live.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
1270
				} else {
1271
					$filter_query .= " AND marine_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1272
				}
1273
			}
1274
			if ($sincedate != '') {
1275
				if ($globalDBdriver == 'mysql') {
1276
					$filter_query .= " AND marine_live.date > '".$sincedate."' ";
1277
				} else {
1278
					$filter_query .= " AND marine_live.date > CAST('".$sincedate."' AS TIMESTAMP)";
1279
				}
1280
			}
1281
			$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_live".$filter_query.") l ON c.iso2 = l.over_country ";
1282
		} else {
1283
			require_once(dirname(__FILE__)."/class.MarineArchive.php");
1284
			$MarineArchive = new MarineArchive($this->db);
1285
			$filter_query = $MarineArchive->getFilter($filters,true,true);
1286
			$filter_query .= " over_country <> ''";
1287
			if ($olderthanmonths > 0) {
1288
				if ($globalDBdriver == 'mysql') {
1289
					$filter_query .= ' AND marine_archive.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) ';
1290
				} else {
1291
					$filter_query .= " AND marine_archive.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1292
				}
1293
			}
1294
			if ($sincedate != '') {
1295
				if ($globalDBdriver == 'mysql') {
1296
					$filter_query .= " AND marine_archive.date > '".$sincedate."' ";
1297
				} else {
1298
					$filter_query .= " AND marine_archive.date > CAST('".$sincedate."' AS TIMESTAMP)";
1299
				}
1300
			}
1301
			$filter_query .= " LIMIT 200 OFFSET 0";
1302
			$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 ";
1303
		}
1304
		$query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC";
1305
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1306
1307
		$sth = $this->db->prepare($query);
1308
		$sth->execute();
1309
 
1310
		$flight_array = array();
1311
		$temp_array = array();
1312
        
1313
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1314
		{
1315
			$temp_array['marine_count'] = $row['nb'];
1316
			$temp_array['marine_country'] = $row['name'];
1317
			$temp_array['marine_country_iso3'] = $row['iso3'];
1318
			$temp_array['marine_country_iso2'] = $row['iso2'];
1319
			$flight_array[] = $temp_array;
1320
		}
1321
		return $flight_array;
1322
	}
1323
	
1324
	
1325
	
1326
	/**
1327
	* Gets all callsigns that have flown over
1328
	*
1329
	* @return Array the callsign list
1330
	*
1331
	*/
1332
	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
1333
	{
1334
		global $globalDBdriver;
1335
		$filter_query = $this->getFilter($filters,true,true);
1336
		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
1337
                    FROM marine_output".$filter_query." marine_output.ident <> ''";
1338
		 if ($olderthanmonths > 0) {
1339
			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
1340
			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
1341
		}
1342
		if ($sincedate != '') {
1343
			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
1344
			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
1345
		}
1346
		$query_values = array();
1347
		if ($year != '') {
1348
			if ($globalDBdriver == 'mysql') {
1349
				$query .= " AND YEAR(marine_output.date) = :year";
1350
				$query_values = array_merge($query_values,array(':year' => $year));
1351
			} else {
1352
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1353
				$query_values = array_merge($query_values,array(':year' => $year));
1354
			}
1355
		}
1356
		if ($month != '') {
1357
			if ($globalDBdriver == 'mysql') {
1358
				$query .= " AND MONTH(marine_output.date) = :month";
1359
				$query_values = array_merge($query_values,array(':month' => $month));
1360
			} else {
1361
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1362
				$query_values = array_merge($query_values,array(':month' => $month));
1363
			}
1364
		}
1365
		if ($day != '') {
1366
			if ($globalDBdriver == 'mysql') {
1367
				$query .= " AND DAY(marine_output.date) = :day";
1368
				$query_values = array_merge($query_values,array(':day' => $day));
1369
			} else {
1370
				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
1371
				$query_values = array_merge($query_values,array(':day' => $day));
1372
			}
1373
		}
1374
		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
1375
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
1376
      		
1377
		$sth = $this->db->prepare($query);
1378
		$sth->execute($query_values);
1379
      
1380
		$callsign_array = array();
1381
		$temp_array = array();
1382
        
1383
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1384
		{
1385
			$temp_array['callsign_icao'] = $row['ident'];
1386
			$temp_array['airline_name'] = $row['airline_name'];
1387
			$temp_array['airline_icao'] = $row['airline_icao'];
1388
			$temp_array['callsign_icao_count'] = $row['callsign_icao_count'];
1389
          
1390
			$callsign_array[] = $temp_array;
1391
		}
1392
1393
		return $callsign_array;
1394
	}
1395
1396
1397
	/**
1398
	* Counts all dates
1399
	*
1400
	* @return Array the date list
1401
	*
1402
	*/
1403
	public function countAllDates($filters = array())
1404
	{
1405
		global $globalTimezone, $globalDBdriver;
1406
		if ($globalTimezone != '') {
1407
			date_default_timezone_set($globalTimezone);
1408
			$datetime = new DateTime();
1409
			$offset = $datetime->format('P');
1410
		} else $offset = '+00:00';
1411
1412
		if ($globalDBdriver == 'mysql') {
1413
			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1414
								FROM marine_output";
1415
			$query .= $this->getFilter($filters);
1416
			$query .= " GROUP BY date_name 
1417
								ORDER BY date_count DESC
1418
								LIMIT 10 OFFSET 0";
1419
		} else {
1420
			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
1421
								FROM marine_output";
1422
			$query .= $this->getFilter($filters);
1423
			$query .= " GROUP BY date_name 
1424
								ORDER BY date_count DESC
1425
								LIMIT 10 OFFSET 0";
1426
		}
1427
      
1428
		
1429
		$sth = $this->db->prepare($query);
1430
		$sth->execute(array(':offset' => $offset));
1431
      
1432
		$date_array = array();
1433
		$temp_array = array();
1434
        
1435
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1436
		{
1437
			$temp_array['date_name'] = $row['date_name'];
1438
			$temp_array['date_count'] = $row['date_count'];
1439
1440
			$date_array[] = $temp_array;
1441
		}
1442
1443
		return $date_array;
1444
	}
1445
	
1446
	
1447
	/**
1448
	* Counts all dates during the last 7 days
1449
	*
1450
	* @return Array the date list
1451
	*
1452
	*/
1453
	public function countAllDatesLast7Days($filters = array())
1454
	{
1455
		global $globalTimezone, $globalDBdriver;
1456
		if ($globalTimezone != '') {
1457
			date_default_timezone_set($globalTimezone);
1458
			$datetime = new DateTime();
1459
			$offset = $datetime->format('P');
1460
		} else $offset = '+00:00';
1461
		$filter_query = $this->getFilter($filters,true,true);
1462
		if ($globalDBdriver == 'mysql') {
1463
			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1464
								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
1465
			$query .= " GROUP BY date_name 
1466
								ORDER BY marine_output.date ASC";
1467
			$query_data = array(':offset' => $offset);
1468
		} else {
1469
			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
1470
								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '7 DAYS'";
1471
			$query .= " GROUP BY date_name 
1472
								ORDER BY date_name ASC";
1473
			$query_data = array(':offset' => $offset);
1474
    		}
1475
		
1476
		$sth = $this->db->prepare($query);
1477
		$sth->execute($query_data);
1478
      
1479
		$date_array = array();
1480
		$temp_array = array();
1481
        
1482
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1483
		{
1484
			$temp_array['date_name'] = $row['date_name'];
1485
			$temp_array['date_count'] = $row['date_count'];
1486
          
1487
			$date_array[] = $temp_array;
1488
		}
1489
1490
		return $date_array;
1491
	}
1492
1493
	/**
1494
	* Counts all dates during the last month
1495
	*
1496
	* @return Array the date list
1497
	*
1498
	*/
1499
	public function countAllDatesLastMonth($filters = array())
1500
	{
1501
		global $globalTimezone, $globalDBdriver;
1502
		if ($globalTimezone != '') {
1503
			date_default_timezone_set($globalTimezone);
1504
			$datetime = new DateTime();
1505
			$offset = $datetime->format('P');
1506
		} else $offset = '+00:00';
1507
		$filter_query = $this->getFilter($filters,true,true);
1508
		if ($globalDBdriver == 'mysql') {
1509
			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1510
								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
1511
			$query .= " GROUP BY date_name 
1512
								ORDER BY marine_output.date ASC";
1513
			$query_data = array(':offset' => $offset);
1514
		} else {
1515
			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count
1516
								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS'";
1517
			$query .= " GROUP BY date_name 
1518
								ORDER BY date_name ASC";
1519
			$query_data = array(':offset' => $offset);
1520
    		}
1521
		
1522
		$sth = $this->db->prepare($query);
1523
		$sth->execute($query_data);
1524
      
1525
		$date_array = array();
1526
		$temp_array = array();
1527
        
1528
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1529
		{
1530
			$temp_array['date_name'] = $row['date_name'];
1531
			$temp_array['date_count'] = $row['date_count'];
1532
          
1533
			$date_array[] = $temp_array;
1534
		}
1535
1536
		return $date_array;
1537
	}
1538
1539
1540
1541
	/**
1542
	* Counts all month
1543
	*
1544
	* @return Array the month list
1545
	*
1546
	*/
1547
	public function countAllMonths($filters = array())
1548
	{
1549
		global $globalTimezone, $globalDBdriver;
1550
		if ($globalTimezone != '') {
1551
			date_default_timezone_set($globalTimezone);
1552
			$datetime = new DateTime();
1553
			$offset = $datetime->format('P');
1554
		} else $offset = '+00:00';
1555
1556
		if ($globalDBdriver == 'mysql') {
1557
			$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
1558
								FROM marine_output";
1559
			$query .= $this->getFilter($filters);
1560
			$query .= " GROUP BY year_name, month_name ORDER BY date_count DESC";
1561
		} else {
1562
			$query  = "SELECT EXTRACT(YEAR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count
1563
								FROM marine_output";
1564
			$query .= $this->getFilter($filters);
1565
			$query .= " GROUP BY year_name, month_name ORDER BY date_count DESC";
1566
		}
1567
      
1568
		
1569
		$sth = $this->db->prepare($query);
1570
		$sth->execute(array(':offset' => $offset));
1571
      
1572
		$date_array = array();
1573
		$temp_array = array();
1574
        
1575
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1576
		{
1577
			$temp_array['month_name'] = $row['month_name'];
1578
			$temp_array['year_name'] = $row['year_name'];
1579
			$temp_array['date_count'] = $row['date_count'];
1580
1581
			$date_array[] = $temp_array;
1582
		}
1583
1584
		return $date_array;
1585
	}
1586
1587
	
1588
	
1589
1590
	/**
1591
	* Counts all dates during the last year
1592
	*
1593
	* @return Array the date list
1594
	*
1595
	*/
1596
	public function countAllMonthsLastYear($filters)
1597
	{
1598
		global $globalTimezone, $globalDBdriver;
1599
		if ($globalTimezone != '') {
1600
			date_default_timezone_set($globalTimezone);
1601
			$datetime = new DateTime();
1602
			$offset = $datetime->format('P');
1603
		} else $offset = '+00:00';
1604
		$filter_query = $this->getFilter($filters,true,true);
1605
		if ($globalDBdriver == 'mysql') {
1606
			$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
1607
								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
1608
			$query .= " GROUP BY year_name, month_name
1609
								ORDER BY year_name, month_name ASC";
1610
			$query_data = array(':offset' => $offset);
1611
		} else {
1612
			$query  = "SELECT EXTRACT(MONTH FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS month_name, EXTRACT(YEAR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS year_name, count(*) as date_count
1613
								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 YEARS'";
1614
			$query .= " GROUP BY year_name, month_name
1615
								ORDER BY year_name, month_name ASC";
1616
			$query_data = array(':offset' => $offset);
1617
    		}
1618
		
1619
		$sth = $this->db->prepare($query);
1620
		$sth->execute($query_data);
1621
      
1622
		$date_array = array();
1623
		$temp_array = array();
1624
        
1625
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1626
		{
1627
			$temp_array['year_name'] = $row['year_name'];
1628
			$temp_array['month_name'] = $row['month_name'];
1629
			$temp_array['date_count'] = $row['date_count'];
1630
          
1631
			$date_array[] = $temp_array;
1632
		}
1633
1634
		return $date_array;
1635
	}
1636
	
1637
	
1638
	
1639
	/**
1640
	* Counts all hours
1641
	*
1642
	* @return Array the hour list
1643
	*
1644
	*/
1645
	public function countAllHours($orderby,$filters = array())
1646
	{
1647
		global $globalTimezone, $globalDBdriver;
1648
		if ($globalTimezone != '') {
1649
			date_default_timezone_set($globalTimezone);
1650
			$datetime = new DateTime();
1651
			$offset = $datetime->format('P');
1652
		} else $offset = '+00:00';
1653
1654
		$orderby_sql = '';
1655
		if ($orderby == "hour")
1656
		{
1657
			$orderby_sql = "ORDER BY hour_name ASC";
1658
		}
1659
		if ($orderby == "count")
1660
		{
1661
			$orderby_sql = "ORDER BY hour_count DESC";
1662
		}
1663
		
1664
		if ($globalDBdriver == 'mysql') {
1665
			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1666
								FROM marine_output";
1667
			$query .= $this->getFilter($filters);
1668
			$query .= " GROUP BY hour_name 
1669
								".$orderby_sql;
1670
1671
/*		$query  = "SELECT HOUR(marine_output.date) AS hour_name, count(*) as hour_count
1672
								FROM marine_output 
1673
								GROUP BY hour_name 
1674
								".$orderby_sql."
1675
								LIMIT 10 OFFSET 00";
1676
  */    
1677
		$query_data = array(':offset' => $offset);
1678
		} else {
1679
			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1680
								FROM marine_output";
1681
			$query .= $this->getFilter($filters);
1682
			$query .= " GROUP BY hour_name 
1683
								".$orderby_sql;
1684
			$query_data = array(':offset' => $offset);
1685
		}
1686
		
1687
		$sth = $this->db->prepare($query);
1688
		$sth->execute($query_data);
1689
      
1690
		$hour_array = array();
1691
		$temp_array = array();
1692
        
1693
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1694
		{
1695
			$temp_array['hour_name'] = $row['hour_name'];
1696
			$temp_array['hour_count'] = $row['hour_count'];
1697
          
1698
			$hour_array[] = $temp_array;
1699
		}
1700
1701
		return $hour_array;
1702
	}
1703
	
1704
	
1705
	
1706
	/**
1707
	* Counts all hours by date
1708
	*
1709
	* @return Array the hour list
1710
	*
1711
	*/
1712
	public function countAllHoursByDate($date, $filters = array())
1713
	{
1714
		global $globalTimezone, $globalDBdriver;
1715
		$filter_query = $this->getFilter($filters,true,true);
1716
		$date = filter_var($date,FILTER_SANITIZE_STRING);
1717
		if ($globalTimezone != '') {
1718
			date_default_timezone_set($globalTimezone);
1719
			$datetime = new DateTime($date);
1720
			$offset = $datetime->format('P');
1721
		} else $offset = '+00:00';
1722
1723
		if ($globalDBdriver == 'mysql') {
1724
			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1725
								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1726
								GROUP BY hour_name 
1727
								ORDER BY hour_name ASC";
1728
		} else {
1729
			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1730
								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1731
								GROUP BY hour_name 
1732
								ORDER BY hour_name ASC";
1733
		}
1734
		
1735
		$sth = $this->db->prepare($query);
1736
		$sth->execute(array(':date' => $date, ':offset' => $offset));
1737
      
1738
		$hour_array = array();
1739
		$temp_array = array();
1740
        
1741
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1742
		{
1743
			$temp_array['hour_name'] = $row['hour_name'];
1744
			$temp_array['hour_count'] = $row['hour_count'];
1745
          
1746
			$hour_array[] = $temp_array;
1747
		}
1748
1749
		return $hour_array;
1750
	}
1751
	
1752
	
1753
	
1754
	/**
1755
	* Counts all hours by a ident/callsign
1756
	*
1757
	* @return Array the hour list
1758
	*
1759
	*/
1760
	public function countAllHoursByIdent($ident, $filters = array())
1761
	{
1762
		global $globalTimezone, $globalDBdriver;
1763
		$filter_query = $this->getFilter($filters,true,true);
1764
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1765
		if ($globalTimezone != '') {
1766
			date_default_timezone_set($globalTimezone);
1767
			$datetime = new DateTime();
1768
			$offset = $datetime->format('P');
1769
		} else $offset = '+00:00';
1770
1771
		if ($globalDBdriver == 'mysql') {
1772
			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1773
								FROM marine_output".$filter_query." marine_output.ident = :ident 
1774
								GROUP BY hour_name 
1775
								ORDER BY hour_name ASC";
1776
		} else {
1777
			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1778
								FROM marine_output".$filter_query." marine_output.ident = :ident 
1779
								GROUP BY hour_name 
1780
								ORDER BY hour_name ASC";
1781
		}
1782
      
1783
		
1784
		$sth = $this->db->prepare($query);
1785
		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1786
      
1787
		$hour_array = array();
1788
		$temp_array = array();
1789
        
1790
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1791
		{
1792
			$temp_array['hour_name'] = $row['hour_name'];
1793
			$temp_array['hour_count'] = $row['hour_count'];
1794
          
1795
			$hour_array[] = $temp_array;
1796
		}
1797
1798
		return $hour_array;
1799
	}
1800
	
1801
	
1802
	
1803
	/**
1804
	* Counts all vessels
1805
	*
1806
	* @return Integer the number of vessels
1807
	*
1808
	*/
1809
	public function countOverallMarine($filters = array(),$year = '',$month = '')
1810
	{
1811
		global $globalDBdriver;
1812
		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1813
		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output";
1814
		$query_values = array();
1815
		$query = '';
1816
		if ($year != '') {
1817
			if ($globalDBdriver == 'mysql') {
1818
				$query .= " AND YEAR(marine_output.date) = :year";
1819
				$query_values = array_merge($query_values,array(':year' => $year));
1820
			} else {
1821
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1822
				$query_values = array_merge($query_values,array(':year' => $year));
1823
			}
1824
		}
1825
		if ($month != '') {
1826
			if ($globalDBdriver == 'mysql') {
1827
				$query .= " AND MONTH(marine_output.date) = :month";
1828
				$query_values = array_merge($query_values,array(':month' => $month));
1829
			} else {
1830
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1831
				$query_values = array_merge($query_values,array(':month' => $month));
1832
			}
1833
		}
1834
		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1835
		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1836
		
1837
		$sth = $this->db->prepare($queryi);
1838
		$sth->execute($query_values);
1839
		return $sth->fetchColumn();
1840
	}
1841
	
1842
	/**
1843
	* Counts all vessel type
1844
	*
1845
	* @return Integer the number of vessels
1846
	*
1847
	*/
1848
	public function countOverallMarineTypes($filters = array(),$year = '',$month = '')
1849
	{
1850
		global $globalDBdriver;
1851
		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output";
1852
		$query_values = array();
1853
		$query = '';
1854
		if ($year != '') {
1855
			if ($globalDBdriver == 'mysql') {
1856
				$query .= " AND YEAR(marine_output.date) = :year";
1857
				$query_values = array_merge($query_values,array(':year' => $year));
1858
			} else {
1859
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1860
				$query_values = array_merge($query_values,array(':year' => $year));
1861
			}
1862
		}
1863
		if ($month != '') {
1864
			if ($globalDBdriver == 'mysql') {
1865
				$query .= " AND MONTH(marine_output.date) = :month";
1866
				$query_values = array_merge($query_values,array(':month' => $month));
1867
			} else {
1868
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1869
				$query_values = array_merge($query_values,array(':month' => $month));
1870
			}
1871
		}
1872
		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1873
		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1874
		
1875
		$sth = $this->db->prepare($queryi);
1876
		$sth->execute($query_values);
1877
		return $sth->fetchColumn();
1878
	}
1879
	
1880
  
1881
	/**
1882
	* Counts all hours of today
1883
	*
1884
	* @return Array the hour list
1885
	*
1886
	*/
1887
	public function countAllHoursFromToday($filters = array())
1888
	{
1889
		global $globalTimezone, $globalDBdriver;
1890
		$filter_query = $this->getFilter($filters,true,true);
1891
		if ($globalTimezone != '') {
1892
			date_default_timezone_set($globalTimezone);
1893
			$datetime = new DateTime();
1894
			$offset = $datetime->format('P');
1895
		} else $offset = '+00:00';
1896
1897
		if ($globalDBdriver == 'mysql') {
1898
			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1899
								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1900
								GROUP BY hour_name 
1901
								ORDER BY hour_name ASC";
1902
		} else {
1903
			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1904
								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1905
								GROUP BY hour_name 
1906
								ORDER BY hour_name ASC";
1907
		}
1908
		
1909
		$sth = $this->db->prepare($query);
1910
		$sth->execute(array(':offset' => $offset));
1911
      
1912
		$hour_array = array();
1913
		$temp_array = array();
1914
        
1915
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1916
		{
1917
			$temp_array['hour_name'] = $row['hour_name'];
1918
			$temp_array['hour_count'] = $row['hour_count'];
1919
			$hour_array[] = $temp_array;
1920
		}
1921
1922
		return $hour_array;
1923
	}
1924
    
1925
    
1926
     /**
1927
	* Gets the Barrie Spotter ID based on the FlightAware ID
1928
	*
1929
	* @return Integer the Barrie Spotter ID
1930
q	*
1931
	*/
1932
	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1933
	{
1934
		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1935
1936
		$query  = "SELECT marine_output.marine_id
1937
				FROM marine_output 
1938
				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1939
        
1940
		
1941
		$sth = $this->db->prepare($query);
1942
		$sth->execute();
1943
1944
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1945
		{
1946
			return $row['marine_id'];
1947
		}
1948
	}
1949
  
1950
 
1951
	/**
1952
	* Parses a date string
1953
	*
1954
	* @param String $dateString the date string
1955
	* @param String $timezone the timezone of a user
1956
	* @return Array the time information
1957
	*
1958
	*/
1959
	public function parseDateString($dateString, $timezone = '')
1960
	{
1961
		$time_array = array();
1962
	
1963
		if ($timezone != "")
1964
		{
1965
			date_default_timezone_set($timezone);
1966
		}
1967
		
1968
		$current_date = date("Y-m-d H:i:s");
1969
		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1970
		
1971
		$diff = abs(strtotime($current_date) - strtotime($date));
1972
1973
		$time_array['years'] = floor($diff / (365*60*60*24)); 
1974
		$years = $time_array['years'];
1975
		
1976
		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1977
		$months = $time_array['months'];
1978
		
1979
		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1980
		$days = $time_array['days'];
1981
		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1982
		$hours = $time_array['hours'];
1983
		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1984
		$minutes = $time_array['minutes'];
1985
		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1986
		
1987
		return $time_array;
1988
	}
1989
	
1990
	/**
1991
	* Parses the direction degrees to working
1992
	*
1993
	* @param Float $direction the direction in degrees
1994
	* @return Array the direction information
1995
	*
1996
	*/
1997
	public function parseDirection($direction = 0)
1998
	{
1999
		if ($direction == '') $direction = 0;
2000
		$direction_array = array();
2001
		$temp_array = array();
2002
2003
		if ($direction == 360 || ($direction >= 0 && $direction < 22.5))
2004
		{
2005
			$temp_array['direction_degree'] = $direction;
2006
			$temp_array['direction_shortname'] = "N";
2007
			$temp_array['direction_fullname'] = "North";
2008
		} elseif ($direction >= 22.5 && $direction < 45){
2009
			$temp_array['direction_degree'] = $direction;
2010
			$temp_array['direction_shortname'] = "NNE";
2011
			$temp_array['direction_fullname'] = "North-Northeast";
2012
		} elseif ($direction >= 45 && $direction < 67.5){
2013
			$temp_array['direction_degree'] = $direction;
2014
			$temp_array['direction_shortname'] = "NE";
2015
			$temp_array['direction_fullname'] = "Northeast";
2016
		} elseif ($direction >= 67.5 && $direction < 90){
2017
			$temp_array['direction_degree'] = $direction;
2018
			$temp_array['direction_shortname'] = "ENE";
2019
			$temp_array['direction_fullname'] = "East-Northeast";
2020
		} elseif ($direction >= 90 && $direction < 112.5){
2021
			$temp_array['direction_degree'] = $direction;
2022
			$temp_array['direction_shortname'] = "E";
2023
			$temp_array['direction_fullname'] = "East";
2024
		} elseif ($direction >= 112.5 && $direction < 135){
2025
			$temp_array['direction_degree'] = $direction;
2026
			$temp_array['direction_shortname'] = "ESE";
2027
			$temp_array['direction_fullname'] = "East-Southeast";
2028
		} elseif ($direction >= 135 && $direction < 157.5){
2029
			$temp_array['direction_degree'] = $direction;
2030
			$temp_array['direction_shortname'] = "SE";
2031
			$temp_array['direction_fullname'] = "Southeast";
2032
		} elseif ($direction >= 157.5 && $direction < 180){
2033
			$temp_array['direction_degree'] = $direction;
2034
			$temp_array['direction_shortname'] = "SSE";
2035
			$temp_array['direction_fullname'] = "South-Southeast";
2036
		} elseif ($direction >= 180 && $direction < 202.5){
2037
			$temp_array['direction_degree'] = $direction;
2038
			$temp_array['direction_shortname'] = "S";
2039
			$temp_array['direction_fullname'] = "South";
2040
		} elseif ($direction >= 202.5 && $direction < 225){
2041
			$temp_array['direction_degree'] = $direction;
2042
			$temp_array['direction_shortname'] = "SSW";
2043
			$temp_array['direction_fullname'] = "South-Southwest";
2044
		} elseif ($direction >= 225 && $direction < 247.5){
2045
			$temp_array['direction_degree'] = $direction;
2046
			$temp_array['direction_shortname'] = "SW";
2047
			$temp_array['direction_fullname'] = "Southwest";
2048
		} elseif ($direction >= 247.5 && $direction < 270){
2049
			$temp_array['direction_degree'] = $direction;
2050
			$temp_array['direction_shortname'] = "WSW";
2051
			$temp_array['direction_fullname'] = "West-Southwest";
2052
		} elseif ($direction >= 270 && $direction < 292.5){
2053
			$temp_array['direction_degree'] = $direction;
2054
			$temp_array['direction_shortname'] = "W";
2055
			$temp_array['direction_fullname'] = "West";
2056
		} elseif ($direction >= 292.5 && $direction < 315){
2057
			$temp_array['direction_degree'] = $direction;
2058
			$temp_array['direction_shortname'] = "WNW";
2059
			$temp_array['direction_fullname'] = "West-Northwest";
2060
		} elseif ($direction >= 315 && $direction < 337.5){
2061
			$temp_array['direction_degree'] = $direction;
2062
			$temp_array['direction_shortname'] = "NW";
2063
			$temp_array['direction_fullname'] = "Northwest";
2064
		} elseif ($direction >= 337.5 && $direction < 360){
2065
			$temp_array['direction_degree'] = $direction;
2066
			$temp_array['direction_shortname'] = "NNW";
2067
			$temp_array['direction_fullname'] = "North-Northwest";
2068
		}
2069
		$direction_array[] = $temp_array;
2070
		return $direction_array;
2071
	}
2072
	
2073
	
2074
	/**
2075
	* Gets Country from latitude/longitude
2076
	*
2077
	* @param Float $latitude latitute of the flight
2078
	* @param Float $longitude longitute of the flight
2079
	* @return String the countrie
2080
	*/
2081
	public function getCountryFromLatitudeLongitude($latitude,$longitude)
2082
	{
2083
		global $globalDBdriver, $globalDebug;
2084
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
2085
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
2086
	
2087
		$Connection = new Connection($this->db);
2088
		if (!$Connection->tableExists('countries')) return '';
2089
	
2090
		try {
2091
			/*
2092
			if ($globalDBdriver == 'mysql') {
2093
				//$query  = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(:latitude :longitude)'), ogc_geom) LIMIT 1";
2094
				$query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(".$longitude.' '.$latitude.")'), ogc_geom) LIMIT 1";
2095
			}
2096
			*/
2097
			// This query seems to work both for MariaDB and PostgreSQL
2098
			$query = "SELECT name,iso2,iso3 FROM countries WHERE ST_Within(ST_GeomFromText('POINT(".$longitude." ".$latitude.")',4326), ogc_geom) LIMIT 1";
2099
		
2100
			$sth = $this->db->prepare($query);
2101
			//$sth->execute(array(':latitude' => $latitude,':longitude' => $longitude));
2102
			$sth->execute();
2103
    
2104
			$row = $sth->fetch(PDO::FETCH_ASSOC);
2105
			$sth->closeCursor();
2106
			if (count($row) > 0) {
2107
				return $row;
2108
			} else return '';
2109
		} catch (PDOException $e) {
2110
			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
2111
			return '';
2112
		}
2113
	
2114
	}
2115
2116
	/**
2117
	* Gets Country from iso2
2118
	*
2119
	* @param String $iso2 ISO2 country code
2120
	* @return String the countrie
2121
	*/
2122
	public function getCountryFromISO2($iso2)
2123
	{
2124
		global $globalDBdriver, $globalDebug;
2125
		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
2126
	
2127
		$Connection = new Connection($this->db);
2128
		if (!$Connection->tableExists('countries')) return '';
2129
	
2130
		try {
2131
			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
2132
		
2133
			$sth = $this->db->prepare($query);
2134
			$sth->execute(array(':iso2' => $iso2));
2135
    
2136
			$row = $sth->fetch(PDO::FETCH_ASSOC);
2137
			$sth->closeCursor();
2138
			if (count($row) > 0) {
2139
				return $row;
2140
			} else return '';
2141
		} catch (PDOException $e) {
2142
			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
2143
			return '';
2144
		}
2145
	
2146
	}
2147
2148
	
2149
	/**
2150
	* Gets the short url from bit.ly
2151
	*
2152
	* @param String $url the full url
2153
	* @return String the bit.ly url
2154
	*
2155
	*/
2156
	public function getBitlyURL($url)
2157
	{
2158
		global $globalBitlyAccessToken;
2159
		
2160
		if ($globalBitlyAccessToken == '') return $url;
2161
        
2162
		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
2163
		
2164
		$ch = curl_init();
2165
		curl_setopt($ch, CURLOPT_HEADER, 0);
2166
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
2167
		curl_setopt($ch, CURLOPT_URL, $google_url);
2168
		$bitly_data = curl_exec($ch);
2169
		curl_close($ch);
2170
		
2171
		$bitly_data = json_decode($bitly_data);
2172
		$bitly_url = '';
2173
		if ($bitly_data->status_txt = "OK"){
2174
			$bitly_url = $bitly_data->data->url;
2175
		}
2176
2177
		return $bitly_url;
2178
	}
2179
2180
	
2181
	/**
2182
	* Gets all vessels types that have flown over
2183
	*
2184
	* @return Array the vessel type list
2185
	*
2186
	*/
2187
	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '')
2188
	{
2189
		global $globalDBdriver;
2190
		$filter_query = $this->getFilter($filters,true,true);
2191
		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id 
2192
		    FROM marine_output ".$filter_query." marine_output.type <> '' AND marine_output.type_id IS NOT NULL";
2193
		if ($olderthanmonths > 0) {
2194
			if ($globalDBdriver == 'mysql') {
2195
				$query .= ' AND marine_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)';
2196
			} else {
2197
				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
2198
			}
2199
		}
2200
		if ($sincedate != '') {
2201
			if ($globalDBdriver == 'mysql') {
2202
				$query .= " AND marine_output.date > '".$sincedate."'";
2203
			} else {
2204
				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
2205
			}
2206
		}
2207
		$query_values = array();
2208
		if ($year != '') {
2209
			if ($globalDBdriver == 'mysql') {
2210
				$query .= " AND YEAR(marine_output.date) = :year";
2211
				$query_values = array_merge($query_values,array(':year' => $year));
2212
			} else {
2213
				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
2214
				$query_values = array_merge($query_values,array(':year' => $year));
2215
			}
2216
		}
2217
		if ($month != '') {
2218
			if ($globalDBdriver == 'mysql') {
2219
				$query .= " AND MONTH(marine_output.date) = :month";
2220
				$query_values = array_merge($query_values,array(':month' => $month));
2221
			} else {
2222
				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
2223
				$query_values = array_merge($query_values,array(':month' => $month));
2224
			}
2225
		}
2226
		if ($day != '') {
2227
			if ($globalDBdriver == 'mysql') {
2228
				$query .= " AND DAY(marine_output.date) = :day";
2229
				$query_values = array_merge($query_values,array(':day' => $day));
2230
			} else {
2231
				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
2232
				$query_values = array_merge($query_values,array(':day' => $day));
2233
			}
2234
		}
2235
		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC";
2236
		if ($limit) $query .= " LIMIT 10 OFFSET 0";
2237
		$sth = $this->db->prepare($query);
2238
		$sth->execute($query_values);
2239
		$marine_array = array();
2240
		$temp_array = array();
2241
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2242
		{
2243
			$temp_array['marine_type'] = $row['marine_type'];
2244
			$temp_array['marine_type_id'] = $row['marine_type_id'];
2245
			$temp_array['marine_type_count'] = $row['marine_type_count'];
2246
			$marine_array[] = $temp_array;
2247
		}
2248
		return $marine_array;
2249
	}
2250
2251
	/**
2252
	* Gets all the tracker information
2253
	*
2254
	* @return Array the tracker information
2255
	*
2256
	*/
2257
	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array())
0 ignored issues
show
Unused Code introduced by
The parameter $includegeodata is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2258
	{
2259
		global $globalTimezone, $globalDBdriver;
2260
		date_default_timezone_set('UTC');
2261
		$query_values = array();
2262
		$additional_query = '';
2263
		$filter_query = $this->getFilter($filters,true,true);
2264
		if ($q != "")
2265
		{
2266
			if (!is_string($q))
2267
			{
2268
				return false;
2269
			} else {
2270
				$q_array = explode(" ", $q);
2271
				foreach ($q_array as $q_item){
2272
					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
2273
					$additional_query .= " AND (";
2274
					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR ";
2275
					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR ";
2276
					if (is_int($q_item)) $additional_query .= "(marine_output.imo = '".$q_item."') OR ";
2277
					$additional_query .= "(marine_output.ident like '%".$q_item."%') OR ";
2278
					$additional_query .= ")";
2279
				}
2280
			}
2281
		}
2282
		if ($callsign != "")
2283
		{
2284
			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
2285
			if (!is_string($callsign))
2286
			{
2287
				return false;
2288
			} else {
2289
				$additional_query .= " AND marine_output.ident = :callsign";
2290
				$query_values = array_merge($query_values,array(':callsign' => $callsign));
2291
			}
2292
		}
2293
		if ($mmsi != "")
2294
		{
2295
			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING);
2296
			if (!is_numeric($mmsi))
2297
			{
2298
				return false;
2299
			} else {
2300
				$additional_query .= " AND marine_output.mmsi = :mmsi";
2301
				$query_values = array_merge($query_values,array(':mmsi' => $mmsi));
2302
			}
2303
		}
2304
		if ($imo != "")
2305
		{
2306
			$imo = filter_var($imo,FILTER_SANITIZE_STRING);
2307
			if (!is_numeric($imo))
2308
			{
2309
				return false;
2310
			} else {
2311
				$additional_query .= " AND marine_output.imo = :imo";
2312
				$query_values = array_merge($query_values,array(':imo' => $imo));
2313
			}
2314
		}
2315
		if ($date_posted != "")
2316
		{
2317
			$date_array = explode(",", $date_posted);
2318
			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING);
2319
			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING);
2320
			if ($globalTimezone != '') {
2321
				date_default_timezone_set($globalTimezone);
2322
				$datetime = new DateTime();
2323
				$offset = $datetime->format('P');
2324
			} else $offset = '+00:00';
2325
			if ($date_array[1] != "")
2326
			{
2327
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
2328
				$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1]));
2329
				if ($globalDBdriver == 'mysql') {
2330
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' ";
2331
				} else {
2332
					$additional_query .= " AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) <= '".$date_array[1]."' ";
2333
				}
2334
			} else {
2335
				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0]));
2336
				if ($globalDBdriver == 'mysql') {
2337
					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' ";
2338
				} else {
2339
					$additional_query .= " AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' ";
2340
				}
2341
			}
2342
		}
2343
		if ($limit != "")
2344
		{
2345
			$limit_array = explode(",", $limit);
2346
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
2347
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
2348
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
2349
			{
2350
				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
2351
			} else $limit_query = "";
2352
		} else $limit_query = "";
2353
		if ($sort != "")
2354
		{
2355
			$search_orderby_array = $this->getOrderBy();
2356
			$orderby_query = $search_orderby_array[$sort]['sql'];
2357
		} else {
2358
			if ($origLat != "" && $origLon != "" && $dist != "") {
2359
				$orderby_query = " ORDER BY distance ASC";
2360
			} else {
2361
				$orderby_query = " ORDER BY marine_output.date DESC";
2362
			}
2363
		}
2364
		if ($origLat != "" && $origLon != "" && $dist != "") {
2365
			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile
2366
			if ($globalDBdriver == 'mysql') {
2367
				$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 
2368
				    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)) 
2369
				    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;
2370
			} else {
2371
				$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 
2372
				    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)) 
2373
				    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;
2374
			}
2375
		} else {
2376
			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> '' 
2377
			    ".$additional_query."
2378
			    ".$orderby_query;
2379
		}
2380
		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query);
2381
		return $marine_array;
2382
	}
2383
2384
	/**
2385
	* Check marine by id
2386
	*
2387
	* @return String the ident
2388
	*
2389
	*/
2390
	public function checkId($id)
2391
	{
2392
		global $globalDBdriver, $globalTimezone;
2393
		$query  = 'SELECT marine_output.ident, marine_output.fammarine_id FROM marine_output WHERE marine_output.fammarine_id = :id';
2394
		$query_data = array(':id' => $id);
2395
		$sth = $this->db->prepare($query);
2396
		$sth->execute($query_data);
2397
		$ident_result='';
2398
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
2399
		{
2400
			$ident_result = $row['fammarine_id'];
2401
		}
2402
		return $ident_result;
2403
	}
2404
2405
	public function getOrderBy()
2406
	{
2407
		$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"));
2408
		
2409
		return $orderby;
2410
		
2411
	}
2412
    
2413
}
2414
?>