From 4b8d048739cc38b5ed70e3b5f0150b3f8c43a1d2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 2 Jun 2011 15:43:30 +0100 Subject: summary page of admin interface --- perllib/FixMyStreet/App/Controller/Admin.pm | 963 ++++++++++++++++++++++++++++ 1 file changed, 963 insertions(+) create mode 100644 perllib/FixMyStreet/App/Controller/Admin.pm (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm new file mode 100644 index 000000000..68f41c21a --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -0,0 +1,963 @@ +package FixMyStreet::App::Controller::Admin; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + +use mySociety::Random qw(random_bytes); + +=head1 NAME + +FixMyStreet::App::Controller::Admin- Catalyst Controller + +=head1 DESCRIPTION + +Admin pages + +=head1 METHODS + +=cut + +=head2 index + +Display contact us page + +=cut + +sub index : Path : Args(0) { + my ( $self, $c ) = @_; + + my $problems = $c->model('DB::Problem')->search( + undef, { group_by => ['state'], select => [ 'state', { count => 'id' } ], as => [qw/state state_count/] } + ); + + my %prob_counts = map { $_->state => $_->get_column( 'state_count' ) } $problems->all; + + %prob_counts = map { $_ => $prob_counts{$_} || 0 } qw(confirmed fixed unconfirmed hidden partial); + $c->stash->{problems} = \%prob_counts; + $c->stash->{total_problems_live} = $prob_counts{confirmed} + $prob_counts{fixed}; + + my $comments = $c->model('DB::Comment')->search( + undef, { group_by => ['state'], select => [ 'state', { count => 'id' } ], as => [qw/state state_count/] } + ); + + my %comment_counts = map { $_->state => $_->get_column( 'state_count' ) } $comments->all; + + $c->stash->{comments} = \%comment_counts; + + my $alerts = $c->model('DB::Alert')->search( + undef, { group_by => ['confirmed'], select => [ 'confirmed', { count => 'id' } ], as => [qw/confirmed confirmed_count/] } + ); + + my %alert_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $alerts->all; + + $c->stash->{alerts} = \%alert_counts; + + my $contacts = $c->model('DB::Contact')->search( + undef, { group_by => ['confirmed'], select => [ 'confirmed', { count => 'id' } ], as => [qw/confirmed confirmed_count/] } + ); + + my %contact_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $contacts->all; + + $c->stash->{contacts} = \%contact_counts; + + my $questionnaires = $c->model('DB::Questionnaire')->search( + undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/] } + ); + + my %questionnaire_counts = map { $_->get_column( 'answered' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all; + + $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1}; + $c->stash->{questionnaires_pc} = $questionnaire_counts{total} ? sprintf('%.1f', $questionnaire_counts{1} / $questionnaire_counts{total} * 100) : 'na'; + $c->stash->{questionnaires} = \%questionnaire_counts; + + return 1; +} + +# use Encode; +# use POSIX qw(strftime strcoll); +# use Digest::MD5 qw(md5_hex); +# +# use Page; +# use mySociety::Config; +# use mySociety::DBHandle qw(dbh select_all); +# use mySociety::MaPit; +# use mySociety::VotingArea; +# use mySociety::Web qw(NewURL ent); +# +# =item get_token Q +# +# Generate a token based on user and secret +# +# =cut +# sub get_token { +# my ($q) = @_; +# my $secret = scalar(dbh()->selectrow_array('select secret from secret')); +# my $token = md5_hex(($q->remote_user() . $secret)); +# return $token; +# } +# +# =item allowed_pages Q +# +# Return a hash of allowed pages, keyed on page param. The values of the hash +# are arrays of the form [link_text, link_order]. Pages without link_texts +# are not to be included in the main admin menu. +# =cut +# sub allowed_pages($) { +# my ($q) = @_; +# my $cobrand = Page::get_cobrand($q); +# my $pages = Cobrand::admin_pages($cobrand); +# if (!$pages) { +# $pages = { +# 'summary' => [_('Summary'), 0], +# 'councilslist' => [_('Council contacts'), 1], +# 'reports' => [_('Search Reports'), 2], +# 'timeline' => [_('Timeline'), 3], +# 'questionnaire' => [_('Survey Results'), 4], +# 'councilcontacts' => [undef, undef], +# 'counciledit' => [undef, undef], +# 'report_edit' => [undef, undef], +# 'update_edit' => [undef, undef], +# }; +# } +# return $pages; +# } +# +# sub html_head($$) { +# my ($q, $title) = @_; +# my $ret = $q->header(-type => 'text/html', -charset => 'utf-8'); +# my $site_title = _('FixMyStreet administration'); +# $ret .= < +# +# $title - $site_title +# +# +# +# END +# my $pages = allowed_pages($q); +# my @links = sort {$pages->{$a}[1] <=> $pages->{$b}[1]} grep {$pages->{$_}->[0] } keys %$pages; +# $ret .= $q->p( +# $q->strong(_("FixMyStreet admin:")), +# map { $q->a( { href => NewURL($q, page => $_) }, $pages->{$_}->[0]) } @links +# ); +# +# return $ret; +# } +# +# sub fetch_data { +# } +# +# +# # admin_councils_list CGI +# sub admin_councils_list ($) { +# my ($q) = @_; +# +# print html_head($q, _("Council contacts")); +# print $q->h1(_("Council contacts")); +# +# # Table of editors +# 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"); +# if (@$edit_activity) { +# print $q->ul( +# map { $q->li( sprintf(_('%d edits by %s'), $_->[0], $_->[1])) } @$edit_activity +# ); +# } else { +# print $q->p(_('No edits have yet been made.')); +# } +# +# # Table of councils +# 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 { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; +# @councils_ids = grep { $_ ne 301 } @councils_ids; +# my $bci_info = dbh()->selectall_hashref(" +# select area_id, count(*) as c, count(case when deleted then 1 else null end) as deleted, +# count(case when confirmed then 1 else null end) as confirmed +# from contacts group by area_id", 'area_id'); +# +# my $list_part = sub { +# my @ids = @_; +# if (!scalar(@ids)) { +# print _("None"); +# return; +# } +# 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' ? +# sprintf(_('%d addresses'), $bci_info->{$_}->{c}) +# : '')); +# } +# print $q->ul(@li); +# }; +# +# print $q->h3(_('No info at all')); +# &$list_part(grep { !$bci_info->{$_} } @councils_ids); +# print $q->h3(_('Currently has 1+ deleted')); +# &$list_part(grep { $bci_info->{$_} && $bci_info->{$_}->{deleted} } @councils_ids); +# print $q->h3(_('Some unconfirmeds')); +# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} != $bci_info->{$_}->{c} } @councils_ids); +# print $q->h3(_('All confirmed')); +# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} == $bci_info->{$_}->{c} } @councils_ids); +# print html_tail($q); +# } +# +# # admin_council_contacts CGI AREA_ID +# sub admin_council_contacts ($$) { +# my ($q, $area_id) = @_; +# +# # Submit form +# my $updated = ''; +# my $posted = $q->param('posted') || ''; +# if ($posted eq 'new') { +# return not_found($q) if $q->param('token') ne get_token($q); +# my $email = trim($q->param('email')); +# my $category = trim($q->param('category')); +# $category = 'Empty property' if $q->{site} eq 'emptyhomes'; +# # History is automatically stored by a trigger in the database +# my $update = dbh()->do("update contacts set +# email = ?, +# confirmed = ?, +# deleted = ?, +# editor = ?, +# whenedited = ms_current_timestamp(), +# note = ? +# where area_id = ? +# and category = ? +# ", {}, +# $email, ($q->param('confirmed') ? 1 : 0), +# ($q->param('deleted') ? 1 : 0), +# ($q->remote_user() || _("*unknown*")), $q->param('note'), +# $area_id, $category +# ); +# $updated = $q->p($q->em(_("Values updated"))); +# unless ($update > 0) { +# dbh()->do('insert into contacts +# (area_id, category, email, editor, whenedited, note, confirmed, deleted) +# values +# (?, ?, ?, ?, ms_current_timestamp(), ?, ?, ?)', {}, +# $area_id, $category, $email, +# ($q->remote_user() || _('*unknown*')), $q->param('note'), +# ($q->param('confirmed') ? 1 : 0), ($q->param('deleted') ? 1 : 0) +# ); +# $updated = $q->p($q->em(_("New category contact added"))); +# } +# dbh()->commit(); +# } elsif ($posted eq 'update') { +# return not_found($q) if $q->param('token') ne get_token($q); +# my @cats = $q->param('confirmed'); +# foreach my $cat (@cats) { +# 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 +# ); +# } +# $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); +# +# if ($q->param('text')) { +# print $q->header(-type => 'text/plain', -charset => 'utf-8'); +# foreach my $l (@$bci_data) { +# next if $l->{deleted} || !$l->{confirmed}; +# print $l->{category} . "\t" . $l->{email} . "\n"; +# } +# return; +# } +# +# $q->delete_all(); # No need for state! +# +# # Title +# my $mapit_data = mySociety::MaPit::call('area', $area_id); +# my $title = sprintf(_('Council contacts for %s'), $mapit_data->{name}); +# print html_head($q, $title); +# print $q->h1($title); +# print $updated; +# +# # Example postcode, link to list of problem reports +# my $links_html; +# my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); +# if ($example_postcode && ! ref $example_postcode) { +# $links_html .= $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, +# "Example postcode " . $example_postcode) . " | "; +# } +# $links_html .= ' ' . +# $q->a({ href => mySociety::Config::get('BASE_URL') . "/reports?council=" . $area_id }, _(" List all reported problems")); +# $links_html .= ' ' . +# $q->a({ href => NewURL($q, area_id => $area_id, page => 'councilcontacts', text => 1) }, _('Text only version')); +# print $q->p($links_html); +# +# # Display of addresses / update statuses form +# print $q->start_form(-method => 'POST', -action => './'); +# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); +# print $q->Tr({}, $q->th({}, [_("Category"), _("Email"), _("Confirmed"), _("Deleted"), _("Last editor"), _("Note"), _("When edited"), _('Confirm')])); +# foreach my $l (@$bci_data) { +# print $q->Tr($q->td([ +# $q->a({ href => NewURL($q, area_id => $area_id, category => $l->{category}, page => 'counciledit') }, +# $l->{category}), $l->{email}, $l->{confirmed} ? _('Yes') : _('No'), +# $l->{deleted} ? _('Yes') : _('No'), $l->{editor}, ent($l->{note}), +# $l->{whenedited} =~ m/^(.+)\.\d+$/, +# $q->checkbox(-name => 'confirmed', -value => $l->{category}, -label => '') +# ])); +# } +# print $q->end_table(); +# # XXX +# print $q->p( +# $q->hidden('area_id', $area_id), +# $q->hidden('posted', 'update'), +# $q->hidden('token', get_token($q)), +# $q->hidden('page', 'councilcontacts'), +# $q->submit(_('Update statuses')) +# ); +# print $q->end_form(); +# +# # Display form for adding new category +# print $q->h2(_('Add new category')); +# print $q->start_form(-method => 'POST', -action => './'); +# if ($q->{site} ne 'emptyhomes') { +# print $q->p($q->strong(_("Category: ")), +# $q->textfield(-name => "category", -size => 30)); +# } +# print $q->p($q->strong(_("Email: ")), +# $q->textfield(-name => "email", -size => 30)); +# $q->autoEscape(0); +# print $q->p( +# $q->checkbox(-id => 'confirmed', -name => "confirmed", -value => 1, -label => ' ' . $q->label({-for => 'confirmed'}, _('Confirmed'))), +# ' ', +# $q->checkbox(-id => 'deleted', -name => "deleted", -value => 1, -label => ' ' . $q->label({-for => 'deleted'}, _('Deleted'))) +# ); +# $q->autoEscape(1); +# print $q->p($q->strong(_("Note: ")), +# $q->textarea(-name => "note", -rows => 3, -columns=>40)); +# print $q->p( +# $q->hidden('area_id', $area_id), +# $q->hidden('posted', 'new'), +# $q->hidden('token', get_token($q)), +# $q->hidden('page', 'councilcontacts'), +# $q->submit(_('Create category')) +# ); +# print $q->end_form(); +# +# print html_tail($q); +# } +# +# # admin_council_edit CGI AREA_ID CATEGORY +# sub admin_council_edit ($$$) { +# my ($q, $area_id, $category) = @_; +# +# # Get all the data +# my $bci_data = select_all("select * from contacts where area_id = ? and category = ?", $area_id, $category); +# $bci_data = $bci_data->[0]; +# my $bci_history = select_all("select * from contacts_history where area_id = ? and category = ? order by contacts_history_id", $area_id, $category); +# my $mapit_data = mySociety::MaPit::call('area', $area_id); +# +# # Title +# my $title = sprintf(_('Council contacts for %s'), $mapit_data->{name}); +# print html_head($q, $title); +# print $q->h1($title); +# +# # Example postcode +# my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); +# if ($example_postcode && ! ref $example_postcode) { +# print $q->p("Example postcode: ", +# $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, +# $example_postcode)); +# } +# +# # Display form for editing details +# print $q->start_form(-method => 'POST', -action => './'); +# map { $q->param($_, $bci_data->{$_}) } qw/category email confirmed deleted/; +# $q->param('page', 'councilcontacts'); +# $q->param('posted', 'new'); +# print $q->strong(_("Category: ")) . $bci_data->{category}; +# print $q->hidden('token', get_token($q)), +# print $q->hidden("category"); +# print $q->strong(' ' . _("Email: ")); +# print $q->textfield(-name => "email", -size => 30) . " "; +# $q->autoEscape(0); +# print $q->checkbox(-id => 'confirmed', -name => "confirmed", -value => 1, -label => ' ' . $q->label({-for => 'confirmed'}, _('Confirmed'))); +# print ' '; +# print $q->checkbox(-id => 'deleted', -name => "deleted", -value => 1, -label => ' ' . $q->label({-for => 'deleted'}, _('Deleted'))); +# $q->autoEscape(1); +# print $q->br(); +# print $q->strong(_("Note: ")); +# print $q->textarea(-name => "note", -rows => 3, -columns=>40) . " "; +# print $q->br(); +# print $q->hidden('area_id'); +# print $q->hidden('posted'); +# print $q->hidden('page'); +# print $q->submit(_('Save changes')); +# print $q->end_form(); +# +# # Display history of changes +# print $q->h2(_('History')); +# print $q->start_table({border=>1}); +# print $q->Tr({}, $q->th({}, [_("When edited"), _("Email"), _("Confirmed"), _("Deleted"), _("Editor"), _("Note")])); +# my $html = ''; +# my $prev = undef; +# foreach my $h (@$bci_history) { +# $h->{confirmed} = $h->{confirmed} ? _("yes") : _("no"), +# $h->{deleted} = $h->{deleted} ? _("yes") : _("no"), +# my $emailchanged = ($prev && $h->{email} ne $prev->{email}) ? 1 : 0; +# my $confirmedchanged = ($prev && $h->{confirmed} ne $prev->{confirmed}) ? 1 : 0; +# my $deletedchanged = ($prev && $h->{deleted} ne $prev->{deleted}) ? 1 : 0; +# $html .= $q->Tr({}, $q->td([ +# $h->{whenedited} =~ m/^(.+)\.\d+$/, +# $emailchanged ? $q->strong($h->{email}) : $h->{email}, +# $confirmedchanged ? $q->strong($h->{confirmed}) : $h->{confirmed}, +# $deletedchanged ? $q->strong($h->{deleted}) : $h->{deleted}, +# $h->{editor}, +# $h->{note} +# ])); +# $prev = $h; +# } +# print $html; +# print $q->end_table(); +# print html_tail($q); +# } +# +# sub admin_reports { +# my $q = shift; +# my $title = _('Search Reports'); +# my $cobrand = Page::get_cobrand($q); +# my $pages = allowed_pages($q); +# print html_head($q, $title); +# print $q->h1($title); +# print $q->start_form(-method => 'GET', -action => './'); +# print $q->label({-for => 'search'}, _('Search:')), ' ', $q->textfield(-id => 'search', -name => "search", -size => 30); +# print $q->hidden('page'); +# print $q->end_form; +# +# if (my $search = $q->param('search')) { +# my $results = Problems::problem_search($search); +# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); +# print $q->Tr({}, $q->th({}, [_('ID'), _('Title'), _('Name'), _('Email'), _('Council'), _('Category'), _('Anonymous'), _('Cobrand'), _('Created'), _('State'), _('When sent'), _('*') ])); +# my $cobrand_data; +# foreach (@$results) { +# my $url = $_->{id}; +# if ($_->{state} eq 'confirmed' || $_->{state} eq 'fixed') { +# # if this is a cobranded admin interface, but we're looking at a generic problem, figure out enough information +# # to create a URL to the cobranded version of the problem +# if ($_->{cobrand}) { +# $cobrand_data = $_->{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, $_); +# } +# $url = $q->a({ -href => Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $_->{id} }, $url); +# } +# my $council = $_->{council} || ' '; +# my $category = $_->{category} || ' '; +# (my $confirmed = $_->{confirmed} || '-') =~ s/ (.*?)\..*/ $1/; +# (my $created = $_->{created}) =~ s/\..*//; +# (my $lastupdate = $_->{lastupdate}) =~ s/ (.*?)\..*/ $1/; +# (my $whensent = $_->{whensent} || ' ') =~ s/\..*//; +# my $state = $_->{state}; +# $state .= ''; +# $state .= "
" . _('Confirmed:') . " $confirmed" if $_->{state} eq 'confirmed' || $_->{state} eq 'fixed'; +# $state .= '
' . _('Fixed:') . ' ' . $lastupdate if $_->{state} eq 'fixed'; +# $state .= "
" . _('Last update:') . " $lastupdate" if $_->{state} eq 'confirmed'; +# $state .= '
'; +# my $anonymous = $_->{anonymous} ? _('Yes') : _('No'); +# my $cobrand = $_->{cobrand}; +# $cobrand .= "
" . $_->{cobrand_data}; +# my $counciltext = ''; +# if (grep {$_ eq 'councilcontacts'} keys %{$pages}) { +# $counciltext = $q->a({ -href => NewURL($q, page=>'councilcontacts', area_id=>$council)}, $council); +# } else { +# $counciltext = $council; +# } +# my $attr = {}; +# $attr->{-class} = 'hidden' if $_->{state} eq 'hidden'; +# print $q->Tr($attr, $q->td([ $url, ent($_->{title}), ent($_->{name}), ent($_->{email}), +# $counciltext, +# $category, $anonymous, $cobrand, $created, $state, $whensent, +# $q->a({ -href => NewURL($q, page=>'report_edit', id=>$_->{id}) }, _('Edit')) +# ])); +# } +# print $q->end_table; +# +# print $q->h2(_('Updates')); +# my $updates = Problems::update_search($search); +# admin_show_updates($q, $updates); +# } +# +# print html_tail($q); +# } +# +# sub admin_edit_report { +# my ($q, $id) = @_; +# my $row = Problems::admin_fetch_problem($id); +# my $cobrand = Page::get_cobrand($q); +# return not_found($q) if ! $row->[0]; +# my %row = %{$row->[0]}; +# my $status_message = ''; +# if ($q->param('resend')) { +# return not_found($q) if $q->param('token') ne get_token($q); +# dbh()->do('update problem set whensent=null where id=?', {}, $id); +# admin_log_edit($q, $id, 'problem', 'resend'); +# dbh()->commit(); +# $status_message = '

' . _('That problem will now be resent.') . '

'; +# } elsif ($q->param('submit')) { +# return not_found($q) if $q->param('token') ne get_token($q); +# my $new_state = $q->param('state'); +# my $done = 0; +# if ($new_state eq 'confirmed' && $row{state} eq 'unconfirmed' && $q->{site} eq 'emptyhomes') { +# $status_message = '

' . _('I am afraid you cannot confirm unconfirmed reports.') . '

'; +# $done = 1; +# } +# my $query = 'update problem set anonymous=?, state=?, name=?, email=?, title=?, detail=?'; +# if ($q->param('remove_photo')) { +# $query .= ', photo=null'; +# } +# if ($new_state ne $row{state}) { +# $query .= ', lastupdate=current_timestamp'; +# } +# if ($new_state eq 'confirmed' and $row{state} eq 'unconfirmed') { +# $query .= ', confirmed=current_timestamp'; +# } +# $query .= ' where id=?'; +# unless ($done) { +# dbh()->do($query, {}, $q->param('anonymous') ? 't' : 'f', $new_state, +# $q->param('name'), $q->param('email'), $q->param('title'), $q->param('detail'), $id); +# if ($new_state ne $row{state}) { +# admin_log_edit($q, $id, 'problem', 'state_change'); +# } +# if ($q->param('anonymous') ne $row{anonymous} || +# $q->param('name') ne $row{name} || +# $q->param('email') ne $row{email} || +# $q->param('title') ne $row{title} || +# $q->param('detail') ne $row{detail}) { +# admin_log_edit($q, $id, 'problem', 'edit'); +# } +# dbh()->commit(); +# map { $row{$_} = $q->param($_) } qw(anonymous state name email title detail); +# $status_message = '

' . _('Updated!') . '

'; +# } +# } +# my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row; +# my $title = sprintf(_("Editing problem %d"), $id); +# print html_head($q, $title); +# print $q->h1($title); +# print $status_message; +# +# my $council = $row{council} || '' . _('None') . ''; +# (my $areas = $row{areas}) =~ s/^,(.*),$/$1/; +# my $latitude = $row{latitude}; +# my $longitude = $row{longitude}; +# my $questionnaire = $row{send_questionnaire} ? _('Yes') : _('No'); +# my $used_map = $row{used_map} ? _('used map') : _("didn't use map"); +# (my $whensent = $row{whensent} || ' ') =~ s/\..*//; +# (my $confirmed = $row{confirmed} || '-') =~ s/ (.*?)\..*/ $1/; +# my $photo = ''; +# my $cobrand_data; +# if ($row{cobrand}) { +# $cobrand_data = $row{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, \%row); +# } +# $photo = '
  • +# +# ' if $row{photo}; +# +# my $url_base = Cobrand::base_url_for_emails($cobrand, $cobrand_data); +# my $url = $url_base . '/report/' . $row{id}; +# +# my $anon = $q->label({-for=>'anonymous'}, _('Anonymous:')) . ' ' . $q->popup_menu(-id => 'anonymous', -name => 'anonymous', -values => { 1=>_('Yes'), 0=>_('No') }, -default => $row{anonymous}); +# my $state = $q->label({-for=>'state'}, _('State:')) . ' ' . $q->popup_menu(-id => 'state', -name => 'state', -values => { confirmed => _('Open'), fixed => _('Fixed'), hidden => _('Hidden'), unconfirmed => _('Unconfirmed'), partial => _('Partial') }, -default => $row{state}); +# +# my $resend = ''; +# $resend = ' ' if $row{state} eq 'confirmed'; +# +# print $q->start_form(-method => 'POST', -action => './'); +# print $q->hidden('page'); +# print $q->hidden('id'); +# print $q->hidden('token', get_token($q)); +# print $q->hidden('submit', 1); +# print " +#
      +#
    • " . _('View report on site') . " +#
    • +#

    • +#
    • " . _('Co-ordinates:') . " $latitude,$longitude (" . _('originally entered') . " $row_h{postcode}, $used_map) +#
    • " . _('For council(s):') . " $council (" . _('other areas:') . " $areas) +#
    • $anon +#
    • $state +#
    • " . _('Category:') . " $row{category} +#
    • " . _('Name:') . " +#
    • " . _('Email:') . " +#
    • " . _('Phone:') . " $row_h{phone} +#
    • " . _('Created:') . " $row{created} +#
    • " . _('Confirmed:') . " $confirmed +#
    • " . _('Sent:') . " $whensent $resend +#
    • " . _('Last update:') . " $row{lastupdate} +#
    • " . _('Service:') . " $row{service} +#
    • " . _('Cobrand:') . " $row{cobrand} +#
    • " . _('Cobrand data:') . " $row{cobrand_data} +#
    • " . _('Going to send questionnaire?') . " $questionnaire +# $photo +#
    +# "; +# print $q->submit(_('Submit changes')); +# print $q->end_form; +# +# print $q->h2(_('Updates')); +# my $updates = select_all('select * from comment where problem_id=? order by created', $id); +# admin_show_updates($q, $updates); +# print html_tail($q); +# } +# +# sub admin_show_updates { +# my ($q, $updates) = @_; +# my $cobrand = Page::get_cobrand($q); +# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); +# print $q->Tr({}, $q->th({}, [ _('ID'), _('State'), _('Name'), _('Email'), _('Created'), _('Cobrand'), _('Text'), _('*') ])); +# my $base_url = ''; +# my $cobrand_data; +# foreach (@$updates) { +# my $url = $_->{id}; +# if ( $_->{state} eq 'confirmed' ) { +# if ($_->{cobrand}) { +# $cobrand_data = $_->{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_update($cobrand, $_); +# } +# $url = $q->a({ -href => Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $_->{problem_id} . '#update_' . $_->{id} }, +# $url); +# } +# my $cobrand = $_->{cobrand} . '
    ' . $_->{cobrand_data}; +# my $attr = {}; +# $attr->{-class} = 'hidden' if $_->{state} eq 'hidden' || ($_->{problem_state} && $_->{problem_state} eq 'hidden'); +# print $q->Tr($attr, $q->td([ $url, $_->{state}, ent($_->{name} || ''), +# ent($_->{email}), $_->{created}, $cobrand, ent($_->{text}), +# $q->a({ -href => NewURL($q, page=>'update_edit', id=>$_->{id}) }, _('Edit')) +# ])); +# } +# print $q->end_table; +# } +# +# sub admin_edit_update { +# my ($q, $id) = @_; +# my $row = Problems::admin_fetch_update($id); +# return not_found($q) if ! $row->[0]; +# my $cobrand = Page::get_cobrand($q); +# +# my %row = %{$row->[0]}; +# my $status_message = ''; +# if ($q->param('submit')) { +# return not_found($q) if $q->param('token') ne get_token($q); +# my $query = 'update comment set state=?, name=?, email=?, text=?'; +# if ($q->param('remove_photo')) { +# $query .= ', photo=null'; +# } +# $query .= ' where id=?'; +# dbh()->do($query, {}, $q->param('state'), $q->param('name'), $q->param('email'), $q->param('text'), $id); +# $status_message = '

    ' . _('Updated!') . '

    '; +# +# # If we're hiding an update, see if it marked as fixed and unfix if so +# if ($q->param('state') eq 'hidden' && $row{mark_fixed}) { +# dbh()->do("update problem set state='confirmed' where state='fixed' and id=?", {}, $row{problem_id}); +# $status_message .= '

    ' . _('Problem marked as open.') . '

    '; +# } +# +# if ($q->param('state') ne $row{state}) { +# admin_log_edit($q, $id, 'update', 'state_change'); +# } +# if (!defined($row{name})){ +# $row{name} = ""; +# } +# if ($q->param('name') ne $row{name} || $q->param('email') ne $row{email} || $q->param('text') ne $row{text}) { +# admin_log_edit($q, $id, 'update', 'edit'); +# } +# dbh()->commit(); +# map { $row{$_} = $q->param($_) } qw(state name email text); +# } +# my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row; +# my $title = sprintf(_("Editing update %d"), $id); +# print html_head($q, $title); +# print $q->h1($title); +# print $status_message; +# my $name = $row_h{name}; +# $name = '' unless $name; +# my $cobrand_data; +# if ($row{cobrand}) { +# $cobrand_data = $row{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_update($cobrand, \%row); +# } +# my $photo = ''; +# $photo = '
  • +# +# ' if $row{photo}; +# +# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $row{problem_id} . '#update_' . $row{id}; +# +# my $state = $q->label({-for=>'state'}, _('State:')) . ' ' . $q->popup_menu(-id => 'state', -name => 'state', -values => { confirmed => _('Confirmed'), hidden => _('Hidden'), unconfirmed => _('Unconfirmed') }, -default => $row{state}); +# +# print $q->start_form(-method => 'POST', -action => './'); +# print $q->hidden('page'); +# print $q->hidden('id'); +# print $q->hidden('token', get_token($q)); +# print $q->hidden('submit', 1); +# print " +#
      +#
    • " . _('View update on site') . " +#

    • +#
    • $state +#
    • " . _('Name:') . " " . _('(blank to go anonymous)') . " +#
    • " . _('Email:') . " +#
    • " . _('Cobrand:') . " $row{cobrand} +#
    • " . _('Cobrand data:') . " $row{cobrand_data} +#
    • " . _('Created:') . " $row{created} +# $photo +#
    +# "; +# print $q->submit(_('Submit changes')); +# print $q->end_form; +# print html_tail($q); +# } +# +# sub get_cobrand_data_from_hash { +# my ($cobrand, $data) = @_; +# my $cobrand_data; +# if ($data->{cobrand}) { +# $cobrand_data = $data->{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, $data); +# } +# return $cobrand_data; +# } +# +# sub admin_log_edit { +# my ($q, $id, $object_type, $action) = @_; +# my $query = "insert into admin_log (admin_user, object_type, object_id, action) +# values (?, ?, ?, ?);"; +# dbh()->do($query, {}, $q->remote_user(), $object_type, $id, $action); +# } +# +# sub admin_timeline { +# my $q = shift; +# my $cobrand = Page::get_cobrand($q); +# print html_head($q, _('Timeline')); +# print $q->h1(_('Timeline')); +# +# my %time; +# #my $backto_unix = time() - 60*60*24*7; +# +# my $probs = Problems::timeline_problems(); +# foreach (@$probs) { +# push @{$time{$_->{created}}}, { type => 'problemCreated', %$_ }; +# push @{$time{$_->{confirmed}}}, { type => 'problemConfirmed', %$_ } if $_->{confirmed}; +# push @{$time{$_->{whensent}}}, { type => 'problemSent', %$_ } if $_->{whensent}; +# } +# +# my $questionnaire = Problems::timeline_questionnaires($cobrand); +# foreach (@$questionnaire) { +# push @{$time{$_->{whensent}}}, { type => 'quesSent', %$_ }; +# push @{$time{$_->{whenanswered}}}, { type => 'quesAnswered', %$_ } if $_->{whenanswered}; +# } +# +# my $updates = Problems::timeline_updates(); +# foreach (@$updates) { +# push @{$time{$_->{created}}}, { type => 'update', %$_} ; +# } +# +# my $alerts = Problems::timeline_alerts($cobrand); +# +# +# foreach (@$alerts) { +# push @{$time{$_->{whensubscribed}}}, { type => 'alertSub', %$_ }; +# } +# $alerts = Problems::timeline_deleted_alerts($cobrand); +# foreach (@$alerts) { +# push @{$time{$_->{whendisabled}}}, { type => 'alertDel', %$_ }; +# } +# +# my $date = ''; +# my $cobrand_data; +# foreach (reverse sort keys %time) { +# my $curdate = decode_utf8(strftime('%A, %e %B %Y', localtime($_))); +# if ($date ne $curdate) { +# print '' if $date; +# print "

    $curdate

    "; +# $date = $curdate; +# } +# print '
    ', decode_utf8(strftime('%H:%M:%S', localtime($_))), ':
    '; +# foreach (@{$time{$_}}) { +# my $type = $_->{type}; +# if ($type eq 'problemCreated') { +# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; +# print sprintf(_("Problem %d created"), $_->{id}) . $name_str; +# } elsif ($type eq 'problemConfirmed') { +# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; +# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); +# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; +# print sprintf(_("Problem %s confirmed"), "$_->{id}") . $name_str; +# } elsif ($type eq 'problemSent') { +# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); +# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; +# print sprintf(_("Problem %s sent to council %s"), "$_->{id}", $_->{council}); +# } elsif ($type eq 'quesSent') { +# print sprintf(_("Questionnaire %d sent for problem %d"), $_->{id}, $_->{problem_id}); +# } elsif ($type eq 'quesAnswered') { +# print sprintf(_("Questionnaire %d answered for problem %d, %s to %s"), $_->{id}, $_->{problem_id}, $_->{old_state}, $_->{new_state}); +# } elsif ($type eq 'update') { +# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); +# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{problem_id}#$_->{id}"; +# my $name = ent($_->{name} || 'anonymous'); +# print sprintf(_("Update %s created for problem %d; by %s"), "$_->{id}", $_->{problem_id}, $name) . " <" . ent($_->{email}) . ">"; +# } elsif ($type eq 'alertSub') { +# my $param = $_->{parameter} || ''; +# my $param2 = $_->{parameter2} || ''; +# print sprintf(_("Alert %d created for %s, type %s, parameters %s / %s"), $_->{id}, ent($_->{email}), $_->{alert_type}, $param, $param2); +# } elsif ($type eq 'alertDel') { +# my $sub = decode_utf8(strftime('%H:%M:%S %e %B %Y', localtime($_->{whensubscribed}))); +# print sprintf(_("Alert %d disabled (created %s)"), $_->{id}, $sub); +# } +# print '
    '; +# } +# print "
    \n"; +# } +# print html_tail($q); +# +# } +# +# sub admin_questionnaire { +# my $q = shift; +# my $cobrand = Page::get_cobrand($q); +# print html_head($q, _('Survey Results')); +# print $q->h1(_('Survey Results')); +# +# # columns in questionnaire is id, problem_id, whensent, +# # whenanswered, ever_reported, old_state, new_state +# +# my $survey = select_all("select ever_reported, count(*) from questionnaire where whenanswered is not null group by ever_reported"); +# +# my %res; +# $res{0} = 0; +# $res{1} = 0; +# foreach my $h (@$survey) { +# $res{$h->{ever_reported}} = $h->{count} if (exists $h->{ever_reported}); +# } +# my $total = $res{0} + $res{1}; +# +# print $q->start_table({border=>1}); +# print $q->Tr({}, +# $q->th({}, [_("Reported before"), +# _("Not reported before")])); +# if ($total) { +# print $q->Tr({}, +# $q->td([ +# sprintf("%d (%d%%)", $res{1}, (100 * $res{1}) / $total), +# sprintf("%d (%d%%)", $res{0}, (100 * $res{0}) / $total), +# ])); +# } else { +# print $q->Tr({}, $q->td([ 'n/a', 'n/a' ])); +# } +# print $q->end_table(); +# print html_tail($q); +# } +# +# sub not_found { +# my ($q) = @_; +# print $q->header(-status=>'404 Not Found',-type=>'text/html'); +# print "

    Not Found

    The requested URL was not found on this server."; +# } +# +# sub main { +# my $q = shift; +# +# my $logout = $q->param('logout'); +# my $timeout = $q->param('timeout'); +# if ($logout) { +# if (!$timeout) { +# print $q->redirect(-location => '?logout=1;timeout=' . (time() + 7)); +# return; +# } +# if (time() < $timeout) { +# print $q->header( +# -status => '401 Unauthorized', +# -www_authenticate => 'Basic realm="www.fixmystreet.com admin pages"' +# ); +# return; +# } +# } +# +# my $page = $q->param('page'); +# $page = "summary" if !$page; +# +# my $area_id = $q->param('area_id'); +# my $category = $q->param('category'); +# my $pages = allowed_pages($q); +# my @allowed_actions = keys %$pages; +# +# if (!grep {$_ eq $page} @allowed_actions) { +# not_found($q); +# return; +# } +# +# if ($page eq "councilslist") { +# admin_councils_list($q); +# } elsif ($page eq "councilcontacts") { +# admin_council_contacts($q, $area_id); +# } elsif ($page eq "counciledit") { +# admin_council_edit($q, $area_id, $category); +# } elsif ($page eq 'reports') { +# admin_reports($q); +# } elsif ($page eq 'report_edit') { +# my $id = $q->param('id'); +# admin_edit_report($q, $id); +# } elsif ($page eq 'update_edit') { +# my $id = $q->param('id'); +# admin_edit_update($q, $id); +# } elsif ($page eq 'timeline') { +# admin_timeline($q); +# } elsif ($page eq 'questionnaire') { +# admin_questionnaire($q); +# } else { +# admin_summary($q); +# } +# } +# Page::do_fastcgi(\&main); +# +# sub trim { +# my $e = shift; +# $e =~ s/^\s+//; +# $e =~ s/\s+$//; +# return $e; +# } + +=head1 AUTHOR + +Struan Donald + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; -- cgit v1.2.3 From 60224af6c2eb20368e0fe4ffaf6827bff78357b8 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 2 Jun 2011 16:41:49 +0100 Subject: questionnaire admin page --- perllib/FixMyStreet/App/Controller/Admin.pm | 59 +++++++++++------------------ 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 68f41c21a..565737e54 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -62,10 +62,12 @@ sub index : Path : Args(0) { $c->stash->{contacts} = \%contact_counts; my $questionnaires = $c->model('DB::Questionnaire')->search( - undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/] } + undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/], join => 'problem' } ); my %questionnaire_counts = map { $_->get_column( 'answered' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all; + $questionnaire_counts{1} ||= 0; + $questionnaire_counts{0} ||= 0; $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1}; $c->stash->{questionnaires_pc} = $questionnaire_counts{total} ? sprintf('%.1f', $questionnaire_counts{1} / $questionnaire_counts{total} * 100) : 'na'; @@ -74,6 +76,26 @@ sub index : Path : Args(0) { return 1; } +sub questionnaire : Path('questionnaire') : Args(0) { + my ( $self, $c ) = @_; + + my $questionnaires = $c->model('DB::Questionnaire')->search( + { whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] } + ); + + + my %questionnaire_counts = map { $_->get_column( 'reported' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all; + + $questionnaire_counts{1} ||= 0; + $questionnaire_counts{0} ||= 0; + + $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1}; + $c->stash->{reported_pc} = ( 100 * $questionnaire_counts{1} ) / $questionnaire_counts{total}; + $c->stash->{not_reported_pc} = ( 100 * $questionnaire_counts{0} ) / $questionnaire_counts{total}; + $c->stash->{questionnaires} = \%questionnaire_counts; + + return 1; +} # use Encode; # use POSIX qw(strftime strcoll); # use Digest::MD5 qw(md5_hex); @@ -842,41 +864,6 @@ sub index : Path : Args(0) { # # } # -# sub admin_questionnaire { -# my $q = shift; -# my $cobrand = Page::get_cobrand($q); -# print html_head($q, _('Survey Results')); -# print $q->h1(_('Survey Results')); -# -# # columns in questionnaire is id, problem_id, whensent, -# # whenanswered, ever_reported, old_state, new_state -# -# my $survey = select_all("select ever_reported, count(*) from questionnaire where whenanswered is not null group by ever_reported"); -# -# my %res; -# $res{0} = 0; -# $res{1} = 0; -# foreach my $h (@$survey) { -# $res{$h->{ever_reported}} = $h->{count} if (exists $h->{ever_reported}); -# } -# my $total = $res{0} + $res{1}; -# -# print $q->start_table({border=>1}); -# print $q->Tr({}, -# $q->th({}, [_("Reported before"), -# _("Not reported before")])); -# if ($total) { -# print $q->Tr({}, -# $q->td([ -# sprintf("%d (%d%%)", $res{1}, (100 * $res{1}) / $total), -# sprintf("%d (%d%%)", $res{0}, (100 * $res{0}) / $total), -# ])); -# } else { -# print $q->Tr({}, $q->td([ 'n/a', 'n/a' ])); -# } -# print $q->end_table(); -# print html_tail($q); -# } # # sub not_found { # my ($q) = @_; -- cgit v1.2.3 From f657edc956939c673f47017a0acbba11efb67d04 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 2 Jun 2011 16:48:51 +0100 Subject: get rid of sprintf warnings --- perllib/FixMyStreet/App/Controller/Admin.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 565737e54..6f667603e 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -51,6 +51,9 @@ sub index : Path : Args(0) { my %alert_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $alerts->all; + $alert_counts{0} ||= 0; + $alert_counts{1} ||= 0; + $c->stash->{alerts} = \%alert_counts; my $contacts = $c->model('DB::Contact')->search( @@ -59,6 +62,10 @@ sub index : Path : Args(0) { my %contact_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $contacts->all; + $contact_counts{0} ||= 0; + $contact_counts{1} ||= 0; + $contact_counts{total} = $contact_counts{0} + $contact_counts{1}; + $c->stash->{contacts} = \%contact_counts; my $questionnaires = $c->model('DB::Questionnaire')->search( -- cgit v1.2.3 From e5f699b66af6d32c7b7c007945bec181cb14967c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 2 Jun 2011 16:49:35 +0100 Subject: perltidy --- perllib/FixMyStreet/App/Controller/Admin.pm | 68 +++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 14 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 6f667603e..304eafd1c 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -28,28 +28,49 @@ sub index : Path : Args(0) { my ( $self, $c ) = @_; my $problems = $c->model('DB::Problem')->search( - undef, { group_by => ['state'], select => [ 'state', { count => 'id' } ], as => [qw/state state_count/] } + undef, + { + group_by => ['state'], + select => [ 'state', { count => 'id' } ], + as => [qw/state state_count/] + } ); - my %prob_counts = map { $_->state => $_->get_column( 'state_count' ) } $problems->all; + my %prob_counts = + map { $_->state => $_->get_column('state_count') } $problems->all; - %prob_counts = map { $_ => $prob_counts{$_} || 0 } qw(confirmed fixed unconfirmed hidden partial); + %prob_counts = + map { $_ => $prob_counts{$_} || 0 } + qw(confirmed fixed unconfirmed hidden partial); $c->stash->{problems} = \%prob_counts; - $c->stash->{total_problems_live} = $prob_counts{confirmed} + $prob_counts{fixed}; + $c->stash->{total_problems_live} = + $prob_counts{confirmed} + $prob_counts{fixed}; my $comments = $c->model('DB::Comment')->search( - undef, { group_by => ['state'], select => [ 'state', { count => 'id' } ], as => [qw/state state_count/] } + undef, + { + group_by => ['state'], + select => [ 'state', { count => 'id' } ], + as => [qw/state state_count/] + } ); - my %comment_counts = map { $_->state => $_->get_column( 'state_count' ) } $comments->all; + my %comment_counts = + map { $_->state => $_->get_column('state_count') } $comments->all; $c->stash->{comments} = \%comment_counts; my $alerts = $c->model('DB::Alert')->search( - undef, { group_by => ['confirmed'], select => [ 'confirmed', { count => 'id' } ], as => [qw/confirmed confirmed_count/] } + undef, + { + group_by => ['confirmed'], + select => [ 'confirmed', { count => 'id' } ], + as => [qw/confirmed confirmed_count/] + } ); - my %alert_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $alerts->all; + my %alert_counts = + map { $_->confirmed => $_->get_column('confirmed_count') } $alerts->all; $alert_counts{0} ||= 0; $alert_counts{1} ||= 0; @@ -57,10 +78,16 @@ sub index : Path : Args(0) { $c->stash->{alerts} = \%alert_counts; my $contacts = $c->model('DB::Contact')->search( - undef, { group_by => ['confirmed'], select => [ 'confirmed', { count => 'id' } ], as => [qw/confirmed confirmed_count/] } + undef, + { + group_by => ['confirmed'], + select => [ 'confirmed', { count => 'id' } ], + as => [qw/confirmed confirmed_count/] + } ); - my %contact_counts = map { $_->confirmed => $_->get_column( 'confirmed_count' ) } $contacts->all; + my %contact_counts = + map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; $contact_counts{0} ||= 0; $contact_counts{1} ||= 0; @@ -69,15 +96,28 @@ sub index : Path : Args(0) { $c->stash->{contacts} = \%contact_counts; my $questionnaires = $c->model('DB::Questionnaire')->search( - undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/], join => 'problem' } + undef, + { + group_by => [ \'whenanswered is not null' ], + select => [ \'(whenanswered is not null)', { count => 'me.id' } ], + as => [qw/answered questionnaire_count/], + join => 'problem' + } ); - my %questionnaire_counts = map { $_->get_column( 'answered' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all; + my %questionnaire_counts = map { + $_->get_column('answered') => $_->get_column('questionnaire_count') + } $questionnaires->all; $questionnaire_counts{1} ||= 0; $questionnaire_counts{0} ||= 0; - $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1}; - $c->stash->{questionnaires_pc} = $questionnaire_counts{total} ? sprintf('%.1f', $questionnaire_counts{1} / $questionnaire_counts{total} * 100) : 'na'; + $questionnaire_counts{total} = + $questionnaire_counts{0} + $questionnaire_counts{1}; + $c->stash->{questionnaires_pc} = + $questionnaire_counts{total} + ? sprintf( '%.1f', + $questionnaire_counts{1} / $questionnaire_counts{total} * 100 ) + : 'na'; $c->stash->{questionnaires} = \%questionnaire_counts; return 1; -- cgit v1.2.3 From 040e507c4e0be26c777ca21c06f1cb45c17749f3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 2 Jun 2011 18:43:43 +0100 Subject: council list admin page --- perllib/FixMyStreet/App/Controller/Admin.pm | 112 +++++++++++++--------------- 1 file changed, 50 insertions(+), 62 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 304eafd1c..fcc55cba0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -4,7 +4,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -use mySociety::Random qw(random_bytes); +use POSIX qw(strftime strcoll); =head1 NAME @@ -143,6 +143,55 @@ sub questionnaire : Path('questionnaire') : Args(0) { return 1; } + +sub council_list : Path('council_list') : Args(0) { + my ( $self, $c ) = @_; + + my $edit_activity = $c->model('DB::ContactsHistory')->search( + undef, + { + select => [ 'editor', { count => 'contacts_history_id', -as => 'c' } ], + group_by => ['editor'], + order_by => { -desc => 'c' } + } + ); + + $c->stash->{edit_activity} = $edit_activity; + + my @area_types = $c->cobrand->area_types; + my $areas = mySociety::MaPit::call('areas', \@area_types); + + my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; + # this is for norway only - put in cobrand + @councils_ids = grep { $_ ne 301 } @councils_ids; + + my $contacts = $c->model('DB::Contact')->search( + undef, + { + select => [ 'area_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' }, + { count => \'case when confirmed then 1 else null end' } ], + as => [qw/area_id c deleted confirmed/], + group_by => [ 'area_id' ], + result_class => 'DBIx::Class::ResultClass::HashRefInflator' + } + ); + + my %council_info = map { $_->{area_id} => $_ } $contacts->all; + + my @no_info = grep { !$council_info{$_} } @councils_ids; + my @one_plus_deleted = grep { $council_info{$_} && $council_info{$_}->{deleted} } @councils_ids; + my @unconfirmeds = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} != $council_info{$_}->{c} } @councils_ids; + my @all_confirmed = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} == $council_info{$_}->{c} } @councils_ids; + + $c->stash->{areas} = $areas; + $c->stash->{counts} = \%council_info; + $c->stash->{no_info} = \@no_info; + $c->stash->{one_plus_deleted} = \@one_plus_deleted; + $c->stash->{unconfirmeds} = \@unconfirmeds; + $c->stash->{all_confirmed} = \@all_confirmed; + + return 1; +} # use Encode; # use POSIX qw(strftime strcoll); # use Digest::MD5 qw(md5_hex); @@ -222,67 +271,6 @@ sub questionnaire : Path('questionnaire') : Args(0) { # } # # -# # admin_councils_list CGI -# sub admin_councils_list ($) { -# my ($q) = @_; -# -# print html_head($q, _("Council contacts")); -# print $q->h1(_("Council contacts")); -# -# # Table of editors -# 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"); -# if (@$edit_activity) { -# print $q->ul( -# map { $q->li( sprintf(_('%d edits by %s'), $_->[0], $_->[1])) } @$edit_activity -# ); -# } else { -# print $q->p(_('No edits have yet been made.')); -# } -# -# # Table of councils -# 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 { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; -# @councils_ids = grep { $_ ne 301 } @councils_ids; -# my $bci_info = dbh()->selectall_hashref(" -# select area_id, count(*) as c, count(case when deleted then 1 else null end) as deleted, -# count(case when confirmed then 1 else null end) as confirmed -# from contacts group by area_id", 'area_id'); -# -# my $list_part = sub { -# my @ids = @_; -# if (!scalar(@ids)) { -# print _("None"); -# return; -# } -# 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' ? -# sprintf(_('%d addresses'), $bci_info->{$_}->{c}) -# : '')); -# } -# print $q->ul(@li); -# }; -# -# print $q->h3(_('No info at all')); -# &$list_part(grep { !$bci_info->{$_} } @councils_ids); -# print $q->h3(_('Currently has 1+ deleted')); -# &$list_part(grep { $bci_info->{$_} && $bci_info->{$_}->{deleted} } @councils_ids); -# print $q->h3(_('Some unconfirmeds')); -# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} != $bci_info->{$_}->{c} } @councils_ids); -# print $q->h3(_('All confirmed')); -# &$list_part(grep { $bci_info->{$_} && !$bci_info->{$_}->{deleted} && $bci_info->{$_}->{confirmed} == $bci_info->{$_}->{c} } @councils_ids); -# print html_tail($q); -# } # # # admin_council_contacts CGI AREA_ID # sub admin_council_contacts ($$) { -- cgit v1.2.3 From 5fc8740c80bc83c4b08a3d813f3bf7a8612474cd Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 12:16:37 +0100 Subject: council contacts admin page --- perllib/FixMyStreet/App/Controller/Admin.pm | 311 +++++++++++++--------------- 1 file changed, 144 insertions(+), 167 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index fcc55cba0..3fef589b4 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use POSIX qw(strftime strcoll); +use Digest::MD5 qw(md5_hex); =head1 NAME @@ -192,9 +193,117 @@ sub council_list : Path('council_list') : Args(0) { return 1; } + +sub council_contacts : Path('council_contacts') : Args(1) { + my ( $self, $c, $area_id ) = @_; + + my $posted = $c->req->param('posted') || ''; + $c->stash->{area_id} = $area_id; + + $c->forward( 'get_token' ); + + if ( $posted ) { + $c->log->debug( 'posted' ); + $c->forward('update_contacts'); + } + + $c->forward('display_contacts'); + + return 1; +} + +sub update_contacts : Private { + my ( $self, $c ) = @_; + + my $posted = $c->req->param('posted'); + my $editor = $c->req->remote_user || _('*unknown*'); + + if ( $posted eq 'new' ) { + $c->forward('check_token'); + + my $category = $self->trim( $c->req->param( 'category' ) ); + my $email = $self->trim( $c->req->param( 'email' ) ); + + $category = 'Empty property' if $c->cobrand->moniker eq 'emptyhomes'; + + my $contact = $c->model('DB::Contact')->find_or_new( + { + area_id => $c->stash->{area_id}, + category => $category, + } + ); + + $contact->email( $email ); + $contact->confirmed( $c->req->param('confirmed') ? 1 : 0 ); + $contact->deleted( $c->req->param('deleted') ? 1 : 0 ); + $contact->note( $c->req->param('note') ); + $contact->whenedited( \'ms_current_timestamp()' ); + $contact->editor( $editor ); + + if ( $contact->in_storage ) { + $c->stash->{updated} = _('Values updated'); + + # NB: History is automatically stored by a trigger in the database + $contact->update; + } else { + $c->stash->{updated} = _('New category contact added'); + $contact->insert; + } + + } elsif ( $posted eq 'update' ) { + $c->forward('check_token'); + + my @categories = $c->req->param('confirmed'); + + my $contacts = $c->model('DB::Contact')->search( + { + area_id => $c->stash->{area_id}, + category => { -in => \@categories }, + } + ); + + $contacts->update( + { + confirmed => 1, + whenedited => \'ms_current_timestamp()', + note => 'Confirmed', + editor => $editor, + } + ); + + $c->stash->{updated} = _('Values updated'); + } +} + +sub display_contacts : Private { + my ( $self, $c ) = @_; + + my $area_id = $c->stash->{area_id}; + + my $contacts = $c->model('DB::Contact')->search( + { area_id => $area_id }, + { order_by => ['category'] } + ); + + $c->stash->{contacts} = $contacts; + + if ( $c->req->param('text') == 1 ) { + $c->stash->{template} = 'admin/council_contacts.txt'; + $c->res->content_encoding('text/plain'); + return 1; + } + + my $mapit_data = mySociety::MaPit::call('area', $area_id); + $c->stash->{council_name} = $mapit_data->{name}; + + my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); + + if ($example_postcode && ! ref $example_postcode) { + $c->stash->{example_pc} = $example_postcode; + } +} + # use Encode; -# use POSIX qw(strftime strcoll); -# use Digest::MD5 qw(md5_hex); # # use Page; # use mySociety::Config; @@ -203,17 +312,32 @@ sub council_list : Path('council_list') : Args(0) { # use mySociety::VotingArea; # use mySociety::Web qw(NewURL ent); # -# =item get_token Q -# -# Generate a token based on user and secret -# -# =cut -# sub get_token { -# my ($q) = @_; -# my $secret = scalar(dbh()->selectrow_array('select secret from secret')); -# my $token = md5_hex(($q->remote_user() . $secret)); -# return $token; -# } +=item get_token + +Generate a token based on user and secret + +=cut +sub get_token : Private { + my ( $self, $c ) = @_; + + my $secret = $c->model('DB::Secret')->search()->first; + + my $token = md5_hex(($c->req->remote_user() . $secret->secret)); + + $c->stash->{token} = $token; + + return 1; +} + +sub check_token : Private { + my ( $self, $c ) = @_; + + if ( $c->req->param('token' ) ne $c->stash->{token} ) { + $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + } + + return 1; +} # # =item allowed_pages Q # @@ -271,154 +395,6 @@ sub council_list : Path('council_list') : Args(0) { # } # # -# -# # admin_council_contacts CGI AREA_ID -# sub admin_council_contacts ($$) { -# my ($q, $area_id) = @_; -# -# # Submit form -# my $updated = ''; -# my $posted = $q->param('posted') || ''; -# if ($posted eq 'new') { -# return not_found($q) if $q->param('token') ne get_token($q); -# my $email = trim($q->param('email')); -# my $category = trim($q->param('category')); -# $category = 'Empty property' if $q->{site} eq 'emptyhomes'; -# # History is automatically stored by a trigger in the database -# my $update = dbh()->do("update contacts set -# email = ?, -# confirmed = ?, -# deleted = ?, -# editor = ?, -# whenedited = ms_current_timestamp(), -# note = ? -# where area_id = ? -# and category = ? -# ", {}, -# $email, ($q->param('confirmed') ? 1 : 0), -# ($q->param('deleted') ? 1 : 0), -# ($q->remote_user() || _("*unknown*")), $q->param('note'), -# $area_id, $category -# ); -# $updated = $q->p($q->em(_("Values updated"))); -# unless ($update > 0) { -# dbh()->do('insert into contacts -# (area_id, category, email, editor, whenedited, note, confirmed, deleted) -# values -# (?, ?, ?, ?, ms_current_timestamp(), ?, ?, ?)', {}, -# $area_id, $category, $email, -# ($q->remote_user() || _('*unknown*')), $q->param('note'), -# ($q->param('confirmed') ? 1 : 0), ($q->param('deleted') ? 1 : 0) -# ); -# $updated = $q->p($q->em(_("New category contact added"))); -# } -# dbh()->commit(); -# } elsif ($posted eq 'update') { -# return not_found($q) if $q->param('token') ne get_token($q); -# my @cats = $q->param('confirmed'); -# foreach my $cat (@cats) { -# 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 -# ); -# } -# $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); -# -# if ($q->param('text')) { -# print $q->header(-type => 'text/plain', -charset => 'utf-8'); -# foreach my $l (@$bci_data) { -# next if $l->{deleted} || !$l->{confirmed}; -# print $l->{category} . "\t" . $l->{email} . "\n"; -# } -# return; -# } -# -# $q->delete_all(); # No need for state! -# -# # Title -# my $mapit_data = mySociety::MaPit::call('area', $area_id); -# my $title = sprintf(_('Council contacts for %s'), $mapit_data->{name}); -# print html_head($q, $title); -# print $q->h1($title); -# print $updated; -# -# # Example postcode, link to list of problem reports -# my $links_html; -# my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); -# if ($example_postcode && ! ref $example_postcode) { -# $links_html .= $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, -# "Example postcode " . $example_postcode) . " | "; -# } -# $links_html .= ' ' . -# $q->a({ href => mySociety::Config::get('BASE_URL') . "/reports?council=" . $area_id }, _(" List all reported problems")); -# $links_html .= ' ' . -# $q->a({ href => NewURL($q, area_id => $area_id, page => 'councilcontacts', text => 1) }, _('Text only version')); -# print $q->p($links_html); -# -# # Display of addresses / update statuses form -# print $q->start_form(-method => 'POST', -action => './'); -# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); -# print $q->Tr({}, $q->th({}, [_("Category"), _("Email"), _("Confirmed"), _("Deleted"), _("Last editor"), _("Note"), _("When edited"), _('Confirm')])); -# foreach my $l (@$bci_data) { -# print $q->Tr($q->td([ -# $q->a({ href => NewURL($q, area_id => $area_id, category => $l->{category}, page => 'counciledit') }, -# $l->{category}), $l->{email}, $l->{confirmed} ? _('Yes') : _('No'), -# $l->{deleted} ? _('Yes') : _('No'), $l->{editor}, ent($l->{note}), -# $l->{whenedited} =~ m/^(.+)\.\d+$/, -# $q->checkbox(-name => 'confirmed', -value => $l->{category}, -label => '') -# ])); -# } -# print $q->end_table(); -# # XXX -# print $q->p( -# $q->hidden('area_id', $area_id), -# $q->hidden('posted', 'update'), -# $q->hidden('token', get_token($q)), -# $q->hidden('page', 'councilcontacts'), -# $q->submit(_('Update statuses')) -# ); -# print $q->end_form(); -# -# # Display form for adding new category -# print $q->h2(_('Add new category')); -# print $q->start_form(-method => 'POST', -action => './'); -# if ($q->{site} ne 'emptyhomes') { -# print $q->p($q->strong(_("Category: ")), -# $q->textfield(-name => "category", -size => 30)); -# } -# print $q->p($q->strong(_("Email: ")), -# $q->textfield(-name => "email", -size => 30)); -# $q->autoEscape(0); -# print $q->p( -# $q->checkbox(-id => 'confirmed', -name => "confirmed", -value => 1, -label => ' ' . $q->label({-for => 'confirmed'}, _('Confirmed'))), -# ' ', -# $q->checkbox(-id => 'deleted', -name => "deleted", -value => 1, -label => ' ' . $q->label({-for => 'deleted'}, _('Deleted'))) -# ); -# $q->autoEscape(1); -# print $q->p($q->strong(_("Note: ")), -# $q->textarea(-name => "note", -rows => 3, -columns=>40)); -# print $q->p( -# $q->hidden('area_id', $area_id), -# $q->hidden('posted', 'new'), -# $q->hidden('token', get_token($q)), -# $q->hidden('page', 'councilcontacts'), -# $q->submit(_('Create category')) -# ); -# print $q->end_form(); -# -# print html_tail($q); -# } -# # # admin_council_edit CGI AREA_ID CATEGORY # sub admin_council_edit ($$$) { # my ($q, $area_id, $category) = @_; @@ -962,12 +938,13 @@ sub council_list : Path('council_list') : Args(0) { # } # Page::do_fastcgi(\&main); # -# sub trim { -# my $e = shift; -# $e =~ s/^\s+//; -# $e =~ s/\s+$//; -# return $e; -# } +sub trim { + my $self = shift; + my $e = shift; + $e =~ s/^\s+//; + $e =~ s/\s+$//; + return $e; +} =head1 AUTHOR -- cgit v1.2.3 From dcce0c9ec9c24feb3931934bd1a727bdc2ad7ca4 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 13:15:16 +0100 Subject: add contact edit admin page --- perllib/FixMyStreet/App/Controller/Admin.pm | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 3fef589b4..d2ea69c94 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -278,6 +278,8 @@ sub update_contacts : Private { sub display_contacts : Private { my ( $self, $c ) = @_; + $c->forward('setup_council_details'); + my $area_id = $c->stash->{area_id}; my $contacts = $c->model('DB::Contact')->search( @@ -293,7 +295,16 @@ sub display_contacts : Private { return 1; } + return 1; +} + +sub setup_council_details : Private { + my ( $self, $c ) = @_; + + my $area_id = $c->stash->{area_id}; + my $mapit_data = mySociety::MaPit::call('area', $area_id); + $c->stash->{council_name} = $mapit_data->{name}; my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); @@ -301,6 +312,40 @@ sub display_contacts : Private { if ($example_postcode && ! ref $example_postcode) { $c->stash->{example_pc} = $example_postcode; } + + return 1; +} + +sub council_edit : Path('council_edit') : Args(2) { + my ( $self, $c, $area_id, $category ) = @_; + + $c->stash->{area_id} = $area_id; + + $c->forward( 'get_token' ); + $c->forward('setup_council_details'); + + my $contact = $c->model('DB::Contact')->search( + { + area_id => $area_id, + category => $category + } + )->first; + + $c->stash->{contact} = $contact; + + my $history = $c->model('DB::ContactsHistory')->search( + { + area_id => $area_id, + category => $category + }, + { + order_by => ['contacts_history_id'] + }, + ); + + $c->stash->{history} = $history; + + return 1; } # use Encode; -- cgit v1.2.3 From be33cdc1ad3be7136132fdd4f1aa578b60e4571b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 16:08:41 +0100 Subject: add in cobrand restrictions --- perllib/FixMyStreet/App/Controller/Admin.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d2ea69c94..1a9aef81f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -28,8 +28,11 @@ Display contact us page sub index : Path : Args(0) { my ( $self, $c ) = @_; + my ( $sql_resttriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; + my $problems = $c->model('DB::Problem')->search( - undef, + $site_restriction, { group_by => ['state'], select => [ 'state', { count => 'id' } ], @@ -48,11 +51,12 @@ sub index : Path : Args(0) { $prob_counts{confirmed} + $prob_counts{fixed}; my $comments = $c->model('DB::Comment')->search( - undef, + $site_restriction, { - group_by => ['state'], - select => [ 'state', { count => 'id' } ], - as => [qw/state state_count/] + group_by => ['me.state'], + select => [ 'me.state', { count => 'me.id' } ], + as => [qw/state state_count/], + join => 'problem' } ); @@ -62,7 +66,7 @@ sub index : Path : Args(0) { $c->stash->{comments} = \%comment_counts; my $alerts = $c->model('DB::Alert')->search( - undef, + $cobrand_restriction, { group_by => ['confirmed'], select => [ 'confirmed', { count => 'id' } ], @@ -97,7 +101,7 @@ sub index : Path : Args(0) { $c->stash->{contacts} = \%contact_counts; my $questionnaires = $c->model('DB::Questionnaire')->search( - undef, + $cobrand_restriction, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], -- cgit v1.2.3 From 4767d166eca6e8c34d5c7d99c829e36722530852 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 16:09:14 +0100 Subject: some rudimentary tests and some removal of warnings. --- perllib/FixMyStreet/App/Controller/Admin.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 1a9aef81f..b8ef97a2f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -293,7 +293,7 @@ sub display_contacts : Private { $c->stash->{contacts} = $contacts; - if ( $c->req->param('text') == 1 ) { + if ( $c->req->param('text') && $c->req->param('text') == 1 ) { $c->stash->{template} = 'admin/council_contacts.txt'; $c->res->content_encoding('text/plain'); return 1; @@ -371,7 +371,10 @@ sub get_token : Private { my $secret = $c->model('DB::Secret')->search()->first; - my $token = md5_hex(($c->req->remote_user() . $secret->secret)); + my $user = $c->req->remote_user(); + $user ||= ''; + + my $token = md5_hex(($user . $secret->secret)); $c->stash->{token} = $token; -- cgit v1.2.3 From 539206556a45bf5cc03fcb87e2ea1ecdb3a40941 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 16:09:35 +0100 Subject: remove ported code --- perllib/FixMyStreet/App/Controller/Admin.pm | 74 ----------------------------- 1 file changed, 74 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b8ef97a2f..b9ee90dcb 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -447,80 +447,6 @@ sub check_token : Private { # } # # -# # admin_council_edit CGI AREA_ID CATEGORY -# sub admin_council_edit ($$$) { -# my ($q, $area_id, $category) = @_; -# -# # Get all the data -# my $bci_data = select_all("select * from contacts where area_id = ? and category = ?", $area_id, $category); -# $bci_data = $bci_data->[0]; -# my $bci_history = select_all("select * from contacts_history where area_id = ? and category = ? order by contacts_history_id", $area_id, $category); -# my $mapit_data = mySociety::MaPit::call('area', $area_id); -# -# # Title -# my $title = sprintf(_('Council contacts for %s'), $mapit_data->{name}); -# print html_head($q, $title); -# print $q->h1($title); -# -# # Example postcode -# my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); -# if ($example_postcode && ! ref $example_postcode) { -# print $q->p("Example postcode: ", -# $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, -# $example_postcode)); -# } -# -# # Display form for editing details -# print $q->start_form(-method => 'POST', -action => './'); -# map { $q->param($_, $bci_data->{$_}) } qw/category email confirmed deleted/; -# $q->param('page', 'councilcontacts'); -# $q->param('posted', 'new'); -# print $q->strong(_("Category: ")) . $bci_data->{category}; -# print $q->hidden('token', get_token($q)), -# print $q->hidden("category"); -# print $q->strong(' ' . _("Email: ")); -# print $q->textfield(-name => "email", -size => 30) . " "; -# $q->autoEscape(0); -# print $q->checkbox(-id => 'confirmed', -name => "confirmed", -value => 1, -label => ' ' . $q->label({-for => 'confirmed'}, _('Confirmed'))); -# print ' '; -# print $q->checkbox(-id => 'deleted', -name => "deleted", -value => 1, -label => ' ' . $q->label({-for => 'deleted'}, _('Deleted'))); -# $q->autoEscape(1); -# print $q->br(); -# print $q->strong(_("Note: ")); -# print $q->textarea(-name => "note", -rows => 3, -columns=>40) . " "; -# print $q->br(); -# print $q->hidden('area_id'); -# print $q->hidden('posted'); -# print $q->hidden('page'); -# print $q->submit(_('Save changes')); -# print $q->end_form(); -# -# # Display history of changes -# print $q->h2(_('History')); -# print $q->start_table({border=>1}); -# print $q->Tr({}, $q->th({}, [_("When edited"), _("Email"), _("Confirmed"), _("Deleted"), _("Editor"), _("Note")])); -# my $html = ''; -# my $prev = undef; -# foreach my $h (@$bci_history) { -# $h->{confirmed} = $h->{confirmed} ? _("yes") : _("no"), -# $h->{deleted} = $h->{deleted} ? _("yes") : _("no"), -# my $emailchanged = ($prev && $h->{email} ne $prev->{email}) ? 1 : 0; -# my $confirmedchanged = ($prev && $h->{confirmed} ne $prev->{confirmed}) ? 1 : 0; -# my $deletedchanged = ($prev && $h->{deleted} ne $prev->{deleted}) ? 1 : 0; -# $html .= $q->Tr({}, $q->td([ -# $h->{whenedited} =~ m/^(.+)\.\d+$/, -# $emailchanged ? $q->strong($h->{email}) : $h->{email}, -# $confirmedchanged ? $q->strong($h->{confirmed}) : $h->{confirmed}, -# $deletedchanged ? $q->strong($h->{deleted}) : $h->{deleted}, -# $h->{editor}, -# $h->{note} -# ])); -# $prev = $h; -# } -# print $html; -# print $q->end_table(); -# print html_tail($q); -# } # # sub admin_reports { # my $q = shift; -- cgit v1.2.3 From dee51cb3a741be837a41924c96dfef479236401f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 16:20:34 +0100 Subject: move Norway special case into cobrand --- perllib/FixMyStreet/App/Controller/Admin.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b9ee90dcb..99a7a962b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -167,8 +167,7 @@ sub council_list : Path('council_list') : Args(0) { my $areas = mySociety::MaPit::call('areas', \@area_types); my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; - # this is for norway only - put in cobrand - @councils_ids = grep { $_ ne 301 } @councils_ids; + @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); my $contacts = $c->model('DB::Contact')->search( undef, -- cgit v1.2.3 From c297e65b2fb0cf61c5d6a3b2caa477c473fccd96 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 12:32:25 +0100 Subject: search and display reports ( no update display yet ) --- perllib/FixMyStreet/App/Controller/Admin.pm | 145 +++++++++++++++------------- 1 file changed, 80 insertions(+), 65 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 99a7a962b..11194fbcf 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -351,6 +351,86 @@ sub council_edit : Path('council_edit') : Args(2) { return 1; } +sub search_reports : Path('search_reports') { + my ( $self, $c ) = @_; + + $c->forward('set_allowed_pages'); + + + if (my $search = $c->req->param('search')) { + $c->stash->{searched} = 1; + + my $search_n = 0; + $search_n = int($search) if $search =~ /^\d+$/; + + my $like_search = "%$search%"; + + # when DBIC creates the join it does 'JOIN users user' in the + # SQL which makes PostgreSQL unhappy as user is a reserved + # word, hence we need to quote this SQL. However, the quoting + # makes PostgreSQL unhappy elsewhere so we only want to do + # it for this query and then switch it off afterwards. + $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); + + my $problems = $c->model('DB::Problem')->search( + { + -or => [ + 'me.id' => $search_n, + 'user.email' => { ilike => $like_search }, + 'me.name' => { ilike => $like_search }, + title => { ilike => $like_search }, + detail => { ilike => $like_search }, + council => { like => $like_search }, + cobrand_data => { like => $like_search }, + # site restriction + ] + }, + { + prefetch => 'user', + order_by => [\"(state='hidden')",'created'] + } + ); + + $c->stash->{problems} = [ $problems->all ]; + + # Switch quoting back off. See above for explanation of this. + $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); + + $c->stash->{edit_council_contacts} = 1 + if ( grep {$_ eq 'councilcontacts'} keys %{$c->stash->{allowed_pages}}); + } + +# print $q->h2(_('Updates')); +# my $updates = Problems::update_search($search); +# admin_show_updates($q, $updates); +# } + +} + +sub set_allowed_pages : Private { + my ( $self, $c ) = @_; + + my $allowed_pages = $c->cobrand->admin_pages; + + if( !$allowed_pages ) { + $allowed_pages = { + 'summary' => [_('Summary'), 0], + 'councilslist' => [_('Council contacts'), 1], + 'reports' => [_('Search Reports'), 2], + 'timeline' => [_('Timeline'), 3], + 'questionnaire' => [_('Survey Results'), 4], + 'councilcontacts' => [undef, undef], + 'counciledit' => [undef, undef], + 'report_edit' => [undef, undef], + 'update_edit' => [undef, undef], + } + } + + $c->stash->{allowed_pages} = $allowed_pages; + + return 1; +} + # use Encode; # # use Page; @@ -448,71 +528,6 @@ sub check_token : Private { # # # sub admin_reports { -# my $q = shift; -# my $title = _('Search Reports'); -# my $cobrand = Page::get_cobrand($q); -# my $pages = allowed_pages($q); -# print html_head($q, $title); -# print $q->h1($title); -# print $q->start_form(-method => 'GET', -action => './'); -# print $q->label({-for => 'search'}, _('Search:')), ' ', $q->textfield(-id => 'search', -name => "search", -size => 30); -# print $q->hidden('page'); -# print $q->end_form; -# -# if (my $search = $q->param('search')) { -# my $results = Problems::problem_search($search); -# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); -# print $q->Tr({}, $q->th({}, [_('ID'), _('Title'), _('Name'), _('Email'), _('Council'), _('Category'), _('Anonymous'), _('Cobrand'), _('Created'), _('State'), _('When sent'), _('*') ])); -# my $cobrand_data; -# foreach (@$results) { -# my $url = $_->{id}; -# if ($_->{state} eq 'confirmed' || $_->{state} eq 'fixed') { -# # if this is a cobranded admin interface, but we're looking at a generic problem, figure out enough information -# # to create a URL to the cobranded version of the problem -# if ($_->{cobrand}) { -# $cobrand_data = $_->{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, $_); -# } -# $url = $q->a({ -href => Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $_->{id} }, $url); -# } -# my $council = $_->{council} || ' '; -# my $category = $_->{category} || ' '; -# (my $confirmed = $_->{confirmed} || '-') =~ s/ (.*?)\..*/ $1/; -# (my $created = $_->{created}) =~ s/\..*//; -# (my $lastupdate = $_->{lastupdate}) =~ s/ (.*?)\..*/ $1/; -# (my $whensent = $_->{whensent} || ' ') =~ s/\..*//; -# my $state = $_->{state}; -# $state .= ''; -# $state .= "
    " . _('Confirmed:') . " $confirmed" if $_->{state} eq 'confirmed' || $_->{state} eq 'fixed'; -# $state .= '
    ' . _('Fixed:') . ' ' . $lastupdate if $_->{state} eq 'fixed'; -# $state .= "
    " . _('Last update:') . " $lastupdate" if $_->{state} eq 'confirmed'; -# $state .= '
    '; -# my $anonymous = $_->{anonymous} ? _('Yes') : _('No'); -# my $cobrand = $_->{cobrand}; -# $cobrand .= "
    " . $_->{cobrand_data}; -# my $counciltext = ''; -# if (grep {$_ eq 'councilcontacts'} keys %{$pages}) { -# $counciltext = $q->a({ -href => NewURL($q, page=>'councilcontacts', area_id=>$council)}, $council); -# } else { -# $counciltext = $council; -# } -# my $attr = {}; -# $attr->{-class} = 'hidden' if $_->{state} eq 'hidden'; -# print $q->Tr($attr, $q->td([ $url, ent($_->{title}), ent($_->{name}), ent($_->{email}), -# $counciltext, -# $category, $anonymous, $cobrand, $created, $state, $whensent, -# $q->a({ -href => NewURL($q, page=>'report_edit', id=>$_->{id}) }, _('Edit')) -# ])); -# } -# print $q->end_table; -# -# print $q->h2(_('Updates')); -# my $updates = Problems::update_search($search); -# admin_show_updates($q, $updates); -# } -# -# print html_tail($q); # } # # sub admin_edit_report { -- cgit v1.2.3 From a2645f6a8a93fa5564a5753bcafd54e8a3074814 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 14:14:38 +0100 Subject: display updates on report search page --- perllib/FixMyStreet/App/Controller/Admin.pm | 37 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 11194fbcf..568d23cf5 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -360,6 +360,8 @@ sub search_reports : Path('search_reports') { if (my $search = $c->req->param('search')) { $c->stash->{searched} = 1; + my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my $search_n = 0; $search_n = int($search) if $search =~ /^\d+$/; @@ -382,7 +384,7 @@ sub search_reports : Path('search_reports') { detail => { ilike => $like_search }, council => { like => $like_search }, cobrand_data => { like => $like_search }, - # site restriction + %{ $site_restriction }, ] }, { @@ -393,18 +395,34 @@ sub search_reports : Path('search_reports') { $c->stash->{problems} = [ $problems->all ]; - # Switch quoting back off. See above for explanation of this. - $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); $c->stash->{edit_council_contacts} = 1 if ( grep {$_ eq 'councilcontacts'} keys %{$c->stash->{allowed_pages}}); - } -# print $q->h2(_('Updates')); -# my $updates = Problems::update_search($search); -# admin_show_updates($q, $updates); -# } + my $updates = $c->model('DB::Comment')->search( + { + -or => [ + 'me.id' => $search_n, + 'problem.id' => $search_n, + 'user.email' => { ilike => $like_search }, + 'me.name' => { ilike => $like_search }, + text => { ilike => $like_search }, + 'me.cobrand_data' => { ilike => $like_search }, + %{ $site_restriction }, + ] + }, + { + -select => [ 'me.*', qw/problem.council problem.state/ ], + prefetch => [qw/user problem/], + order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] + } + ); + + $c->stash->{updates} = [ $updates->all ]; + # Switch quoting back off. See above for explanation of this. + $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); + } } sub set_allowed_pages : Private { @@ -527,9 +545,6 @@ sub check_token : Private { # # # -# sub admin_reports { -# } -# # sub admin_edit_report { # my ($q, $id) = @_; # my $row = Problems::admin_fetch_problem($id); -- cgit v1.2.3 From 54f8fbc34c7842d8e31775e99997cc291c20f310 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 14:53:34 +0100 Subject: use allowed pages for generating nav bar --- perllib/FixMyStreet/App/Controller/Admin.pm | 35 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 568d23cf5..cac8aee0a 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -25,9 +25,16 @@ Display contact us page =cut +sub summary : Path( 'summary' ) : Args(0) { + my ( $self, $c ) = @_; + $c->go( 'index' ); +} + sub index : Path : Args(0) { my ( $self, $c ) = @_; + $c->forward('set_allowed_pages'); + my ( $sql_resttriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; @@ -131,6 +138,8 @@ sub index : Path : Args(0) { sub questionnaire : Path('questionnaire') : Args(0) { my ( $self, $c ) = @_; + $c->forward('set_allowed_pages'); + my $questionnaires = $c->model('DB::Questionnaire')->search( { whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] } ); @@ -152,6 +161,8 @@ sub questionnaire : Path('questionnaire') : Args(0) { sub council_list : Path('council_list') : Args(0) { my ( $self, $c ) = @_; + $c->forward('set_allowed_pages'); + my $edit_activity = $c->model('DB::ContactsHistory')->search( undef, { @@ -200,6 +211,8 @@ sub council_list : Path('council_list') : Args(0) { sub council_contacts : Path('council_contacts') : Args(1) { my ( $self, $c, $area_id ) = @_; + $c->forward('set_allowed_pages'); + my $posted = $c->req->param('posted') || ''; $c->stash->{area_id} = $area_id; @@ -322,6 +335,8 @@ sub setup_council_details : Private { sub council_edit : Path('council_edit') : Args(2) { my ( $self, $c, $area_id, $category ) = @_; + $c->forward('set_allowed_pages'); + $c->stash->{area_id} = $area_id; $c->forward( 'get_token' ); @@ -356,7 +371,6 @@ sub search_reports : Path('search_reports') { $c->forward('set_allowed_pages'); - if (my $search = $c->req->param('search')) { $c->stash->{searched} = 1; @@ -428,23 +442,26 @@ sub search_reports : Path('search_reports') { sub set_allowed_pages : Private { my ( $self, $c ) = @_; - my $allowed_pages = $c->cobrand->admin_pages; + my $pages = $c->cobrand->admin_pages; - if( !$allowed_pages ) { - $allowed_pages = { + if( !$pages ) { + $pages = { 'summary' => [_('Summary'), 0], - 'councilslist' => [_('Council contacts'), 1], - 'reports' => [_('Search Reports'), 2], + 'council_list' => [_('Council contacts'), 1], + 'search_reports' => [_('Search Reports'), 2], 'timeline' => [_('Timeline'), 3], 'questionnaire' => [_('Survey Results'), 4], - 'councilcontacts' => [undef, undef], - 'counciledit' => [undef, undef], + 'council_contacts' => [undef, undef], + 'council_edit' => [undef, undef], 'report_edit' => [undef, undef], 'update_edit' => [undef, undef], } } - $c->stash->{allowed_pages} = $allowed_pages; + my @allowed_links = sort {$pages->{$a}[1] <=> $pages->{$b}[1]} grep {$pages->{$_}->[0] } keys %$pages; + + $c->stash->{allowed_pages} = $pages; + $c->stash->{allowed_links} = \@allowed_links; return 1; } -- cgit v1.2.3 From 30cc0004a14ec330ea693a6b6f94e059a4e6abdd Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 19:33:43 +0100 Subject: edit report admin function --- perllib/FixMyStreet/App/Controller/Admin.pm | 264 +++++++++++++++------------- 1 file changed, 137 insertions(+), 127 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index cac8aee0a..e1a1f9469 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -439,6 +439,130 @@ sub search_reports : Path('search_reports') { } } +sub report_edit : Path('report_edit') : Args(1) { + my ( $self, $c, $id ) = @_; + + my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + + my $problem = $c->model('DB::Problem')->search( + { + id => $id, + %{ $site_restriction }, + } + )->first; + + $c->detach( '/page_error_404_not_found', + [ _('The requested URL was not found on this server.') ] ) + unless $problem; + + $c->stash->{problem} = $problem; + + $c->forward('get_token'); + $c->forward('set_allowed_pages'); + + $c->stash->{updates} = + [ $c->model('DB::Comment') + ->search( { problem_id => $problem->id }, { order_by => 'created' } ) + ->all ]; + + if ( $c->req->param('resend') ) { + $c->forward('check_token'); + + $problem->whensent(undef); + $problem->update(); + $c->stash->{status_message} = + '

    ' . _('That problem will now be resent.') . '

    '; + + $c->forward( 'log_edit', [ $id, 'problem', 'resend' ] ); + } + elsif ( $c->req->param('submit') ) { + $c->forward('check_token'); + + my $done = 0; + my $edited = 0; + + my $new_state = $c->req->param('state'); + my $old_state = $problem->state; + if ( $new_state eq 'confirmed' + && $problem->state eq 'unconfirmed' + && $c->cobrand->moniker eq 'emptyhomes' ) + { + $c->stash->{status_message} = + '

    ' + . _('I am afraid you cannot confirm unconfirmed reports.') + . '

    '; + $done = 1; + } + + # do this here so before we update the values in problem + if ( $c->req->param('anonymous') ne $problem->anonymous + || $c->req->param('name') ne $problem->name + || $c->req->param('email') ne $problem->user->email + || $c->req->param('title') ne $problem->title + || $c->req->param('detail') ne $problem->detail ) + { + $edited = 1; + } + + $problem->anonymous( $c->req->param('anonymous') ); + $problem->title( $c->req->param('title') ); + $problem->detail( $c->req->param('detail') ); + $problem->state( $c->req->param('state') ); + $problem->name( $c->req->param('name') ); + + if ( $c->req->param('email') ne $problem->user->email ) { + my $user = $c->model('DB::User')->find_or_create( + { email => $c->req->param('email') } + ); + + $user->insert unless $user->in_storage; + $problem->user( $user ); + } + + if ( $c->req->param('remove_photo') ) { + $problem->photo(undef); + } + + if ( $new_state ne $old_state ) { + $problem->lastupdate( \'ms_current_timestamp()' ); + } + + if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) { + $problem->confirmed( \'ms_current_timestamp()' ); + } + + if ($done) { + $problem->discard_changes; + } + else { + $problem->update; + + if ( $new_state ne $old_state ) { + $c->forward( 'log_edit', [ $id, 'problem', 'state_change' ] ); + } + if ($edited) { + $c->forward( 'log_edit', [ $id, 'problem', 'edit' ] ); + } + + $c->stash->{status_message} = + '

    ' . _('Updated!') . '

    '; + + # do this here otherwise lastupdate and confirmed times + # do not display correctly + $problem->discard_changes; + } + } + +# my $cobrand_data; +# if ($row{cobrand}) { +# $cobrand_data = $row{cobrand_data}; +# } else { +# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, \%row); +# } + + return 1; +} + sub set_allowed_pages : Private { my ( $self, $c ) = @_; @@ -504,6 +628,19 @@ sub check_token : Private { return 1; } + + +sub log_edit : Private { + my ( $self, $c, $id, $object_type, $action ) = @_; + $c->model('DB::AdminLog')->create( + { + admin_user => ( $c->req->remote_user() || '' ), + object_type => $object_type, + action => $action, + object_id => $id, + } + )->insert(); +} # # =item allowed_pages Q # @@ -562,127 +699,6 @@ sub check_token : Private { # # # -# sub admin_edit_report { -# my ($q, $id) = @_; -# my $row = Problems::admin_fetch_problem($id); -# my $cobrand = Page::get_cobrand($q); -# return not_found($q) if ! $row->[0]; -# my %row = %{$row->[0]}; -# my $status_message = ''; -# if ($q->param('resend')) { -# return not_found($q) if $q->param('token') ne get_token($q); -# dbh()->do('update problem set whensent=null where id=?', {}, $id); -# admin_log_edit($q, $id, 'problem', 'resend'); -# dbh()->commit(); -# $status_message = '

    ' . _('That problem will now be resent.') . '

    '; -# } elsif ($q->param('submit')) { -# return not_found($q) if $q->param('token') ne get_token($q); -# my $new_state = $q->param('state'); -# my $done = 0; -# if ($new_state eq 'confirmed' && $row{state} eq 'unconfirmed' && $q->{site} eq 'emptyhomes') { -# $status_message = '

    ' . _('I am afraid you cannot confirm unconfirmed reports.') . '

    '; -# $done = 1; -# } -# my $query = 'update problem set anonymous=?, state=?, name=?, email=?, title=?, detail=?'; -# if ($q->param('remove_photo')) { -# $query .= ', photo=null'; -# } -# if ($new_state ne $row{state}) { -# $query .= ', lastupdate=current_timestamp'; -# } -# if ($new_state eq 'confirmed' and $row{state} eq 'unconfirmed') { -# $query .= ', confirmed=current_timestamp'; -# } -# $query .= ' where id=?'; -# unless ($done) { -# dbh()->do($query, {}, $q->param('anonymous') ? 't' : 'f', $new_state, -# $q->param('name'), $q->param('email'), $q->param('title'), $q->param('detail'), $id); -# if ($new_state ne $row{state}) { -# admin_log_edit($q, $id, 'problem', 'state_change'); -# } -# if ($q->param('anonymous') ne $row{anonymous} || -# $q->param('name') ne $row{name} || -# $q->param('email') ne $row{email} || -# $q->param('title') ne $row{title} || -# $q->param('detail') ne $row{detail}) { -# admin_log_edit($q, $id, 'problem', 'edit'); -# } -# dbh()->commit(); -# map { $row{$_} = $q->param($_) } qw(anonymous state name email title detail); -# $status_message = '

    ' . _('Updated!') . '

    '; -# } -# } -# my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row; -# my $title = sprintf(_("Editing problem %d"), $id); -# print html_head($q, $title); -# print $q->h1($title); -# print $status_message; -# -# my $council = $row{council} || '' . _('None') . ''; -# (my $areas = $row{areas}) =~ s/^,(.*),$/$1/; -# my $latitude = $row{latitude}; -# my $longitude = $row{longitude}; -# my $questionnaire = $row{send_questionnaire} ? _('Yes') : _('No'); -# my $used_map = $row{used_map} ? _('used map') : _("didn't use map"); -# (my $whensent = $row{whensent} || ' ') =~ s/\..*//; -# (my $confirmed = $row{confirmed} || '-') =~ s/ (.*?)\..*/ $1/; -# my $photo = ''; -# my $cobrand_data; -# if ($row{cobrand}) { -# $cobrand_data = $row{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, \%row); -# } -# $photo = '
  • -# -# ' if $row{photo}; -# -# my $url_base = Cobrand::base_url_for_emails($cobrand, $cobrand_data); -# my $url = $url_base . '/report/' . $row{id}; -# -# my $anon = $q->label({-for=>'anonymous'}, _('Anonymous:')) . ' ' . $q->popup_menu(-id => 'anonymous', -name => 'anonymous', -values => { 1=>_('Yes'), 0=>_('No') }, -default => $row{anonymous}); -# my $state = $q->label({-for=>'state'}, _('State:')) . ' ' . $q->popup_menu(-id => 'state', -name => 'state', -values => { confirmed => _('Open'), fixed => _('Fixed'), hidden => _('Hidden'), unconfirmed => _('Unconfirmed'), partial => _('Partial') }, -default => $row{state}); -# -# my $resend = ''; -# $resend = ' ' if $row{state} eq 'confirmed'; -# -# print $q->start_form(-method => 'POST', -action => './'); -# print $q->hidden('page'); -# print $q->hidden('id'); -# print $q->hidden('token', get_token($q)); -# print $q->hidden('submit', 1); -# print " -#
      -#
    • " . _('View report on site') . " -#
    • -#

    • -#
    • " . _('Co-ordinates:') . " $latitude,$longitude (" . _('originally entered') . " $row_h{postcode}, $used_map) -#
    • " . _('For council(s):') . " $council (" . _('other areas:') . " $areas) -#
    • $anon -#
    • $state -#
    • " . _('Category:') . " $row{category} -#
    • " . _('Name:') . " -#
    • " . _('Email:') . " -#
    • " . _('Phone:') . " $row_h{phone} -#
    • " . _('Created:') . " $row{created} -#
    • " . _('Confirmed:') . " $confirmed -#
    • " . _('Sent:') . " $whensent $resend -#
    • " . _('Last update:') . " $row{lastupdate} -#
    • " . _('Service:') . " $row{service} -#
    • " . _('Cobrand:') . " $row{cobrand} -#
    • " . _('Cobrand data:') . " $row{cobrand_data} -#
    • " . _('Going to send questionnaire?') . " $questionnaire -# $photo -#
    -# "; -# print $q->submit(_('Submit changes')); -# print $q->end_form; -# -# print $q->h2(_('Updates')); -# my $updates = select_all('select * from comment where problem_id=? order by created', $id); -# admin_show_updates($q, $updates); -# print html_tail($q); -# } # # sub admin_show_updates { # my ($q, $updates) = @_; @@ -805,12 +821,6 @@ sub check_token : Private { # return $cobrand_data; # } # -# sub admin_log_edit { -# my ($q, $id, $object_type, $action) = @_; -# my $query = "insert into admin_log (admin_user, object_type, object_id, action) -# values (?, ?, ?, ?);"; -# dbh()->do($query, {}, $q->remote_user(), $object_type, $id, $action); -# } # # sub admin_timeline { # my $q = shift; -- cgit v1.2.3 From 9be9e98438681d2e3b56724269793811d9c0a46c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 19:35:02 +0100 Subject: remove implemented code --- perllib/FixMyStreet/App/Controller/Admin.pm | 100 ---------------------------- 1 file changed, 100 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index e1a1f9469..0f6de6e38 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -553,13 +553,6 @@ sub report_edit : Path('report_edit') : Args(1) { } } -# my $cobrand_data; -# if ($row{cobrand}) { -# $cobrand_data = $row{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, \%row); -# } - return 1; } @@ -641,93 +634,6 @@ sub log_edit : Private { } )->insert(); } -# -# =item allowed_pages Q -# -# Return a hash of allowed pages, keyed on page param. The values of the hash -# are arrays of the form [link_text, link_order]. Pages without link_texts -# are not to be included in the main admin menu. -# =cut -# sub allowed_pages($) { -# my ($q) = @_; -# my $cobrand = Page::get_cobrand($q); -# my $pages = Cobrand::admin_pages($cobrand); -# if (!$pages) { -# $pages = { -# 'summary' => [_('Summary'), 0], -# 'councilslist' => [_('Council contacts'), 1], -# 'reports' => [_('Search Reports'), 2], -# 'timeline' => [_('Timeline'), 3], -# 'questionnaire' => [_('Survey Results'), 4], -# 'councilcontacts' => [undef, undef], -# 'counciledit' => [undef, undef], -# 'report_edit' => [undef, undef], -# 'update_edit' => [undef, undef], -# }; -# } -# return $pages; -# } -# -# sub html_head($$) { -# my ($q, $title) = @_; -# my $ret = $q->header(-type => 'text/html', -charset => 'utf-8'); -# my $site_title = _('FixMyStreet administration'); -# $ret .= < -# -# $title - $site_title -# -# -# -# END -# my $pages = allowed_pages($q); -# my @links = sort {$pages->{$a}[1] <=> $pages->{$b}[1]} grep {$pages->{$_}->[0] } keys %$pages; -# $ret .= $q->p( -# $q->strong(_("FixMyStreet admin:")), -# map { $q->a( { href => NewURL($q, page => $_) }, $pages->{$_}->[0]) } @links -# ); -# -# return $ret; -# } -# -# sub fetch_data { -# } -# -# -# -# -# sub admin_show_updates { -# my ($q, $updates) = @_; -# my $cobrand = Page::get_cobrand($q); -# print $q->start_table({border=>1, cellpadding=>2, cellspacing=>0}); -# print $q->Tr({}, $q->th({}, [ _('ID'), _('State'), _('Name'), _('Email'), _('Created'), _('Cobrand'), _('Text'), _('*') ])); -# my $base_url = ''; -# my $cobrand_data; -# foreach (@$updates) { -# my $url = $_->{id}; -# if ( $_->{state} eq 'confirmed' ) { -# if ($_->{cobrand}) { -# $cobrand_data = $_->{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_update($cobrand, $_); -# } -# $url = $q->a({ -href => Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $_->{problem_id} . '#update_' . $_->{id} }, -# $url); -# } -# my $cobrand = $_->{cobrand} . '
    ' . $_->{cobrand_data}; -# my $attr = {}; -# $attr->{-class} = 'hidden' if $_->{state} eq 'hidden' || ($_->{problem_state} && $_->{problem_state} eq 'hidden'); -# print $q->Tr($attr, $q->td([ $url, $_->{state}, ent($_->{name} || ''), -# ent($_->{email}), $_->{created}, $cobrand, ent($_->{text}), -# $q->a({ -href => NewURL($q, page=>'update_edit', id=>$_->{id}) }, _('Edit')) -# ])); -# } -# print $q->end_table; -# } # # sub admin_edit_update { # my ($q, $id) = @_; @@ -910,12 +816,6 @@ sub log_edit : Private { # } # # -# sub not_found { -# my ($q) = @_; -# print $q->header(-status=>'404 Not Found',-type=>'text/html'); -# print "

    Not Found

    The requested URL was not found on this server."; -# } -# # sub main { # my $q = shift; # -- cgit v1.2.3 From 61bef11543201b290efdad2cb846d744de7e746c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 11:05:57 +0100 Subject: update edits for admin pages --- perllib/FixMyStreet/App/Controller/Admin.pm | 164 ++++++++++++++-------------- 1 file changed, 83 insertions(+), 81 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0f6de6e38..aeddc12ad 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -634,87 +634,89 @@ sub log_edit : Private { } )->insert(); } -# -# sub admin_edit_update { -# my ($q, $id) = @_; -# my $row = Problems::admin_fetch_update($id); -# return not_found($q) if ! $row->[0]; -# my $cobrand = Page::get_cobrand($q); -# -# my %row = %{$row->[0]}; -# my $status_message = ''; -# if ($q->param('submit')) { -# return not_found($q) if $q->param('token') ne get_token($q); -# my $query = 'update comment set state=?, name=?, email=?, text=?'; -# if ($q->param('remove_photo')) { -# $query .= ', photo=null'; -# } -# $query .= ' where id=?'; -# dbh()->do($query, {}, $q->param('state'), $q->param('name'), $q->param('email'), $q->param('text'), $id); -# $status_message = '

    ' . _('Updated!') . '

    '; -# -# # If we're hiding an update, see if it marked as fixed and unfix if so -# if ($q->param('state') eq 'hidden' && $row{mark_fixed}) { -# dbh()->do("update problem set state='confirmed' where state='fixed' and id=?", {}, $row{problem_id}); -# $status_message .= '

    ' . _('Problem marked as open.') . '

    '; -# } -# -# if ($q->param('state') ne $row{state}) { -# admin_log_edit($q, $id, 'update', 'state_change'); -# } -# if (!defined($row{name})){ -# $row{name} = ""; -# } -# if ($q->param('name') ne $row{name} || $q->param('email') ne $row{email} || $q->param('text') ne $row{text}) { -# admin_log_edit($q, $id, 'update', 'edit'); -# } -# dbh()->commit(); -# map { $row{$_} = $q->param($_) } qw(state name email text); -# } -# my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row; -# my $title = sprintf(_("Editing update %d"), $id); -# print html_head($q, $title); -# print $q->h1($title); -# print $status_message; -# my $name = $row_h{name}; -# $name = '' unless $name; -# my $cobrand_data; -# if ($row{cobrand}) { -# $cobrand_data = $row{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_update($cobrand, \%row); -# } -# my $photo = ''; -# $photo = '
  • -# -# ' if $row{photo}; -# -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/report/' . $row{problem_id} . '#update_' . $row{id}; -# -# my $state = $q->label({-for=>'state'}, _('State:')) . ' ' . $q->popup_menu(-id => 'state', -name => 'state', -values => { confirmed => _('Confirmed'), hidden => _('Hidden'), unconfirmed => _('Unconfirmed') }, -default => $row{state}); -# -# print $q->start_form(-method => 'POST', -action => './'); -# print $q->hidden('page'); -# print $q->hidden('id'); -# print $q->hidden('token', get_token($q)); -# print $q->hidden('submit', 1); -# print " -#
      -#
    • " . _('View update on site') . " -#

    • -#
    • $state -#
    • " . _('Name:') . " " . _('(blank to go anonymous)') . " -#
    • " . _('Email:') . " -#
    • " . _('Cobrand:') . " $row{cobrand} -#
    • " . _('Cobrand data:') . " $row{cobrand_data} -#
    • " . _('Created:') . " $row{created} -# $photo -#
    -# "; -# print $q->submit(_('Submit changes')); -# print $q->end_form; -# print html_tail($q); -# } + +sub update_edit : Path('update_edit') : Args(1) { + my ($self, $c, $id) = @_; + + my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my $update = $c->model('DB::Comment')->search( + { + id => $id, + %{ $site_restriction }, + } + )->first; + + $c->detach( '/page_error_404_not_found', + [ _('The requested URL was not found on this server.') ] ) + unless $update; + + $c->forward('get_token'); + $c->forward('set_allowed_pages'); + + $c->stash->{update} = $update; + + my $status_message = ''; + if ($c->req->param('submit')) { + $c->forward('check_token'); + + my $old_state = $update->state; + my $new_state = $c->req->param('state'); + + my $edited = 0; + + if ( $c->req->param('name') ne $update->name + || $c->req->param('email') ne $update->user->email + || $c->req->param('anonymous') ne $update->anonymous + || $c->req->param('text') ne $update->text ) + { + $edited = 1; + } + + if ($c->req->param('remove_photo')) { + $update->photo( undef ); + } + + $update->name( $c->req->param('name') || '' ); + $update->text( $c->req->param('text') ); + $update->anonymous( $c->req->param('anonymous') ); + $update->state( $c->req->param( 'state' ) ); + + if ( $c->req->param('email') ne $update->user->email ) { + my $user = $c->model('DB::User')->find_or_create( + { email => $c->req->param('email') } + ); + + $user->insert unless $user->in_storage; + $update->user( $user ); + } + + $update->update; + + $status_message = '

    ' . _('Updated!') . '

    '; + + # If we're hiding an update, see if it marked as fixed and unfix if so + if ($new_state eq 'hidden' && $update->mark_fixed ) { + if ( $update->problem->state eq 'fixed' ) { + $update->problem->state( 'confirmed' ); + $update->problem->update; + } + + $status_message .= '

    ' . _('Problem marked as open.') . '

    '; + } + + if ($new_state ne $old_state) { + $c->forward('log_edit', [ $update->id, 'update', 'state_change' ]); + } + + if ($edited) { + $c->forward('log_edit', [ $update->id, 'update', 'edit' ]); + } + + } + $c->stash->{status_message} = $status_message; + + return 1; +} # # sub get_cobrand_data_from_hash { # my ($cobrand, $data) = @_; -- cgit v1.2.3 From 9eb232472c3845d195391e5412d753d7bdf0cbe6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 11:15:17 +0100 Subject: bit of tidying up and some docs --- perllib/FixMyStreet/App/Controller/Admin.pm | 102 +++++++++++++++------------- 1 file changed, 56 insertions(+), 46 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index aeddc12ad..22cbf78c0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -19,9 +19,9 @@ Admin pages =cut -=head2 index +=head2 summary -Display contact us page +Redirect to index page. There to make the allowed pages stuff neater =cut @@ -30,6 +30,12 @@ sub summary : Path( 'summary' ) : Args(0) { $c->go( 'index' ); } +=head2 index + +Displays some summary information for the requests. + +=cut + sub index : Path : Args(0) { my ( $self, $c ) = @_; @@ -556,6 +562,13 @@ sub report_edit : Path('report_edit') : Args(1) { return 1; } +=head2 set_allowed_pages + +Sets up the allowed_pages stash entry for checking if the current page is +available in the current cobrand. + +=cut + sub set_allowed_pages : Private { my ( $self, $c ) = @_; @@ -583,20 +596,12 @@ sub set_allowed_pages : Private { return 1; } -# use Encode; -# -# use Page; -# use mySociety::Config; -# use mySociety::DBHandle qw(dbh select_all); -# use mySociety::MaPit; -# use mySociety::VotingArea; -# use mySociety::Web qw(NewURL ent); -# =item get_token Generate a token based on user and secret =cut + sub get_token : Private { my ( $self, $c ) = @_; @@ -612,6 +617,13 @@ sub get_token : Private { return 1; } +=item check_token + +Check that a token has been set on a request and it's the correct token. If +not then display 404 page + +=cut + sub check_token : Private { my ( $self, $c ) = @_; @@ -622,6 +634,13 @@ sub check_token : Private { return 1; } +=item log_edit + + $c->forward( 'log_edit', [ $object_id, $object_type, $action_performed ] ); + +Adds an entry into the admin_log table using the current remote_user. + +=cut sub log_edit : Private { my ( $self, $c, $id, $object_type, $action ) = @_; @@ -634,15 +653,16 @@ sub log_edit : Private { } )->insert(); } - + sub update_edit : Path('update_edit') : Args(1) { - my ($self, $c, $id) = @_; + my ( $self, $c, $id ) = @_; - my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my ( $site_res_sql, $site_key, $site_restriction ) = + $c->cobrand->site_restriction; my $update = $c->model('DB::Comment')->search( - { + { id => $id, - %{ $site_restriction }, + %{$site_restriction}, } )->first; @@ -656,7 +676,7 @@ sub update_edit : Path('update_edit') : Args(1) { $c->stash->{update} = $update; my $status_message = ''; - if ($c->req->param('submit')) { + if ( $c->req->param('submit') ) { $c->forward('check_token'); my $old_state = $update->state; @@ -665,29 +685,29 @@ sub update_edit : Path('update_edit') : Args(1) { my $edited = 0; if ( $c->req->param('name') ne $update->name - || $c->req->param('email') ne $update->user->email - || $c->req->param('anonymous') ne $update->anonymous - || $c->req->param('text') ne $update->text ) + || $c->req->param('email') ne $update->user->email + || $c->req->param('anonymous') ne $update->anonymous + || $c->req->param('text') ne $update->text ) { $edited = 1; } - if ($c->req->param('remove_photo')) { - $update->photo( undef ); + if ( $c->req->param('remove_photo') ) { + $update->photo(undef); } $update->name( $c->req->param('name') || '' ); $update->text( $c->req->param('text') ); $update->anonymous( $c->req->param('anonymous') ); - $update->state( $c->req->param( 'state' ) ); + $update->state( $c->req->param('state') ); if ( $c->req->param('email') ne $update->user->email ) { - my $user = $c->model('DB::User')->find_or_create( - { email => $c->req->param('email') } - ); + my $user = + $c->model('DB::User') + ->find_or_create( { email => $c->req->param('email') } ); $user->insert unless $user->in_storage; - $update->user( $user ); + $update->user($user); } $update->update; @@ -695,21 +715,23 @@ sub update_edit : Path('update_edit') : Args(1) { $status_message = '

    ' . _('Updated!') . '

    '; # If we're hiding an update, see if it marked as fixed and unfix if so - if ($new_state eq 'hidden' && $update->mark_fixed ) { + if ( $new_state eq 'hidden' && $update->mark_fixed ) { if ( $update->problem->state eq 'fixed' ) { - $update->problem->state( 'confirmed' ); + $update->problem->state('confirmed'); $update->problem->update; } - $status_message .= '

    ' . _('Problem marked as open.') . '

    '; + $status_message .= + '

    ' . _('Problem marked as open.') . '

    '; } - if ($new_state ne $old_state) { - $c->forward('log_edit', [ $update->id, 'update', 'state_change' ]); + if ( $new_state ne $old_state ) { + $c->forward( 'log_edit', + [ $update->id, 'update', 'state_change' ] ); } if ($edited) { - $c->forward('log_edit', [ $update->id, 'update', 'edit' ]); + $c->forward( 'log_edit', [ $update->id, 'update', 'edit' ] ); } } @@ -717,19 +739,7 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -# -# sub get_cobrand_data_from_hash { -# my ($cobrand, $data) = @_; -# my $cobrand_data; -# if ($data->{cobrand}) { -# $cobrand_data = $data->{cobrand_data}; -# } else { -# $cobrand_data = Cobrand::cobrand_data_for_generic_problem($cobrand, $data); -# } -# return $cobrand_data; -# } -# -# + # sub admin_timeline { # my $q = shift; # my $cobrand = Page::get_cobrand($q); -- cgit v1.2.3 From a82a51695eacf94b7523502b3a48e1de6836fec0 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 16:46:05 +0100 Subject: admin timeline --- perllib/FixMyStreet/App/Controller/Admin.pm | 139 +++++++++++----------------- 1 file changed, 52 insertions(+), 87 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 22cbf78c0..930739718 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -41,7 +41,7 @@ sub index : Path : Args(0) { $c->forward('set_allowed_pages'); - my ( $sql_resttriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; my $problems = $c->model('DB::Problem')->search( @@ -141,6 +141,57 @@ sub index : Path : Args(0) { return 1; } +sub timeline : Path( 'timeline' ) : Args(0) { + my ($self, $c) = @_; + + $c->forward('set_allowed_pages'); + + my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my $cobrand_restriction = { cobrand => $c->cobrand->moniker }; + my %time; + + $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); + + my $probs = $c->model('DB::Problem')->timeline( $site_restriction ); + + foreach ($probs->all) { + push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created_local, obj => $_ }; + push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed_local, obj => $_ } if $_->confirmed; + push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent_local, obj => $_ } if $_->whensent; + } + + my $questionnaires = $c->model('DB::Questionnaire')->timeline( $cobrand_restriction ); + + foreach ($questionnaires->all) { + push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent_local, obj => $_ }; + push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered_local, obj => $_ } if $_->whenanswered; + } + + my $updates = $c->model('DB::Comment')->timeline( $site_restriction ); + + foreach ($updates->all) { + push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created_local, obj => $_} ; + } + + my $alerts = $c->model('DB::Alert')->timeline_created( $cobrand_restriction ); + + foreach ($alerts->all) { + push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed_local, obj => $_ }; + } + + $alerts = $c->model('DB::Alert')->timeline_disabled( $cobrand_restriction ); + + foreach ($alerts->all) { + push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled_local, obj => $_ }; + } + + $c->model('DB')->schema->storage->sql_maker->quote_char( '' ); + + $c->stash->{time} = \%time; + + return 1; +} + sub questionnaire : Path('questionnaire') : Args(0) { my ( $self, $c ) = @_; @@ -740,92 +791,6 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -# sub admin_timeline { -# my $q = shift; -# my $cobrand = Page::get_cobrand($q); -# print html_head($q, _('Timeline')); -# print $q->h1(_('Timeline')); -# -# my %time; -# #my $backto_unix = time() - 60*60*24*7; -# -# my $probs = Problems::timeline_problems(); -# foreach (@$probs) { -# push @{$time{$_->{created}}}, { type => 'problemCreated', %$_ }; -# push @{$time{$_->{confirmed}}}, { type => 'problemConfirmed', %$_ } if $_->{confirmed}; -# push @{$time{$_->{whensent}}}, { type => 'problemSent', %$_ } if $_->{whensent}; -# } -# -# my $questionnaire = Problems::timeline_questionnaires($cobrand); -# foreach (@$questionnaire) { -# push @{$time{$_->{whensent}}}, { type => 'quesSent', %$_ }; -# push @{$time{$_->{whenanswered}}}, { type => 'quesAnswered', %$_ } if $_->{whenanswered}; -# } -# -# my $updates = Problems::timeline_updates(); -# foreach (@$updates) { -# push @{$time{$_->{created}}}, { type => 'update', %$_} ; -# } -# -# my $alerts = Problems::timeline_alerts($cobrand); -# -# -# foreach (@$alerts) { -# push @{$time{$_->{whensubscribed}}}, { type => 'alertSub', %$_ }; -# } -# $alerts = Problems::timeline_deleted_alerts($cobrand); -# foreach (@$alerts) { -# push @{$time{$_->{whendisabled}}}, { type => 'alertDel', %$_ }; -# } -# -# my $date = ''; -# my $cobrand_data; -# foreach (reverse sort keys %time) { -# my $curdate = decode_utf8(strftime('%A, %e %B %Y', localtime($_))); -# if ($date ne $curdate) { -# print '
  • ' if $date; -# print "

    $curdate

    "; -# $date = $curdate; -# } -# print '
    ', decode_utf8(strftime('%H:%M:%S', localtime($_))), ':
    '; -# foreach (@{$time{$_}}) { -# my $type = $_->{type}; -# if ($type eq 'problemCreated') { -# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; -# print sprintf(_("Problem %d created"), $_->{id}) . $name_str; -# } elsif ($type eq 'problemConfirmed') { -# my $name_str = '; ' . sprintf(_("by %s"), ent($_->{name})) . " <" . ent($_->{email}) . ">, '" . ent($_->{title}) . "'"; -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; -# print sprintf(_("Problem %s confirmed"), "$_->{id}") . $name_str; -# } elsif ($type eq 'problemSent') { -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{id}"; -# print sprintf(_("Problem %s sent to council %s"), "$_->{id}", $_->{council}); -# } elsif ($type eq 'quesSent') { -# print sprintf(_("Questionnaire %d sent for problem %d"), $_->{id}, $_->{problem_id}); -# } elsif ($type eq 'quesAnswered') { -# print sprintf(_("Questionnaire %d answered for problem %d, %s to %s"), $_->{id}, $_->{problem_id}, $_->{old_state}, $_->{new_state}); -# } elsif ($type eq 'update') { -# $cobrand_data = get_cobrand_data_from_hash($cobrand, $_); -# my $url = Cobrand::base_url_for_emails($cobrand, $cobrand_data) . "/report/$_->{problem_id}#$_->{id}"; -# my $name = ent($_->{name} || 'anonymous'); -# print sprintf(_("Update %s created for problem %d; by %s"), "$_->{id}", $_->{problem_id}, $name) . " <" . ent($_->{email}) . ">"; -# } elsif ($type eq 'alertSub') { -# my $param = $_->{parameter} || ''; -# my $param2 = $_->{parameter2} || ''; -# print sprintf(_("Alert %d created for %s, type %s, parameters %s / %s"), $_->{id}, ent($_->{email}), $_->{alert_type}, $param, $param2); -# } elsif ($type eq 'alertDel') { -# my $sub = decode_utf8(strftime('%H:%M:%S %e %B %Y', localtime($_->{whensubscribed}))); -# print sprintf(_("Alert %d disabled (created %s)"), $_->{id}, $sub); -# } -# print '
    '; -# } -# print "
    \n"; -# } -# print html_tail($q); -# -# } # # # sub main { -- cgit v1.2.3 From 5813d21b9ac8b358a557ab67722e8b54c769b663 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 17:34:08 +0100 Subject: move summary count fetching out to result sets --- perllib/FixMyStreet/App/Controller/Admin.pm | 47 +++-------------------------- 1 file changed, 5 insertions(+), 42 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 930739718..7cd358e72 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -44,14 +44,7 @@ sub index : Path : Args(0) { my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; - my $problems = $c->model('DB::Problem')->search( - $site_restriction, - { - group_by => ['state'], - select => [ 'state', { count => 'id' } ], - as => [qw/state state_count/] - } - ); + my $problems = $c->model('DB::Problem')->summary_count( $site_restriction ); my %prob_counts = map { $_->state => $_->get_column('state_count') } $problems->all; @@ -63,29 +56,14 @@ sub index : Path : Args(0) { $c->stash->{total_problems_live} = $prob_counts{confirmed} + $prob_counts{fixed}; - my $comments = $c->model('DB::Comment')->search( - $site_restriction, - { - group_by => ['me.state'], - select => [ 'me.state', { count => 'me.id' } ], - as => [qw/state state_count/], - join => 'problem' - } - ); + my $comments = $c->model('DB::Comment')->summary_count( $site_restriction ); my %comment_counts = map { $_->state => $_->get_column('state_count') } $comments->all; $c->stash->{comments} = \%comment_counts; - my $alerts = $c->model('DB::Alert')->search( - $cobrand_restriction, - { - group_by => ['confirmed'], - select => [ 'confirmed', { count => 'id' } ], - as => [qw/confirmed confirmed_count/] - } - ); + my $alerts = $c->model('DB::Alert')->summary_count( $cobrand_restriction ); my %alert_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $alerts->all; @@ -95,14 +73,7 @@ sub index : Path : Args(0) { $c->stash->{alerts} = \%alert_counts; - my $contacts = $c->model('DB::Contact')->search( - undef, - { - group_by => ['confirmed'], - select => [ 'confirmed', { count => 'id' } ], - as => [qw/confirmed confirmed_count/] - } - ); + my $contacts = $c->model('DB::Contact')->summary_count; my %contact_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; @@ -113,15 +84,7 @@ sub index : Path : Args(0) { $c->stash->{contacts} = \%contact_counts; - my $questionnaires = $c->model('DB::Questionnaire')->search( - $cobrand_restriction, - { - group_by => [ \'whenanswered is not null' ], - select => [ \'(whenanswered is not null)', { count => 'me.id' } ], - as => [qw/answered questionnaire_count/], - join => 'problem' - } - ); + my $questionnaires = $c->model('DB::Questionnaire')->summary_count( $cobrand_restriction ); my %questionnaire_counts = map { $_->get_column('answered') => $_->get_column('questionnaire_count') -- cgit v1.2.3 From 673a2879a74d0d71c4d3be0b9c7ee567cf72b219 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 18:01:02 +0100 Subject: implement allowed actions and remove remaining old code --- perllib/FixMyStreet/App/Controller/Admin.pm | 92 ++++++++--------------------- 1 file changed, 25 insertions(+), 67 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7cd358e72..7af8bf098 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -39,7 +39,7 @@ Displays some summary information for the requests. sub index : Path : Args(0) { my ( $self, $c ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; @@ -107,7 +107,7 @@ sub index : Path : Args(0) { sub timeline : Path( 'timeline' ) : Args(0) { my ($self, $c) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = { cobrand => $c->cobrand->moniker }; @@ -158,7 +158,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { sub questionnaire : Path('questionnaire') : Args(0) { my ( $self, $c ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); my $questionnaires = $c->model('DB::Questionnaire')->search( { whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] } @@ -181,7 +181,7 @@ sub questionnaire : Path('questionnaire') : Args(0) { sub council_list : Path('council_list') : Args(0) { my ( $self, $c ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); my $edit_activity = $c->model('DB::ContactsHistory')->search( undef, @@ -231,7 +231,7 @@ sub council_list : Path('council_list') : Args(0) { sub council_contacts : Path('council_contacts') : Args(1) { my ( $self, $c, $area_id ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); my $posted = $c->req->param('posted') || ''; $c->stash->{area_id} = $area_id; @@ -355,7 +355,7 @@ sub setup_council_details : Private { sub council_edit : Path('council_edit') : Args(2) { my ( $self, $c, $area_id, $category ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); $c->stash->{area_id} = $area_id; @@ -389,7 +389,7 @@ sub council_edit : Path('council_edit') : Args(2) { sub search_reports : Path('search_reports') { my ( $self, $c ) = @_; - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); if (my $search = $c->req->param('search')) { $c->stash->{searched} = 1; @@ -478,7 +478,7 @@ sub report_edit : Path('report_edit') : Args(1) { $c->stash->{problem} = $problem; $c->forward('get_token'); - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); $c->stash->{updates} = [ $c->model('DB::Comment') @@ -685,7 +685,7 @@ sub update_edit : Path('update_edit') : Args(1) { unless $update; $c->forward('get_token'); - $c->forward('set_allowed_pages'); + $c->forward('check_page_allowed'); $c->stash->{update} = $update; @@ -754,64 +754,22 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -# -# -# sub main { -# my $q = shift; -# -# my $logout = $q->param('logout'); -# my $timeout = $q->param('timeout'); -# if ($logout) { -# if (!$timeout) { -# print $q->redirect(-location => '?logout=1;timeout=' . (time() + 7)); -# return; -# } -# if (time() < $timeout) { -# print $q->header( -# -status => '401 Unauthorized', -# -www_authenticate => 'Basic realm="www.fixmystreet.com admin pages"' -# ); -# return; -# } -# } -# -# my $page = $q->param('page'); -# $page = "summary" if !$page; -# -# my $area_id = $q->param('area_id'); -# my $category = $q->param('category'); -# my $pages = allowed_pages($q); -# my @allowed_actions = keys %$pages; -# -# if (!grep {$_ eq $page} @allowed_actions) { -# not_found($q); -# return; -# } -# -# if ($page eq "councilslist") { -# admin_councils_list($q); -# } elsif ($page eq "councilcontacts") { -# admin_council_contacts($q, $area_id); -# } elsif ($page eq "counciledit") { -# admin_council_edit($q, $area_id, $category); -# } elsif ($page eq 'reports') { -# admin_reports($q); -# } elsif ($page eq 'report_edit') { -# my $id = $q->param('id'); -# admin_edit_report($q, $id); -# } elsif ($page eq 'update_edit') { -# my $id = $q->param('id'); -# admin_edit_update($q, $id); -# } elsif ($page eq 'timeline') { -# admin_timeline($q); -# } elsif ($page eq 'questionnaire') { -# admin_questionnaire($q); -# } else { -# admin_summary($q); -# } -# } -# Page::do_fastcgi(\&main); -# +sub check_page_allowed : Private { + my ( $self, $c ) = @_; + + $c->forward('set_allowed_pages'); + + (my $page = $c->req->action) =~ s#admin/##; + + $page ||= 'summary'; + + if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) { + $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + } + + return 1; +} + sub trim { my $self = shift; my $e = shift; -- cgit v1.2.3 From cecf86128b3825f92faa6cc222a6cc777293adff Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 7 Jun 2011 18:06:07 +0100 Subject: allow /admin to work --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7af8bf098..579ee9b41 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -759,7 +759,7 @@ sub check_page_allowed : Private { $c->forward('set_allowed_pages'); - (my $page = $c->req->action) =~ s#admin/##; + (my $page = $c->req->action) =~ s#admin/?##; $page ||= 'summary'; -- cgit v1.2.3 From 614abaa627d3f9dfe14efcb994cdcfc0146a623d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jun 2011 23:55:54 +0100 Subject: Removal of old Cobrand.pm and last . --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 579ee9b41..b76447233 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -73,7 +73,7 @@ sub index : Path : Args(0) { $c->stash->{alerts} = \%alert_counts; - my $contacts = $c->model('DB::Contact')->summary_count; + my $contacts = $c->model('DB::Contact')->summary_count( $c->cobrand->contact_restriction ); my %contact_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; -- cgit v1.2.3 From eb46ea44a80374aa01fd0fe9bac75525dba85f08 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 8 Jun 2011 17:56:04 +0100 Subject: switch to using c->cobrand->problems instead of site restriction --- perllib/FixMyStreet/App/Controller/Admin.pm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b76447233..f4c40d5da 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -44,7 +44,7 @@ sub index : Path : Args(0) { my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; - my $problems = $c->model('DB::Problem')->summary_count( $site_restriction ); + my $problems = $c->cobrand->problems->summary_count; my %prob_counts = map { $_->state => $_->get_column('state_count') } $problems->all; @@ -115,7 +115,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); - my $probs = $c->model('DB::Problem')->timeline( $site_restriction ); + my $probs = $c->cobrand->problems->timeline; foreach ($probs->all) { push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created_local, obj => $_ }; @@ -408,7 +408,7 @@ sub search_reports : Path('search_reports') { # it for this query and then switch it off afterwards. $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); - my $problems = $c->model('DB::Problem')->search( + my $problems = $c->cobrand->problems->search( { -or => [ 'me.id' => $search_n, @@ -418,7 +418,6 @@ sub search_reports : Path('search_reports') { detail => { ilike => $like_search }, council => { like => $like_search }, cobrand_data => { like => $like_search }, - %{ $site_restriction }, ] }, { @@ -464,10 +463,9 @@ sub report_edit : Path('report_edit') : Args(1) { my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; - my $problem = $c->model('DB::Problem')->search( + my $problem = $c->cobrand->problems->search( { id => $id, - %{ $site_restriction }, } )->first; -- cgit v1.2.3 From 4e1b27d3fc4384c1c478864035529671bbd709f6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 8 Jun 2011 18:31:49 +0100 Subject: set URIs to be relative so they work with our auth redirection --- perllib/FixMyStreet/App/Controller/Admin.pm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b76447233..152a167e6 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -25,6 +25,12 @@ Redirect to index page. There to make the allowed pages stuff neater =cut +sub begin : Private { + my ( $self, $c ) = @_; + + $c->uri_disposition('relative'); +} + sub summary : Path( 'summary' ) : Args(0) { my ( $self, $c ) = @_; $c->go( 'index' ); -- cgit v1.2.3 From fb26dda031a9409a1716c379d4a86327aa142dd7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 9 Jun 2011 17:11:11 +0100 Subject: Stop empty string warning, delete some test users, and use same n/a string as elsewhere. --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ce9027c32..e5c924730 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -104,7 +104,7 @@ sub index : Path : Args(0) { $questionnaire_counts{total} ? sprintf( '%.1f', $questionnaire_counts{1} / $questionnaire_counts{total} * 100 ) - : 'na'; + : _('n/a'); $c->stash->{questionnaires} = \%questionnaire_counts; return 1; -- cgit v1.2.3 From b5b39afd0d4c6406c491a04f62560a11407e083e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 9 Jun 2011 18:26:14 +0100 Subject: avoid undefined string in ne warning --- perllib/FixMyStreet/App/Controller/Admin.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ce9027c32..15aef8cc1 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -702,13 +702,15 @@ sub update_edit : Path('update_edit') : Args(1) { my $edited = 0; - if ( $c->req->param('name') ne $update->name - || $c->req->param('email') ne $update->user->email - || $c->req->param('anonymous') ne $update->anonymous - || $c->req->param('text') ne $update->text ) - { - $edited = 1; - } + # $update->name can be null which makes ne unhappy + my $name = $update->name || ''; + + if ( $c->req->param('name') ne $name + || $c->req->param('email') ne $update->user->email + || $c->req->param('anonymous') ne $update->anonymous + || $c->req->param('text') ne $update->text ){ + $edited = 1; + } if ( $c->req->param('remove_photo') ) { $update->photo(undef); -- cgit v1.2.3