Skip to content

Commit

Permalink
Add date and stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
frabcus committed Oct 4, 2007
1 parent 0b1a7b2 commit ae65d12
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 106 deletions.
158 changes: 83 additions & 75 deletions website/election2007.php
@@ -1,6 +1,6 @@
<?php require_once "common.inc"; <?php require_once "common.inc";


# $Id: election2007.php,v 1.16 2007/10/04 14:46:55 publicwhip Exp $ # $Id: election2007.php,v 1.17 2007/10/04 23:05:43 frabcus Exp $


# The Public Whip, Copyright (C) 2003 Francis Irving and Julian Todd # The Public Whip, Copyright (C) 2003 Francis Irving and Julian Todd
# This is free software, and you are welcome to redistribute it under # This is free software, and you are welcome to redistribute it under
Expand Down Expand Up @@ -63,7 +63,8 @@
# XXX terrorism - there are loads of votes # XXX terrorism - there are loads of votes
# XXX ID cards - there are loads of votes # XXX ID cards - there are loads of votes
); );
$polyicystrnum = array("iraq"=>0, "foia"=>1, "lrrb"=>2, "smoking"=>3, "trident"=>4); $policystrnum = array("iraq"=>0, "foia"=>1, "lrrb"=>2, "smoking"=>3, "trident"=>4);
$policynumstr = array_flip($policystrnum);


// Name in database => display name // Name in database => display name
$parties = array( $parties = array(
Expand Down Expand Up @@ -95,7 +96,7 @@
); );





/*
// Grab shorter URL if it is one // Grab shorter URL if it is one
$qstring = $_SERVER["QUERY_STRING"]; $qstring = $_SERVER["QUERY_STRING"];
$shorter_url = false; $shorter_url = false;
Expand All @@ -112,24 +113,29 @@
} }
$shorter_url = true; $shorter_url = true;
} }
*/


// Validate if a submit // Validate if a submit
$errors = array(); $errors = array();
if ($_GET['submit']) { if ($_GET['submit']) {
$mpattr = null;
$constituency = postcode_to_constituency($db, $_GET['mppc'], $postcode_year); $constituency = postcode_to_constituency($db, $_GET['mppc'], $postcode_year);
$row = $db->query_onez_row_assoc("select * from pw_mp where constituency = '$constituency' $constituency = "Kirkcaldy &amp; Cowdenbeath"; // XXX temp
and ($date_clause)"); if ($constituency) {
if ($row) $row = $db->query_onez_row_assoc("select * from pw_mp where constituency = '$constituency'
$mpid = $row['mp_id']; and ($date_clause)");
$mpattr = get_mpid_attr($db, $db2, $mpid, false, 1, null); if ($row)
if ($mpattr == null) { $mpid = $row['mp_id'];
$errors[] = "Your MP wasn't found. Please check you $mpattr = get_mpid_attr($db, $db2, $mpid, false, 1, null);
entered the postcode correctly."; if ($mpattr == null) {
$errors[] = "Your MP wasn't found. Please check you
entered the postcode correctly.";
}
} }
} }


// Redirect to shorter URL // Redirect to shorter URL
if ($_GET['submit'] and !$errors and !$shorter_url) { /*if ($_GET['submit'] and !$errors and !$shorter_url) {
$qpc = strtoupper(trim($_GET['mppc'])); $qpc = strtoupper(trim($_GET['mppc']));
$qpc = str_replace(" ", "", $qpc); $qpc = str_replace(" ", "", $qpc);
$quick = "?$qpc;"; $quick = "?$qpc;";
Expand All @@ -140,7 +146,7 @@
header("Location: /election2007.php$quick\n"); header("Location: /election2007.php$quick\n");
return; return;
} }*/


header("Content-Type: text/html; charset=UTF-8"); header("Content-Type: text/html; charset=UTF-8");
?> ?>
Expand All @@ -156,6 +162,7 @@
<script type="text/javascript" src="./quiz/slider.js"></script> <script type="text/javascript" src="./quiz/slider.js"></script>


<? if ($_GET['submit'] /*and !$errors*/) { <? if ($_GET['submit'] /*and !$errors*/) {

# See if MP is standing again # See if MP is standing again
$mpattr = $mpattr['mpprops'][0]; $mpattr = $mpattr['mpprops'][0];
$constituency = str_replace("&amp;", "&", $mpattr['constituency']); $constituency = str_replace("&amp;", "&", $mpattr['constituency']);
Expand All @@ -170,19 +177,20 @@
$consid = normalise_constituency_name($db, strtolower($constituency), "2001"); $consid = normalise_constituency_name($db, strtolower($constituency), "2001");
if (!$consid) { if (!$consid) {
print "<div class=\"error\">Constituency '$constituency' not found, please <a href=\"team@publicwhip.org.uk\">let us know</a>.</div>"; print "<div class=\"error\">Constituency '$constituency' not found, please <a href=\"team@publicwhip.org.uk\">let us know</a>.</div>";
exit; # exit;
} } else {
if (array_key_exists($consid, $wales_constituencies)) { if (array_key_exists($consid, $wales_constituencies)) {
$parties = array_merge($parties, $wales_parties); $parties = array_merge($parties, $wales_parties);
} }
if (array_key_exists($consid, $scotland_constituencies)) { if (array_key_exists($consid, $scotland_constituencies)) {
$parties = array_merge($parties, $scotland_parties); $parties = array_merge($parties, $scotland_parties);
} }
if (array_key_exists($consid, $northern_ireland_constituencies)) { if (array_key_exists($consid, $northern_ireland_constituencies)) {
$parties = $northern_ireland_parties; $parties = $northern_ireland_parties;
} }
if ($consid == "uk.org.publicwhip/cons/655") { // Wyre Forest, Richard Taylor (Ind) if ($consid == "uk.org.publicwhip/cons/655") { // Wyre Forest, Richard Taylor (Ind)
$parties = array_merge($parties, $independents); $parties = array_merge($parties, $independents);
}
} }
$lookup_parties = $parties; $lookup_parties = $parties;
if ($standing_again) { if ($standing_again) {
Expand Down Expand Up @@ -231,45 +239,50 @@
$distances['Comparison'][$party] += abs($distance - $distances[$dreamid]['You']); $distances['Comparison'][$party] += abs($distance - $distances[$dreamid]['You']);
} }


# And for your MP # And for your MP, if you have one
$query = "select distance_a as dist from pw_cache_dreamreal_distance if ($mpattr) {
where dream_id = $dreamid and person = " . $mpattr['person']; $query = "select distance_a as dist from pw_cache_dreamreal_distance
$row = $db->query_onez_row_assoc($query); where dream_id = $dreamid and person = " . $mpattr['person'];
$dist = $row ? $row['dist'] : 0.5; $row = $db->query_onez_row_assoc($query);
if ($issue[2]) $dist = $row ? $row['dist'] : 0.5;
$dist = 1.0 - $dist; if ($issue[2])
$distances[$dreamid]["Your MP"] = $dist; $dist = 1.0 - $dist;
$distances['Comparison']["Your MP"] += abs($dist - $distances[$dreamid]['You']); $distances[$dreamid]["Your MP"] = $dist;

$distances['Comparison']["Your MP"] += abs($dist - $distances[$dreamid]['You']);
}
} }


// Work out the questions from hell // Work out the questions from hell
$polfill = array(); if ($mpattr) {
foreach ($questlistmaps as $questmap) $polfill = array();
{ foreach ($questlistmaps as $questmap)
$polval = $questmap["policydir"] . $polyicystrnum[$questmap["issue"]];
#print "<pre>"; print_r($questmap); print "</pre>";
if (!$polfill[$polval])
{ {
print "<pre>"; print_r($questmap); print "</pre>"; $polval = $questmap["policydir"] . $policystrnum[$questmap["issue"]];
# XXX should be only when MP is standing again #print "<pre>"; print_r($questmap); print "</pre>";
$divdate = $questmap["date"]; if (!$polfill[$polval])
$divnum = $questmap["divisionno"]; {
$query = "select vote from pw_vote #print "<pre>"; print_r($questmap); print "</pre>";
left join pw_mp on pw_mp.mp_id = pw_vote.mp_id # XXX should be only when MP is standing again
left join pw_division on pw_division.division_id = pw_vote.division_id $divdate = $questmap["date"];
where pw_mp.person = " . $mpattr['person'] . " $divnum = $questmap["divisionno"];
and pw_division.division_date = '" . $divdate . "' and pw_division.division_number = " . $divnum . " $query = "select vote from pw_vote
"; left join pw_mp on pw_mp.mp_id = pw_vote.mp_id
list ($mpvote) = $db->query_onez_row($query); left join pw_division on pw_division.division_id = pw_vote.division_id
if (!$mpvote) where pw_mp.person = " . $mpattr['person'] . "
$mpvote = "absent"; and pw_division.division_date = '" . $divdate . "' and pw_division.division_number = " . $divnum . "
print $mpvote . " --> " . $questmap["mpvote"] . "<br>"; ";
if ($mpvote == $questmap["mpvote"]) list ($mpvote) = $db->query_onez_row($query);
$polfill[$polval] = 'Why did XXXX '.$questmap["mpposition"]." ".$questmap["question"]."?"; if (!$mpvote)
$mpvote = "absent";
#print $mpvote . " --> " . $questmap["mpvote"] . "<br>";
if ($mpvote == $questmap["mpvote"]) {
$polfill[$polval] = 'Why did XXXX '.$questmap["mpposition"]." ".$questmap["question"]."?";

$polfill[$polval] .= " This division was on " . date("j M Y");
}
}
} }
} }
print "<pre>"; print_r($polfill); print "</pre>";


?> ?>
<script type="text/javascript"> <script type="text/javascript">
Expand Down Expand Up @@ -434,6 +447,13 @@ function selpol()
<h2 id="howtheyvoted">How They Voted 2007</h2> <h2 id="howtheyvoted">How They Voted 2007</h2>
<h3>(...and so how you should)</h3> <h3>(...and so how you should)</h3>
<h4>Quick Election Quiz</h4> <h4>Quick Election Quiz</h4>
<?
if ($errors) {
print "<p class=\"error\">";
print join($errors, "<br>");
print "</p>";
}
?>
<? <?


//print "<p class=\"advice\">"; //print "<p class=\"advice\">";
Expand Down Expand Up @@ -516,13 +536,16 @@ function selpol()


<div class="question_from_hell"> <div class="question_from_hell">
<? <?
# print "<pre>"; print_r($polfill); print "</pre>";
foreach ($polfill as $code => $text) { foreach ($polfill as $code => $text) {
print '<div class="floating_question" id="'.$code.'" style="position:absolute">'; print '<div class="floating_question" id="'.$code.'" style="position:absolute">';
print "<h5>Question from Hell</h5>"; print "<h5>Question from Hell</h5>";
$text = str_replace("XXXX", "<strong>".$mpattr["name"]."</strong>", $text); $text = str_replace("XXXX", "<strong>".$mpattr["name"]."</strong>", $text);
print $text; print $text;
print "<p><em>Ask this when irksome ".$parties[$mpattr["party"]]." people knock on your door, or to your former MP at a local hustings.</em>"; print "<p><em>Ask this when irksome ".$parties[$mpattr["party"]]." people knock on your door, or to your former MP at a local hustings.</em>";
$issue = str_replace("policy-against", "", str_replace("policy-for", "", $code));
foreach ($newsarticles[$policynumstr[intval($issue)]] as $id => $newsarticle)
print '<p>'.StrArticle($newsarticle).'</p>';

print "</div>"; print "</div>";
} }
?> ?>
Expand All @@ -542,14 +565,6 @@ function selpol()
<a href="/">Go to the main Public Whip website</a> <a href="/">Go to the main Public Whip website</a>
</p> </p>


<br><br><br><br>
<?
foreach ($newsarticles as $id => $newsarticle)
print '<p>'.StrArticle($newsarticle).'</p>';
?>
<br><br><br><br>


<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[


Expand All @@ -573,13 +588,6 @@ function selpol()
<h3>(...and so how you should)</h3> <h3>(...and so how you should)</h3>
<h4>Quick Election Quiz</h4> <h4>Quick Election Quiz</h4>
<form id="frmHowToVote" name="howtovote" method="get" action="election2007.php"> <form id="frmHowToVote" name="howtovote" method="get" action="election2007.php">
<?
/* if ($errors) {
print "<p class=\"error\">";
print join($errors, "<br>");
print "</p>";
} */
?>


Enter your UK <strong>postcode</strong>: <input type="text" size="10" name="mppc" value="<?=htmlspecialchars($_GET['mppc'])?>" id="Text1"> <br/> 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) (so we know who your last <abbr title="Member of Parliament">MP</abbr> was)
Expand Down

0 comments on commit ae65d12

Please sign in to comment.