aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rwxr-xr-xweb/confirm.cgi69
-rw-r--r--web/css.css4
-rwxr-xr-xweb/index.cgi67
3 files changed, 129 insertions, 11 deletions
diff --git a/web/confirm.cgi b/web/confirm.cgi
new file mode 100755
index 000000000..29f0b7c98
--- /dev/null
+++ b/web/confirm.cgi
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+
+# confirm.cgi:
+# Confirmation code for Neighbourhood Fix-It
+#
+# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: confirm.cgi,v 1.1 2006-09-25 22:59:07 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 Page;
+use mySociety::AuthToken;
+use mySociety::Config;
+use mySociety::DBHandle qw(dbh select_all);
+
+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)
+ );
+}
+
+sub main {
+ my $q = shift;
+
+ my $out = '';
+ my $token = $q->param('token');
+ my $type = $q->param('type');
+ my $id = mySociety::AuthToken::retrieve($type, $token);
+ if ($id) {
+ if ($type eq 'comment') {
+ dbh()->do("update comment set state='confirmed' where id=?", {}, $id);
+ my $id = dbh()->selectrow_array("select problem_id from comment where id=?", {}, $id);
+ $out = <<EOF;
+<p>You have successfully confirmed your comment and you can now <a href="/?id=$id">view it on the site</a>.</p>
+EOF
+ } elsif ($type eq 'problem') {
+ dbh()->do("update problem set state='confirmed' where id=?", {}, $id);
+ $out = <<EOF;
+<p>You have successfully confirmed your problem and you can now <a href="/?id=$id">view it on the site</a>.</p>
+EOF
+ }
+ dbh()->commit();
+ } else {
+ $out = <<EOF;
+<p>Thank you for trying to confirm your comment or problem. We seem to have a
+problem ourselves though, so <a href="/contact">please let us know what went on</a>
+and we'll look into it.
+EOF
+ }
+
+ print Page::header($q, 'Confirmation');
+ print $out;
+ print Page::footer();
+}
+Page::do_fastcgi(\&main);
+
diff --git a/web/css.css b/web/css.css
index 742b68768..d8594d47f 100644
--- a/web/css.css
+++ b/web/css.css
@@ -185,3 +185,7 @@ ul#current img {
position: absolute;
border: none;
}
+
+#comments div em {
+ border-bottom: dotted 1px #968d63;
+}
diff --git a/web/index.cgi b/web/index.cgi
index 6570307a3..fdd670520 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,10 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.24 2006-09-25 18:39:54 matthew Exp $
+# $Id: index.cgi,v 1.25 2006-09-25 22:59:07 matthew Exp $
+
+# TODO
+# Nothing is done about the update checkboxes - not stored anywhere on anything!
use strict;
require 5.8.0;
@@ -16,14 +19,17 @@ use FindBin;
use lib "$FindBin::Bin/../perllib";
use lib "$FindBin::Bin/../../perllib";
use Error qw(:try);
+use File::Slurp;
use LWP::Simple;
use RABX;
use POSIX qw(strftime);
use CGI::Carp;
use Page;
+use mySociety::AuthToken;
use mySociety::Config;
use mySociety::DBHandle qw(dbh select_all);
+use mySociety::Email;
use mySociety::Util;
use mySociety::MaPit;
use mySociety::Web qw(ent NewURL);
@@ -54,8 +60,10 @@ sub main {
my $out = '';
my $title = '';
if ($q->param('submit_problem')) {
+ $title = 'Submitting your problem';
$out = submit_problem($q);
} elsif ($q->param('submit_comment')) {
+ $title = 'Submitting your comment';
$out = submit_comment($q);
} elsif ($q->param('map')) {
$title = 'Reporting a problem';
@@ -117,13 +125,30 @@ sub submit_comment {
push(@errors, 'Please enter your email') unless $input{email};
return display_problem($q, @errors) if (@errors);
+ my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/comment-confirm");
+
+ my $id = dbh()->selectrow_array("select nextval('comment_id_seq');");
dbh()->do("insert into comment
- (problem_id, name, email, website, text, state)
- values (?, ?, ?, ?, ?, 'unconfirmed')", {},
- $input{id}, $input{name}, $input{email}, '', $input{comment});
+ (id, problem_id, name, email, website, text, state)
+ values (?, ?, ?, ?, ?, ?, 'unconfirmed')", {},
+ $id, $input{id}, $input{name}, $input{email}, '', $input{comment});
+ my %h = ();
+ $h{comment} = $input{comment};
+ $h{name} = $input{name};
+ $h{url} = mySociety::Config::get('BASE_URL') . '/C/' . mySociety::AuthToken::store('comment', $id);
dbh()->commit();
- # Send confirmation email
+ my $email = mySociety::Email::construct_email({
+ _template_ => $template,
+ _parameters_ => \%h,
+ From => [mySociety::Config::get('CONTACT_EMAIL'), 'Heighbourhood Fix-It'],
+ To => [[$input{email}, $input{name}]],
+ });
+ my $result = mySociety::Util::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), $input{email});
+ if ($result == mySociety::Util::EMAIL_SUCCESS) {
+ } elsif ($result == mySociety::Util::EMAIL_SOFT_ERROR) {
+ } else {
+ }
my $out = <<EOF;
<h1>Nearly Done! Now check your email...</h1>
@@ -147,6 +172,9 @@ sub submit_problem {
push(@errors, 'Please enter your email') unless $input{email};
return display_form($q, @errors) if (@errors);
+ my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/problem-confirm");
+
+ my $id = dbh()->selectrow_array("select nextval('problem_id_seq');");
dbh()->do("insert into problem
(postcode, easting, northing, title, detail, name, email, state)
values
@@ -154,9 +182,24 @@ sub submit_problem {
$input{pc}, $input{easting}, $input{northing}, $input{title},
$input{detail}, $input{name}, $input{email}
);
+ my %h = ();
+ $h{title} = $input{title};
+ $h{detail} = $input{detail};
+ $h{name} = $input{name};
+ $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id);
dbh()->commit();
- # Send confirmation email
+ my $email = mySociety::Email::construct_email({
+ _template_ => $template,
+ _parameters_ => \%h,
+ From => [mySociety::Config::get('CONTACT_EMAIL'), 'Heighbourhood Fix-It'],
+ To => [[$input{email}, $input{name}]],
+ });
+ my $result = mySociety::Util::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), $input{email});
+ if ($result == mySociety::Util::EMAIL_SUCCESS) {
+ } elsif ($result == mySociety::Util::EMAIL_SOFT_ERROR) {
+ } else {
+ }
my $out = <<EOF;
<h1>Nearly Done! Now check your email...</h1>
@@ -367,20 +410,22 @@ sub display_problem {
# Display comments
my $comments = select_all(
- "select id, name, whenposted, text
+ "select id, name, extract(epoch from whenposted) as whenposted, text
from comment where problem_id = ? and state='confirmed'
order by whenposted desc", $input{id});
if (@$comments) {
- $out .= '<h3>Comments</h3>';
+ $out .= '<div id="comments"> <h3>Comments</h3>';
foreach my $row (@$comments) {
- $out .= "$row->{name} $row->{text}";
+ $out .= "<div><em>Posted by $row->{name} at " . prettify_epoch($row->{whenposted}) . '</em>';
+ $out .= '<br>' . $row->{text} . '</div>';
}
+ $out .= '</div>';
}
$out .= '<h3>Add Comment</h3>';
if (@errors) {
$out .= '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>';
}
- my $updates = $input{updates} ? ' checked' : '';
+ my $updates = (!defined($q->param('updates')) || $input{updates}) ? ' checked' : '';
# XXX: Should we have website too?
$out .= <<EOF;
<form method="post" action="./">
@@ -450,7 +495,7 @@ EOF
sub display_map_end {
my ($type) = @_;
- my $out = '</div></div>';
+ my $out = '</div>';
$out .= '</form>' if ($type);
return $out;
}