diff options
Diffstat (limited to 'web/import.cgi')
-rwxr-xr-x | web/import.cgi | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/web/import.cgi b/web/import.cgi index 2aede1697..371e70f7a 100755 --- a/web/import.cgi +++ b/web/import.cgi @@ -13,16 +13,14 @@ use Error qw(:try); use Standard; use Utils; use mySociety::AuthToken; +use mySociety::Config; use mySociety::EmailUtil; -use mySociety::EvEl; sub main { my $q = shift; my @vars = qw(service subject detail name email phone easting northing lat lon id phone_id); my %input = map { $_ => $q->param($_) || '' } @vars; - $input{easting} ||= 0; - $input{northing} ||= 0; my @errors; unless ($ENV{REQUEST_METHOD} eq 'POST') { @@ -32,6 +30,18 @@ sub main { return; } + # If we were given easting, northing convert to lat lon now + my $latitude = $input{lat} ||= 0; + my $longitude = $input{lon} ||= 0; + if ( + !( $latitude || $longitude ) # have not been given lat or lon + && ( $input{easting} && $input{northing} ) # but do have e and n + ) + { + ( $latitude, $longitude ) = + Utils::convert_en_to_latlon( $input{easting}, $input{northing}); + } + my $fh = $q->upload('photo'); # MUST come before $q->header, don't know why! print $q->header(-charset => 'utf-8', -content_type => 'text/plain'); @@ -50,14 +60,15 @@ sub main { push @errors, 'Please enter a valid email'; } - if ($input{lat}) { + if ( $latitude && mySociety::Config::get('COUNTRY') eq 'GB' ) { try { - ($input{easting}, $input{northing}) = mySociety::GeoUtil::wgs84_to_national_grid($input{lat}, $input{lon}, 'G'); - } catch Error::Simple with { + Utils::convert_latlon_to_en( $latitude, $longitude ); + } catch Error::Simple with { my $e = shift; push @errors, "We had a problem with the supplied co-ordinates - outside the UK?"; }; } + # TODO: Get location from photo if present in EXIF data? my $photo; @@ -70,7 +81,7 @@ sub main { }; } - unless ($photo || ($input{easting} && $input{northing})) { + unless ( $photo || ( $latitude || $longitude ) ) { push @errors, 'Either a location or a photo must be provided.'; } @@ -92,30 +103,23 @@ sub main { # Store what we have so far in the database my $id = dbh()->selectrow_array("select nextval('problem_id_seq')"); Utils::workaround_pg_bytea("insert into problem - (id, postcode, easting, northing, title, detail, name, service, + (id, postcode, latitude, longitude, title, detail, name, service, email, phone, photo, state, used_map, anonymous, category, areas) values (?, '', ?, ?, ?, ?, ?, ?, ?, ?, ?, 'partial', 't', 'f', '', '')", 10, - $id, $input{easting}, $input{northing}, $input{subject}, + $id, $latitude, $longitude, $input{subject}, $input{detail}, $input{name}, $input{service}, $input{email}, $input{phone}, $photo); - # Send checking email - my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/partial"); my $token = mySociety::AuthToken::store('partial', $id); my %h = ( name => $input{name} ? ' ' . $input{name} : '', - url => mySociety::Config::get('BASE_URL') . '/L/' . $token, + url => Page::base_url_with_lang($q, undef, 1) . '/L/' . $token, service => $input{service}, + title => $input{title}, + detail => $input{detail}, ); - my $sender = mySociety::Config::get('CONTACT_EMAIL'); - $sender =~ s/team/fms-DO-NOT-REPLY/; - mySociety::EvEl::send({ - _template_ => $template, - _parameters_ => \%h, - To => $input{name} ? [ [ $input{email}, $input{name} ] ] : $input{email}, - From => [ $sender, 'FixMyStreet' ], - }, $input{email}); + Page::send_email($q, $input{email}, $input{name}, 'partial', %h); dbh()->commit(); print 'SUCCESS'; |