/
election.php
713 lines (645 loc) · 24.2 KB
/
election.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
<?php require_once "common.inc";
# $Id: election.php,v 1.23 2005/11/01 00:56:21 frabcus Exp $
# The Public Whip, Copyright (C) 2003 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under
# certain conditions. However, it comes with ABSOLUTELY NO WARRANTY.
# For details see the file LICENSE.html in the top level of the source.
# 2005 General Election special
# TODO:
# Maybe display anyway when postcode wrong
# Think about dream/person distance, check it works OK
# Do redirect stuff, using interstitial and cookies?
require_once "db.inc";
require_once "decodeids.inc";
require_once "dream.inc";
require_once "pretty.inc";
require_once "constituencies.inc";
require_once "account/user.inc";
$db = new DB();
$db2 = new DB();
$wales_constituencies = array(
"uk.org.publicwhip/cons/1" => 1,
"uk.org.publicwhip/cons/9" => 1,
"uk.org.publicwhip/cons/61" => 1,
"uk.org.publicwhip/cons/79" => 1,
"uk.org.publicwhip/cons/85" => 1,
"uk.org.publicwhip/cons/104" => 1,
"uk.org.publicwhip/cons/105" => 1,
"uk.org.publicwhip/cons/112" => 1,
"uk.org.publicwhip/cons/113" => 1,
"uk.org.publicwhip/cons/114" => 1,
"uk.org.publicwhip/cons/115" => 1,
"uk.org.publicwhip/cons/117" => 1,
"uk.org.publicwhip/cons/118" => 1,
"uk.org.publicwhip/cons/124" => 1,
"uk.org.publicwhip/cons/139" => 1,
"uk.org.publicwhip/cons/140" => 1,
"uk.org.publicwhip/cons/147" => 1,
"uk.org.publicwhip/cons/163" => 1,
"uk.org.publicwhip/cons/168" => 1,
"uk.org.publicwhip/cons/255" => 1,
"uk.org.publicwhip/cons/311" => 1,
"uk.org.publicwhip/cons/351" => 1,
"uk.org.publicwhip/cons/368" => 1,
"uk.org.publicwhip/cons/370" => 1,
"uk.org.publicwhip/cons/383" => 1,
"uk.org.publicwhip/cons/384" => 1,
"uk.org.publicwhip/cons/389" => 1,
"uk.org.publicwhip/cons/398" => 1,
"uk.org.publicwhip/cons/399" => 1,
"uk.org.publicwhip/cons/440" => 1,
"uk.org.publicwhip/cons/457" => 1,
"uk.org.publicwhip/cons/462" => 1,
"uk.org.publicwhip/cons/473" => 1,
"uk.org.publicwhip/cons/569" => 1,
"uk.org.publicwhip/cons/570" => 1,
"uk.org.publicwhip/cons/582" => 1,
"uk.org.publicwhip/cons/595" => 1,
"uk.org.publicwhip/cons/596" => 1,
"uk.org.publicwhip/cons/653" => 1,
"uk.org.publicwhip/cons/658" => 1,
);
$scotland_constituencies = array(
"uk.org.publicwhip/cons/2" => 1,
"uk.org.publicwhip/cons/3" => 1,
"uk.org.publicwhip/cons/4" => 1,
"uk.org.publicwhip/cons/5" => 1,
"uk.org.publicwhip/cons/11" => 1,
"uk.org.publicwhip/cons/12" => 1,
"uk.org.publicwhip/cons/18" => 1,
"uk.org.publicwhip/cons/20" => 1,
"uk.org.publicwhip/cons/106" => 1,
"uk.org.publicwhip/cons/119" => 1,
"uk.org.publicwhip/cons/122" => 1,
"uk.org.publicwhip/cons/141" => 1,
"uk.org.publicwhip/cons/142" => 1,
"uk.org.publicwhip/cons/143" => 1,
"uk.org.publicwhip/cons/160" => 1,
"uk.org.publicwhip/cons/161" => 1,
"uk.org.publicwhip/cons/162" => 1,
"uk.org.publicwhip/cons/181" => 1,
"uk.org.publicwhip/cons/182" => 1,
"uk.org.publicwhip/cons/183" => 1,
"uk.org.publicwhip/cons/184" => 1,
"uk.org.publicwhip/cons/185" => 1,
"uk.org.publicwhip/cons/186" => 1,
"uk.org.publicwhip/cons/196" => 1,
"uk.org.publicwhip/cons/198" => 1,
"uk.org.publicwhip/cons/204" => 1,
"uk.org.publicwhip/cons/207" => 1,
"uk.org.publicwhip/cons/208" => 1,
"uk.org.publicwhip/cons/209" => 1,
"uk.org.publicwhip/cons/212" => 1,
"uk.org.publicwhip/cons/210" => 1,
"uk.org.publicwhip/cons/211" => 1,
"uk.org.publicwhip/cons/225" => 1,
"uk.org.publicwhip/cons/226" => 1,
"uk.org.publicwhip/cons/238" => 1,
"uk.org.publicwhip/cons/242" => 1,
"uk.org.publicwhip/cons/243" => 1,
"uk.org.publicwhip/cons/244" => 1,
"uk.org.publicwhip/cons/245" => 1,
"uk.org.publicwhip/cons/246" => 1,
"uk.org.publicwhip/cons/247" => 1,
"uk.org.publicwhip/cons/248" => 1,
"uk.org.publicwhip/cons/249" => 1,
"uk.org.publicwhip/cons/250" => 1,
"uk.org.publicwhip/cons/251" => 1,
"uk.org.publicwhip/cons/253" => 1,
"uk.org.publicwhip/cons/260" => 1,
"uk.org.publicwhip/cons/269" => 1,
"uk.org.publicwhip/cons/270" => 1,
"uk.org.publicwhip/cons/306" => 1,
"uk.org.publicwhip/cons/316" => 1,
"uk.org.publicwhip/cons/322" => 1,
"uk.org.publicwhip/cons/344" => 1,
"uk.org.publicwhip/cons/350" => 1,
"uk.org.publicwhip/cons/379" => 1,
"uk.org.publicwhip/cons/385" => 1,
"uk.org.publicwhip/cons/388" => 1,
"uk.org.publicwhip/cons/411" => 1,
"uk.org.publicwhip/cons/420" => 1,
"uk.org.publicwhip/cons/439" => 1,
"uk.org.publicwhip/cons/444" => 1,
"uk.org.publicwhip/cons/448" => 1,
"uk.org.publicwhip/cons/449" => 1,
"uk.org.publicwhip/cons/452" => 1,
"uk.org.publicwhip/cons/481" => 1,
"uk.org.publicwhip/cons/485" => 1,
"uk.org.publicwhip/cons/548" => 1,
"uk.org.publicwhip/cons/559" => 1,
"uk.org.publicwhip/cons/588" => 1,
"uk.org.publicwhip/cons/619" => 1,
"uk.org.publicwhip/cons/632" => 1,
"uk.org.publicwhip/cons/627" => 1,
);
$northern_ireland_constituencies = array(
"uk.org.publicwhip/cons/35" => 1,
"uk.org.publicwhip/cons/36" => 1,
"uk.org.publicwhip/cons/37" => 1,
"uk.org.publicwhip/cons/38" => 1,
"uk.org.publicwhip/cons/192" => 1,
"uk.org.publicwhip/cons/197" => 1,
"uk.org.publicwhip/cons/231" => 1,
"uk.org.publicwhip/cons/235" => 1,
"uk.org.publicwhip/cons/325" => 1,
"uk.org.publicwhip/cons/375" => 1,
"uk.org.publicwhip/cons/400" => 1,
"uk.org.publicwhip/cons/402" => 1,
"uk.org.publicwhip/cons/406" => 1,
"uk.org.publicwhip/cons/515" => 1,
"uk.org.publicwhip/cons/519" => 1,
"uk.org.publicwhip/cons/557" => 1,
"uk.org.publicwhip/cons/593" => 1,
"uk.org.publicwhip/cons/629" => 1,
);
$ranks = array(
"strongly for" => 1.0,
"moderately for" => 0.75,
"neutral/mixed on" => 0.50,
"moderately against" => 0.25,
"strongly against" => 0.0,
"don't know about" => 0.50,
);
$issues = array(
array(363, "<strong>foundation hospitals</strong>", false, "foundation hospital"),
array(367, "<strong>student top-up fees</strong>", true, "top-up fees"),
array(258, "Labour's <strong>anti-terrorism laws</strong>", true, "terrorism"),
array(219, "the <strong>Iraq war</strong>", true, "iraq"),
array(230, "introducing <strong>ID cards</strong>", true, "id cards"),
array(358, "the <strong>ban on fox hunting</strong>", true, "hunting"),
array(371, "equal <strong>gay rights</strong>", false, "gay")
);
// Name in database => display name
$parties = array(
"Lab" => "Labour",
"Con" => "Conservative",
"LDem" => "Liberal Democrat",
"Lab/Co-op" => "Labour"
);
$wales_parties = array(
"PC" => "Plaid Cymru"
);
$scotland_parties = array(
"SNP" => "SNP",
);
$northern_ireland_parties = array(
"SF" => "Sinn Féin",
"DU" => "DUP",
"SDLP" => "SDLP",
"UU" => "UUP",
);
$independents = array(
"Ind" => "Independent",
/* "Ind Con" => "Independent",
"Ind Lab" => "Independent",
"Ind UU" => "Independent", */
);
/*print "<pre>";
print count(array_keys($northern_ireland_constituencies));
foreach ($northern_ireland_constituencies as $k) {
print "\"" . normalise_constituency_name(strtolower($k)) . "\" => 1,\n";
}
print "</pre>";*/
function dist_to_desc($dist) {
if ($dist < 0.125)
return "Agree<br>(strong)";
elseif ($dist < 0.375)
return "Agree";
elseif ($dist < 0.625)
return "Neutral";
elseif ($dist < 0.875)
return "Disagree";
else
return "Disagree<br>(strong)";
}
function our_number_format($number) {
return round((1.0-$number) * 100) . "%";
}
function print_friends_form($word) {
?>
<form id="howtovotefriends" name="howtovotefriends" method="post" action="election.php?friend">
<p>Found this useful? <strong>Pass it on</strong>
<br>Your <strong>friend's email</strong>:
<input type="text" size="20" name="friendsemail" value="<?=htmlspecialchars($_POST['friendsemail'])?>">
<br>Your name:
<input type="text" size="20" name="yourname" value="<?=htmlspecialchars($_POST['yourname'])?>">
<br>Your email:
<input type="text" size="20" name="youremail" value="<?=htmlspecialchars($_POST['youremail'])?>">
<input type="hidden" name="submitfriend" value="1">
<br> <input type="submit" name="button" value="Tell <?=$word?> Friend">
<br><small>(privacy: we will not store your email or your friend's email, we
will only use it to send your message to your friend)</small> </p>
</form>
<?
}
function opinion_value($value, $curr)
{
$ret = "value=\"" . html_scrub($value) . "\" ";
if ($value === $curr) {
$ret .= "selected ";
}
return $ret;
}
// Grab shorter URL if it is one
$qstring = $_SERVER["QUERY_STRING"];
$shorter_url = false;
if (preg_match ("/^(.*);([0-4]{7})$/", $qstring, $matches)) {
$_GET = array();
$_GET['submit'] = "1";
$_GET['mppc'] = $matches[1];
$c = 0;
foreach ($issues as $issue) {
$dreamid = $issue[0];
$_GET["i$dreamid"] = floatval(substr($matches[2], $c, 1)) / 4.0;
$c++;
}
$shorter_url = true;
}
// Validate if a submit
$errors = array();
if ($_GET['submit']) {
// Display voting records
$mpattr = get_mpid_attr_decode($db, $db2, "");
if ($mpattr == null) {
$errors[] = "Your MP wasn't found. Please check you
entered the postcode correctly.";
}
foreach ($issues as $issue) {
$dreamid = $issue[0];
if (!array_key_exists("i$dreamid", $_GET) || $_GET["i$dreamid"] < 0) {
$errors[] = "Please select your opinion on " . $issue[1] . ".";
}
}
}
// Redirect to shorter URL
if ($_GET['submit'] and !$errors and !$shorter_url) {
$qpc = strtoupper(trim($_GET['mppc']));
$qpc = str_replace(" ", "", $qpc);
$quick = "?$qpc;";
foreach ($issues as $issue) {
$dreamid = $issue[0];
$quick .= intval($_GET["i$dreamid"] * 4);
}
header("Location: /election.php$quick\n");
return;
}
header("Content-Type: text/html; charset=UTF-8");
?>
<html>
<head>
<title>The Public Whip - How They Voted 2005</title>
<link href="quiz/quiz.css" type="text/css" rel="stylesheet"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<?
if ($_GET['submit'] and !$errors) {
# See if MP is standing again
$mpattr = $mpattr['mpprops'][0];
$constituency = str_replace("&", "&", $mpattr['constituency']);
$standing_again = false;
if ($mpattr['leftreason'] == "general_election_standing") {
$standing_again = true;
}
# Regional parties
$consid = normalise_constituency_name(strtolower($constituency));
if (!$consid) {
print "<div class=\"error\">Constituency '$constituency' not found, please <a href=\"team@publicwhip.org.uk\">let us know</a>.</div>";
}
if (array_key_exists($consid, $wales_constituencies)) {
$parties = array_merge($parties, $wales_parties);
}
if (array_key_exists($consid, $scotland_constituencies)) {
$parties = array_merge($parties, $scotland_parties);
}
if (array_key_exists($consid, $northern_ireland_constituencies)) {
$parties = $northern_ireland_parties;
}
if ($consid == "uk.org.publicwhip/cons/655") { // Wyre Forest, Richard Taylor (Ind)
$parties = array_merge($parties, $independents);
}
$unique_parties = array_values($parties);
$unique_parties = array_unique($unique_parties);
$mp_party = $parties[$mpattr['party']];
#print "<p>MP party $mp_party standing again $standing_again<p>";
# Go through each issue to extract data
$distances = array();
$distances['Comparision'] = array();
$issuecount = 0;
foreach ($issues as $issue) {
$dreamid = $issue[0];
$distances[$dreamid] = array();
$issuecount++;
# Find your score
$distances[$dreamid]['You'] = 1.0 - floatval($_GET["i$dreamid"]);
# Find distance from Dream MP to each party
update_dreammp_person_distance($db, $dreamid);
$query = "select avg(distance_a) as dist, party from
pw_cache_dreamreal_distance
left join pw_mp
on pw_mp.person = pw_cache_dreamreal_distance.person
and left_house = '2005-04-11'
where dream_id = $dreamid group by party";
$db->query($query);
$party_dist = array();
while ($row = $db->fetch_row_assoc()) {
$dist = $row['dist'];
if ($issue[2])
$dist = 1.0 - $dist;
$canonparty = $parties[$row['party']];
$party_dist[$canonparty] += $dist;
}
foreach ($unique_parties as $party) {
$distance = $party_dist[$party];
if ($distance == null) {
$distance = 0.5;
}
$distances[$dreamid][$party] = $distance;
$distances['Comparison'][$party] += abs($distance - $distances[$dreamid]['You']);
}
# And for your MP
$query = "select distance_a as dist from pw_cache_dreamreal_distance
where dream_id = $dreamid and person = " . $mpattr['person'];
$row = $db->query_onez_row_assoc($query);
$dist = $row ? $row['dist'] : 0.5;
if ($issue[2])
$dist = 1.0 - $dist;
$distances[$dreamid]["Your MP"] = $dist;
$distances['Comparison']["Your MP"] += abs($dist - $distances[$dreamid]['You']);
}
# For debugging
#$distances['Comparison']["Your MP"] = 0;
#$distances['Comparison']["Labour"] = 0;
#$standing_again = false;
# Find who you should vote for
$best_party = null;
$best_comparison = 1000000;
foreach ($distances['Comparison'] as $party => $comparison) {
# Remove one out of MP's party and MP
if ($standing_again) {
if ($party == $mp_party)
continue;
} else {
if ($party == "Your MP")
continue;
}
# Test for best
if ($comparison < $best_comparison) {
$best_party = $party;
$best_comparison = $comparison;
}
}
?>
<body>
<div id="divQuizResults">
<h1><a href="/"><span class="fir">The Public Whip</span></a></h1>
<h2>How They Voted 2005</h2>
<h3>(...and so how you should)</h3>
<h4>Quick Election Quiz</h4>
<?
print "<p class=\"advice\">";
if ($best_party == "Your MP") {
?>
The Public Whip suggests you vote for
<b><?=$mpattr['name']?> (<?=$mp_party?>)</b>, your ex-MP
in <?=$constituency?>.
<?
} else {
?>
The Public Whip suggests you vote <b><?=$best_party?></b>
in <?=$constituency?>.
<?
}
if ($standing_again) {
?>
This is based on how your ex-MP (who is standing again)
and MPs of other parties voted in parliament over the last 4 years,
compared to your opinion on these issues. </p>
<?
} else {
?>
This is based on how MPs of that party voted in parliament over the
last 4 years, compared to your opinion on these issues.
Your ex-MP isn't standing again, so we haven't specifically used their vote.
</p>
<?
}
print "</p>";
//<br>distance $best_comparison
print_friends_form("a");
?>
<p class="links">
<b>Questions?</b> Email <a href="mailto:team@publicwhip.org.uk">team@publicwhip.org.uk</a>
<b>Media enquiries?</b> Ring Francis Irving on 07970 543358.
</p>
<p class="links">
We recommend you <b>look at other sources</b> before deciding how to vote.
You might like to take the <a href="http://www.politicalsurvey2005.com/">Political
Survey 2005</a> (more detailed and based on opinion poll data),
or use <a href="http://www.howtovote.co.uk/">how2vote</a> (which asks you
which of different manifesto policies you prefer). For more detail <a
href="http://www.theywanttobeelected.com/manifestos/">read and annotate the
manifestos</a>, or get a useful opinion poll trend graph and links from
<a href="http://election.beasts.org/">election.beasts.org</a>.
</p>
<p class="links">
<a href="election.php">Take the Public Whip quiz again</a> <em>or</em>
<a href="/">Go to the main Public Whip website</a>
</p>
<h5>Detailed Breakdown</h5>
<p>How we worked out who you should vote for.
<?
# Print table
print "<table id=\"tblResult\" class=\"votes\" >";
print "<tr class=\"headings\"><th>Issue (numbers are from <br>100% agrees
strongly to <br>0% disagrees strongly)</th><th>You</th>";
foreach ($unique_parties as $party) {
if ($party == $mp_party and $standing_again) {
print "<th>$party</th><th>".$mpattr['name']. "<br>(your
$party<br>ex-MP)</th>";
} else {
print "<th>$party</th>";
}
}
print "</tr>\n";
$pretty_row = 0;
foreach ($issues as $issue) {
$pretty_row = pretty_row_start($pretty_row);
$dreamid = $issue[0];
print "<td><a href=\"dreammp.php?id=$dreamid\">" . $issue[1] . "</a></td>";
print "<td>" .
dist_to_desc($distances[$dreamid]['You']) . " ";
print our_number_format($distances[$dreamid]['You']);
print "</td>";
foreach ($unique_parties as $party) {
print "<td>";
$distance = $distances[$dreamid][$party];
print dist_to_desc($distance) . " ";
print our_number_format($distance);
if ($party == $mp_party and $standing_again) {
print " <td><a href=\"mp.php?".$mpattr['mpanchor']."&dmp=$dreamid&display=motions\">" .
dist_to_desc($distances[$dreamid]['Your MP']) . "</a> ";
print our_number_format($distances[$dreamid]['Your MP']);
print "</td>";
}
print "</td>";
}
print "</tr>";
}
print "<tr class=\"last\">";
print "<td>Comparison with your opinion:
<br>100% voted same as your view
<br>0% voted opposite to your view</td>";
print "<td> </td>";
foreach ($unique_parties as $party) {
$comparison = $distances['Comparison'][$party];
$comparison /= $issuecount;
print "<td>";
print dist_to_desc($comparison);
print "<br>with you ";
print our_number_format($comparison);
print "</td>";
if ($party == $mp_party and $standing_again) {
$comparison = $distances['Comparison']['Your MP'];
$comparison /= $issuecount;
print "<td>";
print dist_to_desc($comparison);
print "<br>with you ";
print our_number_format($comparison);
print "</td>";
}
}
print "</table>";
?>
<p>This table shows how members of each parliamentary party voted on each issue
in parliament between 2001 and 2005. These are averages for each party. So,
Labour comes out as only "agree" on many issues, rather than "agree
(strong)", because many members rebelled on these controversial issues.
Follow the link for each issue to find out more about which votes we used
to do this calculation. The links in your ex-MP's column (if they are standing
again) will take you to a detailed breakdown of how they voted on the issue.
</p>
<p>The last row shows how each party compares to you. The difference between
you and the party on each each is summed up and averaged. 100% means you
exactly agree with how the party voted, 0% means you exactly disagree.
Each issue is given equal weight, although if you were neutral on an issue
it will naturally score less. The party which we suggest you vote for (above)
has the largest value in this bottom row.
</p>
<?
}
elseif ($_POST['submitfriend']) {
?>
<body>
<div id="divQuizResults">
<h1><a href="/"><span class="fir">The Public Whip</span></a></h1>
<h2>How They Voted 2005</h2>
<h3>(...and so how you should)</h3>
<h4>Quick Election Quiz</h4>
<?
$error = "";
if (!$_POST['friendsemail'] || !$_POST['yourname'] || !$_POST['youremail']) {
$error .= "Please enter all details. ";
} else {
if (!pw_validate_email($_POST['friendsemail']))
$error .= "Enter a valid email address for your friend. ";
if (!pw_validate_email($_POST['youremail']))
$error .= "Enter a valid email address for yourself. ";
}
if ($error) {
print "<p class=\"error\">
Form not complete, please correct and try again.
$error
</p>";
print_friends_form("a");
} else {
$message = <<<END
Your friend ${_POST['yourname']} <${_POST['youremail']}> saw this
'how to vote' website and thought of you.
http://www.publicwhip.org.uk/election.php
The site asks your opinion on key issues (such as the Iraq war,
Hunting and Foundation Hospitals). Then it compares your opinion
with the actual vote in parliament of MPs over the last four
years, and recommends which party you should vote for.
Unlike the parties, we don't have any marketing budget, so
please help us out by forwarding this to any of your friends
who might like it. We believe that both MPs and parties should
be held to account for how they voted in parliament.
Enjoy the election!
-- The Public Whip team
The Public Whip ( http://www.publicwhip.org.uk ) is a project to
data-mine the voting record of Members of the United Kingdom
Parliament, so that you can hold them to account.
END;
$success = mail ($_POST['friendsemail'],'How to vote based on how MPs voted in the last 4 years',$message,'From: The Public Whip <team@publicwhip.org.uk>');
if ($success) {
print "<p class=\"advice\">Mail successfully sent to ".
htmlspecialchars($_POST['friendsemail']).
"</p><p class=\"advice\">You can send another if you like!</p>";
}
else {
print "<div class=\"error\">Failed to send mail</div>";
}
$_POST['friendsemail'] = "";
print_friends_form("another");
?>
<p class="links"><a href="election.php">Take the quiz again</a> <em>or</em>
<a href="/">Go to the main Public Whip website</a> </p>
</div>
<?
}
} else {
?>
<body>
<div id="frmHowToVote">
<form name="howtovote" method="get" action="election.php">
<h1><a href="/"><span class="fir">The Public Whip</span></a></h1>
<h2>How They Voted 2005</h2>
<h3>(...and so how you should)</h3>
<h4>Quick Election Quiz</h4>
<?
if ($errors) {
print "<p class=\"error\">";
print join($errors, "<br>");
print "</p>";
}
?>
<ol id="olQuiz">
<li>
Enter your UK <strong>postcode</strong>: <input type="text" size="10" name="mppc" value="<?=htmlspecialchars($_GET['mppc'])?>" id="Text1"> <br/>
(so we know who your last <abbr title="Member of Parliament">MP</abbr> was)
</li>
<li>
<p>
Choose how you feel about each of these issues. We'll tell you how your ex-<abbr title="Member of Parliament">MP</abbr> and each party voted on them in parliament over the last 4 years.
</p>
<ul id="ulQuestions">
<?
foreach ($issues as $issue) {
print "<li>";
print 'I am <select name="i'.$issue[0].'">' . "\n";
print "<option value=\"-1\" selected>-- please choose --</option>\n";
foreach ($ranks as $rank_name => $rank_value) {
print "<option ";
print opinion_value($rank_value, ($_GET['submit'] ? floatval($_GET['i'.$issue[0]]) : ""));
print ">$rank_name</option>\n";
}
print "</select>" . $issue[1] . "\n";
print "</li>";
}
?>
</ul>
</li>
</ol>
<input id="submit" name="submit" type="hidden" value="1">
<div id="submit"><input type="submit" name="button" value="Submit" id="button"></div>
<p id="pPoweredBy">
Powered by <a href="http://www.publicwhip.org.uk" title="Go to the main Public Whip website">The Public Whip</a>
</p>
</form>
</div>
</body>
<?
}
?>
</html>