diff --git a/website/election2007.php b/website/election2007.php index aec89305..e212f942 100644 --- a/website/election2007.php +++ b/website/election2007.php @@ -1,6 +1,6 @@ 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 $parties = array( @@ -95,7 +96,7 @@ ); - +/* // Grab shorter URL if it is one $qstring = $_SERVER["QUERY_STRING"]; $shorter_url = false; @@ -112,24 +113,29 @@ } $shorter_url = true; } +*/ // Validate if a submit $errors = array(); if ($_GET['submit']) { + $mpattr = null; $constituency = postcode_to_constituency($db, $_GET['mppc'], $postcode_year); - $row = $db->query_onez_row_assoc("select * from pw_mp where constituency = '$constituency' - and ($date_clause)"); - if ($row) - $mpid = $row['mp_id']; - $mpattr = get_mpid_attr($db, $db2, $mpid, false, 1, null); - if ($mpattr == null) { - $errors[] = "Your MP wasn't found. Please check you - entered the postcode correctly."; +$constituency = "Kirkcaldy & Cowdenbeath"; // XXX temp + if ($constituency) { + $row = $db->query_onez_row_assoc("select * from pw_mp where constituency = '$constituency' + and ($date_clause)"); + if ($row) + $mpid = $row['mp_id']; + $mpattr = get_mpid_attr($db, $db2, $mpid, false, 1, null); + if ($mpattr == null) { + $errors[] = "Your MP wasn't found. Please check you + entered the postcode correctly."; + } } } // 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 = str_replace(" ", "", $qpc); $quick = "?$qpc;"; @@ -140,7 +146,7 @@ header("Location: /election2007.php$quick\n"); return; -} +}*/ header("Content-Type: text/html; charset=UTF-8"); ?> @@ -156,6 +162,7 @@ Constituency '$constituency' not found, please let us know."; - exit; - } - 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); +# exit; + } else { + 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); + } } $lookup_parties = $parties; if ($standing_again) { @@ -231,45 +239,50 @@ $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']); - + # And for your MP, if you have one + if ($mpattr) { + $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']); + } } // Work out the questions from hell - $polfill = array(); - foreach ($questlistmaps as $questmap) - { - $polval = $questmap["policydir"] . $polyicystrnum[$questmap["issue"]]; - #print "
"; print_r($questmap); print "
"; - if (!$polfill[$polval]) + if ($mpattr) { + $polfill = array(); + foreach ($questlistmaps as $questmap) { - print "
"; print_r($questmap); print "
"; - # XXX should be only when MP is standing again - $divdate = $questmap["date"]; - $divnum = $questmap["divisionno"]; - $query = "select vote from pw_vote - left join pw_mp on pw_mp.mp_id = pw_vote.mp_id - left join pw_division on pw_division.division_id = pw_vote.division_id - where pw_mp.person = " . $mpattr['person'] . " - and pw_division.division_date = '" . $divdate . "' and pw_division.division_number = " . $divnum . " - "; - list ($mpvote) = $db->query_onez_row($query); - if (!$mpvote) - $mpvote = "absent"; - print $mpvote . " --> " . $questmap["mpvote"] . "
"; - if ($mpvote == $questmap["mpvote"]) - $polfill[$polval] = 'Why did XXXX '.$questmap["mpposition"]." ".$questmap["question"]."?"; + $polval = $questmap["policydir"] . $policystrnum[$questmap["issue"]]; + #print "
"; print_r($questmap); print "
"; + if (!$polfill[$polval]) + { + #print "
"; print_r($questmap); print "
"; + # XXX should be only when MP is standing again + $divdate = $questmap["date"]; + $divnum = $questmap["divisionno"]; + $query = "select vote from pw_vote + left join pw_mp on pw_mp.mp_id = pw_vote.mp_id + left join pw_division on pw_division.division_id = pw_vote.division_id + where pw_mp.person = " . $mpattr['person'] . " + and pw_division.division_date = '" . $divdate . "' and pw_division.division_number = " . $divnum . " + "; + list ($mpvote) = $db->query_onez_row($query); + if (!$mpvote) + $mpvote = "absent"; + #print $mpvote . " --> " . $questmap["mpvote"] . "
"; + if ($mpvote == $questmap["mpvote"]) { + $polfill[$polval] = 'Why did XXXX '.$questmap["mpposition"]." ".$questmap["question"]."?"; + + $polfill[$polval] .= " This division was on " . date("j M Y"); + } + } } } - print "
"; print_r($polfill); print "
"; ?>