#!/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.294 2009-10-07 08:18:42 louise Exp $ use strict; use Standard; use Error qw(:try); use File::Slurp; use LWP::Simple; use RABX; use CGI::Carp; use URI::Escape; use CrossSell; use mySociety::AuthToken; use mySociety::Config; use mySociety::DBHandle qw(select_all); use mySociety::EmailUtil; use mySociety::GeoUtil; use mySociety::Locale; 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; if (my $partial = $q->param('partial_token')) { # We have a partial token, so fetch data from database and see where we're at. my $id = mySociety::AuthToken::retrieve('partial', $partial); if ($id) { my @row = dbh()->selectrow_array( "select easting, northing, name, email, title, (photo is not null) as has_photo, phone from problem where id=? and state='partial'", {}, $id); if (@row) { $q->param('anonymous', 1); $q->param('submit_map', 1); $q->param('easting', $row[0]); $q->param('northing', $row[1]); $q->param('name', $row[2]); $q->param('email', $row[3]); $q->param('title', $row[4]); $q->param('has_photo', $row[5]); $q->param('phone', $row[6]); $q->param('partial', $partial); } else { my $base = mySociety::Config::get('BASE_URL'); print $q->redirect(-location => $base . '/report/' . $id); } } } 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'); } elsif ($q->param('cobrand_page') && ($q->{site} ne 'fixmystreet')) { ($out, %params) = Cobrand::cobrand_page($q); if (! $out){ $out = front_page($q); } } else { $out = front_page($q); } print Page::header($q, %params); print $out; my %footerparams; $footerparams{js} = $params{js} if $params{js}; $footerparams{template} = $params{template} if $params{template}; 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 $cobrand = Page::get_cobrand($q); my $cobrand_form_elements = Cobrand::form_elements(Page::get_cobrand($q), 'postcodeForm', $q); my $out = '
' . _('Report, view, or discuss local problems') . '';
my $subhead = _('(like graffiti, fly tipping, broken paving slabs, or street lighting)');
$out .= '
' . $subhead . '' if $subhead ne ' ';
$out .= '
' . $error . '
' if ($error); # Add pretty commas for display $out .= '' . sprintf(_('All the information you provide here will be sent to %s.
On the site, we will show the subject and details of the problem, plus your
name if you give us permission.'), join(' or ', map { $areas_info->{$_}->{name} } @$all_councils));
$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;
if ($q->{site} ne 'emptyhomes') {
$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.";
} else {
$out .= _(" We do not yet have details for the council that covers
this location. If you submit a report here it will be left on the site, but
not reported to the council – please still leave your report, so that
we can show to the council the activity in their area.");
}
$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 ($q->{site} eq 'emptyhomes') {
$out .= $q->p(_(<
';
}
my $anon = ($input{anonymous}) ? ' checked' : ($input{title} ? '' : ' checked');
$out .= '
The photo you uploaded was:
' . $problem->{title} . '') . "\@$lat,$lon'>View on Google Maps
"; my $pins = Page::display_pin($q, $px, $py, 'blue'); $out .= Page::display_map($q, x => $x_tile, y => $y_tile, type => 0, pins => $pins, px => $px, py => $py, post => $map_links ); if ($q->{site} ne 'emptyhomes' && $problem->{state} eq 'confirmed' && $problem->{duration} > 8*7*24*60*60) { $out .= $q->p({id => 'unknown'}, _('This problem is old and of unknown status.')) } if ($problem->{state} eq 'fixed') { $out .= $q->p({id => 'fixed'}, _('This problem has been fixed') . '.') } $out .= Page::display_problem_text($q, $problem); my $contact_url = NewURL($q, -retain => 1, pc => undef, -url=>'/contact?id=' . $input{id}); $out .= $q->p({align=>'right'}, $q->small($q->a({rel => 'nofollow', href => $contact_url}, _('Offensive? Unsuitable? Tell us'))) ); my $back = NewURL($q, -url => '/', 'x' => $x_tile, 'y' => $y_tile, -retain => 1, pc => undef, id => undef ); $out .= '' . _('More problems nearby') . '
'; $out .= '$blurb
$cobrand_form_elements EOF $out .= '