diff options
-rwxr-xr-x | web-admin/index.cgi | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/web-admin/index.cgi b/web-admin/index.cgi index 9c865a3f1..ef7e75977 100755 --- a/web-admin/index.cgi +++ b/web-admin/index.cgi @@ -7,10 +7,10 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: index.cgi,v 1.20 2007-03-26 16:55:31 matthew Exp $ +# $Id: index.cgi,v 1.21 2007-03-27 14:50:07 matthew Exp $ # -my $rcsid = ''; $rcsid .= '$Id: index.cgi,v 1.20 2007-03-26 16:55:31 matthew Exp $'; +my $rcsid = ''; $rcsid .= '$Id: index.cgi,v 1.21 2007-03-27 14:50:07 matthew Exp $'; use strict; @@ -192,6 +192,9 @@ sub do_councils_list ($) { sub do_council_contacts ($$) { my ($q, $area_id) = @_; + my $bci_data = select_all("select * from contacts where area_id = ? order by category", $area_id); + my $mapit_data = mySociety::MaPit::get_voting_area_info($area_id); + # Submit form my $updated = ''; if ($q->param('posted') eq 'new') { @@ -226,27 +229,42 @@ sub do_council_contacts ($$) { dbh()->commit(); } elsif ($q->param('posted') eq 'update') { my @cats = $q->param('confirmed'); - foreach my $cat (@cats) { - my $update = dbh()->do("update contacts set - confirmed = 't', editor = ?, - whenedited = ms_current_timestamp(), - note = 'Confirmed' - where area_id = ? - and category = ? - ", {}, - ($q->remote_user() || "*unknown*"), - $area_id, $cat - ); + my %cats = map { $_ => 1 } @cats; + foreach my $l (@$bci_data) { + my $cat = $l->{category}; + my $confirmed = $l->{confirmed}; + if ($cats{$cat} && !$confirmed) { + $l->{confirmed} = 1; + dbh()->do("update contacts set + confirmed = 't', editor = ?, + whenedited = ms_current_timestamp(), + note = 'Confirmed' + where area_id = ? + and category = ? + ", {}, + ($q->remote_user() || "*unknown*"), + $area_id, $cat + ); + } elsif (!$cats{$cat} && $confirmed) { + $l->{confirmed} = undef; + dbh()->do("update contacts set + confirmed = 'f', editor = ?, + whenedited = ms_current_timestamp(), + note = 'Unconfirmed' + where area_id = ? + and category = ? + ", {}, + ($q->remote_user() || "*unknown*"), + $area_id, $cat + ); + } } $updated = $q->p($q->em("Values updated")); dbh()->commit(); } - my $bci_data = select_all("select * from contacts where area_id = ? order by category", $area_id); - my $mapit_data = mySociety::MaPit::get_voting_area_info($area_id); - # Title - my $title = 'Council contact for ' . $mapit_data->{name}; + my $title = 'Council contacts for ' . $mapit_data->{name}; print html_head($q, $title); print $q->h2($title); print $updated; @@ -321,7 +339,7 @@ sub do_council_edit ($$$) { my $mapit_data = mySociety::MaPit::get_voting_area_info($area_id); # Title - my $title = 'Council contact for ' . $mapit_data->{name}; + my $title = 'Council contacts for ' . $mapit_data->{name}; print html_head($q, $title); print $q->h2($title); |