Completed
Push — master ( 73f088...7f17b6 )
by Yannick
07:13
created

aircraft-statistics-airline-country.php (3 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
7
if (!isset($_GET['aircraft_type'])) {
8
	header('Location: '.$globalURL.'/aircraft');
9
	die();
10
}
11
$aircraft_type = filter_input(INPUT_GET,'aircraft_type',FILTER_SANITIZE_STRING);
12
$spotter_array = $Spotter->getSpotterDataByAircraft($aircraft_type,"0,1","");
13
14
15
if (!empty($spotter_array))
16
{
17
	$title = sprintf(_("Most Common Airlines by Country from %s (%s)"),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']);
18
	require_once('header.php');
19
    
20
	print '<div class="select-item">';
21
	print '<form action="'.$globalURL.'/aircraft" method="post">';
22
	print '<select name="aircraft_type" class="selectpicker" data-live-search="true">';
23
    	print '<option></option>';
24
    	$aircraft_types = $Spotter->getAllAircraftTypes();
25 View Code Duplication
    	foreach($aircraft_types as $aircrafttype)
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...
26
    	{
27
    		if($aircraft_type == $aircrafttype['aircraft_icao'])
28
    		{
29
    			print '<option value="'.$aircrafttype['aircraft_icao'].'" selected="selected">'.$aircrafttype['aircraft_name'].' ('.$aircrafttype['aircraft_icao'].')</option>';
30
    		} else {
31
    			print '<option value="'.$aircrafttype['aircraft_icao'].'">'.$aircrafttype['aircraft_name'].' ('.$aircrafttype['aircraft_icao'].')</option>';
32
    		}
33
	}
34
	print '</select>';
35
	print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
36
	print '</form>';
37
	print '</div>';
38
39 View Code Duplication
	if ($aircraft_type != "NA")
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...
40
	{
41
		print '<div class="info column">';
42
		print '<h1>'.$spotter_array[0]['aircraft_name'].' ('.$spotter_array[0]['aircraft_type'].')</h1>';
43
		print '<div><span class="label">Name</span>'.$spotter_array[0]['aircraft_name'].'</div>';
44
		print '<div><span class="label">ICAO</span>'.$spotter_array[0]['aircraft_type'].'</div>'; 
45
		print '<div><span class="label">Manufacturer</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>';
46
		print '</div>';
47
	} else {
48
		print '<div class="alert alert-warning">'._("This special aircraft profile shows all flights in where the aircraft type is unknown.").'</div>';
49
	}
50
	include('aircraft-sub-menu.php');
51
	print '<div class="column">';
52
	print '<h2>'._("Most Common Airlines by Country").'</h2>';
53
	print '<p>'.sprintf(_("The statistic below shows the most common airlines by Country of origin of flights from <strong>%s (%s)</strong>."),$spotter_array[0]['aircraft_name'],$spotter_array[0]['aircraft_type']).'</p>';
54
55
	$airline_array = $Spotter->countAllAirlineCountriesByAircraft($aircraft_type);
56
	print '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
57
	print '<div id="chartCountry" class="chart" width="100%"></div>
58
	    <script> 
59
		google.load("visualization", "1", {packages:["geochart"]});
60
        	google.setOnLoadCallback(drawChart);
61
        	function drawChart() {
62
        	    var data = google.visualization.arrayToDataTable([
63
            		["Country", "# of times"], ';
64
            		$country_data = '';
65
	foreach($airline_array as $airline_item)
66
	{
67
		$country_data .= '[ "'.$airline_item['airline_country'].'",'.$airline_item['airline_country_count'].'],';
68
	}
69
	$country_data = substr($country_data, 0, -1);
70
	print $country_data;
71
	print ']);
72
		    var options = {
73
            		legend: {position: "none"},
74
            		chartArea: {"width": "80%", "height": "60%"},
75
            		height:500,
76
            		colors: ["#8BA9D0","#1a3151"]
77
        	    };
78
		    var chart = new google.visualization.GeoChart(document.getElementById("chartCountry"));
79
		    chart.draw(data, options);
80
		}
81
		$(window).resize(function(){
82
    		     drawChart();
83
    		});
84
	     </script>';
85
	if (!empty($airline_array))
86
	{
87
		print '<div class="table-responsive">';
88
		print '<table class="common-country">';
89
		print '<thead>';
90
		print '<th></th>';
91
		print '<th>'._("Country").'</th>';
92
		print '<th>'._("# of times").'</th>';
93
		print '</thead>';
94
		print '<tbody>';
95
		$i = 1;
96
		foreach($airline_array as $airline_item)
97
		{
98
			print '<tr>';
99
			print '<td><strong>'.$i.'</strong></td>';
100
			print '<td>';
101
			print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airline_item['airline_country'])).'">'.$airline_item['airline_country'].'</a>';
102
			print '</td>';
103
			print '<td>';
104
			print $airline_item['airline_country_count'];
105
			print '</td>';
106
			print '</tr>';
107
			$i++;
108
		}
109
		print '<tbody>';
110
		print '</table>';
111
		print '</div>';
112
	}
113
	print '</div>';
114
} else {
115
	$title = _("Aircraft Type");
116
	require_once('header.php');
117
	print '<h1>'._("Error").'</h1>';
118
	print '<p>'._("Sorry, the aircraft type does not exist in this database. :(").'</p>';  
119
}
120
require_once('footer.php');
121
?>
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...