aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Cobrands/Emptyhomes/Util.pm2
-rw-r--r--perllib/Cobrands/Fiksgatami/Util.pm2
-rw-r--r--perllib/Page.pm16
-rwxr-xr-xweb-admin/index.cgi42
-rwxr-xr-xweb/index.cgi8
-rwxr-xr-xweb/reports.cgi106
6 files changed, 112 insertions, 64 deletions
diff --git a/perllib/Cobrands/Emptyhomes/Util.pm b/perllib/Cobrands/Emptyhomes/Util.pm
index 00502eae9..d23857f50 100644
--- a/perllib/Cobrands/Emptyhomes/Util.pm
+++ b/perllib/Cobrands/Emptyhomes/Util.pm
@@ -34,7 +34,7 @@ sub admin_base_url {
}
sub area_types {
- return [qw(DIS LBO MTD UTA LGD COI)]; # No CTY
+ return qw(DIS LBO MTD UTA LGD COI); # No CTY
}
=item set_lang_and_domain LANG UNICODE
diff --git a/perllib/Cobrands/Fiksgatami/Util.pm b/perllib/Cobrands/Fiksgatami/Util.pm
index a0374cf1a..9fb448be5 100644
--- a/perllib/Cobrands/Fiksgatami/Util.pm
+++ b/perllib/Cobrands/Fiksgatami/Util.pm
@@ -35,7 +35,7 @@ sub disambiguate_location {
}
sub area_types {
- return [ 'NKO', 'NFY' ];
+ return ( 'NKO', 'NFY' );
}
sub area_min_generation {
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 886c8d994..4281e584b 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -51,6 +51,8 @@ my $lastmodified;
sub do_fastcgi {
my ($func, $lm) = @_;
+ binmode(STDOUT, ":utf8");
+
try {
my $W = new mySociety::WatchUpdate();
while (my $q = new mySociety::Web()) {
@@ -111,7 +113,7 @@ sub microsite {
my $lang;
$lang = 'cy' if $host =~ /cy/;
$lang = 'en-gb' if $host =~ /^en\./;
- Cobrand::set_lang_and_domain(get_cobrand($q), $lang);
+ Cobrand::set_lang_and_domain(get_cobrand($q), $lang, 1);
Problems::set_site_restriction($q);
Memcached::set_namespace(mySociety::Config::get('BCI_DB_NAME') . ":");
@@ -675,10 +677,16 @@ sub mapit_check_error {
}
sub short_name {
- my $name = shift;
+ my ($area, $info) = @_;
# Special case Durham as it's the only place with two councils of the same name
- return 'Durham+County' if ($name eq 'Durham County Council');
- return 'Durham+City' if ($name eq 'Durham City Council');
+ # And some places in Norway
+ return 'Durham+County' if $area->{name} eq 'Durham County Council';
+ return 'Durham+City' if $area->{name} eq 'Durham City Council';
+ if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) {
+ my $parent = $info->{$area->{parent_area}}->{name};
+ return "$area->{name},+$parent";
+ }
+ my $name = $area->{name};
$name =~ s/ (Borough|City|District|County) Council$//;
$name =~ s/ Council$//;
$name =~ s/ & / and /;
diff --git a/web-admin/index.cgi b/web-admin/index.cgi
index 1044f07c5..be37a479b 100755
--- a/web-admin/index.cgi
+++ b/web-admin/index.cgi
@@ -177,22 +177,25 @@ sub admin_summary ($) {
sub admin_councils_list ($) {
my ($q) = @_;
- print html_head($q, "Council contacts");
- print $q->h1("Council contacts");
+ print html_head($q, _("Council contacts"));
+ print $q->h1(_("Council contacts"));
# Table of editors
- print $q->h2("Diligency prize league table");
+ print $q->h2(_("Diligency prize league table"));
my $edit_activity = dbh()->selectall_arrayref("select count(*) as c, editor from contacts_history group by editor order by c desc");
- print $q->ul(
- map { $q->li($_->[0] . " edits by " . $_->[1]) } @$edit_activity
- );
+ if (@$edit_activity) {
+ print $q->ul(
+ map { $q->li($_->[0] . " edits by " . $_->[1]) } @$edit_activity
+ );
+ } else {
+ print $q->p(_('No edits have yet been made.'));
+ }
# Table of councils
- print $q->h2("Councils");
- my $ignore = 'LGD';
- $ignore .= '|CTY' if $q->{site} eq 'emptyhomes';
- my @types = grep { !/$ignore/ } @$mySociety::VotingArea::council_parent_types; # LGD are NI councils
- my $areas = mySociety::MaPit::call('areas', \@types);
+ print $q->h2(_("Councils"));
+ my $cobrand = Page::get_cobrand($q);
+ my @area_types = Cobrand::area_types($cobrand);
+ my $areas = mySociety::MaPit::call('areas', \@area_types);
my @councils_ids = sort { $areas->{$a}->{name} cmp $areas->{$b}->{name} } keys %$areas;
my $bci_info = dbh()->selectall_hashref("
select area_id, count(*) as c, count(case when deleted then 1 else null end) as deleted,
@@ -205,14 +208,19 @@ sub admin_councils_list ($) {
print "None";
return;
}
- print $q->p(join($q->br(),
- map {
- $q->a({ href => NewURL($q, area_id => $_, page => 'councilcontacts') },
- $areas->{$_}->{name}) . " " .
+ my @li;
+ foreach (@ids) {
+ my $parent = '';
+ $parent = ', ' . $areas->{$areas->{$_}->{parent_area}}->{name}
+ if $areas->{$_}->{parent_area};
+
+ push @li, $q->li($q->a({ href => NewURL($q, area_id => $_, page => 'councilcontacts') },
+ $areas->{$_}->{name}) . $parent .
($bci_info->{$_} && $q->{site} ne 'emptyhomes' ?
$bci_info->{$_}->{c} . ' addresses'
- : '')
- } @ids));
+ : ''));
+ }
+ print $q->ul(@li);
};
print $q->h3('No info at all');
diff --git a/web/index.cgi b/web/index.cgi
index ca2795eaa..7b829ae32 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -325,8 +325,8 @@ sub submit_problem {
$areas = mySociety::MaPit::call( 'point', $mapit_query );
if ($input{council} =~ /^[\d,]+(\|[\d,]+)?$/) {
my $no_details = $1 || '';
- my $area_types = Cobrand::area_types($cobrand);
- my %va = map { $_ => 1 } @$area_types;
+ my @area_types = Cobrand::area_types($cobrand);
+ my %va = map { $_ => 1 } @area_types;
my %councils;
foreach (keys %$areas) {
$councils{$_} = 1 if $va{$areas->{$_}->{type}};
@@ -517,9 +517,9 @@ sub display_form {
}
# Look up councils and do checks for the point we've got
- my $area_types = Cobrand::area_types($cobrand);
+ my @area_types = Cobrand::area_types($cobrand);
# XXX: I think we want in_gb_locale around the next line, needs testing
- my $all_councils = mySociety::MaPit::call('point', "4326/$longitude,$latitude", type => $area_types);
+ my $all_councils = mySociety::MaPit::call('point', "4326/$longitude,$latitude", type => \@area_types);
# Let cobrand do a check
my ($success, $error_msg) = Cobrand::council_check($cobrand, { all_councils => $all_councils }, $q, 'submit_problem');
diff --git a/web/reports.cgi b/web/reports.cgi
index 8dc0bd452..3ac22b0ce 100755
--- a/web/reports.cgi
+++ b/web/reports.cgi
@@ -41,24 +41,46 @@ sub main {
print $q->redirect($base_url . '/reports');
return;
}
- $area_name = Page::short_name($va_info->{name});
+ $area_name = Page::short_name($va_info);
if (length($q_council) == 6) {
$va_info = mySociety::MaPit::call('area', $va_info->{parent_area});
- $area_name = Page::short_name($va_info->{name}) . '/' . $area_name;
+ $area_name = Page::short_name($va_info) . '/' . $area_name;
}
$rss = '/rss' if $rss;
print $q->redirect($base_url . $rss . '/reports/' . $area_name);
return;
+ } elsif (mySociety::Config::get('COUNTRY') eq 'NO' && $q_council =~ /,/) {
+ my ($kommune, $fylke) = split /\s*,\s*/, $q_council;
+ my @area_types = Cobrand::area_types($cobrand);
+ my $areas_k = mySociety::MaPit::call('areas', $kommune, type => \@area_types);
+ my $areas_f = mySociety::MaPit::call('areas', $fylke, type => \@area_types);
+ if (keys %$areas_f == 1) {
+ ($fylke) = values %$areas_f;
+ $kommune = decode_utf8($kommune);
+ foreach (values %$areas_k) {
+ if ($_->{name} eq $kommune && $_->{parent_area} == $fylke->{id}) {
+ $one_council = $_;
+ $area_type = $_->{type};
+ $area_name = $_->{name};
+ last;
+ }
+ }
+ }
+ if (!$one_council) { # Given a false council name
+ print $q->redirect($base_url . '/reports');
+ return;
+ }
} elsif ($q_council =~ /\D/) {
- my $areas = mySociety::MaPit::call('areas', $q_council, type => Cobrand::area_types($cobrand), min_generation=>Cobrand::area_min_generation($cobrand) );
+ my @area_types = Cobrand::area_types($cobrand);
+ my $areas = mySociety::MaPit::call('areas', $q_council, type => \@area_types, min_generation=>Cobrand::area_min_generation($cobrand) );
if (keys %$areas == 1) {
- ($one_council) = keys %$areas;
- $area_type = $areas->{$one_council}->{type};
- $area_name = $areas->{$one_council}->{name};
+ ($one_council) = values %$areas;
+ $area_type = $one_council->{type};
+ $area_name = $one_council->{name};
} else {
foreach (keys %$areas) {
if ($areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/) {
- $one_council = $_;
+ $one_council = $areas->{$_};
$area_type = $areas->{$_}->{type};
$area_name = $q_council;
}
@@ -74,8 +96,7 @@ sub main {
print $q->redirect($base_url . '/reports');
return;
}
- $area_name = $va_info->{name};
- print $q->redirect($base_url . '/reports/' . Page::short_name($area_name));
+ print $q->redirect($base_url . '/reports/' . Page::short_name($va_info));
return;
}
$all = 0 unless $one_council;
@@ -87,21 +108,21 @@ sub main {
my $qw = mySociety::MaPit::call('areas', $q_ward, type => $mySociety::VotingArea::council_child_types,
min_generation => Cobrand::area_min_generation($cobrand));
foreach my $id (sort keys %$qw) {
- if ($qw->{$id}->{parent_area} == $one_council) {
- $ward = $id;
+ if ($qw->{$id}->{parent_area} == $one_council->{id}) {
+ $ward = $qw->{$id};
last;
}
}
if (!$ward) { # Given a false ward name
- print $q->redirect($base_url . '/reports/' . Page::short_name($q_council));
+ print $q->redirect($base_url . '/reports/' . Page::short_name($one_council));
return;
}
}
# RSS - reports for sent reports, area for all problems in area
if ($rss && $one_council) {
- my $url = Page::short_name($q_council);
- $url .= '/' . Page::short_name($q_ward) if $ward;
+ my $url = Page::short_name($one_council);
+ $url .= '/' . Page::short_name($ward) if $ward;
if ($rss eq 'area' && $area_type ne 'DIS' && $area_type ne 'CTY') {
# Two possibilites are the same for one-tier councils, so redirect one to the other
print $q->redirect($base_url . '/rss/reports/' . $url);
@@ -110,8 +131,8 @@ sub main {
my $type = 'council_problems'; # Problems sent to a council
my (@params, %title_params);
$title_params{COUNCIL} = $area_name;
- push @params, $one_council if $rss eq 'reports';
- push @params, $ward ? $ward : $one_council;
+ push @params, $one_council->{id} if $rss eq 'reports';
+ push @params, $ward ? $ward->{id} : $one_council->{id};
if ($ward && $rss eq 'reports') {
$type = 'ward_problems'; # Problems sent to a council, restricted to a ward
$title_params{WARD} = $q_ward;
@@ -129,14 +150,20 @@ sub main {
my $areas_info;
if ($one_council) {
- $areas_info = mySociety::MaPit::call('areas', $one_council);
+ $areas_info = mySociety::MaPit::call('areas', [ $one_council->{id}, $one_council->{parent_area} ])
+ if $one_council->{parent_area};
+ $areas_info = { $one_council->{id} => $one_council }
+ unless $areas_info;
} else {
# Show all councils on main report page
- my $area_types = Cobrand::area_types($cobrand);
- $areas_info = mySociety::MaPit::call('areas', [ @$area_types ], min_generation=>Cobrand::area_min_generation($cobrand) );
+ my @area_types = Cobrand::area_types($cobrand);
+ $areas_info = mySociety::MaPit::call('areas', \@area_types, min_generation=>Cobrand::area_min_generation($cobrand) );
}
- my $problems = Problems::council_problems($ward, $one_council);
+ my $problems = Problems::council_problems(
+ $ward ? $ward->{id} : undef,
+ $one_council ? $one_council->{id} : undef
+ );
my (%fixed, %open);
my $re_councils = join('|', keys %$areas_info);
@@ -151,7 +178,7 @@ sub main {
$row->{council} =~ s/\|.*$//;
my @council = split /,/, $row->{council};
foreach (@council) {
- next if $one_council && $_ != $one_council;
+ next if $one_council && $_ != $one_council->{id};
add_row($row, scalar @council, $_, \%fixed, \%open);
}
}
@@ -173,15 +200,19 @@ sub main {
foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %$areas_info) {
print '<tr align="center"';
++$c;
- if ($areas_info->{$_}->{generation_high}==10) {
+ if (mySociety::Config::get('COUNTRY') eq 'GB' && $areas_info->{$_}->{generation_high} == 10) {
print ' class="gone"';
} elsif ($c%2) {
print ' class="a"';
}
- my $url = Page::short_name($areas_info->{$_}->{name});
+ my $url = Page::short_name($areas_info->{$_}, $areas_info);
my $cobrand_url = Cobrand::url($cobrand, "/reports/$url", $q);
print '><td align="left"><a href="' . $cobrand_url . '">' .
- encode_utf8($areas_info->{$_}->{name}) . '</a></td>';
+ $areas_info->{$_}->{name};
+ if ($areas_info->{$_}->{parent_area} && $url =~ /,/) {
+ print ', ' . $areas_info->{$areas_info->{$_}->{parent_area}}->{name};
+ }
+ print '</a></td>';
summary_cell(\@{$open{$_}{new}});
if ($q->{site} eq 'emptyhomes') {
my $c = 0;
@@ -198,17 +229,17 @@ sub main {
}
print '</table>';
} else {
- my $name = $areas_info->{$one_council}->{name};
+ my $name = $one_council->{name};
if (!$name) {
print Page::header($q, title=>_("Summary reports"));
- print "Council with identifier " . ent($one_council). " not found. ";
+ print "Council with identifier " . ent($one_council->{id}). " not found. ";
print $q->a({href => Cobrand::url($cobrand, '/reports', $q) }, 'Show all councils');
print ".";
} else {
- my $rss_url = '/rss/reports/' . Page::short_name($name);
+ my $rss_url = '/rss/reports/' . Page::short_name($one_council, $areas_info);
my $thing = _('council');
if ($ward) {
- $rss_url .= '/' . Page::short_name($q_ward);
+ $rss_url .= '/' . Page::short_name($ward);
$thing = 'ward';
$name = ent($q_ward) . ", $name";
}
@@ -234,24 +265,25 @@ sub main {
$vars{summary_line} = sprintf(_('You can <a href="%s">see more details</a> or go back and <a href="/reports">show all councils</a>.'), Cobrand::url($cobrand, NewURL($q, all=>1), $q));
}
- if ($open{$one_council}) {
- my $col = list_problems($q, _('New problems'), $open{$one_council}{new}, $all, 0);
+ my $id = $one_council->{id};
+ if ($open{$id}) {
+ my $col = list_problems($q, _('New problems'), $open{$id}{new}, $all, 0);
my $old = [];
if ($q->{site} eq 'emptyhomes') {
- push @$old, @{$open{$one_council}{older}} if $open{$one_council}{older};
- push @$old, @{$open{$one_council}{unknown}} if $open{$one_council}{unknown};
+ push @$old, @{$open{$id}{older}} if $open{$id}{older};
+ push @$old, @{$open{$id}{unknown}} if $open{$id}{unknown};
} else {
- $old = $open{$one_council}{older};
+ $old = $open{$id}{older};
}
$col .= list_problems($q, _('Older problems'), $old, $all, 0);
if ($q->{site} ne 'emptyhomes') {
- $col .= list_problems($q, _('Old problems, state unknown'), $open{$one_council}{unknown}, $all, 0);
+ $col .= list_problems($q, _('Old problems, state unknown'), $open{$id}{unknown}, $all, 0);
}
$vars{col_problems} = $col;
}
- if ($fixed{$one_council}) {
- my $col = list_problems($q, _('Recently fixed'), $fixed{$one_council}{new}, $all, 1);
- $col .= list_problems($q, _('Old fixed'), $fixed{$one_council}{old}, $all, 1);
+ if ($fixed{$id}) {
+ my $col = list_problems($q, _('Recently fixed'), $fixed{$id}{new}, $all, 1);
+ $col .= list_problems($q, _('Old fixed'), $fixed{$id}{old}, $all, 1);
$vars{col_fixed} = $col;
}
print Page::header($q, context => 'reports', title=>sprintf(_('%s - Summary reports'), $name), rss => [ sprintf(_('Problems within %s, FixMyStreet'), $name), Cobrand::url($cobrand, $rss_url, $q) ]);