aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-questionnaires-eha111
-rw-r--r--perllib/Page.pm13
-rw-r--r--templates/emails/questionnaire-eha-26weeks4
-rw-r--r--templates/emails/questionnaire-eha-4weeks4
-rwxr-xr-xweb/about.cgi29
-rwxr-xr-xweb/questionnaire.cgi41
6 files changed, 189 insertions, 13 deletions
diff --git a/bin/send-questionnaires-eha b/bin/send-questionnaires-eha
new file mode 100755
index 000000000..f67e38116
--- /dev/null
+++ b/bin/send-questionnaires-eha
@@ -0,0 +1,111 @@
+#!/usr/bin/perl -w
+
+# send-questionnaires-eha:
+# Send out creator questionnaires
+#
+# 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.1 2008-10-09 18:21:17 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 Page;
+use mySociety::AuthToken;
+use mySociety::Config;
+use mySociety::DBHandle qw(dbh select_all);
+use mySociety::Email;
+use mySociety::MaPit;
+use mySociety::EmailUtil;
+use mySociety::Random qw(random_bytes);
+
+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)
+ );
+}
+
+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;
+
+send_q('4 weeks');
+send_q('26 weeks');
+
+# ---
+
+sub send_q {
+ my ($period) = @_;
+
+ (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
+ from problem
+ where state in ('confirmed', 'fixed')
+ and whensent is not null
+ and send_questionnaire = 't'
+ and whensent < ms_current_timestamp() - '$period'::interval
+ and ";
+ if ($period eq '4 weeks') {
+ $query .= '(select max(whensent) from questionnaire where problem.id=problem_id) is null';
+ } else {
+ $query .= '(select max(whensent) from questionnaire where problem.id=problem_id) is not null';
+ }
+ $query .= ' order by created desc';
+
+ my $unsent = select_all($query);
+ foreach my $row (@$unsent) {
+ my %h = map { $_ => $row->{$_} } qw/name title detail category/;
+
+ 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});
+ dbh()->do("update problem set send_questionnaire = 'f' where id=?", {}, $row->{id})
+ if $period eq '26 weeks';
+
+ my $token = mySociety::AuthToken::store('questionnaire', $id);
+ $h{url} = mySociety::Config::get('BASE_URL') . '/Q/' . $token;
+
+ my $sender = mySociety::Config::get('CONTACT_EMAIL');
+ my $email = mySociety::Email::construct_email({
+ _template_ => $template,
+ _parameters_ => \%h,
+ To => [ [ $row->{email}, $row->{name} ] ],
+ From => [ $sender, 'Empty Homes Agency' ],
+ 'Message-ID' => sprintf('<ques-%s-%s@emptyhomes.com>', time(), unpack('h*', random_bytes(5, 1))),
+ });
+
+ print "Sending questionnaire $id, problem $row->{id}, token $token to $row->{email}\n" if $verbose;
+
+ my $result;
+ if ($nomail) {
+ $result = -1;
+ } else {
+ $result = mySociety::EmailUtil::send_email($email, $sender, $row->{email});
+ }
+ if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) {
+ print " ...success\n" if $verbose;
+ dbh()->commit();
+ } else {
+ print " ...failed\n" if $verbose;
+ dbh()->rollback();
+ }
+ }
+}
+
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 4605c1c2e..f94e2c2bb 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.115 2008-10-09 14:20:54 matthew Exp $
+# $Id: Page.pm,v 1.116 2008-10-09 18:21:17 matthew Exp $
#
package Page;
@@ -577,9 +577,14 @@ sub display_problem_text {
my $out = $q->h1(ent($problem->{title}));
# Display information about problem
- $out .= '<p><em>Reported ';
- $out .= 'in the ' . ent($problem->{category}) . ' category '
- if $problem->{category} && $problem->{category} ne 'Other';
+ $out .= '<p><em>';
+ if ($q->{site} eq 'emptyhomes') {
+ $out .= ent($problem->{category}) . ', reported ';
+ } else {
+ $out .= 'Reported ';
+ $out .= 'in the ' . ent($problem->{category}) . ' category '
+ if $problem->{category} && $problem->{category} ne 'Other';
+ }
$out .= ($problem->{anonymous}) ? 'anonymously' : "by " . ent($problem->{name});
$out .= ' at ' . prettify_epoch($problem->{time});
$out .= '; the map was not used so pin location may be inaccurate' unless ($problem->{used_map});
diff --git a/templates/emails/questionnaire-eha-26weeks b/templates/emails/questionnaire-eha-26weeks
index f10e8461b..4151a9ae3 100644
--- a/templates/emails/questionnaire-eha-26weeks
+++ b/templates/emails/questionnaire-eha-26weeks
@@ -2,7 +2,7 @@ Subject: Questionnaire about your empty property report
Hi <?=$values['name']?>,
-Four weeks ago, you reported an empty home on ReportEmptyHomes.com with the
+Six months ago, you reported an empty home on ReportEmptyHomes.com with the
details provided at the end of this email. To keep our site up to date and
relevant, I'd be grateful if you could fill in this short questionnaire to tell
us what has happened:
@@ -19,5 +19,7 @@ Your report was as follows:
<?=$values['title']?>
+Property type: <?=$values['category']?>
+
<?=$values['detail']?>
diff --git a/templates/emails/questionnaire-eha-4weeks b/templates/emails/questionnaire-eha-4weeks
index a17238452..d4a29666d 100644
--- a/templates/emails/questionnaire-eha-4weeks
+++ b/templates/emails/questionnaire-eha-4weeks
@@ -2,7 +2,7 @@ Subject: Questionnaire about your empty property report
Hi <?=$values['name']?>,
-Six months ago, you reported an empty home on ReportEmptyHomes.com with the
+Four weeks ago, you reported an empty home on ReportEmptyHomes.com with the
details provided at the end of this email. To keep our site up to date and
relevant, I'd be grateful if you could fill in this short questionnaire to tell
us what has happened:
@@ -19,5 +19,7 @@ Your report was as follows:
<?=$values['title']?>
+Property type: <?=$values['category']?>
+
<?=$values['detail']?>
diff --git a/web/about.cgi b/web/about.cgi
new file mode 100755
index 000000000..3d0dcc6fa
--- /dev/null
+++ b/web/about.cgi
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w -I../perllib
+
+# about.cgi:
+# For EHA
+#
+# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: about.cgi,v 1.6 2008-10-09 18:21:18 matthew Exp $
+
+use strict;
+use Standard -db;
+
+# Main code for index.cgi
+sub main {
+ my $q = shift;
+ print Page::header($q, title=>'About us');
+ print <<ABOUTUS if $q->{site} eq 'emptyhomes';
+<p>The Empty Homes agency is an independent campaigning charity. We are not
+part of government, and have no formal links with local councils although we
+work in cooperation with both. We exist to highlight the waste of empty
+property and work with others to devise and promote sustainable solutions to
+bring empty property back into use. We are based in London but work across
+England. We also work in partnership with other charities across the UK.</p>
+ABOUTUS
+ print Page::footer($q);
+}
+Page::do_fastcgi(\&main);
+
diff --git a/web/questionnaire.cgi b/web/questionnaire.cgi
index 43868ad8e..332b56cd6 100755
--- a/web/questionnaire.cgi
+++ b/web/questionnaire.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: questionnaire.cgi,v 1.32 2008-10-09 14:20:54 matthew Exp $
+# $Id: questionnaire.cgi,v 1.33 2008-10-09 18:21:18 matthew Exp $
use strict;
use Standard;
@@ -200,17 +200,42 @@ sub display_questionnaire {
<h1>Questionnaire</h1>
<form method="post" action="/questionnaire" id="questionnaire" enctype="multipart/form-data">
<input type="hidden" name="token" value="$input_h{token}">
-
-<p>The details of your problem are available on the right hand side of this page.
EOF
- $out .= 'Please take a look at the updates that have been left.' if $updates;
+ if ($q->{site} eq 'emptyhomes') {
+ if (!$prev_questionnaire) {
+ $out .= <<EOF;
+<p>Getting empty homes back into use can be difficult. You shouldn't expect
+the property to be back into use yet. But a good council will have started work
+and should have reported what they have done on the website. If you are not
+satisfied with progress or information from the council, now is the right time
+to say. You may also want to try contacting some other people who may be able
+to help. For advice on how to do this and other useful information please
+go to <a href="http://www.emptyhomes.com/getinvolved/campaign.html">http://www.emptyhomes.com/getinvolved/campaign.html</a>.</p>
+EOF
+ } else {
+ $out .= <<EOF;
+<p>Getting empty homes back into use can be difficult, but by now a good council
+will have made a lot of progress and reported what they have done on the
+website. Even so properties can remain empty for many months if the owner is
+unwilling or the property is in very poor repair. If nothing has happened or
+you are not satisfied with the progress the council is making, now is the right
+time to say so. We think it's a good idea to contact some other people who
+may be able to help or put pressure on the council For advice on how to do
+this and other useful information please go to <a
+href="http://www.emptyhomes.com/getinvolved/campaign.html">http://www.emptyhomes.com/getinvolved/campaign.html</a>.</p>
+EOF
+ }
+ }
+
+ $out .= '<p>The details of your problem are available on the right hand side of this page.';
+ $out .= ' Please take a look at the updates that have been left.' if $updates;
$out .= '</p>';
if (@errors) {
$out .= '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>';
}
$out .= '<p>';
$out .= 'An update marked this problem as fixed. ' if $problem->{state} eq 'fixed';
- $out .= 'Has this problem been fixed?</p>';
+ $out .= _('Has this problem been fixed?') . '</p>';
$out .= <<EOF;
<p>
<input type="radio" name="been_fixed" id="been_fixed_yes" value="Yes"$been_fixed{yes}>
@@ -246,7 +271,8 @@ your experience of getting the problem fixed?</p>
<label for="form_photo">Photo:</label>
<input type="file" name="photo" id="form_photo">
</div>
-
+EOF
+ $out .= <<EOF if $q->{site} ne 'emptyhomes';
<div id="another_qn">
<p>Would you like to receive another questionnaire in 4 weeks, reminding you to check the status?</p>
<p>
@@ -256,7 +282,8 @@ your experience of getting the problem fixed?</p>
<label for="another_no">No</label>
</p>
</div>
-
+EOF
+ $out .= <<EOF;
<p align="right"><input type="submit" name="submit" value="Submit questionnaire"></p>
</form>
EOF