aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-reports152
-rw-r--r--perllib/EastHantsWSDL.pm70
-rw-r--r--templates/emails/submit-brent2
-rw-r--r--templates/emails/submit-council2
-rw-r--r--templates/emails/submit-eha2
5 files changed, 178 insertions, 50 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 15037cc55..a0fac7578 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: send-reports,v 1.59 2008-10-09 15:23:08 matthew Exp $
+# $Id: send-reports,v 1.60 2008-10-16 16:18:18 matthew Exp $
use strict;
require 5.8.0;
@@ -15,8 +15,10 @@ require 5.8.0;
use FindBin;
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../../perllib";
+use Error qw(:try);
use File::Slurp;
+use EastHantsWSDL;
use mySociety::Config;
use mySociety::DBHandle qw(dbh);
use mySociety::Email;
@@ -35,7 +37,7 @@ BEGIN {
);
}
-use mySociety::Dress;
+use mySociety::Dress; # Has to come after the BEGIN, my poor coding
die "Either no arguments, --nomail or --verbose" if (@ARGV>1);
my $nomail = 0;
@@ -46,7 +48,7 @@ $verbose = 1 if $nomail;
my $base_url = mySociety::Config::get('BASE_URL');
my $site = 'fixmystreet';
-$site = 'emptyhomes' if $base_url =~ 'emptyhomes' || $base_url eq 'http://matthew.fixmystreet.com'; # XXX
+$site = 'emptyhomes' if $base_url =~ 'emptyhomes'; # || $base_url eq 'http://matthew.fixmystreet.com'; # XXX
my $query = "SELECT id, council, category, title, detail, name, email, phone,
used_map, easting, northing, (photo is not null) as has_photo
@@ -63,12 +65,20 @@ foreach my $row (@$unsent) {
next;
}
+ my $send_email = 0;
+ my $send_web = 0;
+
# Template variables for the email
my %h = map { $_ => $row->{$_} } qw/title detail name email phone category easting northing/;
- $h{phone} = "Phone: $h{phone}\n\n" if $h{phone};
- $h{has_photo} = '';
- $h{has_photo} = "This web page also contains a photo of the problem, provided by the user.\n\n" if $row->{has_photo};
$h{url} = $base_url . '/report/' . $row->{id};
+ $h{phone_line} = $h{phone} ? "Phone: $h{phone}\n\n" : '';
+ if ($row->{has_photo}) {
+ $h{has_photo} = "This web page also contains a photo of the problem, provided by the user.\n\n";
+ $h{image_url} = $base_url . '/photo?id=' . $row->{id};
+ } else {
+ $h{has_photo} = '';
+ $h{image_url} = '';
+ }
$h{fuzzy} = $row->{used_map} ? 'To view a map of the precise location of this issue'
: 'The user could not locate the problem on a map, but to see the area around the location they entered';
$h{closest_address} = '';
@@ -94,11 +104,12 @@ foreach my $row (@$unsent) {
$council_email = 'N/A' unless $council_email;
$notgot{$council_email}{$row->{category}}++;
$note{$council_email}{$row->{category}} = $note;
- next;
+ next;
}
push @to, [ $council_email, $name ];
@recips = ($council_email);
+ $send_email = 1;
$template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/submit-eha");
} else {
@@ -112,32 +123,31 @@ foreach my $row (@$unsent) {
my $all_confirmed = 1;
foreach my $council (@councils) {
my $name = $areas_info->{$council}->{name};
- my ($council_email, $confirmed, $note) = dbh()->selectrow_array(
- "SELECT email,confirmed,note FROM contacts WHERE deleted='f'
- and area_id=? AND category=?", {}, $council, $row->{category});
- $council_email = essex_contact($row->{easting}, $row->{northing}) if $council == 2225;
- $council_email = notts_contact($row->{easting}, $row->{northing}) if $council == 2236;
- unless ($confirmed) {
- $all_confirmed = 0;
- $note = 'Council ' . $row->{council} . ' deleted'
- unless $note;
- $council_email = 'N/A' unless $council_email;
- $notgot{$council_email}{$row->{category}}++;
- $note{$council_email}{$row->{category}} = $note;
- }
- push @to, [ $council_email, $name ];
push @dear, $name;
- $recips{$council_email} = 1;
- }
- @recips = keys %recips;
- if (!@to) {
- if ($verbose) {
- print 'Need to send problem #' . $row->{id} . ' to council(s) ' . join(',',@recips) . "\n";
- print " ...but we have no contact details for any of them!\n";
+ if ($council == 2330) { # E. Hants have a web service
+ $send_web = 1;
+ $h{category} = 'Customer Services' if $h{category} eq 'Other';
+ } else {
+ my ($council_email, $confirmed, $note) = dbh()->selectrow_array(
+ "SELECT email,confirmed,note FROM contacts WHERE deleted='f'
+ and area_id=? AND category=?", {}, $council, $row->{category});
+ $council_email = essex_contact($row->{easting}, $row->{northing}) if $council == 2225;
+ $council_email = notts_contact($row->{easting}, $row->{northing}) if $council == 2236;
+ unless ($confirmed) {
+ $all_confirmed = 0;
+ $note = 'Council ' . $row->{council} . ' deleted'
+ unless $note;
+ $council_email = 'N/A' unless $council_email;
+ $notgot{$council_email}{$row->{category}}++;
+ $note{$council_email}{$row->{category}} = $note;
+ }
+ push @to, [ $council_email, $name ];
+ $recips{$council_email} = 1;
+ $send_email = 1;
}
- next;
}
- next unless ($all_confirmed);
+ @recips = keys %recips;
+ next unless $all_confirmed;
$template = 'submit-council';
$template = 'submit-brent' if $row->{council} eq 2488;
@@ -145,10 +155,10 @@ foreach my $row (@$unsent) {
if ($h{category} eq 'Other') {
$h{category_footer} = 'this type of local problem';
- $h{category} = '';
+ $h{category_line} = '';
} else {
$h{category_footer} = "'" . $h{category} . "'";
- $h{category} = "Category: $h{category}\n\n";
+ $h{category_line} = "Category: $h{category}\n\n";
}
$h{councils_name} = join(' and ', @dear);
@@ -164,8 +174,8 @@ If you know of an appropriate contact address, please do get in touch. ]\n\n";
}
- unless (@recips) {
- die 'Email not going anywhere for ID ' . $row->{id} . '!';
+ unless ($send_email || $send_web) {
+ die 'Report not going anywhere for ID ' . $row->{id} . '!';
}
if (mySociety::Config::get('STAGING_SITE')) {
@@ -182,20 +192,29 @@ If you know of an appropriate contact address, please do get in touch. ]\n\n";
# @recips = ($e);
# }
- my $email = mySociety::Email::construct_email({
- _template_ => $template,
- _parameters_ => \%h,
- To => \@to,
- From => [ $row->{email}, $row->{name} ],
- 'Message-ID' => sprintf('<report-%s-%s@mysociety.org>', time(), unpack('h*', random_bytes(5, 1))),
- });
-
- my $result;
- if ($nomail) {
- $result = -1;
- } else {
- $result = mySociety::EmailUtil::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), @recips);
+ # Multiply results together, so one success counts as a success.
+ my $result = -1;
+
+ if ($send_email) {
+ my $email = mySociety::Email::construct_email({
+ _template_ => $template,
+ _parameters_ => \%h,
+ To => \@to,
+ From => [ $row->{email}, $row->{name} ],
+ 'Message-ID' => sprintf('<report-%s-%s@mysociety.org>', time(), unpack('h*', random_bytes(5, 1))),
+ });
+ if (!$nomail) {
+ $result *= mySociety::EmailUtil::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), @recips);
+ }
}
+
+ if ($send_web) {
+ $h{message} = construct_easthants_message(%h);
+ if (!$nomail) {
+ $result *= post_easthants_message(%h);
+ }
+ }
+
if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) {
dbh()->do('UPDATE problem SET whensent=ms_current_timestamp(),
lastupdate=ms_current_timestamp() WHERE id=?', {}, $row->{id});
@@ -243,3 +262,42 @@ sub notts_contact {
die "Returned district $district which is not in Nottinghamshire!" unless $email;
return "$email\@nottscc.gov.uk";
}
+
+sub construct_easthants_message {
+ my %h = @_;
+ my $message = '';
+ $message .= "[ This report was also sent to the district council covering the location of the problem, as the user did not categorise it; please ignore if you're not the correct council to deal with the issue. ]\n\n"
+ if $h{multiple};
+ $message .= <<EOF;
+Subject: $h{title}
+
+Details: $h{detail}
+
+$h{fuzzy}, or to provide an update on the problem, please visit the following link:
+
+$h{url}
+
+$h{closest_address}
+EOF
+ return $message;
+}
+
+my $eh_service;
+sub post_easthants_message {
+ my %h = @_;
+ my $return = 1;
+ $eh_service ||= EastHantsWSDL->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; });
+ try {
+ # ServiceName, RemoteCreatedBy, Salutation, FirstName, Name, Email, Telephone, HouseNoName, Street, Town, County, Country, Postcode, Comments, FurtherInfo, ImageURL
+ my $result = $eh_service->INPUTFEEDBACK(
+ $h{category}, 'FixMyStreet', '', '', $h{name}, $h{email}, $h{phone},
+ '', '', '', '', '', '', $h{message}, 'Yes', $h{image_url}
+ );
+ $return = 0 if $result eq 'Report received';
+ } otherwise {
+ my $e = shift;
+ print "Caught an error: $e\n";
+ };
+ return $return;
+}
+
diff --git a/perllib/EastHantsWSDL.pm b/perllib/EastHantsWSDL.pm
new file mode 100644
index 000000000..d799f4025
--- /dev/null
+++ b/perllib/EastHantsWSDL.pm
@@ -0,0 +1,70 @@
+package EastHantsWSDL;
+
+# -- generated by SOAP::Lite (v0.60) for Perl -- soaplite.com -- Copyright (C) 2000-2001 Paul Kulchenko --
+# -- generated from http://www.easthants.gov.uk/forms.nsf/InputFeedback?WSDL [Thu Oct 16 12:31:57 2008]
+
+my %methods = (
+ INPUTFEEDBACK => {
+ endpoint => 'http://www.easthants.gov.uk:80/forms.nsf/InputFeedback?OpenWebService',
+ soapaction => 'INPUTFEEDBACK',
+ uri => 'urn:DefaultNamespace',
+ parameters => [
+ SOAP::Data->new(name => 'STRSERVICENAME', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRREMOTECREATEDBY', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRSALUTATION', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRFIRSTNAME', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRNAME', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STREMAIL', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRTELEPHONE', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRHOUSENONAME', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRSTREET', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRTOWN', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRCOUNTY', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRCOUNTRY', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRPOSTCODE', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRCOMMENTS', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRFURTHERINFO', type => 'xsd:string', attr => {}),
+ SOAP::Data->new(name => 'STRIMAGEURL', type => 'xsd:string', attr => {}),
+ ],
+ },
+);
+
+use SOAP::Lite; # +trace => [qw(debug)];
+use Exporter;
+use Carp ();
+
+use vars qw(@ISA $AUTOLOAD @EXPORT_OK %EXPORT_TAGS);
+@ISA = qw(Exporter SOAP::Lite);
+@EXPORT_OK = (keys %methods);
+%EXPORT_TAGS = ('all' => [@EXPORT_OK]);
+
+no strict 'refs';
+for my $method (@EXPORT_OK) {
+ my %method = %{$methods{$method}};
+ *$method = sub {
+ my $self = UNIVERSAL::isa($_[0] => __PACKAGE__)
+ ? ref $_[0] ? shift # OBJECT
+ # CLASS, either get self or create new and assign to self
+ : (shift->self || __PACKAGE__->self(__PACKAGE__->new))
+ # function call, either get self or create new and assign to self
+ : (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new));
+ $self->proxy($method{endpoint} || Carp::croak "No server address (proxy) specified") unless $self->proxy;
+ my @templates = @{$method{parameters}};
+ my $som = $self
+ -> endpoint($method{endpoint})
+ -> uri($method{uri})
+ -> on_action(sub{qq!"$method{soapaction}"!})
+ -> call($method => map {@templates ? shift(@templates)->value($_) : $_} @_);
+ UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall : $som->result
+ : $som;
+ }
+}
+
+sub AUTOLOAD {
+ my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2);
+ return if $method eq 'DESTROY';
+
+ die "Unrecognized method '$method'. List of available method(s): @EXPORT_OK\n";
+}
+
+1;
diff --git a/templates/emails/submit-brent b/templates/emails/submit-brent
index 1a4fff40d..c6d455e71 100644
--- a/templates/emails/submit-brent
+++ b/templates/emails/submit-brent
@@ -17,7 +17,7 @@ Name: <?=$values['name']?>
Email: <?=$values['email']?>
-<?=$values['phone']?><?=$values['category']?>Subject: <?=$values['title']?>
+<?=$values['phone_line']?><?=$values['category_line']?>Subject: <?=$values['title']?>
Details: <?=$values['detail']?>
diff --git a/templates/emails/submit-council b/templates/emails/submit-council
index 1a1db83bb..b30abd365 100644
--- a/templates/emails/submit-council
+++ b/templates/emails/submit-council
@@ -17,7 +17,7 @@ Name: <?=$values['name']?>
Email: <?=$values['email']?>
-<?=$values['phone']?><?=$values['category']?>Subject: <?=$values['title']?>
+<?=$values['phone_line']?><?=$values['category_line']?>Subject: <?=$values['title']?>
Details: <?=$values['detail']?>
diff --git a/templates/emails/submit-eha b/templates/emails/submit-eha
index ba6bfa1b3..ca2b9a205 100644
--- a/templates/emails/submit-eha
+++ b/templates/emails/submit-eha
@@ -28,7 +28,7 @@ Name: <?=$values['name']?>
Email: <?=$values['email']?>
-<?=$values['phone']?>Subject: <?=$values['title']?>
+<?=$values['phone_line']?>Subject: <?=$values['title']?>
Property type: <?=$values['category']?>