#!/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.10 2006-09-20 14:51:00 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 HTML::Entities; use Page; use mySociety::Config; BEGIN { mySociety::Config::set_file("$FindBin::Bin/../conf/general"); } use mySociety::MaPit; mySociety::MaPit::configure(); # Main code for index.cgi sub main { my $q = shift; my $out = ''; if ($q->param('pc')) { $out = display($q); } else { $out = front_page(); } print $q->header(-charset=>'utf-8'); 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 .= <Report a problem with refuse, recycling, fly tipping, pest control, abandoned vechicles, street lighting, graffiti, street cleaning, litter or similar to your local council.

This is currently only for Newham and Lewisham Councils

It’s very simple:

  1. Enter postcode
  2. Find problem on map
  3. Enter details of problem
  4. Send!

Enter your postcode:

EOF return $out; } # This should use postcode, not x/y! sub display { my $q = shift; my $pc = $q->param('pc'); my $areas; my $error; try { $areas = mySociety::MaPit::get_voting_areas($pc); } catch RABX::Error with { my $e = shift; if ($e->value() == mySociety::MaPit::BAD_POSTCODE || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND) { $error = 'That postcode was not recognised, sorry.'; } else { $e->throw(); } }; return front_page($error) if ($error); # Check for London Borough return front_page('I\'m afraid that postcode isn\'t in our covered area.') if (!$areas || !$areas->{LBO}); # Check for Lewisham or Newham my $lbo = $areas->{LBO}; return front_page('I\'m afraid that postcode isn\'t in our covered London boroughs.') unless ($lbo == 2510 || $lbo == 2492); my $area_info = mySociety::MaPit::get_voting_area_info($lbo); my $name = $area_info->{name}; my $out = <$name

Now, please select the location of the problem on the map below. Use the arrows to the left of the map to scroll around.

EOF my @ps = $q->param; foreach (@ps) { my $x = $q->param($_) if /\.x$/; my $y = $q->param($_) if /\.y$/; } my $x = $q->param('x') || 628; my $y = $q->param('y') || 1724; my $dir = mySociety::Config::get('TILES_URL'); my $tl = $x . '.' . $y; my $tr = ($x+1) . '.' . $y; my $bl = $x . '.' . ($y+1); my $br = ($x+1) . '.' . ($y+1); my $tl_src = $dir . $tl . '.png'; my $tr_src = $dir . $tr . '.png'; my $bl_src = $dir . $bl . '.png'; my $br_src = $dir . $br . '.png'; $pc = encode_entities($pc); $out .= Page::compass($pc, $x, $y); $out .= <

Current problems

Recently fixed problems


EOF return $out; }