diff options
-rw-r--r-- | conf/general-example | 5 | ||||
-rw-r--r-- | db/schema.sql | 3 | ||||
-rw-r--r-- | perllib/Page.pm | 6 | ||||
-rw-r--r-- | templates/emails/comment-confirm | 14 | ||||
-rw-r--r-- | templates/emails/update-confirm | 14 | ||||
-rwxr-xr-x | web/index.cgi | 129 | ||||
-rw-r--r-- | web/js2.js | 2 | ||||
-rwxr-xr-x | web/photo.cgi | 49 |
8 files changed, 157 insertions, 65 deletions
diff --git a/conf/general-example b/conf/general-example index abe232331..1fbd26469 100644 --- a/conf/general-example +++ b/conf/general-example @@ -14,7 +14,7 @@ * Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. * Email: francis@mysociety.org; WWW: http://www.mysociety.org * - * $Id: general-example,v 1.5 2006-09-25 22:59:06 matthew Exp $ + * $Id: general-example,v 1.6 2006-10-10 15:53:04 matthew Exp $ * */ @@ -27,6 +27,9 @@ define('OPTION_BCI_DB_PASS', ''); define('OPTION_BASE_URL', 'http://www.example.org'); define('OPTION_CONTACT_EMAIL', 'team@example.org'); +define('OPTION_STAGING_SITE', 1); + +define('OPTION_GEO_CACHE', '/cache/'); define('OPTION_MAPIT_URL', 'http://services.mysociety.org/mapit'); define('OPTION_TILES_URL', 'http://tilma.mysociety.org/tileserver/10k-full-london'); diff --git a/db/schema.sql b/db/schema.sql index cc3f8ef23..b5ce0350d 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -4,7 +4,7 @@ -- Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. -- Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -- --- $Id: schema.sql,v 1.10 2006-10-09 17:30:38 matthew Exp $ +-- $Id: schema.sql,v 1.11 2006-10-10 15:53:04 matthew Exp $ -- -- secret @@ -78,6 +78,7 @@ create table problem ( northing double precision not null, title text not null, detail text not null, + photo bytea, -- category integer not null references category(id), name text not null, email text not null, diff --git a/perllib/Page.pm b/perllib/Page.pm index 1e1f8678e..5938b907d 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.pm,v 1.27 2006-10-09 15:29:52 matthew Exp $ +# $Id: Page.pm,v 1.28 2006-10-10 15:53:05 matthew Exp $ # package Page; @@ -15,6 +15,7 @@ use strict; use Carp; use CGI::Fast qw(-no_xhtml); use Error qw(:try); +use mySociety::Config; use mySociety::WatchUpdate; use mySociety::Web qw(ent NewURL); @@ -90,6 +91,9 @@ EOF $html .= 'Neighbourhood Fix-It'; $html .= $home ? '</h1>' : '</a></div>'; $html .= '<div id="wrapper"><div id="content">'; + if (mySociety::Config::get('STAGING_SITE')) { + $html .= '<p id="error">This is a developer site, things might break at any time.</p>'; + } return $html; } diff --git a/templates/emails/comment-confirm b/templates/emails/comment-confirm deleted file mode 100644 index 6c2861410..000000000 --- a/templates/emails/comment-confirm +++ /dev/null @@ -1,14 +0,0 @@ -Subject: Confirm your comment on Neighbourhood Fix-It - -Hi <?=$values['name']?>, - -Please click on the link below to confirm the comment you just wrote: - -<?=$values['url']?> - -Your comment reads: - -<?=$values['comment']?> - --- -The Neighbourhood Fix-It team diff --git a/templates/emails/update-confirm b/templates/emails/update-confirm new file mode 100644 index 000000000..d5d7c5138 --- /dev/null +++ b/templates/emails/update-confirm @@ -0,0 +1,14 @@ +Subject: Confirm your update on Neighbourhood Fix-It + +Hi <?=$values['name']?>, + +Please click on the link below to confirm the update you just wrote: + +<?=$values['url']?> + +Your update reads: + +<?=$values['update']?> + +-- +The Neighbourhood Fix-It team diff --git a/web/index.cgi b/web/index.cgi index ed98f1ccb..9d1d6bea5 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: index.cgi,v 1.42 2006-10-09 17:30:38 matthew Exp $ +# $Id: index.cgi,v 1.43 2006-10-10 15:53:05 matthew Exp $ # TODO # Nothing is done about the update checkboxes - not stored anywhere on anything! @@ -21,6 +21,7 @@ use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../../perllib"; use Error qw(:try); use File::Slurp; +use Image::Magick; use LWP::Simple; use RABX; use POSIX qw(strftime); @@ -181,13 +182,39 @@ sub submit_problem { my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/problem-confirm"); my $id = dbh()->selectrow_array("select nextval('problem_id_seq');"); - dbh()->do("insert into problem - (id, postcode, easting, northing, title, detail, name, email, phone, state) + + my $image; + if (my $fh = $q->upload('photo')) { + my $ct = $q->uploadInfo($fh)->{'Content-Type'}; + my $cd = $q->uploadInfo($fh)->{'Content-Disposition'}; + $q->delete('photo'); + return display_form($q, ('Please upload an image only')) unless + ($ct eq 'image/jpeg' || $ct eq 'image/pjpeg'); + $image = Image::Magick->new; + $image->Read(file=>$fh); + close $fh; + $image->Scale(geometry=>"250x250>"); + my @blobs = $image->ImageToBlob(); + undef $image; + $image = $blobs[0]; + } + + # This is horrid + my $s = dbh()->prepare("insert into problem + (id, postcode, easting, northing, title, detail, name, email, phone, photo, state) values - (?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed')", {}, - $id, $input{pc}, $input{easting}, $input{northing}, $input{title}, - $input{detail}, $input{name}, $input{email}, $input{phone} - ); + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed')"); + $s->bind_param(1, $id); + $s->bind_param(2, $input{pc}); + $s->bind_param(3, $input{easting}); + $s->bind_param(4, $input{northing}); + $s->bind_param(5, $input{title}); + $s->bind_param(6, $input{detail}); + $s->bind_param(7, $input{name}); + $s->bind_param(8, $input{email}); + $s->bind_param(9, $input{phone}); + $s->bind_param(10, $image, { pg_type => DBD::Pg::PG_BYTEA }); + $s->execute(); my %h = (); $h{title} = $input{title}; $h{detail} = $input{detail}; @@ -269,14 +296,14 @@ EOF my $areas_info = mySociety::MaPit::get_voting_areas_info($council); $council = join(', ', map { $areas_info->{$_}->{name} } @$council); my $pins = display_pin($q, $px, $py, 'purple'); - $out .= display_map($q, $input{x}, $input{y}, 1, 1, $pins); - if ($px && $py) { - $out .= <<EOF; + $out .= display_map($q, $input{x}, $input{y}, 2, 1, $pins); + if ($px && $py) { + $out .= <<EOF; <script type="text/javascript"> drag_x = $px - 254; drag_y = 254 - $py; </script> EOF - } + } $out .= '<h1>Reporting a problem</h1>'; $out .= '<p>You have located the problem at the location marked with a yellow pin on the map, which is within ' . $council . '. If this is not the correct location, simply click on the map again.</p> @@ -306,6 +333,8 @@ exact location of the problem (ie. on a wall or the floor), and so on.</p>'; <div><label for="form_phone">Phone:</label> <input type="text" value="$input_h{phone}" name="phone" id="form_phone" size="20"> <small>(optional, so the council can get in touch)</small></div> +<div><label for="form_photo">Photo:</label> +<input type="file" name="photo" id="form_photo"></div> <div class="checkbox"><input type="checkbox" name="updates" id="form_updates" value="1"$updates> <label for="form_updates">Receive email when updates are left on this problem</label></div> <div class="checkbox"><input type="submit" name="submit_problem" value="Submit"></div> @@ -328,38 +357,38 @@ sub display { try { if (mySociety::Util::is_valid_postcode($input{pc})) { ($name, $x, $y) = postcode_check($input{pc}, $input{x}, $input{y}); - } else { - $x = $input{x}; $y = $input{y}; + } else { + $x = $input{x}; $y = $input{y}; $x ||= 0; $x += 0; $y ||= 0; $y += 0; if (!$x && !$y) { - my @loc = split /\s*,\s*/, $input{pc}; - #if (2 == @loc) { - # my $url = 'http://geo.localsearchmaps.com/?country=UK&cb=cb&cbe=cbe&address='.$loc[0].'&city='.$loc[1]; - # my $js = LWP::Simple::get($url); - my $cache_dir = '/data/vhost/matthew.bci.mysociety.org/cache/'; - if (1 == @loc) { - my $url = 'http://geo.localsearchmaps.com/?country=UK&cb=cb&cbe=cbe&address='.$loc[0].'&city=London'; - my $cache_file = $cache_dir . md5_hex($url); - my $js; - if (-e $cache_file) { - $js = File::Slurp::read_file($cache_file); - } else { - $js = LWP::Simple::get($url); - File::Slurp::write_file($cache_file, $js); - } - if ($js =~ /^cb\((.*?),(.*?),/) { - my $lat = $1; my $lon = $2; - my ($easting,$northing) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G'); - $x = int(os_to_tile($easting))-1; - $y = int(os_to_tile($northing))-1; - } - } else { - $error = 'Could not understand that, sorry. '; - } - - } - } + my @loc = split /\s*,\s*/, $input{pc}; + #if (2 == @loc) { + # my $url = 'http://geo.localsearchmaps.com/?country=UK&cb=cb&cbe=cbe&address='.$loc[0].'&city='.$loc[1]; + # my $js = LWP::Simple::get($url); + my $cache_dir = mySociety::Config::get('GEO_CACHE'); + if (1 == @loc) { + my $url = 'http://geo.localsearchmaps.com/?country=UK&cb=cb&cbe=cbe&address='.$loc[0].'&city=London'; + my $cache_file = $cache_dir . md5_hex($url); + my $js; + if (-e $cache_file) { + $js = File::Slurp::read_file($cache_file); + } else { + $js = LWP::Simple::get($url); + File::Slurp::write_file($cache_file, $js); + } + if ($js =~ /^cb\((.*?),(.*?),/) { + my $lat = $1; my $lon = $2; + my ($easting,$northing) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G'); + $x = int(os_to_tile($easting))-1; + $y = int(os_to_tile($northing))-1; + } + } else { + $error = 'Could not understand that, sorry. '; + } + + } + } } catch RABX::Error with { my $e = shift; if ($e->value() == mySociety::MaPit::BAD_POSTCODE @@ -496,10 +525,10 @@ sub display_problem { # Get all information from database my $problem = dbh()->selectrow_arrayref( - "select easting, northing, title, detail, name, extract(epoch from created) + "select easting, northing, title, detail, name, extract(epoch from created), photo from problem where id=? and state='confirmed'", {}, $input{id}); return display($q, 'Unknown problem ID') unless $problem; - my ($easting, $northing, $title, $desc, $name, $time) = @$problem; + my ($easting, $northing, $title, $desc, $name, $time, $photo) = @$problem; my $x = os_to_tile($easting); my $y = os_to_tile($northing); my $x_tile = $input{x} || int($x); @@ -525,6 +554,10 @@ EOF $out .= ent($desc); $out .= '</p>'; + if ($photo) { + $out .= '<p align="center"><img src="/photo?id=' . $input{id} . '"></p>'; + } + my $back = NewURL($q, id=>undef); $out .= '<p align="right"><a href="' . $back . '">Back to listings</a></p>'; @@ -595,9 +628,11 @@ sub display_map { my $out = ''; my $img_type; if ($type) { + my $encoding = ''; + $encoding = ' enctype="multipart/form-data"' if ($type==2); my $pc_enc = ent($q->param('pc')); $out .= <<EOF; -<form action="./" method="get" id="mapForm"> +<form action="./" method="post" id="mapForm"$encoding> <input type="hidden" name="map" value="1"> <input type="hidden" name="x" value="$x"> <input type="hidden" name="y" value="$y"> @@ -667,12 +702,12 @@ sub postcode_check { my $location = mySociety::MaPit::get_location($pc); my $northing = $location->{northing}; my $easting = $location->{easting}; - my $xx = os_to_tile($easting); - my $yy = os_to_tile($northing); + my $xx = os_to_tile($easting); + my $yy = os_to_tile($northing); $x = int($xx); $y = int($yy); - $x -= 1 if ($xx - $x < 0.5); - $y -= 1 if ($yy - $y < 0.5); + $x -= 1 if ($xx - $x < 0.5); + $y -= 1 if ($yy - $y < 0.5); } return ($name, $x, $y); } diff --git a/web/js2.js b/web/js2.js index cc615b1ed..f426d1990 100644 --- a/web/js2.js +++ b/web/js2.js @@ -135,7 +135,7 @@ function urls_loaded(o) { var img = document.getElementById(id); if (img) { if (!img.galleryimg) { img.galleryimg = false; } - img.onclick = drag_check; + img.onclick = drag_check; img.src = 'http://tilma.mysociety.org/tileserver/10k-full-london/' + tiles[i][j]; img.name = 'tile_' + xx + '.' + yy; continue; diff --git a/web/photo.cgi b/web/photo.cgi new file mode 100755 index 000000000..54fa1647a --- /dev/null +++ b/web/photo.cgi @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w + +# photo.cgi: +# Display a photo for Neighbourhood Fix-It +# +# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: photo.cgi,v 1.1 2006-10-10 15:53:05 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 CGI::Carp; + +use Page; +use mySociety::Config; +use mySociety::DBHandle qw(dbh select_all); + +BEGIN { + mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + mySociety::DBHandle::configure( + Name => mySociety::Config::get('BCI_DB_NAME'), + User => mySociety::Config::get('BCI_DB_USER'), + Password => mySociety::Config::get('BCI_DB_PASS'), + Host => mySociety::Config::get('BCI_DB_HOST', undef), + Port => mySociety::Config::get('BCI_DB_PORT', undef) + ); +} + +sub main { + my $q = shift; + print $q->header(-type => 'image/jpeg', + -expires => '+1y' ); + my $id = $q->param('id') || return; + my $problem = dbh()->selectrow_arrayref( + "select photo from problem where id=? and state='confirmed' + and photo is not null", {}, $id); + return unless $problem; + my $photo = $problem->[0]; + print $photo; +} +Page::do_fastcgi(\&main); + |