Completed
Push — master ( 4ef644...1a000c )
by Yannick
37:19
created

SpotterLive::getDateLiveSpotterDataById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
//$global_query = "SELECT spotter_live.* FROM spotter_live";
3
4
class SpotterLive {
5
	public $db;
6
	static $global_query = "SELECT spotter_live.* FROM spotter_live";
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. (SpotterLive)');
12
	}
13
14
15
	/**
16
	* Get SQL query part for filter used
17
	* @param Array $filter the filter
18
	* @return Array the SQL part
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['airlines']) && !empty($flt['airlines'])) {
38
				if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') {
39
					if (isset($flt['source'])) {
40
						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id";
41
					} else {
42
						$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id";
43
					}
44
				}
45
			}
46
			if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) {
47
				if (isset($flt['source'])) {
48
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id";
49
				} else {
50
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id";
51
				}
52
			}
53
			if (isset($flt['idents']) && !empty($flt['idents'])) {
54
				if (isset($flt['source'])) {
55
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id";
56
				} else {
57
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id";
58
				}
59
			}
60
			if (isset($flt['registrations']) && !empty($flt['registrations'])) {
61
				if (isset($flt['source'])) {
62
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id";
63
				} else {
64
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id";
65
				}
66
			}
67
			if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) {
68
				if (isset($flt['source'])) {
69
					$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) ssf ON ssf.flightaware_id = spotter_live.flightaware_id";
70
				}
71
			}
72
		}
73
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
74
			if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') {
75
				$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) sai ON sai.flightaware_id = spotter_live.flightaware_id";
76
			}
77
		}
78
		if (isset($filter['alliance']) && !empty($filter['alliance'])) {
79
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN (SELECT icao FROM airlines WHERE alliance = '".$filter['alliance']."')) sal ON sal.flightaware_id = spotter_live.flightaware_id ";
80
		}
81
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
82
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
83
		}
84
		if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) {
85
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) sp ON sp.flightaware_id = spotter_live.flightaware_id";
86
		}
87
		if (isset($filter['blocked']) && $filter['blocked'] == true) {
88
			$filter_query_join .= " INNER JOIN (SELECT callsign FROM aircraft_block) cblk ON cblk.callsign = spotter_live.ident";
89
		}
90
		if (isset($filter['source']) && !empty($filter['source'])) {
91
			if (count($filter['source']) == 1) {
92
				$filter_query_where .= " AND format_source = '".$filter['source'][0]."'";
93
			} else {
94
				$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
95
			}
96
		}
97
		if (isset($filter['ident']) && !empty($filter['ident'])) {
98
			$filter_query_where .= " AND ident = '".$filter['ident']."'";
99
		}
100
		if (isset($filter['id']) && !empty($filter['id'])) {
101
			$filter_query_where .= " AND flightaware_id = '".$filter['id']."'";
102
		}
103
		if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) {
104
			$filter_query_date = '';
105
			
106
			if (isset($filter['year']) && $filter['year'] != '') {
107
				if ($globalDBdriver == 'mysql') {
108
					$filter_query_date .= " AND YEAR(spotter_output.date) = '".$filter['year']."'";
109
				} else {
110
					$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_output.date) = '".$filter['year']."'";
111
				}
112
			}
113
			if (isset($filter['month']) && $filter['month'] != '') {
114
				if ($globalDBdriver == 'mysql') {
115
					$filter_query_date .= " AND MONTH(spotter_output.date) = '".$filter['month']."'";
116
				} else {
117
					$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_output.date) = '".$filter['month']."'";
118
				}
119
			}
120
			if (isset($filter['day']) && $filter['day'] != '') {
121
				if ($globalDBdriver == 'mysql') {
122
					$filter_query_date .= " AND DAY(spotter_output.date) = '".$filter['day']."'";
123
				} else {
124
					$filter_query_date .= " AND EXTRACT(DAY FROM spotter_output.date) = '".$filter['day']."'";
125
				}
126
			}
127
			$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_live.flightaware_id";
128
		}
129
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
130
			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
131
		}
132
		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
133
		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
134
		if ($filter_query_where != '') {
135
			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
136
		}
137
		$filter_query = $filter_query_join.$filter_query_where;
138
		return $filter_query;
139
	}
140
141
	/**
142
	* Gets all the spotter information based on the latest data entry
143
	*
144
	* @return Array the spotter information
145
	*
146
	*/
147
	public function getLiveSpotterData($limit = '', $sort = '', $filter = array())
148
	{
149
		global $globalDBdriver, $globalLiveInterval;
150
		$Spotter = new Spotter($this->db);
151
		date_default_timezone_set('UTC');
152
153
		$filter_query = $this->getFilter($filter);
154
		$limit_query = '';
155
		if ($limit != '')
156
		{
157
			$limit_array = explode(',', $limit);
158
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
159
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
160
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
161
			{
162
				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
163
			}
164
		}
165
		$orderby_query = '';
166
		if ($sort != '')
167
		{
168
			$search_orderby_array = $this->getOrderBy();
169
			if (isset($search_orderby_array[$sort]['sql'])) 
170
			{
171
				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
172
			}
173
		}
174
		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
175
176
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
177
		if ($globalDBdriver == 'mysql') {
178
			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
179
			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
180
		} else {
181
			$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query.$orderby_query;
182
		}
183
		$spotter_array = $Spotter->getDataFromDB($query.$limit_query,array(),'',true);
184
185
		return $spotter_array;
186
	}
187
188
	/**
189
	* Gets Minimal Live Spotter data
190
	*
191
	* @return Array the spotter information
192
	*
193
	*/
194
	public function getMinLiveSpotterData($filter = array())
195
	{
196
		global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap2DAircraftsLimit;
197
		date_default_timezone_set('UTC');
198
		$filter_query = $this->getFilter($filter,true,true);
199
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
200
		if ($globalDBdriver == 'mysql') {
201
			if (isset($globalArchive) && $globalArchive === TRUE) {
202
			//	$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
203
			//	FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date AND'." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC";
204
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
205
				FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date AND'." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0";
206
			} else {
207
			//	$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
208
			//	FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC";
209
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
210
				FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0";
211
			}
212
		} else {
213
			if (isset($globalArchive) && $globalArchive === TRUE) {
214
			//	$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
215
			//	FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND  spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC";
216
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
217
				FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND  spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'";
218
			} else {
219
			//	$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
220
			//	FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC";
221
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
222
				FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'";
223
			}
224
		}
225
		if (isset($globalMap2DAircraftsLimit) && $globalMap2DAircraftsLimit != '') {
226
			$query .= ' LIMIT '.$globalMap2DAircraftsLimit;
227
		}
228
229
		try {
230
			$sth = $this->db->prepare($query);
231
			$sth->execute();
232
		} catch(PDOException $e) {
233
			echo $e->getMessage();
234
			die;
235
		}
236
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
237
		return $spotter_array;
238
	}
239
240
	/**
241
	* Gets Minimal Live Spotter data since xx seconds
242
	*
243
	* @return Array the spotter information
244
	*
245
	*/
246
	public function getMinLastLiveSpotterData($coord = array(),$filter = array(), $limit = false, $id = '')
247
	{
248
		global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap3DAircraftsLimit;
249
		date_default_timezone_set('UTC');
250
		$usecoord = false;
251
		if (is_array($coord) && !empty($coord)) {
252
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
253
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
254
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
255
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
256
			$usecoord = true;
257
		}
258
		$id = filter_var($id,FILTER_SANITIZE_STRING);
259
		$filter_query = $this->getFilter($filter,true,true);
260
261
		if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200';
262
		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300';
263
		if ($globalDBdriver == 'mysql') {
264
			if (isset($globalArchive) && $globalArchive === TRUE) {
265
				/*
266
				$query  = 'SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source 
267
				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id 
268
				WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' 
269
				ORDER BY spotter_archive.flightaware_id, spotter_archive.date";
270
				*/
271
				$query  = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
272
				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id ";
273
				if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_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...
274
				if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id ";
275
				$query .= "UNION
276
				SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
277
				FROM spotter_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date";
278
				if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
279
				if ($id != '') $query .= " OR spotter_live.flightaware_id = :id";
280
				$query .= ") AS spotter 
281
				WHERE latitude <> '0' AND longitude <> '0' 
282
				ORDER BY flightaware_id, date";
283
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
284
			} else {
285
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
286
				FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date ";
287
				if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
288
				if ($id != '') $query .= "OR spotter_live.flightaware_id = :id ";
289
				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
290
				ORDER BY spotter_live.flightaware_id, spotter_live.date";
291
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
292
			}
293
		} else {
294
			if (isset($globalArchive) && $globalArchive === TRUE) {
295
				/*
296
				$query  = "SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source 
297
				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id 
298
				WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' 
299
				ORDER BY spotter_archive.flightaware_id, spotter_archive.date";
300
                               */
301
				$query  = "SELECT * FROM (
302
				SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
303
				FROM spotter_archive 
304
				INNER JOIN (
305
				    SELECT flightaware_id 
306
				    FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date";
307
				$query.= ") l ON l.flightaware_id = spotter_archive.flightaware_id ";
308
				if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
309
				if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id ";
310
				$query .= "UNION
311
				    SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
312
				    FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date";
313
				if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
314
				if ($id != '') $query .= " OR spotter_live.flightaware_id = :id";
315
				$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' ";
316
				$query .= "ORDER BY flightaware_id, date";
317
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
318
			} else {
319
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
320
				FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date ";
321
				if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
322
				if ($id != '') $query .= "OR spotter_live.flightaware_id = :id ";
323
				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
324
				ORDER BY spotter_live.flightaware_id, spotter_live.date";
325
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
326
			}
327
		}
328
		$query_values = array();
329
		if ($id != '') $query_values = array(':id' => $id);
330
		try {
331
			$sth = $this->db->prepare($query);
332
			$sth->execute($query_values);
333
		} catch(PDOException $e) {
334
			echo $e->getMessage();
335
			die;
336
		}
337
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
338
		return $spotter_array;
339
	}
340
341
	/**
342
	* Gets Minimal Live Spotter data since xx seconds
343
	*
344
	* @return Array the spotter information
345
	*
346
	*/
347
	public function getMinLastLiveSpotterDataByID($id = '',$filter = array(), $limit = false)
348
	{
349
		global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap3DAircraftsLimit;
350
		date_default_timezone_set('UTC');
351
		$id = filter_var($id,FILTER_SANITIZE_STRING);
352
		$filter_query = $this->getFilter($filter,true,true);
353
354
		if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200';
355
		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300';
356
		if ($globalDBdriver == 'mysql') {
357
			if (isset($globalArchive) && $globalArchive === TRUE) {
358
				$query  = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
359
				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id) l ON l.flightaware_id = spotter_archive.flightaware_id ';
360
				$query .= "UNION
361
				SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
362
				FROM spotter_live".$filter_query.' spotter_live.flightaware_id = :id';
363
				$query .= ") AS spotter 
364
				WHERE latitude <> '0' AND longitude <> '0' 
365
				ORDER BY flightaware_id, date";
366
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
367
			} else {
368
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
369
				FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id ';
370
				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
371
				ORDER BY spotter_live.flightaware_id, spotter_live.date";
372
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
373
			}
374
		} else {
375
			if (isset($globalArchive) && $globalArchive === TRUE) {
376
				$query  = "SELECT * FROM (
377
				SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
378
				FROM spotter_archive 
379
				INNER JOIN (
380
				    SELECT flightaware_id 
381
				    FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id";
382
				$query.= ") l ON l.flightaware_id = spotter_archive.flightaware_id ";
383
				$query .= "UNION
384
				    SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
385
				    FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id";
386
				$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' ";
387
				$query .= "ORDER BY flightaware_id, date";
388
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
389
			} else {
390
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
391
				FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id ";
392
				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
393
				ORDER BY spotter_live.flightaware_id, spotter_live.date";
394
				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
395
			}
396
		}
397
		$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...
398
		$query_values = array(':id' => $id);
399
		try {
400
			$sth = $this->db->prepare($query);
401
			$sth->execute($query_values);
402
		} catch(PDOException $e) {
403
			echo $e->getMessage();
404
			die;
405
		}
406
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
407
		return $spotter_array;
408
	}
409
410
	/**
411
	* Gets number of latest data entry
412
	*
413
	* @return String number of entry
414
	*
415
	*/
416
	public function getLiveSpotterCount($filter = array())
417
	{
418
		global $globalDBdriver, $globalLiveInterval;
419
		$filter_query = $this->getFilter($filter,true,true);
420
421
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
422
		if ($globalDBdriver == 'mysql') {
423
			//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
424
			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
425
		} else {
426
			//$query  = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query;
427
			$query = "SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
428
		}
429
		try {
430
			$sth = $this->db->prepare($query);
431
			$sth->execute();
432
		} catch(PDOException $e) {
433
			echo $e->getMessage();
434
			die;
435
		}
436
		$result = $sth->fetch(PDO::FETCH_ASSOC);
437
		$sth->closeCursor();
438
		return $result['nb'];
439
	}
440
441
	/**
442
	* Gets all the spotter information based on the latest data entry and coord
443
	*
444
	* @return Array the spotter information
445
	*
446
	*/
447
	public function getLiveSpotterDatabyCoord($coord, $filter = array())
448
	{
449
		global $globalDBdriver, $globalLiveInterval;
450
		$Spotter = new Spotter($this->db);
451
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
452
		$filter_query = $this->getFilter($filter);
453
454
		if (is_array($coord)) {
455
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
456
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
457
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
458
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
459
		} else return array();
460
		if ($globalDBdriver == 'mysql') {
461
			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
462
		} else {
463
			$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC'  - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." GROUP BY spotter_live.flightaware_id".$filter_query;
464
465
		}
466
		$spotter_array = $Spotter->getDataFromDB($query);
467
		return $spotter_array;
468
	}
469
470
	/**
471
	* Gets all the spotter information based on the latest data entry and coord
472
	*
473
	* @return Array the spotter information
474
	*
475
	*/
476
	public function getMinLiveSpotterDatabyCoord($coord, $filter = array())
477
	{
478
		global $globalDBdriver, $globalLiveInterval, $globalArchive;
479
		$Spotter = new Spotter($this->db);
0 ignored issues
show
Unused Code introduced by
$Spotter 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...
480
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
481
		$filter_query = $this->getFilter($filter,true,true);
482
483
		if (is_array($coord)) {
484
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
485
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
486
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
487
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
488
		} else return array();
489
		if ($globalDBdriver == 'mysql') {
490
			if (isset($globalArchive) && $globalArchive === TRUE) {
491
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
492
				FROM spotter_live 
493
				'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date 
494
				AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
495
				AND spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC';
496
			} else {
497
				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
498
				FROM spotter_live 
499
				INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate 
500
				    FROM spotter_live l 
501
				    WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date 
502
				    AND l.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND l.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
503
				    GROUP BY l.flightaware_id
504
				) s on spotter_live.flightaware_id = s.flightaware_id 
505
				AND spotter_live.date = s.maxdate'.$filter_query.' spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC';
506
			}
507
		} else {
508
			if (isset($globalArchive) && $globalArchive === TRUE) {
509
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
510
				FROM spotter_live 
511
				".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date 
512
				AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." 
513
				AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." 
514
				AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC";
515
			} else {
516
				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
517
				FROM spotter_live 
518
				INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate 
519
				    FROM spotter_live l 
520
				    WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date 
521
				    AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." 
522
				    AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." 
523
				    GROUP BY l.flightaware_id
524
				) s on spotter_live.flightaware_id = s.flightaware_id 
525
				AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC";
526
			}
527
		}
528
		try {
529
			$sth = $this->db->prepare($query);
530
			$sth->execute();
531
		} catch(PDOException $e) {
532
			echo $e->getMessage();
533
			die;
534
		}
535
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
536
		return $spotter_array;
537
	}
538
539
	/**
540
	* Gets all the spotter information based on a user's latitude and longitude
541
	*
542
	* @return Array the spotter information
543
	*
544
	*/
545
	public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
546
	{
547
		$Spotter = new Spotter($this->db);
548
		date_default_timezone_set('UTC');
549
		if ($lat != '') {
550
			if (!is_numeric($lat)) {
551
				return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterLive::getLatestSpotterForLayar of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
552
			}
553
		}
554
        if ($lng != '')
555
                {
556
                        if (!is_numeric($lng))
557
                        {
558
                                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterLive::getLatestSpotterForLayar of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
559
                        }
560
                }
561
562
                if ($radius != '')
563
                {
564
                        if (!is_numeric($radius))
565
                        {
566
                                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterLive::getLatestSpotterForLayar of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
567
                        }
568
                }
569
		$additional_query = '';
570
        if ($interval != '')
571
                {
572
                        if (!is_string($interval))
573
                        {
574
                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
575
			        return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by SpotterLive::getLatestSpotterForLayar of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
576
                        } else {
577
                if ($interval == '1m')
578
                {
579
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
580
                } else if ($interval == '15m'){
581
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
582
                } 
583
            }
584
                } else {
585
         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
586
        }
587
588
                $query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
589
                   WHERE spotter_live.latitude <> '' 
590
                                   AND spotter_live.longitude <> '' 
591
                   ".$additional_query."
592
                   HAVING distance < :radius  
593
                                   ORDER BY distance";
594
595
                $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
596
597
                return $spotter_array;
598
        }
599
600
    
601
        /**
602
	* Gets all the spotter information based on a particular callsign
603
	*
604
	* @return Array the spotter information
605
	*
606
	*/
607
	public function getLastLiveSpotterDataByIdent($ident)
608
	{
609
		$Spotter = new Spotter($this->db);
610
		date_default_timezone_set('UTC');
611
612
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
613
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
614
615
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true);
616
617
		return $spotter_array;
618
	}
619
620
        /**
621
	* Gets all the spotter information based on a particular callsign
622
	*
623
	* @return Array the spotter information
624
	*
625
	*/
626
	public function getDateLiveSpotterDataByIdent($ident,$date)
627
	{
628
		$Spotter = new Spotter($this->db);
629
		date_default_timezone_set('UTC');
630
631
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
632
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
633
634
                $date = date('c',$date);
635
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
636
637
		return $spotter_array;
638
	}
639
640
        /**
641
	* Gets last spotter information based on a particular callsign
642
	*
643
	* @return Array the spotter information
644
	*
645
	*/
646
	public function getLastLiveSpotterDataById($id)
647
	{
648
		$Spotter = new Spotter($this->db);
649
		date_default_timezone_set('UTC');
650
		$id = filter_var($id, FILTER_SANITIZE_STRING);
651
		$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
652
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true);
653
		return $spotter_array;
654
	}
655
656
        /**
657
	* Gets last spotter information based on a particular callsign
658
	*
659
	* @return Array the spotter information
660
	*
661
	*/
662
	public function getDateLiveSpotterDataById($id,$date)
663
	{
664
		$Spotter = new Spotter($this->db);
665
		date_default_timezone_set('UTC');
666
667
		$id = filter_var($id, FILTER_SANITIZE_STRING);
668
		$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
669
		$date = date('c',$date);
670
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
671
		return $spotter_array;
672
	}
673
674
        /**
675
	* Gets altitude information based on a particular callsign
676
	*
677
	* @return Array the spotter information
678
	*
679
	*/
680
	public function getAltitudeLiveSpotterDataByIdent($ident)
681
	{
682
683
		date_default_timezone_set('UTC');
684
685
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
686
                $query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
687
688
    		try {
689
			
690
			$sth = $this->db->prepare($query);
691
			$sth->execute(array(':ident' => $ident));
692
		} catch(PDOException $e) {
693
			echo $e->getMessage();
694
			die;
695
		}
696
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
697
698
		return $spotter_array;
699
	}
700
701
        /**
702
	* Gets all the spotter information based on a particular id
703
	*
704
	* @return Array the spotter information
705
	*
706
	*/
707
	public function getAllLiveSpotterDataById($id,$liveinterval = false)
708
	{
709
		global $globalDBdriver, $globalLiveInterval;
710
		date_default_timezone_set('UTC');
711
		$id = filter_var($id, FILTER_SANITIZE_STRING);
712
		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
713
		if ($globalDBdriver == 'mysql') {
714
			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
715
			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
716
			$query .= ' ORDER BY date';
717
		} else {
718
			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
719
			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
720
			$query .= ' ORDER BY date';
721
		}
722
723
		try {
724
			$sth = $this->db->prepare($query);
725
			$sth->execute(array(':id' => $id));
726
		} catch(PDOException $e) {
727
			echo $e->getMessage();
728
			die;
729
		}
730
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
731
		return $spotter_array;
732
	}
733
734
        /**
735
	* Gets all the spotter information based on a particular ident
736
	*
737
	* @return Array the spotter information
738
	*
739
	*/
740
	public function getAllLiveSpotterDataByIdent($ident)
741
	{
742
		date_default_timezone_set('UTC');
743
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
744
		$query  = self::$global_query.' WHERE spotter_live.ident = :ident';
745
    		try {
746
			
747
			$sth = $this->db->prepare($query);
748
			$sth->execute(array(':ident' => $ident));
749
		} catch(PDOException $e) {
750
			echo $e->getMessage();
751
			die;
752
		}
753
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
754
		return $spotter_array;
755
	}
756
757
758
	/**
759
	* Deletes all info in the table
760
	*
761
	* @return String success or false
762
	*
763
	*/
764
	public function deleteLiveSpotterData()
765
	{
766
		global $globalDBdriver;
767
		if ($globalDBdriver == 'mysql') {
768
			//$query  = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date";
769
			$query  = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date';
770
            		//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
771
		} else {
772
			$query  = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date";
773
		}
774
        
775
    		try {
776
			
777
			$sth = $this->db->prepare($query);
778
			$sth->execute();
779
		} catch(PDOException $e) {
780
			return "error";
781
		}
782
783
		return "success";
784
	}
785
786
	/**
787
	* Deletes all info in the table for aircraft not seen since 2 HOUR
788
	*
789
	* @return String success or false
790
	*
791
	*/
792
	public function deleteLiveSpotterDataNotUpdated()
793
	{
794
		global $globalDBdriver, $globalDebug;
795
		if ($globalDBdriver == 'mysql') {
796
			//$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0';
797
    			$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0";
798
    			try {
799
				
800
				$sth = $this->db->prepare($query);
801
				$sth->execute();
802
			} catch(PDOException $e) {
803
				return "error";
804
			}
805
			$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
806
                        $i = 0;
807
                        $j =0;
808
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
809
			foreach($all as $row)
810
			{
811
				$i++;
812
				$j++;
813
				if ($j == 30) {
814
					if ($globalDebug) echo ".";
815
				    	try {
816
						
817
						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
818
						$sth->execute();
819
					} catch(PDOException $e) {
820
						return "error";
821
					}
822
                                	$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
823
                                	$j = 0;
824
				}
825
				$query_delete .= "'".$row['flightaware_id']."',";
826
			}
827
			if ($i > 0) {
828
    				try {
829
					
830
					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
831
					$sth->execute();
832
				} catch(PDOException $e) {
833
					return "error";
834
				}
835
			}
836
			return "success";
837
		} elseif ($globalDBdriver == 'pgsql') {
838
			//$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0";
839
    			//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
840
    			$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)";
841
    			try {
842
				
843
				$sth = $this->db->prepare($query);
844
				$sth->execute();
845
			} catch(PDOException $e) {
846
				return "error";
847
			}
848
/*			$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN (";
849
                        $i = 0;
850
                        $j =0;
851
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
852
			foreach($all as $row)
853
			{
854
				$i++;
855
				$j++;
856
				if ($j == 100) {
857
					if ($globalDebug) echo ".";
858
				    	try {
859
						
860
						$sth = $this->db->query(substr($query_delete,0,-1).")");
861
						//$sth->execute();
862
					} catch(PDOException $e) {
863
						return "error";
864
					}
865
                                	$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN (";
866
                                	$j = 0;
867
				}
868
				$query_delete .= "'".$row['flightaware_id']."',";
869
			}
870
			if ($i > 0) {
871
    				try {
872
					
873
					$sth = $this->db->query(substr($query_delete,0,-1).")");
874
					//$sth->execute();
875
				} catch(PDOException $e) {
876
					return "error";
877
				}
878
			}
879
*/
880
			return "success";
881
		}
882
	}
883
884
	/**
885
	* Deletes all info in the table for an ident
886
	*
887
	* @return String success or false
888
	*
889
	*/
890
	public function deleteLiveSpotterDataByIdent($ident)
891
	{
892
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
893
		$query  = 'DELETE FROM spotter_live WHERE ident = :ident';
894
        
895
    		try {
896
			
897
			$sth = $this->db->prepare($query);
898
			$sth->execute(array(':ident' => $ident));
899
		} catch(PDOException $e) {
900
			return "error";
901
		}
902
903
		return "success";
904
	}
905
906
	/**
907
	* Deletes all info in the table for an id
908
	*
909
	* @return String success or false
910
	*
911
	*/
912
	public function deleteLiveSpotterDataById($id)
913
	{
914
		$id = filter_var($id, FILTER_SANITIZE_STRING);
915
		$query  = 'DELETE FROM spotter_live WHERE flightaware_id = :id';
916
        
917
    		try {
918
			
919
			$sth = $this->db->prepare($query);
920
			$sth->execute(array(':id' => $id));
921
		} catch(PDOException $e) {
922
			return "error";
923
		}
924
925
		return "success";
926
	}
927
928
929
	/**
930
	* Gets the aircraft ident within the last hour
931
	*
932
	* @return String the ident
933
	*
934
	*/
935
	public function getIdentFromLastHour($ident)
936
	{
937
		global $globalDBdriver, $globalTimezone;
938
		if ($globalDBdriver == 'mysql') {
939
			$query  = 'SELECT spotter_live.ident FROM spotter_live 
940
				WHERE spotter_live.ident = :ident 
941
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
942
				AND spotter_live.date < UTC_TIMESTAMP()';
943
			$query_data = array(':ident' => $ident);
944
		} else {
945
			$query  = "SELECT spotter_live.ident FROM spotter_live 
946
				WHERE spotter_live.ident = :ident 
947
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
948
				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
949
			$query_data = array(':ident' => $ident);
950
		}
951
		
952
		$sth = $this->db->prepare($query);
953
		$sth->execute($query_data);
954
		$ident_result='';
955
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
956
		{
957
			$ident_result = $row['ident'];
958
		}
959
		return $ident_result;
960
        }
961
962
	/**
963
	* Check recent aircraft
964
	*
965
	* @return String the ident
966
	*
967
	*/
968
	public function checkIdentRecent($ident)
969
	{
970
		global $globalDBdriver, $globalTimezone;
971
		if ($globalDBdriver == 'mysql') {
972
			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
973
				WHERE spotter_live.ident = :ident 
974
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 MINUTE)'; 
975
//				AND spotter_live.date < UTC_TIMESTAMP()";
976
			$query_data = array(':ident' => $ident);
977
		} else {
978
			$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
979
				WHERE spotter_live.ident = :ident 
980
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '20 MINUTES'";
981
//				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
982
			$query_data = array(':ident' => $ident);
983
		}
984
		
985
		$sth = $this->db->prepare($query);
986
		$sth->execute($query_data);
987
		$ident_result='';
988
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
989
		{
990
			$ident_result = $row['flightaware_id'];
991
		}
992
		return $ident_result;
993
        }
994
995
	/**
996
	* Check recent aircraft by id
997
	*
998
	* @return String the ident
999
	*
1000
	*/
1001
	public function checkIdRecent($id)
1002
	{
1003
		global $globalDBdriver, $globalTimezone;
1004
		if ($globalDBdriver == 'mysql') {
1005
			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
1006
				WHERE spotter_live.flightaware_id = :id 
1007
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
1008
//				AND spotter_live.date < UTC_TIMESTAMP()";
1009
			$query_data = array(':id' => $id);
1010
		} else {
1011
			$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
1012
				WHERE spotter_live.flightaware_id = :id 
1013
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
1014
//				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
1015
			$query_data = array(':id' => $id);
1016
		}
1017
		
1018
		$sth = $this->db->prepare($query);
1019
		$sth->execute($query_data);
1020
		$ident_result='';
1021
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1022
		{
1023
			$ident_result = $row['flightaware_id'];
1024
		}
1025
		return $ident_result;
1026
        }
1027
1028
	/**
1029
	* Check recent aircraft by ModeS
1030
	*
1031
	* @return String the ModeS
1032
	*
1033
	*/
1034
	public function checkModeSRecent($modes)
1035
	{
1036
		global $globalDBdriver, $globalTimezone;
1037
		if ($globalDBdriver == 'mysql') {
1038
			$query  = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
1039
				WHERE spotter_live.ModeS = :modes 
1040
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 MINUTE)'; 
1041
//				AND spotter_live.date < UTC_TIMESTAMP()";
1042
			$query_data = array(':modes' => $modes);
1043
		} else {
1044
			$query  = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
1045
				WHERE spotter_live.ModeS = :modes 
1046
				AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 MINUTE'";
1047
//			//	AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1048
			$query_data = array(':modes' => $modes);
1049
		}
1050
		
1051
		$sth = $this->db->prepare($query);
1052
		$sth->execute($query_data);
1053
		$ident_result='';
1054
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1055
		{
1056
			//$ident_result = $row['spotter_live_id'];
1057
			$ident_result = $row['flightaware_id'];
1058
		}
1059
		return $ident_result;
1060
	}
1061
1062
	/**
1063
	* Gets the aircraft data from the last 20 seconds
1064
	*
1065
	* @return Array the spotter data
1066
	*
1067
	*/
1068
	public function getRealTimeData($q = '')
1069
	{
1070
		global $globalDBdriver;
1071
		$additional_query = '';
1072
		if ($q != "")
1073
		{
1074
			if (!is_string($q))
1075
			{
1076
				return array();
1077
			} else {
1078
				$q_array = explode(" ", $q);
1079
				foreach ($q_array as $q_item){
1080
					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
1081
					$additional_query .= " AND (";
1082
					$additional_query .= "(spotter_live.aircraft_icao like '%".$q_item."%') OR ";
1083
					$additional_query .= "(spotter_live.aircraft_name like '%".$q_item."%') OR ";
1084
					$additional_query .= "(spotter_live.aircraft_manufacturer like '%".$q_item."%') OR ";
1085
					$additional_query .= "(spotter_live.airline_icao like '%".$q_item."%') OR ";
1086
					$additional_query .= "(spotter_live.departure_airport_icao like '%".$q_item."%') OR ";
1087
					$additional_query .= "(spotter_live.arrival_airport_icao like '%".$q_item."%') OR ";
1088
					$additional_query .= "(spotter_live.registration like '%".$q_item."%') OR ";
1089
					$additional_query .= "(spotter_live.ident like '%".$q_item."%')";
1090
					$additional_query .= ")";
1091
				}
1092
			}
1093
		}
1094
		if ($globalDBdriver == 'mysql') {
1095
			$query  = "SELECT spotter_live.* FROM spotter_live 
1096
			    WHERE spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
1097
			    AND spotter_live.date < UTC_TIMESTAMP()";
1098
		} else {
1099
			$query  = "SELECT spotter_live.* FROM spotter_live 
1100
			    WHERE spotter_live.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
1101
			    AND spotter_live.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1102
		}
1103
		$Spotter = new Spotter();
1104
		$spotter_array = $Spotter->getDataFromDB($query, array());
1105
		return $spotter_array;
1106
	}
1107
1108
	/**
1109
	* Adds a new spotter data
1110
	*
1111
	* @param String $flightaware_id the ID from flightaware
1112
	* @param String $ident the flight ident
1113
	* @param String $aircraft_icao the aircraft type
1114
	* @param String $departure_airport_icao the departure airport
1115
	* @param String $arrival_airport_icao the arrival airport
1116
	* @return String success or false
1117
	*
1118
	*/
1119
	public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $altitude_real = '',$heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '')
1120
	{
1121
		global $globalURL, $globalArchive, $globalDebug;
1122
		$Common = new Common();
1123
		date_default_timezone_set('UTC');
1124
1125
		//getting the airline information
1126
		if ($ident != '')
1127
		{
1128
			if (!is_string($ident))
1129
			{
1130
				return false;
1131
			} 
1132
		}
1133
1134
		//getting the aircraft information
1135
		if ($aircraft_icao != '')
1136
		{
1137
			if (!is_string($aircraft_icao))
1138
			{
1139
				return false;
1140
			} 
1141
		} 
1142
		//getting the departure airport information
1143
		if ($departure_airport_icao != '')
1144
		{
1145
			if (!is_string($departure_airport_icao))
1146
			{
1147
				return false;
1148
			} 
1149
		}
1150
1151
		//getting the arrival airport information
1152
		if ($arrival_airport_icao != '')
1153
		{
1154
			if (!is_string($arrival_airport_icao))
1155
			{
1156
				return false;
1157
			}
1158
		}
1159
1160
1161
		if ($latitude != '')
1162
		{
1163
			if (!is_numeric($latitude))
1164
			{
1165
				return false;
1166
			}
1167
		} else return '';
1168
1169
		if ($longitude != '')
1170
		{
1171
			if (!is_numeric($longitude))
1172
			{
1173
				return false;
1174
			}
1175
		} else return '';
1176
1177
		if ($waypoints != '')
1178
		{
1179
			if (!is_string($waypoints))
1180
			{
1181
				return false;
1182
			}
1183
		}
1184
1185
		if ($altitude != '')
1186
		{
1187
			if (!is_numeric($altitude))
1188
			{
1189
				return false;
1190
			}
1191
		} else $altitude = 0;
1192
		if ($altitude_real != '')
1193
		{
1194
			if (!is_numeric($altitude_real))
1195
			{
1196
				return false;
1197
			}
1198
		} else $altitude_real = 0;
1199
1200
		if ($heading != '')
1201
		{
1202
			if (!is_numeric($heading))
1203
			{
1204
				return false;
1205
			}
1206
		} else $heading = 0;
1207
1208
		if ($groundspeed != '')
1209
		{
1210
			if (!is_numeric($groundspeed))
1211
			{
1212
				return false;
1213
			}
1214
		} else $groundspeed = 0;
1215
		date_default_timezone_set('UTC');
1216
		if ($date == '') $date = date("Y-m-d H:i:s", time());
1217
1218
        
1219
		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
1220
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1221
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
1222
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
1223
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
1224
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1225
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1226
		$waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING);
1227
		$altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1228
		$altitude_real = filter_var($altitude_real,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1229
		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
1230
		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1231
		$squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT);
1232
		$route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING);
1233
		$ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING);
1234
		$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING);
1235
		$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
1236
		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
1237
		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
1238
		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
1239
		$verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT);
1240
1241
		$airline_name = '';
1242
		$airline_icao = '';
1243
		$airline_country = '';
1244
		$airline_type = '';
1245
		$aircraft_shadow = '';
1246
		$aircraft_type = '';
1247
		$aircraft_manufacturer = '';
1248
1249
1250
1251
		$aircraft_name = '';
1252
		$departure_airport_name = '';
1253
		$departure_airport_city = '';
1254
		$departure_airport_country = '';
1255
		
1256
		$arrival_airport_name = '';
1257
		$arrival_airport_city = '';
1258
		$arrival_airport_country = '';
1259
		
1260
            	
1261
            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1262
            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1263
            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1264
            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1265
		
1266
		$query = '';
1267
		if ($globalArchive) {
1268
			if ($globalDebug) echo '-- Delete previous data -- ';
1269
			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1270
		}
1271
1272
		$query  .= 'INSERT INTO spotter_live (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country, real_altitude) 
1273
		VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country, :real_altitude)';
1274
1275
		$query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,':aircraft_icao' => $aircraft_icao,':aircraft_shadow' => $aircraft_shadow,':aircraft_type' => $aircraft_type,':aircraft_manufacturer' => $aircraft_manufacturer,':departure_airport_icao' => $departure_airport_icao,':departure_airport_name' => $departure_airport_name,':departure_airport_city' => $departure_airport_city,':departure_airport_country' => $departure_airport_country,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk,':route_stop' => $route_stop,':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source,':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country,':real_altitude' => $altitude_real);
1276
		try {
1277
			
1278
			$sth = $this->db->prepare($query);
1279
			$sth->execute($query_values);
1280
			$sth->closeCursor();
1281
		} catch(PDOException $e) {
1282
			return "error : ".$e->getMessage();
1283
		}
1284
		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1285
		    if ($globalDebug) echo '(Add to SBS archive : ';
1286
		    $SpotterArchive = new SpotterArchive($this->db);
1287
		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $altitude_real,$heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1288
		    if ($globalDebug) echo $result.')';
1289
		} elseif ($globalDebug && $putinarchive !== true) {
1290
			echo '(Not adding to archive)';
1291
		} elseif ($globalDebug && $noarchive === true) {
1292
			echo '(No archive)';
1293
		}
1294
		return "success";
1295
1296
	}
1297
1298
	public function getOrderBy()
1299
	{
1300
		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC"));
1301
		return $orderby;
1302
	}
1303
1304
}
1305
1306
1307
?>
1308