diff options
-rwxr-xr-x | bin/import-flickr | 108 | ||||
-rw-r--r-- | conf/crontab.ugly | 3 | ||||
-rw-r--r-- | conf/general-example | 3 | ||||
-rw-r--r-- | conf/httpd.conf | 4 | ||||
-rw-r--r-- | db/schema.sql | 14 | ||||
-rw-r--r-- | templates/emails/flickr-confirm | 14 | ||||
-rw-r--r-- | templates/emails/flickr-submit | 14 | ||||
-rwxr-xr-x | web/flickr.cgi | 116 | ||||
-rwxr-xr-x | web/flickr2.cgi | 71 | ||||
-rwxr-xr-x | web/index.cgi | 129 | ||||
-rwxr-xr-x | web/photo.cgi | 4 |
11 files changed, 439 insertions, 41 deletions
diff --git a/bin/import-flickr b/bin/import-flickr new file mode 100755 index 000000000..dd45545d8 --- /dev/null +++ b/bin/import-flickr @@ -0,0 +1,108 @@ +#!/usr/bin/perl -w + +# import-flickr: +# Get new Flickr photos (uploaded from cameras, hopefully!) +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: import-flickr,v 1.1 2007-06-17 09:40:50 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 File::Slurp; +use LWP::Simple; + +use mySociety::AuthToken; +use mySociety::Config; +use mySociety::DBHandle qw(dbh select_all); +use mySociety::EmailUtil; +use mySociety::Email; +use mySociety::GeoUtil; + +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) + ); +} + +my $key = mySociety::Config::get('FLICKR_API'); +my $url = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&tags=fixmystreet&extras=geo&api_key=' . $key . '&user_id='; +my $ids = select_all('select nsid from flickr'); +my $result = ''; +foreach (@$ids) { + $result .= get($url . $_->{nsid}); +} + +my %ids; +my $st = select_all('select id from flickr_imported'); +foreach (@$st) { + $ids{$_->{id}} = 1; +} + +# XXX: Hmm... Use format=perl now Cal has added it for me! :) +while ($result =~ /<photo id="([^"]*)" owner="([^"]*)" secret="([^"]*)" server="([^"]*)" farm="([^"]*)" title="([^"]*)".*?latitude="([^"]*)" longitude="([^"]*)"/g) { + my ($id, $owner, $secret, $server, $farm, $title, $lat, $lon) = ($1, $2, $3, $4, $5, $6, $7, $8); + next if $ids{$id}; + my $url = "http://farm$farm.static.flickr.com/$server/".$id.'_'.$secret.'_m.jpg'; + my $image = get($url); + problem_create($id, $owner, $title, $lat, $lon, $image); +} + +sub problem_create { + my ($photo_id, $owner, $title, $lat, $lon, $image) = @_; + my ($name, $email) = dbh()->selectrow_array('select name, email from flickr where nsid=?', {}, $owner); + my ($easting, $northing) = (0,0); + if ($lat && $lon) { + # XXX This appears to be going wrong :( + ($easting, $northing) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G'); + } + my $id = dbh()->selectrow_array("select nextval('problem_id_seq')"); + # This is horrid + my $s = dbh()->prepare("insert into problem + (id, postcode, easting, northing, title, detail, name, + email, phone, photo, state, council, used_map, anonymous, category) + values + (?, '', ?, ?, ?, '', ?, ?, '', ?, 'flickr', '', 't', 'f', '')"); + $s->bind_param(1, $id); + $s->bind_param(2, $easting); + $s->bind_param(3, $northing); + $s->bind_param(4, $title); + $s->bind_param(5, $name); + $s->bind_param(6, $email); + $s->bind_param(7, $image, { pg_type => DBD::Pg::PG_BYTEA }); + $s->execute(); + + dbh()->do('insert into flickr_imported (id) values (?)', {}, $photo_id); + + # XXX: Needs to only send email once to user per batch of photos, not one per photo? + my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/flickr-submit"); + my %h = (); + my $token = mySociety::AuthToken::store('flickr', $id); + $h{name} = $name; + $h{url} = mySociety::Config::get('BASE_URL') . '/L/' . $token; + + my $body = mySociety::Email::construct_email({ + _template_ => $template, + _parameters_ => \%h, + To => [ [ $email, $name ] ], + From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ], + }); + + my $result = mySociety::EmailUtil::send_email($body, mySociety::Config::get('CONTACT_EMAIL'), $email); + if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { + dbh()->commit(); + } else { + dbh()->rollback(); + } +} diff --git a/conf/crontab.ugly b/conf/crontab.ugly index 06911dd30..ad76bb6c4 100644 --- a/conf/crontab.ugly +++ b/conf/crontab.ugly @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org/ # -# $Id: crontab.ugly,v 1.9 2007-06-15 14:57:51 matthew Exp $ +# $Id: crontab.ugly,v 1.10 2007-06-17 09:40:50 matthew Exp $ PATH=/usr/local/bin:/usr/bin:/bin !!(* if ($vhost eq "matthew.bci.mysociety.org") { *)!! @@ -14,6 +14,7 @@ MAILTO=team@fixmystreet.com !!(* } *)!! */5 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/send-reports.lock /data/vhost/!!(*= $vhost *)!!/mysociety/bci/bin/send-reports || echo "stalled?" +15,45 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/import-flickr.lock /data/vhost/!!(*= $vhost *)!!/mysociety/bci/bin/import-flickr || echo "stalled?" 3 9,12,15,18 * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/send-reports.lock "/data/vhost/!!(*= $vhost *)!!/mysociety/bci/bin/send-reports --verbose" || echo "stalled?" 2 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/send-alerts.lock /data/vhost/!!(*= $vhost *)!!/mysociety/bci/bin/send-alerts || echo "stalled?" 0,30 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/send-questionnaires.lock /data/vhost/!!(*= $vhost *)!!/mysociety/bci/bin/send-questionnaires || echo "stalled?" diff --git a/conf/general-example b/conf/general-example index 2fe7d66f4..921dcafc6 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.11 2007-06-15 14:57:51 matthew Exp $ + * $Id: general-example,v 1.12 2007-06-17 09:40:51 matthew Exp $ * */ @@ -45,4 +45,5 @@ define('OPTION_GAZE_URL', 'http://gaze.mysociety.org/gaze'); define('OPTION_SMTP_SMARTHOST', 'localhost'); +define('OPTION_FLICKR_API', ''); ?> diff --git a/conf/httpd.conf b/conf/httpd.conf index f2e0bc856..a12f6c0cc 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -20,7 +20,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org # -# $Id: httpd.conf,v 1.17 2007-06-16 21:44:53 matthew Exp $ +# $Id: httpd.conf,v 1.18 2007-06-17 09:40:51 matthew Exp $ DirectoryIndex index.cgi @@ -32,6 +32,8 @@ RewriteRule ^/[Aa]/([0-9A-Za-z]{16}).*$ /alert.cgi?token=$1 RewriteRule ^/[Cc]/([0-9A-Za-z]{16}).*$ /confirm.cgi?type=update;token=$1 RewriteRule ^/[Pp]/([0-9A-Za-z]{16}).*$ /confirm.cgi?type=problem;token=$1 RewriteRule ^/[Qq]/([0-9A-Za-z]{16}).*$ /questionnaire.cgi?token=$1 +RewriteRule ^/[Ff]/([0-9A-Za-z]{16}).*$ /flickr.cgi?token=$1 +RewriteRule ^/[Ll]/([0-9A-Za-z]{16}).*$ /flickr2.cgi?token=$1 RewriteRule ^/rss/([0-9]+)$ /rss.cgi?type=new_updates;id=$1 [QSA] RewriteRule ^/rss/([0-9]+),([0-9]+)$ /rss.cgi?type=local_problems;x=$1;y=$2 [QSA] diff --git a/db/schema.sql b/db/schema.sql index 38b0a61e0..17f08d9d6 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.32 2007-06-15 14:57:51 matthew Exp $ +-- $Id: schema.sql,v 1.33 2007-06-17 09:40:51 matthew Exp $ -- -- secret @@ -279,3 +279,15 @@ create table alert_sent ( whenqueued timestamp not null default ms_current_timestamp() ); +create table flickr ( + id serial not null primary key, + nsid text not null, + name text not null, + email text not null +); +create unique index flickr_email_idx on flickr(email); + +create table flickr_imported ( + id integer not null +); +create unique index flickr_imported_id_idx on flickr_imported(id); diff --git a/templates/emails/flickr-confirm b/templates/emails/flickr-confirm new file mode 100644 index 000000000..f07f53404 --- /dev/null +++ b/templates/emails/flickr-confirm @@ -0,0 +1,14 @@ +Subject: Confirm your email address on FixMyStreet + +Hi, + +Please click on the link below to confirm the email address +you just gave to FixMyStreet: + +<?=$values['url']?> + +This is so we can look up the photos you tag with FixMyStreet, +and send you an email letting you know about your new problems. + +-- +The FixMyStreet team diff --git a/templates/emails/flickr-submit b/templates/emails/flickr-submit new file mode 100644 index 000000000..348f4476f --- /dev/null +++ b/templates/emails/flickr-submit @@ -0,0 +1,14 @@ +Subject: New photo pulled from Flickr to FixMyStreet + +Hi <?=$values['name']?>, + +We've fetched a photo you uploaded to Flickr and tagged with +FixMyStreet. To check the details we have, and to add any more, +please visit the following URL: + +<?=$values['url']?> + +Then we can send your photo to the council. Thanks! + +-- +The FixMyStreet team diff --git a/web/flickr.cgi b/web/flickr.cgi new file mode 100755 index 000000000..f5651b12e --- /dev/null +++ b/web/flickr.cgi @@ -0,0 +1,116 @@ +#!/usr/bin/perl -w + +# flickr.cgi: +# Register for Flickr usage, and update photos +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: flickr.cgi,v 1.1 2007-06-17 09:40:51 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 LWP::Simple; +use mySociety::AuthToken; +use mySociety::DBHandle qw(dbh); +use mySociety::Email; +use mySociety::EmailUtil; + +use Page; + +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 Page::header($q, title=>'Flickr photo upload'); + my $out = ''; + if (my $token = $q->param('token')) { + my $email = mySociety::AuthToken::retrieve('flickr', $token); + if ($email) { + my $key = mySociety::Config::get('FLICKR_API'); + my $url = 'http://api.flickr.com/services/rest/?method=flickr.people.findByEmail&api_key='.$key.'&find_email='.$email; + my $result = get($url); + my ($nsid) = $result =~ /nsid="([^"]*)"/; + $url = 'http://api.flickr.com/services/rest/?method=flickr.people.getInfo&api_key='.$key.'&user_id='.$nsid; + $result = get($url); + my ($name) = $result =~ /<realname>(.*?)<\/realname>/; + + my $id = dbh()->selectrow_array("select nextval('flickr_id_seq');"); + dbh()->do("insert into flickr (id, nsid, name, email) values (?, ?, ?, ?)", {}, + $id, $nsid, $name, $email); + dbh()->commit(); + $out .= $q->p('Thanks for confirming your email address. Please now tag +your photos with FixMyStreet (and geo-tag them if you want/can, automatically if possible!) +for us to pick them up.'); + } else { + $out = $q->p(_(<<EOF)); +Thank you for trying to register for your Flickr photos. We seem to have a +problem ourselves though, so <a href="/contact">please let us know what went on</a> +and we'll look into it. +EOF + } + } elsif (my $email = $q->param('email')) { + my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/flickr-confirm"); + my %h = (); + my $token = mySociety::AuthToken::store('flickr', $email); + $h{url} = mySociety::Config::get('BASE_URL') . '/F/' . $token; + + my $body = mySociety::Email::construct_email({ + _template_ => $template, + _parameters_ => \%h, + To => $email, + From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ], + }); + + my $result; + $result = mySociety::EmailUtil::send_email($body, mySociety::Config::get('CONTACT_EMAIL'), $email); + if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { + $out = 'Thanks, we\'ve sent you a confirmation email!'; + dbh()->commit(); + } else { + $out = 'Sorry, something went wrong - very alpha!'; + dbh()->rollback(); + } + } else { + $out .= <<EOF; +<p><strong>Very alpha status</strong></p> +<p>Using the Flickr API, FixMyStreet can utilise all the methods of uploading photos to Flickr +to report problems to your council:</p> +<ol> +<li>Register that you're going to be using Flickr here, so we know to check your photos. +<li>Upload your photo to Flickr, for example via camera phone on location +<li>Tag the photo with FixMyStreet when uploading, or afterwards; +<li>Locate the problem on Flickr's map (if you have GPS, this should be done automatically :) ) +<li>FixMyStreet will find the photo, and ask you to add/ check the details; +<li>The report is then sent to the council. +</ol> + +<form method="post"> +<p>To begin, please enter your Flickr email address, both so we know the account to watch and +so we can email you when you upload FixMyStreet photos with a link to check and confirm +the details: <input type="text" name="email" value="" size="30"> +<input type="submit" value="Go"> +</p></form> +EOF + } + + print $out; + print Page::footer(); + dbh()->rollback(); +} +Page::do_fastcgi(\&main); + diff --git a/web/flickr2.cgi b/web/flickr2.cgi new file mode 100755 index 000000000..71cc07f39 --- /dev/null +++ b/web/flickr2.cgi @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w + +# flickr2.cgi: +# Check photo details, and confirm for council +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: flickr2.cgi,v 1.1 2007-06-17 09:40:51 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 URI::Escape; + +use mySociety::AuthToken; +use mySociety::DBHandle qw(dbh select_all); +use mySociety::Email; +use mySociety::EmailUtil; + +use Page; + +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; + my $out = ''; + if (my $token = $q->param('token')) { + my $id = mySociety::AuthToken::retrieve('flickr', $token); + if ($id) { + my ($e, $n, $name, $email, $title) = dbh()->selectrow_array( + "select easting,northing,name,email,title from problem where id=? and state='flickr'", {}, $id); + if ($email) { + $name = uri_escape($name); + $email = uri_escape($email); + $title = uri_escape($title); + # XXX: Look up some of this stuff at the destination instead??? + print $q->redirect("/?flickr=$token;submit_map=1;easting=$e;northing=$n;name=$name;email=$email;title=$title;anonymous=1"); + exit; + } + $out = $q->p("That report appears to have been checked already."); + } else { + $out = $q->p(_(<<EOF)); +Thank you for trying to register for your Flickr photos. We seem to have a +problem ourselves though, so <a href="/contact">please let us know what went on</a> +and we'll look into it. +EOF + } + } else { + $out .= $q->p('You need a token to get to this page!'); + } + + print Page::header($q, title=>'Flickr photo upload'); + print $out; + print Page::footer(); + dbh()->rollback(); +} +Page::do_fastcgi(\&main); diff --git a/web/index.cgi b/web/index.cgi index 32ee880a1..0f80b1bde 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.140 2007-06-16 19:42:25 matthew Exp $ +# $Id: index.cgi,v 1.141 2007-06-17 09:40:51 matthew Exp $ use strict; require 5.8.0; @@ -95,8 +95,27 @@ EOF my $fixed = dbh()->selectrow_array("select count(*) from problem where state='fixed' and lastupdate>ms_current_timestamp()-'1 month'::interval"); my $updates = dbh()->selectrow_array("select count(*) from comment where state='confirmed'"); my $new = dbh()->selectrow_array("select count(*) from problem where state in ('confirmed','fixed') and confirmed>ms_current_timestamp()-'1 week'::interval"); + $out .= '<form action="./" method="get" id="postcodeForm">'; + if (my $token = $q->param('flickr')) { + my $id = mySociety::AuthToken::retrieve('flickr', $token); + if ($id) { + my $name = ent($q->param('name')); + my $email = ent($q->param('email')); + my $title = ent($q->param('title')); + $out .= <<EOF; +<p style="margin-top:0;color: #cc0000;">Thanks for uploading your photo via Flickr! We need to locate your problem, +so please enter a nearby street name or postcode in the box below...</p> + +<input type="hidden" name="flickr" value="$token"> +<input type="hidden" name="submit_map" value="1"> +<input type="hidden" name="name" value="$name"> +<input type="hidden" name="email" value="$email"> +<input type="hidden" name="title" value="$title"> +<input type="hidden" name="anonymous" value="1"> +EOF + } + } $out .= <<EOF; -<form action="./" method="get" id="postcodeForm"> <label for="pc">Enter a nearby postcode, or street name and area:</label> <input type="text" name="pc" value="$pc_h" id="pc" size="10" maxlength="200"> <input type="submit" value="Go" id="submit"> @@ -182,7 +201,7 @@ sub submit_update { sub submit_problem { my $q = shift; - my @vars = qw(council title detail name email phone pc easting northing skipped anonymous category); + my @vars = qw(council title detail name email phone pc easting northing skipped anonymous category flickr); my %input = map { $_ => scalar $q->param($_) } @vars; my @errors; @@ -275,43 +294,61 @@ sub submit_problem { my $used_map = $input{skipped} ? 'f' : 't'; $input{category} = 'Other' unless $input{category}; - my $id = dbh()->selectrow_array("select nextval('problem_id_seq');"); - # This is horrid - my $s = dbh()->prepare("insert into problem - (id, postcode, easting, northing, title, detail, name, - email, phone, photo, state, council, used_map, anonymous, category) - values - (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '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->bind_param(11, $input{council}); - $s->bind_param(12, $used_map); - $s->bind_param(13, $input{anonymous} ? 'f': 't'); - $s->bind_param(14, $input{category}); - $s->execute(); - my %h = (); - $h{title} = $input{title}; - $h{detail} = $input{detail}; - $h{name} = $input{name}; - $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id); - dbh()->commit(); - - my $out = Page::send_email($input{email}, $input{name}, 'problem', %h); + my ($id, $out); + if (my $token = $input{flickr}) { + my $id = mySociety::AuthToken::retrieve('flickr', $token); + if ($id) { + dbh()->do("update problem set easting=?, northing=?, title=?, detail=?, + name=?, email=?, phone=?, state='confirmed', council=?, used_map='t', + anonymous=?, category=?, confirmed=ms_current_timestamp(), + lastupdate=ms_current_timestamp() where id=?", {}, $input{easting}, $input{northing}, + $input{title}, $input{detail}, $input{name}, $input{email}, + $input{phone}, $input{council}, $input{anonymous} ? 'f' : 't', + $input{category}, $id); + dbh()->commit(); + $out = $q->p(sprintf(_('You have successfully confirmed your problem and you can now <a href="%s">view it on the site</a>.'), "/?id=$id")); + } else { + $out = $q->p('There appears to have been a problem.'); + } + } else { + $id = dbh()->selectrow_array("select nextval('problem_id_seq');"); + # This is horrid + my $s = dbh()->prepare("insert into problem + (id, postcode, easting, northing, title, detail, name, + email, phone, photo, state, council, used_map, anonymous, category) + values + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '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->bind_param(11, $input{council}); + $s->bind_param(12, $used_map); + $s->bind_param(13, $input{anonymous} ? 'f': 't'); + $s->bind_param(14, $input{category}); + $s->execute(); + my %h = (); + $h{title} = $input{title}; + $h{detail} = $input{detail}; + $h{name} = $input{name}; + $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id); + dbh()->commit(); + + $out = Page::send_email($input{email}, $input{name}, 'problem', %h); + } return $out; } sub display_form { my ($q, @errors) = @_; my ($pin_x, $pin_y, $pin_tile_x, $pin_tile_y) = (0,0,0,0); - my @vars = qw(title detail name email phone pc easting northing x y skipped council anonymous); + my @vars = qw(title detail name email phone pc easting northing x y skipped council anonymous flickr); my %input = map { $_ => $q->param($_) || '' } @vars; my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; my @ps = $q->param; @@ -323,7 +360,8 @@ sub display_form { unless ($pin_x && $pin_y) || ($input{easting} && $input{northing}) || ($input{skipped} && $input{x} && $input{y}) - || ($input{skipped} && $input{pc}); + || ($input{skipped} && $input{pc}) + || ($input{flickr} && $input{pc}); my $out = ''; my ($px, $py, $easting, $northing, $island); @@ -344,8 +382,17 @@ sub display_form { $py = Page::tile_to_px($pin_y, $input{y}); $easting = Page::tile_to_os($pin_x); $northing = Page::tile_to_os($pin_y); + } elsif ($input{flickr} && $input{pc} && !$input{easting} && !$input{northing}) { + my ($x, $y, $e, $n, $i, $error) = geocode($input{pc}); + $easting = $e; $northing = $n; $island = $i; + $input{x} = int(Page::os_to_tile($easting)); + $input{y} = int(Page::os_to_tile($northing)); + $px = Page::os_to_px($easting, $input{x}); + $py = Page::os_to_px($northing, $input{y}); } else { # Normal form submission + $input{x} = int(Page::os_to_tile($input{easting})); + $input{y} = int(Page::os_to_tile($input{northing})); $px = Page::os_to_px($input{easting}, $input{x}); $py = Page::os_to_px($input{northing}, $input{y}); $easting = $input_h{easting}; @@ -475,8 +522,20 @@ $category <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> +EOF + if (my $token = $input{flickr}) { + my $id = mySociety::AuthToken::retrieve('flickr', $token); + if ($id) { + $out .= '<p>The photo you uploaded was:</p> <input type="hidden" name="flickr" value="' . $token . '">'; + $out .= '<p align="center"><img src="/photo?id=' . $id . '"></p>'; + } + } else { + $out .= <<EOF; <div><label for="form_photo">Photo:</label> <input type="file" name="photo" id="form_photo"></div> +EOF + } + $out .= <<EOF; <p>Please note:</p> <ul> <li>Please be polite, concise and to the point. diff --git a/web/photo.cgi b/web/photo.cgi index 41e9221ef..392f1befa 100755 --- a/web/photo.cgi +++ b/web/photo.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: photo.cgi,v 1.5 2007-06-15 14:57:52 matthew Exp $ +# $Id: photo.cgi,v 1.6 2007-06-17 09:40:51 matthew Exp $ use strict; require 5.8.0; @@ -39,7 +39,7 @@ sub main { -expires => '+1y' ); my $id = $q->param('id') || return; my $problem = dbh()->selectrow_arrayref( - "select photo from problem where id=? and state in ('confirmed', 'fixed') + "select photo from problem where id=? and state in ('confirmed', 'fixed', 'flickr') and photo is not null", {}, $id); return unless $problem; my $photo = $problem->[0]; |