#!/usr/bin/perl -w -I../perllib # index.cgi: # Main code for FixMyStreet # # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # # $Id: index.cgi,v 1.201 2008-05-29 11:06:26 matthew Exp $ use strict; use Standard; use Error qw(:try); use File::Slurp; use LWP::Simple; use RABX; use CGI::Carp; use URI::Escape; use mySociety::AuthToken; use mySociety::Config; use mySociety::DBHandle qw(select_all); use mySociety::EmailUtil; use mySociety::Gaze; use mySociety::GeoUtil; use mySociety::MaPit; use mySociety::PostcodeUtil; use mySociety::Random; use mySociety::VotingArea; use mySociety::Web qw(ent NewURL); BEGIN { if (!dbh()->selectrow_array('select secret from secret for update of secret')) { local dbh()->{HandleError}; dbh()->do('insert into secret (secret) values (?)', {}, unpack('h*', mySociety::Random::random_bytes(32))); } dbh()->commit(); } # Main code for index.cgi sub main { my $q = shift; my $out = ''; my %params; if ($q->param('submit_problem') || ($q->param('submit_map') && $q->param('submit_map')==2)) { $params{title} = _('Submitting your report'); ($out) = submit_problem($q); } elsif ($q->param('submit_update')) { $params{title} = _('Submitting your update'); ($out) = submit_update($q); } elsif ($q->param('submit_map')) { ($out, %params) = display_form($q); $params{title} = _('Reporting a problem'); } elsif ($q->param('id')) { ($out, %params) = display_problem($q); $params{title} .= ' - ' . _('Viewing a problem'); } elsif ($q->param('pc') || ($q->param('x') && $q->param('y'))) { ($out, %params) = display_location($q); $params{title} = _('Viewing a location'); } else { $out = front_page($q); } print Page::header($q, %params); print $out; my %footerparams; $footerparams{js} = $params{js} if $params{js}; print Page::footer($q, %footerparams); } Page::do_fastcgi(\&main); # Display front page sub front_page { my ($q, $error) = @_; my $pc_h = ent($q->param('pc') || ''); my $out = '
' . _('Report, view, or discuss local problems') . '';
my $subhead = _('(like graffiti, fly tipping, broken paving slabs, or street lighting)');
$subhead = '(like graffiti, fly tipping, or neighbourhood noise)' if $q->{site} eq 'scambs';
$out .= '
' . $subhead . '' if $subhead ne ' ';
$out .= '
' . $error . '
' if ($error); my $fixed = Problems::recent_fixed(); my $updates = Problems::number_comments(); my $new = Problems::recent_new('1 week'); my $new_text = 'in past week'; if ($new > $fixed) { $new = Problems::recent_new('3 days'); $new_text = 'recently'; } $out .= 'All the information you provide here will be sent to ' . join(' or ', map { $areas_info->{$_}->{name} } @$all_councils) . '. On the site, we will show the subject and details of the problem, plus your name if you give us permission.'; $out .= ''; } elsif ($details eq 'some') { my $e = mySociety::Config::get('CONTACT_EMAIL'); my %councils = map { $_ => 1 } @councils; my @missing; foreach (@$all_councils) { push @missing, $_ unless $councils{$_}; } my $n = @missing; my $list = join(' or ', map { $areas_info->{$_}->{name} } @missing); $out .= '
All the information you provide here will be sent to ' . join(' or ', map { $areas_info->{$_}->{name} } @councils) . '. On the site, we will show the subject and details of the problem, plus your name if you give us permission.'; $out .= ' We do not yet have details for the other council'; $out .= ($n>1) ? 's that cover' : ' that covers'; $out .= " this location. You can help us by finding a contact email address for local problems for $list and emailing it to us at $e."; $out .= ''; } else { my $e = mySociety::Config::get('CONTACT_EMAIL'); my $list = join(' or ', map { $areas_info->{$_}->{name} } @$all_councils); my $n = @$all_councils; $out .= '
We do not yet have details for the council'; $out .= ($n>1) ? 's that cover' : ' that covers'; $out .= " this location. If you submit a problem here it will be left on the site, but not reported to the council. You can help us by finding a contact email address for local problems for $list and emailing it to us at $e."; $out .= ''; } } if ($input{skipped}) { $out .= $q->p(_('Please fill in the form below with details of the problem, and describe the location as precisely as possible in the details box.')); } elsif ($q->{site} eq 'scambs') { $out .= '
Please fill in details of the problem below. We won\'t be able to help unless you leave as much detail as you can, so please describe the exact location of the problem (e.g. on a wall), what it is, how long it has been there, a description (and a photo of the problem if you have one), etc.'; } elsif ($details ne 'none') { $out .= '
Please fill in details of the problem below. The council won\'t be able
to help unless you leave as much detail as you can, so please describe the exact location of
the problem (e.g. on a wall), what it is, how long it has been there, a description (and a
photo of the problem if you have one), etc.';
} elsif ($q->{site} eq 'emptyhomes') {
$out .= <
The photo you uploaded was:
'; $out .= '