aboutsummaryrefslogtreecommitdiffstats
path: root/bin/send-reports
diff options
context:
space:
mode:
Diffstat (limited to 'bin/send-reports')
-rwxr-xr-xbin/send-reports46
1 files changed, 34 insertions, 12 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 9da9b6238..6254337c6 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -27,6 +27,7 @@ use mySociety::Config;
use mySociety::DBHandle qw(dbh);
use mySociety::Email;
use mySociety::EmailUtil;
+use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::MaPit;
use mySociety::Random qw(random_bytes);
@@ -49,10 +50,12 @@ my $base_url = mySociety::Config::get('BASE_URL');
my $site = CronFns::site($base_url);
my $query = "SELECT id, council, category, title, detail, name, email, phone,
- used_map, easting, northing, (photo is not null) as has_photo, lang,
+ used_map, latitude, longitude, (photo is not null) as has_photo, lang,
cobrand, cobrand_data
- FROM problem WHERE state in ('confirmed','fixed') AND whensent IS NULL
- AND council IS NOT NULL";
+ FROM problem
+ WHERE state in ('confirmed','fixed')
+ AND whensent IS NULL
+ AND council IS NOT NULL";
my $unsent = dbh()->selectall_arrayref($query, { Slice => {} });
my (%notgot, %note);
@@ -81,7 +84,7 @@ foreach my $row (@$unsent) {
# Template variables for the email
my $email_base_url = Cobrand::base_url_for_emails($cobrand, $cobrand_data);
- my %h = map { $_ => $row->{$_} } qw/title detail name email phone category easting northing/;
+ my %h = map { $_ => $row->{$_} } qw/title detail name email phone category latitude longitude/;
$h{url} = $email_base_url . '/report/' . $row->{id};
$h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : '';
if ($row->{has_photo}) {
@@ -95,6 +98,21 @@ foreach my $row (@$unsent) {
: _('The user could not locate the problem on a map, but to see the area around the location they entered');
$h{closest_address} = '';
$h{closest_address_machine} = '';
+
+ # If we are in the UK include eastings and northings
+ $h{easting_northing} = '';
+ if ( mySociety::Config::get('COUNTRY') eq 'GB' ) {
+
+ ( $h{easting}, $h{northing} ) =
+ mySociety::GeoUtil::wgs84_to_national_grid( #
+ $h{latitude}, $h{longitude}, 'G'
+ );
+
+ # email templates don't have conditionals so we need to farmat this here
+ $h{easting_northing} #
+ = "Easting: $h{easting}\n\n" #
+ . "Northing: $h{northing}\n\n";
+ }
my (@to, @recips, $template, $areas_info);
if ($site eq 'emptyhomes') {
@@ -137,8 +155,8 @@ foreach my $row (@$unsent) {
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 = oxfordshire_contact($row->{easting}, $row->{northing}) if $council == 2237 && $council_email eq 'SPECIAL';
+ $council_email = essex_contact($row->{latitude}, $row->{longitude}) if $council == 2225;
+ $council_email = oxfordshire_contact($row->{latitude}, $row->{longitude}) if $council == 2237 && $council_email eq 'SPECIAL';
unless ($confirmed) {
$all_confirmed = 0;
$note = 'Council ' . $row->{council} . ' deleted'
@@ -255,13 +273,19 @@ if ($verbose) {
}
}
+sub _get_district_for_contact {
+ my ( $lat, $lon ) = @_;
+ my $district =
+ mySociety::MaPit::call( 'point', "4326/$lon,$lat", type => 'DIS' );
+ ($district) = keys %$district;
+ return $district;
+}
+
# Essex has different contact addresses depending upon the district
# Might be easier if we start storing in the db all areas covered by a point
# Will do for now :)
sub essex_contact {
- my ($E, $N) = @_;
- my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS');
- ($district) = keys %$district;
+ my $district = _get_district_for_contact(@_);
my $email;
$email = 'eastarea' if $district == 2315 || $district == 2312;
$email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316;
@@ -273,9 +297,7 @@ sub essex_contact {
# Oxfordshire has different contact addresses depending upon the district
sub oxfordshire_contact {
- my ($E, $N) = @_;
- my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS');
- ($district) = keys %$district;
+ my $district = _get_district_for_contact(@_);
my $email;
$email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421;
$email = 'southernarea' if $district == 2417 || $district == 2418;