#!/usr/bin/perl # # Page.pm: # Various HTML stuff for the BCI site. # # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # # $Id: Page.pm,v 1.37 2007-03-21 11:58:13 matthew Exp $ # package Page; use strict; use Carp; use CGI::Fast qw(-no_xhtml); use Error qw(:try); use File::Slurp; use mySociety::Config; use mySociety::Email; use mySociety::Util; use mySociety::WatchUpdate; use mySociety::Web qw(ent NewURL); BEGIN { mySociety::Config::set_file("$FindBin::Bin/../conf/general"); } sub do_fastcgi { my $func = shift; try { my $W = new mySociety::WatchUpdate(); while (my $q = new CGI::Fast()) { &$func($q); $W->exit_if_changed(); } } catch Error::Simple with { my $E = shift; my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text()); warn "caught fatal exception: $msg"; warn "aborting"; ent($msg); print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n", q(Sorry! Something's gone wrong.), q(), q(

Sorry! Something's gone wrong.

), q(

Please try again later, or email us to let us know.

), q(
), q(

The text of the error was:

), qq(
$msg
), q( 1 } qw(); foreach (keys %params) { croak "bad parameter '$_'" if (!exists($permitted_params{$_})); } print $q->header(-charset=>'utf-8'); my $html = < EOF # Causes onLoad never to fire in IE... # $html .= < ${title}Neighbourhood Fix-It EOF my $home = !$title && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING}; $html .= $home ? '

' : '

' : ''; $html .= '
'; if (mySociety::Config::get('STAGING_SITE')) { $html .= '

This is a developer site; things might break at any time, and councils are not sent emails (they\'d get annoyed!).

'; } return $html; } =item footer =cut sub footer { return <

Navigation

EOF } =item error_page Q MESSAGE =cut sub error_page ($$) { my ($q, $message); my $html = header($q, "Error") . $q->p($message) . footer(); print $q->header(-content_length => length($html)), $html; } sub compass ($$$) { my ($q, $x, $y) = @_; my @compass; for (my $i=$x-1; $i<=$x+1; $i++) { for (my $j=$y-1; $j<=$y+1; $j++) { $compass[$i][$j] = NewURL($q, x=>$i, y=>$j); } } return < NW N NE W E SW S SE EOF } # send_email TO (NAME) TEMPLATE-NAME PARAMETERS sub send_email { my ($email, $name, $thing, %h) = @_; my $template = "$thing-confirm"; $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/$template"); my $to = $name ? [[$email, $name]] : $email; my $message = mySociety::Email::construct_email({ _template_ => $template, _parameters_ => \%h, From => [mySociety::Config::get('CONTACT_EMAIL'), 'Neighbourhood Fix-It'], To => $to, }); my $result = mySociety::Util::send_email($message, mySociety::Config::get('CONTACT_EMAIL'), $email); my $out; my $action = ($thing eq 'alert') ? 'confirmed' : 'posted'; if ($result == mySociety::Util::EMAIL_SUCCESS) { $out = <Nearly Done! Now check your email...

The confirmation email may take a few minutes to arrive — please be patient.

If you use web-based email or have 'junk mail' filters, you may wish to check your bulk/spam mail folders: sometimes, our messages are marked that way.

You must now click on the link within the email we've just sent you — if you do not, your $thing will not be $action.

(Don't worry — we'll hang on to your $thing while you're checking your email.)

EOF } else { $out = <I'm afraid something went wrong when we tried to send you a confirmation email for your $thing. Please click Back, check your details, and try again.

EOF } return $out; } 1;