예제 #1
0
function show_check_email($error_msg) {
     
    /* Show them the "check your email and click the link" template. */
     global $fyr_representative, $fyr_voting_area; 
     global $fyr_values, $fyr_date, $fyr_group_msg, $cobrand;
     $our_values = array_merge($fyr_values, array('representative' => $fyr_representative,
            'voting_area' => $fyr_voting_area, 'date' => $fyr_date, 'group_msg' => $fyr_group_msg,
            'error_msg' => $error_msg, 'cobrand' => $cobrand, 'host' => fyr_get_host()));
     template_draw("write-checkemail", $our_values); 
}
예제 #2
0
파일: lords.php 프로젝트: vijo/writetothem
            print '<li><a href="' . $url . '">' . $reps_info[$id]['name'] . '</a> <small>' . $reason[$i] . '</small></li>' . "\n";
        }
        print '</ul>';
    }
} else {
    lords_form();
}
?>

		</div>
	</div>

</div>

<?php 
template_draw('footer', $values);
# ---
function lords_form($error = array())
{
    global $form_extra;
    ?>

	<p>WriteToThem <em>Lords edition</em> is an experiment. Lords do not have a duty to
		reply to the public, and they are (obviously) not elected.
		Nevertheless, they get to vote on things that affect all of us, so we
		reckon they should at least be easy to contact.  It is best only to contact a
		Lord about an issue they can help with or influence, which includes national
		legislation and other issues Parliament deals with.
		For more information, read our <a href="about-lords"><strong>Frequently Asked Questions</strong></a>.</p>
	
	<p>Lords do not have constituencies like MPs, so we need
예제 #3
0
파일: stats.php 프로젝트: vijo/writetothem
function mp_response_table($year, $xml, $rep_info, $questionnaire_report, $type_summary, $last_year_report)
{
    $last_year_data = array();
    foreach ($last_year_report as $key => $row) {
        if (is_array($row)) {
            $last_year_data[] = array('name' => $row['name'], 'person_id' => $row['person_id'], 'category' => $row['category'], 'response' => $row['responded_mean'], 'low' => $row['responded_95_low'], 'high' => $row['responded_95_high']);
        }
    }
    usort($last_year_data, 'by_response');
    $position = 0;
    $same_stat = 1;
    $last_response = -1;
    $last_low = -1;
    $fymp_ranked = array();
    $fymp_response = array();
    $fymp_category = array();
    foreach ($last_year_data as $key => $row) {
        if ($row['response'] != $last_response || $row['low'] != $last_low) {
            $position += $same_stat;
            $same_stat = 1;
            $last_response = $row['response'];
            $last_low = $row['low'];
        } else {
            $same_stat++;
        }
        $fymp_ranked[$row['person_id']] = $position;
        $fymp_response[$row['person_id']] = $row['response'];
        $fymp_category[$row['person_id']] = $row['category'];
    }
    # Read in data
    $data = array();
    foreach ($questionnaire_report as $key => $row) {
        if (is_array($row)) {
            $data['data'][] = array('person_id' => $key, 'name' => $row['name'], 'party' => $row['party'], 'area' => $row['area'], 'sent' => $row['dispatched_success'], 'category' => $row['category'], 'notes' => category_lookup($row['category']), 'response' => $row['responded_mean'], 'low' => $row['responded_95_low'], 'high' => $row['responded_95_high'], 'responded' => $row['responded'], 'responded_outof' => $row['responded_outof'], 'fymp_rank' => array_key_exists($key, $fymp_ranked) ? $fymp_ranked[$key] : null, 'fymp_response' => array_key_exists($key, $fymp_response) ? $fymp_response[$key] : null, 'fymp_notes' => array_key_exists($key, $fymp_category) ? category_lookup($fymp_category[$key]) : '');
        } else {
            $data['info'][$key] = $row;
        }
    }
    $non_mp_sent = 0;
    foreach ($type_summary as $type => $row) {
        if ($type != 'westminster' && $type != 'total') {
            $non_mp_sent += $row['dispatched_success'];
        }
    }
    $data['info']['non_mp_sent'] = $non_mp_sent;
    # Sort data
    function by_area($a, $b)
    {
        return strcmp($a['area'], $b['area']);
    }
    function by_sent($a, $b)
    {
        if ($a['sent'] < $b['sent']) {
            return 1;
        } elseif ($a['sent'] > $b['sent']) {
            return -1;
        }
        return 0;
    }
    $sort = get_http_var('o');
    if ($sort == 'n') {
        usort($data['data'], 'by_name');
    } elseif ($sort == 'c') {
        usort($data['data'], 'by_area');
    } elseif ($sort == 's') {
        usort($data['data'], 'by_sent');
    } else {
        $sort = 'r';
        usort($data['data'], 'by_response');
    }
    $data['info']['sort'] = $sort;
    $data['info']['mp'] = null;
    if (count($rep_info)) {
        $key = $rep_info['parlparse_person_id'];
        $row = $questionnaire_report[$key];
        $data['info']['mp'] = array_merge($row, array('pc' => $rep_info['postcode'], 'notes' => category_lookup($row['category']), 'response' => $row['responded_mean'], 'low' => $row['responded_95_low'], 'high' => $row['responded_95_high'], 'fymp_rank' => array_key_exists($key, $fymp_ranked) ? $fymp_ranked[$key] : null, 'fymp_response' => array_key_exists($key, $fymp_response) ? $fymp_response[$key] : null, 'fymp_notes' => array_key_exists($key, $fymp_category) ? category_lookup($fymp_category[$key]) : ''));
    }
    # Output data
    global $year_bar;
    template_draw($xml ? 'stats-mp-twfy' : 'stats-mp-performance', array("title" => "WriteToThem.com Zeitgeist {$year}", 'year' => $year, 'year_bar' => $year_bar, 'data' => $data));
}
예제 #4
0
        $heading = "<strike>$heading</strike>";
    }
    array_push($fyr_rep_descs, $col_blurb);
    array_push($fyr_rep_lists, $text);
    array_push($fyr_representatives, "$col_blurb$text$col_after");
    array_push($fyr_headings, "<h3>$heading</h3>");
    debug_timestamp();
}

// Display page, using all the fyr_* variables set above.
template_draw("who", array(
    "reps" => $fyr_representatives,
    "template" => "who", 
    "headings" => $fyr_headings,
    "error" => $fyr_error,
    "county_note" => $fyr_county_note,
    "all_url" => $fyr_all_url,
    "cobrand" => $cobrand, 
    "host" => fyr_get_host(), 
    "rep_lists" => $fyr_rep_lists, 
    "rep_descs" => $fyr_rep_descs
    ));

debug_timestamp();

function write_all_link($va_type, $rep_desc_plural) {
    global $cobrand, $cocode;
    global $fyr_postcode;
    if ($rep_desc_plural == 'London Assembly Members')
        $rep_desc_plural = 'London Assembly list members';
    if ($rep_desc_plural == 'MSPs')
        $rep_desc_plural = 'regional MSPs';
예제 #5
0
파일: index.php 프로젝트: vijo/writetothem
if ($a_forward) {
    # Subset of representatives
    $area_types = fyr_parse_area_type_list($a_forward);
    if ($area_types) {
        $area_type_desc = fyr_describe_area_type_list($area_types);
        if (!$forced_rep_type) {
            $fyr_all_url = htmlspecialchars(url_new('', false, 'pc', get_http_var('pc'), 'fyr_extref', fyr_external_referrer(), 'cocode', get_http_var('cocode')));
        }
        $blurb_top = "<h2>Write to your {$area_type_desc}</h2><p>Over 200,000 messages sent last year.</p>";
    }
}
if ($template != 'index-advice') {
    header('Cache-Control: max-age=3600');
}
$options = cobrand_postcode_form_options($cobrand);
$form = postcode_form($pc, $cobrand, $cocode, $a_forward, $error_message, $options);
$num_messages = null;
if ($cobrand && file_exists("../../data/cobrand.csv")) {
    if (($handle = fopen("../../data/cobrand.csv", "r")) !== false) {
        while (($row = fgetcsv($handle)) !== false) {
            if ($row[0] === $cobrand) {
                $num_messages = $row[1];
                break;
            }
        }
        fclose($handle);
    }
}
// Display page
template_draw($template, array('body_id' => 'home', "title" => $title, "blurb-top" => $blurb_top, "form" => $form, "error" => $error_message, "all_url" => $fyr_all_url, "cobrand" => $cobrand, "num_messages" => $num_messages, "template" => $template, "host" => fyr_get_host()));
예제 #6
0
파일: about.php 프로젝트: vijo/writetothem
if ($page == 'about-pledgebank') {
    header("Location: http://www.pledgebank.com");
    exit;
}
$t = 'about-qa-';
if (substr($page, 0, strlen($t)) == $t) {
    $page = substr_replace($page, 'qa/', 0, strlen($t));
}
$t = 'about-yourrep-';
if (substr($page, 0, strlen($t)) == $t) {
    $page = substr_replace($page, 'yourrep/', 0, strlen($t));
}
$values = array('cobrand' => $cobrand);
if ($page == 'write-checkemail') {
    /* Fill in some other values as required. */
    $values['voting_area'] = array('rep_name' => 'MP');
}
if ($page == 'confirm-accept') {
    $values['recipient_via'] = '';
}
if ($page == 'write-checkemail') {
    $values['group_msg'] = '';
}
/* Don't want problem pages to be indexed, really. */
if (preg_match('/^problem-/', $page)) {
    $values['robots'] = 'noindex, nofollow';
}
template_draw($page, $values);
?>

예제 #7
0
    }
    foreach ($area_reps as $rep) {
        $oldname = $reps_info[$rep]['name'];
        $oldparty = $reps_info[$rep]['party'];
        $newname = $fyr_names[$rep];
        $newparty = $fyr_parties[$rep];
        if ($oldname != $newname || $oldparty != $newparty) {
            $ret = dadem_store_user_correction($fyr_vatype, $rep, 'modify', $newname, $newparty, $fyr_notes, $fyr_email);
            dadem_check_error($ret);
        }
    }
    if (isset($fyr_new['name']) && $fyr_new['name'] || $fyr_new['party'] && isset($fyr_new['party'])) {
        $ret = dadem_store_user_correction($fyr_vatype, null, 'add', $fyr_new['name'], $fyr_new['party'], $fyr_notes, $fyr_email);
        dadem_check_error($ret);
    }
    foreach ($fyr_delete as $rep_id => $dummy) {
        if (!in_array($rep_id, $area_reps)) {
            template_show_error('Trying to delete a rep not in this area?');
            exit;
        }
        if (sizeof($area_reps) == 1) {
            template_show_error('Trying to delete the only representative?');
            exit;
        }
        $ret = dadem_store_user_correction($fyr_vatype, $rep_id, 'delete', '', '', $fyr_notes, $fyr_email);
        dadem_check_error($ret);
    }
    $template_page = 'corrections-thanks';
}
template_draw($template_page, array('id' => $fyr_vatype, 'va_info' => $va_info, 'reps_info' => $reps_info, 'parent_info' => $parent_info));
예제 #8
0
                if ($rep_specificid == $fyr_who)
                    $form->addElement('static', '', null, $rep_info['name'] . ' is you!', $rep_specificid);
                else
                    $form->addElement('radio', 'who', null, "&nbsp;<b>" .  $rep_info['name'] . '</b><br>'
                        . $rep_info['party'], $rep_specificid);
            }

            $form->addElement('hidden', 'action', 'doforward');
            $form->addElement('hidden', 'id', $id);
            $form->addElement('submit', 'next', 'Forward Message >>');
            $fyr_form_renderer = new HTML_QuickForm_Renderer_mySociety();
            $form->accept($fyr_form_renderer);
            $right_column .= $fyr_form_renderer->toHtml();

            array_push($fyr_representatives, array($left_column, $right_column));

            debug_timestamp();
        }

        // Display page, using all the fyr_* variables set above.
        template_draw("reps-forward", array("representative" => $representative, 
            "voting_area" => $voting_area, 
            "constituent" => $constituent, 
            "message" => $message, 
            "forwardreps" => $fyr_representatives));
    }
}

?>

예제 #9
0
파일: who.php 프로젝트: edent/writetothem
// A/B Testing Hack!
if (isset($_GET['t'])) {
    $template = $_GET['t'];
} else {
    $template = 'who';
}
// Inject extra content for Lords
// A/B Testing Hack!
if ($template == 'who' && !$area_types) {
    array_push($fyr_headings, 'House of Lords');
    array_push($fyr_blurbs, '<p>Lords are not elected by you, but they still get to vote in Parliament just like your MP. You may want to write to a Lord (<a href="about-lords">more info</a>).</p>');
    array_push($fyr_representatives, '<ul class="rep-list lords"><li><a href="/lords">Write to a Lord</a></li></ul>');
    array_push($fyr_more, '');
}
// Display page, using all the fyr_* variables set above.
template_draw($template, array("reps" => $fyr_representatives, "template" => "who", "headings" => $fyr_headings, "blurbs" => $fyr_blurbs, "more" => $fyr_more, "all_url" => $fyr_all_url, "cobrand" => $cobrand, "host" => fyr_get_host(), "rep_lists" => $fyr_rep_lists, "rep_descs" => $fyr_rep_descs));
debug_timestamp();
# ---
function get_postcode()
{
    $postcode = canonicalise_postcode(get_http_var('pc'));
    if (!$postcode) {
        header('Location: /');
        exit;
    }
    debug("FRONTEND", "postcode is {$postcode}");
    fyr_rate_limit(array('postcode' => array($postcode, "Postcode that's been typed in ")));
    return $postcode;
}
function get_area_types()
{
예제 #10
0
if (rabx_is_error($result)) {
    if ($result->code == FYR_QUEUE_MESSAGE_EXPIRED) {
        $url = cobrand_url($cobrand, "/", $cocode);
        $text = <<<EOF
You took so long to confirm your message that under our privacy policy 
your message has already been removed from our database. 
If you’d still like to write a message, you can <a href="{$url}">try again from the
beginning
EOF;
        template_show_error($text);
    } else {
        template_show_error($result->text);
    }
}
if (!$result) {
    template_draw("confirm-trouble", $template_params);
} else {
    $values = msg_admin_get_message($result);
    if (rabx_is_error($values)) {
        template_show_error($values->text);
    } elseif ($values['cobrand'] && cobrand_post_letter_send($values)) {
        // Do nothing - cobrand_post_letter_send must do the special action e.g. header or template_draw etc.
    } else {
        $values['cobrand'] = $cobrand;
        $values['host'] = fyr_get_host();
        template_draw("confirm-accept", $values);
    }
}
?>

예제 #11
0
    template_show_error($missing_answer_message);
}
$yes_url = cobrand_url($cobrand, "/firsttime?token=" . urlencode($token) . "&amp;answer=yes", $cocode);
$no_url = cobrand_url($cobrand, "/firsttime?token=" . urlencode($token) . "&amp;answer=no", $cocode);
$values = array('first_time_yes' => "\"{$yes_url}\"", 'first_time_no' => "\"{$no_url}\"", 'cobrand' => $cobrand, 'cocode' => $cocode, 'host' => fyr_get_host());
// Look up info about the message
$msg_id = msg_get_questionnaire_message($token);
msg_check_error($msg_id);
if (!$msg_id) {
    $unfound_token_message = cobrand_unfound_token_message($cobrand);
    if (!$unfound_token_message) {
        $unfound_token_message = "Failed to look up message id for token";
    }
    template_show_error($unfound_token_message);
}
$msg_info = msg_admin_get_message($msg_id);
msg_check_error($msg_info);
$values = array_merge($msg_info, $values);
// 0 is the responsiveness question
$result = msg_record_questionnaire_answer($token, 0, $answer);
msg_check_error($result);
if ($answer == "yes") {
    template_draw("response-yes", $values);
} elseif ($answer == "no") {
    template_draw("response-no", $values);
} else {
    template_show_error("Unknown answer.");
}
?>

예제 #12
0
function mp_response_table($questionnaire_report) {
    # Read in data
    $data = array();
    foreach ($questionnaire_report as $key => $row) {
        if (is_array($row)) {
            $data['data'][] = array(
                'person_id' => $key,
                'name' => $row['name'],
                'party' => $row['party'],
                'area' => $row['area'],
                'sent' => $row['dispatched_success'],
                'category' => $row['category'],
                'notes' => category_lookup($row['category']),
                'response' => round($row['responded_mean'] * 100, 1),
                'low' => round($row['responded_95_low'] * 100, 1),
                'high' => round($row['responded_95_high'] * 100, 1)
            );
        } else {
            $data['info'][$key] = $row;
        }
    }

    # Sort data
    function by_name($a, $b) {
        return strcmp($a['name'], $b['name']);
    }
    function by_area($a, $b) {
        return strcmp($a['area'], $b['area']);
    }
    function by_sent($a, $b) {
        if ($a['sent']<$b['sent']) return 1;
        elseif ($a['sent']>$b['sent']) return -1;
        return 0;
    }
    $sort = get_http_var('o');
    if ($sort == 'n') {
        usort($data['data'], 'by_name');
    } elseif ($sort == 'c') {
        usort($data['data'], 'by_area');
    } elseif ($sort == 's') {
        usort($data['data'], 'by_sent');
    } else {
        function by_response($a, $b) {
            if ($a['category'] != 'good' && $b['category'] == 'good')
                return 1;
            if ($b['category'] != 'good' && $a['category'] == 'good')
                return -1;
            if ($a['category'] != 'good' && $b['category'] != 'good')
                return by_name($a, $b);
            if ($a['response']<$b['response']) return 1;
            elseif ($a['response']>$b['response']) return -1;
            if ($a['low']<$b['low']) return 1;
            elseif ($a['low']>$b['low']) return -1;
            return 0;
        }
        usort($data['data'], 'by_response');
    }
    $data['info']['sort'] = $sort;

    # Output data
    template_draw('stats-fymp', array(
        "title" => "FYMP stats",
        'data' => $data
        ));
}
예제 #13
0
파일: template.php 프로젝트: palfrey/phplib
function template_show_error($message)
{
    global $template_style_dir;
    if (!isset($template_style_dir) || !file_exists(end($template_style_dir) . '/error-general.html')) {
        print $message;
    } else {
        /* Not safe. */
        template_draw("error-general", array("error_message" => $message));
    }
    exit(1);
}
예제 #14
0
require_once "../commonlib/phplib/utility.php";
require_once "../commonlib/phplib/survey.php";
fyr_rate_limit(array());
$token = get_http_var('token');
if (!$token) {
    template_show_error("The token was missing.");
}
$answer = get_http_var('answer');
if ($answer != "yes" && $answer != "no") {
    template_show_error("The answer type was missing.");
}
// 1 is the firsttime question
$result = msg_record_questionnaire_answer($token, 1, $answer);
if (rabx_is_error($result)) {
    template_show_error($result->text);
}
$values = msg_admin_get_message($result);
$values['cobrand'] = $cobrand;
// Demographic survey
list($values['user_code'], $values['auth_signature']) = survey_sign_email_address($values['sender_email']);
$done_survey = survey_check_if_already_done($values['user_code'], $values['auth_signature']);
//$rand = rand(0, 4); // high rate when want lots of data
$rand = rand(0, 29);
// low rate when not actively doing research, so still get 50-100 responses a month
if (!$done_survey && $rand == 0 && cobrand_display_survey($cobrand)) {
    $values['return_url'] = OPTION_BASE_URL . htmlspecialchars($_SERVER['REQUEST_URI']);
    template_draw("survey-questions", $values);
} else {
    // Either the questionnaire or the survey done
    template_draw("survey-done", $values);
}
예제 #15
0
    foreach ($out['recent_election'] as $date => $data) {
        if (!preg_match('#\\d\\d\\d\\d-\\d\\d-\\d\\d#', $date)) {
            continue;
        }
        print '<strong>' . $date . '</strong> (' . count($data) . ') <ul><li>';
        if (is_array($data)) {
            print join("\n<li>", $data);
        } else {
            print "<li>{$data}";
        }
        print '</ul>';
        unset($out['recent_election'][$date]);
    }
    if (count($out['recent_election'])) {
        ?>
<p>Here is a list of the <?php 
        echo count($out['recent_election']);
        ?>
 areas for which we are still awaiting election results:</p>
<ul><li><?php 
        echo join("\n<li>", $out['recent_election']);
        echo '</ul>';
    } else {
        echo '<p>We are not awaiting any results.</p>';
    }
    echo '</div>';
}
template_draw('footer', array());
?>

예제 #16
0
function template_show_error($message)
{
    global $template_style_dir;
    $host = '';
    if (isset($_SERVER) && array_key_exists('HTTP_HOST', $_SERVER)) {
        $host = $_SERVER['HTTP_HOST'];
    }
    if (!isset($template_style_dir) || !file_exists(end($template_style_dir) . '/error-general.html')) {
        print $message;
    } else {
        /* Not safe. */
        template_draw("error-general", array("error_message" => $message, 'host' => $host));
    }
    exit(1);
}