Completed
Push — master ( ae4662...65be4b )
by Yannick
11:45 queued 04:47
created

country-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
if (!isset($_GET['country'])) {
6
        header('Location: '.$globalURL.'/country');
7
        die();
8
}
9
$Spotter = new Spotter();
10
$country = ucwords(str_replace("-", " ", filter_input(INPUT_GET,'country',FILTER_SANITIZE_STRING)));
11
$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
12
13 View Code Duplication
if (isset($_GET['sort'])) {
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...
14
	$spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", $sort);
15
} else {
16
	$spotter_array = $Spotter->getSpotterDataByCountry($country, "0,1", '');
17
}
18
19 View Code Duplication
if (!empty($spotter_array))
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...
20
{
21
	$title = sprintf(_("Most Common Airlines by Country of %s"),$country);
22
	require_once('header.php');
23
	print '<div class="select-item">';
24
	print '<form action="'.$globalURL.'/country" method="post">';
25
	print '<select name="country" class="selectpicker" data-live-search="true">';
26
	print '<option></option>';
27
	$all_countries = $Spotter->getAllCountries();
28
	foreach($all_countries as $all_country)
29
	{
30
		if($country == $all_country['country'])
31
		{
32
			print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'" selected="selected">'.$all_country['country'].'</option>';
33
		} else {
34
			print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'">'.$all_country['country'].'</option>';
35
		}
36
	}
37
	print '</select>';
38
	print '<button type="submit"><i class="fa fa-angle-double-right"></i></button>';
39
	print '</form>';
40
	print '</div>';
41
42
	if ($_GET['country'] != "NA")
43
	{
44
		print '<div class="info column">';
45
		print '<h1>'.sprintf(_("Airports &amp; Airlines from %s"),$country).'</h1>';
46
		print '</div>';
47
	} else {
48
		print '<div class="alert alert-warning">'._("This special country profile shows all flights that do <u>not</u> have a country of a airline or departure/arrival airport associated with them.").'</div>';
49
	}
50
51
	include('country-sub-menu.php');
52
	print '<div class="column">';
53
	print '<h2>'._("Most Common Airlines by Country").'</h2>';
54
	print '<p>'.sprintf(_("The statistic below shows the most common airlines by Country of origin of flights from airports &amp; airlines of <strong>%s</strong>."),$country).'</p>';
55
	$airline_array = $Spotter->countAllAirlineCountriesByCountry($country);
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
    
73
            var options = {
74
            	legend: {position: "none"},
75
            	chartArea: {"width": "80%", "height": "60%"},
76
            	height:500,
77
            	colors: ["#8BA9D0","#1a3151"]
78
            };
79
    
80
            var chart = new google.visualization.GeoChart(document.getElementById("chartCountry"));
81
            chart.draw(data, options);
82
          }
83
          $(window).resize(function(){
84
    			  drawChart();
85
    			});
86
      </script>';
87
88
	if (!empty($airline_array))
89
	{
90
		print '<div class="table-responsive">';
91
		print '<table class="common-country table-striped">';
92
		print '<thead>';
93
		print '<th></th>';
94
		print '<th>'._("Country").'</th>';
95
		print '<th>'._("# of times").'</th>';
96
		print '</thead>';
97
		print '<tbody>';
98
		$i = 1;
99
		foreach($airline_array as $airline_item)
100
		{
101
			print '<tr>';
102
			print '<td><strong>'.$i.'</strong></td>';
103
			print '<td>';
104
			print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airline_item['airline_country'])).'">'.$airline_item['airline_country'].'</a>';
105
			print '</td>';
106
			print '<td>';
107
			print $airline_item['airline_country_count'];
108
			print '</td>';
109
			print '</tr>';
110
			$i++;
111
		}
112
		print '<tbody>';
113
		print '</table>';
114
		print '</div>';
115
	}
116
	print '</div>';
117
} else {
118
	$title = _("Country");
119
	require_once('header.php');
120
	print '<h1>'._("Error").'</h1>';
121
	print '<p>'._("Sorry, the country does not exist in this database. :(").'</p>';  
122
}
123
124
require_once('footer.php');
125
?>
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...