Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / statistics-fatalities-year.php
blob33466ac284d4cecd69b514e81ced69c245a7234c
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Accident.php');
4 require_once('require/class.Language.php');
5 $Accident = new Accident();
6 $title = _("Statistics").' - '._("Fatalities by Year");
8 require_once('header.php');
9 include('statistics-sub-menu.php');
10 print '<link href="'.$globalURL.'/css/c3.min.css" rel="stylesheet" type="text/css">';
11 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
12 print '<script type="text/javascript" src="'.$globalURL.'/js/c3.min.js"></script>';
13 print '<div class="info">
14 <h1>'._("Fatalities by Year").'</h1>
15 </div>
16 <p>'._("Below is a chart that plots the fatalities by <strong>year</strong>.").'</p>';
18 $date_array = $Accident->countFatalitiesByYear();
19 print '<div id="chart" class="chart" width="100%"></div><script>';
20 $year_data = '';
21 $year_cnt = '';
22 foreach($date_array as $year_item)
24 $year_data .= '"'.$year_item['year'].'-01-01",';
25 $year_cnt .= $year_item['count'].',';
27 $year_data = "['x',".substr($year_data, 0, -1)."]";
28 $year_cnt = "['flights',".substr($year_cnt,0,-1)."]";
29 print 'c3.generate({
30 bindto: "#chart",
31 data: { x: "x",
32 columns: ['.$year_data.','.$year_cnt.'], types: { flights: "area"}, colors: { flights: "#1a3151"}},
33 axis: { x: { type: "timeseries",tick: { format: "%Y"}}, y: { label: "# of Flights"}},legend: { show: false }});';
34 print '</script>';
36 if (!empty($date_array))
38 foreach($date_array as $key => $row) {
39 $years[$key] = $row['year'];
40 $counts[$key] = $row['count'];
42 //array_multisort($years,SORT_DESC,$date_array);
43 array_multisort($counts,SORT_DESC,$date_array);
44 print '<div class="table-responsive">';
45 print '<table class="common-date table-striped">';
46 print '<thead>';
47 print '<th></th>';
48 print '<th>'._("Year").'</th>';
49 print '<th>'._("# of Fatalities").'</th>';
50 print '</thead>';
51 print '<tbody>';
52 $i = 1;
53 foreach($date_array as $date_item)
55 print '<tr>';
56 print '<td><strong>'.$i.'</strong></td>';
57 print '<td>';
58 print '<a href="'.$globalURL.'/accident/'.$date_item['year'].'">'.$date_item['year'].'</a>';
59 print '</td>';
60 print '<td>';
61 print $date_item['count'];
62 print '</td>';
63 print '</tr>';
64 $i++;
66 print '<tbody>';
67 print '</table>';
68 print '</div>';
71 require_once('footer.php');