#!/usr/bin/perl -w # report.cgi: # Display summary reports for FixMyStreet # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # # $Id: report.cgi,v 1.40 2007-06-19 15:54:24 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::Config; use mySociety::DBHandle qw(dbh select_all); use mySociety::MaPit; use mySociety::Web qw(ent NewURL); 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 $all = $q->param('all') || 0; my $one_council = $q->param('council') || ''; $one_council =~ s/\D//g; $all = 0 unless $one_council; my @params; my $where_extra = ''; if ($one_council) { push @params, $one_council; $where_extra = "and council like '%'||?||'%'"; } my (%fixed, %open, %councils); my $problem = select_all( "select id, title, detail, council, state, extract(epoch from ms_current_timestamp()-lastupdate) as duration, extract(epoch from ms_current_timestamp()-confirmed) as age from problem where state in ('confirmed', 'fixed') and whensent is not null $where_extra order by id ", @params); my $fourweeks = 4*7*24*60*60; foreach my $row (@$problem) { my ($council, $missing) = $row->{council} =~ /^(.*?)(?:\|(.*))?$/; my @council = split /,/, $council; my $type = ($row->{duration} > 2 * $fourweeks) ? 'unknown' : ($row->{age} > $fourweeks ? 'older' : 'new'); my $duration = ($row->{duration} > 2 * $fourweeks) ? 'old' : 'new'; foreach (@council) { next if $one_council && $_ != $one_council; my $entry = [ $row->{id}, $row->{title}, $row->{detail}, scalar @council, $missing ]; push @{$fixed{$_}{$duration}}, $entry if $row->{state} eq 'fixed'; push @{$open{$_}{$type}}, $entry if $row->{state} eq 'confirmed'; $councils{$_} = 1; } } my $areas_info = mySociety::MaPit::get_voting_areas_info([keys %councils]); if (!$one_council) { print Page::header($q, title=>'Summary reports'); print $q->p(_('This is a summary of all reports on this site that have been sent to a council; select a particular council to see the reports sent there.')); my $c = 0; print '
Name | New problems | Older problems | Old problems, state unknown | Recently fixed | Old fixed |
---|---|---|---|---|---|
' . $areas_info->{$_}->{name} . ' | '; summary_cell(\@{$open{$_}{new}}); summary_cell(\@{$open{$_}{older}}); summary_cell(\@{$open{$_}{unknown}}); summary_cell(\@{$fixed{$_}{new}}); summary_cell(\@{$fixed{$_}{old}}); print "