Completed
Push — master ( e7716d...f2edfd )
by Yannick
06:34
created

search-gpx.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('require/class.Connection.php');
3
require_once('require/class.Spotter.php');
4
require_once('require/class.Language.php');
5
$Spotter = new Spotter();
6 View Code Duplication
if (isset($_GET['start_date'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
        //for the date manipulation into the query
8
        if($_GET['start_date'] != "" && $_GET['end_date'] != ""){
9
                $start_date = $_GET['start_date'].":00";
10
                $end_date = $_GET['end_date'].":00";
11
                $sql_date = $start_date.",".$end_date;
12
        } else if($_GET['start_date'] != ""){
13
                $start_date = $_GET['start_date'].":00";
14
                $sql_date = $start_date;
15
        } else if($_GET['start_date'] == "" && $_GET['end_date'] != ""){
16
                $end_date = date("Y-m-d H:i:s", strtotime("2014-04-12")).",".$_GET['end_date'].":00";
17
                $sql_date = $end_date;
18
        } else $sql_date = '';
19
} else $sql_date = '';
20
21 View Code Duplication
if (isset($_GET['highest_altitude'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
        //for altitude manipulation
23
        if($_GET['highest_altitude'] != "" && $_GET['lowest_altitude'] != ""){
24
                $end_altitude = $_GET['highest_altitude'];
25
                $start_altitude = $_GET['lowest_altitude'];
26
                $sql_altitude = $start_altitude.",".$end_altitude;
27
        } else if($_GET['highest_altitude'] != ""){
28
                $end_altitude = $_GET['highest_altitude'];
29
                $sql_altitude = $end_altitude;
30
        } else if($_GET['highest_altitude'] == "" && $_GET['lowest_altitude'] != ""){
31
                $start_altitude = $_GET['lowest_altitude'].",60000";
32
                $sql_altitude = $start_altitude;
33
        } else $sql_altitude = '';
34
} else $sql_altitude = '';
35
36
//calculuation for the pagination
37 View Code Duplication
if(!isset($_GET['limit']))
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
{
39
        if (!isset($_GET['number_results']))
40
        {
41
                $limit_start = 0;
42
                $limit_end = 25;
43
                $absolute_difference = 25;
44
        } else {
45
                if ($_GET['number_results'] > 1000){
46
                        $_GET['number_results'] = 1000;
47
                }
48
                $limit_start = 0;
49
                $limit_end = $_GET['number_results'];
50
                $absolute_difference = $_GET['number_results'];
51
        }
52
}  else {
53
        $limit_explode = explode(",", $_GET['limit']);
54
        $limit_start = $limit_explode[0];
55
        $limit_end = $limit_explode[1];
56
}
57
58
$absolute_difference = abs($limit_start - $limit_end);
59
$limit_next = $limit_end + $absolute_difference;
60
$limit_previous_1 = $limit_start - $absolute_difference;
61
$limit_previous_2 = $limit_end - $absolute_difference;
62
63
if ($_GET['download'] == "true")
64
{
65
	header('Content-disposition: attachment; filename="flightairmap.gpx"');
66
}
67
68
header('Content-Type: text/xml');
69
70
if (isset($_GET['sort'])) $sort = $_GET['sort'];
71
else $sort = '';
72
$q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING);
73
$registration = filter_input(INPUT_GET,'registratrion',FILTER_SANITIZE_STRING);
74
$aircraft = filter_input(INPUT_GET,'aircraft',FILTER_SANITIZE_STRING);
75
$manufacturer = filter_input(INPUT_GET,'manufacturer',FILTER_SANITIZE_STRING);
76
$highlights = filter_input(INPUT_GET,'highlights',FILTER_SANITIZE_STRING);
77
$airline = filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING);
78
$airline_country = filter_input(INPUT_GET,'airline_country',FILTER_SANITIZE_STRING);
79
$airline_type = filter_input(INPUT_GET,'airline_type',FILTER_SANITIZE_STRING);
80
$airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
81
$airport_country = filter_input(INPUT_GET,'airport_country',FILTER_SANITIZE_STRING);
82
$callsign = filter_input(INPUT_GET,'callsign',FILTER_SANITIZE_STRING);
83
$owner = filter_input(INPUT_GET,'owner',FILTER_SANITIZE_STRING);
84
$pilot_id = filter_input(INPUT_GET,'pilot_id',FILTER_SANITIZE_STRING);
85
$pilot_name = filter_input(INPUT_GET,'pilot_name',FILTER_SANITIZE_STRING);
86
$departure_airport_route = filter_input(INPUT_GET,'departure_airport_route',FILTER_SANITIZE_STRING);
87
$arrival_airport_route = filter_input(INPUT_GET,'arrival_airport_route',FILTER_SANITIZE_STRING);
88
$spotter_array = $Spotter->searchSpotterData($q,$registration,$aircraft,strtolower(str_replace("-", " ", $manufacturer)),$highlights,$airline,$airline_country,$airline_type,$airport,$airport_country,$callsign,$departure_airport_route,$arrival_airport_route,$owner,$pilot_id,$pilot_name,$sql_altitude,$sql_date,$limit_start.",".$absolute_difference,$sort,'');
89
       
90
      
91
$output = '<?xml version="1.0" encoding="UTF-8"?>';
92
	$output .= '<gpx version="1.0">';
93
		$output .= '<name>FlightAirMap GPX Feed</name>';
94
		
95
if (!empty($spotter_array))
96
{
97
	foreach($spotter_array as $spotter_item)
98
	{
99
		$altitude = $spotter_item['altitude'].'00';
100
101
		//waypoint plotting
102
		$output .= '<trk>';
103
		$output .= '<name>'.$spotter_item['ident'].' '.$spotter_item['airline_name'].' | '.$spotter_item['registration'].' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | '.$spotter_item['departure_airport'].' - '.$spotter_item['arrival_airport'].'</name>';
104
		$output .= '<number>1</number>';
105
		if ($spotter_item['waypoints'] != '') {
106
			$output .= '<trkseg>';
107
			$waypoint_pieces = explode(' ', $spotter_item['waypoints']);
108
			$waypoint_pieces = array_chunk($waypoint_pieces, 2);  
109
			foreach ($waypoint_pieces as $waypoint_coordinate)
110
			{
111
				$output .= '<trkpt lat="'.$waypoint_coordinate[0].'" lon="'.$waypoint_coordinate[1].'"><ele>'.$altitude.'</ele><time>'.date("c", strtotime($spotter_item['date_iso_8601'])).'</time></trkpt>';
112
			}
113
			$output .= '</trkseg>';
114
		}
115
		$output .= '</trk>';
116
117
		//location of aircraft
118
		$output .= '<wpt lat="'.$spotter_item['latitude'].'" lon="'.$spotter_item['longitude'].'">';
119
		$output .= '<ele>'.$altitude.'</ele>';
120
		$output .= '<name>Ident: '.$spotter_item['ident'].' | Registration: '.$spotter_item['registration'].' | Aircraft: '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | Airline: '.$spotter_item['airline_name'].' | Route: '.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_name'].', '.$spotter_item['departure_airport_country'].' ('.$spotter_item['departure_airport'].') - '.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_name'].', '.$spotter_item['arrival_airport_country'].' ('.$spotter_item['arrival_airport'].') | Date: '.date("D M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'</name>';
121
		$output .= '</wpt>';
122
	}
123
}
124
$output .= '</gpx>';
125
print $output;
126
127
?>
1 ignored issue
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...