#!/usr/bin/perl -w # index.pl: # Main code for BCI - not really. # # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # # $Id: index.cgi,v 1.17 2006-09-22 14:30:16 matthew Exp $ use strict; require 5.8.0; # Horrible boilerplate to set up appropriate library paths. use FindBin; use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../../perllib"; use Error qw(:try); use LWP::Simple; use RABX; use Page; use mySociety::Config; BEGIN { mySociety::Config::set_file("$FindBin::Bin/../conf/general"); } use mySociety::MaPit; mySociety::MaPit::configure(); use mySociety::Web qw(ent NewURL); # Main code for index.cgi sub main { my $q = shift; my $out = ''; if ($q->param('submit_problem')) { $out = submit_problem($q); } elsif ($q->param('submit_comment')) { $out = submit_comment($q); } elsif ($q->param('map')) { $out = display_form($q); } elsif ($q->param('pc')) { $out = display($q); } elsif ($q->param('id')) { $out = display_problem($q); } else { $out = front_page(); } print Page::header($q, ''); print $out; print Page::footer($q); } Page::do_fastcgi(\&main); # Display front page sub front_page { my $error = shift; my $out = ''; $out .= '
' . $error . '
' if ($error); $out .= <This is currently only for Newham and Lewisham Councils
It’s very simple:
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 comment will not be posted.
(Don't worry - we'll hang on to your comment while you're checking your email.)
EOF return $out; } sub submit_problem { my $q = shift; my @vars = qw(title detail name email pc easting northing updates); my %input = map { $_ => $q->param($_) } @vars; my @errors; push(@errors, 'Please enter a title') unless $input{title}; push(@errors, 'Please enter some details') unless $input{detail}; push(@errors, 'Please enter your name') unless $input{name}; push(@errors, 'Please enter your email') unless $input{email}; return display_form($q, @errors) if (@errors); # Send confirmation email my $out = <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 problem will not be posted on the site.
(Don't worry - we'll hang on to your message while you're checking your email.)
EOF return $out; } sub display_form { my ($q, @errors) = @_; my ($pin_x, $pin_y, $pin_tile_x, $pin_tile_y); my @vars = qw(title detail name email updates pc easting northing x y skipped); my %input = map { $_ => $q->param($_) || '' } @vars; my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; my @ps = $q->param; foreach (@ps) { ($pin_tile_x, $pin_tile_y, $pin_x) = ($1, $2, $q->param($_)) if /^tile_(\d+)\.(\d+)\.x$/; $pin_y = $q->param($_) if /\.y$/; } return display($q) unless $input{skipped} || ($pin_x && $pin_y) || ($input{easting} && $input{northing}); my $out = ''; $out .= 'Please fill in the form below with details of the problem:
'; } else { my ($px, $py, $easting, $northing); if ($pin_x && $pin_y) { $pin_x -= 254 while $pin_x > 254; $pin_y -= 254 while $pin_y > 254; $pin_y = 254 - $pin_y; $px = 508 - ($pin_tile_x - $input{x})*254 - $pin_x; $py = 508 - ($pin_tile_y - $input{y})*254 - $pin_y; $easting = 5000/31 * ($pin_tile_x + $pin_x/254); $northing = 5000/31 * ($pin_tile_y + $pin_y/254); } else { $px = 508 - ($input{easting} / (5000/31) - $input{x})*254; $py = 508 - ($input{northing} / (5000/31) - $input{y})*254; $easting = $input_h{easting}; $northing = $input_h{northing}; } $out .= display_map($q, $input{x}, $input{y}, 1, 0); $out .= 'You have located the problem at the location marked with a yellow pin on the map. If this is not the correct location, simply click on the map again.
Please fill in details of the problem below:
'; $out .= display_pin($px, $py, 'yellow'); $out .= ' '; } if (@errors) { $out .= 'Or just view existing problems that have already been reported.
EOF $out .= <'; $out .= display_pin($px, $py); $out .= 'Reported by ' . $name . ' at ' . $time; $out .= '
'; $out .= ent($desc); $out .= '
'; # Display comments my $comments = ''; if ($comments) { $out .= '