Completed
Push — master ( 5cca80...e591d4 )
by Yannick
29:03
created

MarineLive   D

Complexity

Total Complexity 198

Size/Duplication

Total Lines 1108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 1108
rs 4.4102
c 0
b 0
f 0
wmc 198
lcom 1
cbo 4

28 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
F getFilter() 0 77 42
D getLiveMarineData() 0 40 9
B getMinLiveMarineData() 0 27 4
F getMinLastLiveMarineData() 0 77 29
C getMinLastLiveMarineDataByID() 0 57 14
B getLiveMarineCount() 0 22 4
A getLiveMarineDatabyCoord() 0 21 4
C getMinLiveMarineDatabyCoord() 0 66 8
C getLatestMarineForLayar() 0 54 11
A getLastLiveMarineDataByIdent() 0 12 1
A getDateLiveMarineDataByIdent() 0 10 1
A getDateLiveMarineDataByMMSI() 0 10 1
A getLastLiveMarineDataById() 0 12 1
A getDateLiveMarineDataById() 0 12 1
B getAllLiveMarineDataById() 0 26 5
A getAllLiveMarineDataByIdent() 0 16 2
A deleteLiveMarineData() 0 21 3
C deleteLiveMarineDataNotUpdated() 0 91 11
A deleteLiveMarineDataByIdent() 0 15 2
A deleteLiveMarineDataById() 0 15 2
A getAllRaces() 0 7 1
B getIdentFromLastHour() 0 26 3
B checkIdentRecent() 0 26 3
B checkIdRecent() 0 26 3
B checkMMSIRecent() 0 26 3
F addLiveMarineData() 0 108 27
A getOrderBy() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like MarineLive 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 MarineLive, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * This class is part of FlightAirmap. It's used for marine live data
4
 *
5
 * Copyright (c) Ycarus (Yannick Chabanois) <[email protected]>
6
 * Licensed under AGPL license.
7
 * For more information see: https://www.flightairmap.com/
8
*/
9
//$global_query = "SELECT marine_live.* FROM marine_live";
10
11
class MarineLive {
12
	public $db;
13
	static $global_query = "SELECT marine_live.* FROM marine_live";
14
15
	public function __construct($dbc = null) {
16
		$Connection = new Connection($dbc);
17
		$this->db = $Connection->db();
18
		if ($this->db === null) die('Error: No DB connection. (MarineLive)');
19
	}
20
21
22
	/**
23
	* Get SQL query part for filter used
24
	* @param Array $filter the filter
25
	* @return Array the SQL part
26
	*/
27
	public function getFilter($filter = array(),$where = false,$and = false) {
28
		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
29
		$filters = array();
30
		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
31
			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
32
				$filters = $globalStatsFilters[$globalFilterName];
33
			} else {
34
				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
35
			}
36
		}
37
		if (isset($filter[0]['source'])) {
38
			$filters = array_merge($filters,$filter);
39
		}
40
		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
41
		$filter_query_join = '';
42
		$filter_query_where = '';
43
		foreach($filters as $flt) {
44
			if (isset($flt['idents']) && !empty($flt['idents'])) {
45
				if (isset($flt['source'])) {
46
					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
47
				} else {
48
					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
49
				}
50
			}
51
		}
52
		if (isset($filter['source']) && !empty($filter['source'])) {
53
			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
54
		}
55
		if (isset($filter['ident']) && !empty($filter['ident'])) {
56
			$filter_query_where .= " AND ident = '".$filter['ident']."'";
57
		}
58
		if (isset($filter['id']) && !empty($filter['id'])) {
59
			$filter_query_where .= " AND fammarine_id = '".$filter['id']."'";
60
		}
61
		if (isset($filter['mmsi']) && !empty($filter['mmsi'])) {
62
			$filter_query_where .= " AND mmsi = '".$filter['mmsi']."'";
63
		}
64
		if (isset($filter['race']) && !empty($filter['race'])) {
65
			$filter_query_where .= " AND race_id = '".$filter['race']."'";
66
		}
67
		if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) {
68
			$filter_query_date = '';
69
			
70
			if (isset($filter['year']) && $filter['year'] != '') {
71
				if ($globalDBdriver == 'mysql') {
72
					$filter_query_date .= " AND YEAR(marine_output.date) = '".$filter['year']."'";
73
				} else {
74
					$filter_query_date .= " AND EXTRACT(YEAR FROM marine_output.date) = '".$filter['year']."'";
75
				}
76
			}
77
			if (isset($filter['month']) && $filter['month'] != '') {
78
				if ($globalDBdriver == 'mysql') {
79
					$filter_query_date .= " AND MONTH(marine_output.date) = '".$filter['month']."'";
80
				} else {
81
					$filter_query_date .= " AND EXTRACT(MONTH FROM marine_output.date) = '".$filter['month']."'";
82
				}
83
			}
84
			if (isset($filter['day']) && $filter['day'] != '') {
85
				if ($globalDBdriver == 'mysql') {
86
					$filter_query_date .= " AND DAY(marine_output.date) = '".$filter['day']."'";
87
				} else {
88
					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
89
				}
90
			}
91
			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
92
		}
93
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
94
			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
95
		}
96
		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
97
		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
98
		if ($filter_query_where != '') {
99
			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
100
		}
101
		$filter_query = $filter_query_join.$filter_query_where;
102
		return $filter_query;
103
	}
104
105
	/**
106
	* Gets all the spotter information based on the latest data entry
107
	*
108
	* @return Array the spotter information
109
	*
110
	*/
111
	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
112
	{
113
		global $globalDBdriver, $globalLiveInterval;
114
		$Marine = new Marine($this->db);
115
		date_default_timezone_set('UTC');
116
117
		$filter_query = $this->getFilter($filter);
118
		$limit_query = '';
119
		if ($limit != '')
120
		{
121
			$limit_array = explode(',', $limit);
122
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
123
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
124
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
125
			{
126
				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
127
			}
128
		}
129
		$orderby_query = '';
130
		if ($sort != '')
131
		{
132
			$search_orderby_array = $this->getOrderBy();
133
			if (isset($search_orderby_array[$sort]['sql'])) 
134
			{
135
				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
136
			}
137
		}
138
		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
139
140
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
141
		if ($globalDBdriver == 'mysql') {
142
			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
143
			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
144
		} else {
145
			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
146
		}
147
		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
148
149
		return $spotter_array;
150
	}
151
152
	/**
153
	* Gets Minimal Live Spotter data
154
	*
155
	* @return Array the spotter information
156
	*
157
	*/
158
	public function getMinLiveMarineData($filter = array())
159
	{
160
		global $globalDBdriver, $globalLiveInterval;
161
		date_default_timezone_set('UTC');
162
163
		$filter_query = $this->getFilter($filter,true,true);
164
165
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
166
		if ($globalDBdriver == 'mysql') {
167
			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
168
			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY marine_live.race_rank";
169
		} else {
170
			$query  = "SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
171
			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query." marine_live.latitude <> '0' AND marine_live.longitude <> '0' ORDER BY marine_live.race_rank";
172
		}
173
174
		try {
175
			$sth = $this->db->prepare($query);
176
			$sth->execute();
177
		} catch(PDOException $e) {
178
			echo $e->getMessage();
179
			die;
180
		}
181
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
182
183
		return $spotter_array;
184
	}
185
186
	/**
187
	* Gets Minimal Live Spotter data since xx seconds
188
	*
189
	* @return Array the spotter information
190
	*
191
	*/
192
	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false, $id = '')
193
	{
194
		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
195
		date_default_timezone_set('UTC');
196
		$usecoord = false;
197
		if (is_array($coord) && !empty($coord)) {
198
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
199
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
200
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
201
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
202
			$usecoord = true;
203
		}
204
		$id = filter_var($id,FILTER_SANITIZE_STRING);
205
		$filter_query = $this->getFilter($filter,true,true);
206
207
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
208
		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
209
		if ($globalDBdriver == 'mysql') {
210
			if (isset($globalArchive) && $globalArchive === TRUE) {
211
				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
212
				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
213
				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
0 ignored issues
show
Bug introduced by
The variable $minlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlat does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $minlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $maxlong does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
214
				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
215
				$query .= "UNION
216
				    SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
217
				    FROM marine_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date";
218
				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
219
				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
220
				$query .= ") AS marine 
221
				    WHERE latitude <> '0' AND longitude <> '0' 
222
				    ORDER BY fammarine_id, date";
223
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
224
			} else {
225
				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
226
				    FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date ";
227
				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
228
				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
229
				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
230
				ORDER BY marine_live.fammarine_id, marine_live.date";
231
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
232
			}
233
		} else {
234
			if (isset($globalArchive) && $globalArchive === TRUE) {
235
				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
236
				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
237
				if ($usecoord) $query .= "AND (marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
238
				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
239
				$query .= "UNION
240
				    SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
241
				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date";
242
				if ($usecoord) $query .= " AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
243
				if ($id != '') $query .= " OR marine_live.fammarine_id = :id";
244
				$query .= ") AS marine WHERE latitude <> '0' AND longitude <> '0' ";
245
				$query .= "ORDER BY fammarine_id, date";
246
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
247
			} else {
248
				$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
249
				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date ";
250
				if ($usecoord) $query .= "AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
251
				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
252
				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
253
				ORDER BY marine_live.fammarine_id, marine_live.date";
254
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
255
			}
256
		}
257
		$query_values = array();
258
		if ($id != '') $query_values = array(':id' => $id);
259
		try {
260
			$sth = $this->db->prepare($query);
261
			$sth->execute($query_values);
262
		} catch(PDOException $e) {
263
			echo $e->getMessage();
264
			die;
265
		}
266
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
267
		return $spotter_array;
268
	}
269
270
	/**
271
	* Gets Minimal Live Spotter data since xx seconds
272
	*
273
	* @return Array the spotter information
274
	*
275
	*/
276
	public function getMinLastLiveMarineDataByID($id = '',$filter = array(), $limit = false)
277
	{
278
		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
279
		date_default_timezone_set('UTC');
280
		$id = filter_var($id,FILTER_SANITIZE_STRING);
281
		$filter_query = $this->getFilter($filter,true,true);
282
283
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
284
		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
285
		if ($globalDBdriver == 'mysql') {
286
			if (isset($globalArchive) && $globalArchive === TRUE) {
287
				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
288
				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' marine_live.fammarine_id = :id) l ON l.fammarine_id = marine_archive.fammarine_id ';
289
				$query .= "UNION
290
				    SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
291
				    FROM marine_live".$filter_query.' marine_live.fammarine_id = :id';
292
				$query .= ") AS marine 
293
				    WHERE latitude <> '0' AND longitude <> '0' 
294
				    ORDER BY fammarine_id, date";
295
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
296
			} else {
297
				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
298
				    FROM marine_live'.$filter_query.' marine_live.fammarine_id = :id ';
299
				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
300
				ORDER BY marine_live.fammarine_id, marine_live.date";
301
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
302
			}
303
		} else {
304
			if (isset($globalArchive) && $globalArchive === TRUE) {
305
				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
306
				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live".$filter_query." marine_live.fammarine_id = :id) l ON l.fammarine_id = marine_archive.fammarine_id ";
307
				$query .= "UNION
308
				    SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
309
				    FROM marine_live".$filter_query." marine_live.fammarine_id = :id";
310
				$query .= ") AS marine 
311
				    WHERE latitude <> '0' AND longitude <> '0' 
312
				    ORDER BY fammarine_id, date";
313
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
314
			} else {
315
				$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
316
				    FROM marine_live".$filter_query." marine_live.fammarine_id = :id ";
317
				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
318
				ORDER BY marine_live.fammarine_id, marine_live.date";
319
				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
320
			}
321
		}
322
		$query_values = array(':id' => $id);
323
		try {
324
			$sth = $this->db->prepare($query);
325
			$sth->execute($query_values);
326
		} catch(PDOException $e) {
327
			echo $e->getMessage();
328
			die;
329
		}
330
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
331
		return $spotter_array;
332
	}
333
334
	/**
335
	* Gets number of latest data entry
336
	*
337
	* @return String number of entry
338
	*
339
	*/
340
	public function getLiveMarineCount($filter = array())
341
	{
342
		global $globalDBdriver, $globalLiveInterval;
343
		$filter_query = $this->getFilter($filter,true,true);
344
345
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
346
		if ($globalDBdriver == 'mysql') {
347
			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
348
		} else {
349
			$query = "SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
350
		}
351
		try {
352
			$sth = $this->db->prepare($query);
353
			$sth->execute();
354
		} catch(PDOException $e) {
355
			echo $e->getMessage();
356
			die;
357
		}
358
		$result = $sth->fetch(PDO::FETCH_ASSOC);
359
		$sth->closeCursor();
360
		return $result['nb'];
361
	}
362
363
	/**
364
	* Gets all the spotter information based on the latest data entry and coord
365
	*
366
	* @return Array the spotter information
367
	*
368
	*/
369
	public function getLiveMarineDatabyCoord($coord, $filter = array())
370
	{
371
		global $globalDBdriver, $globalLiveInterval;
372
		$Marine = new Marine($this->db);
373
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
374
		$filter_query = $this->getFilter($filter);
375
376
		if (is_array($coord)) {
377
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
378
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
379
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
380
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
381
		} else return array();
382
		if ($globalDBdriver == 'mysql') {
383
			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id ORDER BY date DESC'.$filter_query;
384
		} else {
385
			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE NOW() at time zone 'UTC'  - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." GROUP BY marine_live.fammarine_id ORDEr BY date DESC".$filter_query;
386
		}
387
		$spotter_array = $Marine->getDataFromDB($query);
388
		return $spotter_array;
389
	}
390
391
	/**
392
	* Gets all the spotter information based on the latest data entry and coord
393
	*
394
	* @return Array the spotter information
395
	*
396
	*/
397
	public function getMinLiveMarineDatabyCoord($coord, $filter = array())
398
	{
399
		global $globalDBdriver, $globalLiveInterval, $globalArchive;
400
		$Marine = new Marine($this->db);
401
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
402
		$filter_query = $this->getFilter($filter,true,true);
403
404
		if (is_array($coord)) {
405
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
406
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
407
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
408
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
409
		} else return array();
410
		/*
411
		if ($globalDBdriver == 'mysql') {
412
			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
413
			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' AND marine_live.latitude BETWEEN ".$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong."
414
			ORDER BY marine_live.fammarine_id, marine_live.date";
415
		} else {
416
			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
417
			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong."
418
			ORDER BY marine_live.fammarine_id, marine_live.date";
419
		}
420
		*/
421
		if ($globalDBdriver == 'mysql') {
422
			if (isset($globalArchive) && $globalArchive === TRUE) {
423
				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
424
				    FROM marine_live 
425
				    '.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= marine_live.date 
426
				    AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
427
				    AND marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY race_rank,date DESC';
428
			} else {
429
				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
430
				    FROM marine_live 
431
				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
432
				    FROM marine_live l 
433
				    WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date 
434
				    AND l.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND l.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
435
				    GROUP BY l.fammarine_id
436
				    ) s on marine_live.fammarine_id = s.fammarine_id 
437
				    AND marine_live.date = s.maxdate'.$filter_query.' marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY race_rank, date DESC';
438
			}
439
		} else {
440
			if (isset($globalArchive) && $globalArchive === TRUE) {
441
				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
442
				    FROM marine_live 
443
				    ".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date 
444
				    AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." 
445
				    AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." 
446
				    AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' ORDER BY race_rank, date DESC";
447
			} else {
448
				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
449
				    FROM marine_live 
450
				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
451
				    FROM marine_live l 
452
				    WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date 
453
				    AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." 
454
				    AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." 
455
				    GROUP BY l.fammarine_id
456
				    ) s on marine_live.fammarine_id = s.fammarine_id 
457
				    AND marine_live.date = s.maxdate".$filter_query." marine_live.latitude <> '0' AND marine_live.longitude <> '0' ORDER BY race_rank,date DESC";
458
			}
459
		}
460
		$spotter_array = $Marine->getDataFromDB($query);
461
		return $spotter_array;
462
	}
463
464
	/**
465
	* Gets all the spotter information based on a user's latitude and longitude
466
	*
467
	* @return Array the spotter information
468
	*
469
	*/
470
	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
471
	{
472
		$Marine = new Marine($this->db);
473
		date_default_timezone_set('UTC');
474
		if ($lat != '') {
475
			if (!is_numeric($lat)) {
476
				return false;
477
			}
478
		}
479
		if ($lng != '')
480
		{
481
			if (!is_numeric($lng))
482
                        {
483
                                return false;
484
                        }
485
                }
486
487
                if ($radius != '')
488
                {
489
                        if (!is_numeric($radius))
490
                        {
491
                                return false;
492
                        }
493
                }
494
		$additional_query = '';
495
		if ($interval != '')
496
                {
497
                        if (!is_string($interval))
498
                        {
499
                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
500
			        return false;
501
                        } else {
502
                if ($interval == '1m')
503
                {
504
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
505
                } else if ($interval == '15m'){
506
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
507
                } 
508
            }
509
                } else {
510
         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
511
        }
512
513
                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
514
                   WHERE marine_live.latitude <> '' 
515
                                   AND marine_live.longitude <> '' 
516
                   ".$additional_query."
517
                   HAVING distance < :radius  
518
                                   ORDER BY distance";
519
520
                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
521
522
                return $spotter_array;
523
        }
524
525
    
526
        /**
527
	* Gets all the spotter information based on a particular callsign
528
	*
529
	* @return Array the spotter information
530
	*
531
	*/
532
	public function getLastLiveMarineDataByIdent($ident)
533
	{
534
		$Marine = new Marine($this->db);
535
		date_default_timezone_set('UTC');
536
537
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
538
                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
539
540
		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
541
542
		return $spotter_array;
543
	}
544
545
        /**
546
	* Gets all the spotter information based on a particular callsign
547
	*
548
	* @return Array the spotter information
549
	*
550
	*/
551
	public function getDateLiveMarineDataByIdent($ident,$date)
552
	{
553
		$Marine = new Marine($this->db);
554
		date_default_timezone_set('UTC');
555
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
556
		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
557
		$date = date('c',$date);
558
		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
559
		return $spotter_array;
560
	}
561
562
	/**
563
	* Gets all the spotter information based on a particular MMSI
564
	*
565
	* @return Array the spotter information
566
	*
567
	*/
568
	public function getDateLiveMarineDataByMMSI($mmsi,$date)
569
	{
570
		$Marine = new Marine($this->db);
571
		date_default_timezone_set('UTC');
572
		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
573
		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.mmsi = :mmsi AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
574
		$date = date('c',$date);
575
		$spotter_array = $Marine->getDataFromDB($query,array(':mmsi' => $mmsi,':date' => $date));
576
		return $spotter_array;
577
	}
578
579
        /**
580
	* Gets last spotter information based on a particular callsign
581
	*
582
	* @return Array the spotter information
583
	*
584
	*/
585
	public function getLastLiveMarineDataById($id)
586
	{
587
		$Marine = new Marine($this->db);
588
		date_default_timezone_set('UTC');
589
590
		$id = filter_var($id, FILTER_SANITIZE_STRING);
591
                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
592
593
		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
594
595
		return $spotter_array;
596
	}
597
598
        /**
599
	* Gets last spotter information based on a particular callsign
600
	*
601
	* @return Array the spotter information
602
	*
603
	*/
604
	public function getDateLiveMarineDataById($id,$date)
605
	{
606
		$Marine = new Marine($this->db);
607
		date_default_timezone_set('UTC');
608
609
		$id = filter_var($id, FILTER_SANITIZE_STRING);
610
                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
611
                $date = date('c',$date);
612
		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
613
614
		return $spotter_array;
615
	}
616
617
618
        /**
619
	* Gets all the spotter information based on a particular id
620
	*
621
	* @return Array the spotter information
622
	*
623
	*/
624
	public function getAllLiveMarineDataById($id,$liveinterval = false)
625
	{
626
		global $globalDBdriver, $globalLiveInterval;
627
		date_default_timezone_set('UTC');
628
		$id = filter_var($id, FILTER_SANITIZE_STRING);
629
		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
630
		if ($globalDBdriver == 'mysql') {
631
			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
632
			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
633
			$query .= ' ORDER BY date';
634
		} else {
635
			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
636
			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
637
			$query .= ' ORDER BY date';
638
		}
639
640
		try {
641
			$sth = $this->db->prepare($query);
642
			$sth->execute(array(':id' => $id));
643
		} catch(PDOException $e) {
644
			echo $e->getMessage();
645
			die;
646
		}
647
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
648
		return $spotter_array;
649
	}
650
651
        /**
652
	* Gets all the spotter information based on a particular ident
653
	*
654
	* @return Array the spotter information
655
	*
656
	*/
657
	public function getAllLiveMarineDataByIdent($ident)
658
	{
659
		date_default_timezone_set('UTC');
660
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
661
		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
662
    		try {
663
			
664
			$sth = $this->db->prepare($query);
665
			$sth->execute(array(':ident' => $ident));
666
		} catch(PDOException $e) {
667
			echo $e->getMessage();
668
			die;
669
		}
670
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
671
		return $spotter_array;
672
	}
673
674
675
	/**
676
	* Deletes all info in the table
677
	*
678
	* @return String success or false
679
	*
680
	*/
681
	public function deleteLiveMarineData()
682
	{
683
		global $globalDBdriver;
684
		if ($globalDBdriver == 'mysql') {
685
			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
686
			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
687
            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
688
		} else {
689
			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
690
		}
691
        
692
    		try {
693
			
694
			$sth = $this->db->prepare($query);
695
			$sth->execute();
696
		} catch(PDOException $e) {
697
			return "error";
698
		}
699
700
		return "success";
701
	}
702
703
	/**
704
	* Deletes all info in the table for aircraft not seen since 2 HOUR
705
	*
706
	* @return String success or false
707
	*
708
	*/
709
	public function deleteLiveMarineDataNotUpdated()
710
	{
711
		global $globalDBdriver, $globalDebug;
712
		if ($globalDBdriver == 'mysql') {
713
			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
714
    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
715
    			try {
716
				
717
				$sth = $this->db->prepare($query);
718
				$sth->execute();
719
			} catch(PDOException $e) {
720
				return "error";
721
			}
722
			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
723
                        $i = 0;
724
                        $j =0;
725
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
726
			foreach($all as $row)
727
			{
728
				$i++;
729
				$j++;
730
				if ($j == 30) {
731
					if ($globalDebug) echo ".";
732
				    	try {
733
						
734
						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
735
						$sth->execute();
736
					} catch(PDOException $e) {
737
						return "error";
738
					}
739
                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
740
                                	$j = 0;
741
				}
742
				$query_delete .= "'".$row['fammarine_id']."',";
743
			}
744
			if ($i > 0) {
745
    				try {
746
					
747
					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
748
					$sth->execute();
749
				} catch(PDOException $e) {
750
					return "error";
751
				}
752
			}
753
			return "success";
754
		} elseif ($globalDBdriver == 'pgsql') {
755
			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
756
    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
757
    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
758
    			try {
759
				
760
				$sth = $this->db->prepare($query);
761
				$sth->execute();
762
			} catch(PDOException $e) {
763
				return "error";
764
			}
765
/*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
766
                        $i = 0;
767
                        $j =0;
768
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
769
			foreach($all as $row)
770
			{
771
				$i++;
772
				$j++;
773
				if ($j == 100) {
774
					if ($globalDebug) echo ".";
775
				    	try {
776
						
777
						$sth = $this->db->query(substr($query_delete,0,-1).")");
778
						//$sth->execute();
779
					} catch(PDOException $e) {
780
						return "error";
781
					}
782
                                	$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
783
                                	$j = 0;
784
				}
785
				$query_delete .= "'".$row['fammarine_id']."',";
786
			}
787
			if ($i > 0) {
788
    				try {
789
					
790
					$sth = $this->db->query(substr($query_delete,0,-1).")");
791
					//$sth->execute();
792
				} catch(PDOException $e) {
793
					return "error";
794
				}
795
			}
796
*/
797
			return "success";
798
		}
799
	}
800
801
	/**
802
	* Deletes all info in the table for an ident
803
	*
804
	* @return String success or false
805
	*
806
	*/
807
	public function deleteLiveMarineDataByIdent($ident)
808
	{
809
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
810
		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
811
        
812
    		try {
813
			
814
			$sth = $this->db->prepare($query);
815
			$sth->execute(array(':ident' => $ident));
816
		} catch(PDOException $e) {
817
			return "error";
818
		}
819
820
		return "success";
821
	}
822
823
	/**
824
	* Deletes all info in the table for an id
825
	*
826
	* @return String success or false
827
	*
828
	*/
829
	public function deleteLiveMarineDataById($id)
830
	{
831
		$id = filter_var($id, FILTER_SANITIZE_STRING);
832
		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
833
        
834
    		try {
835
			
836
			$sth = $this->db->prepare($query);
837
			$sth->execute(array(':id' => $id));
838
		} catch(PDOException $e) {
839
			return "error";
840
		}
841
842
		return "success";
843
	}
844
845
846
	/**
847
	* Gets the marine races
848
	*
849
	* @return Array all races
850
	*
851
	*/
852
	public function getAllRaces()
853
	{
854
		$query  = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
855
		$sth = $this->db->prepare($query);
856
		$sth->execute();
857
		return $sth->fetchAll(PDO::FETCH_ASSOC);
858
	}
859
860
	/**
861
	* Gets the aircraft ident within the last hour
862
	*
863
	* @return String the ident
864
	*
865
	*/
866
	public function getIdentFromLastHour($ident)
867
	{
868
		global $globalDBdriver, $globalTimezone;
869
		if ($globalDBdriver == 'mysql') {
870
			$query  = 'SELECT marine_live.ident FROM marine_live 
871
				WHERE marine_live.ident = :ident 
872
				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
873
				AND marine_live.date < UTC_TIMESTAMP()';
874
			$query_data = array(':ident' => $ident);
875
		} else {
876
			$query  = "SELECT marine_live.ident FROM marine_live 
877
				WHERE marine_live.ident = :ident 
878
				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
879
				AND marine_live.date < now() AT TIME ZONE 'UTC'";
880
			$query_data = array(':ident' => $ident);
881
		}
882
		
883
		$sth = $this->db->prepare($query);
884
		$sth->execute($query_data);
885
		$ident_result='';
886
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
887
		{
888
			$ident_result = $row['ident'];
889
		}
890
		return $ident_result;
891
        }
892
893
	/**
894
	* Check recent aircraft
895
	*
896
	* @return String the ident
897
	*
898
	*/
899
	public function checkIdentRecent($ident)
900
	{
901
		global $globalDBdriver, $globalTimezone;
902
		if ($globalDBdriver == 'mysql') {
903
			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
904
				WHERE marine_live.ident = :ident 
905
				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
906
//				AND marine_live.date < UTC_TIMESTAMP()";
907
			$query_data = array(':ident' => $ident);
908
		} else {
909
			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
910
				WHERE marine_live.ident = :ident 
911
				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
912
//				AND marine_live.date < now() AT TIME ZONE 'UTC'";
913
			$query_data = array(':ident' => $ident);
914
		}
915
		
916
		$sth = $this->db->prepare($query);
917
		$sth->execute($query_data);
918
		$ident_result='';
919
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
920
		{
921
			$ident_result = $row['fammarine_id'];
922
		}
923
		return $ident_result;
924
        }
925
926
	/**
927
	* Check recent aircraft by id
928
	*
929
	* @return String the ident
930
	*
931
	*/
932
	public function checkIdRecent($id)
933
	{
934
		global $globalDBdriver, $globalTimezone;
935
		if ($globalDBdriver == 'mysql') {
936
			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
937
				WHERE marine_live.fammarine_id = :id 
938
				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
939
//				AND marine_live.date < UTC_TIMESTAMP()";
940
			$query_data = array(':id' => $id);
941
		} else {
942
			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
943
				WHERE marine_live.fammarine_id = :id 
944
				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
945
//				AND marine_live.date < now() AT TIME ZONE 'UTC'";
946
			$query_data = array(':id' => $id);
947
		}
948
		
949
		$sth = $this->db->prepare($query);
950
		$sth->execute($query_data);
951
		$ident_result='';
952
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
953
		{
954
			$ident_result = $row['fammarine_id'];
955
		}
956
		return $ident_result;
957
        }
958
959
	/**
960
	* Check recent aircraft by mmsi
961
	*
962
	* @return String the ident
963
	*
964
	*/
965
	public function checkMMSIRecent($mmsi)
966
	{
967
		global $globalDBdriver, $globalTimezone;
968
		if ($globalDBdriver == 'mysql') {
969
			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
970
				WHERE marine_live.mmsi = :mmsi 
971
				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
972
//				AND marine_live.date < UTC_TIMESTAMP()";
973
			$query_data = array(':mmsi' => $mmsi);
974
		} else {
975
			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
976
				WHERE marine_live.mmsi = :mmsi 
977
				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
978
//				AND marine_live.date < now() AT TIME ZONE 'UTC'";
979
			$query_data = array(':mmsi' => $mmsi);
980
		}
981
		
982
		$sth = $this->db->prepare($query);
983
		$sth->execute($query_data);
984
		$ident_result='';
985
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
986
		{
987
			$ident_result = $row['fammarine_id'];
988
		}
989
		return $ident_result;
990
        }
991
992
	/**
993
	* Adds a new spotter data
994
	*
995
	* @param String $fammarine_id the ID from flightaware
996
	* @param String $ident the flight ident
997
	* @param String $aircraft_icao the aircraft type
0 ignored issues
show
Bug introduced by
There is no parameter named $aircraft_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...
998
	* @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...
999
	* @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...
1000
	* @return String success or false
1001
	*
1002
	*/
1003
	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '',$captain_id = '',$captain_name = '',$race_id = '', $race_name = '', $distance = '', $race_rank = '', $race_time = '')
1004
	{
1005
		global $globalURL, $globalArchive, $globalDebug;
1006
		$Common = new Common();
1007
		date_default_timezone_set('UTC');
1008
1009
		//getting the airline information
1010
		if ($ident != '')
1011
		{
1012
			if (!is_string($ident))
1013
			{
1014
				return false;
1015
			} 
1016
		}
1017
1018
1019
		if ($latitude != '')
1020
		{
1021
			if (!is_numeric($latitude))
1022
			{
1023
				return false;
1024
			}
1025
		} else return '';
1026
1027
		if ($longitude != '')
1028
		{
1029
			if (!is_numeric($longitude))
1030
			{
1031
				return false;
1032
			}
1033
		} else return '';
1034
1035
1036
		if ($heading != '')
1037
		{
1038
			if (!is_numeric($heading))
1039
			{
1040
				return false;
1041
			}
1042
		} else $heading = 0;
1043
1044
		if ($groundspeed != '')
1045
		{
1046
			if (!is_numeric($groundspeed))
1047
			{
1048
				return false;
1049
			}
1050
		} else $groundspeed = 0;
1051
		date_default_timezone_set('UTC');
1052
		if ($date == '') $date = date("Y-m-d H:i:s", time());
1053
1054
        
1055
		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1056
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1057
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1058
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1059
		$distance = filter_var($distance,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1060
		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
1061
		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1062
		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
1063
		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
1064
		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
1065
		$type = filter_var($type,FILTER_SANITIZE_STRING);
1066
		$typeid = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
1067
		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
1068
		$status = filter_var($status,FILTER_SANITIZE_STRING);
1069
		$statusid = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
1070
		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1071
		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1072
		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
1073
		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
1074
		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
1075
		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
1076
		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
1077
		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
1078
		$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
1079
		$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1080
		if ($typeid == '') $typeid = NULL;
1081
		if ($statusid == '') $statusid = NULL;
1082
		if ($distance == '') $distance = NULL;
1083
1084
            	//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1085
            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1086
            	if ($arrival_date == '') $arrival_date = NULL;
1087
            	$query = '';
1088
		if ($globalArchive) {
1089
			if ($globalDebug) echo '-- Delete previous data -- ';
1090
			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
1091
		}
1092
		$query .= 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, 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) 
1093
		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:typeid,:status,:statusid,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name,:distance,:race_rank,:race_time)';
1094
		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':typeid' => $typeid,':status' => $status,':statusid' => $statusid,':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_time' => $race_time,':race_rank' => $race_rank);
1095
		try {
1096
			$sth = $this->db->prepare($query);
1097
			$sth->execute($query_values);
1098
			$sth->closeCursor();
1099
		} catch(PDOException $e) {
1100
			return "error : ".$e->getMessage();
1101
		}
1102
		
1103
		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1104
			if ($globalDebug) echo '(Add to Marine archive : ';
1105
			$MarineArchive = new MarineArchive($this->db);
1106
			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$statusid,$noarchive,$format_source, $source_name, $over_country,$captain_id,$captain_name,$race_id,$race_name,$distance,$race_rank,$race_time);
1107
			if ($globalDebug) echo $result.')';
1108
		}
1109
		return "success";
1110
	}
1111
1112
	public function getOrderBy()
1113
	{
1114
		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1115
		return $orderby;
1116
	}
1117
1118
}
1119
1120
1121
?>
1122