Exemplo n.º 1
0
            $constituency = postcode_to_constituency($pc);
        } else {
            $constituency = $cconstituency;
        }
        if ($constituency == "connection_timed_out") {
            $errors['pc'] = "Sorry, we couldn't check your postcode right now, as our postcode lookup server is under quite a lot of load. Please use the 'All MPs' link above to browse all the 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");
        } elseif (is_array($constituency)) {
            $PAGE->page_start_mobile();
            $PAGE->stripe_start();
            print '<p>There are several electoral divisions within your postcode. Please select from the following:</p><ul>';
            foreach ($constituency as $c) {
                $member = new MEMBER(array('constituency' => $c));
                print '<li><a href="' . WEBPATH . 'mp/?pc=' . $pc . '&c=' . $c . '">' . ucwords(strtolower($member->full_name())) . ', ' . $member->constituency() . '</a></li>';
            }
            print '</ul>';
            $MPSURL = new URL('mps');
            $sidebar = array('type' => 'html', 'content' => '<div class="block">
						<h4><a href="' . $MPSURL->generate() . '">Browse all MPs</a></h4>
					</div>');
            //$PAGE->stripe_end(array($sidebar));
        } else {
            // Redirect to the canonical MP page, with a person id.
            $MEMBER = new MEMBER(array('constituency' => $constituency));
            if ($MEMBER->person_id()) {
                if ($THEUSER->isloggedin()) {
                    # Updates too much in the database to make one change
                    $details = array('firstname' => $THEUSER->firstname(), 'lastname' => $THEUSER->lastname(), 'email' => $THEUSER->email(), 'emailpublic' => $THEUSER->emailpublic(), 'postcode' => $pc, 'constituency' => $constituency, 'url' => $THEUSER->url(), 'optin' => $THEUSER->optin());
                    $success = $THEUSER->update_self($details);
Exemplo n.º 2
0
function display_search_form($alert, $details = array(), $errors = array())
{
    global $this_page, $PAGE;
    $ACTIONURL = new URL($this_page);
    $ACTIONURL->reset();
    $form_start = '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . _htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="email" value="' . _htmlspecialchars(get_http_var('email')) . '">';
    if (isset($details['members']) && $details['members']->rows() > 0) {
        echo '<ul class="hilites">';
        $q = $details['members'];
        for ($n = 0; $n < $q->rows(); $n++) {
            echo '<li>';
            echo $form_start . '<input type="hidden" name="pid" value="' . $q->field($n, 'person_id') . '">';
            echo 'Things by ';
            $name = member_full_name($q->field($n, 'house'), $q->field($n, 'title'), $q->field($n, 'given_name'), $q->field($n, 'family_name'), $q->field($n, 'lordofname'));
            if ($q->field($n, 'constituency')) {
                echo $name . ' (' . $q->field($n, 'constituency') . ') ';
            } else {
                echo $name;
            }
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>\n";
        }
        echo '</ul>';
    }
    if (isset($details['constituencies'])) {
        echo '<ul class="hilites">';
        foreach ($details['constituencies'] as $constituency) {
            $MEMBER = new MEMBER(array('constituency' => $constituency, 'house' => 1));
            echo "<li>";
            echo $form_start . '<input type="hidden" name="pid" value="' . $MEMBER->person_id() . '">';
            if ($details['valid_postcode']) {
                echo '<input type="hidden" name="pc" value="' . _htmlspecialchars($details['alertsearch']) . '">';
            }
            echo $MEMBER->full_name();
            echo ' (' . _htmlspecialchars($constituency) . ')';
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>";
        }
        echo '</ul>';
    }
    if ($details['alertsearch']) {
        echo '<ul class="hilites"><li>';
        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($details['alertsearch']) . '">';
        echo 'Mentions of [';
        $alertsearch = $details['alertsearch'];
        if (preg_match('#speaker:(\\d+)#', $alertsearch, $m)) {
            $MEMBER = new MEMBER(array('person_id' => $m[1]));
            $alertsearch = str_replace("speaker:{$m['1']}", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo _htmlspecialchars($alertsearch) . '] ';
        echo ' <input type="submit" value="Subscribe"></form>';
        # Use original alertsearch variable here, because name replacement might introduce a comma
        if (strstr($details['alertsearch'], ',') > -1) {
            echo '<em class="error">You have used a comma in your search term &ndash; are you sure this is what you want?
You cannot sign up to multiple search terms using a comma &ndash; either use OR, or fill in this form multiple times.</em>';
        }
        if (preg_match('#([A-Z]{1,2}\\d+[A-Z]? ?\\d[A-Z]{2})#i', $alertsearch, $m) && strlen($alertsearch) > strlen($m[1]) && validate_postcode($m[1])) {
            $scottish_text = '';
            $mp_display_text = '';
            if (postcode_is_scottish($m[1])) {
                $mp_display_text = 'your MP, ';
                $scottish_text = ' or MSP';
            }
            echo '<em class="error">You have used a postcode and something else in your search term &ndash; are you sure this is what you want?
                  You will only get an alert if all of these are mentioned in the same debate. Did you mean to get alerts for when your MP' . $scottish_text . ' mentions something instead? If so click subscribe below.</em></li>';
            try {
                $MEMBER = new MEMBER(array('postcode' => $m[1]));
                // move the postcode to the front just to be tidy
                $tidy_alertsearch = $m[1] . " " . trim(str_replace("{$m['1']}", "", $alertsearch));
                $alertsearch_display = str_replace("{$m['1']} ", "", $tidy_alertsearch);
                $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                echo "<li>";
                echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                echo 'Mentions of [';
                echo _htmlspecialchars($alertsearch_display) . '] by ' . $mp_display_text . $MEMBER->full_name();
                echo ' <input type="submit" value="Subscribe"></form>';
                if ($scottish_text) {
                    $constituencies = postcode_to_constituencies($m[1]);
                    if (isset($constituencies['SPC'])) {
                        $MEMBER = new MEMBER(array('constituency' => $constituencies['SPC'], 'house' => 4));
                        // move the postcode to the front just to be tidy
                        $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                        echo "</li><li>";
                        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                        echo 'Mentions of [';
                        echo _htmlspecialchars($alertsearch_display) . '] by your MSP, ' . $MEMBER->full_name();
                        echo ' <input type="submit" value="Subscribe"></form>';
                    }
                }
            } catch (MySociety\TheyWorkForYou\MemberException $e) {
                echo '<p>We had a problem looking up your representative.</p>';
            }
        }
        echo "</li></ul>";
    }
    if ($details['pid']) {
        $MEMBER = new MEMBER(array('person_id' => $details['pid']));
        echo '<ul class="hilites"><li>';
        echo "Signing up for things by " . $MEMBER->full_name();
        echo ' (' . _htmlspecialchars($MEMBER->constituency()) . ')';
        echo "</li></ul>";
    }
    if ($details['keyword']) {
        echo '<ul class="hilites"><li>';
        echo 'Signing up for results from a search for [';
        $alertsearch = $details['keyword'];
        if (preg_match('#speaker:(\\d+)#', $alertsearch, $m)) {
            $MEMBER = new MEMBER(array('person_id' => $m[1]));
            $alertsearch = str_replace("speaker:{$m['1']}", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo _htmlspecialchars($alertsearch) . ']';
        echo "</li></ul>";
    }
    if (!$details['pid'] && !$details['keyword']) {
        ?>

<p><label for="alertsearch">To sign up to an email alert, enter either your
<strong>postcode</strong>, the <strong>name</strong> of who you're interested
in, or the <strong>search term</strong> you wish to receive alerts
for.</label> To be alerted on an exact <strong>phrase</strong>, be sure to put it in quotes.
Also use quotes around a word to avoid stemming (where &lsquo;horse&rsquo; would
also match &lsquo;horses&rsquo;).

<?php 
    }
    echo '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . _htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="submitted" value="1">';
    if (!$details['pid'] && !$details['keyword'] || isset($errors['alertsearch'])) {
        if (isset($errors["alertsearch"])) {
            $PAGE->error_message($errors["alertsearch"]);
        }
        $text = $details['alertsearch'];
        if (!$text) {
            $text = $details['keyword'];
        }
        ?>

<div class="row">
<input type="text" name="alertsearch" id="alertsearch" value="<?php 
        if ($text) {
            echo _htmlentities($text);
        }
        ?>
" maxlength="255" size="30" style="font-size:150%">
</div>

<?php 
    }
    if ($details['pid']) {
        echo '<input type="hidden" name="pid" value="' . _htmlspecialchars($details['pid']) . '">';
    }
    if ($details['keyword']) {
        echo '<input type="hidden" name="keyword" value="' . _htmlspecialchars($details['keyword']) . '">';
    }
    if (!$details['email_verified']) {
        if (isset($errors["email"]) && $details['submitted']) {
            $PAGE->error_message($errors["email"]);
        }
        ?>
        <div class="row">
            <label for="email">Your email address:</label>
            <input type="text" name="email" id="email" value="<?php 
        if (isset($details["email"])) {
            echo _htmlentities($details["email"]);
        }
        ?>
" maxlength="255" size="30" class="form">
        </div>
<?php 
    }
    ?>

    <div class="row">
        <input type="submit" class="submit" value="<?php 
    echo $details['pid'] || $details['keyword'] ? 'Subscribe' : 'Search';
    ?>
">
    </div>

    <div class="row">
<?php 
    if (!$details['email_verified']) {
        ?>
        <p>If you <a href="/user/?pg=join">join</a> or <a href="/user/login/?ret=%2Falert%2F">sign in</a>, you won't need to confirm your email
        address for every alert you set.<br><br>
<?php 
    }
    if (!$details['pid'] && !$details['keyword']) {
        ?>
        <p>Please note that you should only enter <strong>one term per alert</strong> &ndash; if
        you wish to receive alerts on more than one thing, or for more than
        one person, simply fill in this form as many times as you need, or use boolean OR.<br><br></p>
        <p>For example, if you wish to receive alerts whenever the words
        <i>horse</i> or <i>pony</i> are mentioned in Parliament, please fill in
        this form once with the word <i>horse</i> and then again with the word
        <i>pony</i> (or you can put <i>horse OR pony</i> with the OR in capitals
        as explained on the right). Do not put <i>horse, pony</i> as that will only
        sign you up for alerts where <strong>both</strong> horse and pony are mentioned.</p>
<?php 
    }
    ?>
    </div>
<?php 
    if (get_http_var('sign')) {
        echo '<input type="hidden" name="sign" value="' . _htmlspecialchars(get_http_var('sign')) . '">';
    }
    if (get_http_var('site')) {
        echo '<input type="hidden" name="site" value="' . _htmlspecialchars(get_http_var('site')) . '">';
    }
    echo '</form>';
}
Exemplo n.º 3
0
Arquivo: dat.php Projeto: palfrey/twfy
# XXX Lots here copied from elsewhere... Damn you deadlines.
include_once 'min-init.php';
include_once INCLUDESPATH . 'easyparliament/member.php';
include_once '../api/api_functions.php';
$pid = $_GET['pid'];
if (!$pid) {
    print '<error>No ID</error>';
    exit;
}
$member = new MEMBER(array('person_id' => $pid));
if (!$member->valid) {
    print '<error>Unknown ID</error>';
    exit;
}
$member->load_extra_info();
$row = array('person_id' => $pid, 'full_name' => $member->full_name(), 'constituency' => $member->constituency(), 'party' => $member->party_text(), 'majority_in_seat' => number_format($member->extra_info['majority_in_seat']), 'swing_to_lose_seat_today' => number_format($member->extra_info['swing_to_lose_seat_today']));
list($image, $sz) = find_rep_image($pid, true);
if ($image) {
    $row['image'] = $image;
}
foreach ($member->extra_info['office'] as $office) {
    if ($office['to_date'] == '9999-12-31' && $office['source'] == 'chgpages/selctee') {
        $row['selctee'][] = prettify_office($office['position'], $office['dept']);
    }
}
$none = false;
$output = array();
$pw_keys = array_filter(array_keys($member->extra_info), create_function('$a', '
	if (substr($a, 0, 11) != "public_whip") return false;
	if (substr($a, -7) == "_absent") return false;
	return true;
Exemplo n.º 4
0
function display_search_form ( $alert, $details = array(), $errors = array() ) {
    global $this_page, $PAGE;

    $ACTIONURL = new URL($this_page);
    $ACTIONURL->reset();
    $form_start = '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="only" value="1">
<input type="hidden" name="email" value="' . htmlspecialchars(get_http_var('email')) . '">';

    if (isset($details['members']) && $details['members']->rows() > 0) {
        echo '<ul class="hilites">';
        $q = $details['members'];
        $last_pid = null;
        for ($n=0; $n<$q->rows(); $n++) {
            if ($q->field($n, 'person_id') != $last_pid) {
                $last_pid = $q->field($n, 'person_id');
                echo '<li>';
                echo $form_start . '<input type="hidden" name="pid" value="' . $last_pid . '">';
                echo 'Things by ';
                $name = member_full_name($q->field($n, 'house'), $q->field($n, 'title'), $q->field($n, 'first_name'), $q->field($n, 'last_name'), $q->field($n, 'constituency') );
                if ($q->field($n, 'house') != 2) {
                    echo $name . ' (' . $q->field($n, 'constituency') . ') ';
                } else {
                    echo $name;
                }
                echo ' <input type="submit" value="Subscribe"></form>';
                echo "</li>\n";
            }
        }
        echo '</ul>';
    }

    if (isset($details['constituencies'])) {
        echo '<ul class="hilites">';
        foreach ($details['constituencies'] as $constituency) {
            $MEMBER = new MEMBER(array('constituency'=>$constituency, 'house' => 1));
            echo "<li>";
            echo $form_start . '<input type="hidden" name="pid" value="' . $MEMBER->person_id() . '">';
            if ($details['valid_postcode'])
                echo '<input type="hidden" name="pc" value="' . htmlspecialchars($details['alertsearch']) . '">';
            echo $MEMBER->full_name();
            echo ' (' . htmlspecialchars($constituency) . ')';
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>";
        }
        echo '</ul>';
    }

    if ($details['alertsearch']) {
        echo '<ul class="hilites"><li>';
        echo $form_start . '<input type="hidden" name="keyword" value="' . htmlspecialchars($details['alertsearch']) . '">';
        echo 'Mentions of [';
		$alertsearch = $details['alertsearch'];
        if (preg_match('#speaker:(\d+)#', $alertsearch, $m)) {
			$MEMBER = new MEMBER(array('person_id'=>$m[1]));
		    $alertsearch = str_replace("speaker:$m[1]", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo htmlspecialchars($alertsearch) . '] ';
        echo ' <input type="submit" value="Subscribe"></form>';
        echo "</li></ul>";
    }

    if ($details['pid']) {
        $MEMBER = new MEMBER(array('person_id'=>$details['pid']));
        echo '<ul class="hilites"><li>';
        echo "Signing up for things by " . $MEMBER->full_name();
        echo ' (' . htmlspecialchars($MEMBER->constituency()) . ')';
        echo "</li></ul>";
    }

    if ($details['keyword']) {
        echo '<ul class="hilites"><li>';
        echo 'Signing up for results from a search for [';
		$alertsearch = $details['keyword'];
        if (preg_match('#speaker:(\d+)#', $alertsearch, $m)) {
			$MEMBER = new MEMBER(array('person_id'=>$m[1]));
		    $alertsearch = str_replace("speaker:$m[1]", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo htmlspecialchars($alertsearch) . ']';
        echo "</li></ul>";
    }

    if (!$details['add']) {
?>

<p><label for="alertsearch">To sign up to an email alert, enter either your
<strong>postcode</strong>, the <strong>name</strong> of who you're interested
in, or the <strong>search word</strong> or <strong>words</strong> you wish to receive alerts
for.</label> To be alerted on an exact <strong>phrase</strong>, be sure to put it in quotes.
Also use quotes around a word to avoid stemming (where &lsquo;horse&rsquo; will
also match &lsquo;horses&rsquo;),

<?
    }

    echo '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="submitted" value="1">';

    if (!$details['add']) {
        if (isset($errors["alertsearch"])) {
            $PAGE->error_message($errors["alertsearch"]);
        }
?>

<div class="row">
<input type="text" name="alertsearch" id="alertsearch" value="<?php if ($details['alertsearch']) { echo htmlentities($details['alertsearch']); } ?>" size="30" style="font-size:150%">
</div>

<?php
    }

    if ($details['pid'])
        echo '<input type="hidden" name="pid" value="' . htmlspecialchars($details['pid']) . '">';
    if ($details['keyword'])
        echo '<input type="hidden" name="keyword" value="' . htmlspecialchars($details['keyword']) . '">';
    if ($details['pid'] || $details['keyword'])
        echo '<input type="hidden" name="only" value="1">';

    if (!$details['email_verified']) {
        if (isset($errors["email"]) && (get_http_var('submitted') || $details['add'])) {
            $PAGE->error_message($errors["email"]);
        }
?>
        <div class="row">
            <label for="email">Your email address:</label>
            <input type="text" name="email" id="email" value="<?php if (isset($details["email"])) { echo htmlentities($details["email"]); } ?>" maxlength="255" size="30" class="form">
        </div>
<?php
    }
?>

    <div class="row">   
        <input type="submit" class="submit" value="Search">
    </div>

    <div class="row">
<?php
    if (!$details['email_verified']) {
?>
        <p>If you join or sign in, you won't need to confirm your email
        address for every alert you set.
<?php
    }
    if (!$details['add']) {
?>
        <p>Please note that you should only enter one topic per alert - if
        you wish to receive alerts on more than one topic, or for more than
        one person, simply fill in this form as many times as you need.</p>
<?php
    }
?>
    </div>
<?php
    if (get_http_var('sign'))
        echo '<input type="hidden" name="sign" value="' . htmlspecialchars(get_http_var('sign')) . '">';
    if (get_http_var('site'))
        echo '<input type="hidden" name="site" value="' . htmlspecialchars(get_http_var('site')) . '">';
    echo '</form>';
}