-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
126 lines (126 loc) · 4.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
require_once 'database.php';
require_once 'barchart.php';
?>
<html>
<head>
<title>AnyoneButHarper.net</title>
<meta name="description" content="Strategic voting guide for the 2015 Canadian federal election. Anyone but Harper!" />
<meta charset="ISO-8859-1">
<!-- <meta name=viewport content="width=device-width, initial-scale=1"> -->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/x-icon" href="mapleleaf.ico">
</head>
<body>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-67491457-1', 'auto');
ga('send', 'pageview');
</script>
<?php
//include 'navbar.php';
?>
<div class="provincetitle">Canada Election 2015</div>
<p>If the election were held today, these are the projected seat counts
based on the latest polls.</p>
<?php
SqlBarChart("SELECT projected_winner, COUNT(*) AS seat_count " .
"FROM ridings GROUP BY projected_winner", 200);
?>
<p></p><!-- Super lazy vertical spacer. -->
<p>
Do you want a change of government in the 2015 Canadian election?
Vote for the strongest candidate in your riding who isn't a member
of the current governing party. If all non-conservatives voted this way,
the seat counts would be:
</p>
<?php
SqlBarChart("SELECT winner, COUNT(*) AS seat_count FROM " .
"(SELECT CASE WHEN ndp+lib+grn+bq+oth > con " .
"THEN strategic_vote ELSE 'CON' END AS winner FROM ridings) " .
"AS t GROUP BY winner", 200);
?>
<p></p><!-- Super lazy vertical spacer. -->
<p>
You can <a href="http://www.elections.ca/content.aspx?section=vot&dir=reg&document=index&lang=e">
register to vote</a> online. It's fast and easy.</p>
<div class="footnote">Projections updated
<?php include 'update_date.php'; ?></div>
<div class="provincetitle">Strategic Vote Lookup for All 338 Federal Ridings
</div>
<p>Visit Elections Canada to
<a href="http://www.elections.ca/scripts/vis/FindED?L=e&PAGEID=20">
look up your riding</a> or enter your postal code here:
</p>
<form action="postal_code_lookup.php" method="post"><p>
<input type="text" name="postal_code" size="8" id="postal_code">
<input type="submit" value="Go!" id="submit_button">
</p></form>
<p>
The strongest opposition candidate is
<span style="text-decoration:underline">underlined</span>. The coloured
boxes are the current projected winners.
</p>
<?php
$province_names = [
"AB" => "Alberta",
"BC" => "British Columbia",
"MB" => "Manitoba",
"NB" => "New Brunswick",
"NL" => "Newfoundland & Labrador",
"NS" => "Nova Scotia",
"NT" => "Northwest Territories",
"NU" => "Nunavut",
"ON" => "Ontario",
"PE" => "Prince Edward Island",
"QC" => "Québec",
"SK" => "Saskatchewan",
"YT" => "Yukon",
];
$party_order = ["con", "lib", "ndp", "grn", "bq", "oth"];
$previous_province = "";
$result = query("SELECT * FROM ridings ORDER BY province, name");
while ($row = mysql_fetch_assoc($result)) {
$province = $row["province"];
$name = $row["name"];
$riding_number = $row["number"];
$projected_winner = strtolower($row['projected_winner']);
$strategic_vote = strtolower($row['strategic_vote']);
$confidence = intval(round(100 * $row['confidence']));
if ($province != $previous_province) {
if ($previous_province != "") {
echo ("<div class=\"footnote\">Strongest opposition candidate " .
"is <span style=\"text-decoration:underline\">" .
"underlined</span>." .
"The coloured box is the current projected " .
"winner.</div>\n");
}
$province_name = $province_names[$province];
echo "<div class=\"provincetitle\">$province_name</div>\n";
}
$previous_province = $province;
echo "<div class=\"riding\">\n";
echo ("<a href=\"riding.php?riding_number=$riding_number\" " .
"class=\"ridingname\">$name</a>\n");
echo "<span class=\"sequence\">";
foreach ($party_order as $party) {
if ($party == "bq" && $province != "QC") {
continue;
}
$support = intval(round(100 * $row[$party]));
$extra_classes = "";
if ($party == $strategic_vote) {
$extra_classes .= " strategic";
}
echo "<span class=\"estimate $party $extra_classes\">$support</span>";
}
echo ("<span class=\"projection $projected_winner-proj\">" .
"$confidence%</span></span></div>\n");
}
mysql_free_result($result);
mysql_close();
include 'more_info.php';
?>