Ejemplo n.º 1
0
function api_getConstituency_postcode($pc)
{
    $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
    if (!validate_postcode($pc)) {
        api_error('Invalid postcode');
        return;
    }
    $constituency = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc);
    if ($constituency == 'CONNECTION_TIMED_OUT') {
        api_error('Connection timed out');
        return;
    }
    if (!$constituency) {
        api_error('Unknown postcode');
        return;
    }
    return _api_getConstituency_name($constituency);
}
Ejemplo n.º 2
0
<?php

include_once '../../includes/easyparliament/init.php';
include_once INCLUDESPATH . "easyparliament/member.php";
$pc = get_http_var('pc');
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (!$pc) {
    exit;
}
if (validate_postcode($pc)) {
    $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc));
    if ($constituency == "CONNECTION_TIMED_OUT") {
        $errors['pc'] = "Sorry, we couldn't check your postcode right now. Please use the 'All Mps' link above to browse MPs";
    } elseif ($constituency == "") {
        $errors['pc'] = "Sorry, " . _htmlentities($pc) . " isn't a known postcode";
        twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency");
    } else {
        $MEMBER = new MEMBER(array('constituency' => $constituency));
        if ($MEMBER->person_id()) {
            // This will cookie the postcode.
            $THEUSER->set_postcode_cookie($pc);
        }
        if ($MEMBER->person_id()) {
            header('Location: http://' . DOMAIN . '/rss/mp/' . $MEMBER->person_id() . '.rdf');
        }
    }
} else {
    $errors['pc'] = "Sorry, " . _htmlentities($pc) . " isn't a valid postcode";
    twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
}
Ejemplo n.º 3
0
 /**
  * Test converting a broken postcode to a constituency, make sure we get an empty string
  */
 public function testBrokenPostcodeToConstituency()
 {
     $this->assertEquals('', MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency('ZZ00 ABC'));
 }
Ejemplo n.º 4
0
function get_person_by_postcode($pc)
{
    global $THEUSER;
    $pc = preg_replace('#[^a-z0-9]#i', '', $pc);
    if (!validate_postcode($pc)) {
        twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
        throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn&rsquo;t a valid postcode');
    }
    twfy_debug('MP', "MP lookup by postcode");
    $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc));
    if ($constituency == "connection_timed_out") {
        throw new MySociety\TheyWorkForYou\MemberException('Sorry, we couldn&rsquo;t check your postcode right now, as our postcode lookup server is under quite a lot of load.');
    } elseif ($constituency == "") {
        twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency");
        throw new MySociety\TheyWorkForYou\MemberException('Sorry, ' . _htmlentities($pc) . ' isn&rsquo;t a known postcode');
    } else {
        // Redirect to the canonical MP page, with a person id.
        $MEMBER = new MySociety\TheyWorkForYou\Member(array('constituency' => $constituency, 'house' => HOUSE_TYPE_COMMONS));
        if ($MEMBER->person_id()) {
            // This will cookie the postcode.
            $THEUSER->set_postcode_cookie($pc);
        }
        member_redirect($MEMBER, 302);
    }
}
Ejemplo n.º 5
0
 public function set_users_mp()
 {
     // Is this MP THEUSER's MP?
     global $THEUSER;
     if (is_object($THEUSER) && $THEUSER->postcode_is_set() && $this->current_member(1)) {
         $pc = $THEUSER->postcode();
         twfy_debug('MP', "set_users_mp converting postcode to person");
         $constituency = strtolower(MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc));
         if ($constituency == strtolower($this->constituency())) {
             $this->the_users_mp = true;
         }
     }
 }
Ejemplo n.º 6
0
$errors = array();
$email = trim(get_http_var('email'));
if (!$email) {
    $errors[] = 'Please enter your e-mail address';
} elseif (!validate_email($email)) {
    $errors[] = 'Please enter a valid e-mail address';
}
$postcode = trim(get_http_var('postcode'));
$postcode = preg_replace('#[^A-Z0-9]#i', '', $postcode);
if (!$postcode) {
    $errors[] = 'Please enter your postcode';
} elseif (!validate_postcode($postcode)) {
    $errors[] = 'Please enter a valid postcode';
}
if (!$errors) {
    $constituency = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($postcode);
    if ($constituency != "connection_timed_out" && $constituency != "") {
        $token = auth_random_token();
        if (send_subscribe_email($email, $token)) {
            $q = $db->query("INSERT INTO campaigners (email, postcode, token, signup_date, constituency) VALUES (:email, :postcode, :token, now(), :constituency)", array(':email' => $email, ':postcode' => $postcode, ':token' => $token, ':constituency' => $constituency));
            print "<html><head><title>Check your email! - Free Our Bills - TheyWorkForYou</title></head><body>";
            freeourbills_styles();
            ?>
        <h1 class="free_our_bills_confirm">Nearly Done! Now check your email...</h1>
        <h2 class="free_our_bills_confirm">The confirmation email <strong>may</strong> take a few minutes to arrive &mdash; <em>please</em> be patient.</h2>
        <p class="free_our_bills_confirm">If you use web-based email or have 'junk mail' filters, you may wish to check your bulk&#47;spam mail folders: sometimes, our messages are marked that way.</p>
        <p class="free_our_bills_confirm">You must now click on the link within the email we've just sent you -<br>if you do not, you will not have joined the Free Our Bills campaign.</p>

        <?php 
            exit;
        }