aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-alerts6
-rwxr-xr-xbin/send-questionnaires-eha19
-rwxr-xr-xbin/send-reports31
-rw-r--r--db/schema.sql5
-rwxr-xr-xperllib/CronFns.pm51
-rw-r--r--perllib/Page.pm7
-rwxr-xr-xweb/index.cgi14
-rwxr-xr-xweb/questionnaire.cgi9
8 files changed, 95 insertions, 47 deletions
diff --git a/bin/send-alerts b/bin/send-alerts
index ef272ae6f..f282efaaf 100755
--- a/bin/send-alerts
+++ b/bin/send-alerts
@@ -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-alerts,v 1.2 2007-06-15 14:57:51 matthew Exp $
+# $Id: send-alerts,v 1.3 2009-07-10 15:17:28 matthew Exp $
use strict;
require 5.8.0;
@@ -15,6 +15,7 @@ require 5.8.0;
use FindBin;
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../../perllib";
+use CronFns;
use mySociety::Config;
use mySociety::DBHandle qw(dbh);
@@ -31,5 +32,8 @@ BEGIN {
);
}
+my $site = CronFns::site(mySociey::Config::get('BASE_URL'));
+CronFns::language($site);
+
mySociety::Alert::email_alerts();
diff --git a/bin/send-questionnaires-eha b/bin/send-questionnaires-eha
index 4df5c293f..055db39f7 100755
--- a/bin/send-questionnaires-eha
+++ b/bin/send-questionnaires-eha
@@ -6,7 +6,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: send-questionnaires-eha,v 1.2 2009-05-27 15:27:18 matthew Exp $
+# $Id: send-questionnaires-eha,v 1.3 2009-07-10 15:17:28 matthew Exp $
use strict;
require 5.8.0;
@@ -16,12 +16,13 @@ use FindBin;
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../../perllib";
use File::Slurp;
+use CronFns;
-use Page;
use mySociety::AuthToken;
use mySociety::Config;
use mySociety::DBHandle qw(dbh select_all);
use mySociety::Email;
+use mySociety::Locale;
use mySociety::MaPit;
use mySociety::EmailUtil;
use mySociety::Random qw(random_bytes);
@@ -37,12 +38,10 @@ BEGIN {
);
}
-die "Either no arguments, --nomail or --verbose" if (@ARGV>1);
-my $nomail = 0;
-my $verbose = 0;
-$nomail = 1 if (@ARGV==1 && $ARGV[0] eq '--nomail');
-$verbose = 1 if (@ARGV==1 && $ARGV[0] eq '--verbose');
-$verbose = 1 if $nomail;
+# Set up site, language etc.
+my ($verbose, $nomail) = CronFns::options();
+my $site = CronFns::site(mySociety::Config::get('BASE_URL'))
+CronFns::language($site);
send_q('4 weeks');
send_q('26 weeks');
@@ -55,7 +54,7 @@ sub send_q {
(my $template = $period) =~ s/ //;
$template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/questionnaire-eha-$template");
- my $query = "select id, category, title, detail, name, email
+ my $query = "select id, category, title, detail, name, email, lang
from problem
where state in ('confirmed', 'fixed')
and whensent is not null
@@ -73,6 +72,8 @@ sub send_q {
foreach my $row (@$unsent) {
my %h = map { $_ => $row->{$_} } qw/name title detail category/;
+ mySociety::Locale::change($row->{lang});
+
my $id = dbh()->selectrow_array("select nextval('questionnaire_id_seq');");
dbh()->do('insert into questionnaire (id, problem_id, whensent)
values (?, ?, ms_current_timestamp())', {}, $id, $row->{id});
diff --git a/bin/send-reports b/bin/send-reports
index 458244310..723228fa6 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.69 2009-06-10 14:27:54 matthew Exp $
+# $Id: send-reports,v 1.70 2009-07-10 15:17:28 matthew Exp $
use strict;
require 5.8.0;
@@ -18,6 +18,7 @@ use lib "$FindBin::Bin/../../perllib";
use Error qw(:try);
use File::Slurp;
use CGI; # Trying awkward kludge
+use CronFns;
use EastHantsWSDL;
use mySociety::Config;
@@ -42,30 +43,14 @@ BEGIN {
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;
-my $verbose = 0;
-$nomail = 1 if (@ARGV==1 && $ARGV[0] eq '--nomail');
-$verbose = 1 if (@ARGV==1 && $ARGV[0] eq '--verbose');
-$verbose = 1 if $nomail;
-
+# Set up site, language etc.
+my ($verbose, $nomail) = CronFns::options();
my $base_url = mySociety::Config::get('BASE_URL');
-my $site = 'fixmystreet';
-$site = 'emptyhomes' if $base_url =~ 'emptyhomes';
-
-# First, let's pick the right language
-if ($site eq 'emptyhomes') {
- mySociety::Locale::negotiate_language('en-gb,English,en_GB|cy,Cymraeg,cy_GB');
- mySociety::Locale::gettext_domain('FixMyStreet-EmptyHomes');
- mySociety::Locale::change();
-} else {
- mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO'); # XXX Testing
- mySociety::Locale::gettext_domain('FixMyStreet');
- mySociety::Locale::change();
-}
+my $site = CronFns::site($base_url);
+CronFns::language($site);
my $query = "SELECT id, council, category, title, detail, name, email, phone,
- used_map, easting, northing, (photo is not null) as has_photo
+ used_map, easting, northing, (photo is not null) as has_photo, lang
FROM problem WHERE state in ('confirmed','fixed') AND whensent IS NULL
AND council IS NOT NULL";
my $unsent = dbh()->selectall_arrayref($query, { Slice => {} });
@@ -82,6 +67,8 @@ foreach my $row (@$unsent) {
my $send_email = 0;
my $send_web = 0;
+ mySociety::Locale::change($row->{lang});
+
# Template variables for the email
my %h = map { $_ => $row->{$_} } qw/title detail name email phone category easting northing/;
$h{url} = $base_url . '/report/' . $row->{id};
diff --git a/db/schema.sql b/db/schema.sql
index 95038b7d9..f4849448a 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.44 2009-03-10 12:25:10 matthew Exp $
+-- $Id: schema.sql,v 1.45 2009-07-10 15:17:28 matthew Exp $
--
-- secret
@@ -147,6 +147,7 @@ create table problem (
or state = 'hidden'
or state = 'partial'
),
+ lang text not null default 'en-gb',
service text not null default '',
lastupdate timestamp not null default ms_current_timestamp(),
whensent timestamp,
@@ -231,6 +232,7 @@ create table comment (
or state = 'confirmed'
or state = 'hidden'
),
+ lang text not null default 'en-gb',
mark_fixed boolean not null,
mark_open boolean not null default 'f'
-- other fields? one to indicate whether this was written by the council
@@ -274,6 +276,7 @@ create table alert (
parameter2 text, -- e.g. Latitude for local problem alerts
email text not null,
confirmed integer not null default 0,
+ lang text not null default 'en-gb',
whensubscribed timestamp not null default ms_current_timestamp(),
whendisabled timestamp default null
);
diff --git a/perllib/CronFns.pm b/perllib/CronFns.pm
new file mode 100755
index 000000000..f494ed022
--- /dev/null
+++ b/perllib/CronFns.pm
@@ -0,0 +1,51 @@
+#!/usr/bin/perl -w
+
+# CronFns.pm:
+# Shared functions for cron-run scripts
+#
+# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: CronFns.pm,v 1.1 2009-07-10 15:17:29 matthew Exp $
+
+package CronFns;
+
+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 mySociety::Locale;
+
+sub options {
+ die "Either no arguments, --nomail or --verbose" if (@ARGV>1);
+ my $nomail = 0;
+ my $verbose = 0;
+ $nomail = 1 if (@ARGV==1 && $ARGV[0] eq '--nomail');
+ $verbose = 1 if (@ARGV==1 && $ARGV[0] eq '--verbose');
+ $verbose = 1 if $nomail;
+ return ($verbose, $nomail);
+}
+
+sub site {
+ my $base_url = shift;
+ my $site = 'fixmystreet';
+ $site = 'emptyhomes' if $base_url =~ 'emptyhomes';
+ return $site;
+}
+
+sub language {
+ my $site = shift;
+ if ($site eq 'emptyhomes') {
+ mySociety::Locale::negotiate_language('en-gb,English,en_GB|cy,Cymraeg,cy_GB');
+ mySociety::Locale::gettext_domain('FixMyStreet-EmptyHomes', 1);
+ } else {
+ mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO'); # XXX Testing
+ mySociety::Locale::gettext_domain('FixMyStreet', 1);
+ }
+}
+
+1;
diff --git a/perllib/Page.pm b/perllib/Page.pm
index b31d7762a..e2fc687ce 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.146 2009-07-10 12:37:52 matthew Exp $
+# $Id: Page.pm,v 1.147 2009-07-10 15:17:29 matthew Exp $
#
package Page;
@@ -18,7 +18,7 @@ use Error qw(:try);
use File::Slurp;
use HTTP::Date;
use Image::Magick;
-use Image::Size;
+#use Image::Size;
use LWP::Simple;
use Digest::MD5 qw(md5_hex);
use POSIX qw(strftime);
@@ -660,7 +660,8 @@ sub display_problem_text {
}
if ($problem->{photo}) {
- my $dims = Image::Size::html_imgsize(\$problem->{photo});
+ #my $dims = Image::Size::html_imgsize(\$problem->{photo});
+ my $dims = '';
$out .= "<p align='center'><img alt='' $dims src='/photo?id=$problem->{id}'></p>";
}
diff --git a/web/index.cgi b/web/index.cgi
index 65713f1c8..b8ef91cda 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.257 2009-07-06 17:10:21 matthew Exp $
+# $Id: index.cgi,v 1.258 2009-07-10 15:17:29 matthew Exp $
use strict;
use Standard;
@@ -235,10 +235,10 @@ sub submit_update {
my $id = dbh()->selectrow_array("select nextval('comment_id_seq');");
Utils::workaround_pg_bytea("insert into comment
- (id, problem_id, name, email, website, text, state, mark_fixed, photo)
- values (?, ?, ?, ?, '', ?, 'unconfirmed', ?, ?)", 7,
+ (id, problem_id, name, email, website, text, state, mark_fixed, photo, lang)
+ values (?, ?, ?, ?, '', ?, 'unconfirmed', ?, ?, ?)", 7,
$id, $input{id}, $input{name}, $input{rznvy}, $input{update},
- $input{fixed} ? 't' : 'f', $image);
+ $input{fixed} ? 't' : 'f', $image, $mySociety::Locale::lang);
my %h = ();
$h{update} = $input{update};
@@ -391,13 +391,13 @@ Please <a href="/contact">let us know what went on</a> and we\'ll look into it.'
$id = dbh()->selectrow_array("select nextval('problem_id_seq');");
Utils::workaround_pg_bytea("insert into problem
(id, postcode, easting, northing, title, detail, name,
- email, phone, photo, state, council, used_map, anonymous, category, areas)
+ email, phone, photo, state, council, used_map, anonymous, category, areas, lang)
values
- (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed', ?, ?, ?, ?, ?)", 10,
+ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed', ?, ?, ?, ?, ?, ?)", 10,
$id, $input{pc}, $input{easting}, $input{northing}, $input{title},
$input{detail}, $input{name}, $input{email}, $input{phone}, $image,
$input{council}, $used_map, $input{anonymous} ? 'f': 't', $input{category},
- $areas);
+ $areas, $mySociety::Locale::lang);
my %h = ();
$h{title} = $input{title};
$h{detail} = $input{detail};
diff --git a/web/questionnaire.cgi b/web/questionnaire.cgi
index fae205020..68a2f2310 100755
--- a/web/questionnaire.cgi
+++ b/web/questionnaire.cgi
@@ -6,13 +6,14 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: questionnaire.cgi,v 1.38 2009-05-27 13:53:53 matthew Exp $
+# $Id: questionnaire.cgi,v 1.39 2009-07-10 15:17:29 matthew Exp $
use strict;
use Standard;
use Error qw(:try);
use CrossSell;
use mySociety::AuthToken;
+use mySociety::Locale;
use mySociety::MaPit;
use mySociety::Web qw(ent);
@@ -129,11 +130,11 @@ sub submit_questionnaire {
my $name = $problem->{anonymous} ? undef : $problem->{name};
my $update = $input{update} ? $input{update} : _('Questionnaire filled in by problem reporter');
Utils::workaround_pg_bytea("insert into comment
- (problem_id, name, email, website, text, state, mark_fixed, mark_open, photo)
- values (?, ?, ?, '', ?, 'confirmed', ?, ?, ?)", 7,
+ (problem_id, name, email, website, text, state, mark_fixed, mark_open, photo, lang)
+ values (?, ?, ?, '', ?, 'confirmed', ?, ?, ?, ?)", 7,
$problem->{id}, $name, $problem->{email}, $update,
$new_state eq 'fixed' ? 't' : 'f', $new_state eq 'confirmed' ? 't' : 'f',
- $image
+ $image, $mySociety::Locale::lang
)
if $new_state || $input{update};