Esempio n. 1
0
function find_constituency($args)
{
    // We see if the user is searching for a postcode or constituency.
    global $PAGE;
    if ($args['s'] != '') {
        $searchterm = $args['s'];
    } else {
        $PAGE->error_message('No search string');
        return false;
    }
    list($constituencies, $validpostcode) = search_constituencies_by_query($searchterm);
    $constituency = "";
    if (count($constituencies) == 1) {
        $constituency = $constituencies[0];
    }
    if ($constituency != '') {
        // Got a match, display....
        $MEMBER = new MEMBER(array('constituency' => $constituency, 'house' => 1));
        $URL = new URL('mp');
        if ($MEMBER->valid) {
            $URL->insert(array('p' => $MEMBER->person_id()));
            print '<h2>';
            if (!$MEMBER->current_member(1)) {
                print 'Former ';
            }
            print 'MP for ' . preg_replace('#' . preg_quote($searchterm, '#') . '#i', '<span class="hi">$0</span>', $constituency);
            if ($validpostcode) {
                // Display the postcode the user searched for.
                print ' (' . _htmlentities(strtoupper($args['s'])) . ')';
            }
            ?>
</h2>

            <p><a href="<?php 
            echo $URL->generate();
            ?>
"><strong><?php 
            echo $MEMBER->full_name();
            ?>
</strong></a> (<?php 
            echo $MEMBER->party_text();
            ?>
)</p>
    <?php 
        }
    } elseif (count($constituencies)) {
        $out = '';
        $heading = array();
        foreach ($constituencies as $constituency) {
            $MEMBER = new MEMBER(array('constituency' => $constituency, 'house' => 1));
            if ($MEMBER->valid) {
                if ($MEMBER->current_member(1)) {
                    $heading[] = 'MPs';
                } else {
                    $heading[] = 'Former MPs';
                }
                $URL = new URL('mp');
                $URL->insert(array('p' => $MEMBER->person_id()));
                $out .= '<li><a href="' . $URL->generate() . '"><strong>' . $MEMBER->full_name() . '</strong></a> (' . preg_replace('#' . preg_quote($searchterm, '#') . '#i', '<span class="hi">$0</span>', $constituency) . ', ' . $MEMBER->party() . ')</li>';
            }
        }
        print '<h2>';
        print join(" and ", array_unique($heading));
        print " in constituencies matching &lsquo;" . _htmlentities($searchterm) . "&rsquo;</h2>";
        print "<ul>{$out}</ul>";
    }
}